private void btnDelete_Click(object sender, EventArgs e) { string str = MessageBox.Show("Are you want to delete this Company", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning).ToString(); if (str.Equals("Yes")) { SQLHelper objSQLHelper = new SQLHelper(); SqlTransaction objSqlTransaction = objSQLHelper.BeginTrans(); try { PurchaseOrderDL objPurchasesOrderDL = new PurchaseOrderDL(); List <PurchasesOrderDetailEL> lstPurchasesOrderDetailEL = new List <PurchasesOrderDetailEL>(); PurchasesOrderDetailDL objPurchasesOrderDetailDL = new PurchasesOrderDetailDL(); int PurchasesOrderId = SelectedPurchasesOrder.Purchases_Order_Id; lstPurchasesOrderDetailEL = objPurchasesOrderDetailDL.GetPurchasesOrderDetailByOrderId(PurchasesOrderId); lstPurchasesOrderDetailEL.ForEach(r => objPurchasesOrderDetailDL.Delete(objSqlTransaction, r)); objPurchasesOrderDL.Delete(objSqlTransaction, SelectedPurchasesOrder); objSqlTransaction.Commit(); Common.MessageDelete(); FillListBox(); ControlClear(); } catch { objSqlTransaction.Rollback(); } } }
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"); } }
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"); } }