using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using web.Classes; namespace web.Web.Mld { public partial class MainCtnSettings : System.Web.UI.Page { public string _TableHTML; protected void Page_Load(object sender, EventArgs e) { if (Request["action"] == "save") { string rst = Save(); Response.Write(rst); Response.End(); } else if (Request["action"] == "delete") { string rst = Delete(); Response.Write(rst); Response.End(); } CreateDataList(); } private void CreateDataList() { string sql = "select * from HBLNOCTNDetails order by CreateTime desc"; List list = new List(); using (SqlDataReader reader = SQLHelper.GetReader(sql)) { while (reader.Read()) { HBLNOCTNSettingModel m = new HBLNOCTNSettingModel(); m.id = Convert.ToInt32(reader["id"]); m.HBLNO = reader["HBLNO"].ToString(); m.CTNNO = reader["CTNNO"].ToString(); m.CreateTime = reader["CreateTime"].ToString(); m.UpdateTime = reader["UpdateTime"].ToString(); list.Add(m); } } StringBuilder sbHtml = new StringBuilder(); foreach (var item in list) { sbHtml.Append(""); sbHtml.Append(""); sbHtml.Append(item.id.ToString()); sbHtml.Append(""); sbHtml.Append(""); sbHtml.Append(item.HBLNO); sbHtml.Append(""); sbHtml.Append(""); sbHtml.Append(item.CTNNO); sbHtml.Append(""); sbHtml.Append(""); sbHtml.Append(item.UpdateTime); sbHtml.Append(""); sbHtml.Append(""); sbHtml.Append(item.CreateTime); sbHtml.Append(""); sbHtml.Append(""); sbHtml.Append(""); sbHtml.Append(""); sbHtml.Append(""); sbHtml.Append(""); } _TableHTML = sbHtml.ToString(); } private string Save() { string result = ""; string id = Request["id"]; string hblno = Request["hblno"]; string ctnno = Request["ctnno"]; if (id == "") { StringBuilder sb = new StringBuilder(); sb.Append("insert into HBLNOCTNDetails "); sb.Append("(hblno,ctnno,createtime) "); sb.Append("values("); sb.Append("'" + hblno + "',"); sb.Append("'" + ctnno + "',"); string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); sb.Append("'" + time + "')"); int rst = SQLHelper.ExcuteSQL(sb.ToString()); result = rst > 0 ? "添加成功" : "添加失败"; } else { StringBuilder sb = new StringBuilder(); sb.Append("update HBLNOCTNDetails "); sb.Append("set hblno = '" + hblno + "',"); sb.Append("ctnno = '" + ctnno + "'"); sb.Append(" where id = " + id.ToString()); int rst = SQLHelper.ExcuteSQL(sb.ToString()); result = rst > 0 ? "更新成功" : "更新失败"; } return result; } private string Delete() { string result = ""; string id = Request["id"]; string sql = "delete from HBLNOCTNDetails where id=" + id; int rst = SQLHelper.ExcuteSQL(sql); result = rst > 0 ? "删除成功" : "更新失败"; return result; } } }