Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.57 KB | None | 0 0
  1. protected void chkselect_CheckedChanged(object sender, EventArgs e)
  2. {
  3. //Check if a row is selected
  4. selectrow();
  5. //Updates gridview for action
  6. bindgrid();
  7. }
  8.  
  9. protected void grid_pendingapproval()
  10. {
  11. //Connect to SQL Instance
  12. ConnectToDB();
  13. //Get data from view
  14. 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);
  15. //Store data in a datatable
  16. DataTable dt = new DataTable();
  17. sda.Fill(dt);
  18. GridView5.DataSource = dt;
  19. //Bind data to gridview
  20. GridView5.DataBind();
  21. }
  22.  
  23. protected void grid_declined()
  24. {
  25. //Connect to SQL Instance
  26. ConnectToDB();
  27. //Get data from view
  28. 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);
  29. //Store data in a datatable
  30. DataTable dt = new DataTable();
  31. sda.Fill(dt);
  32. GridView5.DataSource = dt;
  33. //Bind data to gridview
  34. GridView5.DataBind();
  35. }
  36.  
  37. protected void grid_approved()
  38. {
  39. //Connect to SQL Instance
  40. ConnectToDB();
  41. //Get data from view
  42. 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);
  43. //Store data in a datatable
  44. DataTable dt = new DataTable();
  45. sda.Fill(dt);
  46. GridView5.DataSource = dt;
  47. //Bind data to gridview
  48. GridView5.DataBind();
  49. }
  50.  
  51. protected void bindgrid()
  52. {
  53. DataTable dt = (DataTable)ViewState["GetRecords"];
  54. GridView6.DataSource = dt;
  55. //Bind data to gridview
  56. GridView6.DataBind();
  57.  
  58. }
  59.  
  60. private DataTable createtable()
  61. {
  62. //Creating the gridview for displaying the data
  63. DataTable dt = new DataTable();
  64. dt.Columns.Add("Sales Order Number");
  65. dt.Columns.Add("Date");
  66. dt.Columns.Add("Customer Code");
  67. dt.Columns.Add("Customer Name");
  68. dt.Columns.Add("Total Weight");
  69. dt.Columns.Add("Order Total (Incl)");
  70. dt.Columns.Add("Account Terms");
  71. dt.Columns.Add("Credit Limit");
  72. dt.Columns.Add("Status");
  73. dt.Columns.Add("AutoIndex");
  74. dt.Columns.Add("Expiration Date");
  75. dt.AcceptChanges();
  76. return dt;
  77. }
  78.  
  79. private DataTable addrows(GridViewRow gridrow, DataTable dt)
  80. {
  81. //Adding rows to gridview for action
  82. DataRow[] dr = dt.Select("AutoIndex='" + gridrow.Cells[11].Text + "'");
  83. if(dr.Length <= 0)
  84. {
  85. dt.Rows.Add();
  86. int rowcount = dt.Rows.Count - 1;
  87. dt.Rows[rowcount]["Sales Order Number"] = gridrow.Cells[1].Text;
  88. dt.Rows[rowcount]["Date"] = gridrow.Cells[2].Text;
  89. dt.Rows[rowcount]["Customer Code"] = gridrow.Cells[3].Text;
  90. dt.Rows[rowcount]["Customer Name"] = gridrow.Cells[4].Text;
  91. dt.Rows[rowcount]["Total Weight"] = gridrow.Cells[5].Text;
  92. dt.Rows[rowcount]["Order Total (Incl)"] = gridrow.Cells[6].Text;
  93. dt.Rows[rowcount]["Account Terms"] = gridrow.Cells[7].Text;
  94. dt.Rows[rowcount]["Credit Limit"] = gridrow.Cells[8].Text;
  95. dt.Rows[rowcount]["Status"] = gridrow.Cells[9].Text;
  96. dt.Rows[rowcount]["AutoIndex"] = gridrow.Cells[10].Text;
  97. dt.Rows[rowcount]["Expiration Date"] = gridrow.Cells[11].Text;
  98. dt.AcceptChanges();
  99. }
  100. return dt;
  101. }
  102.  
  103. private DataTable remove(GridViewRow gridrow, DataTable dt)
  104. {
  105. //Removing rows from gridview for action
  106. DataRow[] dr = dt.Select("AutoIndex ='" + gridrow.Cells[11].Text + "'");
  107. if (dr.Length > 0)
  108. {
  109. dt.Rows.Remove(dr[0]);
  110. dt.AcceptChanges();
  111. }
  112. return dt;
  113. }
  114.  
  115. private void selectrow()
  116. {
  117. //Selecting rows to update action gridview
  118. DataTable dt;
  119. if (ViewState["GetRecords"] != null)
  120. dt = (DataTable)ViewState["GetRecords"];
  121. else
  122. dt = createtable();
  123. for (int i = 0; i < GridView5.Rows.Count; i++)
  124. {
  125. CheckBox chk = (CheckBox)GridView5.Rows[i].Cells[0].FindControl("chkselect");
  126. if (chk.Checked)
  127. {
  128. dt = addrows(GridView5.Rows[i], dt);
  129. }
  130. else
  131. {
  132. dt = remove(GridView5.Rows[i], dt);
  133. }
  134. }
  135. ViewState["GetRecords"] = dt;
  136.  
  137.  
  138. protected void Button_Approve_Click(object sender, EventArgs e)
  139. {
  140.  
  141. //Connect to SQL Instance
  142. ConnectToDB();
  143. //Get status id for approval
  144. SqlCommand cmd = new SqlCommand("SELECT statusid, id FROM ZS_soa_agent WHERE Agent = '" + Session["Agent"].ToString()+"'",conn);
  145. SqlDataReader reader = cmd.ExecuteReader();
  146. try
  147. {
  148. while (reader.Read())
  149. {
  150. //int logitrack_id = (int)reader["logitrack_id"];
  151. int statusid = (int)reader["statusid"];
  152. int agentid = (int)reader["id"];
  153. for (int i = 0; i < GridView6.Rows.Count; i++)
  154. {
  155. try
  156. {
  157. //Connect to SQL Instance
  158. ConnectToDB();
  159. EVOService evs = new EVOService();
  160. evs.EvoConn();
  161.  
  162. int autoid = Int32.Parse(GridView6.Rows[i].Cells[0].Text);
  163. string order = GridView6.Rows[i].Cells[3].Text;
  164. //Convert to string from input, Hold in temp until update**
  165. TextBox txt = (TextBox)GridView6.Rows[i].Cells[0].FindControl("txtComments");
  166. string txtcomments = txt.Text;
  167.  
  168. SqlCommand disabletrg = new SqlCommand("DISABLE TRIGGER ZS_trgSOStatusChange ON InvNum", conn);
  169. disabletrg.ExecuteNonQuery();
  170. //Update order status
  171. SqlCommand update = new SqlCommand("UPDATE InvNum SET OrderStatusID = " + statusid + ", InvNum_iModifiedAgentID = " + agentid + " WHERE AutoIndex = " + autoid, conn);
  172. update.ExecuteNonQuery();
  173. //Update Message1 - insert message from comment box***
  174. SqlCommand updateMessage = new SqlCommand("UPDATE InvNum SET Message1 = '" + txtcomments + "' WHERE AutoIndex = " + autoid, conn);
  175. updateMessage.ExecuteNonQuery();
  176. //Update Message3 with Docstate
  177. SqlCommand update2 = new SqlCommand("UPDATE InvNum SET Message3 = DocState WHERE AutoIndex = " + autoid, conn);
  178. update2.ExecuteNonQuery();
  179. //Add Date to Due Date
  180. //SqlCommand DueDate = new SqlCommand("INSERT INTO InvNum (DueDate) Values (GETDATE()) WHERE AutoIndex = " + autoid, conn);
  181. //DueDate.ExecuteNonQuery();
  182. //Enable status trigger
  183. SqlCommand enabletrg = new SqlCommand("ENABLE TRIGGER ZS_trgSOStatusChange ON InvNum", conn);
  184. enabletrg.ExecuteNonQuery();
  185. //Update log table with action
  186. SqlCommand log = new SqlCommand("INSERT INTO ZS_soa_log VALUES(GETDATE(),"+ autoid + ",'" + Session["Agent"].ToString() + "','" + order + "', 'Approved')", conn);
  187. log.ExecuteNonQuery();
  188. }
  189. catch
  190. {
  191. return;
  192. }
  193. }
  194. conn.Close();
  195. }
  196. }
  197.  
  198. catch
  199.  
  200. {
  201. return;
  202. }
  203. //Refresh page
  204. Response.AddHeader("REFRESH", "1;URL=SalesOrderApproval.aspx");
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement