Пример #1
0
        public void ImportToDatabase(int UploadEmpID)
        {
            DBFilter sessionFilter = new DBFilter();

            sessionFilter.add(new Match("SessionID", m_SessionID));
            if (UploadEmpID > 0)
            {
                sessionFilter.add(new Match("UploadEmpID", UploadEmpID));
            }
            ArrayList uploadEmpCostCenterList = tempDB.select(dbConn, sessionFilter);

            foreach (EUploadEmpCostCenter obj in uploadEmpCostCenterList)
            {
                EEmpCostCenter empCostCenter = new EEmpCostCenter();

                if (obj.ImportActionStatus != ImportDBObject.ImportActionEnum.INSERT)
                {
                    empCostCenter.EmpCostCenterID = obj.EmpCostCenterID;
                    uploadDB.select(dbConn, empCostCenter);
                }

                obj.ExportToObject(empCostCenter);

                if (obj.ImportActionStatus == ImportDBObject.ImportActionEnum.INSERT)
                {
                    empCostCenter.EmpID = ParseTemp.GetEmpIDFromUploadEmpID(dbConn, obj.UploadEmpID);
                    EEmpCostCenter lastObj = (EEmpCostCenter)AppUtils.GetLastObj(dbConn, EEmpCostCenter.db, "EmpCostCenterEffFr", empCostCenter.EmpID, new Match("EmpCostCenterEffFr", "<", empCostCenter.EmpCostCenterEffFr));
                    if (lastObj != null)
                    {
                        if (lastObj.EmpCostCenterEffTo.Ticks == 0)
                        {
                            lastObj.EmpCostCenterEffTo = empCostCenter.EmpCostCenterEffFr.AddDays(-1);
                            uploadDB.update(dbConn, lastObj);
                        }
                    }
                    uploadDB.insert(dbConn, empCostCenter);

                    DBFilter uploadEmpCostCenterFilter = new DBFilter();
                    uploadEmpCostCenterFilter.add(new Match("UploadEmpCostCenterID", obj.UploadEmpCostCenterID));
                    ArrayList uploadEmpCostCenterDetailList = EUploadEmpCostCenterDetail.db.select(dbConn, uploadEmpCostCenterFilter);
                    foreach (EUploadEmpCostCenterDetail uploadEmpCostCenterDetail in uploadEmpCostCenterDetailList)
                    {
                        uploadEmpCostCenterDetail.EmpCostCenterID = empCostCenter.EmpCostCenterID;
                        EEmpCostCenterDetail empCostCenterDetail = new EEmpCostCenterDetail();
                        ImportDBObject.CopyObjectProperties(uploadEmpCostCenterDetail, empCostCenterDetail);
                        uploadDetailDB.insert(dbConn, empCostCenterDetail);
                        EUploadEmpCostCenterDetail.db.delete(dbConn, uploadEmpCostCenterDetail);
                    }
                }
                else if (obj.ImportActionStatus == ImportDBObject.ImportActionEnum.UPDATE)
                {
                    uploadDB.update(dbConn, empCostCenter);

                    DBFilter empCostCenterDetailFilter = new DBFilter();
                    empCostCenterDetailFilter.add(new Match("EmpCostCenterID", empCostCenter.EmpCostCenterID));
                    uploadDetailDB.delete(dbConn, empCostCenterDetailFilter);

                    DBFilter uploadEmpCostCenterDetailFilter = new DBFilter();
                    uploadEmpCostCenterDetailFilter.add(new Match("UploadEmpCostCenterID", obj.UploadEmpCostCenterID));
                    ArrayList uploadEmpCostCenterDetailList = EUploadEmpCostCenterDetail.db.select(dbConn, uploadEmpCostCenterDetailFilter);
                    foreach (EUploadEmpCostCenterDetail uploadEmpCostCenterDetail in uploadEmpCostCenterDetailList)
                    {
                        EEmpCostCenterDetail empCostCenterDetail = new EEmpCostCenterDetail();
                        ImportDBObject.CopyObjectProperties(uploadEmpCostCenterDetail, empCostCenterDetail);
                        uploadDetailDB.insert(dbConn, empCostCenterDetail);
                        EUploadEmpCostCenterDetail.db.delete(dbConn, uploadEmpCostCenterDetail);
                    }
                }
                tempDB.delete(dbConn, obj);
            }
        }
        public override DataTable UploadToTempDatabase(string Filename, int UserID, string ZipPassword)
        {
            ClearTempTable();
            DataTable rawDataTable = HROne.Import.ExcelImport.parse(Filename, ZipPassword).Tables[0];
            ArrayList results      = new ArrayList();
            int       rowCount     = 1;

            try
            {
                foreach (DataRow row in rawDataTable.Rows)
                {
                    rowCount++;
                    string EmpNo = row[FIELD_EMP_NO].ToString();
                    int    EmpID = HROne.Import.Parse.GetEmpID(dbConn, EmpNo, UserID);
                    if (EmpID < 0)
                    {
                        errors.addError(ImportErrorMessage.ERROR_ACCESS_DENIED_EMP_NO, new string[] { EmpNo, rowCount.ToString() });
                    }
                    DateTime AsOfDate = Import.Parse.toDateTimeObject(row[FIELD_AS_OF_DATE]);
                    string   RestDayEntitledString   = row[FIELD_REST_DAY_ENTITLED].ToString();
                    string   RestDayTakenString      = row[FIELD_REST_DAY_TAKEN].ToString();
                    string   TotalWorkingDaysString  = row[FIELD_TOTAL_WORKING_DAYS].ToString();
                    string   TotalWorkingHoursString = row[FIELD_TOTAL_WORKING_HOURS].ToString();
                    string   TotalLunchTimeString    = row[FIELD_TOTAL_LUNCH_HOURS].ToString();



                    double RestDayEntitled   = 0;
                    double RestDayTaken      = 0;
                    double TotalWorkingDays  = 0;
                    double TotalWorkingHours = 0;
                    double TotalLunchTime    = 0;


                    EUploadEmpWorkingSummary uploadEmpWorkingSummary = new EUploadEmpWorkingSummary();
                    uploadEmpWorkingSummary.EmpID = EmpID;

                    ArrayList additionUploadRecordList = new ArrayList();

                    if (EmpID > 0 && AsOfDate.Ticks != 0 &&
                        double.TryParse(RestDayEntitledString, out RestDayEntitled) &&
                        double.TryParse(RestDayTakenString, out RestDayTaken) &&
                        double.TryParse(TotalWorkingDaysString, out TotalWorkingDays) &&
                        double.TryParse(TotalWorkingHoursString, out TotalWorkingHours) &&
                        double.TryParse(TotalLunchTimeString, out TotalLunchTime)
                        )
                    {
                        uploadEmpWorkingSummary.EmpWorkingSummaryAsOfDate            = AsOfDate;
                        uploadEmpWorkingSummary.EmpWorkingSummaryRestDayEntitled     = RestDayEntitled;
                        uploadEmpWorkingSummary.EmpWorkingSummaryRestDayTaken        = RestDayTaken;
                        uploadEmpWorkingSummary.EmpWorkingSummaryTotalWorkingDays    = TotalWorkingDays;
                        uploadEmpWorkingSummary.EmpWorkingSummaryTotalWorkingHours   = TotalWorkingHours;
                        uploadEmpWorkingSummary.EmpWorkingSummaryTotalLunchTimeHours = TotalLunchTime;
                        uploadEmpWorkingSummary.SessionID       = m_SessionID;
                        uploadEmpWorkingSummary.TransactionDate = UploadDateTime;
                        results.Add(uploadEmpWorkingSummary);

                        DBFilter dbFilter = new DBFilter();
                        dbFilter.add(new Match("EmpID", uploadEmpWorkingSummary.EmpID));
                        dbFilter.add(new Match("EmpWorkingSummaryAsOfDate", uploadEmpWorkingSummary.EmpWorkingSummaryAsOfDate));

                        ArrayList list = EEmpWorkingSummary.db.select(dbConn, dbFilter);
                        foreach (EEmpWorkingSummary empWorkingSummary in list)
                        {
                            if (uploadEmpWorkingSummary.EmpWorkingSummaryID.Equals(0))
                            {
                                uploadEmpWorkingSummary.EmpWorkingSummaryID = empWorkingSummary.EmpWorkingSummaryID;
                            }
                            else
                            {
                                //  Set Next Existing record to 0;
                                EUploadEmpWorkingSummary uploadNextWorkingSummary = new EUploadEmpWorkingSummary();
                                ImportDBObject.CopyObjectProperties(empWorkingSummary, uploadNextWorkingSummary);

                                uploadNextWorkingSummary.EmpWorkingSummaryRestDayEntitled     = RestDayEntitled;
                                uploadNextWorkingSummary.EmpWorkingSummaryRestDayTaken        = RestDayTaken;
                                uploadNextWorkingSummary.EmpWorkingSummaryTotalWorkingDays    = TotalWorkingDays;
                                uploadNextWorkingSummary.EmpWorkingSummaryTotalWorkingHours   = TotalWorkingHours;
                                uploadNextWorkingSummary.EmpWorkingSummaryTotalLunchTimeHours = TotalLunchTime;

                                uploadNextWorkingSummary.SessionID          = m_SessionID;
                                uploadNextWorkingSummary.TransactionDate    = UploadDateTime;
                                uploadNextWorkingSummary.ImportActionStatus = ImportDBObject.ImportActionEnum.UPDATE;

                                additionUploadRecordList.Add(uploadNextWorkingSummary);
                            }
                        }
                    }
                    else
                    {
                        double doubleValue;
                        if (EmpID == 0)
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_EMP_NO, new string[] { EmpNo, rowCount.ToString() });
                        }
                        else if (AsOfDate.Ticks == 0)
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_AS_OF_DATE + "=" + row[FIELD_AS_OF_DATE], EmpNo, rowCount.ToString() });
                        }
                        else if (!double.TryParse(RestDayEntitledString, out doubleValue))
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_REST_DAY_ENTITLED + "=" + RestDayEntitledString, EmpNo, rowCount.ToString() });
                        }
                        else if (!double.TryParse(RestDayTakenString, out doubleValue))
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_REST_DAY_TAKEN + "=" + RestDayTakenString, EmpNo, rowCount.ToString() });
                        }
                        else if (!double.TryParse(TotalWorkingDaysString, out doubleValue))
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_TOTAL_WORKING_DAYS + "=" + TotalWorkingDaysString, EmpNo, rowCount.ToString() });
                        }
                        else if (!double.TryParse(TotalWorkingHoursString, out doubleValue))
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_TOTAL_WORKING_HOURS + "=" + TotalWorkingHoursString, EmpNo, rowCount.ToString() });
                        }
                        else if (!double.TryParse(TotalLunchTimeString, out doubleValue))
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_TOTAL_LUNCH_HOURS + "=" + TotalLunchTimeString, EmpNo, rowCount.ToString() });
                        }
                    }

                    if (uploadEmpWorkingSummary.EmpWorkingSummaryID <= 0)
                    {
                        uploadEmpWorkingSummary.ImportActionStatus = ImportDBObject.ImportActionEnum.INSERT;
                    }
                    else
                    {
                        uploadEmpWorkingSummary.ImportActionStatus = ImportDBObject.ImportActionEnum.UPDATE;
                    }

                    if (errors.List.Count == 0)
                    {
                        Hashtable values = new Hashtable();
                        tempDB.populate(uploadEmpWorkingSummary, values);
                        PageErrors pageErrors = new PageErrors(tempDB);
                        tempDB.validate(pageErrors, values);
                        if (pageErrors.errors.Count == 0)
                        {
                            tempDB.insert(dbConn, uploadEmpWorkingSummary);
                            foreach (EUploadEmpWorkingSummary uploadNextWorkingSummary in additionUploadRecordList)
                            {
                                tempDB.insert(dbConn, uploadNextWorkingSummary);
                            }
                        }
                        else
                        {
                            pageErrors.addError(rawDataTable.TableName);
                            throw new HRImportException(pageErrors.getPrompt() + "(line " + rowCount.ToString() + ")");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                errors.addError(e.Message, null);
            }
            if (errors.List.Count > 0)
            {
                ClearTempTable();
                throw (new HRImportException(rawDataTable.TableName + "\r\n" + errors.Message()));
            }
            return(GetImportDataFromTempDatabase(null));
        }