private void FillPlantByOrderType()
        {
            CreamBell_DMS_WebApps.App_Code.Global obj = new Global();
            string    strQuery = string.Empty;
            DataTable dt       = new DataTable();

            if (Convert.ToString(Session["ISDISTRIBUTOR"]) == "Y")
            {
                strQuery = "SELECT P.USERCODE,O.PLANTCODE,(O.PLANTCODE+'-'+O.PLANTDESCRIPTION) AS PLANTDESCRIPTION FROM AX.ACX_ORDERPLANTMAPPING O "
                           + " LEFT JOIN AX.Acx_PACUserCreation P ON O.PLANTCODE=P.PLANTCODE "
                           // + " INNER JOIN AX.ACXUSERMASTER A ON A.USER_CODE=P.USERCODE"
                           //+ " WHERE A.User_Code='" + Session["USERID"].ToString() + "'";
                           + " Where O.ORDERTYPE='" + drpOrderType.SelectedItem.Value.ToString() + "'";
            }
            else
            {
                strQuery = "EXEC ACX_ORDERTYPE_PLANT '" + drpOrderType.SelectedItem.Value.ToString() + "'";
            }

            dt = obj.GetData(strQuery);
            DrpPlant.Items.Clear();
            DataTable dtunique = new DataTable();

            dtunique                = dt.DefaultView.ToTable(true, "PLANTDESCRIPTION", "PLANTCODE");
            DrpPlant.DataSource     = dtunique;
            DrpPlant.DataTextField  = "PLANTDESCRIPTION";
            DrpPlant.DataValueField = "PLANTCODE";
            DrpPlant.DataBind();
            DataRow[] dr = dt.Select("USERCODE = '" + Session["USERID"].ToString() + "'");
            if (dr.Length > 0)
            {
                DrpPlant.SelectedValue = dr[0]["PLANTCODE"].ToString();
            }

            //DrpPlant.Items.Clear();
            //DrpPlant.Items.Add("-Select-");
            // obj.BindToDropDown(DrpPlant, strQuery, "PLANTDESCRIPTION", "PLANTCODE");
            DrpPlant.Focus();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string  sitecode         = Session["SiteCode"].ToString();
            string  dataAreaId       = Session["DATAAREAID"].ToString();
            string  indent_No        = string.Empty;
            string  distributor_Code = string.Empty;
            string  salesOfficeCode  = string.Empty;
            int     line_No          = 1;
            string  product_Code     = string.Empty;
            decimal crateQty         = 0;
            decimal boxQty           = 0;
            decimal PcsQty           = 0;
            int     recid;
            bool    flag;
            int     retVal;
            string  strIndentNO        = string.Empty;
            string  strDistributorCode = string.Empty;
            string  message            = string.Empty;

            //Validate Inputs
            if (drpOrderType.SelectedItem.Value.ToString().Trim() == "-Select-" || drpOrderType.SelectedItem.Value.ToString().Trim().Length == 0)
            {
                message = " alert('Order Type is required!');";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", message, true);
                drpOrderType.Focus();
                return;
            }
            if (DrpPlant.SelectedItem.Value.ToString().Trim() == "-Select-" || DrpPlant.SelectedItem.Value.ToString().Trim().Length == 0)
            {
                message = " alert('Plant Code is required!');";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", message, true);
                DrpPlant.Focus();
                return;
            }
            //if (validateIndentConsolidation()) { return; }

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

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

            if (ds2.Tables["dtl"].Rows.Count != 0)
            {
                recid = Convert.ToInt16(ds2.Tables["dtl"].Rows[0][0].ToString()) + 1;
            }
            else
            {
                recid = 1;
            }

            SqlTransaction transaction;

            transaction = conn.BeginTransaction();

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

                DataTable dtNumSeq = obj.GetNumSequenceNew(16, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString());
                string    strIndentConsolidateNo = string.Empty;
                string    NUMSEQ = string.Empty;

                if (dtNumSeq != null)
                {
                    strIndentConsolidateNo = dtNumSeq.Rows[0][0].ToString();
                    NUMSEQ = dtNumSeq.Rows[0][1].ToString();
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", "alert('Number Sequence Not Defined for Indent Consolidation!');", true);
                    return;
                }

                foreach (GridViewRow row in gvDetails.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        CheckBox chkRow = (row.Cells[0].FindControl("chkStatus") as CheckBox);
                        if (chkRow.Checked)
                        {
                            strIndentNO        += chkRow.Text + ",";
                            strDistributorCode += row.Cells[2].Text + ",";
                        }
                    }
                }

                comm             = new SqlCommand("ax.ACX_IndentConsolidationInsertUsp", conn, transaction);
                comm.CommandType = CommandType.StoredProcedure;

                comm.Parameters.Clear();
                comm.Parameters.AddWithValue("@DATAAREAID", dataAreaId);
                comm.Parameters.AddWithValue("@RECID", recid);
                comm.Parameters.AddWithValue("@CONINDENT_NO", strIndentConsolidateNo);
                comm.Parameters.AddWithValue("@SITEID", sitecode);
                comm.Parameters.AddWithValue("@NUMSEQ", NUMSEQ);
                comm.Parameters.AddWithValue("@USERCODE", Session["USERID"].ToString());
                comm.Parameters.AddWithValue("@InventNOs", strIndentNO);
                comm.Parameters.AddWithValue("@DistributorCode", strDistributorCode);
                comm.Parameters.AddWithValue("@ORDERTYPECODE", drpOrderType.SelectedItem.Value.ToString());
                comm.Parameters.AddWithValue("@PLANTCODE", DrpPlant.SelectedItem.Value.ToString());

                retVal = comm.ExecuteNonQuery();

                transaction.Commit();
                flag = true;

                if (DrpDistributor.SelectedItem.Value.ToString() != "" && DrpDistributor.SelectedItem.Value.ToString() != "-Select-")
                {
                    FillIndentListFilter();
                }
                else
                {
                    FillIndentList();
                }

                GridView2.DataSource = null;
                GridView2.DataBind();
                Session["IndentNo"] = string.Empty;
                if (flag == true)
                {
                    this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Indent Consolidation N0:" + strIndentConsolidateNo + " generated Suucessfull!');", true);
                }
            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                transaction.Rollback();
                conn.Close();
            }
        }