private string getNewInvoiceDocumentNo() { var s2 = string.Empty; DataSet ds = ProjectFunctions.GetDataSet("select isnull(max(Cast(cmno as int)),000000) from CratesData Where CmFyear='" + ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear) + "'"); if (ds.Tables[0].Rows.Count > 0) { s2 = ds.Tables[0].Rows[0][0].ToString().Trim(); s2 = (Convert.ToInt32(s2) + 1).ToString().Trim(); } return(s2); }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateData()) { using (var sqlcon = new SqlConnection(ProjectFunctions.GetConnection())) { sqlcon.Open(); var sqlcom = sqlcon.CreateCommand(); var transaction = sqlcon.BeginTransaction("SaveTransaction"); sqlcom.Connection = sqlcon; sqlcom.Transaction = transaction; sqlcom.CommandType = CommandType.StoredProcedure; try { if (s1 == "&Add") { sqlcom.CommandText = "[sp_Ins_CratesData]"; sqlcom.Parameters.Add("@CmNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim(); sqlcom.Parameters["@CmNo"].Direction = ParameterDirection.InputOutput; sqlcom.Parameters.Add("@CmFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@CmDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@CmSalesManCode", SqlDbType.NVarChar).Value = txtSMCode.Text.Trim(); sqlcom.Parameters.Add("@CmPartyCode", SqlDbType.NVarChar).Value = txtDebitPartyCode.Text.Trim(); sqlcom.Parameters.Add("@CmCrates1", SqlDbType.NVarChar).Value = Convert.ToDecimal(txtCrates1.Text); sqlcom.Parameters.Add("@CmCrates2", SqlDbType.NVarChar).Value = Convert.ToDecimal(txtCrates2.Text); sqlcom.Parameters.Add("@CmBillNo", SqlDbType.NVarChar).Value = txtOrderNo.Text.Trim(); sqlcom.Parameters.Add("@CmBillDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(txtOrderDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@AddEditTag", SqlDbType.VarChar).Value = "&Add"; sqlcom.ExecuteNonQuery(); txtSerialNo.Text = sqlcom.Parameters["@CmNo"].Value.ToString(); sqlcom.Parameters.Clear(); } if (s1 == "Edit") { sqlcom.CommandText = "[sp_Ins_CratesData]"; sqlcom.Parameters.Add("@CmNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim(); sqlcom.Parameters.Add("@CmFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@CmDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@CmSalesManCode", SqlDbType.NVarChar).Value = txtSMCode.Text.Trim(); sqlcom.Parameters.Add("@CmPartyCode", SqlDbType.NVarChar).Value = txtDebitPartyCode.Text.Trim(); sqlcom.Parameters.Add("@CmCrates1", SqlDbType.NVarChar).Value = Convert.ToDecimal(txtCrates1.Text); sqlcom.Parameters.Add("@CmCrates2", SqlDbType.NVarChar).Value = Convert.ToDecimal(txtCrates2.Text); sqlcom.Parameters.Add("@CmBillNo", SqlDbType.NVarChar).Value = txtOrderNo.Text.Trim(); sqlcom.Parameters.Add("@CmBillDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(txtOrderDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@AddEditTag", SqlDbType.VarChar).Value = "EDIT"; sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); sqlcom.CommandType = CommandType.Text; String Query = "Update InvoiceMst Set ImRetCratesNo=null,ImRetCratesDate=null Where ImNo='" + AgainstOldInvNo + "' And ImDate='" + Convert.ToDateTime(AgainstOldInvDate).ToString("yyyy-MM-dd") + "' And ImType='S'"; sqlcom.CommandText = Query; sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } sqlcom.CommandType = CommandType.Text; String QueryUpdate = "Update InvoiceMst Set ImRetCratesNo='" + txtSerialNo.Text + "',ImRetCratesDate='" + dtInvoiceDate.DateTime.Date.ToString("yyyy-MM-dd") + "' Where ImNo='" + txtOrderNo.Text.Trim() + "' And ImDate='" + Convert.ToDateTime(txtOrderDate.Text).ToString("yyyy-MM-dd") + "' And ImType='S'"; sqlcom.CommandText = QueryUpdate; sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); transaction.Commit(); ProjectFunctions.SpeakError("Return Crates Data Saved Successfully"); if (s1 == "&Add") { txtCrates1.Text = string.Empty; txtCrates2.Text = string.Empty; txtDebitPartyCode.Text = string.Empty; txtDebitPartyName.Text = string.Empty; txtInvCrates1.Text = string.Empty; txtInvCrates2.Text = string.Empty; txtInvoiceType.Text = string.Empty; txtOrderDate.Text = string.Empty; txtSMName.Text = string.Empty; txtSMCode.Text = string.Empty; txtOrderNo.Text = string.Empty; txtSerialNo.Text = getNewInvoiceDocumentNo().PadLeft(6, '0'); dtInvoiceDate.EditValue = DateTime.Now; btnLoadOrder.Focus(); } else { this.Close(); } sqlcon.Close(); } catch (Exception ex) { ProjectFunctions.SpeakError("Something Wrong. \n I am going to Roll Back." + ex.Message); try { transaction.Rollback(); } catch (Exception ex2) { ProjectFunctions.SpeakError("Something Wrong. \n Roll Back Failed." + ex2.Message); } } } } }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateDataForSaving()) { using (var sqlcon = new SqlConnection(ProjectFunctions.GetConnection())) { #pragma warning disable CS0618 // 'GridControl.KeyboardFocusView' is obsolete: 'Use the FocusedView property instead.' var MaxRow = ((InfoGrid.KeyboardFocusView as GridView).RowCount); #pragma warning restore CS0618 // 'GridControl.KeyboardFocusView' is obsolete: 'Use the FocusedView property instead.' sqlcon.Open(); var sqlcom = sqlcon.CreateCommand(); var transaction = sqlcon.BeginTransaction("SaveTransaction"); sqlcom.Connection = sqlcon; sqlcom.Transaction = transaction; try { if (s1 == "&Add") { sqlcom.CommandType = CommandType.StoredProcedure; sqlcom.CommandText = "sp_InvoiceMstAdd"; sqlcom.Parameters.Add("@ImFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@ImType", SqlDbType.NVarChar).Value = "S"; sqlcom.Parameters.Add("@ImNo", SqlDbType.NVarChar).Value = txtSerialNo.Text; sqlcom.Parameters["@ImNo"].Direction = ParameterDirection.InputOutput; sqlcom.Parameters.Add("@ImDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@ImPartyCode", SqlDbType.NVarChar).Value = txtDebitPartyCode.Text.Trim(); sqlcom.Parameters.Add("@ImVehCode", SqlDbType.NVarChar).Value = txtVehicleCode.Text.Trim(); sqlcom.Parameters.Add("@ImVogAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtTaxableAmount.Text); sqlcom.Parameters.Add("@ImTxbAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtTaxableAmount.Text); sqlcom.Parameters.Add("@ImTaxAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtTaxAmount.Text); sqlcom.Parameters.Add("@ImSTaxAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtSurcharge.Text); sqlcom.Parameters.Add("@ImNetAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtNetAmount.Text); sqlcom.Parameters.Add("@ImNetAmtRO", SqlDbType.Decimal).Value = Convert.ToDecimal(txtRNetAmount.Text); sqlcom.Parameters.Add("@ImLC", SqlDbType.NVarChar).Value = txtLCTag.Text.Trim(); sqlcom.Parameters.Add("@ImCForm", SqlDbType.NVarChar).Value = txtCForm.Text; sqlcom.Parameters.Add("@ImVRTag", SqlDbType.NVarChar).Value = txtVatInvoice.Text; sqlcom.Parameters.Add("@AddEditTag", SqlDbType.NVarChar).Value = "ADDMST"; sqlcom.ExecuteNonQuery(); txtSerialNo.Text = sqlcom.Parameters["@ImNo"].Value.ToString(); sqlcom.Parameters.Clear(); } if (s1 == "Edit") { sqlcom.CommandType = CommandType.StoredProcedure; sqlcom.CommandText = "sp_InvoiceMstAdd"; sqlcom.Parameters.Add("@ImFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@ImType", SqlDbType.NVarChar).Value = "S"; sqlcom.Parameters.Add("@ImNo", SqlDbType.NVarChar).Value = txtSerialNo.Text; sqlcom.Parameters.Add("@ImDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@ImPartyCode", SqlDbType.NVarChar).Value = txtDebitPartyCode.Text.Trim(); sqlcom.Parameters.Add("@ImVehCode", SqlDbType.NVarChar).Value = txtVehicleCode.Text.Trim(); sqlcom.Parameters.Add("@ImVogAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtTaxableAmount.Text); sqlcom.Parameters.Add("@ImTxbAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtTaxableAmount.Text); sqlcom.Parameters.Add("@ImTaxAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtTaxAmount.Text); sqlcom.Parameters.Add("@ImSTaxAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtSurcharge.Text); sqlcom.Parameters.Add("@ImNetAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtNetAmount.Text); sqlcom.Parameters.Add("@ImNetAmtRO", SqlDbType.Decimal).Value = Convert.ToDecimal(txtRNetAmount.Text); sqlcom.Parameters.Add("@ImLC", SqlDbType.NVarChar).Value = txtLCTag.Text.Trim(); sqlcom.Parameters.Add("@ImCForm", SqlDbType.NVarChar).Value = txtCForm.Text; sqlcom.Parameters.Add("@ImVRTag", SqlDbType.NVarChar).Value = txtVatInvoice.Text; sqlcom.Parameters.Add("@AddEditTag", SqlDbType.NVarChar).Value = "EDITMST"; sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); sqlcom.CommandType = CommandType.Text; sqlcom.CommandText = "Delete from InvoiceData Where IdNo=@IdNo And IdDate=@IdDate And IdType='S'"; sqlcom.Parameters.Add("@IdNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim(); sqlcom.Parameters.Add("@IdDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } for (var i = 0; i < MaxRow; i++) { sqlcom.CommandType = CommandType.Text; var currentrow = InfoGridView.GetDataRow(i); sqlcom.CommandText = " Insert into InvoiceData " + " (IdFyear,IdType,IdNo,IdDate,IdPartyCode" + " ,IdPrdCode,IdPrdAsgnCode,IdPrdQty,IdPrdRate,IdDiscRate,IdPrdAmt," + " IdTxbAmt,IdTaxAmt,IdPrdTaxCode,IdTaxRate,IdSTaxAmt,IdSTaxRate)" + " values(@IdFyear,@IdType,@IdNo,@IdDate,@IdPartyCode," + " @IdPrdCode,@IdPrdAsgnCode,@IdPrdQty,@IdPrdRate,@IdDiscRate,@IdPrdAmt," + " @IdTxbAmt,@IdTaxAmt,@IdPrdTaxCode,@IdTaxRate,@IdSTaxAmt,@IdSTaxRate)"; sqlcom.Parameters.Add("@IdFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@IdType", SqlDbType.NVarChar).Value = "S"; sqlcom.Parameters.Add("@IdNo", SqlDbType.NVarChar).Value = txtSerialNo.Text; sqlcom.Parameters.Add("@IdDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("dd-MM-yyyy"); sqlcom.Parameters.Add("@IdPartyCode", SqlDbType.NVarChar).Value = txtDebitPartyCode.Text.Trim(); sqlcom.Parameters.Add("@IdPrdCode", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdPrdCode"]); sqlcom.Parameters.Add("@IdPrdAsgnCode", SqlDbType.NVarChar).Value = currentrow["IdPrdAsgnCode"].ToString(); sqlcom.Parameters.Add("@IdPrdQty", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdPrdQty"]); sqlcom.Parameters.Add("@IdPrdRate", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdPrdRate"]); sqlcom.Parameters.Add("@IdDiscRate", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdDiscRate"]); sqlcom.Parameters.Add("@IdPrdAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdPrdAmt"]); sqlcom.Parameters.Add("@IdTxbAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdTxbAmt"]); sqlcom.Parameters.Add("@IdTaxAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdTaxAmt"]); sqlcom.Parameters.Add("@IdPrdTaxCode", SqlDbType.NVarChar).Value = currentrow["IdPrdTaxCode"].ToString(); sqlcom.Parameters.Add("@IdTaxRate", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdTaxRate"]); sqlcom.Parameters.Add("@IdSTaxAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdSTaxAmt"]); sqlcom.Parameters.Add("@IdSTaxRate", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdSTaxRate"]); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } if (s1 == "Edit") { sqlcom.CommandType = CommandType.Text; sqlcom.CommandText = "Delete from InvoiceMstAI Where ImNo=@ImNo And ImDate=@ImDate And ImType='S'"; sqlcom.Parameters.Add("@ImNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim(); sqlcom.Parameters.Add("@ImDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } var distinctRows = (from DataRow dRow in dt.Rows select dRow["IdPrdTaxCode"]).Distinct(); foreach (var v in distinctRows) { if (v.ToString() != string.Empty) { decimal AiAmount = 0, AiTaxAmount = 0, AiTaxSurcharge = 0; for (var m = 0; m < dt.Rows.Count; m++) { if (v.ToString() == dt.Rows[m]["IdPrdTaxCode"].ToString()) { AiAmount = AiAmount + Convert.ToDecimal(dt.Rows[m]["IdTxbAmt"]); AiTaxAmount = AiTaxAmount + Convert.ToDecimal(dt.Rows[m]["IdTaxAmt"]); AiTaxSurcharge = AiTaxSurcharge + Convert.ToDecimal(dt.Rows[m]["IdSTaxAmt"]); } if (m == dt.Rows.Count - 1) { sqlcom.CommandType = CommandType.StoredProcedure; sqlcom.CommandText = "[sp_InvoiceMstAIAdd]"; sqlcom.Parameters.Add("@ImFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@ImType", SqlDbType.NVarChar).Value = "S"; sqlcom.Parameters.Add("@ImNo", SqlDbType.NVarChar).Value = txtSerialNo.Text; sqlcom.Parameters.Add("@ImDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("dd-MM-yyyy"); sqlcom.Parameters.Add("@ImPartyCode", SqlDbType.NVarChar).Value = txtDebitPartyCode.Text.Trim(); sqlcom.Parameters.Add("@ImTxbAmt", SqlDbType.Decimal).Value = AiAmount; sqlcom.Parameters.Add("@ImTaxAmt", SqlDbType.Decimal).Value = AiTaxAmount; sqlcom.Parameters.Add("@ImSTaxAmt", SqlDbType.Decimal).Value = AiTaxSurcharge; sqlcom.Parameters.Add("@ImTaxCode", SqlDbType.NVarChar).Value = v.ToString(); sqlcom.Parameters.Add("@ImNetAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtNetAmount.Text); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } } } } sqlcom.CommandType = CommandType.StoredProcedure; sqlcom.CommandText = "SP_SLVPosting"; sqlcom.Parameters.Add("@DocNo", SqlDbType.NVarChar).Value = txtSerialNo.Text; sqlcom.Parameters.Add("@DocDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("dd-MM-yyyy"); sqlcom.Parameters.Add("@DocType", SqlDbType.NVarChar).Value = "S"; sqlcom.Parameters.Add("@ROffCode", SqlDbType.NVarChar).Value = "000001"; sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); transaction.Commit(); sqlcon.Close(); this.Close(); } catch (Exception ex) { ProjectFunctions.SpeakError("Something Wrong. \n I am going to Roll Back." + ex.Message); try { transaction.Rollback(); } catch (Exception ex2) { ProjectFunctions.SpeakError("Something Wrong. \n Roll Back Failed." + ex2.Message); } } } } }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateData()) { using (var sqlcon = new SqlConnection(ProjectFunctions.GetConnection())) { #pragma warning disable CS0618 // 'GridControl.KeyboardFocusView' is obsolete: 'Use the FocusedView property instead.' var MaxRow = ((InfoGrid.KeyboardFocusView as GridView).RowCount); #pragma warning restore CS0618 // 'GridControl.KeyboardFocusView' is obsolete: 'Use the FocusedView property instead.' sqlcon.Open(); var sqlcom = sqlcon.CreateCommand(); var transaction = sqlcon.BeginTransaction("SaveTransaction"); sqlcom.Connection = sqlcon; sqlcom.Transaction = transaction; sqlcom.CommandType = CommandType.Text; try { if (s1 == "&Add") { sqlcom.CommandText = " SET TRANSACTION ISOLATION LEVEL SERIALIZABLE Begin Transaction " + " Insert into InvoiceMst" + " (@ImNo,@ImType,@ImFYear,@ImDate,@ImSalesManCode,@ImPartyCode,@ImRouteCode," + " @ImTotQty,@ImVogAmt,@ImRcds,@ImTxbAmt,@ImTaxAmt,@ImSTaxAmt,@ImNetAmt,@ImNetAmtRO," + " @ImLC,@ImCForm,@ImInvTypeHead)" + " values((SELECT RIGHT('000000'+ CAST( ISNULL( max(Cast(ImNo as int)),0)+1 AS VARCHAR(6)),6) from InvoiceMst),@ImType,@ImFYear,@ImDate,@ImSalesManCode,@ImPartyCode,@ImRouteCode," + " @ImTotQty,@ImVogAmt,@ImRcds,@ImTxbAmt,@ImTaxAmt,@ImSTaxAmt,@ImNetAmt,@ImNetAmtRO," + " @ImLC,@ImCForm,@ImInvTypeHead)" + " Commit "; } if (s1 == "Edit") { sqlcom.CommandText = " UPDATE dealerMaster SET " + " ImFYear=@ImFYear,ImSalesManCode=@ImSalesManCode,ImPartyCode=@ImPartyCode,ImTotQty=@ImTotQty, " + " ImVogAmt=@ImVogAmt,ImRcds=@ImRcds,ImTxbAmt=@ImTxbAmt,ImTaxAmt=@ImTaxAmt, " + " ImSTaxAmt=@ImSTaxAmt,ImNetAmt=@ImNetAmt,ImNetAmtRO=@ImNetAmtRO,ImLC=@ImLC,ImCForm=@ImCForm, " + " ImInvTypeHead=@ImInvTypeHead " + " Where dealerCode=@dealerCode"; } sqlcom.Parameters["@ImNo"].Direction = ParameterDirection.InputOutput; sqlcom.Parameters.Add("@ImDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@ImType", SqlDbType.NVarChar).Value = "S"; sqlcom.Parameters.Add("@ImFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@ImSalesManCode", SqlDbType.NVarChar).Value = txtSmCode.Text.Trim(); sqlcom.Parameters.Add("@ImPartyCode", SqlDbType.NVarChar).Value = txtDebitPartyCode.Text.Trim(); sqlcom.Parameters.Add("@ImRouteCode", SqlDbType.NVarChar).Value = txtRouteCode.Text.Trim(); sqlcom.Parameters.Add("@ImTotQty", SqlDbType.Decimal).Value = Convert.ToDecimal(gridColumn4.SummaryItem.SummaryValue).ToString("0.00"); sqlcom.Parameters.Add("@ImVogAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtTaxableAmount.Text); sqlcom.Parameters.Add("@ImRcds", SqlDbType.Decimal).Value = Convert.ToDecimal(gridColumn2.SummaryItem.SummaryValue).ToString("0.00"); sqlcom.Parameters.Add("@ImTxbAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtTaxableAmount.Text); sqlcom.Parameters.Add("@ImTaxAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtTaxAmount.Text); sqlcom.Parameters.Add("@ImSTaxAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtSurcharge.Text); sqlcom.Parameters.Add("@ImNetAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(txtNetAmount.Text); sqlcom.Parameters.Add("@ImNetAmtRO", SqlDbType.Decimal).Value = Convert.ToDecimal(txtRNetAmount.Text); sqlcom.Parameters.Add("@ImLC", SqlDbType.NVarChar).Value = txtLCTag.Text.Trim(); sqlcom.Parameters.Add("@ImCForm", SqlDbType.NVarChar).Value = txtCForm.Text; sqlcom.Parameters.Add("@ImInvTypeHead", SqlDbType.NVarChar).Value = txtInvoiceType.Text; sqlcom.ExecuteNonQuery(); txtSerialNo.Text = sqlcom.Parameters["@ImNo"].Value.ToString(); sqlcom.Parameters.Clear(); sqlcom.CommandText = "Delete from UsDataData Where IdNo=@IdNo And IdDate=@IdDate And IdType='S'"; sqlcom.Parameters.Add("@IdNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim(); sqlcom.Parameters.Add("@IdDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); for (var i = 0; i < MaxRow; i++) { var currentrow = InfoGridView.GetDataRow(i); sqlcom.CommandText = " Insert into UsDataData " + " (@IdFyear,@IdType,@IdNo,@IdDate,@IdSalesManCode,@IdPartyCode,@IdRouteCode," + " @IdDealerCode,@IdPrdCode,@IdPrdAsgnCode,@IdPrdQty,@IdPrdQtyF,@IdPrdRate,@IdDiscRate,@IdPrdAmt," + " @IdTxbAmt,@IdTaxAmt,@IdPrdTaxCode,@IdTaxRate,IdSTaxAmt,IdSTaxRate)" + " values(@IdFyear,@IdType,@IdNo,@IdDate,@IdSalesManCode,@IdPartyCode,@IdRouteCode," + " @IdDealerCode,@IdPrdCode,@IdPrdAsgnCode,@IdPrdQty,@IdPrdQtyF,@IdPrdRate,@IdDiscRate,@IdPrdAmt," + " @IdTxbAmt,@IdTaxAmt,@IdPrdTaxCode,@IdTaxRate,IdSTaxAmt,IdSTaxRate)"; sqlcom.Parameters.Add("@IdFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@IdType", SqlDbType.NVarChar).Value = "S"; sqlcom.Parameters.Add("@IdCat", SqlDbType.NVarChar).Value = string.Empty; sqlcom.Parameters.Add("@IdNoSeries", SqlDbType.NVarChar).Value = txtserial.Text.Trim(); sqlcom.Parameters.Add("@IdNo", SqlDbType.NVarChar).Value = txtSerialNo.Text; sqlcom.Parameters.Add("@IdDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("dd-MM-yyyy"); sqlcom.Parameters.Add("@IdSalesManCode", SqlDbType.NVarChar).Value = txtSmCode.Text.Trim(); sqlcom.Parameters.Add("@IdPartyCode", SqlDbType.NVarChar).Value = txtDebitPartyCode.Text.Trim(); sqlcom.Parameters.Add("@IdRouteCode", SqlDbType.NVarChar).Value = txtRouteCode.Text.Trim(); sqlcom.Parameters.Add("@IdDealerCode", SqlDbType.NVarChar).Value = currentrow["IdDealerCode"].ToString(); sqlcom.Parameters.Add("@IdPrdCode", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdPrdCode"]); sqlcom.Parameters.Add("@IdPrdAsgnCode", SqlDbType.NVarChar).Value = currentrow["IdPrdAsgnCode"].ToString(); sqlcom.Parameters.Add("@IdPrdQty", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdPrdQty"]); sqlcom.Parameters.Add("@IdPrdQtyF", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdPrdQtyF"]); sqlcom.Parameters.Add("@IdPrdRate", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdPrdRate"]); sqlcom.Parameters.Add("@IdDiscRate", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdDiscRate"]); sqlcom.Parameters.Add("@IdPrdAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdPrdAmt"]); sqlcom.Parameters.Add("@IdTxbAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdTxbAmt"]); sqlcom.Parameters.Add("@IdTaxAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdTaxAmt"]); sqlcom.Parameters.Add("@IdPrdTaxCode", SqlDbType.NVarChar).Value = currentrow["IdPrdTaxCode"].ToString(); sqlcom.Parameters.Add("@IdTaxRate", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdTaxRate"]); sqlcom.Parameters.Add("@IdSTaxAmt", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdSTaxAmt"]); sqlcom.Parameters.Add("@IdSTaxRate", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["IdSTaxRate"]); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } if (OldAgainstInvNo.Trim().Length > 0) { sqlcom.CommandText = "Update InvoiceMst Set ImTypeA=null,ImNoA=null,ImDateA=null Where ImNo=@ImNo And ImDate=@ImDate And ImType='S'"; sqlcom.Parameters.Add("@ImNo", SqlDbType.NVarChar).Value = OldAgainstInvNo; sqlcom.Parameters.Add("@ImDate", SqlDbType.NVarChar).Value = OldAgainstInvDate.Date.ToString("yyyy-MM-dd"); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } sqlcom.CommandText = "Update InvoiceMst Set ImTypeA='US',ImNoA=@ImNoA,ImDateA=@ImDateA Where ImNo=@ImNo And ImDate=@ImDate And ImType='S'"; sqlcom.Parameters.Add("@ImNoA", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim(); sqlcom.Parameters.Add("@ImDateA", SqlDbType.NVarChar).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@ImNo", SqlDbType.NVarChar).Value = txtAgainstInvNo.Text.Trim(); sqlcom.Parameters.Add("@ImDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(txtAgainstInvDate.Text).ToString("yyyy-MM-dd"); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); sqlcom.CommandText = "Update USDataMst Set IminNo=@IminNo,IminDate=@IminDate Where USDataMst.ImNo=@ImNo And And USDataMst.ImDate=@ImDate And ImType='S'"; sqlcom.Parameters.Add("@IminNo", SqlDbType.NVarChar).Value = txtAgainstInvNo.Text.Trim(); sqlcom.Parameters.Add("@IminDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(txtAgainstInvDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@ImNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim(); sqlcom.Parameters.Add("@ImDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); transaction.Commit(); sqlcon.Close(); this.Close(); } catch (Exception ex) { ProjectFunctions.SpeakError("Something Wrong. \n I am going to Roll Back." + ex.Message); try { transaction.Rollback(); } catch (Exception ex2) { ProjectFunctions.SpeakError("Something Wrong. \n Roll Back Failed." + ex2.Message); } } } } }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateDataForSaving()) { using (var sqlcon = new SqlConnection(ProjectFunctions.GetConnection())) { #pragma warning disable CS0618 // 'GridControl.KeyboardFocusView' is obsolete: 'Use the FocusedView property instead.' var MaxRow = ((InfoGrid.KeyboardFocusView as GridView).RowCount); #pragma warning restore CS0618 // 'GridControl.KeyboardFocusView' is obsolete: 'Use the FocusedView property instead.' sqlcon.Open(); var sqlcom = sqlcon.CreateCommand(); var transaction = sqlcon.BeginTransaction("SaveTransaction"); sqlcom.Connection = sqlcon; sqlcom.Transaction = transaction; sqlcom.CommandType = CommandType.StoredProcedure; try { if (s1 == "&Add") { sqlcom.CommandText = "[sp_ProductionMstAdd]"; sqlcom.Parameters.Add("@ImNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim(); sqlcom.Parameters["@ImNo"].Direction = ParameterDirection.InputOutput; sqlcom.Parameters.Add("@ImFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@ImDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@ImType", SqlDbType.NVarChar).Value = "PR"; sqlcom.Parameters.Add("@ImPlant", SqlDbType.NVarChar).Value = txtPlant.Text.Trim(); sqlcom.Parameters.Add("@ImShift", SqlDbType.NVarChar).Value = txtShift.Text.Trim(); sqlcom.Parameters.Add("@ImPlantRunHRs", SqlDbType.NVarChar).Value = Convert.ToDecimal(txtPlantRunHours.Text); sqlcom.Parameters.Add("@AddEditTag", SqlDbType.VarChar).Value = "&Add"; sqlcom.ExecuteNonQuery(); txtSerialNo.Text = sqlcom.Parameters["@ImNo"].Value.ToString(); sqlcom.Parameters.Clear(); } if (s1 == "Edit") { sqlcom.CommandText = "[sp_ProductionMstAdd]"; sqlcom.Parameters.Add("@ImNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim(); sqlcom.Parameters.Add("@ImFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@ImDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.Parameters.Add("@ImType", SqlDbType.NVarChar).Value = "PR"; sqlcom.Parameters.Add("@ImPlant", SqlDbType.NVarChar).Value = txtPlant.Text.Trim(); sqlcom.Parameters.Add("@ImShift", SqlDbType.NVarChar).Value = txtShift.Text.Trim(); sqlcom.Parameters.Add("@ImPlantRunHRs", SqlDbType.NVarChar).Value = Convert.ToDecimal(txtPlantRunHours.Text); sqlcom.Parameters.Add("@AddEditTag", SqlDbType.VarChar).Value = "EDIT"; sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); sqlcom.CommandType = CommandType.Text; sqlcom.CommandText = "Delete from InvoiceData Where IdNo=@IdNo And IdDate=@IdDate And IdType='PR'"; sqlcom.Parameters.Add("@IdNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim(); sqlcom.Parameters.Add("@IdDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd"); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } for (var i = 0; i < MaxRow; i++) { var currentrow = InfoGridView.GetDataRow(i); sqlcom.CommandType = CommandType.Text; sqlcom.CommandText = " Insert into InvoiceData " + " (IdFyear,IdType,IdNo,IdDate,IdPrdCode,IdQtyBag," + " IdPrdQtyW,IdPrdQty,IdPrdBomNo)" + " values(@IdFyear,@IdType,@IdNo,@IdDate,@IdPrdCode,@IdQtyBag," + " @IdPrdQtyW,@IdPrdQty,@IdPrdBomNo)"; sqlcom.Parameters.Add("@IdFyear", SqlDbType.NVarChar).Value = ProjectFunctions.ClipFYearN(GlobalVariables.FinancialYear); sqlcom.Parameters.Add("@IdType", SqlDbType.NVarChar).Value = "PR"; sqlcom.Parameters.Add("@IdNo", SqlDbType.NVarChar).Value = txtSerialNo.Text; sqlcom.Parameters.Add("@IdDate", SqlDbType.DateTime).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("dd-MM-yyyy"); sqlcom.Parameters.Add("@IdPrdCode", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["PrdCode"]); sqlcom.Parameters.Add("@IdQtyBag", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["Bags"]); sqlcom.Parameters.Add("@IdPrdQtyW", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["Wastage"]); sqlcom.Parameters.Add("@IdPrdQty", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["Production"]); //sqlcom.Parameters.Add("@IdPrdBomNo", SqlDbType.NVarChar).Value = dsBom.Tables[0].Rows[0]["BomNo"].ToString(); sqlcom.Parameters.Add("@IdPrdBomNo", SqlDbType.NVarChar).Value = string.Empty; sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } transaction.Commit(); sqlcon.Close(); this.Close(); } catch (Exception ex) { ProjectFunctions.SpeakError("Something Wrong. \n I am going to Roll Back." + ex.Message); try { transaction.Rollback(); } catch (Exception ex2) { ProjectFunctions.SpeakError("Something Wrong. \n Roll Back Failed." + ex2.Message); } } } } }