protected void btn_sess_Click(object sender, EventArgs e)
 {
     try
     {
         //Check remmarks Update or Not
         con = DBaccess.GetConnection();
         string getperiodstr = "";
         getperiodstr = "select *  from( Select procagent,Agent_Name  from (sELECT Agent_id as procagent   FROM Procurementimport   where Plant_Code='" + plant_Code + "'  and Prdate='" + txt_FromDate.Text + "' and sessions='" + ddl_ses.SelectedItem.Text + "' GROUP BY Agent_id  ) as procimport  left  join(Select agent_id,Agent_Name   from Agent_Master  where Plant_code='" + plant_Code + "') as  am on procimport.procagent=am.Agent_Id ) as gg  where gg.procagent=Agent_Name";
         SqlCommand     cmdperiod = new SqlCommand(getperiodstr, con);
         SqlDataAdapter sall      = new SqlDataAdapter(cmdperiod);
         getmissagent.Rows.Clear();
         sall.Fill(getmissagent);
         if (getmissagent.Rows.Count > 0)
         {
             GridView2.DataSource = getmissagent;
             GridView2.DataBind();
             GridView2.Visible = true;
         }
         else
         {
             GridView2.Visible = false;
             int Rstatus = 0;
             Rstatus = Bllusers.Remarksstatussess(Company_code, plant_Code, txt_FromDate.Text, txt_FromDate.Text, ddl_ses.SelectedItem.Value);
             if (Rstatus >= 1)
             {
                 string remarksmsg = "Check the RemarksUpdate...";
                 uscMsgBox1.AddMessage(remarksmsg, MessageBoxUsc_Message.enmMessageType.Success);
             }
             else
             {
                 //Check the Data Already Transfer or Not
                 int DataTrasfer = 0;
                 DataTrasfer = Bllusers.DatatransferChecksess(Company_code, plant_Code, txt_FromDate.Text, txt_FromDate.Text, ddl_ses.SelectedItem.Value);
                 if (DataTrasfer >= 1)
                 {
                     string remarksmsg = "Already DataTransfer...";
                     uscMsgBox1.AddMessage(remarksmsg, MessageBoxUsc_Message.enmMessageType.Success);
                 }
                 else
                 {
                     try
                     {
                         using (con = DBaccess.GetConnection())
                         {
                             setBO();
                             SqlCommand cmdd = new SqlCommand("DELETE from   PROCUREMENT where plant_code='" + plant_Code + "' and  prdate between '" + txt_FromDate.Text + "' and '" + txt_FromDate.Text + "' and Sessions='" + ddl_ses.SelectedItem.Value + "' ", con);
                             cmdd.ExecuteNonQuery();
                             impdbBL.deleteimportsess(rateBO);
                             SqlCommand     cmd  = new SqlCommand();
                             SqlCommand     cmd1 = new SqlCommand();
                             DataTable      dtt  = new DataTable();
                             SqlDataAdapter daa;
                             daa = new SqlDataAdapter("SELECT * from PROCUREMENTIMPORT where plant_code='" + plant_Code + "' and  prdate between '" + txt_FromDate.Text + "' and '" + txt_FromDate.Text + "' and Sessions='" + ddl_ses.SelectedItem.Value + "' ", con);
                             daa.Fill(dtt);
                             int            count1 = dtt.Rows.Count;
                             DataTable      dt     = new DataTable();
                             SqlDataAdapter da;
                             da = new SqlDataAdapter("SELECT * from PROCUREMENT where plant_code='" + plant_Code + "' and  prdate between '" + txt_FromDate.Text + "' and '" + txt_FromDate.Text + "' and Sessions='" + ddl_ses.SelectedItem.Value + "' ", con);
                             da.Fill(dt);
                             int count = dt.Rows.Count;
                             cmd.Connection  = con;
                             cmd1.Connection = con;
                             if (count == count1)
                             {
                                 con.Close();
                                 string countmsg = count.ToString() + "__Rows are inserted...";
                                 uscMsgBox1.AddMessage(countmsg, MessageBoxUsc_Message.enmMessageType.Success);
                             }
                             else
                             {
                                 SqlCommand cmd2 = new SqlCommand("DELETE from   PROCUREMENT where plant_code='" + plant_Code + "' and  prdate between '" + txt_FromDate.Text + "' and '" + txt_FromDate.Text + "' and Sessions='" + ddl_ses.SelectedItem.Value + "' ", con);
                                 cmd2.ExecuteNonQuery();
                                 con.Close();
                                 string countmsg = "Datas Not Inserted...";
                                 uscMsgBox1.AddMessage(countmsg, MessageBoxUsc_Message.enmMessageType.Success);
                             }
                         }
                     }
                     catch (Exception ex)
                     {
                         con.Close();
                         using (con = DBaccess.GetConnection())
                         {
                             SqlCommand     cmd  = new SqlCommand();
                             SqlCommand     cmd1 = new SqlCommand();
                             DataTable      dtt  = new DataTable();
                             SqlDataAdapter daa;
                             daa = new SqlDataAdapter("SELECT * from PROCUREMENTIMPORT where plant_code='" + plant_Code + "' and  prdate between '" + txt_FromDate.Text + "' and '" + txt_FromDate.Text + "' and Sessions='" + ddl_ses.SelectedItem.Value + "' ", con);
                             daa.Fill(dtt);
                             int            count1 = dtt.Rows.Count;
                             DataTable      dt     = new DataTable();
                             SqlDataAdapter da;
                             da = new SqlDataAdapter("SELECT * from PROCUREMENT where plant_code='" + plant_Code + "' and  prdate between '" + txt_FromDate.Text + "' and '" + txt_FromDate.Text + "' and Sessions='" + ddl_ses.SelectedItem.Value + "' ", con);
                             da.Fill(dt);
                             int count = dt.Rows.Count;
                             cmd.Connection  = con;
                             cmd1.Connection = con;
                             if (count == count1)
                             {
                                 con.Close();
                                 string countmsg = count.ToString() + "__Rows are inserted...";
                                 uscMsgBox1.AddMessage(countmsg, MessageBoxUsc_Message.enmMessageType.Success);
                             }
                             else
                             {
                                 SqlCommand cmd2 = new SqlCommand("DELETE from   PROCUREMENT where plant_code='" + plant_Code + "' and  prdate between '" + txt_FromDate.Text + "' and '" + txt_FromDate.Text + "' and Sessions='" + ddl_ses.SelectedItem.Value + "' ", con);
                                 cmd2.ExecuteNonQuery();
                                 con.Close();
                                 string countmsg = "Datas Not Inserted...";
                                 uscMsgBox1.AddMessage(countmsg, MessageBoxUsc_Message.enmMessageType.Success);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
 }