Beispiel #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);
            }
        }
Beispiel #2
0
        public static DataTable Export(DatabaseConnection dbConn, ArrayList empList, bool IsIncludeCurrentPositionInfo, bool IsShowDescription, bool IsIncludeSyncID, DateTime ReferenceDateTime)
        {
            DataTable tmpDataTable = new DataTable(TABLE_NAME);

            //if (IsIncludeInternalID)
            //    tmpDataTable.Columns.Add(FIELD_INTERNAL_ID, typeof(string));
            tmpDataTable.Columns.Add(FIELD_EMP_NO, typeof(string));

            if (IsIncludeCurrentPositionInfo)
            {
                ImportEmpPersonalInfoProcess.AddEmployeeInfoHeader(tmpDataTable);
                ImportEmpPositionInfoProcess.AddEmployeePositionInfoHeader(dbConn, tmpDataTable);
            }

            tmpDataTable.Columns.Add(FIELD_FROM, typeof(DateTime));
            tmpDataTable.Columns.Add(FIELD_TO, typeof(DateTime));
            if (IsIncludeSyncID)
            {
                tmpDataTable.Columns.Add(FIELD_SYNC_ID, typeof(string));
            }
            tmpDataTable.Columns.Add(FIELD_COST_CENTER + "1", typeof(string));
            tmpDataTable.Columns.Add(FIELD_PERCENTAGE + "1", typeof(double));
            tmpDataTable.Columns.Add(FIELD_COST_CENTER + "2", typeof(string));
            tmpDataTable.Columns.Add(FIELD_PERCENTAGE + "2", typeof(double));


            foreach (EEmpPersonalInfo empInfo in empList)
            {
                if (EEmpPersonalInfo.db.select(dbConn, empInfo))
                {
                    DBFilter filter = new DBFilter();
                    filter.add(new Match("EmpID", empInfo.EmpID));
                    filter.add(getCreateModifiedRecordsAfterDBTerm(ReferenceDateTime));
                    ArrayList list = EEmpCostCenter.db.select(dbConn, filter);
                    foreach (EEmpCostCenter empCostCenter in list)
                    {
                        DataRow row = tmpDataTable.NewRow();
                        //if (IsIncludeInternalID)
                        //    row[FIELD_INTERNAL_ID] = ToHexDecWithCheckDigit(empCostCenter.EmpCostCenterID);
                        row[FIELD_EMP_NO] = empInfo.EmpNo;

                        if (IsIncludeCurrentPositionInfo)
                        {
                            ImportEmpPersonalInfoProcess.AddEmployeeInfo(dbConn, row, empInfo.EmpID);
                            ImportEmpPositionInfoProcess.AddEmployeePositionInfo(dbConn, row, empInfo.EmpID);
                        }

                        row[FIELD_FROM] = empCostCenter.EmpCostCenterEffFr;
                        row[FIELD_TO]   = empCostCenter.EmpCostCenterEffTo;

                        DBFilter costCenterDetailFilter = new DBFilter();
                        costCenterDetailFilter.add(new Match("EmpCostCenterID", empCostCenter.EmpCostCenterID));
                        ArrayList costCenterDetailList = EEmpCostCenterDetail.db.select(dbConn, costCenterDetailFilter);
                        for (int i = 1; i <= costCenterDetailList.Count; i++)
                        {
                            EEmpCostCenterDetail empCostCenterDetail = (EEmpCostCenterDetail)costCenterDetailList[i - 1];
                            if (!tmpDataTable.Columns.Contains(FIELD_COST_CENTER + i))
                            {
                                tmpDataTable.Columns.Add(FIELD_COST_CENTER + i, typeof(string));
                            }

                            if (!tmpDataTable.Columns.Contains(FIELD_PERCENTAGE + i))
                            {
                                tmpDataTable.Columns.Add(FIELD_PERCENTAGE + i, typeof(double));
                            }

                            ECostCenter costCenter = new ECostCenter();
                            costCenter.CostCenterID = empCostCenterDetail.CostCenterID;
                            if (ECostCenter.db.select(dbConn, costCenter))
                            {
                                row[FIELD_COST_CENTER + i] = IsShowDescription ? costCenter.CostCenterDesc : costCenter.CostCenterCode;
                                row[FIELD_PERCENTAGE + i]  = empCostCenterDetail.EmpCostCenterPercentage;
                            }
                        }
                        if (IsIncludeSyncID)
                        {
                            row[FIELD_SYNC_ID] = empCostCenter.SynID;
                        }
                        tmpDataTable.Rows.Add(row);
                    }
                }
            }
            if (IsIncludeCurrentPositionInfo)
            {
                ImportEmpPositionInfoProcess.RetriveHierarchyLevelHeader(dbConn, tmpDataTable);
            }
            return(tmpDataTable);
        }
Beispiel #3
0
    protected void Save_Click(object sender, EventArgs e)
    {
        EEmpCostCenter c = new EEmpCostCenter();

        Hashtable values = new Hashtable();

        binding.toValues(values);

        PageErrors errors = PageErrors.getErrors(db, Page.Master);

        errors.clear();


        db.validate(errors, values);

        if (!errors.isEmpty())
        {
            return;
        }


        db.parse(values, c);

        if (c.EmpCostCenterEffTo.Ticks > 0 && c.EmpCostCenterEffTo < c.EmpCostCenterEffFr)
        {
            errors.addError("EmpCostCenterEffTo", HROne.Translation.PageErrorMessage.ERROR_DATE_TO_TOO_EARLY);
            return;
        }

        AND andTerms = new AND();

        andTerms.add(new Match("EmpCostCenterID", "<>", c.EmpCostCenterID));
        andTerms.add(new Match("EmpCostCenterEffFr", "<=", c.EmpCostCenterEffFr));
        EEmpCostCenter lastObj = (EEmpCostCenter)AppUtils.GetLastObj(dbConn, db, "EmpCostCenterEffFr", c.EmpID, andTerms);

        if (lastObj != null && (c.EmpCostCenterEffFr <= lastObj.EmpCostCenterEffTo || c.EmpCostCenterEffFr == lastObj.EmpCostCenterEffFr))
        {
            errors.addError("EmpCostCenterEffFr", HROne.Translation.PageErrorMessage.ERROR_DATE_FROM_OVERLAP);
            return;
        }

        DBFilter filter = new DBFilter();

        filter.add(new Match("EmpID", c.EmpID));
        filter.add(new Match("EmpCostCenterID", "<>", c.EmpCostCenterID));
        OR  or = new OR();
        AND and;

        and = new AND();
        and.add(new Match("EmpCostCenterEffFr", "<=", c.EmpCostCenterEffFr));
        and.add(new Match("EmpCostCenterEffTo", ">=", c.EmpCostCenterEffFr));
        or.add(and);
        // do not allow early terms without "TO" date
        if (c.EmpCostCenterEffTo.Ticks.Equals(0))
        {
            or.add(new Match("EmpCostCenterEffFr", ">", c.EmpCostCenterEffFr));
        }
        if (c.EmpCostCenterEffTo > DateTime.MinValue)
        {
            and = new AND();
            and.add(new Match("EmpCostCenterEffFr", "<=", c.EmpCostCenterEffTo));
            and.add(new Match("EmpCostCenterEffTo", ">=", c.EmpCostCenterEffTo));
            or.add(and);

            and = new AND();
            and.add(new Match("EmpCostCenterEffFr", ">=", c.EmpCostCenterEffFr));
            and.add(new Match("EmpCostCenterEffFr", "<=", c.EmpCostCenterEffTo));
            or.add(and);
        }
        filter.add(or);
        if (db.count(dbConn, filter) > 0)
        {
            errors.addError(HROne.Translation.PageErrorMessage.ERROR_TERMS_OVERLAP);
        }

        if (!errors.isEmpty())
        {
            return;
        }

        double    totalPercentage = 0;
        ArrayList selectedList    = new ArrayList();
        ArrayList unselectedList  = new ArrayList();

        foreach (RepeaterItem i in Repeater.Items)
        {
            CheckBox    cb      = (CheckBox)i.FindControl("ItemSelect");
            TextBox     textBox = (TextBox)i.FindControl("EmpCostCenterPercentage");
            ECostCenter o       = new ECostCenter();
            WebFormUtils.GetKeys(ECostCenter.db, o, cb);
            if (ECostCenter.db.select(dbConn, o))
            {
                double percentage = 0;
                if (!string.IsNullOrEmpty(textBox.Text.Trim()))
                {
                    if (double.TryParse(textBox.Text, out percentage))
                    {
                        EEmpCostCenterDetail empCostCenterDetail = new EEmpCostCenterDetail();
                        empCostCenterDetail.CostCenterID            = o.CostCenterID;
                        empCostCenterDetail.EmpCostCenterPercentage = percentage;
                        selectedList.Add(empCostCenterDetail);
                        totalPercentage += percentage;
                    }
                    else
                    {
                        errors.addError(string.Format(HROne.Translation.PageErrorMessage.ERROR_COSTCENTER_PERECNTAGE_NOT_NUMERIC, new string[] { o.CostCenterCode }));
                    }
                }
                else
                {
                    unselectedList.Add(o);
                }
            }
        }

        if (Math.Abs(Math.Round(totalPercentage, 2) - 100) >= 0.01)
        {
            errors.addError(HROne.Translation.PageErrorMessage.ERROR_TOTAL_PERCENTAGE_NOT_100);
        }

        if (!errors.isEmpty())
        {
            return;
        }

        WebUtils.StartFunction(Session, FUNCTION_CODE, c.EmpID);
        if (CurID < 0)
        {
//            Utils.MarkCreate(Session, c);

            db.insert(dbConn, c);
            CurID = c.EmpCostCenterID;
//            url = Utils.BuildURL(-1, CurID);
        }
        else
        {
//            Utils.Mark(Session, c);
            db.update(dbConn, c);
        }

        foreach (EEmpCostCenterDetail o in selectedList)
        {
            DBFilter costCenterDetailFilter = new DBFilter();
            costCenterDetailFilter.add(new Match("EmpCostCenterID", c.EmpCostCenterID));
            costCenterDetailFilter.add(new Match("CostCenterID", o.CostCenterID));
            ArrayList empCostCenterDetailList = EEmpCostCenterDetail.db.select(dbConn, costCenterDetailFilter);
            if (empCostCenterDetailList.Count == 0)
            {
                o.EmpCostCenterID = c.EmpCostCenterID;
                EEmpCostCenterDetail.db.insert(dbConn, o);
            }
            else
            {
                int count = 0;
                foreach (EEmpCostCenterDetail empCostCenterDetail in empCostCenterDetailList)
                {
                    if (count == 0)
                    {
                        empCostCenterDetail.EmpCostCenterPercentage = o.EmpCostCenterPercentage;
                        EEmpCostCenterDetail.db.update(dbConn, empCostCenterDetail);
                    }
                    else
                    {
                        EEmpCostCenterDetail.db.delete(dbConn, empCostCenterDetail);
                    }
                    count++;
                }
            }
        }

        foreach (ECostCenter o in unselectedList)
        {
            DBFilter costCenterDetailFilter = new DBFilter();
            costCenterDetailFilter.add(new Match("EmpCostCenterID", c.EmpCostCenterID));
            costCenterDetailFilter.add(new Match("CostCenterID", o.CostCenterID));
            ArrayList costCenterDetailList = EEmpCostCenterDetail.db.select(dbConn, costCenterDetailFilter);
            if (costCenterDetailList.Count != 0)
            {
                foreach (EEmpCostCenterDetail empCostCenterDetail in costCenterDetailList)
                {
                    EEmpCostCenterDetail.db.delete(dbConn, empCostCenterDetail);
                }
            }
        }


        if (lastObj != null)
        {
            if (lastObj.EmpCostCenterEffTo < lastObj.EmpCostCenterEffFr)
            {
                lastObj.EmpCostCenterEffTo = c.EmpCostCenterEffFr.AddDays(-1);
                db.update(dbConn, lastObj);
            }
        }
        WebUtils.EndFunction(dbConn);

        HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "Emp_CostCenter_View.aspx?EmpCostCenterID=" + CurID + "&EmpID=" + c.EmpID);
    }