Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void chkselect_CheckedChanged(object sender, EventArgs e)
- {
- //Check if a row is selected
- selectrow();
- //Updates gridview for action
- bindgrid();
- }
- protected void grid_pendingapproval()
- {
- //Connect to SQL Instance
- ConnectToDB();
- //Get data from view
- SqlDataAdapter sda = new SqlDataAdapter("SELECT [Sales Order Number], [Customer Code], [Customer Name], [Total Weight], [Order Total (Incl)], [Account Terms], [Credit Limit], Status, Autoindex, [Document State],Date,CASE[Document State]WHEN 'Unprocessed' THEN DATEADD(day, 14, Date)WHEN 'Partially Processed' THEN DATEADD(day, 7, Date)END AS[Expiration Date]FROM ZS_vwSOA_PendingApproval WHERE[Document State] IN('Unprocessed', 'Partially Processed')", conn);
- //Store data in a datatable
- DataTable dt = new DataTable();
- sda.Fill(dt);
- GridView5.DataSource = dt;
- //Bind data to gridview
- GridView5.DataBind();
- }
- protected void grid_declined()
- {
- //Connect to SQL Instance
- ConnectToDB();
- //Get data from view
- SqlDataAdapter sda = new SqlDataAdapter("SELECT [Customer Code], [Customer Name], [Sales Order Number], [Total Weight], [Order Total (Incl)], [Account Terms], [Credit Limit], Status, Autoindex, [Document State],Date, 'Declined' as [Expiration Date] FROM ZS_vwSOA_Declined WHERE [Document State] = 'Cancelled'", conn);
- //Store data in a datatable
- DataTable dt = new DataTable();
- sda.Fill(dt);
- GridView5.DataSource = dt;
- //Bind data to gridview
- GridView5.DataBind();
- }
- protected void grid_approved()
- {
- //Connect to SQL Instance
- ConnectToDB();
- //Get data from view
- SqlDataAdapter sda = new SqlDataAdapter("SELECT [Customer Code], [Customer Name], [Sales Order Number], [Total Weight], [Order Total (Incl)], [Account Terms], [Credit Limit], Status, Autoindex, [Document State],Date, 'Approved' as [Expiration Date] FROM ZS_vwSOA_Approved WHERE [Document State] IN ('Unprocessed','Partially Processed')", conn);
- //Store data in a datatable
- DataTable dt = new DataTable();
- sda.Fill(dt);
- GridView5.DataSource = dt;
- //Bind data to gridview
- GridView5.DataBind();
- }
- protected void bindgrid()
- {
- DataTable dt = (DataTable)ViewState["GetRecords"];
- GridView6.DataSource = dt;
- //Bind data to gridview
- GridView6.DataBind();
- }
- private DataTable createtable()
- {
- //Creating the gridview for displaying the data
- DataTable dt = new DataTable();
- dt.Columns.Add("Sales Order Number");
- dt.Columns.Add("Date");
- dt.Columns.Add("Customer Code");
- dt.Columns.Add("Customer Name");
- dt.Columns.Add("Total Weight");
- dt.Columns.Add("Order Total (Incl)");
- dt.Columns.Add("Account Terms");
- dt.Columns.Add("Credit Limit");
- dt.Columns.Add("Status");
- dt.Columns.Add("AutoIndex");
- dt.Columns.Add("Expiration Date");
- dt.AcceptChanges();
- return dt;
- }
- private DataTable addrows(GridViewRow gridrow, DataTable dt)
- {
- //Adding rows to gridview for action
- DataRow[] dr = dt.Select("AutoIndex='" + gridrow.Cells[11].Text + "'");
- if(dr.Length <= 0)
- {
- dt.Rows.Add();
- int rowcount = dt.Rows.Count - 1;
- dt.Rows[rowcount]["Sales Order Number"] = gridrow.Cells[1].Text;
- dt.Rows[rowcount]["Date"] = gridrow.Cells[2].Text;
- dt.Rows[rowcount]["Customer Code"] = gridrow.Cells[3].Text;
- dt.Rows[rowcount]["Customer Name"] = gridrow.Cells[4].Text;
- dt.Rows[rowcount]["Total Weight"] = gridrow.Cells[5].Text;
- dt.Rows[rowcount]["Order Total (Incl)"] = gridrow.Cells[6].Text;
- dt.Rows[rowcount]["Account Terms"] = gridrow.Cells[7].Text;
- dt.Rows[rowcount]["Credit Limit"] = gridrow.Cells[8].Text;
- dt.Rows[rowcount]["Status"] = gridrow.Cells[9].Text;
- dt.Rows[rowcount]["AutoIndex"] = gridrow.Cells[10].Text;
- dt.Rows[rowcount]["Expiration Date"] = gridrow.Cells[11].Text;
- dt.AcceptChanges();
- }
- return dt;
- }
- private DataTable remove(GridViewRow gridrow, DataTable dt)
- {
- //Removing rows from gridview for action
- DataRow[] dr = dt.Select("AutoIndex ='" + gridrow.Cells[11].Text + "'");
- if (dr.Length > 0)
- {
- dt.Rows.Remove(dr[0]);
- dt.AcceptChanges();
- }
- return dt;
- }
- private void selectrow()
- {
- //Selecting rows to update action gridview
- DataTable dt;
- if (ViewState["GetRecords"] != null)
- dt = (DataTable)ViewState["GetRecords"];
- else
- dt = createtable();
- for (int i = 0; i < GridView5.Rows.Count; i++)
- {
- CheckBox chk = (CheckBox)GridView5.Rows[i].Cells[0].FindControl("chkselect");
- if (chk.Checked)
- {
- dt = addrows(GridView5.Rows[i], dt);
- }
- else
- {
- dt = remove(GridView5.Rows[i], dt);
- }
- }
- ViewState["GetRecords"] = dt;
- protected void Button_Approve_Click(object sender, EventArgs e)
- {
- //Connect to SQL Instance
- ConnectToDB();
- //Get status id for approval
- SqlCommand cmd = new SqlCommand("SELECT statusid, id FROM ZS_soa_agent WHERE Agent = '" + Session["Agent"].ToString()+"'",conn);
- SqlDataReader reader = cmd.ExecuteReader();
- try
- {
- while (reader.Read())
- {
- //int logitrack_id = (int)reader["logitrack_id"];
- int statusid = (int)reader["statusid"];
- int agentid = (int)reader["id"];
- for (int i = 0; i < GridView6.Rows.Count; i++)
- {
- try
- {
- //Connect to SQL Instance
- ConnectToDB();
- EVOService evs = new EVOService();
- evs.EvoConn();
- int autoid = Int32.Parse(GridView6.Rows[i].Cells[0].Text);
- string order = GridView6.Rows[i].Cells[3].Text;
- //Convert to string from input, Hold in temp until update**
- TextBox txt = (TextBox)GridView6.Rows[i].Cells[0].FindControl("txtComments");
- string txtcomments = txt.Text;
- SqlCommand disabletrg = new SqlCommand("DISABLE TRIGGER ZS_trgSOStatusChange ON InvNum", conn);
- disabletrg.ExecuteNonQuery();
- //Update order status
- SqlCommand update = new SqlCommand("UPDATE InvNum SET OrderStatusID = " + statusid + ", InvNum_iModifiedAgentID = " + agentid + " WHERE AutoIndex = " + autoid, conn);
- update.ExecuteNonQuery();
- //Update Message1 - insert message from comment box***
- SqlCommand updateMessage = new SqlCommand("UPDATE InvNum SET Message1 = '" + txtcomments + "' WHERE AutoIndex = " + autoid, conn);
- updateMessage.ExecuteNonQuery();
- //Update Message3 with Docstate
- SqlCommand update2 = new SqlCommand("UPDATE InvNum SET Message3 = DocState WHERE AutoIndex = " + autoid, conn);
- update2.ExecuteNonQuery();
- //Add Date to Due Date
- //SqlCommand DueDate = new SqlCommand("INSERT INTO InvNum (DueDate) Values (GETDATE()) WHERE AutoIndex = " + autoid, conn);
- //DueDate.ExecuteNonQuery();
- //Enable status trigger
- SqlCommand enabletrg = new SqlCommand("ENABLE TRIGGER ZS_trgSOStatusChange ON InvNum", conn);
- enabletrg.ExecuteNonQuery();
- //Update log table with action
- SqlCommand log = new SqlCommand("INSERT INTO ZS_soa_log VALUES(GETDATE(),"+ autoid + ",'" + Session["Agent"].ToString() + "','" + order + "', 'Approved')", conn);
- log.ExecuteNonQuery();
- }
- catch
- {
- return;
- }
- }
- conn.Close();
- }
- }
- catch
- {
- return;
- }
- //Refresh page
- Response.AddHeader("REFRESH", "1;URL=SalesOrderApproval.aspx");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement