コード例 #1
0
        private void btnReplace_Click(object sender, EventArgs e)
        {
            db = new db_MiletecDataContext();
            if (txtNoofDamages.Text != "Damages (Quanity)" && txtDeliveryNo.Text != "Delivery No." && txtTransactionID.Text != "Transaction ID")
            {
                var query_StockQty = db.sp_RetrieveStocksQuantity(txtproductid.Text, productName);
                foreach (sp_RetrieveStocksQuantityResult entry in query_StockQty.ToList())
                {
                    productID  = entry.productid.ToString();
                    qtyLeft    = int.Parse(entry.availqty.ToString());
                    qtydamages = qtyLeft - int.Parse(txtNoofDamages.Text);

                    if (txtproductid.Text == productID)
                    {
                        db.sp_Update_StocksQty(txtproductid.Text, qtydamages);
                    }
                }

                if (qtyLeft >= int.Parse(txtNoofDamages.Text))
                {
                    if (Convert.ToInt32(txtNoofDamages.Text) > Convert.ToInt32(dgvTransactionDetails.CurrentRow.Cells[4].Value.ToString()))
                    {
                        MessageBox.Show("Quantity is larger than the ordered quantity");
                    }
                    else
                    {
                        MessageBox.Show("Damaged product replaced!!", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);


                        db.sp_insert_DamagesAndReplacement(txtReplacementNo.Text, txtTransactionID.Text, txtDeliveryNo.Text, txtproductid.Text, productName, DateTime.Now, int.Parse(txtNoofDamages.Text));
                        dgvReplacements.Rows.Add(txtproductid.Text, productName, txtNoofDamages.Text);
                    }
                }


                else if (qtyLeft < int.Parse(txtNoofDamages.Text))
                {
                    var query_StockQty1 = db.sp_RetrieveStocksQuantity(txtproductid.Text, productName);
                    foreach (sp_RetrieveStocksQuantityResult entry in query_StockQty1.ToList())
                    {
                        productID  = entry.productid.ToString();
                        qtyLeft    = int.Parse(entry.availqty.ToString());
                        qtydamages = qtyLeft + int.Parse(txtNoofDamages.Text);

                        if (txtproductid.Text == productID)
                        {
                            db.sp_Update_StocksQty(txtproductid.Text, qtydamages);
                        }
                    }
                    MessageBox.Show("Low Stocks");
                }
            }
            else
            {
                MessageBox.Show("Please fill up everything first!!", "NOTE", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }