Пример #1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textPuchasesOrderNo.Text.Trim()))
            {
                Common.MessageAlert("First enter Purchases Order No");
                return;
            }
            if (dataGridView1.Rows.Count - 1 < 0)
            {
                Common.MessageAlert("First Enter Item Detail");
                return;
            }

            SQLHelper      objSQLHelper      = new SQLHelper();
            SqlTransaction objSqlTransaction = objSQLHelper.BeginTrans();

            try
            {
                PurchaseOrderEL        objPurchaseOrderEL  = new PurchaseOrderEL();
                PurchaseOrderDL        objPurchasesOrderDL = new PurchaseOrderDL();
                PurchasesOrderDetailEL objPurchasesOrderDetailEL;
                PurchasesOrderDetailDL objPurchasesOrderDetailDL = new PurchasesOrderDetailDL();

                objPurchaseOrderEL.Company_id         = companyEL.Company_id;
                objPurchaseOrderEL.Purchases_Order_Id = SelectedPurchasesOrder.Purchases_Order_Id;
                objPurchaseOrderEL.Purchases_Order_No = textPuchasesOrderNo.Text.Trim();
                objPurchaseOrderEL.Date = dateTimePickerPurchasesOrderDate.Value;
                objPurchasesOrderDL.Update(objSqlTransaction, objPurchaseOrderEL);

                List <PurchasesOrderDetailEL> lstUpdatigPurchasesOrderDetailEL = new List <PurchasesOrderDetailEL>();
                List <PurchasesOrderDetailEL> lstAddingPurchasesOrderDetailEL  = new List <PurchasesOrderDetailEL>();
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    objPurchasesOrderDetailEL = new PurchasesOrderDetailEL();
                    //objPurchasesOrderDetailEL.Item_Name = dataGridView1.Rows[i].Cells["Item_Name"].Value.ToString().Trim();
                    objPurchasesOrderDetailEL.Item_id       = Convert.ToInt32(dataGridView1.Rows[i].Cells["ItemName"].Value);
                    objPurchasesOrderDetailEL.Item_Quantity = Convert.ToDouble(dataGridView1.Rows[i].Cells["Item_Quantity"].Value);
                    objPurchasesOrderDetailEL.Item_Rate     = Convert.ToDouble(dataGridView1.Rows[i].Cells["Item_Rate"].Value);

                    if (Convert.ToInt32(dataGridView1.Rows[i].Cells["Purchase_Order_Detail_Id"].Value) == 0)
                    {
                        objPurchasesOrderDetailEL.Purchases_Order_Id = SelectedPurchasesOrder.Purchases_Order_Id;
                        lstAddingPurchasesOrderDetailEL.Add(objPurchasesOrderDetailEL);
                    }
                    else
                    {
                        objPurchasesOrderDetailEL.Purchase_Order_Detail_Id = Convert.ToInt32(dataGridView1.Rows[i].Cells["Purchase_Order_Detail_Id"].Value);
                        lstUpdatigPurchasesOrderDetailEL.Add(objPurchasesOrderDetailEL);
                    }
                }
                lstAddingPurchasesOrderDetailEL.ForEach(r => objPurchasesOrderDetailDL.Insert(objSqlTransaction, r));
                lstUpdatigPurchasesOrderDetailEL.ForEach(r => objPurchasesOrderDetailDL.Update(objSqlTransaction, r));
                lstDeletingPurchasesOrderDetailEL.ForEach(r => objPurchasesOrderDetailDL.Delete(objSqlTransaction, r));

                objSqlTransaction.Commit();
                Common.MessageSave();
                FillListBox();
                ControlClear();
            }
            catch
            {
                objSqlTransaction.Rollback();
                Common.MessageAlert("First enter data in correct format");
            }
        }
Пример #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textPuchasesOrderNo.Text.Trim()))
            {
                Common.MessageAlert("First enter Purchases Order No");
                return;
            }
            decimal result;

            if (string.IsNullOrEmpty(textTax.Text.Trim()) || !decimal.TryParse(textTax.Text, out result))
            {
                Common.MessageAlert("First enter Tax Percentage");
                return;
            }
            if (dataGridView1.Rows.Count - 1 < 0)
            {
                Common.MessageAlert("First Enter Item Detail");
                return;
            }

            SQLHelper      objSQLHelper      = new SQLHelper();
            SqlTransaction objSqlTransaction = objSQLHelper.BeginTrans();

            try
            {
                PurchaseOrderEL        objPurchaseOrderEL  = new PurchaseOrderEL();
                PurchaseOrderDL        objPurchasesOrderDL = new PurchaseOrderDL();
                PurchasesOrderDetailEL objPurchasesOrderDetailEL;
                PurchasesOrderDetailDL objPurchasesOrderDetailDL = new PurchasesOrderDetailDL();

                objPurchaseOrderEL.Company_id         = SelectedCompany.Company_id;
                objPurchaseOrderEL.Purchases_Order_Id = SelectedPurchasesOrder.Purchases_Order_Id;
                objPurchaseOrderEL.Purchases_Order_No = textPuchasesOrderNo.Text.Trim();
                objPurchaseOrderEL.Date           = dateTimePickerPurchasesOrderDate.Value;
                objPurchaseOrderEL.Tax_Percentage = Convert.ToDecimal(textTax.Text);


                if (string.IsNullOrEmpty(txtOtherAmount.Text.Trim()))
                {
                    objPurchaseOrderEL.Other_Amount = 0;
                }
                else
                {
                    objPurchaseOrderEL.Other_Amount = Convert.ToDecimal(txtOtherAmount.Text);
                }



                objPurchaseOrderEL.Requisitioner = txtRequisitioner.Text;
                objPurchaseOrderEL.Credit_Term   = txtCreditTerm.Text;
                objPurchaseOrderEL.Shipping_Term = txtShippingTerm.Text;
                objPurchaseOrderEL.Comments      = txtComments.Text;
                objPurchasesOrderDL.Update(objSqlTransaction, objPurchaseOrderEL);

                List <PurchasesOrderDetailEL> lstUpdatigPurchasesOrderDetailEL = new List <PurchasesOrderDetailEL>();
                List <PurchasesOrderDetailEL> lstAddingPurchasesOrderDetailEL  = new List <PurchasesOrderDetailEL>();
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    objPurchasesOrderDetailEL = new PurchasesOrderDetailEL();
                    //objPurchasesOrderDetailEL.Item_Name = dataGridView1.Rows[i].Cells["Item_Name"].Value.ToString().Trim();
                    objPurchasesOrderDetailEL.Item_id       = Convert.ToInt32(dataGridView1.Rows[i].Cells["ItemName"].Value);
                    objPurchasesOrderDetailEL.Item_Quantity = Convert.ToDouble(dataGridView1.Rows[i].Cells["Item_Quantity"].Value);
                    objPurchasesOrderDetailEL.Item_Rate     = Convert.ToDouble(dataGridView1.Rows[i].Cells["Item_Rate"].Value);
                    objPurchasesOrderDetailEL.Item_Unit     = dataGridView1.Rows[i].Cells["Item_Unit"].Value.ToString();

                    if (Convert.ToInt32(dataGridView1.Rows[i].Cells["Purchase_Order_Detail_Id"].Value) == 0)
                    {
                        objPurchasesOrderDetailEL.Purchases_Order_Id = SelectedPurchasesOrder.Purchases_Order_Id;
                        lstAddingPurchasesOrderDetailEL.Add(objPurchasesOrderDetailEL);
                    }
                    else
                    {
                        objPurchasesOrderDetailEL.Purchase_Order_Detail_Id = Convert.ToInt32(dataGridView1.Rows[i].Cells["Purchase_Order_Detail_Id"].Value);
                        lstUpdatigPurchasesOrderDetailEL.Add(objPurchasesOrderDetailEL);
                    }
                }
                lstAddingPurchasesOrderDetailEL.ForEach(r => objPurchasesOrderDetailDL.Insert(objSqlTransaction, r));
                lstUpdatigPurchasesOrderDetailEL.ForEach(r => objPurchasesOrderDetailDL.Update(objSqlTransaction, r));
                lstDeletingPurchasesOrderDetailEL.ForEach(r => objPurchasesOrderDetailDL.Delete(objSqlTransaction, r));

                objSqlTransaction.Commit();
                Common.MessageSave();
                FillListBox();
                ControlClear();
            }
            catch
            {
                objSqlTransaction.Rollback();
                Common.MessageAlert("First enter data in correct format");
            }
        }