コード例 #1
0
        public Guid Save(Employee employee)
        {
            Transaction tx = null;

            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    tx = em.BeginTransaction();

                    Guid ID = Guid.NewGuid();

                    string[] columns = { "ID",          "EmployeeCode",    "OldEmployeeCode", "EmployeeName",   "BirthPlace",  "BirthDate", "Gender", "Religion", "IsTransfer",
                                         "BankName",    "AccountNumber",   "MaritalStatus",   "NumberOfChilds", "IsInsurance", "IsTax",     "NPWP",   "PTKPId",
                                         "IsPrincipal", "IsFuelAllowance", "StartDate",       "EndDate",        "IsActive",
                                         "CreatedDate", "CreatedBy",       "ModifiedDate",    "ModifiedBy" };

                    object[] values = { ID,                                   employee.EmployeeCode,            employee.OldEmployeeCode,             employee.EmployeeName,                  employee.BirthPlace,    employee.BirthDate.ToShortDateString(),
                                        employee.Gender == true?1:0,          employee.Religion,                employee.IsTransfer == true?1:0,      employee.BankName,                      employee.AccountNumber,
                                        employee.MaritalStatus == true?1:0,   employee.NumberOfChilds,          employee.IsInsurance == true?1:0,     employee.IsTax == true?1:0,             employee.NPWP,
                                        employee.PTKPId,                      employee.IsPrincipal == true?1:0, employee.IsFuelAllowance == true?1:0, employee.StartDate.ToShortDateString(),
                                        employee.EndDate.ToShortDateString(), employee.IsActive == true?1:0,
                                        DateTime.Now.ToShortDateString(),     Store.ActiveUser,                 DateTime.Now.ToShortDateString(),     Store.ActiveUser };

                    var q = new Query().Select(columns).From(tableName).Insert(values);

                    em.ExecuteNonQuery(q.ToSql(), tx);

                    foreach (var family in employee.Families)
                    {
                        family.EmployeeId = ID;
                        employeeFamilyRepository.Save(em, tx, family);
                    }

                    foreach (var department in employee.Departments)
                    {
                        department.EmployeeId = ID;
                        employeeDepatmentRepository.Save(em, tx, department);
                    }

                    foreach (var grade in employee.Grades)
                    {
                        grade.EmployeeId = ID;
                        employeeGradeRepository.Save(em, tx, grade);
                    }

                    foreach (var occupation in employee.Occupations)
                    {
                        occupation.EmployeeId = ID;
                        employeeOccupationRepository.Save(em, tx, occupation);
                    }

                    foreach (var principal in employee.Principals)
                    {
                        principal.EmployeeId = ID;
                        employeePrincipalRepository.Save(em, tx, principal);
                    }

                    foreach (var employeeStatus in employee.Status)
                    {
                        employeeStatus.EmployeeId = ID;
                        employeeStatusRepository.Save(em, tx, employeeStatus);
                    }

                    foreach (var employeeInsurance in employee.Insurances)
                    {
                        employeeInsurance.EmployeeId = ID;
                        employeeInsuranceRepository.Save(em, tx, employeeInsurance);
                    }


                    foreach (var employeeSalary in employee.Salaries)
                    {
                        employeeSalary.EmployeeId = ID;
                        employeeSalaryRepository.Save(em, tx, employeeSalary);
                    }


                    branchRepository.UpdateEmployeeCounter(employee.CurrentInfo.BranchName, em, tx);

                    tx.Commit();



                    return(ID);
                }
            }
            catch (Exception ex)
            {
                tx.Rollback();
                throw ex;
            }
        }
コード例 #2
0
ファイル: ImportUI.cs プロジェクト: neonerdy/paycare
        private void ImportEmployeeDetail(string fileName)
        {
            Excel.Application xlApp;
            Excel.Workbook    xlWorkBook;
            Excel.Worksheet   xlWorkSheet;
            Excel.Range       range;

            xlApp = new Excel.ApplicationClass();

            xlWorkBook  = xlApp.Workbooks.Open(fileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);

            range = xlWorkSheet.UsedRange;

            for (var row = 2; row <= range.Rows.Count; row++)
            {
                string nik             = (string)(range.Cells[row, 1] as Excel.Range).Value2;
                string branch          = (string)(range.Cells[row, 2] as Excel.Range).Value2;
                string department      = (string)(range.Cells[row, 3] as Excel.Range).Value2;
                string departmentDate  = (string)(range.Cells[row, 4] as Excel.Range).Value2;
                string grade           = (string)(range.Cells[row, 5] as Excel.Range).Value2;
                string gradeDate       = (string)(range.Cells[row, 6] as Excel.Range).Value2;
                string occupation      = (string)(range.Cells[row, 7] as Excel.Range).Value2;
                string occupationDate  = (string)(range.Cells[row, 8] as Excel.Range).Value2;
                string isTaskForce     = (string)(range.Cells[row, 9] as Excel.Range).Value2;
                string principal       = (string)(range.Cells[row, 10] as Excel.Range).Value2;
                string principalDate   = (string)(range.Cells[row, 11] as Excel.Range).Value2;
                string status          = (string)(range.Cells[row, 12] as Excel.Range).Value2;
                string paymentType     = (string)(range.Cells[row, 13] as Excel.Range).Value2;
                string statusDate      = (string)(range.Cells[row, 14] as Excel.Range).Value2;
                string jamsostekNumber = (string)(range.Cells[row, 15] as Excel.Range).Value2;
                string jamsostekDate   = (string)(range.Cells[row, 16] as Excel.Range).Value2;


                string salaryDate             = (string)(range.Cells[row, 17] as Excel.Range).Value2;
                double mainSalary             = (double)(range.Cells[row, 18] as Excel.Range).Value2;
                double occupationAllowance    = (double)(range.Cells[row, 19] as Excel.Range).Value2;
                double fixedAllowance         = (double)(range.Cells[row, 20] as Excel.Range).Value2;
                double healthAllowance        = (double)(range.Cells[row, 21] as Excel.Range).Value2;
                double communicationAllowance = (double)(range.Cells[row, 22] as Excel.Range).Value2;
                double supervisionAllowance   = (double)(range.Cells[row, 23] as Excel.Range).Value2;
                double otherAllowance         = (double)(range.Cells[row, 24] as Excel.Range).Value2;
                double fuelAllowance          = (double)(range.Cells[row, 25] as Excel.Range).Value2;
                double vehicleAllowance       = (double)(range.Cells[row, 26] as Excel.Range).Value2;
                double lunchAllowance         = (double)(range.Cells[row, 27] as Excel.Range).Value2;
                double transportAllowance     = (double)(range.Cells[row, 28] as Excel.Range).Value2;


                if (nik == null)
                {
                    break;
                }

                var employee = employeeRepository.GetByCode(nik);

                if (employee != null)
                {
                    //Department

                    var employeeDepartment = new EmployeeDepartment();

                    employeeDepartment.EmployeeId    = employee.ID;
                    employeeDepartment.EffectiveDate = DateTime.ParseExact(departmentDate,
                                                                           "dd/MM/yyyy", CultureInfo.InvariantCulture);

                    employeeDepartment.BranchId     = branchRepository.GetByName(branch).ID;
                    employeeDepartment.DepartmentId = departmentRepository.GetByName(department).ID;

                    employeeDepartmentRepository.Save(employeeDepartment);


                    //Grade

                    var employeeGrade = new EmployeeGrade();

                    employeeGrade.EmployeeId    = employee.ID;
                    employeeGrade.EffectiveDate = DateTime.ParseExact(gradeDate,
                                                                      "dd/MM/yyyy", CultureInfo.InvariantCulture);

                    employeeGrade.GradeId = gradeRepository.GetByName(grade).ID;

                    employeeGradeRepository.Save(employeeGrade);


                    //Occupation

                    var employeeOccupation = new EmployeeOccupation();

                    employeeOccupation.EmployeeId    = employee.ID;
                    employeeOccupation.EffectiveDate = DateTime.ParseExact(occupationDate,
                                                                           "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    employeeOccupation.OccupationId = occupationRepository.GetByName(occupation).ID;
                    employeeOccupation.IsTaskForce  = isTaskForce.ToUpper() == "Y" ? true : false;

                    employeeOccupationRepository.Save(employeeOccupation);


                    //Status

                    var employeeStatus = new EmployeeStatus();

                    employeeStatus.EmployeeId    = employee.ID;
                    employeeStatus.EffectiveDate = DateTime.ParseExact(statusDate,
                                                                       "dd/MM/yyyy", CultureInfo.InvariantCulture);

                    employeeStatus.IsEnd       = false;
                    employeeStatus.EndDate     = DateTime.Now;
                    employeeStatus.Status      = status;
                    employeeStatus.PaymentType = paymentType;

                    employeeStatusRepository.Save(employeeStatus);


                    //Insurance

                    var insurancePrograms = insuranceProgramRepository.GetByInsuranceId(Guid.Empty);

                    foreach (var program in insurancePrograms)
                    {
                        var employeeInsurance = new EmployeeInsurance();

                        employeeInsurance.EmployeeId         = employee.ID;
                        employeeInsurance.InsuranceId        = Guid.Empty;
                        employeeInsurance.InsuranceProgramId = program.ID;

                        employeeInsurance.EffectiveDate = DateTime.ParseExact(jamsostekDate,
                                                                              "dd/MM/yyyy", CultureInfo.InvariantCulture);

                        employeeInsurance.EndDate         = DateTime.Now;
                        employeeInsurance.InsuranceNumber = jamsostekNumber;

                        employeeInsuranceRepository.Save(employeeInsurance);
                    }


                    //Salary

                    var employeeSalary = new EmployeeSalary();

                    employeeSalary.EmployeeId    = employee.ID;
                    employeeSalary.EffectiveDate = DateTime.ParseExact(salaryDate,
                                                                       "dd/MM/yyyy", CultureInfo.InvariantCulture);

                    employeeSalary.MainSalary = Convert.ToDecimal(mainSalary);
                    employeeSalary.OccupationAllowancePerMonth    = Convert.ToDecimal(occupationAllowance);
                    employeeSalary.FixedAllowancePerMonth         = Convert.ToDecimal(fixedAllowance);
                    employeeSalary.HealthAllowancePerMonth        = Convert.ToDecimal(healthAllowance);
                    employeeSalary.CommunicationAllowancePerMonth = Convert.ToDecimal(communicationAllowance);
                    employeeSalary.SupervisionAllowancePerMonth   = Convert.ToDecimal(supervisionAllowance);
                    employeeSalary.OtherAllowance                 = Convert.ToDecimal(otherAllowance);
                    employeeSalary.FuelAllowancePerDays           = Convert.ToDecimal(fuelAllowance);
                    employeeSalary.VehicleAllowancePerDays        = Convert.ToDecimal(vehicleAllowance);
                    employeeSalary.LunchAllowancePerDays          = Convert.ToDecimal(lunchAllowance);
                    employeeSalary.TransportationAllowancePerDays = Convert.ToDecimal(transportAllowance);
                    employeeSalary.JamsostekAmount                = 0;
                    employeeSalary.PersonalDebt = 0;
                    employeeSalary.OtherFee     = 0;

                    employeeSalaryRepository.Save(employeeSalary);


                    UpdateEmployeeCurrentInfo(employee.ID, branch, department, grade, occupation, status, paymentType);
                }
            }

            xlWorkBook.Close(true, null, null);
            xlApp.Quit();

            ReleaseObject(xlWorkSheet);
            ReleaseObject(xlWorkBook);
            ReleaseObject(xlApp);
        }