protected void Button1_Click(object sender, EventArgs e) { string id = Request.QueryString["id"]; string name = TextBox1.Text; string jianjie = TextBox2.Text; string leixing = Request.Form["checkname"]; string tpdizhi = TextBox4.Text; string zuozhe = TextBox5.Text; string jieshao = TextBox6.Text; using (CDBAccess cn = new CDBAccess(System.Configuration.ConfigurationSettings.AppSettings["OledbStr"])) { string Tleixing = ""; string[] T = null; if (!string.IsNullOrEmpty(leixing)) { T = leixing.Split(','); string Tsql = ""; if (T.Length > 0) { foreach (string s in T) { Tsql += " C00004 = '" + s + "' or"; } Tsql = Tsql.Substring(0, Tsql.LastIndexOf("or")); using (DataTable dt = cn.ExecQuery("select * from T0001 where " + Tsql)) { foreach (DataRow dr in dt.Rows) { Tleixing += dr[2] + "/"; } if (dt.Rows.Count > 0) { Tleixing = Tleixing.Substring(0, Tleixing.LastIndexOf("/")); } } } } if (string.IsNullOrEmpty(id)) { Dictionary <string, string> dc = new Dictionary <string, string>(); int iid = int.Parse(cn.ExecQuery("select top 1 C00010 from T0003 order by C00010 desc").Rows[0][0].ToString()) + 1; dc.Add("id", iid.ToString()); dc.Add("name", name); dc.Add("jianjie", jianjie); dc.Add("tpdizhi", tpdizhi); dc.Add("zuozhe", zuozhe); dc.Add("jieshao", jieshao); dc.Add("tm", exPagers.getSecondEnd(DateTime.Now).ToString()); //添加 string sql = "insert into T0004(C00016,C00017,C00018,C00024,C00025,C00026,C00028,C00023) values (@id,@name,@jianjie,@tpdizhi,@zuozhe,@jieshao,1,@tm)"; cn.ExecSQL("insert into T0003 (C00010,C00011,C00013,C00012,C00014) values (@p1,@p2,@p3,@p4,@p5)", new OleDbParameter[] { new OleDbParameter("@p1", iid), new OleDbParameter("@p2", name), new OleDbParameter("@p3", tpdizhi), new OleDbParameter("@p4", exPagers.getSecondEnd(DateTime.Now)), new OleDbParameter("@p5", exPagers.getSecondEnd(DateTime.Now)) }); cn.ExecQuery(sql, cn.sqlparameter_append(dc)); // string Tid = cn.ExecQuery("select C00016 from T0004 where C00017 = @name", new OleDbParameter[] { new OleDbParameter("@name", name) }).Rows[0][0].ToString(); string insertsql = "insert into T0002(C00008,C00009) values (@p2,@p3)"; if (T != null) { foreach (string s in T) { cn.ExecSQL(insertsql, new OleDbParameter[] { new OleDbParameter("@p2", s), new OleDbParameter("@p3", iid) }); } } Response.Write("<script>alert('添加成功');window.location.href='addcomic.aspx'</script>"); } else { //修改 Dictionary <string, string> dc = new Dictionary <string, string>(); dc.Add("name", name); dc.Add("jianjie", jianjie); dc.Add("tpdizhi", tpdizhi); dc.Add("zuozhe", zuozhe); dc.Add("jieshao", jieshao); dc.Add("id", id); cn.ExecQuery("update T0003 set C00011 = @name,C00013=@tpdizhi where C00010=@id", new OleDbParameter[] { new OleDbParameter("@name", name), new OleDbParameter("@tpdizhi", tpdizhi), new OleDbParameter("@id", id) }); cn.ExecSQL("update T0004 set C00017 = @name,C00018 = @jianjie,C00024 = @tpdizhi,C00025 = @zuozhe,C00026 = @jieshao where C00016 = @id", cn.sqlparameter_append(dc)); //循环插入分类 string insertsql = "insert into T0002(C00008,C00009) values (@p2,@p3)"; cn.ExecSQL("delete from T0002 where C00009 = @id", new OleDbParameter[] { new OleDbParameter("@p", id) }); if (T != null) { foreach (string s in T) { cn.ExecSQL(insertsql, new OleDbParameter[] { new OleDbParameter("@p2", s), new OleDbParameter("@p3", id) }); } } Response.Write("<script>alert('修改成功');window.location.href='addcomic.aspx?id=" + id + "'</script>"); } } }