public static bool Insert(OSMaterialBorrowModel model)
        {
            var @OSCheckingID    = new SqlParameter("@OSCheckingID", model.OSCheckingId);
            var @ProductNoBorrow = new SqlParameter("@ProductNoBorrow", model.ProductNoBorrow);
            var @QuantityBorrow  = new SqlParameter("@QuantityBorrow", model.QuantityBorrow);

            using (var db = new SaovietMasterScheduleEntities())
            {
                if (db.ExecuteStoreCommand("EXEC spm_InsertOSMaterialBorrow @OSCheckingID, @ProductNoBorrow, @QuantityBorrow", @OSCheckingID, @ProductNoBorrow, @QuantityBorrow) >= 1)
                {
                    return(true);
                }
                return(false);
            }
        }
        public static bool Update(OSMaterialBorrowModel model)
        {
            var @Id = new SqlParameter("@Id", model.Id);
            var @ProductNoBorrow = new SqlParameter("@ProductNoBorrow", model.ProductNoBorrow);
            var @QuantityBorrow  = new SqlParameter("@QuantityBorrow", model.QuantityBorrow);

            using (var db = new SaovietMasterScheduleEntities())
            {
                if (db.ExecuteStoreCommand("EXEC spm_UpdateOSMaterialBorrow @Id, @ProductNoBorrow, @QuantityBorrow", @Id, @ProductNoBorrow, @QuantityBorrow) >= 1)
                {
                    return(true);
                }
                return(false);
            }
        }
Exemplo n.º 3
0
        private void btnBorrow_Click(object sender, RoutedEventArgs e)
        {
            var po      = oswhCheckList.FirstOrDefault().ProductNo;
            var poInput = txtProductNo.Text.Trim().ToUpper().ToString();

            int    qtyInput       = 0;
            string qtyInputString = txtQuantity.Text.Trim().ToUpper().ToString();

            Int32.TryParse(qtyInputString, out qtyInput);

            if (string.IsNullOrEmpty(poInput))
            {
                MessageBox.Show(string.Format("PO {0} is invalid !\nĐơn hàng không hợp lệ!", poInput), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                txtProductNo.Focus();
                return;
            }

            if (po.ToUpper().ToString() == poInput)
            {
                MessageBox.Show(string.Format("PO {0} duplicated !\nĐơn hàng bị trùng!", poInput), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                txtProductNo.Focus();
                return;
            }

            var osCheckingByPOList = new List <OutsoleMaterialCheckingModel>();
            var osMaterialBorrowed = new List <OSMaterialBorrowModel>();

            try
            {
                if (qtyInput == 0)
                {
                    goto TheEnd;
                }

                osCheckingByPOList = OutsoleMaterialCheckingController.SelectByPO(poInput).Where(w => w.OutsoleSupplierId == supplier.OutsoleSupplierId).ToList();
                if (osCheckingByPOList.Count() == 0)
                {
                    MessageBox.Show(string.Format("PO {0} is invalid !\nĐơn hàng không hợp lệ!", poInput), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtProductNo.Focus();
                    return;
                }
                //osCheckingBorrowedByPOList  = OutsoleMaterialCheckingController.SelectByPOBorrow(poInput).Where(w => w.OutsoleSupplierId == supplier.OutsoleSupplierId).ToList();
                osMaterialBorrowed = OSMaterialBorrowController.GetByPO(poInput).Where(w => w.OSCheckingId == osCheckingId).ToList();
                var qtyBorrowed  = osMaterialBorrowed.Sum(s => s.QuantityBorrow);
                var qtyCanBorrow = osCheckingByPOList.Where(w => w.SizeNo == sizeBorrow).Sum(s => s.Quantity + s.ReturnReject);
                var totalReject  = oswhCheckBySupplier.Where(w => w.SizeNo == sizeBorrow).Sum(s => s.Reject);
                var qtyCanInput  = qtyCanBorrow - qtyBorrowed;

                if (qtyInput + qtyBorrowed > totalReject)
                {
                    goto TheEnd;
                }
                if (qtyInput > qtyCanInput)
                {
                    goto TheEnd;
                }

                if (MessageBox.Show($"Confirm borrow {qtyInput} pairs size: #{sizeBorrow} from PO: {poInput} ?\nXác nhận mượn Outsole Material", this.Title, MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK)
                {
                    txtQuantity.Focus();
                    return;
                }

                // Update Record DB
                var borrowItem = new OSMaterialBorrowModel
                {
                    OSCheckingId    = osCheckingId,
                    ProductNoBorrow = poInput,
                    QuantityBorrow  = qtyInput
                };
                OSMaterialBorrowController.Insert(borrowItem);
                //oswhBorrowedList = OSMaterialBorrowController.GetByOSCheckingId(osCheckingId);
                oswhAfterBorrow = OutsoleMaterialCheckingController.SelectByPO_1(poTransfer).Where(w => w.OutsoleSupplierId == supplier.OutsoleSupplierId).ToList();

                this.Close();
                return;

TheEnd:
                {
                    MessageBox.Show(string.Format("Quantity is invalid !\nSố lượng không hợp lệ!"), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtQuantity.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{ex.InnerException.Message}", this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                txtProductNo.Focus();
                return;
            }
        }