protected void Page_Load(object sender, EventArgs e) { //先得到操作类型 string SysType = Request.Params["systype"].ToString(); if (SysType == "e")//修改,不能修改用户的类型及学校参数 { btname = "修改"; id = Request.Params["autoid"].ToString(); SchSystem.BLL.SysColl bll = new SchSystem.BLL.SysColl(); SchSystem.Model.SysColl model = bll.GetModel(int.Parse(id)); if (model != null && model.AutoId > 0) { code = model.CollCode; name = model.CollName; stat = model.Stat.ToString(); } else { Response.Write("无该名称!"); Response.End(); } } else//不在添加及修改之内,则返回 { } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SchSystem.Model.SysColl model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update SysColl set "); strSql.Append("CollName=@CollName,"); strSql.Append("Stat=@Stat"); strSql.Append(" where AutoId=@AutoId"); SqlParameter[] parameters = { new SqlParameter("@CollName", SqlDbType.NVarChar, 20), new SqlParameter("@Stat", SqlDbType.TinyInt, 1), new SqlParameter("@AutoId", SqlDbType.Int, 4) }; parameters[0].Value = model.CollName; parameters[1].Value = model.Stat; parameters[2].Value = model.AutoId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SchSystem.Model.SysColl model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into SysColl("); strSql.Append("CollName,CollCode,Stat)"); strSql.Append(" values ("); strSql.Append("@CollName,@CollCode,@Stat)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CollName", SqlDbType.NVarChar, 20), new SqlParameter("@CollCode", SqlDbType.VarChar, 10), new SqlParameter("@Stat", SqlDbType.TinyInt, 1) }; parameters[0].Value = model.CollName; parameters[1].Value = model.CollCode; parameters[2].Value = model.Stat; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
public static Com.DataPack.DataRsp <string> save(string Name, string stat, string AutoId) { Com.DataPack.DataRsp <string> rsp = new Com.DataPack.DataRsp <string>(); if (Com.Session.userid == null) { rsp.code = "expire"; rsp.msg = "页面已经过期,请重新登录"; } else { try { SchSystem.BLL.SysColl bll = new SchSystem.BLL.SysColl(); SchSystem.Model.SysColl model = new SchSystem.Model.SysColl(); model.CollName = Com.Public.SqlEncStr(Name).ToString(); model.Stat = Convert.ToInt32(Com.Public.SqlEncStr(stat)); if (AutoId != "") { model.AutoId = Convert.ToInt32(AutoId); if (bll.Update(model)) { rsp.code = "success"; rsp.msg = "修改成功"; } } else { DataTable dt = bll.GetList(" top 1 CollCode", " 1=1 order by CollCode desc").Tables[0]; if (dt != null && dt.Rows.Count > 0) { string Code = dt.Rows[0]["CollCode"].ToString(); model.CollCode = (int.Parse(Code) + 1).ToString("0000"); } else { model.CollCode = "0001"; } if (bll.Add(model) != 0) { rsp.code = "success"; rsp.msg = "添加成功"; } } } catch (Exception ex) { rsp.code = "error"; rsp.msg = ex.Message; } } return(rsp); }
/// <summary> /// 得到一个对象实体 /// </summary> public SchSystem.Model.SysColl DataRowToModel(DataRow row) { SchSystem.Model.SysColl model = new SchSystem.Model.SysColl(); if (row != null) { if (row["AutoId"] != null && row["AutoId"].ToString() != "") { model.AutoId = int.Parse(row["AutoId"].ToString()); } if (row["CollName"] != null) { model.CollName = row["CollName"].ToString(); } if (row["CollCode"] != null) { model.CollCode = row["CollCode"].ToString(); } if (row["Stat"] != null && row["Stat"].ToString() != "") { model.Stat = int.Parse(row["Stat"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public SchSystem.Model.SysColl GetModel(int AutoId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 AutoId,CollName,CollCode,Stat from SysColl "); strSql.Append(" where AutoId=@AutoId"); SqlParameter[] parameters = { new SqlParameter("@AutoId", SqlDbType.Int, 4) }; parameters[0].Value = AutoId; SchSystem.Model.SysColl model = new SchSystem.Model.SysColl(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }