Exemplo n.º 1
0
 /// <summary>
 /// 跳转到分配部门界面
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAssignUser_Click(object sender, EventArgs e)
 {
     if (D_ID != null)
     {
         DepDetailDto dep = AutofacConfig.departmentService.GetDepartmentByDepID(D_ID);
         if (dep != null)
         {
             DepInputDto department = new DepInputDto();
             department.Dep_ID     = dep.Dep_ID;
             department.Dep_Name   = dep.Dep_Name;
             department.Dep_Leader = dep.Dep_Leader;
             department.Dep_Icon   = dep.Dep_Icon;
             frmDepAssignUser frmDepAssignUser = new frmDepAssignUser();
             frmDepAssignUser.department = department;
             Show(frmDepAssignUser, (MobileForm form, object args) =>
             {
                 if (frmDepAssignUser.ShowResult == ShowResult.Yes)
                 {
                     ShowResult = ShowResult.Yes;
                     Close();
                 }
             });
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 跳转到分配部门界面
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAssignUser_Click(object sender, EventArgs e)
 {
     if (D_ID != null)
     {
         DepartmentDto dep = AutofacConfig.DepartmentService.GetDepartmentByDepID(D_ID);
         if (dep != null)
         {
             DepInputDto department = new DepInputDto();
             department.DEPARTMENTID = dep.DEPARTMENTID;
             department.NAME         = dep.NAME;
             department.MANAGER      = dep.MANAGER;
             department.IMAGEID      = dep.IMAGEID;
             frmDepAssignUser frmDepAssignUser = new frmDepAssignUser();
             frmDepAssignUser.department = department;
             Show(frmDepAssignUser, (MobileForm form, object args) =>
             {
                 if (frmDepAssignUser.ShowResult == ShowResult.Yes)
                 {
                     ShowResult = ShowResult.Yes;
                     Close();
                 }
             });
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="entity">部门对象</param>
        public ReturnInfo AddDepartment(DepInputDto entity)
        {
            ReturnInfo    RInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();
            string        MaxID = _departmentRepository.GetMaxID();
            string        NowID = Helper.GenerateDepID("D", MaxID);

            entity.DEPARTMENTID = NowID;
            string ValidateInfo = Helper.ValidateDepInputDto(entity);

            sb.Append(ValidateInfo);
            if (string.IsNullOrEmpty(ValidateInfo))
            {
                try
                {
                    Department d = Mapper.Map <DepInputDto, Department>(entity);
                    d.ISENABLE   = (int)IsEnable.启用;
                    d.CREATEDATE = DateTime.Now;
                    d.MODIFYDATE = DateTime.Now;
                    string MaxID2 = _departmentRepository.GetMaxID();
                    string NowID2 = Helper.GenerateDepID("D", MaxID2);
                    d.DEPARTMENTID = NowID2;
                    _unitOfWork.RegisterNew(d);
                    foreach (string s in entity.UserIDs)
                    {
                        coreUser u = _coreUserRepository.GetByID(s).FirstOrDefault();
                        u.USER_DEPARTMENTID = NowID;
                        _unitOfWork.RegisterDirty(u);
                    }
                    bool result = _unitOfWork.Commit();
                    RInfo.IsSuccess = result;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
                catch (Exception ex)
                {
                    _unitOfWork.Rollback();
                    sb.Append(ex.Message);
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
            }
            else
            {
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 部门验证
        /// </summary>
        /// <param name="entity">部门对象</param>
        public static string ValidateDepInputDto(DepInputDto entity)
        {
            //基础验证
            StringBuilder sb = BasicValidate <DepInputDto>(entity);

            //额外验证
            if (entity.UserIDs.Count > 0)
            {
                foreach (string s in entity.UserIDs)
                {
                    if (!userRepository.IsExists(s))
                    {
                        sb.Append("部门人员" + s + "不在用户表中!");
                    }
                }
            }
            else
            {
                sb.Append("部门人员至少需要一人!");
            }
            return(sb.ToString());
        }
Exemplo n.º 5
0
        /// <summary>
        /// 部门验证
        /// </summary>
        /// <param name="entity">部门对象</param>
        public static string ValidateDepInputDto(DepInputDto entity)
        {
            //基础验证
            StringBuilder sb = BasicValidate <DepInputDto>(entity);

            //额外验证
            if (entity.Dep_OtherDay < 0)
            {
                sb.Append("目标其他/人天不能为负!");
            }
            if (!Regex.IsMatch(entity.Dep_OtherDay.ToString(), @"/^0$|^[0-9]\d{0,15}$|^[0-9]\d{0,15}\.{1}\d{1,1}$|^0\.{1}\d{1,1}$/g"))
            {
                sb.Append("目标其他/人天格式错误,至多1位小数!");
            }
            if (entity.Dep_ProDay < 0)
            {
                sb.Append("目标项目/人天不能为负!");
            }
            if (!Regex.IsMatch(entity.Dep_ProDay.ToString(), @"/^0$|^[0-9]\d{0,15}$|^[0-9]\d{0,15}\.{1}\d{1,1}$|^0\.{1}\d{1,1}$/g"))
            {
                sb.Append("目标其他/人天格式错误,至多1位小数!");
            }
            if (entity.UserIDs.Count > 0)
            {
                foreach (string s in entity.UserIDs)
                {
                    if (!userRepository.IsExists(s))
                    {
                        sb.Append("部门人员" + s + "不在用户表中!");
                    }
                }
            }
            else
            {
                sb.Append("部门人员至少需要一人!");
            }
            return(sb.ToString());
        }
Exemplo n.º 6
0
        /// <summary>
        /// 更新部门
        /// </summary>
        /// <param name="entity">部门对象</param>
        public ReturnInfo UpdateDepartment(DepInputDto entity)
        {
            ReturnInfo    RInfo        = new ReturnInfo();
            StringBuilder sb           = new StringBuilder();
            string        ValidateInfo = Helper.ValidateDepInputDto(entity);

            sb.Append(ValidateInfo);
            if (string.IsNullOrEmpty(ValidateInfo))
            {
                Department d = _departmentRepository.GetByID(entity.DEPARTMENTID).FirstOrDefault();
                if (d == null)
                {
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = "找不到该部门!";
                    return(RInfo);
                }
                else
                {
                    try
                    {
                        #region 如果字段非空或0,则更新对应字段
                        if (entity.MANAGER != null)
                        {
                            d.MANAGER = entity.MANAGER;
                        }
                        if (entity.NAME != null)
                        {
                            d.NAME = entity.NAME;
                        }
                        d.MODIFYDATE = DateTime.Now;
                        if (entity.MODIFYUSER != null)
                        {
                            d.MODIFYUSER = entity.MODIFYUSER;
                        }
                        if (entity.IMAGEID != null)
                        {
                            d.IMAGEID = entity.IMAGEID;
                        }
                        #endregion
                        _unitOfWork.RegisterDirty(d);
                        List <string> OldIDs = GetUserByDepID(entity.DEPARTMENTID).Select(o => o.USER_ID).ToList();
                        List <string> Add    = entity.UserIDs.Except(OldIDs).ToList();
                        List <string> Delete = OldIDs.Except(entity.UserIDs).ToList();
                        if (Add.Count > 0)
                        {
                            foreach (string addID in Add)
                            {
                                if (!string.IsNullOrEmpty(addID))
                                {
                                    coreUser u = _coreUserRepository.GetByID(addID).FirstOrDefault();
                                    u.USER_DEPARTMENTID = entity.DEPARTMENTID;
                                    _unitOfWork.RegisterDirty(u);
                                }
                                else
                                {
                                    RInfo.IsSuccess = false;
                                    RInfo.ErrorInfo = "不能存在空的用户ID!";
                                }
                            }
                        }
                        if (Delete.Count > 0)
                        {
                            foreach (string deleteID in Delete)
                            {
                                if (!string.IsNullOrEmpty(deleteID))
                                {
                                    coreUser u = _coreUserRepository.GetByID(deleteID).FirstOrDefault();
                                    u.USER_DEPARTMENTID = "";
                                    _unitOfWork.RegisterDirty(u);
                                }
                                else
                                {
                                    RInfo.IsSuccess = false;
                                    RInfo.ErrorInfo = "不能存在空的用户ID!";
                                }
                            }
                        }
                        bool result = _unitOfWork.Commit();
                        RInfo.IsSuccess = result;
                        RInfo.ErrorInfo = sb.ToString();
                        return(RInfo);
                    }
                    catch (Exception ex)
                    {
                        _unitOfWork.RegisterClean(d);
                        _unitOfWork.Rollback();
                        sb.Append(ex.Message);
                        RInfo.IsSuccess = false;
                        RInfo.ErrorInfo = sb.ToString();
                        return(RInfo);
                    }
                }
            }
            else
            {
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
        }
Exemplo n.º 7
0
        AutofacConfig AutofacConfig = new AutofacConfig(); //调用配置类
        #endregion

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtDep_Name.Text.Trim().Length <= 0)
                {
                    throw new Exception("请输入部门名称!");
                }

                if (leader.Length <= 0)
                {
                    throw new Exception("请输入责任人!");
                }
                DepInputDto department = new DepInputDto();
                department.Dep_Name       = txtDep_Name.Text;
                department.Dep_UpdateUser = Client.Session["U_ID"].ToString();
                department.Dep_Leader     = leader;
                if (string.IsNullOrEmpty(D_Portrait) == false)
                {
                    department.Dep_Icon = D_Portrait;
                }
                else
                {
                    department.Dep_Icon = "";
                }
                if (string.IsNullOrEmpty(D_ID) == false)
                {
                    department.Dep_ID = D_ID;
                    List <UserDto> listuserDto = AutofacConfig.userService.GetUserByDepID(D_ID);
                    List <string>  listUser    = new List <string> ();
                    foreach (UserDto user in listuserDto)
                    {
                        listUser.Add(user.U_ID);
                    }
                    department.UserIDs = listUser;
                    ReturnInfo result = AutofacConfig.departmentService.UpdateDepartment(department);
                    if (result.IsSuccess == false)
                    {
                        throw new Exception(result.ErrorInfo);
                    }
                    else
                    {
                        ShowResult = ShowResult.Yes;
                        Close();
                        Toast("部门提交成功!", ToastLength.SHORT);
                    }
                }
                else
                {
                    //ShowResult = ShowResult.Yes;

                    frmDepAssignUser frmDepAssignUser = new frmDepAssignUser();
                    frmDepAssignUser.department = department;
                    //Show(frmDepAssignUser);
                    Show(frmDepAssignUser, (MobileForm form, object args) =>
                    {
                        if (frmDepAssignUser.ShowResult == ShowResult.Yes)
                        {
                            ShowResult = ShowResult.Yes;
                            Close();
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Toast(ex.Message, ToastLength.SHORT);
            }
        }