AddRecord.aspx.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. public partial class AddRecord : System.Web.UI.Page
  8. {
  9. LYS.UserData1 myud = new LYS.UserData1();
  10. //string ranCode = "";//HttpContext.Current.Request.QueryString["RanCode"].ToString();
  11. /// <summary>
  12. /// 使用方法,首先从参数中得到表名,然后根据表名得到SQL语句
  13. /// AddRecord.aspx?RanCode=Adr5332tr5454dai //班级管理表
  14. /// </summary>
  15. /// <param name="sender"></param>
  16. /// <param name="e"></param>
  17. protected void Page_Load(object sender, EventArgs e)
  18. {
  19. string myURL = myud.GetAddressUrl().ToString();
  20. if (myURL.LastIndexOf("tn") <= 0)
  21. {
  22. Response.Write("<script>alert('程序非法调用!')</script>");
  23. Response.End();
  24. }
  25. // ranCode = HttpContext.Current.Request.QueryString["tn"].ToString();
  26. Session["TableNameSQL"] = Request.QueryString["tn"].ToString(); ;
  27. Session["addSQL"] = "select * from " + Session["TableNameSQL"].ToString();
  28. // Session["TableNameSQL"] = "Tb_Dempent";
  29. //Session["addSQL"] = "select * from " + Session["TableNameSQL"].ToString();
  30. // Response.Write(Session["addSQL"].ToString());
  31. Literal1.Text = myud.BuildAddRecordFormOK(Session["addSQL"].ToString()).ToString();
  32. // Literal2.Text = Literal2.Text + "--" + myud.GetKeyFieldValue(3, "RanCode", ranCode, "AdminTreeGJK").ToString();
  33. }
  34. protected void Button1_Click(object sender, EventArgs e)
  35. {// 自动添加之前自动查重
  36. // string key1 = "用户名";
  37. // string key2 = "工号";//myud.GetKeyFieldValue(9, "RanCode", ranCode, "AdminTreeGJK").ToString();
  38. // string key1v=myud.GetKeyFieldName(key1,
  39. // Response.Write("Key2="+key1);
  40. //if (myud.CheckSQLRepeatRecord(SQL))
  41. //{
  42. // Response.Write("<script>alert('数据库已经有同样的数据,不能重复添加!')</script>");
  43. //}
  44. //for (int i = 1; i < HttpContext.Current.Request.Form.Count; i++)
  45. //{
  46. // string name = HttpContext.Current.Request.Form.GetKey(i);
  47. // //Response.Write(name + ":<br>");
  48. // if (name.IndexOf("Text") > 0 || name.IndexOf("Label") > 0)
  49. // {
  50. // if (HttpContext.Current.Request.Form[i].ToString() == key1)
  51. // {
  52. // Response.Write(HttpContext.Current.Request.Form[i].ToString() + ":");
  53. // Response.Write(HttpContext.Current.Request.Form["MyText"+i.ToString()] + "<br>");
  54. // }
  55. // if (HttpContext.Current.Request.Form[i].ToString() == key2)
  56. // {
  57. // Response.Write(HttpContext.Current.Request.Form[i].ToString() + ":");
  58. // Response.Write(HttpContext.Current.Request.Form["MyText" + i.ToString()] + "<br>");
  59. // }
  60. // }
  61. //if (name.IndexOf("Text") > 0)
  62. //{
  63. // Response.Write("Text" + HttpContext.Current.Request.Form[i] + "<br>");
  64. //}
  65. // }
  66. try
  67. {
  68. //myud.AddRecordToDB1(Session["addSQL"].ToString(), Session["TableNameSQL"].ToString(),key1,key2); //查重复,有点问题最后两个字段丢失
  69. // string chkSQL= Session["addSQL"] +" where key1
  70. myud.AddRecordToDB(Session["addSQL"].ToString(), Session["TableNameSQL"].ToString());
  71. Response.Write("<script>alert('数据添加成功!')</script>");
  72. }
  73. catch (Exception ex)
  74. { Response.Write("<script>alert('" + ex.Message + ";或者是数据库已经有同样的数据,不能重复添加!或出现无法预料的错误!!')</script>"); }
  75. finally
  76. { }
  77. }
  78. protected void Button2_Click(object sender, EventArgs e)
  79. {
  80. // TextBox2.Text = myud.EncryptDes(TextBox1.Text);
  81. }
  82. }