Пример #1
0
        private void dgAccessoriesInfor_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var cellClicked = dgAccessoriesInfor.CurrentCell;
            var rowClicked  = dgAccessoriesInfor.CurrentItem as MaterialPlanModel;

            if (cellClicked == null || rowClicked == null)
            {
                return;
            }
            if (!cellClicked.Column.Equals(colSupplier))
            {
                return;
            }

            supplierClicked      = supplierAccessoriesList.FirstOrDefault(f => f.SupplierId.Equals(rowClicked.SupplierId));
            materialPlanChecking = rowClicked;

            if (string.IsNullOrEmpty(workerId) && account.MaterialDelivery)
            {
                popInputWorkerId.IsOpen = true;
                txtWorkerId.Focus();
                txtWorkerId.SelectAll();
            }
            else
            {
                LoadSupplierClicked();
            }
        }
        public static bool Delete(MaterialPlanModel model)
        {
            var @ProductNo  = new SqlParameter("@ProductNo", model.ProductNo);
            var @SupplierId = new SqlParameter("@SupplierId", model.SupplierId);

            using (var db = new SaovietMasterScheduleEntities())
            {
                if (db.ExecuteStoreCommand("EXEC spm_DeleteMaterialPlanByPOBySupplier @ProductNo, @SupplierId", @ProductNo, @SupplierId) > 0)
                {
                    return(true);
                }
                return(false);
            }
        }
        public static bool UpdateRejectWhenInspect(MaterialPlanModel model)
        {
            var @ProductNo  = new SqlParameter("@ProductNo", model.ProductNo);
            var @SupplierId = new SqlParameter("@SupplierId", model.SupplierId);

            using (var db = new SaovietMasterScheduleEntities())
            {
                if (db.ExecuteStoreCommand("EXEC spm_UpdateRejectWhenInspectUpperAccesoriesMaterial @ProductNo, @SupplierId",
                                           @ProductNo, @SupplierId) > 0)
                {
                    return(true);
                }
                return(false);
            }
        }
        public AddMaterialPlanForProductNoWindow(string productNo, List <SupplierModel> supplierAccessoriesList, MaterialPlanModel matsSubmit, List <MaterialPlanModel> matsPlanCurrentList)
        {
            this.supplierAccessoriesList = supplierAccessoriesList;
            this.productNo           = productNo;
            this.matsSubmit          = matsSubmit;
            this.matsPlanCurrentList = matsPlanCurrentList;

            bwInsert                     = new BackgroundWorker();
            bwInsert.DoWork             += BwInsert_DoWork;
            bwInsert.RunWorkerCompleted += BwInsert_RunWorkerCompleted;

            InitializeComponent();

            this.Title = this.Title + " - " + productNo;
        }
        public AddRejectForMaterialWindow(List <RejectModel> rejectUpperAccessoriesList, SizeRunModel sizeRunClicked, MaterialPlanModel materialPlanChecking, DataRowView rowEditting, List <MaterialInspectModel> deliveryCurrentList, int totalRejectCurrent, string workerId, List <SizeRunModel> sizeRunList)
        {
            this.rejectUpperAccessoriesList = rejectUpperAccessoriesList;
            this.sizeRunClicked             = sizeRunClicked;
            this.materialPlanChecking       = materialPlanChecking;
            this.rowEditting        = rowEditting;
            this.inspectListCurrent = deliveryCurrentList;
            this.totalRejectCurrent = totalRejectCurrent;
            this.workerId           = workerId;
            this.sizeRunList        = sizeRunList;
            bwUpload                     = new BackgroundWorker();
            bwUpload.DoWork             += BwUpload_DoWork;
            bwUpload.RunWorkerCompleted += BwUpload_RunWorkerCompleted;

            rejectClickedList    = new List <RejectModel>();
            inspectListHasReject = new List <MaterialInspectModel>();
            dtReject             = new DataTable();
            InitializeComponent();
        }
        private void BwInsert_DoWork(object sender, DoWorkEventArgs e)
        {
            var par            = e.Argument as object[];
            var suppSelected   = par[0] as SupplierModel;
            var etdPicked      = (DateTime)par[1];
            var remarks        = par[2] as String;
            var materialRevise = new MaterialPlanModel()
            {
                ProductNo          = productNo,
                SupplierId         = suppSelected.SupplierId,
                Name               = suppSelected.Name,
                ProvideAccessories = suppSelected.ProvideAccessories,
                Remarks            = remarks,
                ETD        = etdPicked,
                ActualDate = matsSubmit != null ? matsSubmit.ActualDate : new DateTime(2000, 01, 01)
            };

            try
            {
                if (runMode == EExcute.AddNew)
                {
                    MaterialPlanController.Insert(materialRevise, isUpdateActualDate: false);
                }
                else if (runMode == EExcute.Update)
                {
                    MaterialPlanController.Update(matsSubmit.ProductNo, matsSubmit.SupplierId, materialRevise);
                }
                else if (runMode == EExcute.Delete)
                {
                    MaterialPlanController.Delete(materialRevise);
                }
                materialUpdate = materialRevise as MaterialPlanModel;
                runModeRespone = runMode;
                e.Result       = true;
            }
            catch (Exception ex)
            {
                e.Result = false;
                Dispatcher.Invoke(new Action(() => {
                    MessageBox.Show(ex.Message.ToString());
                }));
            }
        }
        public static bool Update(string productNoOld, int supplierIdOld, MaterialPlanModel model)
        {
            //
            var @ProductNoOld  = new SqlParameter("@ProductNoOld", productNoOld);
            var @SupplierIdOld = new SqlParameter("@SupplierIdOld", supplierIdOld);
            var @ProductNo     = new SqlParameter("@ProductNo", model.ProductNo);
            var @SupplierId    = new SqlParameter("@SupplierId", model.SupplierId);
            var @ETD           = new SqlParameter("@ETD", model.ETD);
            var @Remarks       = new SqlParameter("@Remarks", model.Remarks);

            using (var db = new SaovietMasterScheduleEntities())
            {
                if (db.ExecuteStoreCommand("EXEC spm_UpdateMaterialPlanByPOBySupplier @ProductNoOld, @SupplierIdOld, @ProductNo, @SupplierId, @ETD, @Remarks", @ProductNoOld, @SupplierIdOld, @ProductNo, @SupplierId, @ETD, @Remarks) > 0)
                {
                    return(true);
                }
                return(false);
            }
        }
        public static bool Insert(MaterialPlanModel model, bool isUpdateActualDate)
        {
            var @ProductNo          = new SqlParameter("@ProductNo", model.ProductNo);
            var @SupplierId         = new SqlParameter("@SupplierId", model.SupplierId);
            var @ETD                = new SqlParameter("@ETD", model.ETD);
            var @Remarks            = new SqlParameter("@Remarks", model.Remarks);
            var @ActualDate         = new SqlParameter("@ActualDate", model.ActualDate);
            var @IsUpdateActualDate = new SqlParameter("@IsUpdateActualDate", isUpdateActualDate);

            using (var db = new SaovietMasterScheduleEntities())
            {
                if (db.ExecuteStoreCommand("EXEC spm_InsertMaterialPlan @ProductNo, @SupplierId, @ETD, @Remarks, @ActualDate, @IsUpdateActualDate",
                                           @ProductNo, @SupplierId, @ETD, @Remarks, @ActualDate, @IsUpdateActualDate) > 0)
                {
                    return(true);
                }
                return(false);
            }
        }
        //
        public static bool UpdatePlanWhenDelivery(MaterialPlanModel model)
        {
            var @ProductNo          = new SqlParameter("@ProductNo", model.ProductNo);
            var @SupplierId         = new SqlParameter("@SupplierId", model.SupplierId);
            var @ActualDeliveryDate = new SqlParameter("@ActualDeliveryDate", model.ActualDeliveryDate);
            var @ETDPO            = new SqlParameter("@ETDPO", model.ETDPO);
            var @BalancePO        = new SqlParameter("@BalancePO", model.BalancePO);
            var @RejectPO         = new SqlParameter("@RejectPO", model.RejectPO);
            var @ActualDeliveryPO = new SqlParameter("@ActualDeliveryPO", model.ActualDeliveryPO);

            using (var db = new SaovietMasterScheduleEntities())
            {
                if (db.ExecuteStoreCommand("EXEC spm_UpdateMaterialPlanWhenDelivery @ProductNo, @SupplierId, @ActualDeliveryDate, @ETDPO, @BalancePO, @RejectPO, @ActualDeliveryPO",
                                           @ProductNo, @SupplierId, @ActualDeliveryDate, @ETDPO, @BalancePO, @RejectPO, @ActualDeliveryPO) > 0)
                {
                    return(true);
                }
                return(false);
            }
        }
        private void BwReadExcel_DoWork(object sender, DoWorkEventArgs e)
        {
            Dispatcher.Invoke(new Action(() =>
            {
                txtStatus.Text = "Reading ...";
            }));
            int filePathIndex = 1;

            foreach (string filePath in filePathArray)
            {
                Excel.Application excelApplication = new Excel.Application();
                Excel.Workbook    excelWorkbook    = excelApplication.Workbooks.Open(filePath);
                Excel.Worksheet   excelWorksheet;
                Excel.Range       excelRange;
                try
                {
                    excelWorksheet = (Excel.Worksheet)excelWorkbook.Worksheets[1];
                    excelRange     = excelWorksheet.UsedRange;

                    var upperAccessoriesSuppliersList = supplierList.Where(w => String.IsNullOrEmpty(w.ProvideAccessories) == false).ToList();
                    int pgValue = 2;
                    Dispatcher.Invoke(new Action(() =>
                    {
                        prgStatus.Maximum = excelRange.Rows.Count;
                    }));
                    for (int r = 2; r <= excelRange.Rows.Count; r++)
                    {
                        var accessoriesNameCell = excelRange[r, 1].Value2;
                        var supplierNameCell    = excelRange[r, 2].Value2;
                        var productNoCell       = excelRange[r, 3].Value2;
                        var etdCell             = excelRange[r, 4].Value2;

                        string accessoriesName = accessoriesNameCell != null?accessoriesNameCell.ToString() : "";

                        string supplierName = supplierNameCell != null?supplierNameCell.ToString() : "";

                        string etd = etdCell != null?etdCell.ToString() : "";

                        string productNo = productNoCell != null?productNoCell.ToString() : "";

                        if (productNoCell != null)
                        {
                            // Ignore Error Cell
                            if (String.IsNullOrEmpty(accessoriesName) ||
                                String.IsNullOrEmpty(supplierName))
                            {
                                Dispatcher.Invoke(new Action(() =>
                                {
                                    MessageBox.Show(String.Format("Supplier or Accessories Name is empty\nRows {0} !", r), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                                }));
                                break;
                            }
                            var checkSupplier = upperAccessoriesSuppliersList.FirstOrDefault(f => f.ProvideAccessories.ToUpper().Equals(accessoriesName.Trim().ToUpper()) &&
                                                                                             f.Name.ToUpper().Equals(supplierName.Trim().ToUpper()));

                            if (checkSupplier == null)
                            {
                                Dispatcher.Invoke(new Action(() =>
                                {
                                    MessageBox.Show(String.Format("Supplier: {0} {1}\nDoes not exist in system, Please Check again !\nRow: {2}", accessoriesName, supplierName, r), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                                }));
                                break;
                            }

                            double etdDouble = 0;
                            Double.TryParse(etd, out etdDouble);
                            var etdDate      = etdDouble > 0 ? DateTime.FromOADate(etdDouble) : new DateTime(2000, 01, 01);
                            var materialPlan = new MaterialPlanModel {
                                SupplierId         = checkSupplier.SupplierId,
                                ProductNo          = productNo,
                                ETD                = etdDate,
                                Name               = checkSupplier.Name,
                                ProvideAccessories = checkSupplier.ProvideAccessories,
                                ActualDate         = new DateTime(2000, 01, 01),
                                Remarks            = ""
                            };
                            materialPlanList.Add(materialPlan);
                        }

                        Dispatcher.Invoke(new Action(() =>
                        {
                            txtStatus.Text  = String.Format("Reading PO: {0}   file: {1} / {2}", productNo, filePathIndex, filePathArray.Count());
                            prgStatus.Value = pgValue;
                        }));
                        pgValue++;
                    }
                }
                catch
                {
                }
                finally
                {
                    excelWorkbook.Close(false, Missing.Value, Missing.Value);
                    excelApplication.Quit();
                }
                filePathIndex++;
            }
        }