Beispiel #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (validationResult() == true)
            {
                var    demandMaster = dbContext.ItemDemandMaster.Find(_itemDemandMasterId);
                double quantity     = Convert.ToDouble(txtQuantity.EditValue == "" ? 0 : txtQuantity.EditValue);
                if (_stockDetailId == 0)
                {
                    string barcode            = BarcodeHelper.BarcodeVerify(txtBarcode.EditValue.ToString());
                    var    barcodeStockDetail = StockHelper.GetBarcodeStocksWithStore(barcode, (int)lueStore.EditValue);
                    if (barcodeStockDetail == null)
                    {
                        MessageBox.Show("Ürün Bulunamadı !");
                        txtBarcode.EditValue = "";
                        txtBarcode.Focus();
                        return;
                    }
                    var stockDetail = new StockDetail();
                    stockDetail.STOCKDETAIL_BARCODE_ID = barcode;
                    stockDetail.STOCKDETAIL_MASTER_ID  = _stockMasterId;
                    stockDetail.STOCKDETAIL_STORE_ID   = (int)lueStore.EditValue;
                    stockDetail.STOCKDETAIL_ITEM_ID    = barcodeStockDetail.STOCKDETAIL_ITEM_ID;
                    stockDetail.STOCKDETAIL_RACK_ID    = barcodeStockDetail.STOCKDETAIL_RACK_ID;
                    stockDetail.STOCKDETAIL_QUANTITY   = quantity * -1;
                    dbContext.StockDetail.Add(stockDetail);
                    dbContext.SaveChanges();

                    var stockDetailSecond = new StockDetail();
                    stockDetailSecond.STOCKDETAIL_BARCODE_ID    = barcode;
                    stockDetailSecond.STOCKDETAIL_MASTER_ID     = _stockMasterId;
                    stockDetailSecond.STOCKDETAIL_STORE_ID      = demandMaster.Project.Company.COMPANY_STORE_ID.Value;
                    stockDetailSecond.STOCKDETAIL_ITEM_ID       = barcodeStockDetail.STOCKDETAIL_ITEM_ID;
                    stockDetailSecond.STOCKDETAIL_RACK_ID       = barcodeStockDetail.STOCKDETAIL_RACK_ID;
                    stockDetailSecond.STOCKDETAIL_QUANTITY      = quantity;
                    stockDetailSecond.STOCKDETAIL_PRIVATEVALUE1 = string.IsNullOrEmpty(txtCableStart.Text) ? 0 : (double)txtCableStart.EditValue;
                    stockDetailSecond.STOCKDETAIL_PRIVATEVALUE2 = string.IsNullOrEmpty(txtCableEnd.Text) ? 0 : (double)txtCableEnd.EditValue;
                    stockDetailSecond.STOCKDETAIL_REF_ID        = stockDetail.ID;
                    dbContext.StockDetail.Add(stockDetailSecond);
                    dbContext.SaveChanges();
                }
                else
                {
                    var existStockDetail = dbContext.StockDetail.FirstOrDefault(x => x.ID == _stockDetailId);
                    existStockDetail.STOCKDETAIL_QUANTITY = quantity * -1;
                    var existStockDetailSecond = dbContext.StockDetail.FirstOrDefault(x => x.STOCKDETAIL_REF_ID == _stockDetailId);
                    existStockDetailSecond.STOCKDETAIL_QUANTITY      = quantity;
                    existStockDetailSecond.STOCKDETAIL_PRIVATEVALUE1 = string.IsNullOrEmpty(txtCableStart.Text) ? 0 : (double)txtCableStart.EditValue;
                    existStockDetailSecond.STOCKDETAIL_PRIVATEVALUE2 = string.IsNullOrEmpty(txtCableEnd.Text) ? 0 : (double)txtCableEnd.EditValue;
                    dbContext.SaveChanges();
                }
                ClearControl();
            }
        }