public static void Setup(int testItems) { SetTestRepo(); for(int i=0;i<testItems;i++){ Manager item=new Manager(); _testRepo._items.Add(item); } }
public static void Setup(Manager item) { SetTestRepo(); _testRepo._items.Add(item); }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(txtLoginName.Text.Trim())) { return txtLoginName.Label + "不能为空!"; } var logName = StringHelper.Left(txtLoginName.Text, 20); if (Manager.Exists(x => x.LoginName == logName && x.Id != id)) { return txtLoginName.Label + "已存在!请重新输入!"; } //新增用户时,密码不能为空 if (id == 0 && string.IsNullOrEmpty(txtLoginPass.Text.Trim())) { return "密码不能为空!"; } //密码长度不能短于6位 if (!string.IsNullOrEmpty(txtLoginPass.Text.Trim()) && txtLoginPass.Text.Trim().Length < 6) { return "密码长度必须6位以上,请重新输入!"; } if (!txtLoginPass.Text.Equals(txtLoginPassaAgin.Text)) return "两次输入的密码不一样,请重新输入!"; if (string.IsNullOrEmpty(txtCName.Text.Trim())) { return txtCName.Label + "不能为空!"; } //所属部门 if (ConvertHelper.Cint0(ddlBranch_Id.SelectedValue) < 1) { return ddlBranch_Id.Label + "为必选项,请选择!"; } //所属职位 if (string.IsNullOrEmpty(hidPositionId.Text)) { return txtPosition.Label + "为必选项,请选择!"; } #endregion #region 赋值 //获取实体 var model = new Manager(x => x.Id == id); model.LoginName = logName; //如果是添加管理员 if (id == 0) { model.CreateTime = DateTime.Now; model.UpdateTime = DateTime.Now; model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); model.LoginPass = Encrypt.Md5(Encrypt.Md5(txtLoginPass.Text)); model.IsWork = 1; } else { //修改时间与管理员 model.UpdateTime = DateTime.Now; model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); //修改用户时,填写了密码,则更新密码 if (txtLoginPass.Text.Trim().Length >= 6) { model.LoginPass = Encrypt.Md5(Encrypt.Md5(txtLoginPass.Text)); } } model.Branch_Id = ConvertHelper.Cint0(ddlBranch_Id.SelectedValue); var branch = BranchBll.GetInstence().GetModelForCache(x => x.Id == model.Branch_Id); if (branch != null) { model.Branch_Code = branch.Code; model.Branch_Name = branch.Name; } model.Position_Id = StringHelper.Left(hidPositionId.Text, 100); model.Position_Name = StringHelper.Left(txtPosition.Text, 500); model.CName = StringHelper.Left(txtCName.Text, 20); model.EName = StringHelper.Left(txtEName.Text, 50); model.Sex = StringHelper.Left(rblSex.SelectedValue, 4); model.Birthday = StringHelper.Left(dpBirthday.Text, 20); model.Record = StringHelper.Left(txtRecord.Text, 25); model.GraduateCollege = StringHelper.Left(txtGraduateCollege.Text, 30); model.GraduateSpecialty = StringHelper.Left(txtGraduateSpecialty.Text, 50); model.Tel = StringHelper.Left(txtTel.Text, 30); model.Mobile = StringHelper.Left(txtMobile.Text, 30); model.Email = StringHelper.Left(txtEmail.Text, 50); model.Qq = StringHelper.Left(txtQq.Text, 30); model.Msn = StringHelper.Left(txtMsn.Text, 30); model.Address = StringHelper.Left(txtAddress.Text, 100); model.IsEnable = ConvertHelper.Ctinyint(rblIsEnable.SelectedValue); model.IsMultiUser = ConvertHelper.Ctinyint(rblIsMultiUser.SelectedValue); model.Content = StringHelper.Left(txtContent.Text, 0); model.NationalName = StringHelper.Left(txtNationalName.Text, 50); model.NativePlace = StringHelper.Left(txtNativePlace.Text, 100); #region 上传图片 if (this.fuSinger_AvatarPath.HasFile && this.fuSinger_AvatarPath.FileName.Length > 3) { int vid = 1; //1 管理员头像(头像图片) //--------------------------------------------------- var upload = new UploadFile(); result = new UploadFileBll().Upload_AspNet(this.fuSinger_AvatarPath.PostedFile, vid, RndKey, OnlineUsersBll.GetInstence().GetManagerId(), OnlineUsersBll.GetInstence().GetManagerCName(), upload); this.fuSinger_AvatarPath.Dispose(); //--------------------------------------------------- if (result.Length == 0)//上传成功 { model.PhotoImg = upload.Path; } else { CommonBll.WriteLog("上传管理员头像图片未成功:" + result, null);//收集异常信息 return "上传管理员头像图片未成功!" + result; } } //如果是修改,检查用户是否重新上传过封面图片,如果是删除旧的图片 if (model.Id > 0) { UploadFileBll.GetInstence().Upload_DiffFile(ManagerTable.Id, ManagerTable.PhotoImg, ManagerTable.TableName, model.Id, model.PhotoImg); //同步UploadFile上传表 UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, ManagerTable.TableName, model.Id); } #endregion #endregion //---------------------------------------------------------- //存储到数据库 ManagerBll.GetInstence().Save(this, model); #region 同步更新上传图片表绑定Id if (id == 0) { //同步UploadFile上传表记录,绑定刚刚上传成功的文件Id为当前记录Id UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, ManagerTable.TableName, model.Id); } #endregion } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return result; }
/// <summary> /// 将Manager记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.Manager) /// </summary> /// <param name="model">SubSonic插件生成的实体</param> /// <returns>DataAccess.Model.Manager</returns> public DataAccess.Model.Manager Transform(Manager model) { if (model == null) return null; return new DataAccess.Model.Manager { Id = model.Id, LoginName = model.LoginName, LoginPass = model.LoginPass, LoginTime = model.LoginTime, LoginIp = model.LoginIp, LoginCount = model.LoginCount, CreateTime = model.CreateTime, UpdateTime = model.UpdateTime, IsMultiUser = model.IsMultiUser, Branch_Id = model.Branch_Id, Branch_Code = model.Branch_Code, Branch_Name = model.Branch_Name, Position_Id = model.Position_Id, Position_Name = model.Position_Name, IsWork = model.IsWork, IsEnable = model.IsEnable, CName = model.CName, EName = model.EName, PhotoImg = model.PhotoImg, Sex = model.Sex, Birthday = model.Birthday, NativePlace = model.NativePlace, NationalName = model.NationalName, Record = model.Record, GraduateCollege = model.GraduateCollege, GraduateSpecialty = model.GraduateSpecialty, Tel = model.Tel, Mobile = model.Mobile, Email = model.Email, Qq = model.Qq, Msn = model.Msn, Address = model.Address, Content = model.Content, Manager_Id = model.Manager_Id, Manager_CName = model.Manager_CName, }; }
/// <summary> /// 更新IIS缓存中指定Id记录 /// </summary> /// <param name="model">记录实体</param> public void SetModelForCache(Manager model) { SetModelForCache(Transform(model)); }
/// <summary> /// 添加与编辑Manager记录 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="model">Manager表实体</param> /// <param name="content">更新说明</param> /// <param name="isCache">是否更新缓存</param> /// <param name="isAddUseLog">是否添加用户操作日志</param> public void Save(Page page, Manager model, string content = null, bool isCache = true, bool isAddUseLog = true) { try { //保存 model.Save(); //判断是否启用缓存 if (CommonBll.IsUseCache() && isCache) { SetModelForCache(model); } if (isAddUseLog) { if (string.IsNullOrEmpty(content)) { content = "{0}" + (model.Id == 0 ? "添加" : "编辑") + "Manager记录成功,ID为【" + model.Id + "】"; } //添加用户访问记录 UseLogBll.GetInstence().Save(page, content); } } catch (Exception e) { var result = "执行ManagerBll.Save()函数出错!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } }