コード例 #1
0
ファイル: EmployeeSalaryImport.cs プロジェクト: jjg0519/OA
        /// <summary>
        /// 从Excel读取数据
        /// </summary>
        /// <param name="strPhysicalPath"></param>
        /// <returns></returns>
        public string ImportEmployeeMonthlySalary(GenerateUserInfo GenerateUser, string strPhysicalPath, string year, string month, string owerCompayId, ref string UImsg)
        {
            if (DateTime.Now.Hour != Convert.ToInt32(ConfigurationManager.AppSettings["ElapsedHour"]))
            {
            }
            string msg = string.Empty;

            Microsoft.VisualBasic.FileIO.TextFieldParser TF = new Microsoft.VisualBasic.FileIO.TextFieldParser(strPhysicalPath, Encoding.GetEncoding("GB2312"));
            EmployeeBLL empBll = new EmployeeBLL();
            var         User   = empBll.GetEmployeeDetailView(GenerateUser.GenerateUserId);

            TF.Delimiters = new string[] { "," }; //设置分隔符
            string[] strLine;

            EmployeeSalaryRecordBLL bll = new EmployeeSalaryRecordBLL();

            while (!TF.EndOfData)
            {
                try
                {
                    strLine = TF.ReadFields();
                    string strIDNUMBER       = strLine[0]; //身份证号码
                    string strEmployeeName   = strLine[1]; //员工姓名
                    string strSalaryItemName = strLine[2]; //员工薪资项目名
                    string strSalaryItemSUM  = strLine[3]; //员工薪资项目金额

                    var employee = (from ent in dal.GetObjects <T_HR_EMPLOYEE>()
                                    where ent.IDNUMBER == strIDNUMBER
                                    select ent).FirstOrDefault();
                    if (employee == null)
                    {
                        msg    = "薪资项目导入,根据身份证未找到相关员工档案,身份证号码:" + strIDNUMBER;
                        UImsg += msg + System.Environment.NewLine;
                        Tracer.Debug(msg);
                        continue;
                    }
                    else
                    {
                        Tracer.Debug("薪资项目导入,根据身份证找到相关员工档案,身份证号码:" + strIDNUMBER
                                     + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME
                                     + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM
                                     + " 导入人id:" + GenerateUser.GenerateUserId + " 名称:" + User.EMPLOYEENAME
                                     + " 导入人主岗位id(结算岗位):" + " 名称:" + GenerateUser.GeneratePostId + User.EMPLOYEEPOSTS[0].PostName
                                     + " 导入人所属公司id(发薪机构):" + GenerateUser.GenerateCompanyId + " 名称:" + User.EMPLOYEEPOSTS[0].CompanyName);
                    }
                    var salaryAchive = bll.GetEmployeeAcitiveSalaryArchive(employee.EMPLOYEEID, GenerateUser.GeneratePostId, GenerateUser.GenerateCompanyId, int.Parse(year), int.Parse(month));

                    T_HR_EMPLOYEESALARYRECORD record = (from r in dal.GetTable()
                                                        where r.EMPLOYEEID == employee.EMPLOYEEID &&
                                                        r.SALARYMONTH == month && r.SALARYYEAR == year &&
                                                        r.OWNERCOMPANYID == owerCompayId
                                                        select r).FirstOrDefault();

                    #region 新建薪资项目
                    if (record == null)
                    {
                        try
                        {
                            Tracer.Debug("导入员工薪资项目,未生成员工月薪,开始生成,员工姓名:" + employee.EMPLOYEECNAME + " " + year + "年" + month + "月"
                                         + "的月薪,record == null" + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME
                                         + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM);
                            record = new T_HR_EMPLOYEESALARYRECORD();
                            record.EMPLOYEESALARYRECORDID = Guid.NewGuid().ToString();
                            record.EMPLOYEEID             = employee.EMPLOYEEID;
                            record.CREATEUSERID           = GenerateUser.GenerateUserId;
                            record.CREATEPOSTID           = GenerateUser.GeneratePostId;
                            //  record.CREATEPOSTID = archive.CREATEPOSTID;
                            record.CREATEDEPARTMENTID = GenerateUser.GenerateDepartmentId;
                            record.CREATECOMPANYID    = GenerateUser.GenerateCompanyId;

                            record.OWNERID           = employee.EMPLOYEEID;;
                            record.OWNERPOSTID       = employee.OWNERPOSTID;
                            record.OWNERDEPARTMENTID = employee.OWNERDEPARTMENTID;
                            record.OWNERCOMPANYID    = employee.OWNERCOMPANYID;

                            record.ATTENDANCEUNUSUALTIMES = employee.OWNERCOMPANYID;      //记录薪资人的所属公司
                            record.ATTENDANCEUNUSUALTIME  = employee.OWNERPOSTID;         //记录薪资人的所属岗位
                            record.ABSENTTIMES            = salaryAchive.SALARYARCHIVEID; //记录生成薪资使用的薪资档案

                            record.PAIDTYPE     = bll.GetPaidType(employee.EMPLOYEEID);   //发放方式
                            record.REMARK       = "薪资项目导入生成";
                            record.PAIDTYPE     = bll.GetPaidType(employee.EMPLOYEEID);
                            record.EMPLOYEECODE = salaryAchive.EMPLOYEECODE;
                            record.EMPLOYEENAME = salaryAchive.EMPLOYEENAME;
                            record.PAYCONFIRM   = "0";
                            record.CHECKSTATE   = "0";
                            record.CREATEDATE   = System.DateTime.Now;
                            record.SALARYYEAR   = year;
                            record.SALARYMONTH  = month;
                            record.T_HR_EMPLOYEESALARYRECORDITEM.Clear();
                            int i = dal.Add(record);
                            if (i == 1)
                            {
                                ImportSalaryRecordItem(ref UImsg, ref msg, strIDNUMBER, strEmployeeName, strSalaryItemName, strSalaryItemSUM, employee, record, salaryAchive);
                            }
                            else
                            {
                                msg = "薪资项目导入添加员工薪资记录失败!" + " 身份证号码:" + strIDNUMBER
                                      + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME
                                      + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM;
                                UImsg += msg + System.Environment.NewLine;
                                Tracer.Debug(msg);
                            }
                        }
                        catch (Exception ex)
                        {
                            msg = "薪资项目导入添加员工薪资记录失败!" + ex.ToString() + " 身份证号码:" + strIDNUMBER
                                  + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME
                                  + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM;
                            UImsg += msg + System.Environment.NewLine;
                            Tracer.Debug(msg);
                        }
                        ;
                    }
                    #endregion
                    #region 更新薪资项目
                    else
                    {
                        var SalaryRecord = (from a in dal.GetObjects <T_HR_EMPLOYEESALARYRECORD>()
                                            join b in dal.GetObjects <T_HR_EMPLOYEESALARYRECORDITEM>() on a.EMPLOYEESALARYRECORDID equals b.T_HR_EMPLOYEESALARYRECORD.EMPLOYEESALARYRECORDID
                                            join c in dal.GetObjects <T_HR_SALARYITEM>() on b.SALARYITEMID equals c.SALARYITEMID
                                            where a.EMPLOYEEID == employee.EMPLOYEEID &&
                                            a.SALARYYEAR == year &&
                                            a.SALARYMONTH == month &&
                                            a.OWNERCOMPANYID == owerCompayId &&
                                            a.CHECKSTATE == "0" &&
                                            c.SALARYITEMNAME == strSalaryItemName
                                            select new
                        {
                            b.SALARYRECORDITEMID,
                            c.SALARYITEMNAME,
                            b.SUM
                        });
                        var item = SalaryRecord.FirstOrDefault();
                        if (item != null)
                        {
                            var q = from ent in dal.GetObjects <T_HR_EMPLOYEESALARYRECORDITEM>()
                                    where ent.SALARYRECORDITEMID == item.SALARYRECORDITEMID
                                    select ent;
                            var entsum = q.FirstOrDefault();
                            if (entsum != null)
                            {
                                entsum.SUM = AES.AESEncrypt(strSalaryItemSUM);
                                int i = dal.Update(entsum);
                                if (i >= 1)
                                {
                                    msg = "薪资项目导入成功,受影响的条数:" + i + " 身份证号码:" + strIDNUMBER
                                          + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME
                                          + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM;
                                    UImsg += msg + System.Environment.NewLine;
                                    Tracer.Debug(msg);
                                }
                                else
                                {
                                    msg = "薪资项目导入失败,受影响的条数:" + i + " 身份证号码:" + strIDNUMBER
                                          + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME
                                          + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM;
                                    UImsg += msg + System.Environment.NewLine;
                                    Tracer.Debug(msg);
                                    continue;
                                }
                            }
                            else
                            {
                                msg = "薪资项目导入失败,未找到薪资项目," + " 身份证号码:" + strIDNUMBER
                                      + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME
                                      + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM;
                                UImsg += msg + System.Environment.NewLine;
                                Tracer.Debug(msg);
                                continue;
                            }
                        }
                        else
                        {
                            ImportSalaryRecordItem(ref UImsg, ref msg, strIDNUMBER, strEmployeeName, strSalaryItemName, strSalaryItemSUM, employee, record, salaryAchive);
                        }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    UImsg += "导入薪资项目异常:" + ex + System.Environment.NewLine;
                    Utility.SaveLog(ex.ToString());
                    continue;
                }
            }
            TF.Close();
            return(UImsg);
        }
コード例 #2
0
        private void ShowDTGrid(string year, string month)
        {
            try
            {
                Stream Stream = (System.IO.Stream)openFileDialog.File.OpenRead();

                byte[] Buffer = new byte[Stream.Length];
                Stream.Read(Buffer, 0, (int)Stream.Length);

                Stream.Dispose();
                Stream.Close();
                SMT.Saas.Tools.SalaryWS.UploadFileModel UploadFile = new Saas.Tools.SalaryWS.UploadFileModel();
                UploadFile.FileName = openFileDialog.File.Name;
                UploadFile.File = Buffer;
                loadbar.Start();
                GenerateUserInfo guser = new GenerateUserInfo();
                guser.GenerateUserId = Common.CurrentLoginUserInfo.EmployeeID;
                guser.GenerateUserPostId = Common.CurrentLoginUserInfo.UserPosts[0].PostID;
                guser.GenerateUserDepartmentId = Common.CurrentLoginUserInfo.UserPosts[0].DepartmentID; 
                guser.GenerateUserCompanyId = Common.CurrentLoginUserInfo.UserPosts[0].CompanyID;
                //结算公司,结算岗位
                guser.GenerateCompanyId = Common.CurrentLoginUserInfo.UserPosts[0].CompanyID;
                guser.GeneratePostId = Common.CurrentLoginUserInfo.UserPosts[0].PostID;
                
                
                client.ImportEmployeeMonthlySalaryAsync(UploadFile,guser, year, month, Common.CurrentLoginUserInfo.UserPosts[0].CompanyID, UIMsg);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }