private void btnUpdate_Click(object sender, EventArgs e) { if (Validation()) { try { ProcessingManager manageProcessing = new ProcessingManager(); int EmployeeId = manageEmployee.GetEmployeeIdByCode(txtEmployeeCode.Text); if (EmployeeId < 0) { MessageBox.Show("Employee does not found.", "Employee Identity not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } int ProductId = -1; if (!string.IsNullOrEmpty(txtPCode.Text)) { ProductId = manageProduct.GetProductIdByCode(txtPCode.Text); } dataAcess.BeginTransaction(); if (dataAcess.getDBCommand().Transaction == null) { dataAcess.SetDBTransaction(); } foreach (int id in DeletedIds) { //manageProduct.DeleteProductFromLedgerByTransNoAndDetailId(txtWTCode.Text, id, dataAcess); managewarehouse.DeleteWTDetailByDetailId(id, dataAcess); } //hum pehele ProductLedger se Clear kry gy than again insert. manageProduct.DeleteProductLedgerByTransNo(txtWTCode.Text, true, dataAcess); manageProcessing.DeleteProductionLedgerByTransNo(txtWTCode.Text, true, dataAcess); managewarehouse.UpdateWTMaster(WTMasterId, EmployeeId, Convert.ToInt32(cmbFWarehouse.SelectedValue), Convert.ToInt32(cmbTWarehouse.SelectedValue), dtpDate.Value, txtSONo.Text, ProductId, txtRemarks.Text, false, false, "H", MainForm.User_Id, DateTime.Now, "", chkProcess.Checked, (string.IsNullOrEmpty(txtProcessQty.Text) ? 0 : Convert.ToDecimal(txtProcessQty.Text)), txtBatchNo.Text, dataAcess); foreach (DataRow dr in dsMain.Tables["WTDetail"].Rows) { if (dr.RowState != DataRowState.Deleted) { int DetailId = managewarehouse.InsertUpdateWTDetail(Convert.ToInt32(dr["WTDetailId"]), Convert.ToInt32(dr["WTMasterId"]), Convert.ToInt32(dr["ProductId"]), "H", "Stock", "", "Stock", Convert.ToDecimal(dr["QtyToTransfer"]), MainForm.User_Id, DateTime.Now, "", dataAcess); manageProduct.InsertProductLedger(Convert.ToInt32(dr["ProductId"]), dtpDate.Value, txtWTCode.Text, DetailId, "O", Convert.ToDecimal(dr["QtyToTransfer"]), 0, 0, 0, 0, 0, MainForm.User_Id, DateTime.Now.Date, "", "", null, "Transfer Out from Warehouse Transfer", Convert.ToInt32(cmbFWarehouse.SelectedValue), -1, "", dataAcess); manageProduct.InsertProductLedger(Convert.ToInt32(dr["ProductId"]), dtpDate.Value, txtWTCode.Text, DetailId, "I", Convert.ToDecimal(dr["QtyToTransfer"]), 0, 0, 0, 0, 0, MainForm.User_Id, DateTime.Now.Date, "", "", null, "Transfer Inn from Warehouse Transfer", Convert.ToInt32(cmbTWarehouse.SelectedValue), -1, "", dataAcess); } } if (chkProcess.Checked) { manageProcessing.InsertUpdateProductionLedger(Convert.ToInt32(cmbTWarehouse.SelectedValue), ProductId, -1, txtSONo.Text, dtpDate.Value, txtWTCode.Text, WTMasterId, "I", (string.IsNullOrEmpty(txtProcessQty.Text.ToString()) ? 0 : Convert.ToDecimal(txtProcessQty.Text)), -1, "Entry From Department Transfer", false, dataAcess); } dataAcess.TransCommit(); MessageBox.Show("Warehouse Transfer Update Successfull", "Record Updated", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearFeilds(); } catch (SqlException sqlex) { MessageBox.Show(sqlex.Message); dataAcess.TransRollback(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { dataAcess.ConnectionClose(); } } }
private void btnAdd_Click(object sender, EventArgs e) { if (Validation()) { try { ProcessingManager manageProcessing = new ProcessingManager(); DataTable dtWTMaster = new DataTable(); int EmployeeId = manageEmployee.GetEmployeeIdByCode(txtEmployeeCode.Text); if (EmployeeId < 0) { MessageBox.Show("Employee does not found.", "Employee Identity not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } int ProductId = -1; if (!string.IsNullOrEmpty(txtPCode.Text)) { ProductId = manageProduct.GetProductIdByCode(txtPCode.Text); } dataAcess.BeginTransaction(); if (dataAcess.getDBCommand().Transaction == null) { dataAcess.SetDBTransaction(); } dtWTMaster = managewarehouse.InsertWTMaster(EmployeeId, Convert.ToInt32(cmbFWarehouse.SelectedValue), Convert.ToInt32(cmbTWarehouse.SelectedValue), dtpDate.Value, txtSONo.Text, ProductId, txtRemarks.Text, false, false, "H", MainForm.User_Id, DateTime.Now, "", chkProcess.Checked, (string.IsNullOrEmpty(txtProcessQty.Text) ? 0 : Convert.ToDecimal(txtProcessQty.Text)), txtBatchNo.Text, dataAcess); if (dtWTMaster.Rows.Count == 0) { MessageBox.Show("Department Transfer Insert Error", "Can not Insert", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new Exception(); } else { WTMasterId = Convert.ToInt32(dtWTMaster.Rows[0]["Id"]); } foreach (DataRow dr in dsMain.Tables["WTDetail"].Rows) { int DetailId = managewarehouse.InsertUpdateWTDetail(Convert.ToInt32(dr["WTDetailId"]), WTMasterId, Convert.ToInt32(dr["ProductId"]), "H", "Stock", "", "Stock", Convert.ToDecimal(dr["QtyToTransfer"]), MainForm.User_Id, DateTime.Now, "", dataAcess); manageProduct.InsertProductLedger(Convert.ToInt32(dr["ProductId"]), dtpDate.Value, dtWTMaster.Rows[0]["TransferNo"].ToString(), DetailId, "O", Convert.ToDecimal(dr["QtyToTransfer"]), 0, 0, 0, 0, 0, MainForm.User_Id, DateTime.Now.Date, "", "", null, "Transfer Out from Warehouse Transfer", Convert.ToInt32(cmbFWarehouse.SelectedValue), -1, "", dataAcess); manageProduct.InsertProductLedger(Convert.ToInt32(dr["ProductId"]), dtpDate.Value, dtWTMaster.Rows[0]["TransferNo"].ToString(), DetailId, "I", Convert.ToDecimal(dr["QtyToTransfer"]), 0, 0, 0, 0, 0, MainForm.User_Id, DateTime.Now.Date, "", "", null, " Transfer Inn from Warehouse Transfer ", Convert.ToInt32(cmbTWarehouse.SelectedValue), -1, "", dataAcess); } if (chkProcess.Checked) { manageProcessing.InsertUpdateProductionLedger(Convert.ToInt32(cmbTWarehouse.SelectedValue), ProductId, -1, txtSONo.Text, dtpDate.Value, txtWTCode.Text, WTMasterId, "I", (string.IsNullOrEmpty(txtProcessQty.Text.ToString()) ? 0 : Convert.ToDecimal(txtProcessQty.Text)), -1, "Entry From Department Transfer", false, dataAcess); } dataAcess.TransCommit(); MessageBox.Show("Warehouse Transfer Insert Successfull", "Record Inserted", MessageBoxButtons.OK, MessageBoxIcon.Information); ButtonRights(false); ClearFeilds(); } catch (SqlException sqlex) { MessageBox.Show(sqlex.Message); dataAcess.TransRollback(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { dataAcess.ConnectionClose(); } } }