You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.3 KiB
C#

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<HBLNOCTNSettingModel> list = new List<HBLNOCTNSettingModel>();
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("<tr>");
sbHtml.Append("<td>");
sbHtml.Append(item.id.ToString());
sbHtml.Append("</td>");
sbHtml.Append("<td>");
sbHtml.Append(item.HBLNO);
sbHtml.Append("</td>");
sbHtml.Append("<td>");
sbHtml.Append(item.CTNNO);
sbHtml.Append("</td>");
sbHtml.Append("<td>");
sbHtml.Append(item.UpdateTime);
sbHtml.Append("</td>");
sbHtml.Append("<td>");
sbHtml.Append(item.CreateTime);
sbHtml.Append("</td>");
sbHtml.Append("<td>");
sbHtml.Append("<button type=\"button\" class=\"btn btn-success btn-xs dataEdit\">修改</button>");
sbHtml.Append("<button type = \"button\" class=\"btn btn-danger btn-xs dataDel\">删除</button>");
sbHtml.Append("</td>");
sbHtml.Append("</tr>");
}
_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;
}
}
}