/// <summary> /// 更新一条数据 /// </summary> public bool Update(SchSystem.Model.SchClassUser model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update SchClassUser set "); strSql.Append("ClassId=@ClassId,"); strSql.Append("SubCode=@SubCode,"); strSql.Append("UserName=@UserName,"); strSql.Append("UserTname=@UserTname,"); strSql.Append("IsMs=@IsMs,"); strSql.Append("RecTime=@RecTime,"); strSql.Append("RecUser=@RecUser,"); strSql.Append("LastRecTime=@LastRecTime,"); strSql.Append("LastRecUser=@LastRecUser"); strSql.Append(" where AutoId=@AutoId"); SqlParameter[] parameters = { new SqlParameter("@ClassId", SqlDbType.Int, 4), new SqlParameter("@SubCode", SqlDbType.VarChar, 10), new SqlParameter("@UserName", SqlDbType.VarChar, 50), new SqlParameter("@UserTname", SqlDbType.NVarChar, 50), new SqlParameter("@IsMs", SqlDbType.TinyInt, 1), new SqlParameter("@RecTime", SqlDbType.DateTime), new SqlParameter("@RecUser", SqlDbType.VarChar, 50), new SqlParameter("@LastRecTime", SqlDbType.DateTime), new SqlParameter("@LastRecUser", SqlDbType.VarChar, 20), new SqlParameter("@AutoId", SqlDbType.Int, 4) }; parameters[0].Value = model.ClassId; parameters[1].Value = model.SubCode; parameters[2].Value = model.UserName; parameters[3].Value = model.UserTname; parameters[4].Value = model.IsMs; parameters[5].Value = model.RecTime; parameters[6].Value = model.RecUser; parameters[7].Value = model.LastRecTime; parameters[8].Value = model.LastRecUser; parameters[9].Value = model.AutoId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SchSystem.Model.SchClassUser DataRowToModel(DataRow row) { SchSystem.Model.SchClassUser model = new SchSystem.Model.SchClassUser(); if (row != null) { if (row["AutoId"] != null && row["AutoId"].ToString() != "") { model.AutoId = int.Parse(row["AutoId"].ToString()); } if (row["ClassId"] != null && row["ClassId"].ToString() != "") { model.ClassId = int.Parse(row["ClassId"].ToString()); } if (row["SubCode"] != null) { model.SubCode = row["SubCode"].ToString(); } if (row["UserName"] != null) { model.UserName = row["UserName"].ToString(); } if (row["UserTname"] != null) { model.UserTname = row["UserTname"].ToString(); } if (row["IsMs"] != null && row["IsMs"].ToString() != "") { model.IsMs = int.Parse(row["IsMs"].ToString()); } if (row["RecTime"] != null && row["RecTime"].ToString() != "") { model.RecTime = DateTime.Parse(row["RecTime"].ToString()); } if (row["RecUser"] != null) { model.RecUser = row["RecUser"].ToString(); } if (row["LastRecTime"] != null && row["LastRecTime"].ToString() != "") { model.LastRecTime = DateTime.Parse(row["LastRecTime"].ToString()); } if (row["LastRecUser"] != null) { model.LastRecUser = row["LastRecUser"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SchSystem.Model.SchClassUser model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into SchClassUser("); strSql.Append("ClassId,SubCode,UserName,UserTname,IsMs,RecTime,RecUser,LastRecTime,LastRecUser,SchId)"); strSql.Append(" values ("); strSql.Append("@ClassId,@SubCode,@UserName,@UserTname,@IsMs,@RecTime,@RecUser,@LastRecTime,@LastRecUser,@SchId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ClassId", SqlDbType.Int, 4), new SqlParameter("@SubCode", SqlDbType.VarChar, 10), new SqlParameter("@UserName", SqlDbType.VarChar, 50), new SqlParameter("@UserTname", SqlDbType.NVarChar, 50), new SqlParameter("@IsMs", SqlDbType.TinyInt, 1), new SqlParameter("@RecTime", SqlDbType.DateTime), new SqlParameter("@RecUser", SqlDbType.VarChar, 50), new SqlParameter("@LastRecTime", SqlDbType.DateTime), new SqlParameter("@LastRecUser", SqlDbType.VarChar, 20), new SqlParameter("@SchId", SqlDbType.Int, 4) }; parameters[0].Value = model.ClassId; parameters[1].Value = model.SubCode; parameters[2].Value = model.UserName; parameters[3].Value = model.UserTname; parameters[4].Value = model.IsMs; parameters[5].Value = model.RecTime; parameters[6].Value = model.RecUser; parameters[7].Value = model.LastRecTime; parameters[8].Value = model.LastRecUser; parameters[9].Value = model.SchId; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SchSystem.Model.SchClassUser GetModel(int AutoId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 AutoId,ClassId,SubCode,UserName,UserTname,IsMs,RecTime,RecUser,LastRecTime,LastRecUser from SchClassUser "); strSql.Append(" where AutoId=@AutoId"); SqlParameter[] parameters = { new SqlParameter("@AutoId", SqlDbType.Int, 4) }; parameters[0].Value = AutoId; SchSystem.Model.SchClassUser model = new SchSystem.Model.SchClassUser(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public static string classsave(string dotype, string schid, string gradecode, string classid, string classname, string tagsusers) { dotype = Com.Public.SqlEncStr(dotype); schid = Com.Public.SqlEncStr(schid); gradecode = Com.Public.SqlEncStr(gradecode); classid = Com.Public.SqlEncStr(classid); classname = Com.Public.SqlEncStr(classname); tagsusers = Com.Public.SqlEncStr(tagsusers); string ret = ""; if (Com.Session.userid == null) { ret = "expire"; } else { //字符串匹配验证 string PatternStr = @"^[0-9a-zA-Z\u4e00-\u9fa5]+$"; bool resultStr = Regex.IsMatch(classname, PatternStr); if (resultStr != true) { return(ret = "必填,只能输入中文、数字和字母"); } try { if (!Com.Public.isVa(schid, "")) { return(ret = "无跨界权限"); } if (schid == Com.Public.getKey("adminschid")) { ret = "此为系统学校,不允许操作"; } else if (string.IsNullOrEmpty(schid) || schid == "0") { ret += "非法的学校!"; } //SchSystem.BLL.SchClassInfo classbll = new SchSystem.BLL.SchClassInfo(); //SchSystem.Model.SchClassInfo classmodel = new SchSystem.Model.SchClassInfo(); //classmodel.LastRecTime = DateTime.Now; //classmodel.LastRecUser = Com.Session.userid; //classmodel.GradeId = gradecode; //classmodel.ClassName = classname; //判断编号及账号是否有重复,生成密码加密 if (dotype == "e") { /*if (userbll.ExistsUserCode(int.Parse(userid), usercode, int.Parse(schid))) * { * ret += "用户编号重复!"; * }*/ } if (dotype == "a") { /*if (userbll.ExistsUserCode(0, usercode, int.Parse(schid))) * { * ret += "用户编号重复!"; * } * if (userbll.ExistsUserCode(0, username, int.Parse(schid))) * { * ret += "账号重复!"; * }*/ } if (ret == "") { //if (dotype == "e") //{ // classmodel.ClassId = int.Parse(classid); // classbll.Update(classmodel); //} //if (dotype == "a") //{ // //usermodel.PassWord = SchManagerInfoSystem.Common.DESEncrypt.Encrypt(userpw); // classmodel.RecTime = DateTime.Now; // classmodel.RecUser = Com.Session.userid; // classmodel.IsFinish = 0; // classmodel.SchId = int.Parse(schid); // classid = classbll.Add(classmodel).ToString(); //} //清除关联的老师,再添加或更新关联老师 SchSystem.BLL.SchClassUser classuserbll = new SchSystem.BLL.SchClassUser(); SchSystem.Model.SchClassUser classusermodel; classuserbll.DeleteUserSub("ClassId=" + Com.Public.SqlEncStr(classid)); tagsusers = tagsusers.Replace("u_", "");//UID,UTNAME,SUB,ISMS string[] uss = tagsusers.Split('|'); if (uss.Length > 0) { foreach (string item in uss) { string[] its = item.Split(','); if (its.Length == 4) { if (its[0] != "") { classusermodel = new SchSystem.Model.SchClassUser(); classusermodel.ClassId = int.Parse(classid); classusermodel.LastRecTime = DateTime.Now; classusermodel.SchId = int.Parse(schid); classusermodel.LastRecUser = Com.Session.userid; classusermodel.RecTime = DateTime.Now; classusermodel.RecUser = Com.Session.userid; classusermodel.UserName = its[0]; classusermodel.SubCode = its[1]; classusermodel.UserTname = its[2]; classusermodel.IsMs = int.Parse(its[3]); classuserbll.Add(classusermodel); } } } } ret = "success"; } } catch (Exception ex) { ret = ex.Message; } } return(ret); }
public static string classsave(string dotype, string schid, string gradecode, string classid, string classname, string tagsusers) { dotype = Com.Public.SqlEncStr(dotype); schid = Com.Public.SqlEncStr(schid); gradecode = Com.Public.SqlEncStr(gradecode); classid = Com.Public.SqlEncStr(classid); classname = Com.Public.SqlEncStr(classname); tagsusers = Com.Public.SqlEncStr(tagsusers); /* * //手机号码验证 * string PatternPhone = @"^(?:13|15\d|15[89])-?\d{5}(\d{3}|\*{3})$"; * bool ResultPhone = Regex.IsMatch(classname, PatternPhone); * if (ResultPhone != true) * { * return "手机号码(格式:15153585510)或固定电话(格式:0531-1234678)格式不正确"; * } */ //字符串匹配验证 string PatternStr = @"^[\u4e00-\u9fa5]+$"; bool resultStr = Regex.IsMatch(classname, PatternStr); if (resultStr != true) { return("只能输入中文名称"); } string ret = ""; try { if (!Com.Public.IsOne(Com.Session.userrolestr, 12)) { return(ret = "无操作权限"); } if (!Com.Public.isVa(schid, "")) { return(ret = "无跨界权限"); } if (schid == Com.Public.getKey("adminschid")) { ret = "此为系统学校,不允许操作"; } else if (string.IsNullOrEmpty(schid) || schid == "0") { ret += "非法的学校!"; } SchSystem.BLL.SchClassInfo classbll = new SchSystem.BLL.SchClassInfo(); SchSystem.Model.SchClassInfo classmodel = new SchSystem.Model.SchClassInfo(); classmodel.LastRecTime = DateTime.Now; classmodel.LastRecUser = Com.Session.userid; classmodel.GradeCode = gradecode; classmodel.ClassName = classname; //判断编号及账号是否有重复,生成密码加密 if (dotype == "e") { /*if (userbll.ExistsUserCode(int.Parse(userid), usercode, int.Parse(schid))) * { * ret += "用户编号重复!"; * }*/ } if (dotype == "a") { /*if (userbll.ExistsUserCode(0, usercode, int.Parse(schid))) * { * ret += "用户编号重复!"; * } * if (userbll.ExistsUserCode(0, username, int.Parse(schid))) * { * ret += "账号重复!"; * }*/ } if (ret == "") { if (dotype == "e") { classmodel.ClassId = int.Parse(classid); classbll.Update(classmodel); } if (dotype == "a") { //usermodel.PassWord = SchManagerInfoSystem.Common.DESEncrypt.Encrypt(userpw); classmodel.RecTime = DateTime.Now; classmodel.RecUser = Com.Session.userid; classmodel.IsFinish = 0; classmodel.SchId = int.Parse(schid); classid = classbll.Add(classmodel).ToString(); } //清除关联的老师,再添加或更新关联老师 SchSystem.BLL.SchClassUser classuserbll = new SchSystem.BLL.SchClassUser(); SchSystem.Model.SchClassUser classusermodel; classuserbll.DeleteUserSub("ClassId=" + Com.Public.SqlEncStr(classid)); tagsusers = tagsusers.Replace("u_", "");//UID,UTNAME,SUB,ISMS string[] uss = tagsusers.Split('|'); if (uss.Length > 0) { foreach (string item in uss) { string[] its = item.Split(','); if (its.Length == 4) { classusermodel = new SchSystem.Model.SchClassUser(); classusermodel.ClassId = int.Parse(classid); classusermodel.IsMs = int.Parse(its[3]); classusermodel.LastRecTime = DateTime.Now; classusermodel.LastRecUser = Com.Session.userid; classusermodel.RecTime = DateTime.Now; classusermodel.RecUser = Com.Session.userid; classusermodel.UserName = its[0]; classusermodel.UserTname = its[1]; classusermodel.SubCode = its[2]; classusermodel.SchId = int.Parse(schid); classuserbll.Add(classusermodel); } } } ret = "success"; } } catch (Exception ex) { ret = ex.Message; } return(ret); }