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.SysSub SysSub_bll = new SchSystem.BLL.SysSub(); SchSystem.Model.SysSub SysSub_model = new SchSystem.Model.SysSub(); SysSub_model.SubName = Com.Public.SqlEncStr(Name).ToString(); SysSub_model.Stat = Convert.ToInt32(Com.Public.SqlEncStr(stat)); if (AutoId != "") { SysSub_model.AutoId = Convert.ToInt32(AutoId); if (SysSub_bll.Update(SysSub_model)) { rsp.code = "success"; rsp.msg = "修改成功"; } } else { DataTable dt = SysSub_bll.GetList("top 1 SubCode", " 1=1 order by SubCode DESC").Tables[0]; if (dt != null && dt.Rows.Count > 0) { string Code = dt.Rows[0]["SubCode"].ToString(); int scode = int.Parse(Code) + 1; if (scode < 100) { SysSub_model.SubCode = (int.Parse(Code) + 1).ToString("00"); } else { SysSub_model.SubCode = (int.Parse(Code) + 1).ToString("0000"); } } else { SysSub_model.SubCode = "01"; } if (SysSub_bll.Add(SysSub_model) != 0) { rsp.code = "success"; rsp.msg = "添加成功"; } } } catch (Exception ex) { rsp.code = "error"; rsp.msg = ex.Message; } } return(rsp); }
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.SysSub bll = new SchSystem.BLL.SysSub(); SchSystem.Model.SysSub model = bll.GetModel(int.Parse(id)); if (model != null && model.AutoId > 0) { code = model.SubCode; name = model.SubName; stat = model.Stat.ToString(); } else { Response.Write("无该名称!"); Response.End(); } } else//不在添加及修改之内,则返回 { } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SchSystem.Model.SysSub model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update SysSub set "); strSql.Append("SubName=@SubName,"); strSql.Append("Stat=@Stat"); strSql.Append(" where AutoId=@AutoId"); SqlParameter[] parameters = { new SqlParameter("@SubName", SqlDbType.NVarChar, 20), new SqlParameter("@Stat", SqlDbType.TinyInt, 1), new SqlParameter("@AutoId", SqlDbType.Int, 4) }; parameters[0].Value = model.SubName; parameters[1].Value = model.Stat; parameters[2].Value = model.AutoId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); DbHelperSQL.ExecuteSql("update SchSub set SubName=b.SubName from SchSub a,SysSub b where a.SubCode=b.SubCode and a.SubName<>b.SubName"); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SchSystem.Model.SysSub model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into SysSub("); strSql.Append("SubCode,SubName,Stat)"); strSql.Append(" values ("); strSql.Append("@SubCode,@SubName,@Stat)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@SubCode", SqlDbType.VarChar, 10), new SqlParameter("@SubName", SqlDbType.NVarChar, 20), new SqlParameter("@Stat", SqlDbType.TinyInt, 1) }; parameters[0].Value = model.SubCode; parameters[1].Value = model.SubName; parameters[2].Value = model.Stat; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SchSystem.Model.SysSub DataRowToModel(DataRow row) { SchSystem.Model.SysSub model = new SchSystem.Model.SysSub(); if (row != null) { if (row["AutoId"] != null && row["AutoId"].ToString() != "") { model.AutoId = int.Parse(row["AutoId"].ToString()); } if (row["SubCode"] != null) { model.SubCode = row["SubCode"].ToString(); } if (row["SubName"] != null) { model.SubName = row["SubName"].ToString(); } if (row["Stat"] != null && row["Stat"].ToString() != "") { model.Stat = int.Parse(row["Stat"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public SchSystem.Model.SysSub GetModel(int AutoId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 AutoId,SubCode,SubName,Stat from SysSub "); strSql.Append(" where AutoId=@AutoId"); SqlParameter[] parameters = { new SqlParameter("@AutoId", SqlDbType.Int, 4) }; parameters[0].Value = AutoId; SchSystem.Model.SysSub model = new SchSystem.Model.SysSub(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }