Exemplo n.º 1
0
        //Customer P/O Status
        public static string setCustomerPOStatus(mh_CustomerPODT dt)
        {
            var fullQty = dt.Qty * dt.PCSUnit;
            var Qty     = dt.Qty;

            if (dt.OutPlan == fullQty && dt.OutSO == Qty)
            {
                return("Waiting");
            }
            else if (dt.OutPlan == 0 && dt.OutSO == 0)
            {
                return("Completed");
            }
            else if (dt.OutPlan != fullQty || dt.OutSO != Qty)
            {
                return("Process");
            }
            else
            {
                return("Waiting");
            }
        }
Exemplo n.º 2
0
        void OpenImport(string filePath)
        {
            //MessageBox.Show(filePath);
            this.Cursor = Cursors.WaitCursor;
            try
            {
                using (TextFieldParser parser = new TextFieldParser(filePath, Encoding.GetEncoding("windows-874")))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(",");
                    int a = 0;
                    int c = 0;

                    int impCom = 0;
                    using (var db = new DataClasses1DataContext())
                    {
                        while (!parser.EndOfData)
                        {
                            a += 1;
                            string[] fields = parser.ReadFields();
                            c = 0;

                            string   CustomerNo      = "";
                            string   CustomerPONo    = "";
                            DateTime?OrderDate       = null;
                            string   Remark          = "";
                            DateTime?CustomerReqDate = null;
                            string   ItemNo          = "";
                            string   ItemName        = "";
                            decimal  OrderQty        = 0.00m;
                            string   UOM             = "";
                            decimal  PCSUnit         = 0.00m;
                            decimal  UnitPrice       = 0.00m;
                            decimal  Amnt            = 0.00m;
                            foreach (string field in fields)
                            {
                                c += 1;
                                if (a < 8)
                                {
                                    continue;
                                }
                                if (c == 4)
                                {
                                }
                                string f = field.ToSt().Trim();
                                switch (c)
                                {
                                case 2: CustomerNo = f; break;

                                case 3: CustomerPONo = f; break;

                                case 4: OrderDate = f.ToDateTime(); break;

                                case 5: Remark = f; break;

                                case 6: CustomerReqDate = f.ToDateTime(); break;

                                case 7: ItemNo = f; break;

                                case 8: ItemName = f; break;

                                case 9: OrderQty = f.ToDecimal(); break;

                                case 10: UOM = f; break;

                                case 11: PCSUnit = f.ToDecimal(); break;

                                case 12: UnitPrice = f.ToDecimal(); break;

                                case 13: Amnt = f.ToDecimal(); break;

                                default: break;
                                }
                            }
                            //check customerNo
                            var cstm = db.mh_Customers.Where(x => x.No == CustomerNo).FirstOrDefault();
                            if (cstm == null)
                            {
                                continue;
                            }
                            //check OrderDate
                            if (OrderDate == null)
                            {
                                continue;
                            }
                            //check CustomerReqDate
                            if (CustomerReqDate == null)
                            {
                                continue;
                            }
                            //Check ItemNo
                            var tool = db.mh_Items.Where(x => x.InternalNo == ItemNo).FirstOrDefault();
                            if (tool == null)
                            {
                                continue;
                            }
                            //Check Order Qty
                            if (OrderQty <= 0)
                            {
                                continue;
                            }
                            //Check UOM
                            var unit = db.mh_ItemUOMs.Where(x => x.ItemNo == ItemNo && x.UOMCode == UOM).FirstOrDefault();
                            if (unit == null)
                            {
                                continue;
                            }
                            //check PCSUnit
                            if (PCSUnit <= 0)
                            {
                                PCSUnit = unit.QuantityPer;
                            }

                            Amnt = Math.Round(OrderQty * UnitPrice, 2);

                            //add to CustomerPO
                            var cstmPo = db.mh_CustomerPOs.Where(x => x.CustomerNo == CustomerNo && x.CustomerPONo == CustomerPONo).FirstOrDefault();
                            if (cstmPo == null)
                            {
                                cstmPo = new mh_CustomerPO();
                                db.mh_CustomerPOs.InsertOnSubmit(cstmPo);
                            }
                            cstmPo.Active       = true;
                            cstmPo.CreateBy     = Classlib.User;
                            cstmPo.CreateDate   = DateTime.Now;
                            cstmPo.CustomerNo   = CustomerNo;
                            cstmPo.CustomerPONo = CustomerPONo;
                            cstmPo.DemandType   = 0; //Customer P/O
                            cstmPo.OrderDate    = OrderDate.Value.Date;
                            cstmPo.Remark       = Remark;
                            cstmPo.UpdateBy     = Classlib.User;
                            cstmPo.UpdateDate   = DateTime.Now;
                            db.SubmitChanges();

                            //add to Customer PO Dt
                            decimal allQ     = Math.Round(OrderQty * PCSUnit, 2);
                            var     cstmpoDt = new mh_CustomerPODT
                            {
                                Active            = true,
                                Amount            = Amnt,
                                forSafetyStock    = false,
                                genPR             = false,
                                idCustomerPO      = cstmPo.id,
                                ItemName          = ItemName,
                                ItemNo            = ItemNo,
                                OutPlan           = OrderQty,
                                OutQty            = allQ,
                                OutSO             = OrderQty,
                                PCSUnit           = PCSUnit,
                                Qty               = OrderQty,
                                Remark            = "",
                                ReplenishmentType = tool.ReplenishmentType,
                                ReqDate           = CustomerReqDate.Value.Date,
                                ReqReceiveDate    = CustomerReqDate.Value.Date,
                                Status            = "Waiting",
                                UnitPrice         = UnitPrice,
                                UOM               = UOM,
                            };
                            db.mh_CustomerPODTs.InsertOnSubmit(cstmpoDt);
                            db.SubmitChanges();

                            impCom++;
                        }
                    }

                    if (impCom > 0)
                    {
                        baseClass.Info($"Improt Data({impCom}) completes.\n");
                    }
                }
            }
            catch (Exception ex)
            {
                baseClass.Error(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }