|  |  | 1 | +using CustomsCargoSystem.Data; | 
|  |  | 2 | +using CustomsCargoSystem.Helper; | 
|  |  | 3 | +using CustomsCargoSystem.MessageQueue; | 
|  |  | 4 | +using CustomsCargoSystem.Model; | 
|  |  | 5 | +using CustomsCargoSystem.Parser; | 
|  |  | 6 | +using System; | 
|  |  | 7 | +using System.Collections.Generic; | 
|  |  | 8 | +using System.ComponentModel; | 
|  |  | 9 | +using System.Configuration; | 
|  |  | 10 | +using System.IO; | 
|  |  | 11 | +using System.Linq; | 
|  |  | 12 | +using System.ServiceProcess; | 
|  |  | 13 | +using System.Text.RegularExpressions; | 
|  |  | 14 | +using System.Threading; | 
|  |  | 15 | +using System.Xml; | 
|  |  | 16 | +using System.Runtime.InteropServices; | 
|  |  | 17 | + | 
|  |  | 18 | +namespace CustomsCargoSystem.ExchangeDataStorageService | 
|  |  | 19 | +{ | 
|  |  | 20 | +    public class MainService : ServiceBase | 
|  |  | 21 | +    { | 
|  |  | 22 | +        private IContainer components = null; | 
|  |  | 23 | + | 
|  |  | 24 | +        [DllImport("kernel32.dll")] | 
|  |  | 25 | +        public static extern IntPtr _lopen(string lpPathName, int iReadWrite); | 
|  |  | 26 | + | 
|  |  | 27 | +        [DllImport("kernel32.dll")] | 
|  |  | 28 | +        public static extern bool CloseHandle(IntPtr hObject); | 
|  |  | 29 | + | 
|  |  | 30 | +        public const int OF_READWRITE = 2; | 
|  |  | 31 | +        public const int OF_SHARE_DENY_NONE = 0x40; | 
|  |  | 32 | +        public readonly IntPtr HFILE_ERROR = new IntPtr(-1); | 
|  |  | 33 | + | 
|  |  | 34 | + | 
|  |  | 35 | +        public string ConnectionString | 
|  |  | 36 | +        { | 
|  |  | 37 | +            get; | 
|  |  | 38 | +            set; | 
|  |  | 39 | +        } | 
|  |  | 40 | + | 
|  |  | 41 | +        public string QmName | 
|  |  | 42 | +        { | 
|  |  | 43 | +            get; | 
|  |  | 44 | +            set; | 
|  |  | 45 | +        } | 
|  |  | 46 | + | 
|  |  | 47 | +        public string QueueInName | 
|  |  | 48 | +        { | 
|  |  | 49 | +            get; | 
|  |  | 50 | +            set; | 
|  |  | 51 | +        } | 
|  |  | 52 | + | 
|  |  | 53 | +        public string Channel | 
|  |  | 54 | +        { | 
|  |  | 55 | +            get; | 
|  |  | 56 | +            set; | 
|  |  | 57 | +        } | 
|  |  | 58 | + | 
|  |  | 59 | +        public string ConnName | 
|  |  | 60 | +        { | 
|  |  | 61 | +            get; | 
|  |  | 62 | +            set; | 
|  |  | 63 | +        } | 
|  |  | 64 | + | 
|  |  | 65 | +        public string IMFMsgPath | 
|  |  | 66 | +        { | 
|  |  | 67 | +            get; | 
|  |  | 68 | +            set; | 
|  |  | 69 | +        } | 
|  |  | 70 | + | 
|  |  | 71 | +        public Thread ServiceThread | 
|  |  | 72 | +        { | 
|  |  | 73 | +            get; | 
|  |  | 74 | +            set; | 
|  |  | 75 | +        } | 
|  |  | 76 | + | 
|  |  | 77 | +        public bool IsThreadNeedRun | 
|  |  | 78 | +        { | 
|  |  | 79 | +            get; | 
|  |  | 80 | +            set; | 
|  |  | 81 | +        } | 
|  |  | 82 | + | 
|  |  | 83 | +        public MainService() | 
|  |  | 84 | +        { | 
|  |  | 85 | +            InitializeComponent(); | 
|  |  | 86 | +            IsThreadNeedRun = true; | 
|  |  | 87 | +            ConnectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString; | 
|  |  | 88 | +            QmName = ConfigurationManager.AppSettings["qmName"]; | 
|  |  | 89 | +            QueueInName = ConfigurationManager.AppSettings["queueInName"]; | 
|  |  | 90 | +            Channel = ConfigurationManager.AppSettings["Channel"]; | 
|  |  | 91 | +            ConnName = ConfigurationManager.AppSettings["ConnName"]; | 
|  |  | 92 | +            IMFMsgPath = ConfigurationManager.AppSettings["IMFMsgPath"]; | 
|  |  | 93 | +        } | 
|  |  | 94 | + | 
|  |  | 95 | +        protected override void OnStart(string[] args) | 
|  |  | 96 | +        { | 
|  |  | 97 | +            try | 
|  |  | 98 | +            { | 
|  |  | 99 | +                Log.WriteLog("9systemlog", "订阅服务开启"); | 
|  |  | 100 | +                IsThreadNeedRun = true; | 
|  |  | 101 | +                ServiceThread = new Thread(StartServiceThread_IMF); | 
|  |  | 102 | +                ServiceThread.Start(); | 
|  |  | 103 | +            } | 
|  |  | 104 | +            catch (Exception ex) | 
|  |  | 105 | +            { | 
|  |  | 106 | +                Log.WriteLog("9systemlog", ex.ToString()); | 
|  |  | 107 | +            } | 
|  |  | 108 | +        } | 
|  |  | 109 | + | 
|  |  | 110 | +        public bool CheckFileCanRead(string filePath) | 
|  |  | 111 | +        { | 
|  |  | 112 | +            string vFileName = filePath; | 
|  |  | 113 | + | 
|  |  | 114 | +            //文件不存在 | 
|  |  | 115 | +            if (!File.Exists(vFileName)) | 
|  |  | 116 | +            { | 
|  |  | 117 | +                return false; | 
|  |  | 118 | +            } | 
|  |  | 119 | +            IntPtr vHandle = _lopen(vFileName, OF_READWRITE | OF_SHARE_DENY_NONE); | 
|  |  | 120 | +            //文件不可读取 | 
|  |  | 121 | +            if (vHandle == HFILE_ERROR) | 
|  |  | 122 | +            { | 
|  |  | 123 | +                return false; | 
|  |  | 124 | +            } | 
|  |  | 125 | +            CloseHandle(vHandle); | 
|  |  | 126 | + | 
|  |  | 127 | +            return true; | 
|  |  | 128 | +        } | 
|  |  | 129 | +        public void StartServiceThread(object obj) | 
|  |  | 130 | +        { | 
|  |  | 131 | +            string connectionString = ConnectionString; | 
|  |  | 132 | +            while (IsThreadNeedRun) | 
|  |  | 133 | +            { | 
|  |  | 134 | +                string text = MessageQueueManager.ReadMessage(QmName, QueueInName, Channel, ConnName); | 
|  |  | 135 | +                if (!string.IsNullOrWhiteSpace(text)) | 
|  |  | 136 | +                { | 
|  |  | 137 | +                    Log.WriteMessage("999All", DateTime.Now.ToString("yyyyMMddHHmmss"), text); | 
|  |  | 138 | +                    try | 
|  |  | 139 | +                    { | 
|  |  | 140 | +                        if (text.Contains("FWB/")) | 
|  |  | 141 | +                        { | 
|  |  | 142 | +                            Log.WriteMessage("1fwboriginal", DateTime.Now.ToString("yyyyMMddHHmmssfff"), text); | 
|  |  | 143 | +                            if (!text.Contains("<Msg>")) | 
|  |  | 144 | +                            { | 
|  |  | 145 | +                                ProcessXmlDocumentFWB(text); | 
|  |  | 146 | +                            } | 
|  |  | 147 | +                        } | 
|  |  | 148 | +                        else if (text.Contains("FFM/") && text.Contains("CGO")) | 
|  |  | 149 | +                        { | 
|  |  | 150 | +                            Log.WriteMessage("2ffmoriginal", DateTime.Now.ToString("yyyyMMddHHmmssfff"), text); | 
|  |  | 151 | +                            if (!text.Contains("<Msg>")) | 
|  |  | 152 | +                            { | 
|  |  | 153 | +                                BookingFFMINFO(text); | 
|  |  | 154 | +                            } | 
|  |  | 155 | +                        } | 
|  |  | 156 | +                        else if (text.Contains("FHL/")) | 
|  |  | 157 | +                        { | 
|  |  | 158 | +                            Log.WriteMessage("3fhloriginal", DateTime.Now.ToString("yyyyMMddHHmmssfff"), text); | 
|  |  | 159 | +                            if (!text.Contains("<Msg>")) | 
|  |  | 160 | +                            { | 
|  |  | 161 | +                                ProcessXmlDocumentFHL(text); | 
|  |  | 162 | +                            } | 
|  |  | 163 | +                        } | 
|  |  | 164 | +                        else if (text.Contains("<TYPE>ICUSTOMS</TYPE>") && (text.Contains("FSU_FOH") || text.Contains("FZE_FOH") || text.Contains("FSU_DEP") || text.Contains("FZE_DEP") || text.Contains("FSU_RCF") || text.Contains("FZE_RCF") || text.Contains("<STYP>PFFM</STYP>"))) | 
|  |  | 165 | +                        { | 
|  |  | 166 | +                            XmlDocument xmlDocument = new XmlDocument(); | 
|  |  | 167 | +                            xmlDocument.LoadXml(text); | 
|  |  | 168 | +                            ProcessXmlDocument_New(xmlDocument); | 
|  |  | 169 | +                        } | 
|  |  | 170 | +                    } | 
|  |  | 171 | +                    catch (Exception ex) | 
|  |  | 172 | +                    { | 
|  |  | 173 | +                        Log.WriteLog("9systemlog", ex.ToString()); | 
|  |  | 174 | +                    } | 
|  |  | 175 | +                    Thread.Sleep(200); | 
|  |  | 176 | +                } | 
|  |  | 177 | +            } | 
|  |  | 178 | +        } | 
|  |  | 179 | + | 
|  |  | 180 | +        public void StartServiceThread_IMF(object obj) | 
|  |  | 181 | +        { | 
|  |  | 182 | +            try | 
|  |  | 183 | +            { | 
|  |  | 184 | +                string connectionString = ConnectionString; | 
|  |  | 185 | +                while (IsThreadNeedRun) | 
|  |  | 186 | +                { | 
|  |  | 187 | +                    string text = ""; | 
|  |  | 188 | +                    string[] files = Directory.GetFiles(IMFMsgPath, "*.txt"); | 
|  |  | 189 | +                    for (int i = 0; i < files.Length; i++) | 
|  |  | 190 | +                    { | 
|  |  | 191 | +                        if (!CheckFileCanRead(files[i])) | 
|  |  | 192 | +                        { | 
|  |  | 193 | +                            continue; | 
|  |  | 194 | +                        } | 
|  |  | 195 | +                        text = File.ReadAllText(files[i]); | 
|  |  | 196 | +                        if (string.IsNullOrWhiteSpace(text)) | 
|  |  | 197 | +                        { | 
|  |  | 198 | +                            if (File.Exists(files[i])) | 
|  |  | 199 | +                            { | 
|  |  | 200 | +                                File.Delete(files[i]); | 
|  |  | 201 | +                            } | 
|  |  | 202 | +                            continue; | 
|  |  | 203 | +                        } | 
|  |  | 204 | +                        Log.WriteMessage("999All", DateTime.Now.ToString("yyyyMMddHHmmss"), text); | 
|  |  | 205 | +                        if (!text.Contains("<META>")) | 
|  |  | 206 | +                        { | 
|  |  | 207 | +                            if (File.Exists(files[i])) | 
|  |  | 208 | +                            { | 
|  |  | 209 | +                                File.Delete(files[i]); | 
|  |  | 210 | +                            } | 
|  |  | 211 | +                        } | 
|  |  | 212 | +                        else | 
|  |  | 213 | +                        { | 
|  |  | 214 | +                            try | 
|  |  | 215 | +                            { | 
|  |  | 216 | +                                XmlDocument xmlDocument = new XmlDocument(); | 
|  |  | 217 | +                                xmlDocument.LoadXml(File.ReadAllText(files[i])); | 
|  |  | 218 | +                                if (text.Contains("<STYP>IFWB</STYP>") && text.Contains("FWB/")) | 
|  |  | 219 | +                                { | 
|  |  | 220 | +                                    Log.WriteMessage("1fwboriginal", DateTime.Now.ToString("yyyyMMddHHmmssfff"), text); | 
|  |  | 221 | +                                    XmlNode xmlNode = xmlDocument.SelectSingleNode("/MSG/FWB"); | 
|  |  | 222 | +                                    if (xmlNode != null) | 
|  |  | 223 | +                                    { | 
|  |  | 224 | +                                        ProcessXmlDocumentFWB(xmlNode.InnerText); | 
|  |  | 225 | +                                    } | 
|  |  | 226 | +                                } | 
|  |  | 227 | +                                else if (text.Contains("<STYP>FFM</STYP>") && text.Contains("FFM/") && text.Contains("CGO")) | 
|  |  | 228 | +                                { | 
|  |  | 229 | +                                    Log.WriteMessage("2ffmoriginal", DateTime.Now.ToString("yyyyMMddHHmmssfff"), text); | 
|  |  | 230 | +                                    XmlNode xmlNode = xmlDocument.SelectSingleNode("/MSG/FFM"); | 
|  |  | 231 | +                                    if (xmlNode != null) | 
|  |  | 232 | +                                    { | 
|  |  | 233 | +                                        BookingFFMINFO(xmlNode.InnerText); | 
|  |  | 234 | +                                    } | 
|  |  | 235 | +                                } | 
|  |  | 236 | +                                else if (text.Contains("<STYP>IFHL</STYP>") && text.Contains("FHL/")) | 
|  |  | 237 | +                                { | 
|  |  | 238 | +                                    Log.WriteMessage("3fhloriginal", DateTime.Now.ToString("yyyyMMddHHmmssfff"), text); | 
|  |  | 239 | +                                    XmlNode xmlNode = xmlDocument.SelectSingleNode("/MSG/FHL"); | 
|  |  | 240 | +                                    if (xmlNode != null) | 
|  |  | 241 | +                                    { | 
|  |  | 242 | +                                        ProcessXmlDocumentFHL(xmlNode.InnerText); | 
|  |  | 243 | +                                    } | 
|  |  | 244 | +                                } | 
|  |  | 245 | +                                else if (text.Contains("<TYPE>DFME</TYPE>") && (text.Contains("<STYP>UFOH</STYP>") || text.Contains("<STYP>EFOH</STYP>") || text.Contains("<STYP>UDEP</STYP>") || text.Contains("<STYP>EDEP</STYP>") || text.Contains("<STYP>URCF</STYP>") || text.Contains("<STYP>ERCF</STYP>") || text.Contains("<STYP>PFFM</STYP>"))) | 
|  |  | 246 | +                                { | 
|  |  | 247 | +                                    ProcessXmlDocument_New(xmlDocument); | 
|  |  | 248 | +                                } | 
|  |  | 249 | +                            } | 
|  |  | 250 | +                            catch (Exception ex) | 
|  |  | 251 | +                            { | 
|  |  | 252 | +                                Log.WriteLog("9systemlog", ex.ToString()); | 
|  |  | 253 | +                            } | 
|  |  | 254 | +                            finally | 
|  |  | 255 | +                            { | 
|  |  | 256 | +                                if (File.Exists(files[i])) | 
|  |  | 257 | +                                { | 
|  |  | 258 | +                                    File.Delete(files[i]); | 
|  |  | 259 | +                                } | 
|  |  | 260 | +                            } | 
|  |  | 261 | +                        } | 
|  |  | 262 | +                    } | 
|  |  | 263 | +                    Thread.Sleep(500); | 
|  |  | 264 | +                } | 
|  |  | 265 | +            }catch(IOException e){ | 
|  |  | 266 | +                Log.WriteLog("9systemlog", e.ToString()); | 
|  |  | 267 | +            } | 
|  |  | 268 | +        } | 
|  |  | 269 | + | 
|  |  | 270 | +        protected override void OnStop() | 
|  |  | 271 | +        { | 
|  |  | 272 | +            IsThreadNeedRun = false; | 
|  |  | 273 | +            try | 
|  |  | 274 | +            { | 
|  |  | 275 | +                ServiceThread.Abort(); | 
|  |  | 276 | +                ServiceThread = null; | 
|  |  | 277 | +            } | 
|  |  | 278 | +            catch (Exception) | 
|  |  | 279 | +            { | 
|  |  | 280 | +                throw; | 
|  |  | 281 | +            } | 
|  |  | 282 | +        } | 
|  |  | 283 | + | 
|  |  | 284 | +        public bool ProcessXmlDocument(XmlDocument xmlDoc) | 
|  |  | 285 | +        { | 
|  |  | 286 | +            string text = ""; | 
|  |  | 287 | +            int num = 0; | 
|  |  | 288 | +            string connectionString = ConnectionString; | 
|  |  | 289 | +            try | 
|  |  | 290 | +            { | 
|  |  | 291 | +                XmlNode xmlNode = xmlDoc.SelectSingleNode("/MSG/META/TYPE"); | 
|  |  | 292 | +                XmlNode xmlNode2 = xmlDoc.SelectSingleNode("/MSG/META/STYP"); | 
|  |  | 293 | +                if (xmlNode == null || xmlNode2 == null) | 
|  |  | 294 | +                { | 
|  |  | 295 | +                    return false; | 
|  |  | 296 | +                } | 
|  |  | 297 | +                string innerText = xmlNode.InnerText; | 
|  |  | 298 | +                string innerText2 = xmlNode2.InnerText; | 
|  |  | 299 | +                if (innerText != "ICUSTOMS") | 
|  |  | 300 | +                { | 
|  |  | 301 | +                    return false; | 
|  |  | 302 | +                } | 
|  |  | 303 | +                if ("FSU_FOH" == innerText2) | 
|  |  | 304 | +                { | 
|  |  | 305 | +                    CustomsCargoSystem.Model.ArrivedMaster arrivedMaster = CustomsCargoSystem.Parser.ArrivedMaster.Parse(xmlDoc); | 
|  |  | 306 | +                    text = arrivedMaster.WAYBILLNOMASTER; | 
|  |  | 307 | +                    Log.WriteMessage("FSU_FOH", arrivedMaster.WAYBILLNOMASTER, xmlDoc.InnerXml); | 
|  |  | 308 | +                    string masterid = ""; | 
|  |  | 309 | +                    num = CustomsCargoSystem.Data.ArrivedMaster.Save(connectionString, arrivedMaster, out masterid); | 
|  |  | 310 | +                    if (num > 0 && !string.IsNullOrEmpty(masterid)) | 
|  |  | 311 | +                    { | 
|  |  | 312 | +                        IEnumerable<CustomsCargoSystem.Model.ArrivedSecondary> source = CustomsCargoSystem.Data.ArrivedSecondary.exist_arrivedmasteride(connectionString, arrivedMaster.WAYBILLNOMASTER); | 
|  |  | 313 | +                        if (source.Count() > 0) | 
|  |  | 314 | +                        { | 
|  |  | 315 | +                            CustomsCargoSystem.Data.ArrivedSecondary.UpdateArrivedSecondary_arrivedmasterid(connectionString, arrivedMaster.WAYBILLNOMASTER, masterid, arrivedMaster.CUSTOMSCODE); | 
|  |  | 316 | +                        } | 
|  |  | 317 | +                    } | 
|  |  | 318 | +                } | 
|  |  | 319 | +                if ("FZE_FOH" == innerText2) | 
|  |  | 320 | +                { | 
|  |  | 321 | +                    CustomsCargoSystem.Model.ArrivedSecondary arrivedSecondary = CustomsCargoSystem.Parser.ArrivedSecondary.Parse(xmlDoc); | 
|  |  | 322 | +                    Log.WriteMessage("FZE_FOH", arrivedSecondary.WAYBILLNOMASTER, xmlDoc.InnerXml); | 
|  |  | 323 | +                    num = CustomsCargoSystem.Data.ArrivedSecondary.Save(connectionString, arrivedSecondary); | 
|  |  | 324 | +                } | 
|  |  | 325 | +                if ("FSU_DEP" == innerText2) | 
|  |  | 326 | +                { | 
|  |  | 327 | +                    CustomsCargoSystem.Model.TallyMaster tallyMaster = CustomsCargoSystem.Parser.TallyMaster.Parse(xmlDoc, "FSU_DEP"); | 
|  |  | 328 | +                    text = tallyMaster.WAYBILLNOMASTER; | 
|  |  | 329 | +                    Log.WriteMessage("FSU_DEP", tallyMaster.WAYBILLNOMASTER, xmlDoc.InnerXml); | 
|  |  | 330 | +                    string masterid = ""; | 
|  |  | 331 | +                    num = CustomsCargoSystem.Data.TallyMaster.Save(connectionString, tallyMaster, out masterid); | 
|  |  | 332 | +                    if (num > 0) | 
|  |  | 333 | +                    { | 
|  |  | 334 | +                        IEnumerable<CustomsCargoSystem.Model.TallySecondary> source2 = CustomsCargoSystem.Data.TallySecondary.tallymasteridisnull(connectionString, tallyMaster.WAYBILLNOMASTER); | 
|  |  | 335 | +                        if (source2.Count() > 0 && !string.IsNullOrEmpty(masterid)) | 
|  |  | 336 | +                        { | 
|  |  | 337 | +                            CustomsCargoSystem.Data.TallySecondary.update_tallysecondary_tallymasterid(connectionString, tallyMaster.WAYBILLNOMASTER, masterid); | 
|  |  | 338 | +                        } | 
|  |  | 339 | +                    } | 
|  |  | 340 | +                } | 
|  |  | 341 | +                if ("FZE_DEP" == innerText2) | 
|  |  | 342 | +                { | 
|  |  | 343 | +                    CustomsCargoSystem.Model.TallySecondary tallySecondary = CustomsCargoSystem.Parser.TallySecondary.Parse(xmlDoc, "FZE_DEP"); | 
|  |  | 344 | +                    text = tallySecondary.WAYBILLNOSECONDARY; | 
|  |  | 345 | +                    Log.WriteMessage("FZE_DEP", tallySecondary.WAYBILLNOMASTER, xmlDoc.InnerXml); | 
|  |  | 346 | +                    num = CustomsCargoSystem.Data.TallySecondary.Save(connectionString, tallySecondary); | 
|  |  | 347 | +                } | 
|  |  | 348 | +                if ("FSU_RCF" == innerText2) | 
|  |  | 349 | +                { | 
|  |  | 350 | +                    Log.WriteMessage("FSU_RCF", DateTime.Now.ToString("yyyyMMddHHmmss"), xmlDoc.InnerXml); | 
|  |  | 351 | +                    CustomsCargoSystem.Model.TallyMaster tallyMaster = CustomsCargoSystem.Parser.TallyMaster.Parse(xmlDoc, "FSU_RCF"); | 
|  |  | 352 | +                    text = tallyMaster.WAYBILLNOMASTER; | 
|  |  | 353 | +                    IEnumerable<CustomsCargoSystem.Model.TallyMaster> source3 = CustomsCargoSystem.Data.TallyMaster.TallyMasterIsExist(connectionString, text, tallyMaster.FLIGHTNO, tallyMaster.FLIGHTDATE.ToString("yyyy-MM-dd")); | 
|  |  | 354 | +                    List<CustomsCargoSystem.Model.OriginManifestMaster> source4 = CustomsCargoSystem.Data.OriginManifestMaster.GetFlightOgi(connectionString, tallyMaster.FLIGHTNO, tallyMaster.FLIGHTDATE).ToList(); | 
|  |  | 355 | +                    if (source4.Count() > 0) | 
|  |  | 356 | +                    { | 
|  |  | 357 | +                        tallyMaster.ORIGINATINGSTATION = source4.FirstOrDefault().OriginatingStation; | 
|  |  | 358 | +                    } | 
|  |  | 359 | +                    if (source3.Count() == 0) | 
|  |  | 360 | +                    { | 
|  |  | 361 | +                        string masterid = ""; | 
|  |  | 362 | +                        num = CustomsCargoSystem.Data.TallyMaster.Save(connectionString, tallyMaster, out masterid); | 
|  |  | 363 | +                        if (num > 0) | 
|  |  | 364 | +                        { | 
|  |  | 365 | +                            IEnumerable<CustomsCargoSystem.Model.TallySecondary> source2 = CustomsCargoSystem.Data.TallySecondary.tallymasteridisnull(connectionString, tallyMaster.WAYBILLNOMASTER); | 
|  |  | 366 | +                            if (source2.Count() > 0 && !string.IsNullOrEmpty(masterid)) | 
|  |  | 367 | +                            { | 
|  |  | 368 | +                                CustomsCargoSystem.Data.TallySecondary.update_tallysecondary_tallymasterid(connectionString, tallyMaster.WAYBILLNOMASTER, masterid); | 
|  |  | 369 | +                            } | 
|  |  | 370 | +                        } | 
|  |  | 371 | +                    } | 
|  |  | 372 | +                } | 
|  |  | 373 | +                if ("FZE_RCF" == innerText2) | 
|  |  | 374 | +                { | 
|  |  | 375 | +                    Log.WriteMessage("FZE_RCF", DateTime.Now.ToString("yyyyMMddHHmmss"), xmlDoc.InnerXml); | 
|  |  | 376 | +                    CustomsCargoSystem.Model.TallySecondary tallySecondary = CustomsCargoSystem.Parser.TallySecondary.Parse(xmlDoc, "FZE_RCF"); | 
|  |  | 377 | +                    text = tallySecondary.WAYBILLNOMASTER; | 
|  |  | 378 | +                    IEnumerable<CustomsCargoSystem.Model.TallySecondary> source5 = CustomsCargoSystem.Data.TallySecondary.TallySecondaryIsExist(connectionString, text, tallySecondary.WAYBILLNOSECONDARY); | 
|  |  | 379 | +                    if (source5.Count() == 0) | 
|  |  | 380 | +                    { | 
|  |  | 381 | +                        num = CustomsCargoSystem.Data.TallySecondary.Save(connectionString, tallySecondary); | 
|  |  | 382 | +                    } | 
|  |  | 383 | +                } | 
|  |  | 384 | +                if ("PFFM" == innerText2) | 
|  |  | 385 | +                { | 
|  |  | 386 | +                    List<DEPARTURESLOADING> list = departuresloading.Parse(xmlDoc); | 
|  |  | 387 | +                    Log.WriteMessage("PFFM", DateTime.Now.ToString("yyyyMMddHHmmssfff"), xmlDoc.InnerXml); | 
|  |  | 388 | +                    foreach (DEPARTURESLOADING item in list) | 
|  |  | 389 | +                    { | 
|  |  | 390 | +                        text = item.waybillno; | 
|  |  | 391 | +                        num = departuresloading_service.Save(connectionString, item); | 
|  |  | 392 | +                    } | 
|  |  | 393 | +                } | 
|  |  | 394 | +                return true; | 
|  |  | 395 | +            } | 
|  |  | 396 | +            catch (Exception ex) | 
|  |  | 397 | +            { | 
|  |  | 398 | +                Log.WriteLog("4xml_error", ex.ToString() + "\r\n\r\n" + xmlDoc.InnerText); | 
|  |  | 399 | +                return false; | 
|  |  | 400 | +            } | 
|  |  | 401 | +        } | 
|  |  | 402 | + | 
|  |  | 403 | +        public bool ProcessXmlDocument_New(XmlDocument xmlDoc) | 
|  |  | 404 | +        { | 
|  |  | 405 | +            string text = ""; | 
|  |  | 406 | +            int num = 0; | 
|  |  | 407 | +            string connectionString = ConnectionString; | 
|  |  | 408 | +            try | 
|  |  | 409 | +            { | 
|  |  | 410 | +                XmlNode xmlNode = xmlDoc.SelectSingleNode("/MSG/META/TYPE"); | 
|  |  | 411 | +                XmlNode xmlNode2 = xmlDoc.SelectSingleNode("/MSG/META/STYP"); | 
|  |  | 412 | +                if (xmlNode == null || xmlNode2 == null) | 
|  |  | 413 | +                { | 
|  |  | 414 | +                    return false; | 
|  |  | 415 | +                } | 
|  |  | 416 | +                string innerText = xmlNode.InnerText; | 
|  |  | 417 | +                string innerText2 = xmlNode2.InnerText; | 
|  |  | 418 | +                if (innerText != "DFME") | 
|  |  | 419 | +                { | 
|  |  | 420 | +                    return false; | 
|  |  | 421 | +                } | 
|  |  | 422 | +                if ("UFOH" == innerText2) | 
|  |  | 423 | +                { | 
|  |  | 424 | +                    CustomsCargoSystem.Model.ArrivedMaster arrivedMaster = CustomsCargoSystem.Parser.ArrivedMaster.Parse(xmlDoc); | 
|  |  | 425 | +                    text = arrivedMaster.WAYBILLNOMASTER; | 
|  |  | 426 | +                    Log.WriteMessage("FSU_FOH", arrivedMaster.WAYBILLNOMASTER, xmlDoc.InnerXml); | 
|  |  | 427 | +                    string masterid = ""; | 
|  |  | 428 | +                    num = CustomsCargoSystem.Data.ArrivedMaster.Save(connectionString, arrivedMaster, out masterid); | 
|  |  | 429 | +                    if (num > 0 && !string.IsNullOrEmpty(masterid)) | 
|  |  | 430 | +                    { | 
|  |  | 431 | +                        IEnumerable<CustomsCargoSystem.Model.ArrivedSecondary> source = CustomsCargoSystem.Data.ArrivedSecondary.exist_arrivedmasteride(connectionString, arrivedMaster.WAYBILLNOMASTER); | 
|  |  | 432 | +                        if (source.Count() > 0) | 
|  |  | 433 | +                        { | 
|  |  | 434 | +                            CustomsCargoSystem.Data.ArrivedSecondary.UpdateArrivedSecondary_arrivedmasterid(connectionString, arrivedMaster.WAYBILLNOMASTER, masterid, arrivedMaster.CUSTOMSCODE); | 
|  |  | 435 | +                        } | 
|  |  | 436 | +                    } | 
|  |  | 437 | +                } | 
|  |  | 438 | +                if ("EFOH" == innerText2) | 
|  |  | 439 | +                { | 
|  |  | 440 | +                    CustomsCargoSystem.Model.ArrivedSecondary arrivedSecondary = CustomsCargoSystem.Parser.ArrivedSecondary.Parse(xmlDoc); | 
|  |  | 441 | +                    Log.WriteMessage("FZE_FOH", arrivedSecondary.WAYBILLNOMASTER, xmlDoc.InnerXml); | 
|  |  | 442 | +                    num = CustomsCargoSystem.Data.ArrivedSecondary.Save(connectionString, arrivedSecondary); | 
|  |  | 443 | +                } | 
|  |  | 444 | +                if ("UDEP" == innerText2) | 
|  |  | 445 | +                { | 
|  |  | 446 | +                    CustomsCargoSystem.Model.TallyMaster tallyMaster = CustomsCargoSystem.Parser.TallyMaster.Parse(xmlDoc, "FSU_DEP"); | 
|  |  | 447 | +                    text = tallyMaster.WAYBILLNOMASTER; | 
|  |  | 448 | +                    Log.WriteMessage("FSU_DEP", tallyMaster.WAYBILLNOMASTER, xmlDoc.InnerXml); | 
|  |  | 449 | +                    string masterid = ""; | 
|  |  | 450 | +                    num = CustomsCargoSystem.Data.TallyMaster.Save(connectionString, tallyMaster, out masterid); | 
|  |  | 451 | +                    if (num > 0) | 
|  |  | 452 | +                    { | 
|  |  | 453 | +                        IEnumerable<CustomsCargoSystem.Model.TallySecondary> source2 = CustomsCargoSystem.Data.TallySecondary.tallymasteridisnull(connectionString, tallyMaster.WAYBILLNOMASTER); | 
|  |  | 454 | +                        if (source2.Count() > 0 && !string.IsNullOrEmpty(masterid)) | 
|  |  | 455 | +                        { | 
|  |  | 456 | +                            CustomsCargoSystem.Data.TallySecondary.update_tallysecondary_tallymasterid(connectionString, tallyMaster.WAYBILLNOMASTER, masterid); | 
|  |  | 457 | +                        } | 
|  |  | 458 | +                    } | 
|  |  | 459 | +                } | 
|  |  | 460 | +                if ("EDEP" == innerText2) | 
|  |  | 461 | +                { | 
|  |  | 462 | +                    CustomsCargoSystem.Model.TallySecondary tallySecondary = CustomsCargoSystem.Parser.TallySecondary.Parse(xmlDoc, "FZE_DEP"); | 
|  |  | 463 | +                    text = tallySecondary.WAYBILLNOSECONDARY; | 
|  |  | 464 | +                    Log.WriteMessage("FZE_DEP", tallySecondary.WAYBILLNOMASTER, xmlDoc.InnerXml); | 
|  |  | 465 | +                    num = CustomsCargoSystem.Data.TallySecondary.Save(connectionString, tallySecondary); | 
|  |  | 466 | +                } | 
|  |  | 467 | +                if ("URCF" == innerText2) | 
|  |  | 468 | +                { | 
|  |  | 469 | +                    Log.WriteMessage("FSU_RCF", DateTime.Now.ToString("yyyyMMddHHmmss"), xmlDoc.InnerXml); | 
|  |  | 470 | +                    CustomsCargoSystem.Model.TallyMaster tallyMaster = CustomsCargoSystem.Parser.TallyMaster.Parse(xmlDoc, "FSU_RCF"); | 
|  |  | 471 | +                    text = tallyMaster.WAYBILLNOMASTER; | 
|  |  | 472 | +                    IEnumerable<CustomsCargoSystem.Model.TallyMaster> source3 = CustomsCargoSystem.Data.TallyMaster.TallyMasterIsExist(connectionString, text, tallyMaster.FLIGHTNO, tallyMaster.FLIGHTDATE.ToString("yyyy-MM-dd")); | 
|  |  | 473 | +                    List<CustomsCargoSystem.Model.OriginManifestMaster> source4 = CustomsCargoSystem.Data.OriginManifestMaster.GetFlightOgi(connectionString, tallyMaster.FLIGHTNO, tallyMaster.FLIGHTDATE).ToList(); | 
|  |  | 474 | +                    if (source4.Count() > 0) | 
|  |  | 475 | +                    { | 
|  |  | 476 | +                        tallyMaster.ORIGINATINGSTATION = source4.FirstOrDefault().OriginatingStation; | 
|  |  | 477 | +                    } | 
|  |  | 478 | +                    if (source3.Count() == 0) | 
|  |  | 479 | +                    { | 
|  |  | 480 | +                        string masterid = ""; | 
|  |  | 481 | +                        num = CustomsCargoSystem.Data.TallyMaster.Save(connectionString, tallyMaster, out masterid); | 
|  |  | 482 | +                        if (num > 0) | 
|  |  | 483 | +                        { | 
|  |  | 484 | +                            IEnumerable<CustomsCargoSystem.Model.TallySecondary> source2 = CustomsCargoSystem.Data.TallySecondary.tallymasteridisnull(connectionString, tallyMaster.WAYBILLNOMASTER); | 
|  |  | 485 | +                            if (source2.Count() > 0 && !string.IsNullOrEmpty(masterid)) | 
|  |  | 486 | +                            { | 
|  |  | 487 | +                                CustomsCargoSystem.Data.TallySecondary.update_tallysecondary_tallymasterid(connectionString, tallyMaster.WAYBILLNOMASTER, masterid); | 
|  |  | 488 | +                            } | 
|  |  | 489 | +                        } | 
|  |  | 490 | +                    } | 
|  |  | 491 | +                    else if (source3.Count() > 0) | 
|  |  | 492 | +                    { | 
|  |  | 493 | +                        tallyMaster.AUTOID = source3.FirstOrDefault().AUTOID; | 
|  |  | 494 | +                        CustomsCargoSystem.Data.TallyMaster.Update(connectionString, tallyMaster); | 
|  |  | 495 | +                        IEnumerable<CustomsCargoSystem.Model.TallySecondary> source2 = CustomsCargoSystem.Data.TallySecondary.tallymasteridisnull(connectionString, tallyMaster.WAYBILLNOMASTER); | 
|  |  | 496 | +                        if (source2.Count() > 0 && !string.IsNullOrEmpty(tallyMaster.AUTOID)) | 
|  |  | 497 | +                        { | 
|  |  | 498 | +                            CustomsCargoSystem.Data.TallySecondary.update_tallysecondary_tallymasterid(connectionString, tallyMaster.WAYBILLNOMASTER, tallyMaster.AUTOID); | 
|  |  | 499 | +                        } | 
|  |  | 500 | +                    } | 
|  |  | 501 | +                } | 
|  |  | 502 | +                if ("ERCF" == innerText2) | 
|  |  | 503 | +                { | 
|  |  | 504 | +                    Log.WriteMessage("FZE_RCF", DateTime.Now.ToString("yyyyMMddHHmmss"), xmlDoc.InnerXml); | 
|  |  | 505 | +                    CustomsCargoSystem.Model.TallySecondary tallySecondary = CustomsCargoSystem.Parser.TallySecondary.Parse(xmlDoc, "FZE_RCF"); | 
|  |  | 506 | +                    text = tallySecondary.WAYBILLNOMASTER; | 
|  |  | 507 | +                    IEnumerable<CustomsCargoSystem.Model.TallyMaster> byWayBillNoMaster = CustomsCargoSystem.Data.TallyMaster.GetByWayBillNoMaster(connectionString, text); | 
|  |  | 508 | +                    if (byWayBillNoMaster != null && byWayBillNoMaster.Count() > 0) | 
|  |  | 509 | +                    { | 
|  |  | 510 | +                        tallySecondary.TALLYMASTERID = byWayBillNoMaster.FirstOrDefault().AUTOID; | 
|  |  | 511 | +                    } | 
|  |  | 512 | +                    IEnumerable<CustomsCargoSystem.Model.TallySecondary> source5 = CustomsCargoSystem.Data.TallySecondary.TallySecondaryIsExist(connectionString, text, tallySecondary.WAYBILLNOSECONDARY); | 
|  |  | 513 | +                    if (source5.Count() == 0) | 
|  |  | 514 | +                    { | 
|  |  | 515 | +                        num = CustomsCargoSystem.Data.TallySecondary.Save(connectionString, tallySecondary); | 
|  |  | 516 | +                    } | 
|  |  | 517 | +                    else if (source5.Count() > 0) | 
|  |  | 518 | +                    { | 
|  |  | 519 | +                        tallySecondary.AUTOID = source5.FirstOrDefault().AUTOID; | 
|  |  | 520 | +                        CustomsCargoSystem.Data.TallySecondary.Update(connectionString, tallySecondary); | 
|  |  | 521 | +                    } | 
|  |  | 522 | +                } | 
|  |  | 523 | +                if ("PFFM" == innerText2) | 
|  |  | 524 | +                { | 
|  |  | 525 | +                    List<DEPARTURESLOADING> list = departuresloading.Parse(xmlDoc); | 
|  |  | 526 | +                    Log.WriteMessage("PFFM", DateTime.Now.ToString("yyyyMMddHHmmssfff"), xmlDoc.InnerXml); | 
|  |  | 527 | +                    foreach (DEPARTURESLOADING item in list) | 
|  |  | 528 | +                    { | 
|  |  | 529 | +                        text = item.waybillno; | 
|  |  | 530 | +                        num = departuresloading_service.Save(connectionString, item); | 
|  |  | 531 | +                    } | 
|  |  | 532 | +                } | 
|  |  | 533 | +                return true; | 
|  |  | 534 | +            } | 
|  |  | 535 | +            catch (Exception ex) | 
|  |  | 536 | +            { | 
|  |  | 537 | +                Log.WriteLog("4xml_error", ex.ToString() + "\r\n\r\n" + xmlDoc.InnerText); | 
|  |  | 538 | +                return false; | 
|  |  | 539 | +            } | 
|  |  | 540 | +        } | 
|  |  | 541 | + | 
|  |  | 542 | +        public static bool ProcessXmlDocumentFWB(string FWB) | 
|  |  | 543 | +        { | 
|  |  | 544 | +            bool result = false; | 
|  |  | 545 | +            string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString; | 
|  |  | 546 | +            string text = string.Empty; | 
|  |  | 547 | +            string text2 = string.Empty; | 
|  |  | 548 | +            string cARRIER = string.Empty; | 
|  |  | 549 | +            string aRRIVALSTATION = string.Empty; | 
|  |  | 550 | +            string cARRIER2 = string.Empty; | 
|  |  | 551 | +            string aRRIVALSTATION2 = string.Empty; | 
|  |  | 552 | +            string cARRIER3 = string.Empty; | 
|  |  | 553 | +            string text3 = string.Empty; | 
|  |  | 554 | +            string text4 = string.Empty; | 
|  |  | 555 | +            string text5 = string.Empty; | 
|  |  | 556 | +            string text6 = string.Empty; | 
|  |  | 557 | +            string text7 = string.Empty; | 
|  |  | 558 | +            string text8 = "0"; | 
|  |  | 559 | +            string text9 = "0"; | 
|  |  | 560 | +            string value = ""; | 
|  |  | 561 | +            string text10 = ""; | 
|  |  | 562 | +            string text11 = ""; | 
|  |  | 563 | +            string iSTRANSFER = "-1"; | 
|  |  | 564 | +            string text12 = ""; | 
|  |  | 565 | +            string text13 = ""; | 
|  |  | 566 | +            string shipper_phone = ""; | 
|  |  | 567 | +            string shipper_fax = ""; | 
|  |  | 568 | +            string text14 = ""; | 
|  |  | 569 | +            string text15 = ""; | 
|  |  | 570 | +            string text16 = ""; | 
|  |  | 571 | +            string consignee_fax = ""; | 
|  |  | 572 | +            string text17 = ""; | 
|  |  | 573 | +            string text18 = ""; | 
|  |  | 574 | +            try | 
|  |  | 575 | +            { | 
|  |  | 576 | +                string[] source = FWB.Split('\n'); | 
|  |  | 577 | +                source = source.Where((string p) => !string.IsNullOrEmpty(p.Trim())).ToArray(); | 
|  |  | 578 | +                if (source.Length > 0) | 
|  |  | 579 | +                { | 
|  |  | 580 | +                    for (int i = 0; i < source.Length; i++) | 
|  |  | 581 | +                    { | 
|  |  | 582 | +                        string text19 = source[i].Trim(); | 
|  |  | 583 | +                        if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2) && !string.IsNullOrEmpty(text3) && !string.IsNullOrEmpty(text5) && !string.IsNullOrEmpty(text7) && !string.IsNullOrEmpty(text8) && !string.IsNullOrEmpty(text10) && !string.IsNullOrEmpty(text11) && !string.IsNullOrEmpty(text12) && !string.IsNullOrEmpty(text14) && !string.IsNullOrEmpty(text17) && !string.IsNullOrEmpty(text18)) | 
|  |  | 584 | +                        { | 
|  |  | 585 | +                            break; | 
|  |  | 586 | +                        } | 
|  |  | 587 | +                        if (!string.IsNullOrEmpty(text19)) | 
|  |  | 588 | +                        { | 
|  |  | 589 | +                            if (text19.Contains("FWB/") && string.IsNullOrEmpty(value)) | 
|  |  | 590 | +                            { | 
|  |  | 591 | +                                value = text19; | 
|  |  | 592 | +                            } | 
|  |  | 593 | +                            if (text19.Length > 12 && Regex.IsMatch(text19.Substring(0, 12), "^(\\d{3}-)?\\d{8}$")) | 
|  |  | 594 | +                            { | 
|  |  | 595 | +                                text = text19.Substring(0, 12); | 
|  |  | 596 | +                                if (text8 == "0" || text9 == "0") | 
|  |  | 597 | +                                { | 
|  |  | 598 | +                                    string text20 = text19.Split('/')[1]; | 
|  |  | 599 | +                                    text20 = text20.Substring(1, text20.Length - 1); | 
|  |  | 600 | +                                    if (text20.Contains("K")) | 
|  |  | 601 | +                                    { | 
|  |  | 602 | +                                        text8 = text20.Substring(0, text20.IndexOf("K")); | 
|  |  | 603 | +                                        text9 = text20.Substring(text20.IndexOf("K") + 1, text20.Length - text20.IndexOf("K") - 1); | 
|  |  | 604 | +                                        Regex regex = new Regex("[a-zA-Z]+"); | 
|  |  | 605 | +                                        Match match = regex.Match(text9); | 
|  |  | 606 | +                                        if (match.Success) | 
|  |  | 607 | +                                        { | 
|  |  | 608 | +                                            text9 = text9.Substring(0, text9.IndexOf(match.Value)); | 
|  |  | 609 | +                                        } | 
|  |  | 610 | +                                    } | 
|  |  | 611 | +                                    if (text20.Contains("L")) | 
|  |  | 612 | +                                    { | 
|  |  | 613 | +                                        text8 = text20.Substring(0, text20.IndexOf("L")); | 
|  |  | 614 | +                                        text9 = text20.Substring(text20.IndexOf("L") + 1, text20.Length - text20.IndexOf("L") - 1); | 
|  |  | 615 | +                                        Regex regex = new Regex("[a-zA-Z]+"); | 
|  |  | 616 | +                                        Match match = regex.Match(text9); | 
|  |  | 617 | +                                        if (match.Success) | 
|  |  | 618 | +                                        { | 
|  |  | 619 | +                                            text9 = text9.Substring(0, text9.IndexOf(match.Value)); | 
|  |  | 620 | +                                        } | 
|  |  | 621 | +                                    } | 
|  |  | 622 | +                                } | 
|  |  | 623 | +                            } | 
|  |  | 624 | +                            else | 
|  |  | 625 | +                            { | 
|  |  | 626 | +                                if (text19.Length > 2) | 
|  |  | 627 | +                                { | 
|  |  | 628 | +                                    if (text19.Substring(0, 3) == "SHP" && string.IsNullOrEmpty(text3) && string.IsNullOrEmpty(text4)) | 
|  |  | 629 | +                                    { | 
|  |  | 630 | +                                        text3 = source[i + 1].Trim().Substring(1); | 
|  |  | 631 | +                                        text4 = source[i + 2].Trim().Substring(1); | 
|  |  | 632 | +                                        string text21 = source[i + 4].Trim().Substring(1); | 
|  |  | 633 | +                                        if (!string.IsNullOrEmpty(text21) && text21.Length >= 2) | 
|  |  | 634 | +                                        { | 
|  |  | 635 | +                                            string[] array = text21.Split('/'); | 
|  |  | 636 | +                                            if (array[0].Length == 2) | 
|  |  | 637 | +                                            { | 
|  |  | 638 | +                                                text13 = array[0]; | 
|  |  | 639 | +                                            } | 
|  |  | 640 | +                                            if (array.Length >= 3) | 
|  |  | 641 | +                                            { | 
|  |  | 642 | +                                                if (array[2] == "TE") | 
|  |  | 643 | +                                                { | 
|  |  | 644 | +                                                    shipper_phone = array[3]; | 
|  |  | 645 | +                                                } | 
|  |  | 646 | +                                                if (array.Length >= 5 && array[4] == "FX") | 
|  |  | 647 | +                                                { | 
|  |  | 648 | +                                                    shipper_fax = array[5]; | 
|  |  | 649 | +                                                } | 
|  |  | 650 | +                                            } | 
|  |  | 651 | +                                        } | 
|  |  | 652 | +                                    } | 
|  |  | 653 | +                                    if (string.IsNullOrEmpty(text12) && text19.Contains("/SHP/T/")) | 
|  |  | 654 | +                                    { | 
|  |  | 655 | +                                        string[] array2 = text19.Split('/'); | 
|  |  | 656 | +                                        text12 = array2[array2.Length - 1]; | 
|  |  | 657 | +                                    } | 
|  |  | 658 | +                                    if (string.IsNullOrEmpty(text14) && text19.Contains("/CNE/T/")) | 
|  |  | 659 | +                                    { | 
|  |  | 660 | +                                        string[] array2 = text19.Split('/'); | 
|  |  | 661 | +                                        text14 = array2[array2.Length - 1]; | 
|  |  | 662 | +                                    } | 
|  |  | 663 | +                                    if (string.IsNullOrEmpty(text17) && (text19.Contains("/CNE/CP/") || text19.Contains("/CNE/ST/") || text19.Contains("/CNE/KC/"))) | 
|  |  | 664 | +                                    { | 
|  |  | 665 | +                                        string[] array2 = text19.Split('/'); | 
|  |  | 666 | +                                        text17 = array2[array2.Length - 1]; | 
|  |  | 667 | +                                    } | 
|  |  | 668 | +                                    if (string.IsNullOrEmpty(text18) && (text19.Contains("/CNE/CT/") || text19.Contains("/CNE/U/"))) | 
|  |  | 669 | +                                    { | 
|  |  | 670 | +                                        string[] array2 = text19.Split('/'); | 
|  |  | 671 | +                                        text18 = array2[array2.Length - 1]; | 
|  |  | 672 | +                                    } | 
|  |  | 673 | +                                } | 
|  |  | 674 | +                                if (text19.Length > 2 && text19.Substring(0, 3) == "CNE" && string.IsNullOrEmpty(text5) && string.IsNullOrEmpty(text6)) | 
|  |  | 675 | +                                { | 
|  |  | 676 | +                                    text5 = source[i + 1].Trim().Substring(1); | 
|  |  | 677 | +                                    text6 = source[i + 2].Trim().Substring(1); | 
|  |  | 678 | +                                    string text21 = source[i + 4].Trim().Substring(1); | 
|  |  | 679 | +                                    if (!string.IsNullOrEmpty(text21) && text21.Length >= 2) | 
|  |  | 680 | +                                    { | 
|  |  | 681 | +                                        string[] array = text21.Split('/'); | 
|  |  | 682 | +                                        if (array[0].Length == 2) | 
|  |  | 683 | +                                        { | 
|  |  | 684 | +                                            text15 = array[0]; | 
|  |  | 685 | +                                        } | 
|  |  | 686 | +                                        if (array.Length >= 3) | 
|  |  | 687 | +                                        { | 
|  |  | 688 | +                                            if (array[2] == "TE") | 
|  |  | 689 | +                                            { | 
|  |  | 690 | +                                                text16 = array[3]; | 
|  |  | 691 | +                                            } | 
|  |  | 692 | +                                            if (array.Length >= 5 && array[4] == "FX") | 
|  |  | 693 | +                                            { | 
|  |  | 694 | +                                                consignee_fax = array[5]; | 
|  |  | 695 | +                                            } | 
|  |  | 696 | +                                        } | 
|  |  | 697 | +                                    } | 
|  |  | 698 | +                                } | 
|  |  | 699 | +                                else | 
|  |  | 700 | +                                { | 
|  |  | 701 | +                                    if (text19.Length > 3) | 
|  |  | 702 | +                                    { | 
|  |  | 703 | +                                        if (text19.Substring(0, 3) == "RTG") | 
|  |  | 704 | +                                        { | 
|  |  | 705 | +                                            string[] array3 = text19.Split('/'); | 
|  |  | 706 | +                                            if (array3 != null) | 
|  |  | 707 | +                                            { | 
|  |  | 708 | +                                                if (array3.Length == 4) | 
|  |  | 709 | +                                                { | 
|  |  | 710 | +                                                    if (!string.IsNullOrEmpty(array3[1]) && array3[1].Length > 3) | 
|  |  | 711 | +                                                    { | 
|  |  | 712 | +                                                        text2 = array3[1].Substring(0, 3); | 
|  |  | 713 | +                                                        cARRIER = array3[1].Substring(3, array3[1].Length - 3); | 
|  |  | 714 | +                                                    } | 
|  |  | 715 | +                                                    if (!string.IsNullOrEmpty(array3[2]) && array3[2].Length > 3) | 
|  |  | 716 | +                                                    { | 
|  |  | 717 | +                                                        aRRIVALSTATION = array3[2].Substring(0, 3); | 
|  |  | 718 | +                                                        cARRIER2 = array3[2].Substring(3, array3[2].Length - 3); | 
|  |  | 719 | +                                                    } | 
|  |  | 720 | +                                                    if (!string.IsNullOrEmpty(array3[3]) && array3[3].Length > 3) | 
|  |  | 721 | +                                                    { | 
|  |  | 722 | +                                                        aRRIVALSTATION2 = array3[3].Substring(0, 3); | 
|  |  | 723 | +                                                        cARRIER3 = array3[3].Substring(3, array3[3].Length - 3); | 
|  |  | 724 | +                                                    } | 
|  |  | 725 | +                                                } | 
|  |  | 726 | +                                                if (array3.Length == 3) | 
|  |  | 727 | +                                                { | 
|  |  | 728 | +                                                    if (!string.IsNullOrEmpty(array3[1]) && array3[1].Length > 3) | 
|  |  | 729 | +                                                    { | 
|  |  | 730 | +                                                        text2 = array3[1].Substring(0, 3); | 
|  |  | 731 | +                                                        cARRIER = array3[1].Substring(3, array3[1].Length - 3); | 
|  |  | 732 | +                                                    } | 
|  |  | 733 | +                                                    if (!string.IsNullOrEmpty(array3[2]) && array3[2].Length > 3) | 
|  |  | 734 | +                                                    { | 
|  |  | 735 | +                                                        aRRIVALSTATION = array3[2].Substring(0, 3); | 
|  |  | 736 | +                                                        cARRIER2 = array3[2].Substring(3, array3[2].Length - 3); | 
|  |  | 737 | +                                                    } | 
|  |  | 738 | +                                                } | 
|  |  | 739 | +                                                if (array3.Length == 2 && !string.IsNullOrEmpty(array3[1]) && array3[1].Length > 3) | 
|  |  | 740 | +                                                { | 
|  |  | 741 | +                                                    text2 = array3[1].Substring(0, 3); | 
|  |  | 742 | +                                                    cARRIER = array3[1].Substring(3, array3[1].Length - 3); | 
|  |  | 743 | +                                                } | 
|  |  | 744 | +                                            } | 
|  |  | 745 | +                                        } | 
|  |  | 746 | +                                        if (text19.Substring(0, 3) == "CVD") | 
|  |  | 747 | +                                        { | 
|  |  | 748 | +                                            string[] array3 = text19.Split('/'); | 
|  |  | 749 | +                                            if (array3 != null) | 
|  |  | 750 | +                                            { | 
|  |  | 751 | +                                                text7 = array3[3]; | 
|  |  | 752 | +                                            } | 
|  |  | 753 | +                                        } | 
|  |  | 754 | +                                    } | 
|  |  | 755 | +                                    if (text19.Contains("/NG/") && string.IsNullOrEmpty(text10) && text19.Substring(0, 4) == "/NG/") | 
|  |  | 756 | +                                    { | 
|  |  | 757 | +                                        text10 = text19.Replace("/NG/", ""); | 
|  |  | 758 | +                                    } | 
|  |  | 759 | +                                    else if (text19.Contains("/NC/") && string.IsNullOrEmpty(text10) && text19.Substring(0, 4) == "/NC/") | 
|  |  | 760 | +                                    { | 
|  |  | 761 | +                                        text10 = text19.Replace("/NC/", ""); | 
|  |  | 762 | +                                    } | 
|  |  | 763 | +                                    else if (text19.Contains("SPH/") && string.IsNullOrEmpty(text11)) | 
|  |  | 764 | +                                    { | 
|  |  | 765 | +                                        text11 = text19.Replace("SPH/", ""); | 
|  |  | 766 | +                                    } | 
|  |  | 767 | +                                } | 
|  |  | 768 | +                            } | 
|  |  | 769 | +                        } | 
|  |  | 770 | +                    } | 
|  |  | 771 | +                    if (text7.Contains("C")) | 
|  |  | 772 | +                    { | 
|  |  | 773 | +                        text7 = "CC"; | 
|  |  | 774 | +                    } | 
|  |  | 775 | +                    if (string.IsNullOrEmpty(text7)) | 
|  |  | 776 | +                    { | 
|  |  | 777 | +                        text7 = "PP"; | 
|  |  | 778 | +                    } | 
|  |  | 779 | +                    if (!string.IsNullOrEmpty(text12) && !string.IsNullOrEmpty(text13)) | 
|  |  | 780 | +                    { | 
|  |  | 781 | +                        bool flag = false; | 
|  |  | 782 | +                        List<t_bas_enterprise> list = CustomsCargoSystem.Data.OriginManifestMaster.get_t_bas_enterprise(connectionString, text13).ToList(); | 
|  |  | 783 | +                        string text22 = ""; | 
|  |  | 784 | +                        if (list.Count > 0) | 
|  |  | 785 | +                        { | 
|  |  | 786 | +                            foreach (t_bas_enterprise item in list) | 
|  |  | 787 | +                            { | 
|  |  | 788 | +                                if (text12.Contains(item.enterprise_code)) | 
|  |  | 789 | +                                { | 
|  |  | 790 | +                                    flag = true; | 
|  |  | 791 | +                                    text22 = item.enterprise_code; | 
|  |  | 792 | +                                } | 
|  |  | 793 | +                            } | 
|  |  | 794 | +                        } | 
|  |  | 795 | +                        if (flag) | 
|  |  | 796 | +                        { | 
|  |  | 797 | +                            string value2 = "+"; | 
|  |  | 798 | +                            text12 = text12.Insert(text12.LastIndexOf(text22) + text22.Length, value2); | 
|  |  | 799 | +                        } | 
|  |  | 800 | +                    } | 
|  |  | 801 | +                    if (!string.IsNullOrEmpty(text14) && !string.IsNullOrEmpty(text15)) | 
|  |  | 802 | +                    { | 
|  |  | 803 | +                        bool flag = false; | 
|  |  | 804 | +                        List<t_bas_enterprise> list = CustomsCargoSystem.Data.OriginManifestMaster.get_t_bas_enterprise(connectionString, text15).ToList(); | 
|  |  | 805 | +                        string text22 = ""; | 
|  |  | 806 | +                        if (list.Count > 0) | 
|  |  | 807 | +                        { | 
|  |  | 808 | +                            foreach (t_bas_enterprise item2 in list) | 
|  |  | 809 | +                            { | 
|  |  | 810 | +                                if (text14.Contains(item2.enterprise_code)) | 
|  |  | 811 | +                                { | 
|  |  | 812 | +                                    flag = true; | 
|  |  | 813 | +                                    text22 = item2.enterprise_code; | 
|  |  | 814 | +                                } | 
|  |  | 815 | +                            } | 
|  |  | 816 | +                        } | 
|  |  | 817 | +                        if (flag) | 
|  |  | 818 | +                        { | 
|  |  | 819 | +                            string value2 = "+"; | 
|  |  | 820 | +                            text14 = text14.Insert(text14.LastIndexOf(text22) + text22.Length, value2); | 
|  |  | 821 | +                        } | 
|  |  | 822 | +                    } | 
|  |  | 823 | +                    fwb_info fwb_info = new fwb_info(); | 
|  |  | 824 | +                    fwb_info.AUTOID = Guid.NewGuid().ToString(); | 
|  |  | 825 | +                    fwb_info.WAYBILLNOMASTER = text; | 
|  |  | 826 | +                    fwb_info.TOTALPIECE = text8; | 
|  |  | 827 | +                    fwb_info.TOTALWEIGHT = text9; | 
|  |  | 828 | +                    fwb_info.CARRIER1 = cARRIER; | 
|  |  | 829 | +                    fwb_info.ARRIVALSTATION1 = text2; | 
|  |  | 830 | +                    fwb_info.CARRIER2 = cARRIER2; | 
|  |  | 831 | +                    fwb_info.ARRIVALSTATION2 = aRRIVALSTATION; | 
|  |  | 832 | +                    fwb_info.CARRIER3 = cARRIER3; | 
|  |  | 833 | +                    fwb_info.ARRIVALSTATION3 = aRRIVALSTATION2; | 
|  |  | 834 | +                    fwb_info.SHIPPERNAME = text3; | 
|  |  | 835 | +                    fwb_info.SHIPPERADDRESS = text4; | 
|  |  | 836 | +                    fwb_info.CONSIGNEENAME = text5; | 
|  |  | 837 | +                    fwb_info.CONSIGNEEADDRESS = text6; | 
|  |  | 838 | +                    fwb_info.PAYMODE = text7; | 
|  |  | 839 | +                    fwb_info.CREATEDATE = DateTime.Now; | 
|  |  | 840 | +                    fwb_info.PRODUCTNAME = text10; | 
|  |  | 841 | +                    fwb_info.SPECIALGOODSCODE = text11; | 
|  |  | 842 | +                    fwb_info.ISTRANSFER = iSTRANSFER; | 
|  |  | 843 | +                    fwb_info.shipper_code = text12; | 
|  |  | 844 | +                    fwb_info.shipper_countrycode = text13; | 
|  |  | 845 | +                    fwb_info.shipper_phone = shipper_phone; | 
|  |  | 846 | +                    fwb_info.shipper_fax = shipper_fax; | 
|  |  | 847 | +                    if (string.IsNullOrEmpty(text18) && !string.IsNullOrEmpty(text16)) | 
|  |  | 848 | +                    { | 
|  |  | 849 | +                        text18 = text16; | 
|  |  | 850 | +                    } | 
|  |  | 851 | +                    else if (string.IsNullOrEmpty(text16) && !string.IsNullOrEmpty(text18)) | 
|  |  | 852 | +                    { | 
|  |  | 853 | +                        text16 = text18; | 
|  |  | 854 | +                    } | 
|  |  | 855 | +                    fwb_info.consignee_code = text14; | 
|  |  | 856 | +                    fwb_info.consignee_countrycode = text15; | 
|  |  | 857 | +                    fwb_info.consignee_phone = text16; | 
|  |  | 858 | +                    fwb_info.consignee_fax = consignee_fax; | 
|  |  | 859 | +                    fwb_info.specific_consigneename = text17; | 
|  |  | 860 | +                    fwb_info.specific_consignee_phone = text18; | 
|  |  | 861 | +                    if (!string.IsNullOrEmpty(fwb_info.WAYBILLNOMASTER) && CustomsCargoSystem.Data.OriginManifestMaster.InsertFwbInfo(connectionString, fwb_info) > 0) | 
|  |  | 862 | +                    { | 
|  |  | 863 | +                        IEnumerable<CustomsCargoSystem.Model.OriginManifestMaster> originManifestMasterFromWayBillNoMaster = CustomsCargoSystem.Data.OriginManifestMaster.GetOriginManifestMasterFromWayBillNoMaster(connectionString, fwb_info.WAYBILLNOMASTER); | 
|  |  | 864 | +                        if (originManifestMasterFromWayBillNoMaster.Count() > 0) | 
|  |  | 865 | +                        { | 
|  |  | 866 | +                            CustomsCargoSystem.Data.OriginManifestMaster.UpdateFWB(connectionString, fwb_info); | 
|  |  | 867 | +                        } | 
|  |  | 868 | +                    } | 
|  |  | 869 | +                } | 
|  |  | 870 | +            } | 
|  |  | 871 | +            catch (Exception ex) | 
|  |  | 872 | +            { | 
|  |  | 873 | +                Log.WriteLog("1fwb_error", ex.ToString() + "\r\n\r\n" + FWB); | 
|  |  | 874 | +            } | 
|  |  | 875 | +            return result; | 
|  |  | 876 | +        } | 
|  |  | 877 | + | 
|  |  | 878 | +        public static bool ProcessXmlDocumentFHL(string FHL) | 
|  |  | 879 | +        { | 
|  |  | 880 | +            bool result = false; | 
|  |  | 881 | +            string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString; | 
|  |  | 882 | +            string wayBillNoMaster = ""; | 
|  |  | 883 | +            string wayBillNoSecondary = ""; | 
|  |  | 884 | +            string text = "0"; | 
|  |  | 885 | +            string text2 = "0"; | 
|  |  | 886 | +            string specialGoodsCode = ""; | 
|  |  | 887 | +            string productName = ""; | 
|  |  | 888 | +            string shipperName = ""; | 
|  |  | 889 | +            string shipperAddress = ""; | 
|  |  | 890 | +            string consigneeName = ""; | 
|  |  | 891 | +            string consigneeAddress = ""; | 
|  |  | 892 | +            string value = ""; | 
|  |  | 893 | +            string text3 = ""; | 
|  |  | 894 | +            string cUSTOMSSTATUS = "-1"; | 
|  |  | 895 | +            string originatingstation_bill = ""; | 
|  |  | 896 | +            string destinationstation_bill = ""; | 
|  |  | 897 | +            string text4 = ""; | 
|  |  | 898 | +            string text5 = ""; | 
|  |  | 899 | +            string shipper_phone = ""; | 
|  |  | 900 | +            string shipper_fax = ""; | 
|  |  | 901 | +            string text6 = ""; | 
|  |  | 902 | +            string text7 = ""; | 
|  |  | 903 | +            string text8 = ""; | 
|  |  | 904 | +            string consignee_fax = ""; | 
|  |  | 905 | +            string text9 = ""; | 
|  |  | 906 | +            string text10 = ""; | 
|  |  | 907 | +            try | 
|  |  | 908 | +            { | 
|  |  | 909 | +                string text11 = FHL.Trim(); | 
|  |  | 910 | +                string[] source = (from x in text11.Split(Environment.NewLine.ToCharArray()) | 
|  |  | 911 | +                                   where x.Length > 0 | 
|  |  | 912 | +                                   select x).ToArray(); | 
|  |  | 913 | +                source = source.Where((string p) => !string.IsNullOrEmpty(p.Trim())).ToArray(); | 
|  |  | 914 | +                if (source.Length > 0) | 
|  |  | 915 | +                { | 
|  |  | 916 | +                    for (int i = 0; i < source.Length; i++) | 
|  |  | 917 | +                    { | 
|  |  | 918 | +                        if (!string.IsNullOrEmpty(source[i])) | 
|  |  | 919 | +                        { | 
|  |  | 920 | +                            if (source[i].ToString().Contains("FHL/") && string.IsNullOrEmpty(value)) | 
|  |  | 921 | +                            { | 
|  |  | 922 | +                                value = source[i].ToString(); | 
|  |  | 923 | +                            } | 
|  |  | 924 | +                            string text12 = source[i]; | 
|  |  | 925 | +                            if (string.IsNullOrEmpty(text4) && text12.Contains("/SHP/T/")) | 
|  |  | 926 | +                            { | 
|  |  | 927 | +                                string[] array = text12.Split('/'); | 
|  |  | 928 | +                                text4 = array[array.Length - 1]; | 
|  |  | 929 | +                            } | 
|  |  | 930 | +                            if (string.IsNullOrEmpty(text6) && text12.Contains("/CNE/T/")) | 
|  |  | 931 | +                            { | 
|  |  | 932 | +                                string[] array = text12.Split('/'); | 
|  |  | 933 | +                                text6 = array[array.Length - 1]; | 
|  |  | 934 | +                            } | 
|  |  | 935 | +                            if (string.IsNullOrEmpty(text9) && (text12.Contains("/CNE/CP/") || text12.Contains("/CNE/ST/") || text12.Contains("/CNE/KC/"))) | 
|  |  | 936 | +                            { | 
|  |  | 937 | +                                string[] array = text12.Split('/'); | 
|  |  | 938 | +                                text9 = array[array.Length - 1]; | 
|  |  | 939 | +                            } | 
|  |  | 940 | +                            if (string.IsNullOrEmpty(text10) && (text12.Contains("/CNE/CT/") || text12.Contains("/CNE/U/"))) | 
|  |  | 941 | +                            { | 
|  |  | 942 | +                                string[] array = text12.Split('/'); | 
|  |  | 943 | +                                text10 = array[array.Length - 1]; | 
|  |  | 944 | +                            } | 
|  |  | 945 | +                            string[] source2 = new string[6] | 
|  |  | 946 | +                            { | 
|  |  | 947 | +                                "2", | 
|  |  | 948 | +                                "3", | 
|  |  | 949 | +                                "4", | 
|  |  | 950 | +                                "02", | 
|  |  | 951 | +                                "03", | 
|  |  | 952 | +                                "04" | 
|  |  | 953 | +                            }; | 
|  |  | 954 | +                            string[][] source3 = source.Select((string x) => (from y in x.Split('/') select y.Trim(' ')).ToArray()).ToArray(); | 
|  |  | 955 | +                            string[] array2 = source3.First((string[] y) => y[0] == "FHL"); | 
|  |  | 956 | +                            string[] array3 = (from x in source[i].Split('/') select x.Trim(' ')).ToArray(); | 
|  |  | 957 | +                            if (array3[0] == "MBI") | 
|  |  | 958 | +                            { | 
|  |  | 959 | +                                wayBillNoMaster = array3[1].Substring(0, 12); | 
|  |  | 960 | +                            } | 
|  |  | 961 | +                            else if (array3[0] == "HBS") | 
|  |  | 962 | +                            { | 
|  |  | 963 | +                                wayBillNoSecondary = array3[1]; | 
|  |  | 964 | +                                text = array3[3]; | 
|  |  | 965 | +                                text2 = array3[4].Substring(1); | 
|  |  | 966 | +                                if (array3.Length >= 6) | 
|  |  | 967 | +                                { | 
|  |  | 968 | +                                    productName = array3[6]; | 
|  |  | 969 | +                                } | 
|  |  | 970 | +                                if (array3.Length <= 6) | 
|  |  | 971 | +                                { | 
|  |  | 972 | +                                } | 
|  |  | 973 | +                            } | 
|  |  | 974 | +                            else if (array3[0] == "SHP") | 
|  |  | 975 | +                            { | 
|  |  | 976 | +                                if (array2 != null && source2.Contains(array2[1]) && array3.Length > 1) | 
|  |  | 977 | +                                { | 
|  |  | 978 | +                                    shipperName = array3[1]; | 
|  |  | 979 | +                                    string[] array4 = (from x in source[i + 1].Split('/') | 
|  |  | 980 | +                                                       select x.Trim(' ')).ToArray(); | 
|  |  | 981 | +                                    shipperAddress = array4[1]; | 
|  |  | 982 | +                                    string text13 = source[i + 3].Trim().Substring(1); | 
|  |  | 983 | +                                    if (!string.IsNullOrEmpty(text13) && text13.Length >= 2) | 
|  |  | 984 | +                                    { | 
|  |  | 985 | +                                        string[] array5 = text13.Split('/'); | 
|  |  | 986 | +                                        if (array5 != null && array5[0].Length == 2) | 
|  |  | 987 | +                                        { | 
|  |  | 988 | +                                            text5 = array5[0]; | 
|  |  | 989 | +                                        } | 
|  |  | 990 | +                                        if (array5.Length >= 3) | 
|  |  | 991 | +                                        { | 
|  |  | 992 | +                                            if (array5[2] == "TE") | 
|  |  | 993 | +                                            { | 
|  |  | 994 | +                                                shipper_phone = array5[3]; | 
|  |  | 995 | +                                            } | 
|  |  | 996 | +                                            if (array5[2] == "FX") | 
|  |  | 997 | +                                            { | 
|  |  | 998 | +                                                shipper_fax = array5[3]; | 
|  |  | 999 | +                                            } | 
|  |  | 1000 | +                                        } | 
|  |  | 1001 | +                                    } | 
|  |  | 1002 | +                                } | 
|  |  | 1003 | +                                else | 
|  |  | 1004 | +                                { | 
|  |  | 1005 | +                                    string[] array6 = (from x in source[i + 1].Split('/') | 
|  |  | 1006 | +                                                       select x.Trim(' ')).ToArray(); | 
|  |  | 1007 | +                                    shipperName = array6[1]; | 
|  |  | 1008 | +                                    string[] array4 = (from x in source[i + 2].Split('/') | 
|  |  | 1009 | +                                                       select x.Trim(' ')).ToArray(); | 
|  |  | 1010 | +                                    shipperAddress = array4[1]; | 
|  |  | 1011 | +                                    string text13 = source[i + 4].Trim().Substring(1); | 
|  |  | 1012 | +                                    if (!string.IsNullOrEmpty(text13) && text13.Length >= 3) | 
|  |  | 1013 | +                                    { | 
|  |  | 1014 | +                                        string[] array5 = text13.Split('/'); | 
|  |  | 1015 | +                                        if (array5 != null && array5[0].Length == 2) | 
|  |  | 1016 | +                                        { | 
|  |  | 1017 | +                                            text5 = array5[0]; | 
|  |  | 1018 | +                                        } | 
|  |  | 1019 | +                                        if (array5.Length >= 3) | 
|  |  | 1020 | +                                        { | 
|  |  | 1021 | +                                            if (array5[2] == "TE") | 
|  |  | 1022 | +                                            { | 
|  |  | 1023 | +                                                shipper_phone = array5[3]; | 
|  |  | 1024 | +                                            } | 
|  |  | 1025 | +                                            if (array5[2] == "FX") | 
|  |  | 1026 | +                                            { | 
|  |  | 1027 | +                                                shipper_fax = array5[3]; | 
|  |  | 1028 | +                                            } | 
|  |  | 1029 | +                                        } | 
|  |  | 1030 | +                                    } | 
|  |  | 1031 | +                                } | 
|  |  | 1032 | +                            } | 
|  |  | 1033 | +                            else if (array3[0] == "CNE") | 
|  |  | 1034 | +                            { | 
|  |  | 1035 | +                                if (array2 != null && source2.Contains(array2[1]) && array3.Length > 1) | 
|  |  | 1036 | +                                { | 
|  |  | 1037 | +                                    consigneeName = array3[1]; | 
|  |  | 1038 | +                                    string[] array4 = (from x in source[i + 1].Split('/') select x.Trim(' ')).ToArray(); | 
|  |  | 1039 | +                                    consigneeAddress = array4[1]; | 
|  |  | 1040 | +                                    string text13 = source[i + 3].Trim().Substring(1); | 
|  |  | 1041 | +                                    if (!string.IsNullOrEmpty(text13) && text13.Length >= 2) | 
|  |  | 1042 | +                                    { | 
|  |  | 1043 | +                                        string[] array5 = text13.Split('/'); | 
|  |  | 1044 | +                                        if (array5 != null && array5[0].Length == 2) | 
|  |  | 1045 | +                                        { | 
|  |  | 1046 | +                                            text7 = array5[0]; | 
|  |  | 1047 | +                                        } | 
|  |  | 1048 | +                                        if (array5.Length >= 3) | 
|  |  | 1049 | +                                        { | 
|  |  | 1050 | +                                            if (array5[2] == "TE") | 
|  |  | 1051 | +                                            { | 
|  |  | 1052 | +                                                text8 = array5[3]; | 
|  |  | 1053 | +                                            } | 
|  |  | 1054 | +                                            if (array5[2] == "FX") | 
|  |  | 1055 | +                                            { | 
|  |  | 1056 | +                                                consignee_fax = array5[3]; | 
|  |  | 1057 | +                                            } | 
|  |  | 1058 | +                                        } | 
|  |  | 1059 | +                                    } | 
|  |  | 1060 | +                                } | 
|  |  | 1061 | +                                else | 
|  |  | 1062 | +                                { | 
|  |  | 1063 | +                                    if (i + 1 < source.Length) | 
|  |  | 1064 | +                                    { | 
|  |  | 1065 | +                                        string[] array6 = (from x in source[i + 1].Split('/') | 
|  |  | 1066 | +                                                           select x.Trim(' ')).ToArray(); | 
|  |  | 1067 | +                                        consigneeName = array6[1]; | 
|  |  | 1068 | +                                    } | 
|  |  | 1069 | +                                    if (i + 2 < source.Length) | 
|  |  | 1070 | +                                    { | 
|  |  | 1071 | +                                        string[] array4 = (from x in source[i + 2].Split('/') select x.Trim(' ')).ToArray(); | 
|  |  | 1072 | +                                        consigneeAddress = array4[1]; | 
|  |  | 1073 | +                                    } | 
|  |  | 1074 | +                                    string text13 = source[(i + 3 >= source.Length) ? (source.Length - 1) : (i + 3)].Trim().Substring(1); | 
|  |  | 1075 | +                                    if (!string.IsNullOrEmpty(text13) && text13.Length >= 3) | 
|  |  | 1076 | +                                    { | 
|  |  | 1077 | +                                        string[] array5 = text13.Split('/'); | 
|  |  | 1078 | +                                        if (array5 != null && array5[0].Length == 2) | 
|  |  | 1079 | +                                        { | 
|  |  | 1080 | +                                            text7 = array5[0]; | 
|  |  | 1081 | +                                        } | 
|  |  | 1082 | +                                        if (array5.Length >= 3) | 
|  |  | 1083 | +                                        { | 
|  |  | 1084 | +                                            if (array5[2] == "TE") | 
|  |  | 1085 | +                                            { | 
|  |  | 1086 | +                                                text8 = array5[3]; | 
|  |  | 1087 | +                                            } | 
|  |  | 1088 | +                                            if (array5[2] == "FX") | 
|  |  | 1089 | +                                            { | 
|  |  | 1090 | +                                                consignee_fax = array5[3]; | 
|  |  | 1091 | +                                            } | 
|  |  | 1092 | +                                        } | 
|  |  | 1093 | +                                    } | 
|  |  | 1094 | +                                } | 
|  |  | 1095 | +                            } | 
|  |  | 1096 | +                            else if (array3[0] == "CVD" && string.IsNullOrEmpty(text3)) | 
|  |  | 1097 | +                            { | 
|  |  | 1098 | +                                text3 = source[i].Split('/')[2]; | 
|  |  | 1099 | +                            } | 
|  |  | 1100 | +                        } | 
|  |  | 1101 | +                    } | 
|  |  | 1102 | +                    if (text3.Contains("C")) | 
|  |  | 1103 | +                    { | 
|  |  | 1104 | +                        text3 = "CC"; | 
|  |  | 1105 | +                    } | 
|  |  | 1106 | +                    if (string.IsNullOrEmpty(text3)) | 
|  |  | 1107 | +                    { | 
|  |  | 1108 | +                        text3 = "PP"; | 
|  |  | 1109 | +                    } | 
|  |  | 1110 | +                    if (!string.IsNullOrEmpty(text4) && !string.IsNullOrEmpty(text5)) | 
|  |  | 1111 | +                    { | 
|  |  | 1112 | +                        bool flag = false; | 
|  |  | 1113 | +                        List<t_bas_enterprise> list = CustomsCargoSystem.Data.OriginManifestMaster.get_t_bas_enterprise(connectionString, text5).ToList(); | 
|  |  | 1114 | +                        string text14 = ""; | 
|  |  | 1115 | +                        if (list.Count > 0) | 
|  |  | 1116 | +                        { | 
|  |  | 1117 | +                            foreach (t_bas_enterprise item in list) | 
|  |  | 1118 | +                            { | 
|  |  | 1119 | +                                if (text4.Contains(item.enterprise_code)) | 
|  |  | 1120 | +                                { | 
|  |  | 1121 | +                                    flag = true; | 
|  |  | 1122 | +                                    text14 = item.enterprise_code; | 
|  |  | 1123 | +                                } | 
|  |  | 1124 | +                            } | 
|  |  | 1125 | +                        } | 
|  |  | 1126 | +                        if (flag) | 
|  |  | 1127 | +                        { | 
|  |  | 1128 | +                            string value2 = "+"; | 
|  |  | 1129 | +                            text4 = text4.Insert(text4.LastIndexOf(text14) + text14.Length, value2); | 
|  |  | 1130 | +                        } | 
|  |  | 1131 | +                    } | 
|  |  | 1132 | +                    if (!string.IsNullOrEmpty(text6) && !string.IsNullOrEmpty(text7)) | 
|  |  | 1133 | +                    { | 
|  |  | 1134 | +                        bool flag = false; | 
|  |  | 1135 | +                        List<t_bas_enterprise> list = CustomsCargoSystem.Data.OriginManifestMaster.get_t_bas_enterprise(connectionString, text7).ToList(); | 
|  |  | 1136 | +                        string text14 = ""; | 
|  |  | 1137 | +                        if (list.Count > 0) | 
|  |  | 1138 | +                        { | 
|  |  | 1139 | +                            foreach (t_bas_enterprise item2 in list) | 
|  |  | 1140 | +                            { | 
|  |  | 1141 | +                                if (text6.Contains(item2.enterprise_code)) | 
|  |  | 1142 | +                                { | 
|  |  | 1143 | +                                    flag = true; | 
|  |  | 1144 | +                                    text14 = item2.enterprise_code; | 
|  |  | 1145 | +                                } | 
|  |  | 1146 | +                            } | 
|  |  | 1147 | +                        } | 
|  |  | 1148 | +                        if (flag) | 
|  |  | 1149 | +                        { | 
|  |  | 1150 | +                            string value2 = "+"; | 
|  |  | 1151 | +                            text6 = text6.Insert(text6.LastIndexOf(text14) + text14.Length, value2); | 
|  |  | 1152 | +                        } | 
|  |  | 1153 | +                    } | 
|  |  | 1154 | +                    if (string.IsNullOrEmpty(text10) && !string.IsNullOrEmpty(text8)) | 
|  |  | 1155 | +                    { | 
|  |  | 1156 | +                        text10 = text8; | 
|  |  | 1157 | +                    } | 
|  |  | 1158 | +                    else if (string.IsNullOrEmpty(text8) && !string.IsNullOrEmpty(text10)) | 
|  |  | 1159 | +                    { | 
|  |  | 1160 | +                        text8 = text10; | 
|  |  | 1161 | +                    } | 
|  |  | 1162 | +                    IEnumerable<CustomsCargoSystem.Model.OriginManifestMaster> originManifestMasterFromWayBillNoMaster = CustomsCargoSystem.Data.OriginManifestMaster.GetOriginManifestMasterFromWayBillNoMaster(connectionString, wayBillNoMaster); | 
|  |  | 1163 | +                    if (originManifestMasterFromWayBillNoMaster.Count() > 0) | 
|  |  | 1164 | +                    { | 
|  |  | 1165 | +                        CustomsCargoSystem.Model.OriginManifestMaster originManifestMaster = originManifestMasterFromWayBillNoMaster.ToList().FirstOrDefault(); | 
|  |  | 1166 | +                        if (originManifestMaster != null) | 
|  |  | 1167 | +                        { | 
|  |  | 1168 | +                            IEnumerable<CustomsCargoSystem.Model.OriginManifestSecondary> originManifestSecondaryTureOrFalse = CustomsCargoSystem.Data.OriginManifestMaster.GetOriginManifestSecondaryTureOrFalse(connectionString, wayBillNoMaster, wayBillNoSecondary); | 
|  |  | 1169 | +                            string customsCode = originManifestMaster.CustomsCode; | 
|  |  | 1170 | +                            cUSTOMSSTATUS = originManifestMaster.CustomsStatus; | 
|  |  | 1171 | +                            CustomsCargoSystem.Model.OriginManifestSecondary originManifestSecondary = new CustomsCargoSystem.Model.OriginManifestSecondary(); | 
|  |  | 1172 | +                            originManifestSecondary.AutoID = Guid.NewGuid().ToString(); | 
|  |  | 1173 | +                            originManifestSecondary.WayBillNoMaster = wayBillNoMaster; | 
|  |  | 1174 | +                            originManifestSecondary.WayBillNoSecondary = wayBillNoSecondary; | 
|  |  | 1175 | +                            originManifestSecondary.Weight = text2; | 
|  |  | 1176 | +                            originManifestSecondary.Piece = text; | 
|  |  | 1177 | +                            originManifestSecondary.ManifestPiece = text; | 
|  |  | 1178 | +                            originManifestSecondary.ManifestWeight = text2; | 
|  |  | 1179 | +                            originManifestSecondary.ProductName = productName; | 
|  |  | 1180 | +                            originManifestSecondary.PayMode = text3; | 
|  |  | 1181 | +                            originManifestSecondary.SpecialGoodsCode = specialGoodsCode; | 
|  |  | 1182 | +                            originManifestSecondary.CustomsCode = customsCode; | 
|  |  | 1183 | +                            originManifestSecondary.ShipperName = shipperName; | 
|  |  | 1184 | +                            originManifestSecondary.ShipperAddress = shipperAddress; | 
|  |  | 1185 | +                            originManifestSecondary.ConsigneeName = consigneeName; | 
|  |  | 1186 | +                            originManifestSecondary.ConsigneeAddress = consigneeAddress; | 
|  |  | 1187 | +                            originManifestSecondary.CreateDate = DateTime.Now; | 
|  |  | 1188 | +                            originManifestSecondary.ORIGINMANIFESTMASTERAUTOID = originManifestMaster.AutoID; | 
|  |  | 1189 | +                            originManifestSecondary.CUSTOMSSTATUS = cUSTOMSSTATUS; | 
|  |  | 1190 | +                            originManifestSecondary.STATUS = "01"; | 
|  |  | 1191 | +                            originManifestSecondary.originatingstation_bill = originatingstation_bill; | 
|  |  | 1192 | +                            originManifestSecondary.destinationstation_bill = destinationstation_bill; | 
|  |  | 1193 | +                            originManifestSecondary.shipper_code = text4; | 
|  |  | 1194 | +                            originManifestSecondary.shipper_countrycode = text5; | 
|  |  | 1195 | +                            originManifestSecondary.shipper_phone = shipper_phone; | 
|  |  | 1196 | +                            originManifestSecondary.shipper_fax = shipper_fax; | 
|  |  | 1197 | +                            originManifestSecondary.consignee_code = text6; | 
|  |  | 1198 | +                            originManifestSecondary.consignee_countrycode = text7; | 
|  |  | 1199 | +                            originManifestSecondary.consignee_phone = text8; | 
|  |  | 1200 | +                            originManifestSecondary.consignee_fax = consignee_fax; | 
|  |  | 1201 | +                            originManifestSecondary.specific_consigneename = text9; | 
|  |  | 1202 | +                            originManifestSecondary.specific_consignee_phone = text10; | 
|  |  | 1203 | +                            if (originManifestSecondaryTureOrFalse.Count() == 0) | 
|  |  | 1204 | +                            { | 
|  |  | 1205 | +                                if (CustomsCargoSystem.Data.OriginManifestMaster.InsertFHL(connectionString, originManifestSecondary) > 0) | 
|  |  | 1206 | +                                { | 
|  |  | 1207 | +                                    result = true; | 
|  |  | 1208 | +                                } | 
|  |  | 1209 | +                            } | 
|  |  | 1210 | +                            else if (originManifestSecondaryTureOrFalse.ToList().FirstOrDefault().STATUS == "01" || originManifestSecondaryTureOrFalse.ToList().FirstOrDefault().STATUS == "17") | 
|  |  | 1211 | +                            { | 
|  |  | 1212 | +                                originManifestSecondary.AutoID = originManifestSecondaryTureOrFalse.ToList().FirstOrDefault().AutoID; | 
|  |  | 1213 | +                                if (CustomsCargoSystem.Data.OriginManifestMaster.UpdateFHL(connectionString, originManifestSecondary) > 0) | 
|  |  | 1214 | +                                { | 
|  |  | 1215 | +                                    result = true; | 
|  |  | 1216 | +                                } | 
|  |  | 1217 | +                            } | 
|  |  | 1218 | +                            InitTallySecondary(originManifestSecondary); | 
|  |  | 1219 | +                        } | 
|  |  | 1220 | +                    } | 
|  |  | 1221 | +                    else | 
|  |  | 1222 | +                    { | 
|  |  | 1223 | +                        IEnumerable<CustomsCargoSystem.Model.OriginManifestSecondary> originManifestSecondaryTureOrFalse = CustomsCargoSystem.Data.OriginManifestMaster.GetOriginManifestSecondaryTureOrFalse(connectionString, wayBillNoMaster, wayBillNoSecondary); | 
|  |  | 1224 | +                        CustomsCargoSystem.Model.OriginManifestSecondary originManifestSecondary = new CustomsCargoSystem.Model.OriginManifestSecondary(); | 
|  |  | 1225 | +                        originManifestSecondary.AutoID = Guid.NewGuid().ToString(); | 
|  |  | 1226 | +                        originManifestSecondary.WayBillNoMaster = wayBillNoMaster; | 
|  |  | 1227 | +                        originManifestSecondary.WayBillNoSecondary = wayBillNoSecondary; | 
|  |  | 1228 | +                        originManifestSecondary.Weight = text2; | 
|  |  | 1229 | +                        originManifestSecondary.Piece = text; | 
|  |  | 1230 | +                        originManifestSecondary.ManifestPiece = text; | 
|  |  | 1231 | +                        originManifestSecondary.ManifestWeight = text2; | 
|  |  | 1232 | +                        originManifestSecondary.ProductName = productName; | 
|  |  | 1233 | +                        originManifestSecondary.PayMode = text3; | 
|  |  | 1234 | +                        originManifestSecondary.SpecialGoodsCode = specialGoodsCode; | 
|  |  | 1235 | +                        originManifestSecondary.CustomsCode = "4604"; | 
|  |  | 1236 | +                        originManifestSecondary.ShipperName = shipperName; | 
|  |  | 1237 | +                        originManifestSecondary.ShipperAddress = shipperAddress; | 
|  |  | 1238 | +                        originManifestSecondary.ConsigneeName = consigneeName; | 
|  |  | 1239 | +                        originManifestSecondary.ConsigneeAddress = consigneeAddress; | 
|  |  | 1240 | +                        originManifestSecondary.CreateDate = DateTime.Now; | 
|  |  | 1241 | +                        originManifestSecondary.ORIGINMANIFESTMASTERAUTOID = "0"; | 
|  |  | 1242 | +                        originManifestSecondary.CUSTOMSSTATUS = cUSTOMSSTATUS; | 
|  |  | 1243 | +                        originManifestSecondary.STATUS = "01"; | 
|  |  | 1244 | +                        originManifestSecondary.originatingstation_bill = originatingstation_bill; | 
|  |  | 1245 | +                        originManifestSecondary.destinationstation_bill = destinationstation_bill; | 
|  |  | 1246 | +                        originManifestSecondary.shipper_code = text4; | 
|  |  | 1247 | +                        originManifestSecondary.shipper_countrycode = text5; | 
|  |  | 1248 | +                        originManifestSecondary.shipper_phone = shipper_phone; | 
|  |  | 1249 | +                        originManifestSecondary.shipper_fax = shipper_fax; | 
|  |  | 1250 | +                        originManifestSecondary.consignee_code = text6; | 
|  |  | 1251 | +                        originManifestSecondary.consignee_countrycode = text7; | 
|  |  | 1252 | +                        originManifestSecondary.consignee_phone = text8; | 
|  |  | 1253 | +                        originManifestSecondary.consignee_fax = consignee_fax; | 
|  |  | 1254 | +                        originManifestSecondary.specific_consigneename = text9; | 
|  |  | 1255 | +                        originManifestSecondary.specific_consignee_phone = text10; | 
|  |  | 1256 | +                        if (originManifestSecondaryTureOrFalse.Count() == 0) | 
|  |  | 1257 | +                        { | 
|  |  | 1258 | +                            if (CustomsCargoSystem.Data.OriginManifestMaster.InsertFHL(connectionString, originManifestSecondary) > 0) | 
|  |  | 1259 | +                            { | 
|  |  | 1260 | +                                result = true; | 
|  |  | 1261 | +                            } | 
|  |  | 1262 | +                        } | 
|  |  | 1263 | +                        else if (originManifestSecondaryTureOrFalse.ToList().FirstOrDefault().STATUS == "01" || originManifestSecondaryTureOrFalse.ToList().FirstOrDefault().STATUS == "17") | 
|  |  | 1264 | +                        { | 
|  |  | 1265 | +                            originManifestSecondary.AutoID = originManifestSecondaryTureOrFalse.ToList().FirstOrDefault().AutoID; | 
|  |  | 1266 | +                            if (CustomsCargoSystem.Data.OriginManifestMaster.UpdateFHL(connectionString, originManifestSecondary) > 0) | 
|  |  | 1267 | +                            { | 
|  |  | 1268 | +                                result = true; | 
|  |  | 1269 | +                            } | 
|  |  | 1270 | +                        } | 
|  |  | 1271 | +                        InitTallySecondary(originManifestSecondary); | 
|  |  | 1272 | +                    } | 
|  |  | 1273 | +                } | 
|  |  | 1274 | +            } | 
|  |  | 1275 | +            catch (Exception ex) | 
|  |  | 1276 | +            { | 
|  |  | 1277 | +                Log.WriteLog("3fhl_error", ex.ToString() + "\r\n\r\n" + FHL); | 
|  |  | 1278 | +            } | 
|  |  | 1279 | +            return result; | 
|  |  | 1280 | +        } | 
|  |  | 1281 | + | 
|  |  | 1282 | +        public static bool BookingFFMINFO(string FFM) | 
|  |  | 1283 | +        { | 
|  |  | 1284 | +            string text = ""; | 
|  |  | 1285 | +            string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString; | 
|  |  | 1286 | +            string text2 = ""; | 
|  |  | 1287 | +            string text3 = ""; | 
|  |  | 1288 | +            string text4 = ""; | 
|  |  | 1289 | +            string destinationstation = ""; | 
|  |  | 1290 | +            string text5 = ""; | 
|  |  | 1291 | +            string text6 = string.Empty; | 
|  |  | 1292 | +            string islast = string.Empty; | 
|  |  | 1293 | +            ffm_info ffm_info = new ffm_info(); | 
|  |  | 1294 | +            try | 
|  |  | 1295 | +            { | 
|  |  | 1296 | +                string text7 = FFM.Trim(); | 
|  |  | 1297 | +                string[] source = text7.Split(new char[2] | 
|  |  | 1298 | +                { | 
|  |  | 1299 | +                    '\t', | 
|  |  | 1300 | +                    '\n' | 
|  |  | 1301 | +                }, StringSplitOptions.None); | 
|  |  | 1302 | +                text7 = source.Aggregate((string str1, string str2) => str1 + str2); | 
|  |  | 1303 | +                string[] source2 = text7.Split('\r'); | 
|  |  | 1304 | +                source2 = source2.Where((string p) => !string.IsNullOrEmpty(p.Trim())).ToArray(); | 
|  |  | 1305 | +                string item = source2.Where((string p) => p.Contains("FFM/")).ToList().FirstOrDefault() | 
|  |  | 1306 | +                    .ToString(); | 
|  |  | 1307 | +                int count = source2.ToList().IndexOf(item); | 
|  |  | 1308 | +                List<string> list = source2.ToList(); | 
|  |  | 1309 | +                list.RemoveRange(0, count); | 
|  |  | 1310 | +                if (list.Count > 0) | 
|  |  | 1311 | +                { | 
|  |  | 1312 | +                    for (int i = 0; i < list.Count; i++) | 
|  |  | 1313 | +                    { | 
|  |  | 1314 | +                        text2 = list[i].Trim(); | 
|  |  | 1315 | +                        if (string.IsNullOrEmpty(text3) && string.IsNullOrEmpty(text4) && text2.Contains("/") && text2.Split('/').Length >= 4) | 
|  |  | 1316 | +                        { | 
|  |  | 1317 | +                            string pattern = "^\\d*$"; | 
|  |  | 1318 | +                            if (Regex.IsMatch(text2.Split('/')[0], pattern)) | 
|  |  | 1319 | +                            { | 
|  |  | 1320 | +                                if (string.IsNullOrEmpty(text6)) | 
|  |  | 1321 | +                                { | 
|  |  | 1322 | +                                    text6 = int.Parse(text2.Split('/')[0]).ToString(); | 
|  |  | 1323 | +                                } | 
|  |  | 1324 | +                                text3 = ((text2.Split('/')[1] == null) ? "" : text2.Split('/')[1]); | 
|  |  | 1325 | +                                text4 = ((text2.Split('/')[2] == null) ? "" : text2.Split('/')[2]); | 
|  |  | 1326 | +                                if (text4.Length > 5) | 
|  |  | 1327 | +                                { | 
|  |  | 1328 | +                                    text4 = text4.Substring(0, 5); | 
|  |  | 1329 | +                                } | 
|  |  | 1330 | +                                text5 = text2.Split('/')[3]; | 
|  |  | 1331 | +                            } | 
|  |  | 1332 | +                        } | 
|  |  | 1333 | +                    } | 
|  |  | 1334 | +                    if (text5 != "CGO") | 
|  |  | 1335 | +                    { | 
|  |  | 1336 | +                        try | 
|  |  | 1337 | +                        { | 
|  |  | 1338 | +                            for (int num = list.Count - 1; num > 0; num--) | 
|  |  | 1339 | +                            { | 
|  |  | 1340 | +                                if (list[num] != null && (list[num].Trim() == "LAST" || list[num].Trim() == "CONT")) | 
|  |  | 1341 | +                                { | 
|  |  | 1342 | +                                    islast = list[num].Trim(); | 
|  |  | 1343 | +                                    break; | 
|  |  | 1344 | +                                } | 
|  |  | 1345 | +                            } | 
|  |  | 1346 | +                        } | 
|  |  | 1347 | +                        catch | 
|  |  | 1348 | +                        { | 
|  |  | 1349 | +                            islast = string.Empty; | 
|  |  | 1350 | +                        } | 
|  |  | 1351 | +                        for (int i = 0; i < list.Count; i++) | 
|  |  | 1352 | +                        { | 
|  |  | 1353 | +                            text2 = list[i].Trim(); | 
|  |  | 1354 | +                            if (text2.Length > 12 && Regex.IsMatch(text2.Substring(0, 12), "^(\\d{3}-)?\\d{8}$")) | 
|  |  | 1355 | +                            { | 
|  |  | 1356 | +                                for (int num2 = i - 1; num2 > 0; num2--) | 
|  |  | 1357 | +                                { | 
|  |  | 1358 | +                                    string text8 = list[num2].Trim(); | 
|  |  | 1359 | +                                    if (!string.IsNullOrEmpty(text8) && text8.Length >= 3 && text8.Length <= 40 && (text8.Length == 3 || text8.Substring(0, 3) == "CGO")) | 
|  |  | 1360 | +                                    { | 
|  |  | 1361 | +                                        destinationstation = text8.Substring(0, 3); | 
|  |  | 1362 | +                                        break; | 
|  |  | 1363 | +                                    } | 
|  |  | 1364 | +                                } | 
|  |  | 1365 | +                                int num3 = 0; | 
|  |  | 1366 | +                                text = text2.Substring(0, 12); | 
|  |  | 1367 | +                                ffm_info = CustomsCargoSystem.Parser.OriginManifestMaster.Parse_ffm_info(text2, text3, text4, text5, destinationstation); | 
|  |  | 1368 | +                                ffm_info.reportorder = text6; | 
|  |  | 1369 | +                                ffm_info.islast = islast; | 
|  |  | 1370 | +                                if (ffm_info != null && !string.IsNullOrEmpty(ffm_info.waybillnomaster) && !string.IsNullOrEmpty(ffm_info.flightno) && !string.IsNullOrEmpty(ffm_info.reportorder) && !string.IsNullOrEmpty(ffm_info.islast)) | 
|  |  | 1371 | +                                { | 
|  |  | 1372 | +                                    var _theflightdate = ffm_info.flightdate; | 
|  |  | 1373 | +                                    bool flag = 1 == 0; | 
|  |  | 1374 | +                                    int num4 = (int)ffm_info.flightdate.DayOfWeek; | 
|  |  | 1375 | +                                    if (num4 == 0) | 
|  |  | 1376 | +                                    { | 
|  |  | 1377 | +                                        num4 = 7; | 
|  |  | 1378 | +                                    } | 
|  |  | 1379 | +                                    IEnumerable<FlightSettingModel> flightPlan = CustomsCargoSystem.Data.OriginManifestMaster.GetFlightPlan(connectionString, ffm_info.flightno, ffm_info.originatingstation, num4.ToString()); | 
|  |  | 1380 | +                                    if (flightPlan.Count() > 0) | 
|  |  | 1381 | +                                    { | 
|  |  | 1382 | +                                        FlightSettingModel flightSettingModel = flightPlan.FirstOrDefault(); | 
|  |  | 1383 | +                                        if (flightSettingModel != null) | 
|  |  | 1384 | +                                        { | 
|  |  | 1385 | +                                            ffm_info.flightdate = ffm_info.flightdate.AddDays(flightSettingModel.crossdatys); | 
|  |  | 1386 | +                                        } | 
|  |  | 1387 | +                                    } | 
|  |  | 1388 | +                                    string text9 = ""; | 
|  |  | 1389 | +                                    for (int num2 = i - 1; num2 > 0; num2--) | 
|  |  | 1390 | +                                    { | 
|  |  | 1391 | +                                        string text10 = list[num2].Trim(); | 
|  |  | 1392 | +                                        if (!string.IsNullOrEmpty(text10) && text10.Length > 4 && text10.Substring(0, 4) == "ULD/") | 
|  |  | 1393 | +                                        { | 
|  |  | 1394 | +                                            text9 = text10.Split('/')[1]; | 
|  |  | 1395 | +                                            break; | 
|  |  | 1396 | +                                        } | 
|  |  | 1397 | +                                    } | 
|  |  | 1398 | +                                    if (string.IsNullOrEmpty(text9)) | 
|  |  | 1399 | +                                    { | 
|  |  | 1400 | +                                        text9 = "BUG0625"; | 
|  |  | 1401 | +                                    } | 
|  |  | 1402 | +                                    ffm_info.pallet = text9; | 
|  |  | 1403 | +                                    ffm_info.dealstatus = "0"; | 
|  |  | 1404 | +                                    num3 = CustomsCargoSystem.Data.OriginManifestMaster.insert_ffminfo(connectionString, ffm_info); | 
|  |  | 1405 | +                                } | 
|  |  | 1406 | +                                if (num3 > 0) | 
|  |  | 1407 | +                                { | 
|  |  | 1408 | +                                    Log.ffminfo_log("sucess_ffminfo", ffm_info.flightno + ".txt", string.Format("{0}舱单信息航班号:{1}航班日期:{2},主单号:{3}入库成功。" + Environment.NewLine, DateTime.Now, ffm_info.flightno, ffm_info.flightdate, ffm_info.waybillnomaster)); | 
|  |  | 1409 | +                                } | 
|  |  | 1410 | +                            } | 
|  |  | 1411 | +                        } | 
|  |  | 1412 | +                    } | 
|  |  | 1413 | +                } | 
|  |  | 1414 | +                return true; | 
|  |  | 1415 | +            } | 
|  |  | 1416 | +            catch (Exception ex) | 
|  |  | 1417 | +            { | 
|  |  | 1418 | +                Log.WriteLog("2ffm_error", ex.ToString() + "\r\n\r\n" + FFM); | 
|  |  | 1419 | +                Log.ffminfo_log("failed_ffminfo", ffm_info.flightno + ".txt", string.Format("{0}舱单信息航班号:{1}航班日期:{2},主单号:{3}入库成功。" + Environment.NewLine, DateTime.Now, ffm_info.flightno, ffm_info.flightdate, ffm_info.waybillnomaster)); | 
|  |  | 1420 | +                return false; | 
|  |  | 1421 | +            } | 
|  |  | 1422 | +        } | 
|  |  | 1423 | + | 
|  |  | 1424 | +        private static void InitTallySecondary(CustomsCargoSystem.Model.OriginManifestSecondary model) | 
|  |  | 1425 | +        { | 
|  |  | 1426 | +            try | 
|  |  | 1427 | +            { | 
|  |  | 1428 | +                string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString; | 
|  |  | 1429 | +                CustomsCargoSystem.Model.TallySecondary tallySecondary = new CustomsCargoSystem.Model.TallySecondary(); | 
|  |  | 1430 | +                tallySecondary.AUTOID = Guid.NewGuid().ToString("N"); | 
|  |  | 1431 | +                tallySecondary.WAYBILLNOMASTER = model.WayBillNoMaster; | 
|  |  | 1432 | +                tallySecondary.WAYBILLNOSECONDARY = model.WayBillNoSecondary; | 
|  |  | 1433 | +                tallySecondary.PIECE = model.ManifestPiece; | 
|  |  | 1434 | +                tallySecondary.WEIGHT = model.ManifestWeight; | 
|  |  | 1435 | +                tallySecondary.TALLYPIECE = "0"; | 
|  |  | 1436 | +                tallySecondary.TALLYWEIGHT = "0"; | 
|  |  | 1437 | +                tallySecondary.CUSTOMSCODE = model.CustomsCode; | 
|  |  | 1438 | +                tallySecondary.PRODUCTNAME = model.ProductName; | 
|  |  | 1439 | +                tallySecondary.CREATEDATE = DateTime.Now; | 
|  |  | 1440 | +                tallySecondary.status = "00"; | 
|  |  | 1441 | +                IEnumerable<CustomsCargoSystem.Model.TallyMaster> byWayBillNoMaster = CustomsCargoSystem.Data.TallyMaster.GetByWayBillNoMaster(connectionString, model.WayBillNoMaster); | 
|  |  | 1442 | +                if (byWayBillNoMaster != null && byWayBillNoMaster.Count() > 0) | 
|  |  | 1443 | +                { | 
|  |  | 1444 | +                    tallySecondary.TALLYMASTERID = byWayBillNoMaster.FirstOrDefault().AUTOID; | 
|  |  | 1445 | +                } | 
|  |  | 1446 | +                IEnumerable<CustomsCargoSystem.Model.TallySecondary> source = CustomsCargoSystem.Data.TallySecondary.TallySecondaryIsExist(connectionString, tallySecondary.WAYBILLNOMASTER, tallySecondary.WAYBILLNOSECONDARY); | 
|  |  | 1447 | +                if (source.Count() == 0) | 
|  |  | 1448 | +                { | 
|  |  | 1449 | +                    CustomsCargoSystem.Data.TallySecondary.Insert(connectionString, tallySecondary); | 
|  |  | 1450 | +                } | 
|  |  | 1451 | +                else if (source.FirstOrDefault().status == "00") | 
|  |  | 1452 | +                { | 
|  |  | 1453 | +                    CustomsCargoSystem.Data.TallySecondary.Update(connectionString, tallySecondary); | 
|  |  | 1454 | +                } | 
|  |  | 1455 | +            } | 
|  |  | 1456 | +            catch (Exception ex) | 
|  |  | 1457 | +            { | 
|  |  | 1458 | +                Log.WriteLog("4xml_error", "生成理货分单出错,错误:" + ex.ToString()); | 
|  |  | 1459 | +            } | 
|  |  | 1460 | +        } | 
|  |  | 1461 | + | 
|  |  | 1462 | +        protected override void Dispose(bool disposing) | 
|  |  | 1463 | +        { | 
|  |  | 1464 | +            if (disposing && components != null) | 
|  |  | 1465 | +            { | 
|  |  | 1466 | +                components.Dispose(); | 
|  |  | 1467 | +            } | 
|  |  | 1468 | +            base.Dispose(disposing); | 
|  |  | 1469 | +        } | 
|  |  | 1470 | + | 
|  |  | 1471 | +        private void InitializeComponent() | 
|  |  | 1472 | +        { | 
|  |  | 1473 | +            components = new Container(); | 
|  |  | 1474 | +            base.ServiceName = "货运系统数据交换协议数据入库服务"; | 
|  |  | 1475 | +        } | 
|  |  | 1476 | +    } | 
|  |  | 1477 | +} |