Ejemplo n.º 1
0
        private void BwInsert_DoWork(object sender, DoWorkEventArgs e)
        {
            var par                       = e.Argument as object[];
            var osmCheckCurrent           = par[0] as OutsoleMaterialCheckingModel;
            var currentOSMCheckListBySupp = par[1] as List <OutsoleMaterialCheckingModel>;

            try
            {
                OutsoleMaterialCheckingController.Insert(osmCheckCurrent);
                // Update Reject to WHMasterFile.
                var osMaterialCheckByPO = OutsoleMaterialCheckingController.SelectByPOSumBySize(osmCheckCurrent.ProductNo).ToList();
                foreach (var sizeRun in sizeRunList)
                {
                    var osMaterialCheckByPOBySupplier = osMaterialCheckByPO.Where(w => w.OutsoleSupplierId == osmCheckCurrent.OutsoleSupplierId).ToList();

                    var sizeCompare      = String.IsNullOrEmpty(sizeRun.OutsoleSize) == false ? sizeRun.OutsoleSize : sizeRun.SizeNo;
                    var osMatCheckBySize = osMaterialCheckByPOBySupplier.FirstOrDefault(f => f.SizeNo == sizeCompare);

                    int rejectUpdate = 0;
                    if (osMatCheckBySize != null)
                    {
                        rejectUpdate = osMatCheckBySize.Reject - osMatCheckBySize.ReturnReject > 0 ? osMatCheckBySize.Reject - osMatCheckBySize.ReturnReject : 0;
                    }
                    var osMaterialUpdate = new OutsoleMaterialModel()
                    {
                        ProductNo         = osmCheckCurrent.ProductNo,
                        OutsoleSupplierId = osmCheckCurrent.OutsoleSupplierId,
                        SizeNo            = sizeRun.SizeNo,
                        QuantityReject    = rejectUpdate
                    };
                    OutsoleMaterialController.UpdateByOSCheck(osMaterialUpdate);
                }

                // Tranfer to mainwindow sum order by size
                // Update current list
                currentOSMCheckListBySupp.RemoveAll(r => r.SizeNo == osmCheckCurrent.SizeNo &&
                                                    r.CheckingDate == osmCheckCurrent.CheckingDate &&
                                                    r.WorkingCard == osmCheckCurrent.WorkingCard);

                currentOSMCheckListBySupp.Add(osmCheckCurrent);
                if (modeReject == false && modeReturnReject == false)
                {
                    osmCheckCurrent.Quantity = currentOSMCheckListBySupp.Where(w => w.SizeNo == osmCheckCurrent.SizeNo &&
                                                                               w.CheckingDate == osmCheckCurrent.CheckingDate).Sum(s => s.Quantity);
                }
                else if (modeReject == true && modeReturnReject == false)
                {
                    osmCheckCurrent.Reject = currentOSMCheckListBySupp.Where(w => w.SizeNo == osmCheckCurrent.SizeNo &&
                                                                             w.CheckingDate == osmCheckCurrent.CheckingDate).Sum(s => s.Reject);
                }
                if (modeReturnReject == true)
                {
                    osmCheckCurrent.ReturnReject = currentOSMCheckListBySupp.Where(w => w.SizeNo == osmCheckCurrent.SizeNo &&
                                                                                   w.CheckingDate == osmCheckCurrent.CheckingDate).Sum(s => s.ReturnReject);
                }
                outsoleMaterialCheckingUpdatedBySizeList.Add(osmCheckCurrent);
            }
            catch
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    MessageBox.Show("An error occured when execute data !\nPlease try again !", this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                }));
            }
        }