emma oj

emma oj

  • 1.5k
  • 195
  • 22.1k

Pop out a new page inside an update if statement

Jun 20 2018 3:52 PM
Please help i want to pop up a new page like a size of 350 by 400 pixel inside an update if statement.i was able to do this
  1. <asp:Button ID="btnpopup" runat="server" BackColor="#0099FF" Font-Bold="True" ForeColor="White" Height="39px" onclick="btnpopup_Click"  
  2. onclientclick="return openPopup()" Text="Print Now" Width="135px" />  
  3. <script type="text/javascript">  
  4. function openPopup() {  
  5. window.open("Reciept.aspx""_blank""WIDTH=350,HEIGHT=400, scrollbars=no, menubar=no,resizable=no,directories=no,location=no");  
  6. }  
  7. </script>  
it worked but the page pops out before the update statement takes place ,so it displays the last record before the update statement took place
  1. using System;  
  2. using System.Collections;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Linq;  
  6. using System.Web;  
  7. using System.Web.Security;  
  8. using System.Web.UI;  
  9. using System.Web.UI.WebControls;  
  10. using System.Web.UI.WebControls.WebParts;  
  11. using System.Web.UI.HtmlControls;  
  12. using System.Data.SqlClient;  
  13. using System.Web.Configuration;  
  14. using System.Collections.Generic;  
  15. using System.Text;  
  16. using System.Globalization;  
  17. public partial class Nampak_Home : System.Web.UI.Page  
  18. {  
  19. string selectSQL, selectSQL1, selectSQL5, selectSQL6;  
  20. string updateSQL, updateSQL1, updateSQL5, updateSQL6, updateSQL2;  
  21. SqlCommand cmd = new SqlCommand();  
  22. SqlConnection dbConn = new SqlConnection();  
  23. SqlDataReader dr, ;  
  24. protected void Page_Load(object sender, EventArgs e)  
  25. {  
  26. selectSQL = "select * from List_Staff WHERE Emp_No ='" + Session["Emp"].ToString() + "'";  
  27. dbConn.ConnectionString = "Data Source=LAPTOP-VO\\SQLEXPRESS; Initial Catalog=Client;Integrated Security=True;";  
  28. cmd.Connection = dbConn;  
  29. cmd.CommandText = selectSQL;  
  30. cmd.CommandType = CommandType.Text;  
  31. try  
  32. {  
  33. dbConn.Open();  
  34. dr = cmd.ExecuteReader();  
  35. if (dr.Read())  
  36. {  
  37. Label1.Text = dr["Name"].ToString();  
  38. Session["L"] = dr["Name"].ToString();  
  39. Label2.Text = dr["Emp_No"].ToString();  
  40. Session["D"] = dr["Emp_No"].ToString();  
  41. Label3.Text = dr["Department"].ToString();  
  42. Session["J"] = dr["Department"].ToString();  
  43. Label4.Text = dr["Company"].ToString();  
  44. Session["E"] = dr["Company"].ToString();  
  45. Session["Value"] = dr["Value"].ToString();  
  46. Session["Cat"] = dr["Meal_Cat"].ToString();  
  47. Label5.Text = dr["Meal_Ticket"].ToString();  
  48. Session["Cv"] = dr["Meal_Ticket"].ToString();  
  49. int C = Convert.ToInt32(Session["Cv"]);  
  50. if (C < 1)  
  51. {  
  52. btnpopup.Enabled = false;  
  53. }  
  54. else  
  55. {  
  56. }  
  57. }  
  58. else  
  59. {  
  60. }  
  61. dr.Close();  
  62. }  
  63. catch (Exception err)  
  64. {  
  65. Label6.Text = "Error Logging in ";  
  66. Label6.Text += err.ToString();  
  67. }  
  68. finally  
  69. {  
  70. dbConn.Close();  
  71. }  
  72. }  
  73. protected void btnpopup_Click(object sender, EventArgs e)  
  74. {  
  75. string dt = DateTime.Now.ToString("dd.MM.yyyy HH:mm");  
  76. String.Format("{0:d/M/yyyy HH:mm}", dt);  
  77. Session["T"] = dt;  
  78. DateTime bt = System.DateTime.Now;  
  79. string format = "dd/MM/yyyy";  
  80. string newDate = bt.ToString(format);  
  81. Session["T1"] = newDate;  
  82. selectSQL = "select Meal_Ticket from List_Staff WHERE Emp_No ='" + Session["Emp"].ToString() + "'";  
  83. dbConn.ConnectionString = "Data Source=LAPTOP-VO\\SQLEXPRESS; Initial Catalog=Client;Integrated Security=True;";  
  84. cmd.Connection = dbConn;  
  85. cmd.CommandText = selectSQL;  
  86. cmd.CommandType = CommandType.Text;  
  87. try  
  88. {  
  89. dbConn.Open();  
  90. dr = cmd.ExecuteReader();  
  91. if (dr.Read())  
  92. {  
  93. Session["RT"] = dr["Meal_Ticket"].ToString();  
  94. int x = Convert.ToInt32(Session["RT"]);  
  95. int y = x - 1;  
  96. string t = y.ToString();  
  97. Session["TR"] = y.ToString();updateSQL = "update List_Staff set Meal_Ticket='" + y + "' where Emp_No ='" + Session["Emp"].ToString() + "'";  
  98. dbConn.ConnectionString = "Data Source=LAPTOP-VO\\SQLEXPRESS; Initial Catalog=Client;Integrated Security=True;";  
  99. cmd.Connection = dbConn;  
  100. cmd.CommandText = updateSQL;  
  101. cmd.CommandType = CommandType.Text;  
  102. try  
  103. {  
  104. dbConn.Open();  
  105. // Response.Write(updateSQL1);  
  106. int updated1 = cmd.ExecuteNonQuery();  
  107. if (updated1 == 1)  
  108. {  
  109. selectSQL = "select Value1 from Static WHERE id ='1'";  
  110. dbConn.ConnectionString = "Data Source=LAPTOP-VO\\SQLEXPRESS; Initial Catalog=Client;Integrated Security=True;";  
  111. cmd.Connection = dbConn;  
  112. cmd.CommandText = selectSQL;  
  113. cmd.CommandType = CommandType.Text;  
  114. try  
  115. {  
  116. dbConn.Open();  
  117. dr = cmd.ExecuteReader();  
  118. if (dr.Read())  
  119. {  
  120. Session["Val"] = dr5["Value1"].ToString();  
  121. int G = Convert.ToInt32(Session["Val"]);  
  122. int H = G + 1;  
  123. string j = H.ToString();  
  124. Session["V1"] = H.ToString();  
  125. updateSQL = "update Static set Value1='" + Session["V1"].ToString() + "' where id ='1'";  
  126. dbConn.ConnectionString = "Data Source=LAPTOP-VO\\SQLEXPRESS; Initial Catalog=Client;Integrated Security=True;";  
  127. cmd.Connection = dbConn;  
  128. cmd.CommandText = updateSQL;  
  129. cmd.CommandType = CommandType.Text;  
  130. try  
  131. {  
  132. dbConn.Open();  
  133. int updated2 = cmd.ExecuteNonQuery();  
  134. if (updated2 == 1)  
  135. {  
  136. String insertSQL9;  
  137. DateTimeFormatInfo dateFormatProvider = new DateTimeFormatInfo();  
  138. dateFormatProvider.ShortDatePattern = "0:d/M/yyyy HH:mm";  
  139. var tt = DateTime.Parse(Session["T"].ToString(), dateFormatProvider);  
  140. DateTimeFormatInfo dateFormatProvider1 = new DateTimeFormatInfo();  
  141. dateFormatProvider1.ShortDatePattern = "dd/MM/yyyy";  
  142. var tt1 = DateTime.Parse(Session["T1"].ToString(), dateFormatProvider);  
  143. insertSQL = "INSERT INTO MealLog (";  
  144. insertSQL += "Name,Emp_No,Meal_Cat,Department,Company,Reciept_No,Value,Time,Time1)";  
  145. insertSQL += "VALUES('";  
  146. insertSQL += Session["L"].ToString() + "','";  
  147. insertSQL += Session["D"].ToString() + "','";  
  148. insertSQL += Session["Cat"].ToString() + "','";  
  149. insertSQL += Session["J"].ToString() + "','";  
  150. insertSQL += Session["E"].ToString() + "','";  
  151. insertSQL += Session["V1"].ToString() + "','";  
  152. insertSQL += Session["Value"].ToString() + "','";  
  153. insertSQL += tt + "','";  
  154. insertSQL += tt1 + "')";  
  155. String connectionString = "Data Source=LAPTOP-VO\\SQLEXPRESS; Initial Catalog=Client;Integrated Security=True;";  
  156. SqlConnection con = new SqlConnection(connectionString);  
  157. SqlCommand cmd = new SqlCommand(insertSQL, con);  
  158. int added9 = 0;  
  159. try  
  160. {  
  161. con.Open();  
  162. added9 = cmd.ExecuteNonQuery();  
  163. if (added9 == 1)  
  164. {  
  165. //i want the page to pop out after this update is done.  
  166. //i want to pop up a new page like a size of 350 by 400 pixel after the update  
  167. }  
  168. else  
  169. {  
  170. // Response.Redirect("No.aspx");  
  171. }  
  172. // Label1.Text = added.ToString() + "records Inserted";  
  173. }  
  174. catch (Exception err)  
  175. {  
  176. Label6.Text += err.ToString();  
  177. }  
  178. finally  
  179. {  
  180. dbConn.Close();  
  181. }  
  182. }  
  183. else  
  184. {  
  185. // Response.Write("It happened");  
  186. }  
  187. }  
  188. catch (Exception err)  
  189. {  
  190. Label6.Text = "Error Updating ";  
  191. Label6.Text += err.ToString();  
  192. }  
  193. finally  
  194. {  
  195. dbConn6.Close();  
  196. }  
  197. }  
  198. else  
  199. {  
  200. }  
  201. dr.Close();  
  202. }  
  203. catch (Exception err)  
  204. {  
  205. Label6.Text = "Error Logging in 2 ";  
  206. Label6.Text += err.ToString();  
  207. }  
  208. finally  
  209. {  
  210. dbConn5.Close();  
  211. }  
  212. }  
  213. }  
  214. catch (Exception err)  
  215. {  
  216. Response.Write(err.ToString());  
  217. }  
  218. finally  
  219. {  
  220. dbConn.Close();  
  221. }  
  222.   
  223. }  
  224. else  
  225. {  
  226. Label6.Text = "sorry you cant view this page ";  
  227. }  
  228. dr.Close();  
  229. }  
  230. catch (Exception err)  
  231. {  
  232. Label6.Text = "Error Logging in 3";  
  233. Label6.Text += err.ToString();  
  234. }  
  235. finally  
  236. {  
  237. dbConn.Close();  
  238. }  
  239. Response.Redirect(HttpContext.Current.Request.Path);  
  240. }  
  241. protected void LinkButton1_Click(object sender, EventArgs e)  
  242. {  
  243. Session.Remove("Emp");  
  244. Session["Emp"] = "";  
  245. }  
  246. }  
Please help i want to pop up a new page like a size of 350 by 400 pixel inside the update if statement

Answers (1)