Exemple #1
0
        public static void IncreaseShipmentBarcode(int No)
        {
            string Prefix = "";
            int NextSONo = 0;
            const string BarcodePath = "http://nwszmail/public/namwah/system/barcodes/SZ_ShipOrderCode.EML";
            Logger.For(typeof(Glob)).Info("开始");

            try
            {
                ADODB.Record Rec = new ADODB.Record();
                Rec.Open(BarcodePath, Type.Missing, ADODB.ConnectModeEnum.adModeReadWrite &
                    ADODB.ConnectModeEnum.adModeShareDenyWrite,
                    ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
                    ADODB.RecordOpenOptionsEnum.adOpenRecordUnspecified, "Namwah", "ParaW0rld");

                Prefix = Rec.Fields["nw:barcode:prefix"].Value.ToString();
                NextSONo = int.Parse(Rec.Fields["nw:barcode:nextnumber"].Value.ToString());

                Rec.Fields["nw:barcode:nextnumber"].Value = NextSONo + No;
                Rec.Fields.Update();
                Rec = null;

            }
            catch (Exception ex)
            {
                Logger.For(typeof(Glob)).Error(ex.Message);
            }
            Logger.For(typeof(Glob)).Info("結束");
        }
Exemple #2
0
        public static string GetShipmentBarcode()
        {
            string Prefix = "", Barcode = "";
            int NextSONo = 0;
            string BarcodePath = "http://nwszmail/public/namwah/system/barcodes/SZ_ShipOrderCode.EML";
            Logger.For(typeof(Glob)).Info("开始");
            try
            {
                ADODB.Connection Cnn = ServerHelper.ConnectExchange(BarcodePath);
                ADODB.Record Rec = new ADODB.Record();

                Rec.Open(BarcodePath, Cnn, ADODB.ConnectModeEnum.adModeReadWrite,
                    ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
                    ADODB.RecordOpenOptionsEnum.adOpenRecordUnspecified, "Namwah", "ParaW0rld");

                Prefix = Rec.Fields["nw:barcode:prefix"].Value.ToString();
                NextSONo = int.Parse(Rec.Fields["nw:barcode:nextnumber"].Value.ToString());
                Rec.Fields["nw:barcode:nextnumber"].Value = NextSONo + 1;
                Rec.Fields.Update();
                Rec = null;

                Barcode = string.Format("{0}{1}", Prefix, NextSONo.ToString("0000000"));
            }
            catch (Exception ex)
            {
                Logger.For(typeof(Glob)).Error(ex.Message);
                throw ex;
            }

            Logger.For(typeof(Glob)).Info("結束");
            return Barcode;
        }
 private void UpdateToExchange()
 {
     try
     {
         Logger.For(this).Info(string.Format("寄货单号 {0}.  开始", OrderNo));
         ADODB.Connection Cnn = ServerHelper.ConnectExchange(SHIPMENTPATH);
         ADODB.Record Rec = new ADODB.Record();
         string StrSQL = string.Format("{0}{1}.eml", SHIPMENTPATH, OrderNo);
         Rec.Open(StrSQL, Cnn, ADODB.ConnectModeEnum.adModeReadWrite,
             ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
             ADODB.RecordOpenOptionsEnum.adOpenRecordUnspecified,
                 "Namwah", "ParaW0rld");
         RecToExchange(Rec);
         Rec.Fields.Update();
         Rec.Close();
         Rec = null;
         Cnn = null;
         Logger.For(this).Info(string.Format("寄货单号 {0}.  结束", OrderNo));
     }
     catch (Exception ex)
     {
         Logger.For(this).Error(string.Format("寄货单号 {0}不能储存.  原因 : {1}.", OrderNo, ex.Message));
         throw ex;
     }
 }
        public void UpdateFQC()
        {
            if (Glob.IsDebugMode)
                return;

            try
            {
                Logger.For(this).Info(string.Format("Order No : {0}. Start.", OrderNo));
                ADODB.Connection Cnn = ServerHelper.ConnectExchange(JSPATH);
                ADODB.Record Rec = new ADODB.Record();

                Rec.Open(string.Format("{0}{1}.eml", JSPATH, OrderNo), Cnn, ADODB.ConnectModeEnum.adModeReadWrite, ADODB.RecordCreateOptionsEnum.adFailIfNotExists, ADODB.RecordOpenOptionsEnum.adOpenRecordUnspecified, "namwah", "ParaW0rld");
                Rec.Fields["nw:fqc:inspector"].Value = FQCInspector;

                if (FQCInspectionDate != DateTime.MinValue)
                    Rec.Fields["nw:fqc:inspectiondate"].Value = FQCInspectionDate;

                Rec.Fields["nw:fqc:sample:inspectqty"].Value = int.Parse(ActiveQty.ToString());
                Rec.Fields["nw:js:irno"].Value = IrNo;
                Rec.Fields["nw:js:activeqty"].Value = int.Parse(ActiveQty.ToString());
                Rec.Fields["nw:js:status"].Value = "Complete";
                Rec.Fields["nw:js:activelocation"].Value = "Q";
                Rec.Fields.Update();

                Logger.For(this).Info(string.Format("Order No : {0}. End.", OrderNo));
            }
            catch (Exception ex)
            {
                Logger.For(this).Error(string.Format("Order No : {0}. Error : {1}.", OrderNo, ex.Message));
                throw ex;
            }
        }
        private void InsertToExchange()
        {
            Logger.For(this).Info(string.Format("开始.  寄货单号 {0}.", OrderNo));

            ADODB.Connection Cnn = ServerHelper.ConnectExchange(SHIPMENTPATH);
            ADODB.Record Rec = new ADODB.Record();

            for (int Attempt = 0; Attempt < 2; Attempt++)
            {
                Rec = new ADODB.Record();
                try
                {
                    if (OrderNo == "")
                        OrderNo = Glob.GetShipmentBarcode();

                    string StrSQL = string.Format("{0}{1}.eml", SHIPMENTPATH, OrderNo);

                    Rec.Open(StrSQL, Cnn, ADODB.ConnectModeEnum.adModeReadWrite,
                        ADODB.RecordCreateOptionsEnum.adCreateNonCollection,
                        ADODB.RecordOpenOptionsEnum.adOpenRecordUnspecified,
                        "Namwah", "ParaW0rld");
                    break;
                }
                catch (Exception ex)
                {
                    if (Attempt == 2)
                    {
                        Logger.For(this).Error(string.Format("不能建立寄货单.  原因 : {0}.", ex.Message));
                        throw ex;
                    }
                    else
                    {
                        Glob.IncreaseShipmentBarcode(10);
                    }
                }
            }

            Rec.Fields["http://schemas.microsoft.com/exchange/outlookmessageclass"].Value = "IPM.Post.ship_order";
            Rec.Fields["DAV:contentclass"].Value = "nw:content-classes:mo";
            Rec.Fields["urn:schemas:httpmail:subject"].Value = OrderNo;

            AddHistory("Created");
            AddHistory(string.Format("Original Ship Qty is {0}", MoveQty));

            RecToExchange(Rec);
            Rec.Fields.Update();
            Logger.For(this).Info(string.Format("结束.  寄货单号 {0}.", OrderNo));
        }
        public static WHTotal LoadByExchange(string ItemNo)
        {
            Logger.For(typeof(WHTotal)).Info(string.Format("开始.  编码 : {0}", ItemNo));
            ADODB.Connection Cnn = ServerHelper.ConnectExchange(SZInvPath);
            ADODB.Record Rst = new ADODB.Record();
            WHTotal WHTotal = new WHTotal();

            try
            {
                Rst.Open(string.Format("{0}{1}.eml", SZInvPath, ItemNo), Cnn, ADODB.ConnectModeEnum.adModeReadWrite, ADODB.RecordCreateOptionsEnum.adOpenIfExists, ADODB.RecordOpenOptionsEnum.adDelayFetchFields, "namwah", "ParaW0rld");
                WHTotal.InitFromExchange(Rst);
                Logger.For(typeof(WHTotal)).Info(string.Format("结束.  编码 : {0}", ItemNo));
            }
            catch(Exception ex)
            {
                Logger.For(typeof(WHTotal)).Error(string.Format("编码 {0} :  原因 : {1}.", ItemNo, ex.Message));
                return null;
            }

            return WHTotal;
        }
 public static JobSchedule LoadExchange(string StrJSNo)
 {
     try
     {
         Logger.For(typeof(JobSchedule)).Info(string.Format("开始.  单号 : {0}.", StrJSNo));
         ADODB.Connection Cnn = ServerHelper.ConnectExchange(JSPATH);
         ADODB.Record Rec = new ADODB.Record();
         Rec.Open(string.Format("{0}{1}.eml", JSPATH, StrJSNo), Cnn, ADODB.ConnectModeEnum.adModeReadWrite, ADODB.RecordCreateOptionsEnum.adFailIfNotExists, ADODB.RecordOpenOptionsEnum.adOpenRecordUnspecified, "namwah", "ParaW0rld");
         JobSchedule JS = new JobSchedule();
         JS.InitFromRec(Rec);
         Logger.For(typeof(JobSchedule)).Info(string.Format("结束.  单号 : {0}.", StrJSNo));
         return JS;
     }
     catch (Exception ex)
     {
         Logger.For(typeof(JobSchedule)).Error(string.Format("单号 : {0}.  原因 : {1}", StrJSNo, ex.Message));
         throw ex;
     }
 }
        public void UpdateToExchange()
        {
            if (Glob.IsDebugMode)
                return ;

            try
            {
                Logger.For(this).Info(string.Format("开始.  编码 : {0}", ItemNo));
                ADODB.Connection Cnn = ServerHelper.ConnectExchange(SZInvPath);
                ADODB.Record Rec = new ADODB.Record();
                Rec.Open(string.Format("{0}{1}.eml", SZInvPath, ItemNo), Cnn, ADODB.ConnectModeEnum.adModeReadWrite, ADODB.RecordCreateOptionsEnum.adOpenIfExists, ADODB.RecordOpenOptionsEnum.adDelayFetchFields, "namwah", "ParaW0rld");
                Rec.Fields["nw:inv:totalqty"].Value = int.Parse(Qty.ToString());
                Rec.Fields["nw:inv:qaqty"].Value = int.Parse(QAQty.ToString());
                Rec.Fields["nw:inv:availqty"].Value = int.Parse(Qty.ToString()) - int.Parse(QAQty.ToString());
                Rec.Fields["nw:inv:defectqty"].Value = int.Parse(DefectQty.ToString());
                Rec.Fields.Update();
                Logger.For(this).Info(string.Format("结束.  编码 : {0}", ItemNo));
            }
            catch (Exception ex)
            {
                Logger.For(this).Error(string.Format("编码 {0} :  原因 : {1}.", ItemNo, ex.Message));
                throw ex;
            }
        }
        public void SaveToOutlookSystem(Item item)
        {
            cnn = new ADODB.Connection();
            rst = new ADODB.Record();

            ConnectDB(cnn);

            try
            {
                rst.Open(string.Format("{0}{1}.eml", partPath, item.ItemNo), cnn, ADODB.ConnectModeEnum.adModeReadWrite, ADODB.RecordCreateOptionsEnum.adOpenIfExists, ADODB.RecordOpenOptionsEnum.adDelayFetchFields, "namwah", "ParaW0rld");
            }
            catch
            {
                rst.Open(string.Format("{0}{1}.eml", partPath, item.ItemNo), cnn, ADODB.ConnectModeEnum.adModeReadWrite, ADODB.RecordCreateOptionsEnum.adCreateNonCollection, ADODB.RecordOpenOptionsEnum.adDelayFetchFields, "namwah", "ParaW0rld");
                rst.Fields["http://schemas.microsoft.com/exchange/outlookmessageclass"].Value = "IPM.Post.parts_hk";
                rst.Fields["DAV:contentclass"].Value = "nw:content-classes:part";
                rst.Fields["urn:schemas:httpmail:subject"].Value = item.ItemNo;

                rst.Fields["nw:material"].Value = "";
                rst.Fields["nw:part:category"].Value = "";
                rst.Fields["nw:part:pricecat"].Value = "";

                rst.Fields["nw:part:orderfactor"].Value = 1;
                rst.Fields["nw:part:reworkpartno"].Value = "XXX";
                rst.Fields["nw:part:cellcap"].Value = "";

                rst.Fields["nw:part:chr1"].Value = "";
                rst.Fields["nw:part:chr2"].Value = "";
                rst.Fields["nw:part:chr3"].Value = "";
                rst.Fields["nw:part:chr4"].Value = "";
                rst.Fields["nw:part:chr5"].Value = "";
                rst.Fields["nw:part:chr6"].Value = "";
                rst.Fields["nw:part:chr7"].Value = "";
                rst.Fields["nw:part:chr8"].Value = "";
                rst.Fields["nw:part:chr9"].Value = "";
                rst.Fields["nw:part:chr10"].Value = "";

                rst.Fields["nw:part:supplier:detail"].Value = "";
                rst.Fields["nw:part:supplier:refno"].Value = "";
                rst.Fields["nw:supplierlist"].Value = "";
                rst.Fields["nw:part:cost"].Value = "";

                rst.Fields["nw:plating"].Value = "";
                rst.Fields["nw:plating:leadtime"].Value = 0;
                rst.Fields["nw:plating:plater"].Value = "";
                rst.Fields["nw:plating:paidby"].Value = "";

                rst.Fields["nw:bom:list:partno"].Value = "";
                rst.Fields["nw:bom:list:partname"].Value = "";
                rst.Fields["nw:bom:list:parttype"].Value = "";
                rst.Fields["nw:bom:list:qty"].Value = "";
                rst.Fields["nw:bom:list:partprice"].Value = "";

                rst.Fields["nw:rout1:resoption"].Value = false;
                rst.Fields["nw:rout1:resourceno"].Value = "";
                rst.Fields["nw:rout1:resourcename"].Value = "";
                rst.Fields["nw:rout1:resourcetype"].Value = "";
                rst.Fields["nw:rout1:type"].Value = "";

                rst.Fields["nw:part:supplier:detail"].Value = "";
                rst.Fields["nw:part:supplier:refno"].Value = ",,,,";
                rst.Fields["nw:supplierlist"].Value = ",,,,";
                rst.Fields["nw:part:cost"].Value = "----";
            }

            rst.Fields["http://schemas.microsoft.com/exchange/outlookmessageclass"].Value = "IPM.Post.parts_hk";
            rst.Fields["DAV:contentclass"].Value = "nw:content-classes:part";
            rst.Fields["urn:schemas:httpmail:subject"].Value = item.ItemNo;
            rst.Fields["nw:partno"].Value = item.ItemNo;
            rst.Fields["nw:partname"].Value = item.ItemName;
            rst.Fields["nw:parttype"].Value = item.ItemType.ItemTypeName;
            rst.Fields["nw:part:tmxrefno"].Value = item.CustomerItemNo;
            rst.Fields["nw:qtyunit"].Value = item.Unit.UnitName;
            rst.Fields["nw:description"].Value = item.ItemDescription;
            rst.Fields["nw:part:status"].Value = "Design";
            if (item.ItemType.ItemTypeName == "Bar")
                rst.Fields["nw:part:chr1"].Value = item.NetWeight.ToString();

            rst.Fields.Update();

            if (item.ItemType.ItemTypeName == "CaseBack")
            {
                rst.Fields["nw:part:chr1"].Value = item.OutsideMark;
                rst.Fields["nw:part:chr2"].Value = item.QtyPerKg.ToString();
                rst.Fields["nw:part:chr6"].Value  = item.InsideMark;
            }

            rst.Fields["nw:minorderqty"].Value = int.Parse(item.MinOrderQty.ToString());
            rst.Fields["nw:drawingno"].Value = item.DrawingNo;
            rst.Fields["nw:oldversion"].Value = "False";

            if (item.PriceCategory != null)
                rst.Fields["nw:part:pricecat"].Value = item.PriceCategory.PriceCategoryNo ;

            rst.Fields["nw:part:leadtime"].Value = int.Parse(item.LeadTime.ToString());
            rst.Fields["nw:strprice"].Value = item.SalesPrice.ToString();

            if (item.Source == Item.ItemSource.Make)
                rst.Fields["nw:part:source"].Value = "Make";
            else
                rst.Fields["nw:part:source"].Value = "Buy";

            if (item.InCharge == Item.ItemInCharge.HK)
                rst.Fields["nw:part:incharge"].Value = "HK";
            else
                rst.Fields["nw:part:incharge"].Value = "SZ";

            if (item.ItemCategory != null)
                rst.Fields["nw:part:category"].Value = item.ItemCategory.ItemCategoryNo;

            if (item.Material != null)
                rst.Fields["nw:material"].Value = item.Material.Name;

            if (item.Size != null)
                rst.Fields["nw:part:size"].Value = item.Size;

            if (item.ColorCode != null)
                rst.Fields["nw:part:color"].Value = item.ColorCode.ColorNo;

            if (item.RemarkToSupplier != null)
                rst.Fields["nw:part:supplier:detail"].Value = item.RemarkToSupplier;

            #region Save Supplier Detail

            rst.Fields["nw:part:supplier:refno"].Value = ",,,,";
            rst.Fields["nw:supplierlist"].Value = ",,,,";
            rst.Fields["nw:part:cost"].Value = "----";

            if (item.PriceDiscs.Count > 0)
            {
                StringBuilder sbSupplierRefNo = new StringBuilder();
                StringBuilder sbSupplier = new StringBuilder();
                StringBuilder sbSupplierCost = new StringBuilder();
                StringBuilder sbSupplierName = new StringBuilder();

                SortingCollection sorting = new SortingCollection();
                sorting.Add(new SortProperty("Index", SortingDirection.Ascending));
                item.PriceDiscs.Sorting = sorting;

                // 先取主要供应商资料
                foreach (PriceDisc pDisc in item.PriceDiscs)
                {
                    if (pDisc.Type == PriceDisc.PriceType.Purch && pDisc.ExternalContact == item.MainVendor)
                    {
                        if (pDisc.ExternalContact != null)
                        {
                            sbSupplier.Append(string.Format("{0},", pDisc.ExternalContact.No));
                            sbSupplierRefNo.Append(string.Format("{0},", pDisc.ExternalNo));
                            sbSupplierCost.Append(string.Format("{0}-", pDisc.Price));
                            sbSupplierName.Append(string.Format("{0},", pDisc.ExternalName));
                        }
                    }
                }

                // 再取其余供应商资料
                foreach (PriceDisc pDisc in item.PriceDiscs)
                {
                    if (pDisc.Type == PriceDisc.PriceType.Purch)
                    {
                        if (pDisc.ExternalContact != item.MainVendor)
                        {
                            sbSupplier.Append(string.Format("{0},", pDisc.ExternalContact.No));
                            sbSupplierRefNo.Append(string.Format("{0},", pDisc.ExternalNo));
                            sbSupplierCost.Append(string.Format("{0}-", pDisc.Price));
                            sbSupplierName.Append(string.Format("{0},", pDisc.ExternalName));
                        }
                    }
                }

                if (sbSupplier.ToString() != "")
                {
                    if (sbSupplierRefNo.ToString().Length == 1)
                        rst.Fields["nw:part:supplier:refno"].Value = " ";
                    else
                        rst.Fields["nw:part:supplier:refno"].Value = sbSupplierRefNo.ToString().Substring(0, sbSupplierRefNo.ToString().Length - 1);

                    rst.Fields["nw:supplierlist"].Value = sbSupplier.ToString().Substring(0, sbSupplier.ToString().Length - 1);
                    rst.Fields["nw:part:cost"].Value = sbSupplierCost.ToString().Substring(0, sbSupplierCost.ToString().Length - 1);
                }
            }

            // OK.

            #endregion

            /*  Save Bom Or Route */

            #region SaveBom

            rst.Fields["nw:bom:list:partno"].Value = "";
            rst.Fields["nw:bom:list:partname"].Value = "";
            rst.Fields["nw:bom:list:parttype"].Value = "";
            rst.Fields["nw:bom:list:qty"].Value = "";

            rst.Fields["nw:rout1:resoption"].Value = false;
            rst.Fields["nw:rout1:resourceno"].Value = "";
            rst.Fields["nw:rout1:resourcename"].Value = "";
            rst.Fields["nw:rout1:resourcetype"].Value = "";
            rst.Fields["nw:rout1:type"].Value = "";

            if (item.BomLines.Count > 1)
            {
                StringBuilder sbBomNo = new StringBuilder();
                StringBuilder sbBomName = new StringBuilder();
                StringBuilder sbBomType = new StringBuilder();
                StringBuilder sbBomQty = new StringBuilder();

                SortingCollection sorting = new SortingCollection();
                sorting.Add(new SortProperty("BomItem.ItemNo", SortingDirection.Ascending));
                item.BomLines.Sorting = sorting;

                foreach (BomLine bomLine in item.BomLines)
                {
                    sbBomNo.Append(string.Format("{0},", bomLine.BomItem.ItemNo));
                    sbBomName.Append(string.Format("{0},", bomLine.BomItem.ItemName));
                    sbBomType.Append(string.Format("{0},", bomLine.BomItem.ItemType.ItemTypeName));
                    sbBomQty.Append(string.Format("{0},", bomLine.Qty));
                }

                if (sbBomNo.ToString() != "")
                {
                    rst.Fields["nw:bom:list:partno"].Value = sbBomNo.ToString().Substring(0, sbBomNo.ToString().Length - 1);
                    rst.Fields["nw:bom:list:partname"].Value = sbBomName.ToString().Substring(0, sbBomName.ToString().Length - 1);
                    rst.Fields["nw:bom:list:parttype"].Value = sbBomType.ToString().Substring(0, sbBomType.ToString().Length - 1);
                    rst.Fields["nw:bom:list:qty"].Value = sbBomQty.ToString().Substring(0, sbBomQty.ToString().Length - 1);
                }

                rst.Fields["nw:rout1:resoption"].Value = false;
                rst.Fields["nw:rout1:resourceno"].Value = "bom";
                rst.Fields["nw:rout1:resourcename"].Value = "";
                rst.Fields["nw:rout1:resourcetype"].Value = "A";
                rst.Fields["nw:rout1:type"].Value = "A";

                RouteLine routeLine = item.GetFirstRouteLine();

                if (routeLine != null)
                {
                    rst.Fields["nw:rout1:resourcetype"].Value = routeLine.WorkCenter.WorkCenterNo ;
                    rst.Fields["nw:rout1:type"].Value = routeLine.WorkOper.WorkOperNo;
                }
            }
            #endregion

            #region Save Route

            if (item.BomLines.Count == 1)
            {
                rst.Fields["nw:rout1:resoption"].Value = false;
                rst.Fields["nw:rout1:resourceno"].Value = item.BomLines[0].BomItem.ItemNo;
                rst.Fields["nw:rout1:resourcename"].Value = item.BomLines[0].BomItem.ItemName;
                rst.Fields["nw:rout1:resourcetype"].Value = item.BomLines[0].BomItem.ItemType.ItemTypeName;

                RouteLine routeLine = item.GetFirstRouteLine();

                if (routeLine != null)
                {
                    rst.Fields["nw:rout1:type"].Value = routeLine.WorkOper.WorkOperNo;

                    if (routeLine.wipItem != null)
                    {
                        rst.Fields["nw:rout1:resoption"].Value = true;
                        rst.Fields["nw:rout1:resourceno"].Value = routeLine.wipItem.ItemNo;
                        rst.Fields["nw:rout1:resourcename"].Value = routeLine.wipItem.ItemName;
                        rst.Fields["nw:rout1:resourcetype"].Value = routeLine.wipItem.ItemType.ItemTypeName;
                    }
                }
            }

            RouteLine lastRouteLine = item.GetLastRouteLine();

            rst.Fields["nw:plating"].Value = "";
            rst.Fields["nw:plating:plater"].Value = "";
            rst.Fields["nw:plating:leadtime"].Value = 0;

            if (lastRouteLine != null)
            {
                rst.Fields["nw:rout1:type"].Value = lastRouteLine.WorkOper.WorkOperNo;

                if (lastRouteLine.WorkCenter.Type == WorkCenter.WorkCenterType.Vendor)
                {
                    rst.Fields["nw:plating"].Value = lastRouteLine.WorkDesc;  //  lastRouteLine.WorkCenter.WorkCenterNo;
                    rst.Fields["nw:plating:plater"].Value = lastRouteLine.WorkCenter.WorkCenterNo;
                    rst.Fields["nw:plating:leadtime"].Value = int.Parse(lastRouteLine.RunTime.ToString());
                }
            }

            #endregion

            rst.Fields.Update();
        }
        public void LoadOutLook(string itemNo)
        {
            cnn = new ADODB.Connection();
            rst = new ADODB.Record();

            ConnectDB(cnn);
            rst.Open(string.Format("{0}{1}.eml", partPath, itemNo), cnn, ADODB.ConnectModeEnum.adModeReadWrite, ADODB.RecordCreateOptionsEnum.adOpenIfExists, ADODB.RecordOpenOptionsEnum.adDelayFetchFields, "namwah", "ParaW0rld");
        }
        public Item CreateItemFromOutlookSystem(string itemNo, UnitOfWork uow, bool isOverride)
        {
            Item item;
            item = Item.FindItem(uow, itemNo);

            if (isOverride == false && item != null)
                return item;

            cnn = new ADODB.Connection();
            rst = new ADODB.Record();

            ConnectDB(cnn);
            rst.Open(string.Format("{0}{1}.eml", partPath, itemNo), cnn, ADODB.ConnectModeEnum.adModeReadWrite, ADODB.RecordCreateOptionsEnum.adOpenIfExists, ADODB.RecordOpenOptionsEnum.adDelayFetchFields, "namwah", "ParaW0rld");

            if (GetStringField(rst.Fields["nw:partno"]) == "")
            {
                if (isOverride == false)
                    DevExpress.XtraEditors.XtraMessageBox.Show(string.Format("在大货系统找不到此编码 : {0}", itemNo));

                rst.Fields["urn:schemas:httpmail:subject"].Value = itemNo;
                rst.Fields.Update();
                rst.DeleteRecord(string.Format("{0}{1}.eml", partPath, itemNo), false);
                return null;
            }

            try
            {
                if (item == null)
                    item = new Item(uow);

                item.ItemNo = itemNo;
                item.ItemName = GetStringField(rst.Fields["nw:partname"]);
                item.ItemType = ItemType.FindItemType(uow, GetStringField(rst.Fields["nw:parttype"]));
                item.CustomerItemNo = GetStringField(rst.Fields["nw:part:tmxrefno"]);
                item.ItemDescription = GetStringField(rst.Fields["nw:description"]);
                item.MinOrderQty = GetIntField(rst.Fields["nw:minorderqty"]);
                item.DrawingNo = GetStringField(rst.Fields["nw:drawingno"]);
                item.LeadTime = GetIntField(rst.Fields["nw:part:leadtime"]);
                item.SalesPrice = GetFloatField(rst.Fields["nw:strprice"]);
                item.Size = GetStringField(rst.Fields["nw:part:size"]);

                if (item.ItemType.ItemTypeName == "Bar")
                    item.NetWeight = GetFloatField(rst.Fields["nw:part:chr1"]);

                if (item.ItemType.ItemTypeName == "CaseBack")
                {
                    item.OutsideMark = GetStringField(rst.Fields["nw:part:chr1"]);
                    item.QtyPerKg = GetFloatField(rst.Fields["nw:part:chr2"]);
                    item.InsideMark = GetStringField(rst.Fields["nw:part:chr6"]);
                }

                if (GetStringField(rst.Fields["nw:part:source"]) == "Buy")
                    item.Source = Item.ItemSource.Buy;
                else
                    item.Source = Item.ItemSource.Make;

                if (GetStringField(rst.Fields["nw:part:incharge"]) == "HK")
                    item.InCharge = Item.ItemInCharge.HK;
                else
                    item.InCharge = Item.ItemInCharge.SZ;

                item.PriceCategory = PriceCategory.FindPriceCategory(uow, GetStringField(rst.Fields["nw:part:pricecat"]));
                item.ItemCategory = ItemCategory.FindItemCategory(uow, GetStringField(rst.Fields["nw:part:category"]));
                item.Material = Material.FindMaterial(uow, GetStringField(rst.Fields["nw:material"]));
                item.Warehouse = WareHouse.Find(uow, "SZ1良品仓");
                item.Unit = Unit.FindUnit(uow, "PCS");
                item.RemarkToSupplier = GetStringField(rst.Fields["nw:part:supplier:detail"]);

                #region Save PriceDisc

                if (item.PriceDiscs.Count > 0)
                {
                    for (int i = 0; i < item.PriceDiscs.Count; i++)
                    {
                        if (item.PriceDiscs[i].Type == PriceDisc.PriceType.Purch)
                        {
                            item.PriceDiscs[i].Delete();
                        }
                        i--;
                    }
                }

                string[] supplierRefNo = GetStringField(rst.Fields["nw:part:supplier:refno"]).Split(',');
                string[] supplierList = GetStringField(rst.Fields["nw:supplierlist"]).Split(',');
                string[] supplierCost = GetStringField(rst.Fields["nw:part:cost"]).Split('-');

                for (int i = 0; i < supplierList.Length; i++)
                {
                    if (supplierList[i].Trim() != "")
                    {
                        PriceDisc pDisc = new PriceDisc(uow);
                        pDisc.Index = i;
                        pDisc.Item = item;
                        pDisc.Type = PriceDisc.PriceType.Purch;
                        pDisc.ExternalContact = Vendor.FindVendor(uow, supplierList[i]);
                        pDisc.ExternalName = "";
                        pDisc.ExternalNo = supplierRefNo[i];
                        if (supplierCost[i] == "")
                            pDisc.Price = 0;
                        else
                            pDisc.Price = float.Parse(supplierCost[i]);

                        pDisc.PriceQty = 1;
                        pDisc.PriceUnit = Unit.FindUnit(uow, "PCS");
                        pDisc.Save();

                        if (i == 0)
                            item.MainVendor = (Vendor)pDisc.ExternalContact;

                    }
                }

                #endregion

                #region Clear BOM & Route

                if (item.BomLines.Count > 0)
                {
                    for (int i = 0; i < item.BomLines.Count; i++)
                    {
                        item.BomLines[i].Delete();
                        i--;
                    }
                }

                for (int i = 0; i < item.RouteLines.Count; i++)
                {
                    item.RouteLines[i].Delete();
                    i--;
                }

                #endregion

                #region Bom Line

                if (GetStringField(rst.Fields["nw:bom:list:partno"]) != "")
                {
                    string[] bPartNo = GetStringField(rst.Fields["nw:bom:list:partno"]).Split(',');
                    string[] bQty = GetStringField(rst.Fields["nw:bom:list:qty"]).Split(',');

                    for (int i = 0; i < bPartNo.Length; i++)
                    {
                        OutlookSystemItem osItem = new OutlookSystemItem();
                        item.Save();
                        uow.CommitChanges();

                        Item bomItem = osItem.CreateItemFromOutlookSystem(bPartNo[i], uow, isOverride);

                        if (isOverride == false && bomItem == null)
                        {
                            item.UnconfirmItem();
                            item.Save();
                            uow.CommitChanges();
                            return null;
                        }

                        CreateBomLine(item, bomItem, uow, int.Parse(bQty[i]));
                    }

                    CreateRouteLine(item, 10, 0, "A", "A", "", "", uow);
                }

                #endregion

                #region Route

                if (GetStringField(rst.Fields["nw:rout1:resourceno"]) != "bom" &&
                    GetStringField(rst.Fields["nw:rout1:resourceno"]) != "")
                {
                    OutlookSystemItem osWipItem = new OutlookSystemItem();
                    item.Save();
                    uow.CommitChanges();

                    Item wipItem = osWipItem.CreateItemFromOutlookSystem(GetStringField(rst.Fields["nw:rout1:resourceno"]), uow, isOverride);

                    if (wipItem == null && isOverride == false)
                    {
                        item.UnconfirmItem();
                        item.Save();
                        uow.CommitChanges();
                        return null;
                    }

                    if (GetBoolField(rst.Fields["nw:rout1:resoption"]) == false)
                    {
                        // 只有一个流程 (非 电镀)
                        CreateRouteLine(item, 10, 0, GetStringField(rst.Fields["nw:rout1:type"]), GetStringField(rst.Fields["nw:rout1:type"]),
                            GetStringField(rst.Fields["nw:plating:plater"]), GetStringField(rst.Fields["nw:plating"]),  uow);

                        int routeQty = 1;
                        if (GetStringField(rst.Fields["nw:rout1:type"]) == "M")
                        {
                            routeQty = GetIntField(rst.Fields["nw:part:chr1"]);

                            if (routeQty == 0)
                                routeQty = 1;
                        }

                        CreateBomLine(item, wipItem, uow, routeQty);
                    }
                    else
                    {
                        // 相同加工部门
                        // P Route
                        RouteLine rLine = CreateRouteLine(item, 20, 0, GetStringField(rst.Fields["nw:rout1:type"]), GetStringField(rst.Fields["nw:rout1:type"]),
                            GetStringField(rst.Fields["nw:plating:plater"]), GetStringField(rst.Fields["nw:plating"]),  uow);

                        rLine.Save();

                        // M Route
                        RouteLine wipRouteLine = wipItem.GetFirstRouteLine();

                        if (wipRouteLine == null)
                            System.Diagnostics.Debug.Print("No WIP RouteLine");
                        else
                        {
                            RouteLine rLine2 = CreateRouteLine(item, 10, 20, wipRouteLine.WorkOper.WorkOperNo, wipRouteLine.WorkCenter.WorkCenterNo, "", "", uow);
                            rLine2.wipItem = wipItem;
                            rLine2.Save();
                        }
                        CreateBomLine(item, wipItem.BomLines[0].BomItem, uow, 1);

                    }
                }

                #endregion

                if (item.Source == Item.ItemSource.Make && item.RouteLines.Count == 0)
                {
                    if (item.PriceDiscs.Count > 0)
                        item.Source = Item.ItemSource.Buy;
                    else
                        item.Source = Item.ItemSource.None;

                }

                if (item.Source == Item.ItemSource.Buy && item.PriceDiscs.Count == 0)
                {
                    if (item.RouteLines.Count > 0)
                        item.Source = Item.ItemSource.Make;
                    else
                        item.Source = Item.ItemSource.None;

                }

                item.ConfirmItem();
                item.Save();
                uow.CommitChanges();
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(string.Format("产品 {0} 出现错误, 不能取出产品资料 \n {1}", itemNo, ex.Message));
                throw new Exception("不能成功取出产品资料");
            }

            return item;
        }
        private void SaveToExchange()
        {
            Logger.For(this).Info(string.Format("开始.  编码 : {0}", ItemNo));

            ADODB.Record Rec = new ADODB.Record();
            string Subject = string.Format("{0}_{1}", DateTime.Now.ToString("yyMMddhhmmss"), ItemNo);
            string StrSQL = string.Format("{0}{1}.eml", SZInvHisPath, Subject);

            Rec.Open(StrSQL, Type.Missing, ADODB.ConnectModeEnum.adModeReadWrite,
                 ADODB.RecordCreateOptionsEnum.adCreateNonCollection,
                 ADODB.RecordOpenOptionsEnum.adOpenRecordUnspecified,
                 "Namwah", "ParaW0rld");

            Rec.Fields["DAV:contentclass"].Value = "nw:content-classes:invHistory";
            Rec.Fields["urn:schemas:httpmail:subject"].Value = Subject;
            Rec.Fields["nw:partno"].Value = ItemNo;
            Rec.Fields["nw:partname"].Value = ItemName;
            Rec.Fields["nw:parttype"].Value = ItemType;
            Rec.Fields["nw:inv:refno"].Value = RefNo;
            Rec.Fields["nw:inv:reftype"].Value = "SS";
            Rec.Fields["nw:inv:totalqty"].Value = int.Parse(OKQty.ToString());
            Rec.Fields["nw:inv:sectionqty"].Value = OKQty.ToString();
            Rec.Fields["nw:inv:vendefectqty"].Value = int.Parse(VendDefectQty.ToString());
            Rec.Fields["nw:inv:defectqty"].Value = int.Parse(DefectQty.ToString());
            Rec.Fields["nw:inv:section"].Value = "";
            Rec.Fields["nw:inv:ok"].Value = "";
            Rec.Fields["nw:supplier"].Value = Supplier;
            Rec.Fields["nw:inv:remark"].Value = Remark;
            Rec.Fields["nw:inv:supplierdn"].Value = ProdOrderNo;
            Rec.Fields["nw:inv:status"].Value = Status;
            //Rec.Fields["urn:schemas:httpmail:fromname"].Value = CreatedBy;

            Rec.Fields["nw:inv:io"].Value = IOType.ToString();

            if (IOType == WHIOType.Input)
                Rec.Fields["http://schemas.microsoft.com/exchange/outlookmessageclass"].Value = "IPM.Post.invparts_szinput";
            else
                Rec.Fields["http://schemas.microsoft.com/exchange/outlookmessageclass"].Value = "IPM.Post.invparts_szoutput";

            Rec.Fields.Update();

            Logger.For(this).Info(string.Format("结束.  编码 : {0}", ItemNo));
        }