Exemplo n.º 1
0
        private void btnAddToTransaction_Click(object sender, EventArgs e)
        {
            if (ValidateTransactionDetails())
            {
                DataRowView drProduct;
                DataRowView drWareHouse;
                drProduct = cmbProducts.SelectedItem as DataRowView;
                int ProductID = Convert.ToInt32(drProduct.Row["ProductID"]);

                drWareHouse = cmbWareHouse.SelectedItem as DataRowView;
                int WareHouseID = Convert.ToInt32(drWareHouse.Row["WareHouseID"]);

                Decimal TransactCost     = Convert.ToDecimal(txtCost.Text.Trim());
                Decimal TransactQuantity = Convert.ToDecimal(txtQuantity.Text.Trim());

                InventoryStoreDataSetTableAdapters.tblInventoryTableAdapter adp = new InventoryStoreDataSetTableAdapters.tblInventoryTableAdapter();
                InventoryStoreDataSet.tblInventoryDataTable dtInventory         = adp.GetDataByProductAndWareHouse(ProductID, WareHouseID);

                TransactionDataSet.TransactionDetailsRow drTransactionDetail = dtTransactionDetails.NewTransactionDetailsRow();
                drTransactionDetail.ProductID         = ProductID;
                drTransactionDetail.ProductName       = drProduct.Row["ProductName"].ToString();
                drTransactionDetail.Manufacturer      = drProduct.Row["Manufacturer"].ToString();
                drTransactionDetail.FromWareHouseID   = WareHouseID;
                drTransactionDetail.FromWareHouseName = drWareHouse.Row["WareHouseName"].ToString();
                drTransactionDetail.SetToWareHouseIDNull();
                drTransactionDetail.SetToWareHouseNameNull();
                drTransactionDetail.TransactQuantity = TransactQuantity;
                drTransactionDetail.TransactCost     = TransactCost;
                drTransactionDetail.TotalCost        = TransactCost * TransactQuantity;
                drTransactionDetail.TransactionID    = 0;
                dtTransactionDetails.AddTransactionDetailsRow(drTransactionDetail);

                foreach (InventoryStoreDataSet.tblInventoryRow drInventory in dtInventory.Rows)
                {
                    Decimal OldQty = drInventory.Quantity;
                    TransactionDataSet.TransactionStockInformationRow drTransactionStockInformation = dtTransactionStockInformation.NewTransactionStockInformationRow();
                    drTransactionStockInformation.Cost                = drInventory.Cost;
                    drTransactionStockInformation.OldQuantity         = OldQty;
                    drTransactionStockInformation.NewQuantity         = (TransactQuantity > OldQty) ? 0 : OldQty - TransactQuantity;
                    drTransactionStockInformation.TransactionDetailID = drTransactionDetail.TransactionDetailID;
                    drTransactionStockInformation.TransactQuantity    = (TransactQuantity > OldQty) ? OldQty : TransactQuantity;
                    drTransactionStockInformation.IsFromWareHouse     = true;
                    dtTransactionStockInformation.AddTransactionStockInformationRow(drTransactionStockInformation);

                    if (TransactQuantity > OldQty)
                    {
                        TransactQuantity = TransactQuantity - OldQty;
                    }
                    else
                    {
                        TransactQuantity = 0;
                    }
                }

                dgvTransactionDetails.Refresh();
            }
        }
Exemplo n.º 2
0
        private void btnAddToTransaction_Click(object sender, EventArgs e)
        {
            if (ValidateTransactionDetails())
            {
                DataRowView drProduct;
                DataRowView drWareHouse;
                drProduct = cmbProducts.SelectedItem as DataRowView;
                int ProductID = Convert.ToInt32(drProduct.Row["ProductID"]);

                drWareHouse = cmbWareHouse.SelectedItem as DataRowView;
                int WareHouseID = Convert.ToInt32(drWareHouse.Row["WareHouseID"]);

                Decimal TransactCost     = Convert.ToDecimal(txtCost.Text.Trim());
                Decimal TransactQuantity = Convert.ToDecimal(txtQuantity.Text.Trim());

                InventoryStoreDataSetTableAdapters.tblInventoryTableAdapter adp = new InventoryStoreDataSetTableAdapters.tblInventoryTableAdapter();
                Decimal OldQty = Convert.ToDecimal(adp.GetQuantity(ProductID, WareHouseID, TransactCost));

                TransactionDataSet.TransactionDetailsRow          drTransactionDetail           = dtTransactionDetails.NewTransactionDetailsRow();
                TransactionDataSet.TransactionStockInformationRow drTransactionStockInformation = dtTransactionStockInformation.NewTransactionStockInformationRow();

                drTransactionDetail.ProductID         = ProductID;
                drTransactionDetail.ProductName       = drProduct.Row["ProductName"].ToString();
                drTransactionDetail.Manufacturer      = drProduct.Row["Manufacturer"].ToString();
                drTransactionDetail.FromWareHouseID   = WareHouseID;
                drTransactionDetail.FromWareHouseName = drWareHouse.Row["WareHouseName"].ToString();
                drTransactionDetail.SetToWareHouseIDNull();
                drTransactionDetail.SetToWareHouseNameNull();
                drTransactionDetail.TransactQuantity = TransactQuantity;
                drTransactionDetail.TransactCost     = TransactCost;
                drTransactionDetail.TotalCost        = TransactCost * TransactQuantity;
                drTransactionDetail.TransactionID    = 0;
                //Object objTrID = dt.Compute("MAX(TransactionDetailID)", "");
                //tr.TransactionDetailID = Convert.ToInt32(objTrID == DBNull.Value ? 0 : objTrID) + 1;
                dtTransactionDetails.AddTransactionDetailsRow(drTransactionDetail);

                drTransactionStockInformation.Cost                = TransactCost;
                drTransactionStockInformation.OldQuantity         = OldQty;
                drTransactionStockInformation.NewQuantity         = OldQty + TransactQuantity;
                drTransactionStockInformation.TransactionDetailID = drTransactionDetail.TransactionDetailID;
                drTransactionStockInformation.TransactQuantity    = TransactQuantity;
                drTransactionStockInformation.IsFromWareHouse     = true;
                dtTransactionStockInformation.AddTransactionStockInformationRow(drTransactionStockInformation);

                dgvTransactionDetails.Refresh();
            }
        }