//取消选择 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)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.student 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 + "student("); strSql.Append("no,name,school,score,re_score,add_time,teacher_id,status,is_aca,attach)"); strSql.Append(" values ("); strSql.Append("@no,@name,@school,@score,@re_score,@add_time,@teacher_id,@status,@is_aca,@attach)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@no", SqlDbType.NVarChar, 50), new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@school", SqlDbType.NVarChar, 50), new SqlParameter("@score", SqlDbType.NVarChar, 50), new SqlParameter("@re_score", SqlDbType.NVarChar, 50), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@teacher_id", SqlDbType.Int, 4), new SqlParameter("@status", SqlDbType.NVarChar, 50), new SqlParameter("@is_aca", SqlDbType.NVarChar, 50), new SqlParameter("@attach", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.no; parameters[1].Value = model.name; parameters[2].Value = model.school; parameters[3].Value = model.score; parameters[4].Value = model.re_score; parameters[5].Value = model.add_time; parameters[6].Value = model.teacher_id; parameters[7].Value = model.status; parameters[8].Value = model.is_aca; parameters[9].Value = model.attach; //添加主表数据 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> private Model.student DataRowToModel(DataRow row) { Model.student model = new Model.student(); 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["school"] != null) { model.school = row["school"].ToString(); } if (row["score"] != null) { model.score = row["score"].ToString(); } if (row["name"] != null) { model.re_score = row["re_score"].ToString(); } if (row["teacher_id"] != null && row["teacher_id"].ToString() != "") { model.teacher_id = int.Parse(row["teacher_id"].ToString()); } if (row["status"] != null) { model.status = row["status"].ToString(); } if (row["is_aca"] != null) { model.is_aca = row["is_aca"].ToString(); } if (row["attach"] != null) { model.attach = row["attach"].ToString(); } if (row["add_time"] != null && row["add_time"].ToString() != "") { model.add_time = DateTime.Parse(row["add_time"].ToString()); } #endregion } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.student 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 + "student set "); strSql.Append("no=@no,name=@name,school=@school,score=@score,re_score=@re_score,teacher_id=@teacher_id,status=@status,is_aca=@is_aca,attach=@attach "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@no", SqlDbType.NVarChar, 50), new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@school", SqlDbType.NVarChar, 50), new SqlParameter("@score", SqlDbType.NVarChar, 50), new SqlParameter("@re_score", SqlDbType.NVarChar, 50), new SqlParameter("@teacher_id", SqlDbType.Int, 4), new SqlParameter("@status", SqlDbType.NVarChar, 50), new SqlParameter("@is_aca", SqlDbType.NVarChar, 50), new SqlParameter("@attach", SqlDbType.NVarChar, 50), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.no; parameters[1].Value = model.name; parameters[2].Value = model.school; parameters[3].Value = model.score; parameters[4].Value = model.re_score; parameters[5].Value = model.teacher_id; parameters[6].Value = model.status; parameters[7].Value = model.is_aca; parameters[8].Value = model.attach; parameters[9].Value = model.id; DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); #endregion trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }
private void ShowInfo(int _id) { BLL.student bll = new BLL.student(); Model.student model = bll.GetModel(_id); txtNo.Text = model.no; txtName.Text = model.name; txtSchool.Text = model.school; txtScore.Text = model.score; txtReScore.Text = model.re_score; txtAttach.Text = model.attach; txtAddTime.Text = model.add_time.ToString("yyyy-MM-dd HH:mm:ss"); rblIsAca.SelectedValue = model.is_aca.ToString(); }
private bool DoAdd() { bool result = false; Model.student model = new Model.student(); BLL.student bll = new BLL.student(); model.no = txtNo.Text.Trim(); model.name = txtName.Text.Trim(); model.school = txtSchool.Text.Trim(); model.score = txtScore.Text.Trim(); model.re_score = txtReScore.Text.Trim(); model.attach = txtAttach.Text.Trim(); model.add_time = Utils.StrToDateTime(txtAddTime.Text.Trim()); model.is_aca = Utils.ObjectToStr(rblIsAca.SelectedValue); //该研究生已经存在 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 = 2; 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 RptBind(string _strWhere, string _orderby) { BLL.teacher bll = new BLL.teacher(); if (this.action == DTEnums.ActionEnum.Edit.ToString()) { BLL.student studentBll = new BLL.student(); Model.student studentModel = studentBll.GetModel(this.id); txtIsAsa.Value = studentModel.is_aca; //如果是学术型研究生则只能看到学术型导师 if (studentModel.is_aca == "1") { _strWhere += " and is_aca='1' and resquota>0"; } else if (studentModel.is_aca == "0") { _strWhere += " and is_pro='1' and pro_resquota>0"; } //导师列表 this.rptList1.Visible = true; this.rptList1.DataSource = bll.GetList(0, _strWhere, _orderby); this.rptList1.DataBind(); } }
private bool DoEdit(int _id) { bool result = false; BLL.student bll = new BLL.student(); Model.student model = bll.GetModel(_id); model.no = txtNo.Text.Trim(); model.name = txtName.Text.Trim(); model.school = txtSchool.Text.Trim(); model.score = txtScore.Text.Trim(); model.re_score = txtReScore.Text.Trim(); model.attach = txtAttach.Text.Trim(); model.add_time = Utils.StrToDateTime(txtAddTime.Text.Trim()); model.is_aca = Utils.ObjectToStr(rblIsAca.SelectedValue); if (bll.Update(model)) { AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改研究生" + model.name); //记录日志 result = true; } return(result); }
//保存 protected void btnSubmit_Click(object sender, EventArgs e) { if (action == DTEnums.ActionEnum.Edit.ToString()) //修改 { BLL.student bll = new BLL.student(); Model.student model = bll.GetModel(this.id); if (model.status == "导师已通过您的申请") { 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 > 1) { JscriptMsg("您只能选择一名导师!", string.Empty); return; } if (selectList.Count > 0) { BLL.teacher teacherBll = new BLL.teacher(); var requota = "0"; //学术型研究生 if (model.is_aca == "1") { requota = teacherBll.GetQuota(selectList[0]); } else { requota = teacherBll.GetProResQuota(selectList[0]); } if (Utils.ObjToInt(requota) == 0) { JscriptMsg("您选择的导师配额已满,请重新选择!", string.Empty); return; } model.teacher_id = selectList[0]; } else { JscriptMsg("请选择导师!", string.Empty); return; } model.status = "待导师确认"; if (!bll.Update(model)) { JscriptMsg("保存过程中发生错误啦!", string.Empty); return; } JscriptMsg("选择导师成功!", Utils.CombUrlTxt("student_list.aspx", "keywords={0}&property={1}", "", "")); } }
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", "姓名" }, { "School", "本科毕业院校" }, { "Score", "笔试成绩" }, { "ReScore", "复试成绩" }, { "IsAca", "是否为学术型研究生" }, }; // 1.2解析文件,存放到一个List集合里 List <StudentEntity> enlist = ExcelHelper.ExcelToEntityList <StudentEntity>(cellheader, filePath, out errorMsg); #endregion var sucCount = 0; for (int i = 0; i < enlist.Count; i++) { StudentEntity en = enlist[i]; string errorMsgStr = "第" + (i + 1) + "行数据检测异常:"; //未填写研究生编号 if (string.IsNullOrWhiteSpace(en.No)) { continue; } Model.student model = new Model.student(); BLL.student bll = new BLL.student(); //该研究生已经存在 if (bll.Exists(en.No)) { continue; } model.no = en.No; model.name = en.Name; model.school = en.School; model.score = en.Score; model.re_score = en.ReScore; model.is_aca = en.IsAca; 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 = 2; 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.No + "123", 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("student_list.aspx", "keywords={0}&property={1}", this.keywords, this.property)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.student model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.student 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)); } }