private void InfoGrid_DoubleClick(object sender, EventArgs e)
        {
#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.'
            if (MaxRow == 0)
            {
                ProjectFunctions.SpeakError("Invalid Operation");
            }
            else
            {
                BtnOK.Text = "&Update";
                rowindex   = InfoGridView.FocusedRowHandle;
                var row = InfoGridView.GetDataRow(InfoGridView.FocusedRowHandle);

                txtDealerCode.Text  = row["IdDealerCode"].ToString();
                txtDealerName.Text  = row["dealerName"].ToString();
                txtPrdAsgnCode.Text = row["IdPrdAsgnCode"].ToString();
                txtProductName.Text = row["PrdName"].ToString();
                txtFor.Text         = row["IdPrdQty"].ToString();
                txtFree.Text        = row["IdPrdQtyF"].ToString();

                DtFrom.EditValue = Convert.ToDateTime(row["IdDtFrom"]);
                DtTo.EditValue   = Convert.ToDateTime(row["IdDtUpto"]);

                txtPrdCode.Text = row["IdPrdCode"].ToString();
                txtPrdAsgnCode.Focus();
            }
        }
        private void InfoGrid_DoubleClick(object sender, EventArgs e)
        {
            var MaxRow = ((InfoGrid.FocusedView as GridView).RowCount);

            if (MaxRow == 0)
            {
                ProjectFunctions.SpeakError("Invalid Operation");
            }
            else
            {
                BtnOK.Text = "&Update";
                DataRow currentrow = InfoGridView.GetDataRow(InfoGridView.FocusedRowHandle);
                TransID = currentrow["TransId"].ToString();
                DataSet ds = ProjectFunctions.GetDataSet("sp_LoadDelAddress '" + TransID + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    txtDelAccName.Text  = ds.Tables[0].Rows[0]["DelAccName"].ToString();
                    txtDelZipCode.Text  = ds.Tables[0].Rows[0]["DelZipCode"].ToString();
                    txtDelAddress1.Text = ds.Tables[0].Rows[0]["AccAddress1"].ToString();
                    txtDelAddress2.Text = ds.Tables[0].Rows[0]["AccAddress2"].ToString();
                    txtDelAddress3.Text = ds.Tables[0].Rows[0]["AccAddress3"].ToString();
                    txtDelCitycode.Text = ds.Tables[0].Rows[0]["CityCode"].ToString();
                    txtDelCityName.Text = ds.Tables[0].Rows[0]["CTNAME"].ToString();
                    txtDelGSTNo.Text    = ds.Tables[0].Rows[0]["AccGSTNo"].ToString();
                    txtDelAddress1.Focus();
                }
            }
        }
Ejemplo n.º 3
0
        private void InfoGrid_DoubleClick(object sender, EventArgs e)
        {
#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.'
            if (MaxRow == 0)
            {
                ProjectFunctions.SpeakError("Invalid Operation");
            }
            else
            {
                BtnOK.Text = "&Update";
                rowindex   = InfoGridView.FocusedRowHandle;
                var row = InfoGridView.GetDataRow(InfoGridView.FocusedRowHandle);
                txtPrdAsgnCode.Text = row["PrdAsgnCode"].ToString();
                txtPrdCode.Text     = row["PrdCode"].ToString();
                txtProductName.Text = row["PrdName"].ToString();

                txtQty.Text = row["Quantity"].ToString();
                txtPrdAsgnCode.Focus();
            }
        }
        private void InfoGrid_DoubleClick(object sender, EventArgs e)
        {
            // var MaxRow = ((InfoGrid.FocusedView as GridView).RowCount);
            var MaxRow = ((InfoGrid.FocusedView as GridView).RowCount);

            if (MaxRow == 0)
            {
                ProjectFunctions.SpeakError("Invalid Operation");
            }
            else
            {
                BtnOK.Text = "&Update";
                rowindex   = InfoGridView.FocusedRowHandle;
                var row = InfoGridView.GetDataRow(InfoGridView.FocusedRowHandle);
                txtProductACode.Text = row["PrdAsgnCode"].ToString();
                txtProductName.Text  = row["PrdName"].ToString();
                txtProductQty.Text   = row["Qty"].ToString();
                txtAmount.Text       = row["Amount"].ToString();
                txtProductCode.Text  = row["PrdCode"].ToString();


                txtProductACode.Focus();
            }
        }
        private void InfoGrid_DoubleClick(object sender, EventArgs e)
        {
#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.'
            if (MaxRow == 0)
            {
                ProjectFunctions.SpeakError("Invalid Operation");
            }
            else
            {
                BtnOK.Text = "&Update";
                rowindex   = InfoGridView.FocusedRowHandle;
                var row = InfoGridView.GetDataRow(InfoGridView.FocusedRowHandle);
                txtAccCode.Text = row["AccCode"].ToString();
                txtAccName.Text = row["AccName"].ToString();
                if (Convert.ToDecimal(row["Debit"]) > Convert.ToDecimal(row["Credit"]))
                {
                    txtAmount.Text = row["Debit"].ToString();
                }
                else
                {
                    txtAmount.Text = row["Credit"].ToString();
                }

                txtNarration.Text = row["Narration"].ToString();
                txtChqNo.Text     = row["VutChequeNo"].ToString();
                if (row["VutChequeDate"].ToString().Trim().Length > 0)
                {
                    txtChqDate.EditValue = Convert.ToDateTime(row["VutChequeDate"]);
                }
                txtDrCr.Text = row["CrDr"].ToString();

                txtAccCode.Focus();
            }
        }
Ejemplo n.º 6
0
        private void SaveInvoice()
        {
            try

            {
                if (ValidateDataForSaving())
                {
                    using (var sqlcon = new SqlConnection(ProjectFunctions.GetConnection()))
                    {
                        var MaxRow = ((InfoGrid.FocusedView as GridView).RowCount);

                        sqlcon.Open();
                        var sqlcom = sqlcon.CreateCommand();
                        sqlcom.Connection  = sqlcon;
                        sqlcom.CommandType = CommandType.Text;
                        try
                        {
                            if (S1 == "&Add")
                            {
                                string BillNo = string.Empty;

                                BillNo             = ProjectFunctions.GetDataSet("select isnull(max(SIMNO),0)+1 from SALEINVMAIN where SIMSERIES='AP' And SIMFNYR='" + GlobalVariables.FinancialYear + "' And UnitCode='" + GlobalVariables.CUnitID + "'").Tables[0].Rows[0][0].ToString();
                                txtApprovalNo.Text = BillNo;
                                sqlcom.CommandText = "Insert into SALEINVMAIN(SIMSYSDATE,SIMFNYR,SIMDATE,SIMNO,SIMSERIES,CustCode,SIMRemarks,SIMRETURNDATE ,UnitCode,SIMGRANDTOT,SIMApprovedBy )values(" +
                                                     "@SIMSYSDATE,@SIMFNYR,@SIMDATE,@SIMNO,@SIMSERIES,@CustCode,@SIMRemarks,@SIMRETURNDATE,@UnitCode,@SIMGRANDTOT,@SIMApprovedBy)";
                                sqlcom.Parameters.Add("@SIMSYSDATE", SqlDbType.NVarChar).Value    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                sqlcom.Parameters.Add("@SIMFNYR", SqlDbType.NVarChar).Value       = GlobalVariables.FinancialYear;
                                sqlcom.Parameters.Add("@SIMDATE", SqlDbType.NVarChar).Value       = Convert.ToDateTime(txtApprovalDate.Text).ToString("yyyy-MM-dd");
                                sqlcom.Parameters.Add("@SIMNO", SqlDbType.NVarChar).Value         = txtApprovalNo.Text;
                                sqlcom.Parameters.Add("@SIMSERIES", SqlDbType.NVarChar).Value     = "AP";
                                sqlcom.Parameters.Add("@CustCode", SqlDbType.NVarChar).Value      = txtCustCode.Text;
                                sqlcom.Parameters.Add("@SIMRemarks", SqlDbType.NVarChar).Value    = txtRemarks.Text;
                                sqlcom.Parameters.Add("@SIMRETURNDATE", SqlDbType.NVarChar).Value = Convert.ToDateTime(txtReturnedUpTo.Text).ToString("yyyy-MM-dd");
                                sqlcom.Parameters.Add("@UnitCode", SqlDbType.NVarChar).Value      = GlobalVariables.CUnitID;
                                sqlcom.Parameters.Add("@SIMGRANDTOT", SqlDbType.NVarChar).Value   = gridColumn7.SummaryItem.SummaryValue.ToString();
                                sqlcom.Parameters.Add("@SIMApprovedBy", SqlDbType.NVarChar).Value = txtApprovedBy.Text;
                                sqlcom.ExecuteNonQuery();
                                sqlcom.Parameters.Clear();
                            }
                            if (S1 == "Edit")
                            {
                                sqlcom.CommandText = "Update SALEINVMAIN Set SIMSYSDATE=@SIMSYSDATE,SIMFNYR=@SIMFNYR,SIMDATE=@SIMDATE,SIMNO=@SIMNO," +
                                                     " SIMSERIES=@SIMSERIES,CustCode=@CustCode,SIMRemarks=@SIMRemarks,SIMRETURNDATE=@SIMRETURNDATE,SIMGRANDTOT=@SIMGRANDTOT,SIMApprovedBy=@SIMApprovedBy Where SIMDATE='" + Convert.ToDateTime(ImDate).ToString("yyyy-MM-dd") + "' And SIMNO='" + ImNo + "' And SIMSERIES='" + ImSeries + "' And UnitCode='" + GlobalVariables.CUnitID + "'";

                                sqlcom.Parameters.Add("@SIMSYSDATE", SqlDbType.NVarChar).Value    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                sqlcom.Parameters.Add("@SIMFNYR", SqlDbType.NVarChar).Value       = GlobalVariables.FinancialYear;
                                sqlcom.Parameters.Add("@SIMDATE", SqlDbType.NVarChar).Value       = Convert.ToDateTime(txtApprovalDate.Text).ToString("yyyy-MM-dd");
                                sqlcom.Parameters.Add("@SIMNO", SqlDbType.NVarChar).Value         = txtApprovalNo.Text;
                                sqlcom.Parameters.Add("@SIMSERIES", SqlDbType.NVarChar).Value     = "AP";
                                sqlcom.Parameters.Add("@CustCode", SqlDbType.NVarChar).Value      = txtCustCode.Text;
                                sqlcom.Parameters.Add("@SIMRemarks", SqlDbType.NVarChar).Value    = txtRemarks.Text;
                                sqlcom.Parameters.Add("@SIMRETURNDATE", SqlDbType.NVarChar).Value = Convert.ToDateTime(txtReturnedUpTo.Text).ToString("yyyy-MM-dd");
                                sqlcom.Parameters.Add("@SIMGRANDTOT", SqlDbType.NVarChar).Value   = gridColumn7.SummaryItem.SummaryValue.ToString();
                                sqlcom.Parameters.Add("@SIMApprovedBy", SqlDbType.NVarChar).Value = txtApprovedBy.Text;
                                sqlcom.ExecuteNonQuery();
                                sqlcom.Parameters.Clear();

                                sqlcom.CommandType = System.Data.CommandType.Text;
                                sqlcom.CommandText = "update SFDET set Used='N' Where SFDBARCODE in (Select SIDBARCODE  from SALEINVDET Where SIDSERIES=@SIDSERIES And SIDNO=@SIDNO And SIDDATE=@SIDDATE And UnitCode='" + GlobalVariables.CUnitID + "') AND UnitCode='" + GlobalVariables.CUnitID + "'";
                                sqlcom.Parameters.Add("@SIDSERIES", SqlDbType.NVarChar).Value = ImSeries;
                                sqlcom.Parameters.Add("@SIDNO", SqlDbType.NVarChar).Value     = ImNo;
                                sqlcom.Parameters.Add("@SIDDATE", SqlDbType.NVarChar).Value   = Convert.ToDateTime(ImDate).ToString("yyyy-MM-dd");
                                sqlcom.ExecuteNonQuery();
                                sqlcom.Parameters.Clear();



                                sqlcom.CommandType = CommandType.Text;
                                sqlcom.CommandText = "Delete from SALEINVDET Where SIDSERIES=@SIDSERIES And SIDNO=@SIDNO And SIDDATE=@SIDDATE And UnitCode ='" + GlobalVariables.CUnitID + "'";
                                sqlcom.Parameters.Add("@SIDSERIES", SqlDbType.NVarChar).Value = ImSeries;
                                sqlcom.Parameters.Add("@SIDNO", SqlDbType.NVarChar).Value     = ImNo;
                                sqlcom.Parameters.Add("@SIDDATE", SqlDbType.NVarChar).Value   = Convert.ToDateTime(ImDate).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 SALEINVDET "
                                                     + " (SIDSYSDATE,SIDFNYR,SIDDATE,SIDNO,SIDSERIES,"
                                                     + " SIDBARCODE,SIDARTNO,SIDARTID,SIDCOLID,"
                                                     + " SIDSIZID,SIDSCANQTY,SIDARTMRP,SIDARTWSP,CustCode,SIDRETURNDATE,UnitCode  )"
                                                     + " values(@SIDSYSDATE,@SIDFNYR,@SIDDATE,@SIDNO,@SIDSERIES,@SIDBARCODE,@SIDARTNO,@SIDARTID,@SIDCOLID,"
                                                     + " @SIDSIZID,@SIDSCANQTY,@SIDARTMRP,@SIDARTWSP,@CustCode,@SIDRETURNDATE,@UnitCode)";
                                sqlcom.Parameters.Add("@SIDSYSDATE", SqlDbType.NVarChar).Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                sqlcom.Parameters.Add("@SIDFNYR", SqlDbType.NVarChar).Value    = GlobalVariables.FinancialYear;
                                sqlcom.Parameters.Add("@SIDDATE", SqlDbType.NVarChar).Value    = Convert.ToDateTime(txtApprovalDate.Text).ToString("yyyy-MM-dd");
                                sqlcom.Parameters.Add("@SIDNO", SqlDbType.NVarChar).Value      = txtApprovalNo.Text.Trim();;
                                sqlcom.Parameters.Add("@SIDSERIES", SqlDbType.NVarChar).Value  = "AP";
                                sqlcom.Parameters.Add("@SIDBARCODE", SqlDbType.NVarChar).Value = currentrow["SIDBARCODE"].ToString();
                                sqlcom.Parameters.Add("@SIDARTNO", SqlDbType.NVarChar).Value   = currentrow["SIDARTNO"].ToString();
                                sqlcom.Parameters.Add("@SIDARTID", SqlDbType.NVarChar).Value   = currentrow["SIDARTID"].ToString();
                                sqlcom.Parameters.Add("@SIDCOLID", SqlDbType.NVarChar).Value   = currentrow["SIDCOLID"].ToString();
                                sqlcom.Parameters.Add("@SIDSIZID", SqlDbType.NVarChar).Value   = currentrow["SIDSIZID"].ToString();
                                sqlcom.Parameters.Add("@SIDSCANQTY", SqlDbType.NVarChar).Value = Convert.ToDecimal(currentrow["SIDSCANQTY"]);
                                sqlcom.Parameters.Add("@SIDARTMRP", SqlDbType.NVarChar).Value  = Convert.ToDecimal(currentrow["SIDARTMRP"]);
                                sqlcom.Parameters.Add("@SIDARTWSP", SqlDbType.NVarChar).Value  = Convert.ToDecimal(currentrow["SIDARTWSP"]);

                                sqlcom.Parameters.Add("@CustCode", SqlDbType.NVarChar).Value      = txtCustCode.Text;
                                sqlcom.Parameters.Add("@SIDRETURNDATE", SqlDbType.NVarChar).Value = Convert.ToDateTime(txtReturnedUpTo.Text).ToString("yyyy-MM-dd");
                                sqlcom.Parameters.Add("@UnitCode", SqlDbType.NVarChar).Value      = GlobalVariables.CUnitID;
                                sqlcom.ExecuteNonQuery();
                                sqlcom.Parameters.Clear();

                                ProjectFunctions.GetDataSet("update SFDET set Used='Y' Where SFDBARCODE='" + currentrow["SIDBARCODE"].ToString() + "' And UnitCode='" + GlobalVariables.CUnitID + "'");
                            }


                            ProjectFunctions.SpeakError("Article Approval Saved Successfully");
                            sqlcon.Close();

                            Close();
                        }
                        catch (Exception ex)
                        {
                            XtraMessageBox.Show(ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (ValidateData())
            {
                InfoGridView.CloseEditor();
                InfoGridView.UpdateCurrentRow();
                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
                    {
                        sqlcom.CommandText = "sp_InsertOrderMst";
                        sqlcom.Parameters.AddWithValue("@OrdNo", txtOrderNo.Text.Trim());
                        sqlcom.Parameters["@OrdNo"].Direction = ParameterDirection.InputOutput;
                        sqlcom.Parameters.AddWithValue("@OrdDate", Convert.ToDateTime(dtOrderDate.Text).ToString("yyyy-MM-dd"));
                        sqlcom.Parameters.AddWithValue("@OrdForDate", Convert.ToDateTime(dtOrderForDate.Text).ToString("yyyy-MM-dd"));
                        sqlcom.Parameters.AddWithValue("@OrdDealerCode", txtDealerCode.Text.Trim());
                        if (S1 == "&Add")
                        {
                            sqlcom.Parameters.AddWithValue("@Tag", "&Add");
                        }
                        else
                        {
                            sqlcom.Parameters.AddWithValue("@Tag", "Edit");
                        }
                        sqlcom.ExecuteNonQuery();
                        txtOrderNo.Text = sqlcom.Parameters["@OrdNo"].Value.ToString();
                        sqlcom.Parameters.Clear();

                        if (S1 == "Edit")
                        {
                            sqlcom.CommandType = CommandType.Text;
                            sqlcom.CommandText = " Delete from DealerOrderData Where OrdDNo = @OrdDNo ";
                            sqlcom.Parameters.AddWithValue("@OrdDNo", txtOrderNo.Text.Trim());
                            sqlcom.ExecuteNonQuery();
                            sqlcom.Parameters.Clear();
                        }



#pragma warning disable CS0618 // 'GridControl.KeyboardFocusView' is obsolete: 'Use the FocusedView property instead.'
                        for (var i = 0; i < ((InfoGrid.KeyboardFocusView as GridView).RowCount); i++)
#pragma warning restore CS0618 // 'GridControl.KeyboardFocusView' is obsolete: 'Use the FocusedView property instead.'
                        {
                            sqlcom.CommandType = CommandType.Text;
                            var currentrow = InfoGridView.GetDataRow(i);
                            if (Convert.ToDecimal(currentrow["OrdDPrdQuantity"]) > 0)
                            {
                                sqlcom.CommandText = " Insert into DealerOrderData"
                                                     + " (OrdDNo,OrdDDate,OrdDDealerCode,OrdDPrdCode,OrdDPrdQuantity,OrdDForDate)"
                                                     + " values(@OrdDNo,@OrdDDate,@OrdDDealerCode,@OrdDPrdCode,@OrdDPrdQuantity,@OrdDForDate)";

                                sqlcom.Parameters.AddWithValue("@OrdDNo", txtOrderNo.Text.Trim());
                                sqlcom.Parameters.AddWithValue("@OrdDDate", Convert.ToDateTime(dtOrderDate.Text).ToString("yyyy-MM-dd"));
                                sqlcom.Parameters.AddWithValue("@OrdDDealerCode", txtDealerCode.Text.Trim());
                                sqlcom.Parameters.AddWithValue("@OrdDPrdCode", Convert.ToDecimal(currentrow["OrdDPrdCode"]));
                                sqlcom.Parameters.AddWithValue("@OrdDPrdQuantity", Convert.ToDecimal(currentrow["OrdDPrdQuantity"]));
                                sqlcom.Parameters.AddWithValue("@OrdDForDate", Convert.ToDateTime(dtOrderForDate.Text).ToString("yyyy-MM-dd"));

                                sqlcom.ExecuteNonQuery();
                                sqlcom.Parameters.Clear();
                            }
                        }
                        transaction.Commit();
                        ProjectFunctions.SpeakError("Order Data Saved Successfully");
                        sqlcon.Close();
                        if (S1 == "&Add")
                        {
                            txtDealerCode.Text = string.Empty;
                            txtDealerName.Text = string.Empty;
                            FrmDealerOrderMaster_Load(null, e);
                        }
                        else
                        {
                            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.Text;
                    try
                    {
                        if (s1 == "Edit")
                        {
                            sqlcom.CommandText = "Delete from SchmData Where IdNo=@IdNo And IdDate=@IdDate ";
                            sqlcom.Parameters.Add("@IdNo", SqlDbType.NVarChar).Value   = txtSerialNo.Text.Trim();
                            sqlcom.Parameters.Add("@IdDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(DtfeedingDate.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 SchmData "
                                                 + " (IdNo,IdDate,IdDealerCode,IdPrdAsgnCode,IdPrdCode, IdPrdQty,IdPrdQtyF,IdDtFrom,IdDtUpto)values("
                                                 + " @IdNo,@IdDate,@IdDealerCode,@IdPrdAsgnCode,@IdPrdCode, @IdPrdQty,@IdPrdQtyF,@IdDtFrom,@IdDtUpto)";

                            if (s1 == "Edit")
                            {
                                sqlcom.Parameters.Add("@IdNo", SqlDbType.NVarChar).Value = getNewInvoiceDocumentNo().PadLeft(6, '0');
                            }
                            else
                            {
                                sqlcom.Parameters.Add("@IdNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim();
                            }
                            sqlcom.Parameters.Add("@IdDate", SqlDbType.NVarChar).Value        = Convert.ToDateTime(DtfeedingDate.Text).ToString("yyyy-MM-dd");
                            sqlcom.Parameters.Add("@IdDealerCode", SqlDbType.NVarChar).Value  = currentrow["IdDealerCode"].ToString();
                            sqlcom.Parameters.Add("@IdPrdAsgnCode", SqlDbType.NVarChar).Value = currentrow["IdPrdAsgnCode"].ToString();
                            sqlcom.Parameters.Add("@IdPrdCode", SqlDbType.NVarChar).Value     = Convert.ToDecimal(currentrow["IdPrdCode"]);
                            sqlcom.Parameters.Add("@IdPrdQty", SqlDbType.NVarChar).Value      = Convert.ToDecimal(currentrow["IdPrdQty"]);
                            sqlcom.Parameters.Add("@IdPrdQtyF", SqlDbType.Decimal).Value      = Convert.ToDecimal(currentrow["IdPrdQtyF"]);
                            sqlcom.Parameters.Add("@IdDtFrom", SqlDbType.NVarChar).Value      = Convert.ToDateTime(currentrow["IdDtFrom"]).ToString("yyyy-MM-dd");
                            sqlcom.Parameters.Add("@IdDtUpto", SqlDbType.Decimal).Value       = Convert.ToDateTime(currentrow["IdDtUpto"]).ToString("yyyy-MM-dd");
                            sqlcom.ExecuteNonQuery();
                            sqlcom.Parameters.Clear();
                        }



                        transaction.Commit();
                        sqlcon.Close();
                        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()))
                {
                    //var MaxRow = ((InfoGrid.FocusedView as GridView).RowCount);

                    var MaxRow = ((InfoGrid.FocusedView as GridView).RowCount);
                    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_IndMstAddEdit]";
                            sqlcom.Parameters.Add("@IndmNo", SqlDbType.NVarChar).Value = "000000";
                            sqlcom.Parameters["@IndmNo"].Direction = ParameterDirection.InputOutput;
                            sqlcom.Parameters.Add("@IndmDate", SqlDbType.DateTime).Value     = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd");
                            sqlcom.Parameters.Add("@IndmDeptCode", SqlDbType.NVarChar).Value = txtDeptCode.Text.Trim();
                            sqlcom.Parameters.Add("@UnitCode", SqlDbType.NVarChar).Value     = GlobalVariables.CUnitID;
                            sqlcom.Parameters.Add("@AddEditTag", SqlDbType.VarChar).Value    = "ADD";
                            sqlcom.ExecuteNonQuery();
                            txtSerialNo.Text = sqlcom.Parameters["@IndmNo"].Value.ToString();
                            sqlcom.Parameters.Clear();
                        }
                        if (S1 == "Edit")
                        {
                            sqlcom.CommandText = "[sp_IndMstAddEdit]";
                            sqlcom.Parameters.Add("@IndmNo", SqlDbType.NVarChar).Value       = txtSerialNo.Text.Trim();
                            sqlcom.Parameters.Add("@IndmDate", SqlDbType.DateTime).Value     = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd");
                            sqlcom.Parameters.Add("@IndmDeptCode", SqlDbType.NVarChar).Value = txtDeptCode.Text.Trim();
                            sqlcom.Parameters.Add("@UnitCode", SqlDbType.NVarChar).Value     = GlobalVariables.CUnitID;
                            sqlcom.Parameters.Add("@AddEditTag", SqlDbType.VarChar).Value    = "EDIT";
                            sqlcom.ExecuteNonQuery();
                            sqlcom.Parameters.Clear();


                            sqlcom.CommandType = CommandType.Text;
                            sqlcom.CommandText = "Delete from IndData Where InddNo=@InddNo And IndDDate=@IndDDate ANd UnitCode=@UnitCode ";
                            sqlcom.Parameters.Add("@InddNo", SqlDbType.NVarChar).Value   = txtSerialNo.Text.Trim();
                            sqlcom.Parameters.Add("@IndDDate", SqlDbType.NVarChar).Value = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd");
                            sqlcom.Parameters.Add("@UnitCode", SqlDbType.NVarChar).Value = GlobalVariables.CUnitID;
                            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 IndData "
                                                 + " (InddNo,IndDDate,IndDItemCode,"
                                                 + " IndDItemQty,IndEstAmt,UnitCode)"
                                                 + " values(@InddNo,@IndDDate,@IndDItemCode,@IndDItemQty,"
                                                 + " @IndEstAmt,@UnitCode)";
                            sqlcom.Parameters.Add("@InddNo", SqlDbType.NVarChar).Value      = txtSerialNo.Text;
                            sqlcom.Parameters.Add("@IndDDate", SqlDbType.DateTime).Value    = Convert.ToDateTime(dtInvoiceDate.Text).ToString("dd-MM-yyyy");
                            sqlcom.Parameters.Add("@IndDItemCode", SqlDbType.Decimal).Value = Convert.ToDecimal(currentrow["PrdCode"]);
                            sqlcom.Parameters.Add("@IndDItemQty", SqlDbType.Decimal).Value  = Convert.ToDecimal(currentrow["Qty"]);
                            sqlcom.Parameters.Add("@IndEstAmt", SqlDbType.Decimal).Value    = Convert.ToDecimal(currentrow["Amount"]);
                            sqlcom.Parameters.Add("@UnitCode", SqlDbType.NVarChar).Value    = GlobalVariables.CUnitID;
                            sqlcom.ExecuteNonQuery();
                            sqlcom.Parameters.Clear();
                        }

                        transaction.Commit();


                        sqlcon.Close();
                        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        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_Ins_StockOutMst]";
                            sqlcom.Parameters.Add("@MmDocNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim();
                            sqlcom.Parameters["@MmDocNo"].Direction = ParameterDirection.InputOutput;
                            sqlcom.Parameters.Add("@MmDocDate", SqlDbType.DateTime).Value  = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd");
                            sqlcom.Parameters.Add("@MmDocType", SqlDbType.NVarChar).Value  = "SO";
                            sqlcom.Parameters.Add("@MMPlant", SqlDbType.NVarChar).Value    = txtPlant.Text.Trim();
                            sqlcom.Parameters.Add("@MMShift", SqlDbType.NVarChar).Value    = txtShift.Text.Trim();
                            sqlcom.Parameters.Add("@MmDeptCode", SqlDbType.NVarChar).Value = txtDeptCode.Text.Trim();
                            sqlcom.Parameters.Add("@AddEditTag", SqlDbType.VarChar).Value  = "&Add";
                            sqlcom.ExecuteNonQuery();
                            txtSerialNo.Text = sqlcom.Parameters["@MmDocNo"].Value.ToString();
                            sqlcom.Parameters.Clear();
                        }
                        if (s1 == "Edit")
                        {
                            sqlcom.CommandText = "[sp_Ins_StockOutMst]";
                            sqlcom.Parameters.Add("@MmDocNo", SqlDbType.NVarChar).Value = txtSerialNo.Text.Trim();
                            sqlcom.Parameters["@MmDocNo"].Direction = ParameterDirection.InputOutput;
                            sqlcom.Parameters.Add("@MmDocDate", SqlDbType.DateTime).Value  = Convert.ToDateTime(dtInvoiceDate.Text).ToString("yyyy-MM-dd");
                            sqlcom.Parameters.Add("@MmDocType", SqlDbType.NVarChar).Value  = "SO";
                            sqlcom.Parameters.Add("@MMPlant", SqlDbType.NVarChar).Value    = txtPlant.Text.Trim();
                            sqlcom.Parameters.Add("@MMShift", SqlDbType.NVarChar).Value    = txtShift.Text.Trim();
                            sqlcom.Parameters.Add("@MmDeptCode", SqlDbType.NVarChar).Value = txtDeptCode.Text.Trim();
                            sqlcom.Parameters.Add("@AddEditTag", SqlDbType.VarChar).Value  = "EDIT";
                            sqlcom.ExecuteNonQuery();
                            sqlcom.Parameters.Clear();

                            sqlcom.CommandType = CommandType.Text;
                            sqlcom.CommandText = "Delete from MrData Where MdDocNo=@MdDocNo And MdDocDate=@MdDocDate And MdDocType='SO'";
                            sqlcom.Parameters.Add("@MdDocNo", SqlDbType.NVarChar).Value   = txtSerialNo.Text.Trim();
                            sqlcom.Parameters.Add("@MdDocDate", 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 MrData "
                                                 + " (MdDocType,MdDocNo,MdDocDate,MdPrdCode,MdPrdQty,MdDeptCode,MdPlant,MdShift)"

                                                 + " values(@MdDocType,@MdDocNo,@MdDocDate,@MdPrdCode,@MdPrdQty,@MdDeptCode,@MdPlant,@MdShift)";


                            sqlcom.Parameters.Add("@MdDocType", SqlDbType.NVarChar).Value  = "SO";
                            sqlcom.Parameters.Add("@MdDocNo", SqlDbType.NVarChar).Value    = txtSerialNo.Text;
                            sqlcom.Parameters.Add("@MdDocDate", SqlDbType.DateTime).Value  = Convert.ToDateTime(dtInvoiceDate.Text).ToString("dd-MM-yyyy");
                            sqlcom.Parameters.Add("@MdPrdCode", SqlDbType.Decimal).Value   = Convert.ToDecimal(currentrow["PrdCode"]);
                            sqlcom.Parameters.Add("@MdPrdQty", SqlDbType.Decimal).Value    = -Convert.ToDecimal(currentrow["Quantity"]);
                            sqlcom.Parameters.Add("@MdDeptCode", SqlDbType.NVarChar).Value = txtDeptCode.Text.Trim();
                            sqlcom.Parameters.Add("@MdPlant", SqlDbType.NVarChar).Value    = txtPlant.Text.Trim();
                            sqlcom.Parameters.Add("@MdShift", SqlDbType.NVarChar).Value    = txtShift.Text.Trim();

                            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 SaveInvoice()
        {
            if (ValidateDataForSaving())
            {
                using (var sqlcon = new SqlConnection(ProjectFunctions.GetConnection()))
                {
                    var MaxRow = ((InfoGrid.FocusedView as GridView).RowCount);
                    sqlcon.Open();
                    var sqlcom = sqlcon.CreateCommand();
                    sqlcom.Connection  = sqlcon;
                    sqlcom.CommandType = CommandType.Text;
                    try
                    {
                        if (S1 == "&Add")
                        {
                            string BillNo = string.Empty;

                            BillNo             = ProjectFunctions.GetDataSet("select isnull(max(SIMNO),0)+1 from SALEINVMAIN where SIMSERIES='AR' And SIMFNYR='" + GlobalVariables.FinancialYear + "'And UnitCode='" + GlobalVariables.CUnitID + "'").Tables[0].Rows[0][0].ToString();
                            txtReturnNo.Text   = BillNo;
                            sqlcom.CommandText = "Insert into SALEINVMAIN(SIMSYSDATE,SIMFNYR,SIMDATE,SIMNO,SIMSERIES,CustCode,SIMRemarks,UnitCode)values(" +
                                                 "@SIMSYSDATE,@SIMFNYR,@SIMDATE,@SIMNO,@SIMSERIES,@CustCode,@SIMRemarks,@UnitCode)";
                            sqlcom.Parameters.Add("@SIMSYSDATE", SqlDbType.NVarChar).Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            sqlcom.Parameters.Add("@SIMFNYR", SqlDbType.NVarChar).Value    = GlobalVariables.FinancialYear;
                            sqlcom.Parameters.Add("@SIMDATE", SqlDbType.NVarChar).Value    = Convert.ToDateTime(txtReturnDate.Text).ToString("yyyy-MM-dd");
                            sqlcom.Parameters.Add("@SIMNO", SqlDbType.NVarChar).Value      = txtReturnNo.Text;
                            sqlcom.Parameters.Add("@SIMSERIES", SqlDbType.NVarChar).Value  = "AR";
                            sqlcom.Parameters.Add("@CustCode", SqlDbType.NVarChar).Value   = txtCustCode.Text;
                            sqlcom.Parameters.Add("@SIMRemarks", SqlDbType.NVarChar).Value = txtRemarks.Text;
                            sqlcom.Parameters.Add("@UnitCode", SqlDbType.NVarChar).Value   = GlobalVariables.CUnitID;
                            sqlcom.ExecuteNonQuery();
                            sqlcom.Parameters.Clear();
                        }
                        if (S1 == "Edit")
                        {
                            sqlcom.CommandText = "Update SALEINVMAIN Set SIMSYSDATE=@SIMSYSDATE,SIMFNYR=@SIMFNYR,SIMDATE=@SIMDATE,SIMNO=@SIMNO," +
                                                 " SIMSERIES=@SIMSERIES,CustCode=@CustCode,SIMRemarks=@SIMRemarks Where SIMDATE='" + Convert.ToDateTime(ImDate).ToString("yyyy-MM-dd") + "' And SIMNO='" + ImNo + "' And SIMSERIES='" + ImSeries + "' ANd UnitCode='" + GlobalVariables.CUnitID + "'";

                            sqlcom.Parameters.Add("@SIMSYSDATE", SqlDbType.NVarChar).Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            sqlcom.Parameters.Add("@SIMFNYR", SqlDbType.NVarChar).Value    = GlobalVariables.FinancialYear;
                            sqlcom.Parameters.Add("@SIMDATE", SqlDbType.NVarChar).Value    = Convert.ToDateTime(txtReturnDate.Text).ToString("yyyy-MM-dd");
                            sqlcom.Parameters.Add("@SIMNO", SqlDbType.NVarChar).Value      = txtReturnNo.Text;
                            sqlcom.Parameters.Add("@SIMSERIES", SqlDbType.NVarChar).Value  = "AR";
                            sqlcom.Parameters.Add("@CustCode", SqlDbType.NVarChar).Value   = txtCustCode.Text;
                            sqlcom.Parameters.Add("@SIMRemarks", SqlDbType.NVarChar).Value = txtRemarks.Text;
                            sqlcom.ExecuteNonQuery();
                            sqlcom.Parameters.Clear();


                            sqlcom.CommandType = CommandType.Text;
                            sqlcom.CommandText = "update SFDET set Used='Y' Where SFDBARCODE in (Select SIDBARCODE  from SALEINVDET Where SIDSERIES=@SIDSERIES And SIDNO=@SIDNO And SIDDATE=@SIDDATE And UnitCode='" + GlobalVariables.FinancialYear + "') ANd UnitCode='" + GlobalVariables.CUnitID + "'";
                            sqlcom.Parameters.Add("@SIDSERIES", SqlDbType.NVarChar).Value = ImSeries;
                            sqlcom.Parameters.Add("@SIDNO", SqlDbType.NVarChar).Value     = ImNo;
                            sqlcom.Parameters.Add("@SIDDATE", SqlDbType.NVarChar).Value   = Convert.ToDateTime(ImDate).ToString("yyyy-MM-dd");
                            sqlcom.ExecuteNonQuery();
                            sqlcom.Parameters.Clear();

                            sqlcom.CommandType = CommandType.Text;
                            sqlcom.CommandText = "Delete from SALEINVDET Where SIDSERIES=@SIDSERIES And SIDNO=@SIDNO And SIDDATE=@SIDDATE ANd UnitCode='" + GlobalVariables.CUnitID + "'";
                            sqlcom.Parameters.Add("@SIDSERIES", SqlDbType.NVarChar).Value = ImSeries;
                            sqlcom.Parameters.Add("@SIDNO", SqlDbType.NVarChar).Value     = ImNo;
                            sqlcom.Parameters.Add("@SIDDATE", SqlDbType.NVarChar).Value   = Convert.ToDateTime(ImDate).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 SALEINVDET "
                                                 + " (SIDSYSDATE,SIDFNYR,SIDDATE,SIDNO,SIDSERIES,"
                                                 + " SIDBARCODE,SIDARTNO,SIDARTID,SIDCOLID,"
                                                 + " SIDSIZID,SIDSCANQTY,SIDARTMRP,SIDARTWSP,CustCode,UnitCode  )"
                                                 + " values(@SIDSYSDATE,@SIDFNYR,@SIDDATE,@SIDNO,@SIDSERIES,@SIDBARCODE,@SIDARTNO,@SIDARTID,@SIDCOLID,"
                                                 + " @SIDSIZID,@SIDSCANQTY,@SIDARTMRP,@SIDARTWSP,@CustCode,@UnitCode)";
                            sqlcom.Parameters.Add("@SIDSYSDATE", SqlDbType.NVarChar).Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            sqlcom.Parameters.Add("@SIDFNYR", SqlDbType.NVarChar).Value    = GlobalVariables.FinancialYear;
                            sqlcom.Parameters.Add("@SIDDATE", SqlDbType.NVarChar).Value    = Convert.ToDateTime(txtReturnDate.Text).ToString("yyyy-MM-dd");
                            sqlcom.Parameters.Add("@SIDNO", SqlDbType.NVarChar).Value      = txtReturnNo.Text.Trim();;
                            sqlcom.Parameters.Add("@SIDSERIES", SqlDbType.NVarChar).Value  = "AR";
                            sqlcom.Parameters.Add("@SIDBARCODE", SqlDbType.NVarChar).Value = currentrow["SIDBARCODE"].ToString();
                            sqlcom.Parameters.Add("@SIDARTNO", SqlDbType.NVarChar).Value   = currentrow["SIDARTNO"].ToString();
                            sqlcom.Parameters.Add("@SIDARTID", SqlDbType.NVarChar).Value   = currentrow["SIDARTID"].ToString();
                            sqlcom.Parameters.Add("@SIDCOLID", SqlDbType.NVarChar).Value   = currentrow["SIDCOLID"].ToString();
                            sqlcom.Parameters.Add("@SIDSIZID", SqlDbType.NVarChar).Value   = currentrow["SIDSIZID"].ToString();
                            sqlcom.Parameters.Add("@SIDSCANQTY", SqlDbType.NVarChar).Value = -Convert.ToDecimal(currentrow["SIDSCANQTY"]);
                            sqlcom.Parameters.Add("@SIDARTMRP", SqlDbType.NVarChar).Value  = Convert.ToDecimal(currentrow["SIDARTMRP"]);
                            sqlcom.Parameters.Add("@SIDARTWSP", SqlDbType.NVarChar).Value  = Convert.ToDecimal(currentrow["SIDARTWSP"]);
                            sqlcom.Parameters.Add("@CustCode", SqlDbType.NVarChar).Value   = txtCustCode.Text;
                            sqlcom.Parameters.Add("@UnitCode", SqlDbType.NVarChar).Value   = GlobalVariables.CUnitID;
                            sqlcom.ExecuteNonQuery();
                            sqlcom.Parameters.Clear();

                            ProjectFunctions.GetDataSet("update SFDET set Used='N' Where SFDBARCODE='" + currentrow["SIDBARCODE"].ToString() + "' And UnitCode='" + GlobalVariables.CUnitID + "'");
                        }


                        ProjectFunctions.SpeakError("Approval Return Saved Successfully");
                        sqlcon.Close();

                        Close();
                    }
#pragma warning disable CS0168 // The variable 'ex' is declared but never used
                    catch (Exception ex)
#pragma warning restore CS0168 // The variable 'ex' is declared but never used
                    {
                    }
                }
            }
        }
        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);
                        }
                    }
                }
            }
        }