123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class AddRecord : System.Web.UI.Page
- {
- LYS.UserData1 myud = new LYS.UserData1();
- //string ranCode = "";//HttpContext.Current.Request.QueryString["RanCode"].ToString();
- /// <summary>
- /// 使用方法,首先从参数中得到表名,然后根据表名得到SQL语句
- /// AddRecord.aspx?RanCode=Adr5332tr5454dai //班级管理表
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void Page_Load(object sender, EventArgs e)
- {
- string myURL = myud.GetAddressUrl().ToString();
- if (myURL.LastIndexOf("tn") <= 0)
- {
- Response.Write("<script>alert('程序非法调用!')</script>");
- Response.End();
- }
- // ranCode = HttpContext.Current.Request.QueryString["tn"].ToString();
- Session["TableNameSQL"] = Request.QueryString["tn"].ToString(); ;
- Session["addSQL"] = "select * from " + Session["TableNameSQL"].ToString();
- // Session["TableNameSQL"] = "Tb_Dempent";
- //Session["addSQL"] = "select * from " + Session["TableNameSQL"].ToString();
- // Response.Write(Session["addSQL"].ToString());
- Literal1.Text = myud.BuildAddRecordFormOK(Session["addSQL"].ToString()).ToString();
- // Literal2.Text = Literal2.Text + "--" + myud.GetKeyFieldValue(3, "RanCode", ranCode, "AdminTreeGJK").ToString();
- }
- protected void Button1_Click(object sender, EventArgs e)
- {// 自动添加之前自动查重
- // string key1 = "用户名";
- // string key2 = "工号";//myud.GetKeyFieldValue(9, "RanCode", ranCode, "AdminTreeGJK").ToString();
- // string key1v=myud.GetKeyFieldName(key1,
- // Response.Write("Key2="+key1);
- //if (myud.CheckSQLRepeatRecord(SQL))
- //{
- // Response.Write("<script>alert('数据库已经有同样的数据,不能重复添加!')</script>");
- //}
- //for (int i = 1; i < HttpContext.Current.Request.Form.Count; i++)
- //{
- // string name = HttpContext.Current.Request.Form.GetKey(i);
- // //Response.Write(name + ":<br>");
- // if (name.IndexOf("Text") > 0 || name.IndexOf("Label") > 0)
- // {
- // if (HttpContext.Current.Request.Form[i].ToString() == key1)
- // {
- // Response.Write(HttpContext.Current.Request.Form[i].ToString() + ":");
- // Response.Write(HttpContext.Current.Request.Form["MyText"+i.ToString()] + "<br>");
- // }
- // if (HttpContext.Current.Request.Form[i].ToString() == key2)
- // {
- // Response.Write(HttpContext.Current.Request.Form[i].ToString() + ":");
- // Response.Write(HttpContext.Current.Request.Form["MyText" + i.ToString()] + "<br>");
- // }
- // }
- //if (name.IndexOf("Text") > 0)
- //{
- // Response.Write("Text" + HttpContext.Current.Request.Form[i] + "<br>");
- //}
- // }
- try
- {
- //myud.AddRecordToDB1(Session["addSQL"].ToString(), Session["TableNameSQL"].ToString(),key1,key2); //查重复,有点问题最后两个字段丢失
- // string chkSQL= Session["addSQL"] +" where key1
- myud.AddRecordToDB(Session["addSQL"].ToString(), Session["TableNameSQL"].ToString());
- Response.Write("<script>alert('数据添加成功!')</script>");
- }
- catch (Exception ex)
- { Response.Write("<script>alert('" + ex.Message + ";或者是数据库已经有同样的数据,不能重复添加!或出现无法预料的错误!!')</script>"); }
- finally
- { }
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- // TextBox2.Text = myud.EncryptDes(TextBox1.Text);
- }
- }
|