Exemplo n.º 1
0
        protected void btnSubmit_Click1(object sender, EventArgs e)
        {
            SqlConnection  con  = baseObj.GetConnection();
            SqlCommand     cmd  = new SqlCommand();
            SqlTransaction tran = null;

            try
            {
                if (grvDetail.Rows.Count <= 0)
                {
                    this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('No Line Exist in GridView...!');", true);
                    return;
                }

                DataTable dt     = baseObj.GetNumSequenceNew(11, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString()); //st.Substring(st.Length - 6) + System.DateTime.Now.ToString("yyMMddhhmmss");
                string    Doc_NO = string.Empty;
                string    NUMSEQ = string.Empty;
                if (dt != null)
                {
                    Doc_NO = dt.Rows[0][0].ToString();
                    NUMSEQ = dt.Rows[0][1].ToString();
                }
                else
                {
                    return;
                }

                if (con.State.ToString() == "Closed")
                {
                    con.Open();
                }
                tran            = con.BeginTransaction();
                cmd.Connection  = con;
                cmd.Transaction = tran;

                foreach (GridViewRow grv in grvDetail.Rows)
                {
                    string      OBJECT_CODE        = grv.Cells[8].Text;
                    string      OBJECT_SUBCODE     = grv.Cells[7].Text;
                    string      TARGET_CODE        = "";
                    string      OBJECT             = "";
                    string      TARGET_DESCRIPTION = grv.Cells[10].Text;
                    string      FROM_DATE          = grv.Cells[0].Text;
                    string      TO_DATE            = grv.Cells[1].Text;
                    string      TARGET             = "0";
                    string      ACHIVEMENT         = "0";
                    string      TARGET_INCENTIVE   = "0";
                    string      ACTUAL_INCENTIVE   = grv.Cells[11].Text;
                    string      CLAIM_CATEGORY     = grv.Cells[2].Text;
                    string      CLAIM_SUBCATEGORY  = grv.Cells[4].Text;
                    string      ClaimType          = "0";
                    HiddenField hdnBUCode          = (HiddenField)grv.FindControl("BUCode");
                    string      BU_CODE            = hdnBUCode.Value.ToString();
                    if (grv.Cells[6].Text == "PSR")
                    {
                        ClaimType = "0";
                    }
                    if (grv.Cells[6].Text == "SITE")
                    {
                        ClaimType = "1";
                    }
                    if (grv.Cells[6].Text == "CUSTOMERGROUP")
                    {
                        ClaimType = "2";
                    }

                    string CLAIM_TYPE = ClaimType;
                    string STATUS     = "0";
                    cmd.Connection = con;
                    cmd.Parameters.Clear();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "ACXINSERTCLAIMMASTER";
                    cmd.Parameters.Add("@DATAAREAID", SqlDbType.NVarChar).Value         = Session["DATAAREAID"];
                    cmd.Parameters.Add("@DOCUMENT_CODE", SqlDbType.NVarChar).Value      = Doc_NO;
                    cmd.Parameters.Add("@SITE_CODE", SqlDbType.NVarChar).Value          = Session["SiteCode"].ToString();
                    cmd.Parameters.Add("@OBJECT", SqlDbType.NVarChar).Value             = OBJECT;
                    cmd.Parameters.Add("@OBJECT_CODE", SqlDbType.NVarChar).Value        = OBJECT_CODE;
                    cmd.Parameters.Add("@OBJECT_SUBCODE", SqlDbType.NVarChar).Value     = OBJECT_SUBCODE;
                    cmd.Parameters.Add("@TARGET_CODE", SqlDbType.NVarChar).Value        = TARGET_CODE;
                    cmd.Parameters.Add("@TARGET_DESCRIPTION", SqlDbType.NVarChar).Value = TARGET_DESCRIPTION;
                    cmd.Parameters.Add("@FROM_DATE", SqlDbType.SmallDateTime).Value     = FROM_DATE;
                    cmd.Parameters.Add("@TO_DATE", SqlDbType.SmallDateTime).Value       = TO_DATE;
                    cmd.Parameters.Add("@TARGET", SqlDbType.Decimal).Value             = TARGET;
                    cmd.Parameters.Add("@ACHIVEMENT", SqlDbType.Decimal).Value         = ACHIVEMENT;
                    cmd.Parameters.Add("@TARGET_INCENTIVE", SqlDbType.Decimal).Value   = TARGET_INCENTIVE;
                    cmd.Parameters.Add("@ACTUAL_INCENTIVE", SqlDbType.Decimal).Value   = ACTUAL_INCENTIVE;
                    cmd.Parameters.Add("@CLAIM_CATEGORY", SqlDbType.NVarChar).Value    = CLAIM_CATEGORY;
                    cmd.Parameters.Add("@CLAIM_SUBCATEGORY", SqlDbType.NVarChar).Value = CLAIM_SUBCATEGORY;
                    cmd.Parameters.Add("@CLAIM_TYPE", SqlDbType.NVarChar).Value        = CLAIM_TYPE;
                    cmd.Parameters.Add("@STATUS", SqlDbType.Int).Value                   = STATUS;
                    cmd.Parameters.Add("@NumSeq", SqlDbType.BigInt).Value                = NUMSEQ;
                    cmd.Parameters.Add("@TARGET_GROUP", SqlDbType.NVarChar).Value        = "";
                    cmd.Parameters.Add("@CALCULATION_PATTERN", SqlDbType.NVarChar).Value = "";
                    cmd.Parameters.Add("CLAIM_MONTH", SqlDbType.NVarChar).Value          = FROM_DATE;
                    cmd.Parameters.Add("@BU_CODE", SqlDbType.NVarChar).Value             = BU_CODE;

                    cmd.ExecuteNonQuery();
//                    string sqlstr = @"INSERT INTO [ax].[ACXCLAIMMASTER] ([DATAAREAID],[RECID]
//                                   ,[DOCUMENT_CODE],[DOCUMENT_DATE],[SITE_CODE],[OBJECT],[OBJECT_CODE],[OBJECT_SUBCODE],[TARGET_CODE]
//                                   ,[TARGET_DESCRIPTION],[FROM_DATE],[TO_DATE],[TARGET],[ACHIVEMENT],[TARGET_INCENTIVE],[ACTUAL_INCENTIVE],[CLAIM_CATEGORY]
//                                   ,[CLAIM_SUBCATEGORY],[CLAIM_TYPE],[STATUS],[NumSeq],[Target_Group],[Calculation_Pattern])
//                                    VALUES ( '" + Session["DATAAREAID"] + "','" + Recid + "','" + Doc_NO + "','" + System.DateTime.Now + "','" + Session["SiteCode"].ToString() + "','" + CLAIM_TYPE + "','" + OBJECT_CODE + "', " +
//                        " '" + OBJECT_SUBCODE + "', '" + TARGET_CODE + "','" + TARGET_DESCRIPTION + "','" + FROM_DATE + "','" + TO_DATE + "','" + TARGET + "','" + ACHIVEMENT + "', " +
//                        " '" + TARGET_INCENTIVE + "','" + ACTUAL_INCENTIVE + "','" + CLAIM_CATEGORY + "','" + CLAIM_SUBCATEGORY + "','0','" + STATUS + "','" + NUMSEQ + "','','')";

//                    cmd.Connection = con;
//                    cmd.CommandText = sqlstr;
//                    cmd.ExecuteNonQuery();
                }
                tran.Commit();
                //string message = "alert('Data Saved Successfully : " + Doc_NO + "')";
                //ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);
                //this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Data Saved Successfully : " + Doc_NO + "');", true);
                Cleardata();
                grvDetail.DataSource = null;
                grvDetail.DataBind();
                grvDetail.Visible = false;
                creataDataTabel();
                updatepnlGrid.Update();
                string message = "alert('Data Saved Successfully : " + Doc_NO + "')";
                ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                lblError.Text = ex.Message;
                ErrorSignal.FromCurrentContext().Raise(ex);
            }
            finally { if (con.State.ToString() == "Open")
                      {
                          con.Close();
                      }
            }
        }
Exemplo n.º 2
0
        protected void btnsave_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection  con  = baseObj.GetConnection();
                SqlTransaction tran = null;
                SqlCommand     cmd  = new SqlCommand();
                try
                {
                    DataTable dt     = baseObj.GetNumSequenceNew(11, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString()); //st.Substring(st.Length - 6) + System.DateTime.Now.ToString("yyMMddhhmmss");
                    string    Doc_NO = string.Empty;
                    string    NUMSEQ = string.Empty;
                    if (dt != null)
                    {
                        Doc_NO = dt.Rows[0][0].ToString();
                        NUMSEQ = dt.Rows[0][1].ToString();
                    }
                    else
                    {
                        return;
                    }

                    if (con.State.ToString() == "Closed")
                    {
                        con.Open();
                    }
                    tran            = con.BeginTransaction();
                    cmd.Transaction = tran;

                    Boolean FoundAlready, FoundSuccess;
                    FoundAlready = false;
                    FoundSuccess = false;
                    //foreach (GridViewRow grv in grvDetail.Rows)
                    for (int i = 0; i < grvDetail.Rows.Count; i++)
                    {
                        string OBJECT = string.Empty;
                        if (grvDetail.Rows[i].Cells[6].Text.ToString() == "Site")
                        {
                            OBJECT = "1";
                        }
                        else if (grvDetail.Rows[i].Cells[6].Text.ToString() == "PSR")
                        {
                            OBJECT = "0";
                        }
                        else
                        {
                            OBJECT = "2";
                        }
                        string OBJECT_CODE         = grvDetail.Rows[i].Cells[7].Text.ToString().Replace("&nbsp;", "");
                        string OBJECT_SUBCODE      = grvDetail.Rows[i].Cells[8].Text.ToString().Replace("&nbsp;", "");
                        string TARGET_CODE         = grvDetail.Rows[i].Cells[1].Text.ToString().Replace("&nbsp;", "");
                        string TARGET_DESCRIPTION  = grvDetail.Rows[i].Cells[2].Text.ToString().Replace("&nbsp;", "");
                        string FROM_DATE           = Convert.ToDateTime(grvDetail.Rows[i].Cells[4].Text).ToString("yyyy-MM-dd");
                        string TO_DATE             = Convert.ToDateTime(grvDetail.Rows[i].Cells[5].Text).ToString("yyyy-MM-dd");
                        string TARGET              = Convert.ToDouble(grvDetail.Rows[i].Cells[18].Text.ToString().Replace("&nbsp;", "")).ToString();
                        string ACHIVEMENT          = Convert.ToDouble(grvDetail.Rows[i].Cells[20].Text.ToString().Replace("&nbsp;", "")).ToString();
                        string TARGET_INCENTIVE    = Convert.ToDouble(grvDetail.Rows[i].Cells[19].Text.ToString().Replace("&nbsp;", "")).ToString();
                        string ACTUAL_INCENTIVE    = Convert.ToDouble(grvDetail.Rows[i].Cells[21].Text.ToString().Replace("&nbsp;", "")).ToString();
                        string CLAIM_CATEGORY      = grvDetail.Rows[i].Cells[14].Text.ToString().Replace("&nbsp;", "");
                        string CLAIM_SUBCATEGORY   = grvDetail.Rows[i].Cells[16].Text.ToString().Replace("&nbsp;", "");
                        string CLAIM_TYPE          = drptargetType.SelectedValue.ToString();
                        string STATUS              = "0";
                        string MODIFIEDDATETIME    = string.Empty;
                        string CREATEDDATETIME     = string.Empty;
                        string TARGET_GROUP        = grvDetail.Rows[i].Cells[13].Text.ToString().Replace("&nbsp;", "");
                        string CALCULATION_PATTERN = grvDetail.Rows[i].Cells[11].Text.ToString().Replace("&nbsp;", "");
                        string sqlstr              = @"SELECT * FROM AX.ACXCLAIMMASTER where SITE_CODE='" + Session["SiteCode"].ToString() + "' and FROM_DATE='" + FROM_DATE + "' ";
                        sqlstr += "and TO_DATE='" + TO_DATE + "' and OBJECT_CODE='" + OBJECT_CODE + "' AND OBJECT='" + OBJECT + "' and OBJECT_SUBCODE='" + OBJECT_SUBCODE + "' and TARGET_CODE='" + TARGET_CODE + "' ";
                        sqlstr += "and TARGET=" + TARGET + " and CLAIM_CATEGORY='" + CLAIM_CATEGORY + "' and CLAIM_SUBCATEGORY='" + CLAIM_SUBCATEGORY + "' and DATAAREAID='" + Session["DATAAREAID"] + "' and TARGET_GROUP='" + TARGET_GROUP + "'";
                        dt      = baseObj.GetData(sqlstr);
                        if (dt.Rows.Count == 0)
                        {
                            #region this for creating a single row of fix incentive
                            //for (int j = i + 1; j < grvDetail.Rows.Count; j++)
                            //{
                            //    string NEXT_OBJECT = string.Empty;
                            //    if (grvDetail.Rows[j].Cells[6].Text.ToString() == "Site")
                            //        NEXT_OBJECT = "1";
                            //    else if (grvDetail.Rows[j].Cells[6].Text.ToString() == "PSR")
                            //        NEXT_OBJECT = "0";
                            //    else
                            //        NEXT_OBJECT = "2";
                            //    string NEXT_OBJECT_CODE = grvDetail.Rows[j].Cells[7].Text.ToString().Replace("&nbsp;", "");
                            //    string NEXT_OBJECT_SUBCODE = grvDetail.Rows[j].Cells[9].Text.ToString().Replace("&nbsp;", "");
                            //    string NEXT_TARGET_CODE = grvDetail.Rows[j].Cells[1].Text.ToString().Replace("&nbsp;", "");
                            //    string NEXT_FROM_DATE = Convert.ToDateTime(grvDetail.Rows[j].Cells[4].Text).ToString("yyyy-MM-dd");
                            //    string NEXT_TO_DATE = Convert.ToDateTime(grvDetail.Rows[j].Cells[5].Text).ToString("yyyy-MM-dd");
                            //    string NEXT_ACTUAL_INCENTIVE = Convert.ToDouble(grvDetail.Rows[j].Cells[21].Text.ToString().Replace("&nbsp;", "")).ToString();
                            //    string NEXT_CLAIM_CATEGORY = grvDetail.Rows[j].Cells[14].Text.ToString().Replace("&nbsp;", "");
                            //    string NEXT_CLAIM_SUBCATEGORY = grvDetail.Rows[j].Cells[16].Text.ToString().Replace("&nbsp;", "");
                            //    string NEXT_TARGET_GROUP = grvDetail.Rows[j].Cells[13].Text.ToString().Replace("&nbsp;", ""); ;

                            //    if (FROM_DATE == NEXT_FROM_DATE && TO_DATE == NEXT_TO_DATE && OBJECT_CODE == NEXT_OBJECT_CODE && OBJECT == NEXT_OBJECT && TARGET_CODE == NEXT_TARGET_CODE && CLAIM_CATEGORY == NEXT_CLAIM_CATEGORY && CLAIM_SUBCATEGORY == NEXT_CLAIM_SUBCATEGORY && TARGET_GROUP == NEXT_TARGET_GROUP && OBJECT_SUBCODE == NEXT_OBJECT_SUBCODE)
                            //    {
                            //        ACTUAL_INCENTIVE += NEXT_ACTUAL_INCENTIVE;
                            //    }
                            //    else
                            //    { break; }
                            //}
                            #endregion
                            if (Convert.ToDouble(ACTUAL_INCENTIVE) > 0)
                            {
                                cmd.Connection = con;
                                cmd.Parameters.Clear();
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.CommandText = "ACXINSERTCLAIMMASTER";
                                cmd.Parameters.Add("@DATAAREAID", SqlDbType.NVarChar).Value         = Session["DATAAREAID"];
                                cmd.Parameters.Add("@DOCUMENT_CODE", SqlDbType.NVarChar).Value      = Doc_NO;
                                cmd.Parameters.Add("@SITE_CODE", SqlDbType.NVarChar).Value          = Session["SiteCode"].ToString();
                                cmd.Parameters.Add("@OBJECT", SqlDbType.NVarChar).Value             = OBJECT;
                                cmd.Parameters.Add("@OBJECT_CODE", SqlDbType.NVarChar).Value        = OBJECT_CODE;
                                cmd.Parameters.Add("@OBJECT_SUBCODE", SqlDbType.NVarChar).Value     = OBJECT_SUBCODE;
                                cmd.Parameters.Add("@TARGET_CODE", SqlDbType.NVarChar).Value        = TARGET_CODE;
                                cmd.Parameters.Add("@TARGET_DESCRIPTION", SqlDbType.NVarChar).Value = TARGET_DESCRIPTION;
                                cmd.Parameters.Add("@FROM_DATE", SqlDbType.SmallDateTime).Value     = FROM_DATE;
                                cmd.Parameters.Add("@TO_DATE", SqlDbType.SmallDateTime).Value       = TO_DATE;
                                cmd.Parameters.Add("@TARGET", SqlDbType.Decimal).Value             = TARGET;
                                cmd.Parameters.Add("@ACHIVEMENT", SqlDbType.Decimal).Value         = ACHIVEMENT;
                                cmd.Parameters.Add("@TARGET_INCENTIVE", SqlDbType.Decimal).Value   = TARGET_INCENTIVE;
                                cmd.Parameters.Add("@ACTUAL_INCENTIVE", SqlDbType.Decimal).Value   = ACTUAL_INCENTIVE;
                                cmd.Parameters.Add("@CLAIM_CATEGORY", SqlDbType.NVarChar).Value    = CLAIM_CATEGORY;
                                cmd.Parameters.Add("@CLAIM_SUBCATEGORY", SqlDbType.NVarChar).Value = CLAIM_SUBCATEGORY;
                                cmd.Parameters.Add("@CLAIM_TYPE", SqlDbType.NVarChar).Value        = CLAIM_TYPE;
                                cmd.Parameters.Add("@STATUS", SqlDbType.Int).Value                   = STATUS;
                                cmd.Parameters.Add("@NumSeq", SqlDbType.BigInt).Value                = NUMSEQ;
                                cmd.Parameters.Add("@TARGET_GROUP", SqlDbType.NVarChar).Value        = TARGET_GROUP;
                                cmd.Parameters.Add("@CALCULATION_PATTERN", SqlDbType.NVarChar).Value = CALCULATION_PATTERN;
                                cmd.Parameters.Add("CLAIM_MONTH", SqlDbType.NVarChar).Value          = null;
                                cmd.Parameters.Add("@BU_CODE", SqlDbType.NVarChar).Value             = ddlBusinessUnit.SelectedValue;
                                cmd.ExecuteNonQuery();

//                                sqlstr = @"INSERT INTO [ax].[ACXCLAIMMASTER] ([DATAAREAID],[RECID],[DOCUMENT_CODE],[DOCUMENT_DATE],[SITE_CODE],[OBJECT],[OBJECT_CODE],[OBJECT_SUBCODE],[TARGET_CODE]
//                                                       ,[TARGET_DESCRIPTION],[FROM_DATE],[TO_DATE],[TARGET],[ACHIVEMENT],[TARGET_INCENTIVE],[ACTUAL_INCENTIVE],[CLAIM_CATEGORY]
//                                                       ,[CLAIM_SUBCATEGORY],[CLAIM_TYPE],[STATUS],[MODIFIEDDATETIME],[CREATEDDATETIME],[NumSeq],TARGET_GROUP,CALCULATION_PATTERN)
//                                                        VALUES ( '" + Session["DATAAREAID"] + "','1','" + Doc_NO + "',getdate(),'" + Session["SiteCode"].ToString() + "'," + OBJECT + ",'" + OBJECT_CODE + "', " +
//                                    " '" + OBJECT_SUBCODE + "', '" + TARGET_CODE + "','" + TARGET_DESCRIPTION + "','" + FROM_DATE + "','" + TO_DATE + "'," + TARGET + "," + ACHIVEMENT + ", " +
//                                    " " + TARGET_INCENTIVE + "," + ACTUAL_INCENTIVE + ",'" + CLAIM_CATEGORY + "','" + CLAIM_SUBCATEGORY + "','" + CLAIM_TYPE + "','" + STATUS + "','" + MODIFIEDDATETIME + "'," +
//                                    " '" + CREATEDDATETIME + "','" + NUMSEQ + "','" + TARGET_GROUP + "','" + CALCULATION_PATTERN + "')";
//                                cmd.Connection = con;
//                                cmd.CommandText = sqlstr;
//                                cmd.ExecuteNonQuery();
                                grvDetail.Rows[i].Cells[22].Text = "Success";
                                FoundSuccess = true;
                            }
                        }
                        else
                        {
                            FoundAlready = true;
                            grvDetail.Rows[i].Cells[22].Text = "Already";
                        }
                    }
                    tran.Commit();
                    if (FoundAlready == true && FoundSuccess == true)
                    {
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "Information", "alert('Some data already saved. Except that saved successfully.');", true);
                    }
                    else if (FoundAlready)
                    {
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "Information", "alert('Data already saved.');", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "Information", "alert('Data saved successfully.');", true);
                    }
                    grvDetail.DataSource = null;
                    grvDetail.Visible    = false;
                    // grvDetail.Columns[22].Visible = true;
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    lblError.Text = ex.Message;
                    ErrorSignal.FromCurrentContext().Raise(ex);
                }
                finally { if (con.State.ToString() == "Open")
                          {
                              con.Close();
                          }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
                ErrorSignal.FromCurrentContext().Raise(ex);
            }
        }
        public void SaveDetails()
        {
            try
            {
                dt = new DataTable();

                //============Generate Doc Number=============
                query = "SELECT ISNULL(MAX(CAST(RIGHT([Document_No],6) AS INT)),0)+1 as [Document_No] FROM [ax].[ACXCOLLECTIONENTRY] where [SiteCode]='" + Session["SiteCode"].ToString() + "' and [DATAAREAID]='" + Session["DATAAREAID"].ToString() + "'";
                dt    = baseObj.GetData(query);
                int vc = Convert.ToInt32(dt.Rows[0]["Document_No"].ToString());

                //string DocumentNo = obj.GetNumSequence(8, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString());

                DataTable dtNumSeq   = obj.GetNumSequenceNew(8, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString()); //st.Substring(st.Length - 6) + System.DateTime.Now.ToString("yyMMddhhmmss");
                string    NUMSEQ     = string.Empty;
                string    DocumentNo = string.Empty;
                if (dtNumSeq != null)
                {
                    DocumentNo = dtNumSeq.Rows[0][0].ToString();
                    NUMSEQ     = dtNumSeq.Rows[0][1].ToString();
                }
                else
                {
                    return;
                }
                conn               = baseObj.GetConnection();
                cmd                = new SqlCommand("ACX_CollectionEntry");
                transaction        = conn.BeginTransaction();
                cmd.Connection     = conn;
                cmd.Transaction    = transaction;
                cmd.CommandTimeout = 0;
                cmd.CommandType    = CommandType.StoredProcedure;

                cmd1                = new SqlCommand("ACX_CollectionEntry");
                cmd1.Connection     = conn;
                cmd1.Transaction    = transaction;
                cmd1.CommandTimeout = 0;
                cmd1.CommandType    = CommandType.StoredProcedure;


                //======Save CollectionEntry===================
                //cmd.CommandText = string.Empty;
                //cmd.CommandType = CommandType.StoredProcedure;
                //cmd = new SqlCommand("ACX_CollectionEntry");


                int i = 0;
                foreach (GridViewRow gv in gvDetails.Rows)
                {
                    i = i + 1;

                    HiddenField  Customercode     = (HiddenField)gv.Cells[0].FindControl("HiddenField2");
                    DropDownList InstrumentCode   = (DropDownList)gv.Cells[3].FindControl("drpInstrument");
                    TextBox      InstrumentNo     = (TextBox)gv.Cells[4].FindControl("txtInstrument");
                    DropDownList RefDocument_No   = (DropDownList)gv.Cells[5].FindControl("drpRefDocument");
                    Label        RefDocument_Date = (Label)gv.Cells[6].FindControl("lblRefDocDate");
                    Label        PendingAmount    = (Label)gv.Cells[7].FindControl("lblPendingAmount");
                    TextBox      Amount           = (TextBox)gv.Cells[8].FindControl("txtAmount");
                    //TextBox Remark = (TextBox)gv.Cells[9].FindControl("txtRemark");
                    TextBox Remark = gv.FindControl("txtRemark") as TextBox;

                    decimal amount, pendingamount;
                    if (Amount.Text == string.Empty)
                    {
                        amount = 0;
                    }
                    else
                    {
                        amount = Convert.ToDecimal(Amount.Text);
                    }
                    if (PendingAmount.Text == string.Empty)
                    {
                        pendingamount = 0;
                    }
                    else
                    {
                        pendingamount = Convert.ToDecimal(PendingAmount.Text);
                    }


                    if (amount != 0)
                    {
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@SiteCode", Session["SiteCode"].ToString());
                        cmd.Parameters.AddWithValue("@DATAAREAID", Session["DATAAREAID"].ToString());
                        cmd.Parameters.AddWithValue("@Customer_Code", Customercode.Value);
                        cmd.Parameters.AddWithValue("@Document_No", DocumentNo);
                        cmd.Parameters.AddWithValue("@Instrument_Code", InstrumentCode.SelectedItem.Value);
                        cmd.Parameters.AddWithValue("@Instrument_No", InstrumentNo.Text);
                        cmd.Parameters.AddWithValue("@Ref_DocumentNo", RefDocument_No.SelectedItem.Text);
                        cmd.Parameters.AddWithValue("@Ref_DocumentDate", RefDocument_Date.Text);
                        cmd.Parameters.AddWithValue("@Collection_Amount", amount);
                        cmd.Parameters.AddWithValue("@Collection_Date", txtCollectionDate.Text);
                        cmd.Parameters.AddWithValue("@Status", "INSERT");
                        cmd.Parameters.AddWithValue("@NUMSEQ", NUMSEQ);
                        cmd.Parameters.AddWithValue("@Remark", Remark.Text.Trim());

                        cmd.ExecuteNonQuery();

                        //===============Update Customer Ledger/Transaction Table===============
                        cmd1.Parameters.Clear();
                        cmd1.Parameters.AddWithValue("@SiteCode", Session["SiteCode"].ToString());
                        cmd1.Parameters.AddWithValue("@DATAAREAID", Session["DATAAREAID"].ToString());
                        cmd1.Parameters.AddWithValue("@Customer_Code", Customercode.Value);
                        cmd1.Parameters.AddWithValue("@Document_No", RefDocument_No.SelectedItem.Text);
                        cmd1.Parameters.AddWithValue("@RemainingAmount", pendingamount - amount);
                        cmd1.Parameters.AddWithValue("@Status", "UPDATE");
                        cmd1.Parameters.AddWithValue("@Remark", Remark.Text.Trim());

                        cmd1.ExecuteNonQuery();

                        //obj.UpdateLastNumSequence(8, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString(), conn, transaction);

                        //============Commit All Data================
                    }

                    else
                    {
                    }
                }
                transaction.Commit();
                this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Collection Entry Document No : " + DocumentNo + " Generated Successfully.!');", true);
                BindGridview();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                //this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Please Try Again!!');", true);
                LblMessage.Text    = "'Please Try Again!! !";
                LblMessage.Visible = true;
                uppanel.Update();

                ErrorSignal.FromCurrentContext().Raise(ex);
            }
            finally
            {
                conn.Close();
            }
        }
Exemplo n.º 4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (gvDetails.Rows.Count > 0)
                {
                    Button      btn = sender as Button;
                    GridViewRow row = btn.NamingContainer as GridViewRow;
                    // string pk = gvDetails.DataKeys[row.RowIndex].Values[0].ToString();
                    // string strInvoiceNo = string.Empty;

                    foreach (GridViewRow gv in gvDetails.Rows)
                    {
                        DataTable dt = new DataTable();
                        //============Generate Doc Number=============
                        query = "SELECT ISNULL(MAX(CAST(RIGHT([Document_No],6) AS INT)),0)+1 as [Document_No] FROM [ax].[ACXCOLLECTIONENTRY] where [SiteCode]='" + Session["SiteCode"].ToString() + "' and [DATAAREAID]='" + Session["DATAAREAID"].ToString() + "'";
                        dt    = baseObj.GetData(query);
                        int       vc         = Convert.ToInt32(dt.Rows[0]["Document_No"].ToString());
                        DataTable dtNumSeq   = baseObj.GetNumSequenceNew(8, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString()); //st.Substring(st.Length - 6) + System.DateTime.Now.ToString("yyMMddhhmmss");
                        string    NUMSEQ     = string.Empty;
                        string    DocumentNo = string.Empty;
                        if (dtNumSeq != null)
                        {
                            DocumentNo = dtNumSeq.Rows[0][0].ToString();
                            NUMSEQ     = dtNumSeq.Rows[0][1].ToString();
                        }
                        else
                        {
                            return;
                        }
                        conn                = baseObj.GetConnection();
                        cmd                 = new SqlCommand("ACX_CollectionEntry");
                        transaction         = conn.BeginTransaction();
                        cmd.Connection      = conn;
                        cmd.Transaction     = transaction;
                        cmd.CommandTimeout  = 3600;
                        cmd.CommandType     = CommandType.StoredProcedure;
                        cmd1                = new SqlCommand("ACX_CollectionEntry");
                        cmd1.Connection     = conn;
                        cmd1.Transaction    = transaction;
                        cmd1.CommandTimeout = 3600;
                        cmd1.CommandType    = CommandType.StoredProcedure;
                        decimal     amount        = 0;
                        CheckBox    chkbox        = (CheckBox)gv.FindControl("chkInvoice");
                        HiddenField strInvoice_No = (HiddenField)gv.FindControl("hdInvoice_No");
                        if (chkbox.Checked == true)
                        {
                            try
                            {
                                Label lblRemainingAmount = (Label)gv.FindControl("lblRemainingAmount");
                                Label lblCUSTOMER_CODE   = (Label)gv.FindControl("lblCUSTOMER_CODE");
                                Label lblDocument_Date   = (Label)gv.FindControl("lblDocument_Date");
                                amount = Convert.ToDecimal(lblRemainingAmount.Text.Trim());
                                if (amount > 0)
                                {
                                    cmd.Parameters.Clear();
                                    cmd.Parameters.AddWithValue("@SiteCode", Session["SiteCode"].ToString());
                                    cmd.Parameters.AddWithValue("@DATAAREAID", Session["DATAAREAID"].ToString());
                                    cmd.Parameters.AddWithValue("@Customer_Code", lblCUSTOMER_CODE.Text.Trim());
                                    cmd.Parameters.AddWithValue("@Document_No", DocumentNo);
                                    cmd.Parameters.AddWithValue("@Instrument_Code", "CASH");
                                    cmd.Parameters.AddWithValue("@Instrument_No", "");
                                    cmd.Parameters.AddWithValue("@Ref_DocumentNo", strInvoice_No.Value);
                                    cmd.Parameters.AddWithValue("@Ref_DocumentDate", Convert.ToDateTime(lblDocument_Date.Text));
                                    cmd.Parameters.AddWithValue("@Collection_Amount", amount);
                                    cmd.Parameters.AddWithValue("@Collection_Date", DateTime.Now);
                                    cmd.Parameters.AddWithValue("@Status", "INSERT");
                                    cmd.Parameters.AddWithValue("@NUMSEQ", NUMSEQ);
                                    cmd.Parameters.AddWithValue("@Remark", "WRITE OFF");

                                    cmd.ExecuteNonQuery();

                                    //===============Update Customer Ledger/Transaction Table===============
                                    cmd1.Parameters.Clear();
                                    cmd1.Parameters.AddWithValue("@SiteCode", Session["SiteCode"].ToString());
                                    cmd1.Parameters.AddWithValue("@DATAAREAID", Session["DATAAREAID"].ToString());
                                    cmd1.Parameters.AddWithValue("@Customer_Code", lblCUSTOMER_CODE.Text.Trim());
                                    cmd1.Parameters.AddWithValue("@Document_No", strInvoice_No.Value);
                                    cmd1.Parameters.AddWithValue("@RemainingAmount", 0);
                                    cmd1.Parameters.AddWithValue("@Status", "UPDATE");
                                    cmd1.Parameters.AddWithValue("@Remark", "WRITE OFF");

                                    cmd1.ExecuteNonQuery();

                                    //obj.UpdateLastNumSequence(8, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString(), conn, transaction);

                                    //============Commit All Data================
                                    transaction.Commit();
                                }
                                else
                                {
                                }
                                //
                            }
                            catch (Exception ex)
                            {
                                transaction.Rollback();
                                //this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Please Try Again!!');", true);
                                LblMessage.Text    = "'Please Try Again!! !";
                                LblMessage.Visible = true;
                                uppanel.Update();
                                ErrorSignal.FromCurrentContext().Raise(ex);
                            }
                            finally
                            {
                                conn.Close();
                            }
                        }
                    }
                    BtnShowReport0_Click(null, null);
                    this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Generated Successfully.!');", true);
                }
            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
            }
        }
        private void SaveData()
        {
            try
            {
                LblMessage.Text = "";
                bool b = Validation();
                if (b == true)
                {
                    conn = obj.GetConnection();
                    string strCode = string.Empty;
                    cmd                = new SqlCommand();
                    transaction        = conn.BeginTransaction();
                    cmd.Connection     = conn;
                    cmd.Transaction    = transaction;
                    cmd.CommandTimeout = 3600;


                    DataTable dtNumSeq = obj.GetNumSequenceNew(3, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString());  //st.Substring(st.Length - 6) + System.DateTime.Now.ToString("yyMMddhhmmss");
                    string    NUMSEQ   = string.Empty;
                    if (dtNumSeq != null)
                    {
                        strCode = dtNumSeq.Rows[0][0].ToString();
                        NUMSEQ  = dtNumSeq.Rows[0][1].ToString();
                    }
                    else
                    {
                        return;
                    }
                    cmd.CommandText = string.Empty;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "ACX_ACXPURCHINVREVERSAL";


                    #region Header Insert Data

                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("@SITE_CODE", Session["SiteCode"].ToString());
                    cmd.Parameters.AddWithValue("@PURCH_RETURNNO", strCode);
                    cmd.Parameters.AddWithValue("@PURCH_RECIEPTNO", drpRecieptNo.Text.Trim().ToString());
                    cmd.Parameters.AddWithValue("@TRANSPORTER_CODE", txtDriverNumber.Text);
                    cmd.Parameters.AddWithValue("@VEHICAL_NO", txtVehicleNumber.Text);
                    cmd.Parameters.AddWithValue("@VEHICAL_TYPE", txtVehicleType.Text);
                    cmd.Parameters.AddWithValue("@RETURN_REASONCODE", drpReturnReason.SelectedValue.ToString());
                    cmd.Parameters.AddWithValue("@REMARK", txtRemark.Text.Trim().ToString());
                    cmd.Parameters.AddWithValue("@DATAAREAID", Session["DATAAREAID"].ToString());
                    cmd.Parameters.AddWithValue("@NUMSEQ", NUMSEQ);
                    DataTable dtgrid = new DataTable();
                    if (Session[SessionGrid] != null)
                    {
                        dtgrid = (DataTable)Session[SessionGrid];
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "Validation", "alert('Session expired! Reselect the receipt no.');", true);
                        LblMessage.Text = "Session expired! Reselect the receipt no.";
                        return;
                    }
                    #endregion
                    DataSet   ds         = new DataSet();
                    DataTable dtLineItem = new DataTable();
                    dtLineItem           = dtgrid.Copy();
                    dtLineItem.TableName = "PurchReturn";
                    ds.Tables.Add(dtLineItem);
                    string ReversalLineXml = ds.GetXml();

                    cmd.Parameters.AddWithValue("@XmlData", ReversalLineXml);
                    cmd.ExecuteNonQuery();
                    //using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                    //{
                    //    using (DataTable dtt = new DataTable())
                    //    {
                    //        sda.Fill(dtt);
                    //    }
                    //}
                    //SaveManualPurchaseReturnToInventTransTable(strCode, transaction, conn);
                    transaction.Commit();


                    LblMessage.Text = "Purchase Return Order : " + strCode.ToString() + " Generated Successfully.!";
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", " alert('Purchase Return Order : " + strCode.ToString() + " Generated Successfully.!');", true);
                    ClearAll();
                    //LblMessage.Text = "Inventory Affected Successfully.!";
                    //this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Inventory Affected Successfully.!');", true);
                }
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                string message = "alert('Error:" + ex.Message.Replace("'", "") + " !');";
                ScriptManager.RegisterStartupScript(this, typeof(Page), "Error", message, true);
                LblMessage.Text = message;
                ErrorSignal.FromCurrentContext().Raise(ex);
            }
        }
Exemplo n.º 6
0
        private void Addloadsheetheader()
        {
            string productcode1;
            int    recid;

            CreamBell_DMS_WebApps.App_Code.Global obj = new CreamBell_DMS_WebApps.App_Code.Global();
            conn = obj.GetConnection();

            adp1 = new SqlDataAdapter("SELECT Top (1) recid FROM ax.ACXLOADSHEETHEADER order by recid desc ", conn);
            ds2.Clear();
            adp1.Fill(ds2, "dtl");

            if (ds2.Tables["dtl"].Rows.Count != 0)
            {
                productcode1 = string.Copy(ds2.Tables["dtl"].Rows[0][0].ToString());
                recid        = Convert.ToInt32((productcode1).ToString()) + 1;
            }
            else
            {
                recid = 1;
            }
            SqlTransaction transaction;

            transaction = conn.BeginTransaction();

            int k = 0;

            try
            {
                SqlCommand     comm   = new SqlCommand();
                SqlCommand     comm1  = new SqlCommand();
                SqlCommand     comm2  = new SqlCommand();
                SqlDataAdapter sqladp = new SqlDataAdapter();
                DataTable      dt     = new DataTable();
                string         sono   = "";

                //string strLoadSheetNo = obj.GetNumSequence(5, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString());

                DataTable dtNumSeq       = obj.GetNumSequenceNew(5, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString()); //st.Substring(st.Length - 6) + System.DateTime.Now.ToString("yyMMddhhmmss");
                string    strLoadSheetNo = string.Empty;
                string    NUMSEQ         = string.Empty;
                if (dtNumSeq != null)
                {
                    strLoadSheetNo = dtNumSeq.Rows[0][0].ToString();
                    NUMSEQ         = dtNumSeq.Rows[0][1].ToString();
                }
                else
                {
                    return;
                }

                bool   flag  = false;
                string lodNO = string.Empty;
                for (int i = 0; i < gvDetails.Rows.Count; i++)
                {
                    if (((CheckBox)gvDetails.Rows[i].FindControl("chkStatus")).Checked)
                    {
                        sono = ((CheckBox)gvDetails.Rows[i].FindControl("chkStatus")).Text;

                        string sodate        = gvDetails.Rows[i].Cells[1].Text;
                        string customergroup = gvDetails.Rows[i].Cells[2].Text;
                        string customercode  = gvDetails.Rows[i].Cells[3].Text;
                        string psrname       = gvDetails.Rows[i].Cells[6].Text;
                        string beatname      = gvDetails.Rows[i].Cells[8].Text;
                        string deliverydate  = gvDetails.Rows[i].Cells[10].Text;
                        string value         = gvDetails.Rows[i].Cells[11].Text;


                        string sitecode1, DataAreaId;

                        sitecode1  = Session["SiteCode"].ToString();
                        DataAreaId = Session["DATAAREAID"].ToString();
                        decimal value1;

                        value1 = Convert.ToDecimal(value);

                        comm = new SqlCommand("ax.ACX_ACXLOADSHEETHEADER", conn, transaction);

                        comm.CommandType    = CommandType.StoredProcedure;
                        comm.CommandTimeout = 0;
                        comm.Parameters.AddWithValue("@SITEID", sitecode1);
                        comm.Parameters.AddWithValue("@DATAAREAID", DataAreaId);
                        comm.Parameters.AddWithValue("@RECID", i + recid);
                        comm.Parameters.AddWithValue("@CUSTOMER_CODE", customercode);
                        comm.Parameters.AddWithValue("@LOADSHEET_NO", strLoadSheetNo);
                        lodNO = strLoadSheetNo;

                        comm.Parameters.AddWithValue("@SO_NO", sono);
                        comm.Parameters.AddWithValue("@SO_DATE", sodate);
                        comm.Parameters.AddWithValue("@PSR_CODE", psrname);
                        comm.Parameters.AddWithValue("@PSR_BEAT", beatname);
                        comm.Parameters.AddWithValue("@INVOICE_DATE", deliverydate);
                        comm.Parameters.AddWithValue("@DELIVERY_DATE", deliverydate);
                        comm.Parameters.AddWithValue("@VALUE", value1);
                        comm.Parameters.AddWithValue("@RATE", value1);
                        comm.Parameters.AddWithValue("@NUMSEQ", NUMSEQ);

                        int a1 = comm.ExecuteNonQuery();

                        string box = ""; decimal box2;

                        for (int j = 0; j < GridView2.Rows.Count; j++)
                        {
                            string productgroup = GridView2.Rows[j].Cells[0].Text;
                            string productcode  = GridView2.Rows[j].Cells[1].Text;
                            string crate        = GridView2.Rows[j].Cells[3].Text;

                            TextBox txtBox    = ((TextBox)GridView2.Rows[j].FindControl("txtqty"));    //with conv
                            TextBox txtPcs    = ((TextBox)GridView2.Rows[j].FindControl("txtPCS"));    //pcs
                            TextBox txtBoxQty = ((TextBox)GridView2.Rows[j].FindControl("txtBox"));    //box qty
                            TextBox txtBoxPcs = ((TextBox)GridView2.Rows[j].FindControl("txtBoxPcs")); // boxpcs

                            box = txtBox.Text;
                            string Ltr      = GridView2.Rows[j].Cells[8].Text;
                            string stockBox = GridView2.Rows[j].Cells[9].Text;
                            string StockLtr = GridView2.Rows[j].Cells[10].Text;

                            string sitecode2, DataAreaId2, uom;
                            uom         = "";
                            sitecode2   = Session["SiteCode"].ToString();
                            DataAreaId2 = Session["DATAAREAID"].ToString();

                            decimal crate1, ltr1, stockBox1, StockLtr1;

                            stockBox1 = Convert.ToDecimal(stockBox);
                            StockLtr1 = Convert.ToDecimal(StockLtr);
                            crate1    = Convert.ToDecimal(crate);
                            box2      = Convert.ToDecimal(box);
                            ltr1      = Convert.ToDecimal(Ltr);

                            if (Convert.ToDecimal(txtBox.Text) <= Convert.ToDecimal(stockBox) && Convert.ToDecimal(txtBox.Text) > 0)
                            {
                                comm1 = new SqlCommand("ax.ACX_ACXLOADSHEETLINE", conn, transaction);

                                comm1.CommandType    = CommandType.StoredProcedure;
                                comm1.CommandTimeout = 0;
                                comm1.Parameters.AddWithValue("@SHITEID", sitecode2);
                                comm1.Parameters.AddWithValue("@DATAAREAID", DataAreaId2);
                                comm1.Parameters.AddWithValue("@RECID", j + 1 + recid);
                                comm1.Parameters.AddWithValue("@CUSTOMER_CODE", customercode);
                                comm1.Parameters.AddWithValue("@LOADSHEET_NO", strLoadSheetNo);
                                comm1.Parameters.AddWithValue("@LINE_NO", j + 1);
                                comm1.Parameters.AddWithValue("@UOM", uom);
                                comm1.Parameters.AddWithValue("@STOCKQTY_BOX", stockBox1);
                                comm1.Parameters.AddWithValue("@STOCKQTY_LTR", StockLtr1);
                                comm1.Parameters.AddWithValue("@BOX", box2);
                                comm1.Parameters.AddWithValue("@CRATES", crate1);
                                comm1.Parameters.AddWithValue("@LINENUM", j + 1);
                                comm1.Parameters.AddWithValue("@LTR", ltr1);
                                comm1.Parameters.AddWithValue("@PRODUCT_CODE", productcode);
                                comm1.Parameters.AddWithValue("@BOXQty", Convert.ToDecimal(txtBoxQty.Text.Trim()));
                                comm1.Parameters.AddWithValue("@PcsQty", Convert.ToDecimal(txtPcs.Text.Trim()));
                                comm1.Parameters.AddWithValue("@BOXPcs", txtBoxPcs.Text.Trim());

                                int a = comm1.ExecuteNonQuery();
                            }
                        }

                        for (k = 0; k < gvDetails.Rows.Count; k++)
                        {
                            if (((CheckBox)gvDetails.Rows[k].FindControl("chkStatus")).Checked)
                            {
                                sono = ((CheckBox)gvDetails.Rows[k].FindControl("chkStatus")).Text;

                                sitecode1  = Session["SiteCode"].ToString();
                                DataAreaId = Session["DATAAREAID"].ToString();

                                comm2 = new SqlCommand("ax.ACX_ACXLOADSHEETHEADERUPDATE_LOADNO", conn, transaction);

                                comm2.CommandType = CommandType.StoredProcedure;

                                comm2.Parameters.AddWithValue("@LOADSHEET_NO", strLoadSheetNo);
                                comm2.Parameters.AddWithValue("@SO_NO", sono);
                                comm2.Parameters.AddWithValue("@SiteCode", sitecode1);
                                comm2.Parameters.AddWithValue("@DATAAREAID", DataAreaId);

                                int a2 = comm2.ExecuteNonQuery();
                            }
                        }

                        //obj.UpdateLastNumSequence(5, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString(), conn, transaction);

                        transaction.Commit();

                        flag = true;
                        break;
                    }
                }
                if (flag == true)
                {
                    this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Load Sheet N0:" + lodNO + " generated Suucessfull!');", true);
                    Session["LSNO"] = lodNO;
                }
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                conn.Close();
                ErrorSignal.FromCurrentContext().Raise(ex);
            }
        }
Exemplo n.º 7
0
        protected void btnsave_Click(object sender, EventArgs e)
        {
            try
            {
                if (drptargetType.SelectedValue.ToString() == "3")
                {
                    SavePSRStipend();
                }
                else
                {
                    DataTable dtExpense = new DataTable();
                    if (Session["DistributorExpense"] == null)
                    {
                        dtExpense = GetData(Convert.ToDateTime(txtFromDate.Text));
                    }
                    else
                    {
                        dtExpense = (DataTable)Session["DistributorExpense"];
                    }
                    SqlConnection  con  = baseObj.GetConnection();
                    SqlTransaction tran = null;
                    SqlCommand     cmd  = new SqlCommand();
                    SqlCommand     cmd1 = new SqlCommand();
                    try
                    {
                        DataTable dt     = baseObj.GetNumSequenceNew(11, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString()); //st.Substring(st.Length - 6) + System.DateTime.Now.ToString("yyMMddhhmmss");
                        string    Doc_NO = string.Empty;
                        string    NUMSEQ = string.Empty;
                        if (dt != null)
                        {
                            Doc_NO = dt.Rows[0][0].ToString();
                            NUMSEQ = dt.Rows[0][1].ToString();
                        }
                        else
                        {
                            return;
                        }

                        //Generate Document Number Seq for VRS Claim Setup
                        dt = baseObj.GetNumSequenceNew(17, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString());  //st.Substring(st.Length - 6) + System.DateTime.Now.ToString("yyMMddhhmmss");
                        string Doc_NO_Claim = string.Empty;
                        string NUMSEQ_Claim = string.Empty;
                        if (dt != null)
                        {
                            Doc_NO_Claim = dt.Rows[0][0].ToString();
                            NUMSEQ_Claim = dt.Rows[0][1].ToString();
                        }



                        if (con.State.ToString() == "Closed")
                        {
                            con.Open();
                        }
                        tran            = con.BeginTransaction();
                        cmd.Transaction = tran;

                        Boolean FoundAlready, FoundSuccess;
                        FoundAlready = false;
                        FoundSuccess = false;
                        if (!dtExpense.Columns.Contains("STATUS"))
                        {
                            dtExpense.Columns.Add("STATUS", typeof(string));
                        }
                        //foreach (GridViewRow grv in grvDetail.Rows)
                        for (int i = 0; i < dtExpense.Rows.Count; i++)
                        {
                            string OBJECT_CODE = dtExpense.Rows[i]["DISTRIBUTOR CODE"].ToString();
                            string OBJECT_SUBCODE = "";
                            string FROM_DATE = "", TO_DATE = "";
                            string TARGET              = "0";
                            string ACHIVEMENT          = "0";
                            string TARGET_INCENTIVE    = "";
                            string ACTUAL_INCENTIVE    = dtExpense.Rows[i]["EXPENSE AMOUNT"].ToString();
                            string CLAIM_CATEGORY      = dtExpense.Rows[i]["CATEGORY"].ToString();
                            string CLAIM_SUBCATEGORY   = dtExpense.Rows[i]["EXPENSECODE"].ToString();
                            string STATUS              = "0";
                            string MODIFIEDDATETIME    = string.Empty;
                            string CREATEDDATETIME     = string.Empty;
                            string TARGET_GROUP        = "";
                            string CALCULATION_PATTERN = "";
                            string CLAIM_MONTH         = "";
                            string BUCODE              = "";

                            //string VALUE_PER = "0";// dtExpense.Rows[i]["AMOUNT%"].ToString(); ;
                            //string FIXED_AMT = "0"; //dtExpense.Rows[i]["FIXED AMT"].ToString(); ;
                            //string FIXED_PER_DAY = "0"; //dtExpense.Rows[i]["FIXED PER DAY"].ToString(); ;
                            string PRESENT_DAYS  = "0"; //dtExpense.Rows[i]["PRESENT DAYS"].ToString(); ;
                            string VDCLAIM_TYPE  = "1";
                            string VALUE_PER     = "0"; // dtExpense.Rows[i]["AMOUNT%"].ToString(); ;
                            string FIXED_AMT     = "0"; // dtExpense.Rows[i]["FIXED AMT"].ToString(); ;
                            string FIXED_PER_DAY = "0"; // dtExpense.Rows[i]["FIXED PER DAY"].ToString();

                            CLAIM_MONTH = FROM_DATE = Convert.ToDateTime("01 " + txtFromDate.Text).ToString("yyyy-MM-dd");
                            TO_DATE     = Convert.ToDateTime(FROM_DATE).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");

                            if (drptargetType.SelectedValue.ToString() == "1")
                            {
                                TARGET_INCENTIVE    = dtExpense.Rows[i]["CALCULATE ON"].ToString();
                                CALCULATION_PATTERN = dtExpense.Rows[i]["EXPENSE ON"].ToString();
                                BUCODE = dtExpense.Rows[i]["BUCODE"].ToString();
                            }
                            if (drptargetType.SelectedValue.ToString() == "2")
                            {
                                OBJECT_SUBCODE      = dtExpense.Rows[i]["CUSTGROUP"].ToString();
                                FROM_DATE           = Convert.ToDateTime(dtExpense.Rows[i]["FROMDATE"]).ToString("yyyy-MM-dd");
                                TO_DATE             = Convert.ToDateTime(dtExpense.Rows[i]["TODATE"]).ToString("yyyy-MM-dd");
                                TARGET              = dtExpense.Rows[i]["TARGET"].ToString();
                                ACHIVEMENT          = dtExpense.Rows[i]["ACHIVEMENT"].ToString();
                                CLAIM_MONTH         = Convert.ToDateTime(txtFromDate.Text).ToString("yyyy-MM-01");
                                TARGET_INCENTIVE    = dtExpense.Rows[i]["INCENTIVE VALUE"].ToString();
                                CALCULATION_PATTERN = dtExpense.Rows[i]["CALCULATION ON"].ToString().ToUpper() == "FIX" ? "0" : "1";
                                TARGET_GROUP        = dtExpense.Rows[i]["INCENTIVE ON"].ToString().ToUpper() == "VALUE" ? "0" : "1";
                                BUCODE              = dtExpense.Rows[i]["BUCODE"].ToString();
                            }
                            if (drptargetType.SelectedValue.ToString() == "4")
                            {
                                OBJECT_CODE         = dtExpense.Rows[i]["VRS CODE"].ToString();
                                OBJECT_SUBCODE      = dtExpense.Rows[i]["VENDORCODE"].ToString();
                                ACHIVEMENT          = dtExpense.Rows[i]["ACHIVEMENT"].ToString();
                                TARGET_INCENTIVE    = dtExpense.Rows[i]["INCENTIVE VALUE"].ToString();
                                CALCULATION_PATTERN = dtExpense.Rows[i]["CALCULATION ON"].ToString().ToUpper() == "FIX" ? "0" : "1";
                                TARGET_GROUP        = dtExpense.Rows[i]["INCENTIVE ON"].ToString().ToUpper() == "VALUE" ? "0" : "1";
                                BUCODE = dtExpense.Rows[i]["BUCODE"].ToString();
                            }
                            if (drptargetType.SelectedValue.ToString() == "5")
                            {
                                OBJECT_CODE         = dtExpense.Rows[i]["VRS CODE"].ToString();
                                OBJECT_SUBCODE      = dtExpense.Rows[i]["VENDORCODE"].ToString();
                                FROM_DATE           = Convert.ToDateTime(dtExpense.Rows[i]["FROMDATE"]).ToString("yyyy-MM-dd");
                                TO_DATE             = Convert.ToDateTime(dtExpense.Rows[i]["TODATE"]).ToString("yyyy-MM-dd");
                                TARGET              = dtExpense.Rows[i]["TARGET"].ToString();
                                ACHIVEMENT          = dtExpense.Rows[i]["ACHIVEMENT"].ToString();
                                TARGET_INCENTIVE    = dtExpense.Rows[i]["FIXVALUE"].ToString();
                                CALCULATION_PATTERN = dtExpense.Rows[i]["CALCULATION ON"].ToString().ToUpper() == "FIX" ? "0" : "1";
                                TARGET_GROUP        = dtExpense.Rows[i]["INCENTIVE ON"].ToString().ToUpper() == "VALUE" ? "0" : "1";
                                BUCODE              = dtExpense.Rows[i]["BUCODE"].ToString();
                            }
                            if (drptargetType.SelectedValue.ToString() == "6")
                            {
                                OBJECT_CODE      = dtExpense.Rows[i]["VRS CODE"].ToString();
                                OBJECT_SUBCODE   = dtExpense.Rows[i]["VENDORCODE"].ToString();
                                ACHIVEMENT       = dtExpense.Rows[i]["ACHIVEMENT"].ToString();
                                TARGET_INCENTIVE = dtExpense.Rows[i]["FIXED AMT"].ToString();
                                BUCODE           = dtExpense.Rows[i]["BUCODE"].ToString();
                            }
                            if (drptargetType.SelectedValue.ToString() == "7")
                            {
                                OBJECT_CODE    = dtExpense.Rows[i]["VRS CODE"].ToString();
                                OBJECT_SUBCODE = dtExpense.Rows[i]["VENDORCODE"].ToString();
                                FROM_DATE      = Convert.ToDateTime(dtExpense.Rows[i]["FROMDATE"]).ToString("yyyy-MM-dd");
                                TO_DATE        = Convert.ToDateTime(dtExpense.Rows[i]["TODATE"]).ToString("yyyy-MM-dd");
                                //TARGET = dtExpense.Rows[i]["TARGET"].ToString();
                                ACHIVEMENT          = dtExpense.Rows[i]["ACHIVEMENT"].ToString();
                                TARGET_INCENTIVE    = dtExpense.Rows[i]["FIXVALUE"].ToString();
                                CALCULATION_PATTERN = dtExpense.Rows[i]["CALCULATION ON"].ToString();
                                TARGET_GROUP        = dtExpense.Rows[i]["INCENTIVE ON"].ToString().ToUpper() == "VALUE" ? "0" : "1";
                                VDCLAIM_TYPE        = "2";
                                PRESENT_DAYS        = dtExpense.Rows[i]["PRESENT DAYS"].ToString();
                                BUCODE = dtExpense.Rows[i]["BUCODE"].ToString();
                            }
                            if (drptargetType.SelectedValue.ToString() == "8")
                            {
                                OBJECT_CODE         = dtExpense.Rows[i]["VRS CODE"].ToString();
                                OBJECT_SUBCODE      = dtExpense.Rows[i]["VENDORCODE"].ToString();
                                FROM_DATE           = Convert.ToDateTime(dtExpense.Rows[i]["FROMDATE"]).ToString("yyyy-MM-dd");
                                TO_DATE             = Convert.ToDateTime(dtExpense.Rows[i]["TODATE"]).ToString("yyyy-MM-dd");
                                TARGET              = dtExpense.Rows[i]["TARGET"].ToString();
                                ACHIVEMENT          = dtExpense.Rows[i]["ACHIVEMENT"].ToString();
                                TARGET_INCENTIVE    = dtExpense.Rows[i]["FIXVALUE"].ToString();
                                CALCULATION_PATTERN = dtExpense.Rows[i]["CALCULATION ON"].ToString().ToUpper() == "FIX" ? "0" : "1";
                                TARGET_GROUP        = dtExpense.Rows[i]["INCENTIVE ON"].ToString().ToUpper() == "VALUE" ? "0" : "1";
                                VDCLAIM_TYPE        = "3";
                                PRESENT_DAYS        = dtExpense.Rows[i]["PRESENT DAYS"].ToString();
                                BUCODE              = dtExpense.Rows[i]["BUCODE"].ToString();
                            }
                            if (drptargetType.SelectedValue.ToString() == "9")
                            {
                                OBJECT_CODE         = dtExpense.Rows[i]["VRS CODE"].ToString();
                                OBJECT_SUBCODE      = dtExpense.Rows[i]["VENDORCODE"].ToString();
                                FROM_DATE           = Convert.ToDateTime(dtExpense.Rows[i]["FROMDATE"]).ToString("yyyy-MM-dd");
                                TO_DATE             = Convert.ToDateTime(dtExpense.Rows[i]["TODATE"]).ToString("yyyy-MM-dd");
                                TARGET              = dtExpense.Rows[i]["TARGET"].ToString();
                                ACHIVEMENT          = dtExpense.Rows[i]["ACHIVEMENT"].ToString();
                                TARGET_INCENTIVE    = dtExpense.Rows[i]["FIXVALUE"].ToString();
                                CALCULATION_PATTERN = dtExpense.Rows[i]["CALCULATION ON"].ToString().ToUpper() == "FIX" ? "0" : "1";
                                TARGET_GROUP        = dtExpense.Rows[i]["INCENTIVE ON"].ToString().ToUpper() == "VALUE" ? "0" : "1";
                                VDCLAIM_TYPE        = "4";
                                BUCODE              = dtExpense.Rows[i]["BUCODE"].ToString();
                            }
                            if (drptargetType.SelectedValue.ToString() == "10")
                            {
                                OBJECT_CODE         = dtExpense.Rows[i]["VRS CODE"].ToString();
                                OBJECT_SUBCODE      = dtExpense.Rows[i]["VENDORCODE"].ToString();
                                FROM_DATE           = Convert.ToDateTime(dtExpense.Rows[i]["FROMDATE"]).ToString("yyyy-MM-dd");
                                TO_DATE             = Convert.ToDateTime(dtExpense.Rows[i]["TODATE"]).ToString("yyyy-MM-dd");
                                TARGET              = dtExpense.Rows[i]["TARGET"].ToString();
                                ACHIVEMENT          = dtExpense.Rows[i]["ACHIVEMENT"].ToString();
                                TARGET_INCENTIVE    = dtExpense.Rows[i]["VALUE%"].ToString();
                                CALCULATION_PATTERN = dtExpense.Rows[i]["CALCULATION ON"].ToString().ToUpper() == "FIX" ? "0" : "1";
                                TARGET_GROUP        = dtExpense.Rows[i]["INCENTIVE ON"].ToString().ToUpper() == "VALUE" ? "0" : "1";
                                BUCODE              = dtExpense.Rows[i]["BUCODE"].ToString();
                                VDCLAIM_TYPE        = "5";
                            }

                            VALUE_PER = dtExpense.Columns.Contains("AMOUNT%") == true?dtExpense.Rows[i]["AMOUNT%"].ToString():"0";
                            if (dtExpense.Columns.Contains("FIXED AMT"))
                            {
                                FIXED_AMT = dtExpense.Rows[i]["FIXED AMT"].ToString();
                            }
                            else if (dtExpense.Columns.Contains("FIXVALUE"))
                            {
                                FIXED_AMT = dtExpense.Rows[0]["FIXVALUE"].ToString();
                            }
                            else
                            {
                                FIXED_AMT = "0";
                            }
                            FIXED_PER_DAY = dtExpense.Columns.Contains("FIXED PER DAY") == true ? dtExpense.Rows[i]["FIXED PER DAY"].ToString() : "0";

                            string EXP_TYPE = dtExpense.Rows[i]["TARGET TYPE"].ToString();
                            if (EXP_TYPE == "SALE")
                            {
                                EXP_TYPE = "1";
                            }
                            else if (EXP_TYPE == "PURCHASE")
                            {
                                EXP_TYPE = "2";
                            }
                            else
                            {
                                EXP_TYPE = "0";
                            }

                            string sqlstr = @"SELECT * FROM [ax].[ACX_VRSCLAIMMASTER] where SITE_CODE='" + Session["SiteCode"].ToString() + "' and FROM_DATE='" + FROM_DATE + "' ";
                            sqlstr += "and TO_DATE='" + TO_DATE + "' and VRS_CODE='" + OBJECT_CODE + "' AND EXP_TYPE='" + EXP_TYPE + "' and VD_SUBCODE='" + OBJECT_SUBCODE + "'  ";
                            sqlstr += "and TARGET=" + TARGET + " and CLAIM_CATEGORY='" + CLAIM_CATEGORY + "' and CLAIM_SUBCATEGORY='" + CLAIM_SUBCATEGORY + "' and DATAAREAID='" + Session["DATAAREAID"] + "' and [INCENTIVE_ON]='" + TARGET_GROUP + "'";
                            dt      = baseObj.GetData(sqlstr);

                            if (dt.Rows.Count == 0)
                            {
                                if (Convert.ToDouble(ACTUAL_INCENTIVE) > 0)
                                {
                                    #region  SAVE ON VRS CLAIM TABLE

                                    //===================New===============
                                    if (OBJECT_CODE.Trim().Length > 0)
                                    {
                                        if (TARGET_GROUP == "VALUE" || TARGET_GROUP == "")
                                        {
                                            TARGET_GROUP = "0";
                                        }
                                        else if (TARGET_GROUP == "LTR")
                                        {
                                            TARGET_GROUP = "1";
                                        }

                                        if (CALCULATION_PATTERN == "FIX")
                                        {
                                            CALCULATION_PATTERN = "0";
                                        }
                                        else
                                        {
                                            CALCULATION_PATTERN = "1";
                                        }

                                        cmd1            = new SqlCommand("ACXINSERTCLAIMMASTER_MONTHLY");
                                        cmd1.Connection = con;
                                        cmd1.Parameters.Clear();
                                        cmd1.Transaction    = tran;
                                        cmd1.CommandTimeout = 3600;
                                        cmd1.CommandType    = CommandType.StoredProcedure;

                                        string sqlstr1 = @"SELECT * FROM ax.ACX_VRSClaimMaster where SITE_CODE='" + Session["SiteCode"].ToString() + "' and FROM_DATE='" + FROM_DATE + "' ";
                                        sqlstr1 += "and TO_DATE='" + TO_DATE + "' and VRS_CODE='" + OBJECT_CODE + "'  and VD_SUBCODE='" + OBJECT_SUBCODE + "' and CLAIM_CATEGORY='" + CLAIM_CATEGORY + "' and CLAIM_SUBCATEGORY='" + CLAIM_SUBCATEGORY + "' and DATAAREAID='" + Session["DATAAREAID"] + "' ";


                                        dt = baseObj.GetData(sqlstr1);
                                        if (dt.Rows.Count == 0)
                                        {
                                            if (Convert.ToDouble(ACTUAL_INCENTIVE) > 0)
                                            {
                                                cmd1.Parameters.Add("@DATAAREAID", SqlDbType.NVarChar).Value    = Session["DATAAREAID"];
                                                cmd1.Parameters.Add("@DOCUMENT_CODE", SqlDbType.NVarChar).Value = Doc_NO_Claim;
                                                cmd1.Parameters.Add("@SITE_CODE", SqlDbType.NVarChar).Value     = Session["SiteCode"].ToString();

                                                cmd1.Parameters.Add("@VRS_CODE", SqlDbType.NVarChar).Value   = OBJECT_CODE;
                                                cmd1.Parameters.Add("@VD_SUBCODE", SqlDbType.NVarChar).Value = OBJECT_SUBCODE;

                                                cmd1.Parameters.Add("@FROM_DATE", SqlDbType.DateTime).Value = FROM_DATE;
                                                cmd1.Parameters.Add("@TO_DATE", SqlDbType.DateTime).Value   = TO_DATE;

                                                cmd1.Parameters.Add("@EXP_TYPE", SqlDbType.Int).Value       = EXP_TYPE;
                                                cmd1.Parameters.Add("@INCENTIVE_ON", SqlDbType.Int).Value   = TARGET_GROUP;
                                                cmd1.Parameters.Add("@CALCULATION_ON", SqlDbType.Int).Value = CALCULATION_PATTERN;

                                                cmd1.Parameters.Add("@TARGET", SqlDbType.Decimal).Value     = TARGET;
                                                cmd1.Parameters.Add("@ACHIVEMENT", SqlDbType.Decimal).Value = ACHIVEMENT;

                                                cmd1.Parameters.Add("@VALUE_PER", SqlDbType.Decimal).Value     = VALUE_PER;
                                                cmd1.Parameters.Add("@FIXED_AMT", SqlDbType.Decimal).Value     = FIXED_AMT;
                                                cmd1.Parameters.Add("@FIXED_PER_DAY", SqlDbType.Decimal).Value = FIXED_PER_DAY;
                                                cmd1.Parameters.Add("@PRESENT_DAYS", SqlDbType.Int).Value      = PRESENT_DAYS;

                                                cmd1.Parameters.Add("@ACTUAL_INCENTIVE", SqlDbType.Decimal).Value   = ACTUAL_INCENTIVE;
                                                cmd1.Parameters.Add("@CLAIM_CATEGORY", SqlDbType.NVarChar).Value    = CLAIM_CATEGORY;
                                                cmd1.Parameters.Add("@CLAIM_SUBCATEGORY", SqlDbType.NVarChar).Value = CLAIM_SUBCATEGORY;
                                                cmd1.Parameters.Add("@CLAIM_TYPE", SqlDbType.NVarChar).Value        = VDCLAIM_TYPE;
                                                cmd1.Parameters.Add("@STATUS", SqlDbType.Int).Value                = STATUS;
                                                cmd1.Parameters.Add("@NumSeq", SqlDbType.BigInt).Value             = NUMSEQ_Claim;
                                                cmd1.Parameters.Add("@CLAIM_MONTH", SqlDbType.SmallDateTime).Value = CLAIM_MONTH;
                                                cmd1.Parameters.Add("@BUCODE", SqlDbType.NVarChar).Value           = BUCODE;

                                                cmd1.ExecuteNonQuery();
                                                DataRow[] dr = dtExpense.Select("[EXPENSECODE]='" + CLAIM_SUBCATEGORY + "'");
                                                if (dr.Length > 0)
                                                {
                                                    for (int j = 0; j < dr.Length; j++)
                                                    {
                                                        dr[j]["STATUS"] = "Success";
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            } //IF END
                            else
                            {
                                FoundAlready = true;
                                //if (drptargetType.SelectedValue.ToString() == "1")
                                //{
                                DataRow[] dr = dtExpense.Select("[EXPENSECODE]='" + CLAIM_SUBCATEGORY + "'");
                                if (dr.Length > 0)
                                {
                                    for (int j = 0; j < dr.Length; j++)
                                    {
                                        dr[j]["STATUS"] = "Already";
                                    }
                                }
                                //}
                            }
                        } //FOR END
                        tran.Commit();
                        if (FoundAlready == true && FoundSuccess == true)
                        {
                            ScriptManager.RegisterStartupScript(this, typeof(Page), "Information", "alert('Some data already saved. Except that saved successfully.');", true);
                            grvDetail.DataSource = dtExpense;
                            grvDetail.DataBind();
                            return;
                        }
                        else if (FoundAlready)
                        {
                            ScriptManager.RegisterStartupScript(this, typeof(Page), "Information", "alert('Data already saved.');", true);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, typeof(Page), "Information", "alert('Data saved successfully.');", true);
                        }
                        grvDetail.DataSource = null;
                        grvDetail.Visible    = false;
                        // grvDetail.Columns[22].Visible = true;
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        lblError.Text = ex.Message;
                        ErrorSignal.FromCurrentContext().Raise(ex);
                    }
                    finally { if (con.State.ToString() == "Open")
                              {
                                  con.Close();
                              }
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
                ErrorSignal.FromCurrentContext().Raise(ex);
            }
            finally { }
        }