Exemple #1
0
        /// <summary>
        /// 执行导出功能
        /// </summary>
        /// <returns></returns>
        public DataTable Excute()
        {
            List <EmployeeSalary> employeeSalarys =
                new GetEmployeeAccountSet().GetEmployeeAccountSetByCondition(_EmployeeName, _DepartmentID, _PositionID,
                                                                             _EmployeeTypeEnum, _IsRecursionDepartment,
                                                                             _AccountOperator, _EmployeeStatus);

            foreach (EmployeeSalary employeeSalary in employeeSalarys)
            {
                EmployeeSalary employeeSalaryInfo =
                    new GetEmployeeAccountSet().GetEmployeeAccountSetByEmployeeID(employeeSalary.Employee.Account.Id);
                if (employeeSalaryInfo != null)
                {
                    employeeSalary.AccountSet = employeeSalaryInfo.AccountSet;
                }
            }
            //表格组成
            DataTable dt = new DataTable();

            dt.Columns.Add("员工姓名");
            dt.Columns.Add("所属部门");
            dt.Columns.Add("职位");
            dt.Columns.Add("员工类型");
            dt.Columns.Add("帐套名称");
            foreach (EmployeeSalary employeeSalary in employeeSalarys)
            {
                if (employeeSalary.AccountSet == null || employeeSalary.AccountSet.Items == null)
                {
                    continue;
                }
                foreach (AccountSetItem accountSetItem in employeeSalary.AccountSet.Items)
                {
                    if (accountSetItem.AccountSetPara.FieldAttribute.Id == FieldAttributeEnum.FixedField.Id &&
                        !dt.Columns.Contains(accountSetItem.AccountSetPara.AccountSetParaName))
                    {
                        dt.Columns.Add(accountSetItem.AccountSetPara.AccountSetParaName);
                    }
                }
            }
            //赋值table
            foreach (EmployeeSalary employeeSalary in employeeSalarys)
            {
                DataRow dr = dt.NewRow();
                dr["员工姓名"] = employeeSalary.Employee.Account.Name;
                dr["所属部门"] = employeeSalary.Employee.Account.Dept.Name;
                dr["职位"]   = employeeSalary.Employee.Account.Position.Name;
                dr["员工类型"] = EmployeeTypeUtility.EmployeeTypeDisplay(employeeSalary.Employee.EmployeeType);
                dr["帐套名称"] = employeeSalary.AccountSet.AccountSetName;
                if (employeeSalary.AccountSet != null && employeeSalary.AccountSet.Items != null)
                {
                    foreach (AccountSetItem accountSetItem in employeeSalary.AccountSet.Items)
                    {
                        if (accountSetItem.AccountSetPara.FieldAttribute.Id == FieldAttributeEnum.FixedField.Id &&
                            dt.Columns.Contains(accountSetItem.AccountSetPara.AccountSetParaName))
                        {
                            dr[accountSetItem.AccountSetPara.AccountSetParaName] = accountSetItem.CalculateResult;
                        }
                    }
                }
                dt.Rows.Add(dr);
            }
            return(dt);
        }
        /// <summary>
        /// 开始更新员工的帐套
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="indexAccountSetName"></param>
        /// <param name="indexEmployeeName"></param>
        private void ToInsertUpdateEmployeeAccountSet(DataTable dt, int indexAccountSetName, int indexEmployeeName)
        {
            List <Account> allAccount = _IAccountBll.GetAllAccount();

            allAccount = Tools.RemoteUnAuthAccount(allAccount, AuthType.HRMIS, _Operator, HrmisPowers.A604);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ModelPayModule.AccountSet accountSet = null;
                //有没有当前账号
                Account account =
                    _IAccountBll.GetAccountByName(dt.Rows[i][indexEmployeeName].ToString().Trim());
                if (account == null || !Tools.ContainsAccountById(allAccount, account.Id))
                {
                    continue;
                }
                //当前账号有没有工资套,如果有则给accountSet赋上当前帐套,以便更新
                bool           IsEmployeeHaveAccountSet = false;
                EmployeeSalary employeeSalary           =
                    new GetEmployeeAccountSet().GetEmployeeAccountSetByEmployeeID(account.Id);
                if (employeeSalary != null && employeeSalary.AccountSet != null)
                {
                    accountSet = employeeSalary.AccountSet;
                    IsEmployeeHaveAccountSet = true;
                }
                //excel是否有帐套名称列,如果有则需要确定是否要更新帐套
                if (indexAccountSetName != -1)
                {
                    ModelPayModule.AccountSet accountSetInExcel =
                        new GetAccountSet().GetAccountSetByName(
                            dt.Rows[i][indexAccountSetName].ToString().Trim());
                    if (accountSetInExcel != null)
                    {
                        //如果accountSet是空,则将accountSetInExcel赋值给accountSet
                        if (accountSet == null)
                        {
                            accountSet = new GetAccountSet().GetWholeAccountSetByPKID(accountSetInExcel.AccountSetID);
                        }
                        //如果accountSet不是空,是否和accountSetInExcel的帐套一致,如果不一致,则要覆盖accountSet,并且做AccountSet信息的数据Merge,保留原有的固定值信息
                        else if (accountSetInExcel.AccountSetID != accountSet.AccountSetID)
                        {
                            accountSet = new GetAccountSet().GetWholeAccountSetByPKID(accountSetInExcel.AccountSetID);
                            if (employeeSalary != null && employeeSalary.AccountSet != null)
                            {
                                //AccountSet信息的数据Merge,保留原有的固定值信息
                                MergeAccountSetData(accountSet, employeeSalary.AccountSet);
                            }
                        }
                    }
                }
                if (accountSet == null)
                {
                    continue;
                }

                BindAccountSetData(dt, i, accountSet);
                if (IsEmployeeHaveAccountSet)
                {
                    new UpdateEmployeeAccountSet(account.Id, accountSet, _Operator.Name,
                                                 DateTime.Now,
                                                 EmployeeAccount_DataString).Excute();
                }
                else
                {
                    new CreateEmployeeAccountSet(account.Id, accountSet, _Operator.Name,
                                                 DateTime.Now,
                                                 EmployeeAccount_DataString).Excute();
                }
            }
        }