/// <summary> /// 增加一条数据 /// </summary> public int Add(SchSystem.Model.SchSub model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into SchSub("); strSql.Append("SubName,SubCode,Stat,SchId,OrderId)"); strSql.Append(" values ("); strSql.Append("@SubName,@SubCode,@Stat,@SchId,@OrderId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@SubName", SqlDbType.VarChar, 10), new SqlParameter("@SubCode", SqlDbType.VarChar, 10), new SqlParameter("@Stat", SqlDbType.TinyInt, 1), new SqlParameter("@SchId", SqlDbType.Int, 4), new SqlParameter("@OrderId", SqlDbType.TinyInt, 1) }; parameters[0].Value = model.SubName; parameters[1].Value = model.SubCode; parameters[2].Value = model.Stat; parameters[3].Value = model.SchId; parameters[4].Value = model.OrderId; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SchSystem.Model.SchSub DataRowToModel(DataRow row) { SchSystem.Model.SchSub model = new SchSystem.Model.SchSub(); if (row != null) { if (row["SubId"] != null && row["SubId"].ToString() != "") { model.SubId = int.Parse(row["SubId"].ToString()); } if (row["SubName"] != null) { model.SubName = row["SubName"].ToString(); } if (row["SubCode"] != null) { model.SubCode = row["SubCode"].ToString(); } if (row["Stat"] != null && row["Stat"].ToString() != "") { model.Stat = int.Parse(row["Stat"].ToString()); } if (row["SchId"] != null && row["SchId"].ToString() != "") { model.SchId = int.Parse(row["SchId"].ToString()); } if (row["OrderId"] != null && row["OrderId"].ToString() != "") { model.OrderId = int.Parse(row["OrderId"].ToString()); } } return(model); }
public SchSystem.Model.SchSub GetModelSubs(string SubId, string schid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select SubId,sysSub.SubName,SchSub.SubCode,SchSub.Stat,SchId,OrderId from SchSub "); strSql.Append("left join SysSub on SchSub.SubCode=SysSub.SubCode"); strSql.Append(" where SchSub.SubCode=@SubId and SchSub.SchId=@schid and SchSub.Stat=1"); SqlParameter[] parameters = { new SqlParameter("@SubId", SqlDbType.Int, 4), new SqlParameter("@SchId", SqlDbType.Int, 6) }; parameters[0].Value = SubId; parameters[1].Value = schid; SchSystem.Model.SchSub model = new SchSystem.Model.SchSub(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SchSystem.Model.SchSub model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update SchSub set "); strSql.Append("SubName=@SubName,"); strSql.Append("SubCode=@SubCode,"); strSql.Append("Stat=@Stat,"); strSql.Append("SchId=@SchId,"); strSql.Append("OrderId=@OrderId"); strSql.Append(" where SubId=@SubId"); SqlParameter[] parameters = { new SqlParameter("@SubName", SqlDbType.VarChar, 10), new SqlParameter("@SubCode", SqlDbType.VarChar, 10), new SqlParameter("@Stat", SqlDbType.TinyInt, 1), new SqlParameter("@SchId", SqlDbType.Int, 4), new SqlParameter("@OrderId", SqlDbType.TinyInt, 1), new SqlParameter("@SubId", SqlDbType.Int, 4) }; parameters[0].Value = model.SubName; parameters[1].Value = model.SubCode; parameters[2].Value = model.Stat; parameters[3].Value = model.SchId; parameters[4].Value = model.OrderId; parameters[5].Value = model.SubId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SchSystem.Model.SchSub GetModel(int SubId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 SubId,SubName,SubCode,Stat,SchId,OrderId from SchSub "); strSql.Append(" where SubId=@SubId"); SqlParameter[] parameters = { new SqlParameter("@SubId", SqlDbType.Int, 4) }; parameters[0].Value = SubId; SchSystem.Model.SchSub model = new SchSystem.Model.SchSub(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
//需要根据不同情况建立或修改的不同学校用户和不同类型的用户,本学校用户唯一,不需要全系统唯一 protected void Page_Load(object sender, EventArgs e) { //if (true)//如果没对应权限,及判断用户类型是否跨界,主要防止非法篡改数据出现 //{ // Response.Write("无对应权限"); // Response.End(); //} if (!IsPostBack) { //不是超管获取本学校的 if (Com.Session.systype != "2") { schid = Com.Session.schid; systype = "0"; } else { schid = Request.Params["schid"].ToString(); if (string.IsNullOrEmpty(schid))//如果没有对应参数中任意一个 { Response.Write("学校ID为空或者添加的类型为空!"); Response.End(); } } SchSystem.BLL.SchSub ssBll = new SchSystem.BLL.SchSub(); //先得到操作类型 dotype = Com.Public.SqlEncStr(Request.Params["dotype"].ToString()); string subid = "0"; //修改时的用户ID string uname = ""; //修改时的用户账号 if (dotype == "e") //修改,不能修改用户的类型及学校参数 { btnname = "保存"; subid = Com.Public.SqlEncStr(Request.Params["subid"].ToString()); if (string.IsNullOrEmpty(subid)) { Response.Write("无对应修改的用户!"); Response.End(); } //获取修改的对应用户的 SchSystem.Model.SchSub ssModel = ssBll.GetModelSub(subid, schid); if (ssModel != null && ssModel.SubId > 0) { umodelstr = Newtonsoft.Json.JsonConvert.SerializeObject(ssModel); schid = ssModel.SchId.ToString(); } else { Response.Write("无该科目!"); Response.End(); } } else//不在添加及修改之内,则返回 { Response.Write("没有可供确认的操作类型!"); Response.End(); } //判断跨界操作的可能性 if (!Com.Public.isVa(schid, systype)) { Response.Write("出错,用户非法跨界操作!"); Response.End(); } #region SchSystem.BLL.SchInfo schbll = new SchSystem.BLL.SchInfo(); schname = schbll.GetSchName(int.Parse(schid)); SchSystem.BLL.SchDepartInfo sdiBll = new SchSystem.BLL.SchDepartInfo(); //获取部门列表 DataTable dtdpt = sdiBll.GetList("Pid pId,convert(varchar(20),DepartId) id,DepartName name,'false' checked,'true' nochecks", "SchId=" + schid + " and Stat=1 Order by OrderId").Tables[0]; dtdpt.Columns["nochecks"].ColumnName = "nocheck"; DataTable dtdptuser = dtdpt.Clone(); if (dtdpt.Rows.Count > 0) { //获取该年级组长 SchSystem.BLL.SchSubLeader sslBll = new SchSystem.BLL.SchSubLeader(); DataTable dtgradeuser = sslBll.GetList("UserName", "SubCode=" + subid).Tables[0]; //获取该学校的所有人员 SchSystem.BLL.SchUserDeptV userbll = new SchSystem.BLL.SchUserDeptV(); DataTable dtuser = userbll.GetList("DeptId ,UserId,UserTname", "Stat=1 and Ustat=1 and SchId=" + Com.Public.SqlEncStr(schid)).Tables[0]; //合并人员到部门表 for (int i = 0; i < dtdpt.Rows.Count; i++) { dtdptuser.Rows.Add(dtdpt.Rows[i].ItemArray); //获取该部门下的人员 DataRow[] drs = dtuser.Select("DeptId='" + dtdpt.Rows[i]["id"].ToString() + "'"); if (drs.Length > 0) { foreach (DataRow item in drs) { //如果是被绑定了,则勾选 DataRow[] drsgrade = dtgradeuser.Select("UserName='******'"); DataRow dr = dtdptuser.NewRow(); dr["id"] = "sub_" + item["UserId"].ToString(); dr["name"] = item["UserTname"].ToString(); dr["pId"] = item["DeptId"].ToString(); if (drsgrade.Length > 0) { dr["checked"] = "true"; } dtdptuser.Rows.Add(dr); } } } } depart = Newtonsoft.Json.JsonConvert.SerializeObject(dtdptuser); #endregion } }