private string DoAction() { string result = ""; BLL.CCOM.User_information bll = new BLL.CCOM.User_information(); Model.CCOM.User_information model; if (action != MyEnums.ActionEnum.Edit.ToString()) { model = new Model.CCOM.User_information(); } else { model = bll.GetModel("User_id=" + userId); } string Sex = this.rblSex.SelectedValue; string Mobile = this.txtMobile.Text.Trim(); string Pass1 = this.txtPass1.Text.Trim(); string Pass2 = this.txtPass2.Text.Trim(); // string IdNumberType = this.ddlIdType.SelectedItem.Value; //string IdNumber = this.txtIdNumber.Text.Trim(); string Realname = this.txtRealname.Text.Trim(); string Agency = this.ddlAgency.SelectedItem.Value; // string Role = this.ddlRole.SelectedItem.Value; //必填部分 if (Tools.CheckParams(Mobile + Realname + Pass1 + Pass2)) { return("请勿输入非法字符"); } if (Realname == "") { return("请填写真实姓名"); } model.User_realname = Realname; if (Mobile == "") { return("请填写学号/工号"); } if (!Validator.IsMobile(Mobile)) { return("学号/工号不合法"); } if (action != MyEnums.ActionEnum.Edit.ToString() && bll.GetRecordCount(" User_number='" + Mobile + "'") > 0) { return("该学号/工号已被添加"); } model.User_number = Mobile; if (action != MyEnums.ActionEnum.Edit.ToString()) { if (Pass1 == "") { return("请填写密码"); } if (Pass2 == "") { return("请填写确认密码"); } } if (Pass1.Length > 0 || Pass2.Length > 0) { if (Pass1.Length < 6 || Pass1.Length > 16) { return("密码长度请控制在6-16位"); } if (Pass1 != Pass2) { return("两次输入密码不符"); } } model.User_password = DESEncrypt.MD5Encrypt(Pass1); model.User_addtime = DateTime.Now; model.User_status = true; model.Role_id = 1; if (Agency == "#") { return("请选择机构"); } model.Agency_id = Convert.ToInt32(Agency); //if (Role == "#") //{ // return "请选择角色"; //} //model.Role_id = Convert.ToInt32(Role); //选填部分 model.User_gender = Convert.ToInt32(Sex) == 0; //if (IdNumber != "") //{ // if (IdNumberType == "#") // { // return "请选择证件类型"; // } // //验证身份证信息,只能验证身份证 // else if (Convert.ToInt32(IdNumberType) == 1) // { // bool check = false; // if (IdNumber.Length == 18) // { // check = CheckIDCard18(IdNumber); // } // else if (IdNumber.Length == 15) // { // check = CheckIDCard15(IdNumber); // } // if (check) // { // if (action != MyEnums.ActionEnum.Edit.ToString() && bll.GetRecordCount(" User_ID_number='" + IdNumber + "'") > 0) // { // return "该证件号已被添加"; // } // model.User_ID_number_type = Convert.ToInt32(IdNumberType); // model.User_ID_number = IdNumber; // } // else // { // return "请检查身份证号码是否正确"; // } // } //} if (this.txtBirthday.Value != "") { DateTime Birthday = Convert.ToDateTime(this.txtBirthday.Value); model.User_birthday = Birthday; } try { if (action == MyEnums.ActionEnum.Edit.ToString()) //修改 { bll.Update(model); } else { bll.Add(model); } } catch (Exception ex) { result = action == MyEnums.ActionEnum.Edit.ToString() ? "修改失败" : "添加失败" + ex.Message.ToString(); } return(result); }
protected string ImportDataItem(DataSet ds, ref int success, ref int error)//基础数据 { string result = ""; BLL.CCOM.User_information bll = new BLL.CCOM.User_information(); Model.CCOM.User_information model = new Model.CCOM.User_information(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string checkmsg = null; //姓名 string name = ds.Tables[0].Rows[i]["姓名"].ToString().Trim(); if (!ValidDFValue(name, true, "", ref checkmsg)) { result += "×第" + (i + 1).ToString() + "行数据更新失败,姓名" + checkmsg + "<br/>"; error++; continue; } else if (name != "") { model.User_realname = name; } //学号/工号 string mobile = ds.Tables[0].Rows[i]["学号/工号"].ToString().Trim(); if (!Validator.IsMobile(mobile)) { result += "×第" + (i + 1).ToString() + "行数据更新失败,学号/工号要为整数<br/>"; error++; continue; } if (!ValidDFValue(mobile, true, "", ref checkmsg)) { result += "×第" + (i + 1).ToString() + "行数据更新失败,学号/工号" + checkmsg + "<br/>"; error++; continue; } else if (bll.GetRecordCount(" User_number='" + mobile + "'") > 0) { result += "×第" + (i + 1).ToString() + "行数据更新失败,该学号/工号已被添加<br/>"; error++; continue; } else if (mobile != "") { model.User_number = mobile; } //性别 string gender = ds.Tables[0].Rows[i]["性别"].ToString().Trim(); if (!ValidDFValue(gender, true, "男|女", ref checkmsg)) { result += "×第" + (i + 1).ToString() + "行数据更新失败,性别" + checkmsg + "<br/>"; error++; continue; } else if (gender == "男") { model.User_gender = false; } else if (gender == "女") { model.User_gender = true; } //机构 string angency = ds.Tables[0].Rows[i]["机构/班号"].ToString().Trim(); if (!ValidDFValue(angency, true, "", ref checkmsg)) { result += "×第" + (i + 1).ToString() + "行数据更新失败,所在机构/班号" + checkmsg + "<br/>"; error++; continue; } BLL.CCOM.Agency agency_bll = new BLL.CCOM.Agency(); Model.CCOM.Agency agency_model = new Model.CCOM.Agency(); agency_model = agency_bll.GetModel(" Agency_name='" + angency + "'"); if (agency_model == null) { result += "×第" + (i + 1).ToString() + "行数据更新失败,所在机构/班号不存在<br/>"; error++; continue; } model.Agency_id = agency_model.Agency_id; //角色 string role = ds.Tables[0].Rows[i]["角色"].ToString().Trim(); if (!ValidDFValue(role, true, "", ref checkmsg)) { result += "×第" + (i + 1).ToString() + "行数据更新失败,角色<br/>"; error++; continue; } BLL.CCOM.Role role_bll = new BLL.CCOM.Role(); Model.CCOM.Role role_model = new Model.CCOM.Role(); role_model = role_bll.GetModel(" Role_name='" + role + "'"); if (role_model == null) { result += "×第" + (i + 1).ToString() + "行数据更新失败,用户角色不存在<br/>"; error++; continue; } model.Role_id = role_model.Role_id; //生日 //string birthday = ds.Tables[0].Rows[i]["生日"].ToString().Trim(); //if (!ValidDFValue(birthday, false, "", ref checkmsg)) //{ // result += "×第" + (i + 1).ToString() + "行数据更新失败,生日" + checkmsg + "<br/>"; // error++; // continue; //} //else if (birthday != "") //{ // if (!Validator.IsBirthday(birthday)) // { // result += "×第" + (i + 1).ToString() + "行数据更新失败,生日格式不对<br/>"; // error++; // continue; // } // model.User_birthday = Convert.ToDateTime(birthday); //} //model.User_password = mobile; ////教师职称 //string title = ds.Tables[0].Rows[i]["教师职称"].ToString().Trim(); //BLL.CCOM.Title title_bll = new BLL.CCOM.Title(); //Model.CCOM.Title title_model = new Model.CCOM.Title(); //title_model = title_bll.GetModel(" Title_name='" + title + "'"); //if (title_model == null) //{ // result += "×第" + (i + 1).ToString() + "行数据更新失败,该教师职称不存在<br/>"; // error++; // continue; //} //else if (!ValidDFValue(title, true, "", ref checkmsg)) //{ // result += "×第" + (i + 1).ToString() + "行数据更新失败,教师职称<br/>"; // error++; // continue; //} model.User_password = DESEncrypt.MD5Encrypt(mobile); if (bll.Add(model) == 0) { result += "×第" + (i + 1).ToString() + "行数据更新异常<br/>"; error++; continue; } else { success++; BLL.CCOM.User_information user_bll = new BLL.CCOM.User_information(); Model.CCOM.User_information user_model = user_bll.GetModel("User_number='" + mobile + "'"); if (model.Role_id == 2) //如果为指导教师,插入Tutor表 { BLL.CCOM.Tutor tutor_bll = new BLL.CCOM.Tutor(); Model.CCOM.Tutor tutor_model = new Model.CCOM.Tutor(); tutor_model.User_id = user_model.User_id; tutor_model.Title_id = 1; tutor_bll.Add(tutor_model); } if (model.Role_id == 3)//如果为学生,插入Student表 { BLL.CCOM.Student student_bll = new BLL.CCOM.Student(); Model.CCOM.Student student_model = new Model.CCOM.Student(); student_model.User_id = user_model.User_id; student_model.Period_id = 4; student_bll.Add(student_model); } } } return(result); }