public string ChangePassword(int t_id, string user_name, string oldpwd, string newpwd, string newpwd2) { user_name = WebUtility.InputText(user_name, 30); oldpwd = WebUtility.InputText(oldpwd, 16); newpwd = WebUtility.InputText(newpwd, 16); newpwd2 = WebUtility.InputText(newpwd2, 16); oldpwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(oldpwd, "MD5"), "MD5"); if (!Login(user_name, oldpwd)) { return("原始密码不正确。"); } if (newpwd != newpwd2) { return("两次输入密码不一致。"); } Model.teacher model = GetModel(t_id); if (model == null || model.Teacher_name != user_name) { return("教师信息获取失败或者被删除。"); } string pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(newpwd, "MD5"); pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5"); model.Teacher_password = pwd; if (Update(model)) { return("修改成功。"); } else { return("修改失败。"); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.teacher model) { using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { #region 修改主表数据========================== StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "teacher set "); strSql.Append("no=@no,name=@name,quota=@quota,email=@email,students=@students,resquota=@resquota,direction=@direction,major=@major,is_aca=@is_aca,is_pro=@is_pro,pro_quota=@pro_quota,pro_resquota=@pro_resquota "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@no", SqlDbType.NVarChar, 50), new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@quota", SqlDbType.NVarChar, 50), new SqlParameter("@email", SqlDbType.NVarChar, 50), new SqlParameter("@students", SqlDbType.NVarChar, 100), new SqlParameter("@resquota", SqlDbType.NVarChar, 50), new SqlParameter("@direction", SqlDbType.NVarChar, 50), new SqlParameter("@major", SqlDbType.NVarChar, 50), new SqlParameter("@is_aca", SqlDbType.NVarChar, 50), new SqlParameter("@is_pro", SqlDbType.NVarChar, 50), new SqlParameter("@pro_quota", SqlDbType.NVarChar, 50), new SqlParameter("@pro_resquota", SqlDbType.NVarChar, 50), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.no; parameters[1].Value = model.name; parameters[2].Value = model.quota; parameters[3].Value = model.email; parameters[4].Value = model.students; parameters[5].Value = model.resquota; parameters[6].Value = model.direction; parameters[7].Value = model.major; parameters[8].Value = model.is_aca; parameters[9].Value = model.is_pro; parameters[10].Value = model.pro_quota; parameters[11].Value = model.pro_resquota; parameters[12].Value = model.id; DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); #endregion trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }
//取消选择 protected void btnCalcel_Click(object sender, EventArgs e) { BLL.teacher bll = new BLL.teacher(); Model.teacher model = bll.GetModel(this.id); var selectList = new List <int>(); var unSelectList = new List <int>(); StringBuilder tempStr = new StringBuilder(); for (int i = 0; i < rptList2.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList2.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList2.Items[i].FindControl("chkId"); if (cb.Checked) { selectList.Add(id); } else { unSelectList.Add(id); tempStr.Append(id + ","); } } if (selectList.Count == 0) { JscriptMsg("请选择研究生!", string.Empty); return; } model.students = Utils.DelLastComma(tempStr.ToString()); foreach (var item in selectList) { BLL.student studentBll = new BLL.student(); Model.student studentModel = studentBll.GetModel(Utils.ObjToInt(item)); //学术型研究生 if (studentModel.is_aca == "1") { model.resquota = (Utils.ObjToInt(model.resquota) + 1).ToString(); } else { model.pro_resquota = (Utils.ObjToInt(model.pro_resquota) + 1).ToString(); } studentModel.status = "导师未通过您的申请,请再次操作选择其他导师"; studentBll.Update(studentModel); } if (!bll.Update(model)) { JscriptMsg("保存过程中发生错误啦!", string.Empty); return; } JscriptMsg("取消选择研究生成功!", Utils.CombUrlTxt("teacher_list.aspx", "keywords={0}&property={1}", this.keywords, this.property)); }
private bool DoAdd() { bool result = false; Model.teacher model = new Model.teacher(); BLL.teacher bll = new BLL.teacher(); model.no = txtNo.Text.Trim(); model.name = txtName.Text.Trim(); model.quota = txtQuota.Text.Trim(); model.email = txtEmail.Text.Trim(); model.direction = txtDirection.Text.Trim(); model.major = txtMajor.Text.Trim(); model.add_time = Utils.StrToDateTime(txtAddTime.Text.Trim()); model.is_aca = Utils.ObjectToStr(rblIsAca.SelectedValue); model.is_pro = Utils.ObjectToStr(rblIsPro.SelectedValue); model.pro_quota = txtProQuota.Text.Trim();; model.resquota = model.quota; model.pro_resquota = model.pro_quota; //该导师已经存在 if (bll.Exists(model.no)) { JscriptMsg("工号不能重复!", string.Empty); return(result); } if (bll.Add(model) > 0) { Model.manager manModel = new Model.manager(); BLL.manager manBll = new BLL.manager(); //不存在用户则进行提前加 if (!manBll.Exists(model.no)) { manModel.role_id = 3; manModel.role_type = new BLL.manager_role().GetModel(manModel.role_id).role_type; manModel.is_lock = 0; manModel.user_name = model.no; manModel.real_name = model.name; //获得6位的salt加密字符串 manModel.salt = Utils.GetCheckCode(6); //以随机生成的6位字符串做为密钥加密 manModel.password = DESEncrypt.Encrypt(model.no + "123", manModel.salt); manModel.real_name = model.name; manModel.add_time = DateTime.Now; manBll.Add(manModel); } AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加导师" + model.name); //记录日志 result = true; } return(result); }
private void ShowInfo(int _id) { BLL.teacher bll = new BLL.teacher(); Model.teacher model = bll.GetModel(_id); txtNo.Text = model.no; txtName.Text = model.name; txtQuota.Text = model.quota; txtEmail.Text = model.email; txtDirection.Text = model.direction; txtMajor.Text = model.major; txtAddTime.Text = model.add_time.ToString("yyyy-MM-dd HH:mm:ss"); rblIsAca.SelectedValue = model.is_aca.ToString(); rblIsPro.SelectedValue = model.is_pro.ToString(); txtProQuota.Text = model.pro_quota; }
private void ShowInfo(int teacher_id) { BLL.teacher bll = new BLL.teacher(); model = bll.GetModel(teacher_id); adminModel = GetAdminInfo(); this.rptList.DataSource = bll.GetList(0, "id=" + teacher_id, " name "); this.rptList.DataBind(); BLL.student studentBll = new BLL.student(); var students = bll.GetStudentIds(teacher_id); var strWhere = ""; if (!string.IsNullOrEmpty(students)) { strWhere = " id in(select * from dbo.f_split((select students from dt_teacher where id=" + teacher_id + "),','))"; this.rptList1.DataSource = studentBll.GetList(0, strWhere, "name asc"); this.rptList1.DataBind(); } }
protected void btnImport_Click(object sender, EventArgs e) { StringBuilder errorMsg = new StringBuilder(); // 错误信息 try { #region 1.获取Excel文件并转换为一个List集合 // 1.1存放Excel文件到本地服务器 string filePath = Server.MapPath(txtImgUrl.Text.Trim()); // 保存文件并获取文件路径 // 单元格抬头 // key:实体对象属性名称,可通过反射获取值 // value:属性对应的中文注解 Dictionary <string, string> cellheader = new Dictionary <string, string> { { "No", "导师工号" }, { "Name", "姓名" }, { "IsAca", "是否为学术型导师" }, { "Quota", "学硕分配指标" }, { "IsPro", "是否为专业性导师" }, { "ProQuota", "专硕分配指标" }, { "Email", "邮箱" }, { "Direction", "研究方向" }, { "Major", "专业" }, { "Password", "密码" }, }; // 1.2解析文件,存放到一个List集合里 List <TeacherEntity> enlist = ExcelHelper.ExcelToEntityList <TeacherEntity>(cellheader, filePath, out errorMsg); #endregion var sucCount = 0; for (int i = 0; i < enlist.Count; i++) { TeacherEntity en = enlist[i]; string errorMsgStr = "第" + (i + 1) + "行数据检测异常:"; //未填写研究生编号 if (string.IsNullOrWhiteSpace(en.No)) { continue; } Model.teacher model = new Model.teacher(); BLL.teacher bll = new BLL.teacher(); //该研究生已经存在 if (bll.Exists(en.No)) { continue; } model.no = en.No; model.name = en.Name; model.quota = en.Quota; model.resquota = en.Quota; model.email = en.Email; model.direction = en.Direction; model.major = en.Major; model.is_aca = en.IsAca; model.is_pro = en.IsPro; model.pro_quota = en.ProQuota; model.pro_resquota = en.ProQuota; model.add_time = DateTime.Now; bll.Add(model); sucCount++; Model.manager manModel = new Model.manager(); BLL.manager manBll = new BLL.manager(); //该用户已经存在 if (manBll.Exists(en.No)) { continue; } manModel.role_id = 3; manModel.role_type = new BLL.manager_role().GetModel(manModel.role_id).role_type; manModel.is_lock = 0; manModel.user_name = en.No; manModel.real_name = en.Name; //获得6位的salt加密字符串 manModel.salt = Utils.GetCheckCode(6); //以随机生成的6位字符串做为密钥加密 manModel.password = DESEncrypt.Encrypt(en.Password, manModel.salt); manModel.real_name = en.Name; manModel.add_time = DateTime.Now; manBll.Add(manModel); } //context.Response.Write("{\"status\": 1, \"msg\": \"导入成功!\"}"); JscriptMsg("导入成功" + sucCount + "条", Utils.CombUrlTxt("teacher_list.aspx", "keywords={0}&property={1}", this.keywords, this.property)); } catch (Exception ex) { throw ex; } }
private bool DoEdit(int _id) { bool result = false; BLL.teacher bll = new BLL.teacher(); Model.teacher model = bll.GetModel(_id); model.no = txtNo.Text.Trim(); model.name = txtName.Text.Trim(); model.email = txtEmail.Text.Trim(); model.direction = txtDirection.Text.Trim(); model.major = txtMajor.Text.Trim(); model.add_time = Utils.StrToDateTime(txtAddTime.Text.Trim()); model.is_aca = Utils.ObjectToStr(rblIsAca.SelectedValue); model.is_pro = Utils.ObjectToStr(rblIsPro.SelectedValue); var quota = txtQuota.Text.Trim(); //如果增加导师指标,则对应增加剩余指标 if (Utils.ObjToInt(quota) != Utils.ObjToInt(model.quota)) { if (model.is_aca == "0") { JscriptMsg("该导师不是学术型导师,无法修改学硕指标!", string.Empty); return(false); } if (Utils.ObjToInt(quota) > Utils.ObjToInt(model.quota)) { //增加指标数 var addQuota = Utils.ObjToInt(quota) - Utils.ObjToInt(model.quota); model.resquota = Utils.ObjectToStr(Utils.ObjToInt(model.resquota) + addQuota); model.quota = quota; } else { //减少指标数 var resQuota = Utils.ObjToInt(model.quota) - Utils.ObjToInt(quota); var resquota = Utils.ObjToInt(model.resquota) - resQuota; if (resquota < 0) { JscriptMsg("由于您是减少指标,请先取消相应研究生的选择以确保指标正常!", string.Empty); return(false); } model.resquota = Utils.ObjectToStr(resquota); model.quota = quota; } } var proQuota = txtProQuota.Text.Trim(); //如果增加导师指标,则对应增加剩余指标 if (Utils.ObjToInt(proQuota) != Utils.ObjToInt(model.pro_quota)) { if (model.is_pro == "0") { JscriptMsg("该导师不是专业型导师,无法修改专硕指标!", string.Empty); return(false); } if (Utils.ObjToInt(proQuota) > Utils.ObjToInt(model.pro_quota)) { //增加指标数 var addQuota = Utils.ObjToInt(proQuota) - Utils.ObjToInt(model.pro_quota); model.pro_resquota = Utils.ObjectToStr(Utils.ObjToInt(model.pro_resquota) + addQuota); model.pro_quota = proQuota; } else { //减少指标数 var resQuota = Utils.ObjToInt(model.pro_quota) - Utils.ObjToInt(proQuota); var resquota = Utils.ObjToInt(model.pro_resquota) - resQuota; if (resquota < 0) { JscriptMsg("由于您是减少指标,请先取消相应研究生的选择以确保指标正常!", string.Empty); return(false); } model.pro_resquota = Utils.ObjectToStr(resquota); model.pro_quota = proQuota; } } if (bll.Update(model)) { AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改导师" + model.name); //记录日志 result = true; } return(result); }
/// <summary> /// 将对象转换为实体 /// </summary> private Model.teacher DataRowToModel(DataRow row) { Model.teacher model = new Model.teacher(); if (row != null) { #region 主表信息====================== if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["no"] != null) { model.no = row["no"].ToString(); } if (row["name"] != null) { model.name = row["name"].ToString(); } if (row["quota"] != null) { model.quota = row["quota"].ToString(); } if (row["resquota"] != null) { model.resquota = row["resquota"].ToString(); } if (row["email"] != null) { model.email = row["email"].ToString(); } if (row["add_time"] != null && row["add_time"].ToString() != "") { model.add_time = DateTime.Parse(row["add_time"].ToString()); } if (row["students"] != null) { model.students = row["students"].ToString(); } if (row["direction"] != null) { model.direction = row["direction"].ToString(); } if (row["major"] != null) { model.major = row["major"].ToString(); } if (row["is_aca"] != null) { model.is_aca = row["is_aca"].ToString(); } if (row["is_pro"] != null) { model.is_pro = row["is_pro"].ToString(); } if (row["pro_quota"] != null) { model.pro_quota = row["pro_quota"].ToString(); } if (row["pro_resquota"] != null) { model.pro_resquota = row["pro_resquota"].ToString(); } #endregion } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.teacher model) { using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { #region 添加主表数据==================== StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "teacher("); strSql.Append("no,name,quota,email,add_time,students,resquota,direction,major,is_aca,is_pro,pro_quota,pro_resquota)"); strSql.Append(" values ("); strSql.Append("@no,@name,@quota,@email,@add_time,@students,@resquota,@direction,@major,@is_aca,@is_pro,@pro_quota,@pro_resquota)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@no", SqlDbType.NVarChar, 50), new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@quota", SqlDbType.NVarChar, 50), new SqlParameter("@email", SqlDbType.NVarChar, 50), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@students", SqlDbType.NVarChar, 100), new SqlParameter("@resquota", SqlDbType.NVarChar, 100), new SqlParameter("@direction", SqlDbType.NVarChar, 50), new SqlParameter("@major", SqlDbType.NVarChar, 50), new SqlParameter("@is_aca", SqlDbType.NVarChar, 50), new SqlParameter("@is_pro", SqlDbType.NVarChar, 50), new SqlParameter("@pro_quota", SqlDbType.NVarChar, 50), new SqlParameter("@pro_resquota", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.no; parameters[1].Value = model.name; parameters[2].Value = model.quota; parameters[3].Value = model.email; parameters[4].Value = model.add_time; parameters[5].Value = model.students; parameters[6].Value = model.resquota; parameters[7].Value = model.direction; parameters[8].Value = model.major; parameters[9].Value = model.is_aca; parameters[10].Value = model.is_pro; parameters[11].Value = model.pro_quota; parameters[12].Value = model.pro_resquota; //添加主表数据 object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务 model.id = Convert.ToInt32(obj); #endregion trans.Commit(); } catch { trans.Rollback(); return(0); } } } return(model.id); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.teacher model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.teacher model) { return(dal.Add(model)); }
//保存 protected void btnSubmit_Click(object sender, EventArgs e) { if (action == DTEnums.ActionEnum.Edit.ToString()) //修改 { int sucCount = 0; //成功数量 int errorCount = 0; //失败数量 BLL.teacher bll = new BLL.teacher(); Model.teacher model = bll.GetModel(this.id); if (Utils.ObjToInt(model.resquota) == 0 && Utils.ObjToInt(model.pro_resquota) == 0) { JscriptMsg("您的名额已满!", string.Empty); return; } var selectList = new List <int>(); var unSelectList = new List <int>(); StringBuilder tempStr = new StringBuilder(); for (int i = 0; i < rptList1.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList1.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList1.Items[i].FindControl("chkId"); if (cb.Checked) { selectList.Add(id); tempStr.Append(id + ","); } else { unSelectList.Add(id); } } if (selectList.Count == 0) { JscriptMsg("请选择研究生!", string.Empty); return; } if (selectList.Count > Utils.ObjToInt(model.resquota) + Utils.ObjToInt(model.pro_resquota)) { JscriptMsg("您选中学生过多,超出的您的配额!", string.Empty); btnCancel.Visible = false; return; } model.students = string.IsNullOrEmpty(model.students) ? Utils.DelLastComma(tempStr.ToString()) : model.students + "," + Utils.DelLastComma(tempStr.ToString()); var xsQuota = 0; var zsQuota = 0; foreach (var item in selectList) { BLL.student studentBll = new BLL.student(); Model.student studentModel = studentBll.GetModel(Utils.ObjToInt(item)); //学术型研究生 if (studentModel.is_aca == "1") { xsQuota++; } else { zsQuota++; } } if (xsQuota > Utils.StrToInt(model.resquota, 0)) { JscriptMsg("您选中学生过多,超出的您您的学硕配额!", string.Empty); btnCancel.Visible = false; return; } if (zsQuota > Utils.StrToInt(model.pro_resquota, 0)) { JscriptMsg("您选中学生过多,超出的您您的专硕配额!", string.Empty); btnCancel.Visible = false; return; } foreach (var item in selectList) { BLL.student studentBll = new BLL.student(); Model.student studentModel = studentBll.GetModel(Utils.ObjToInt(item)); //学术型研究生 if (studentModel.is_aca == "1") { model.resquota = (Utils.ObjToInt(model.resquota) - 1).ToString(); } else { model.pro_resquota = (Utils.ObjToInt(model.pro_resquota) - 1).ToString(); } studentModel.status = "导师已通过您的申请"; if (studentBll.Update(studentModel)) { sucCount++; } else { errorCount++; } } foreach (var item in unSelectList) { BLL.student studentBll = new BLL.student(); Model.student studentModel = studentBll.GetModel(Utils.ObjToInt(item)); studentModel.status = "导师未通过您的申请,请再次操作选择其他导师"; studentBll.Update(studentModel); } if (!bll.Update(model)) { JscriptMsg("保存过程中发生错误啦!", string.Empty); return; } JscriptMsg("选择研究生成功!", Utils.CombUrlTxt("teacher_list.aspx", "keywords={0}&property={1}", this.keywords, this.property)); } }