/// <summary>
        /// use this function to modify employment data
        /// </summary>
        /// <param name="headCountHR"></param>
        /// <returns></returns>
        public bool UpdateHeadCountHR(HeadCountHR headCountHR)
        {
            bool   _Success = false;
            string _JobFunctionItem = "", _TitleItem = "";

            //just get item list once can approve performance
            _JobFunctionItem = headCountHR.Account.StartsWith("L") ? "JobFunction" : "JobFunctionKSZ";
            _TitleItem       = headCountHR.Account.StartsWith("L") ? "Title" : "TitleKSZ";
            List <ItemCatalog>             _ItemCatalog = this._itemCatalogService.GetAll().ToList();
            List <Budget_DepartmentReport> _Budget_DepartmentReportList = this._budget_DepartmentReportService.GetAll().ToList();
            Budget_HeadCountHR             _HeadCountHR = this._budget_HeadCountHRService.GetByID(headCountHR.Id);

            _HeadCountHR.Id        = headCountHR.Id;
            _HeadCountHR.Account   = headCountHR.Account;
            _HeadCountHR.AltwName  = headCountHR.AltwName;
            _HeadCountHR.ItemId_HR = _ItemCatalog.Where(x => x.ClassName == "HR" && x.Name.Trim() == headCountHR.HR.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == "HR" && x.Name == headCountHR.HR).First().ItemId : "";

            _HeadCountHR.ItemId_DirectType = _ItemCatalog.Where(x => x.ClassName == "DirectType" && x.Name.Trim() == headCountHR.DirectType.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == "DirectType" && x.Name.Trim() == headCountHR.DirectType.Trim()).First().ItemId : "";

            _HeadCountHR.ItemId_JobFunction = _ItemCatalog.Where(x => x.ClassName == _JobFunctionItem && x.Name.Trim() == headCountHR.JobFunction.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == _JobFunctionItem && x.Name.Trim() == headCountHR.JobFunction.Trim()).First().ItemId : "";

            _HeadCountHR.ItemId_Title = _ItemCatalog.Where(x => x.ClassName == _TitleItem && x.Name.Trim() == headCountHR.Title.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == _TitleItem && x.Name.Trim() == headCountHR.Title.Trim()).First().ItemId : "";

            this._budget_HeadCountHRService.Update(_HeadCountHR);
            _Success = true;
            return(_Success);
        }
Exemple #2
0
        /// <summary>
        /// insertHeadCountHR
        /// </summary>
        /// <param name="headcount"></param>
        /// <param name="itemCatalog"></param>
        /// <param name="newEmployee"></param>
        private void insertHeadCountHR(Headcount headcount, List <ItemCatalog> itemCatalog, string newEmployee)
        {
            string             _JobFunction        = base.Factory == "LT" ? "JobFunction" : "JobFunctionKSZ";
            string             _Title              = base.Factory == "LT" ? "Title" : "TitleKSZ";
            Budget_HeadCountHR _Budget_HeadCountHR = this._budget_HeadCountHRService.GetByName(headcount.AltwName);

            if (_Budget_HeadCountHR == null)
            {
                _Budget_HeadCountHR = new Budget_HeadCountHR();
            }
            string _FactoryType = base.Factory == "LT" ? "L" : "K";

            _Budget_HeadCountHR.Account = this._budget_HeadCountHRService.GetAll().Where(x => x.AltwName == headcount.AltwName).ToList().Count > 0 ? this._budget_HeadCountHRService.GetAll().Where(x => x.AltwName == headcount.AltwName).First().Account : newEmployee;

            _Budget_HeadCountHR.AltwName           = headcount.AltwName;
            _Budget_HeadCountHR.ItemId_DirectType  = itemCatalog.Where(x => x.ClassName == "DirectType" && x.Name.Trim() == headcount.DirectType.Trim()).ToList().Count > 0 ? itemCatalog.Where(x => x.ClassName == "DirectType" && x.Name.Trim() == headcount.DirectType.Trim()).First().ItemId : "";
            _Budget_HeadCountHR.ItemId_JobFunction = itemCatalog.Where(x => x.ClassName == _JobFunction && x.Name.Trim() == headcount.JobFunction.Trim()).ToList().Count > 0 ? itemCatalog.Where(x => x.ClassName == _JobFunction && x.Name.Trim() == headcount.JobFunction.Trim()).First().ItemId : "";
            _Budget_HeadCountHR.ItemId_Title       = itemCatalog.Where(x => x.ClassName == _Title && x.Name.Trim().ToLower() == headcount.Title.Trim().ToLower()).ToList().Count > 0 ? itemCatalog.Where(x => x.ClassName == _Title && x.Name.Trim().ToLower() == headcount.Title.Trim().ToLower()).First().ItemId : "";
            _Budget_HeadCountHR.IsDel = false;
            if (_Budget_HeadCountHR.Id == 0)
            {
                this._budget_HeadCountHRService.Create(_Budget_HeadCountHR);
            }
            else
            {
                this._budget_HeadCountHRService.Update(_Budget_HeadCountHR);
            }
        }
Exemple #3
0
 public void Update(Budget_HeadCountHR instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException();
     }
     this._repository.Update(instance);
 }
        public override Budget Parse(string filePath)
        {
            Budget                       _Budget                 = new Budget();
            List <ItemCatalog>           _ItemCatalog            = this._itemCatalogService.GetAll().ToList();
            List <Budget_HeadCountHR>    _Budget_HeadCountHRList = new List <Budget_HeadCountHR>();
            IQueryable <CustomHeadcount> _CustomHeadcountList;

            LinqToExcel.ExcelQueryFactory _Excel = new LinqToExcel.ExcelQueryFactory(filePath);
            _Excel.AddMapping <CustomHeadcount>(d => d.Account, "Employee Code");
            _Excel.AddMapping <CustomHeadcount>(d => d.AltwName, "Employee Name");
            _Excel.AddMapping <CustomHeadcount>(d => d.HR, "銷/管/研");
            _Excel.AddMapping <CustomHeadcount>(d => d.DirectType, "DL/IDL");
            _Excel.AddMapping <CustomHeadcount>(d => d.Func, "Func");
            _Excel.AddMapping <CustomHeadcount>(d => d.Title, "Title");
            // every time get first sheet data
            _CustomHeadcountList = from x in _Excel.Worksheet <CustomHeadcount>(0)
                                   select x;
            int    _Start       = 2;
            string _JobFunction = base.Factory == "LT" ? "JobFunction" : "JobFunctionKSZ";
            string _Title       = base.Factory == "LT" ? "Title" : "TitleKSZ";

            foreach (CustomHeadcount ch in _CustomHeadcountList)
            {
                try
                {
                    Budget_HeadCountHR _Budget_HeadCountHR = new Budget_HeadCountHR();
                    _Budget_HeadCountHR.Account  = ch.Account;
                    _Budget_HeadCountHR.AltwName = ch.AltwName;
                    string _ItemId_HR = "";
                    if (ch.HR != null && ch.HR != "")
                    {
                        _ItemId_HR = _ItemCatalog.Where(x => x.ClassName == "HR" && x.Name.Trim() == ch.HR.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == "HR" && x.Name == ch.HR).First().ItemId : "";
                    }
                    _Budget_HeadCountHR.ItemId_HR         = _ItemId_HR;
                    _Budget_HeadCountHR.ItemId_DirectType = _ItemCatalog.Where(x => x.ClassName == "DirectType" && x.Name.Trim() == ch.DirectType.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == "DirectType" && x.Name.Trim() == ch.DirectType.Trim()).First().ItemId : "";

                    _Budget_HeadCountHR.ItemId_JobFunction = _ItemCatalog.Where(x => x.ClassName == _JobFunction && x.Name.Trim() == ch.Func.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == _JobFunction && x.Name.Trim() == ch.Func.Trim()).First().ItemId : "";

                    _Budget_HeadCountHR.ItemId_Title = _ItemCatalog.Where(x => x.ClassName == _Title && x.Name.Trim() == ch.Title.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == _Title && x.Name.Trim() == ch.Title.Trim()).First().ItemId : "";

                    _Budget_HeadCountHR.IsDel = false;
                    _Budget_HeadCountHRList.Add(_Budget_HeadCountHR);
                }
                catch (Exception ex)
                {
                    string _Ch = JsonConvert.SerializeObject(ch);
                    this.ListError.Add(" row : " + _Start.ToString() + " , row data has error format:" + ex.Message + "\r\n data:" + _Ch);
                }
                _Start++;
            }
            _Budget.HeadCountHR = _Budget_HeadCountHRList;
            return(_Budget);
        }
        /// <summary>
        /// if you change employee account ,and  synchronize headcount data
        /// </summary>
        /// <param name="headCountHR"></param>
        /// <returns></returns>
        public bool UpdateHeadCount(HeadCountHR headCountHR)
        {
            bool _Success = false;

            try
            {
                Budget_HeadCountHR _HeadCountHR = this._budget_HeadCountHRService.GetByID(headCountHR.Id);
                if (headCountHR.Account != _HeadCountHR.Account)
                {
                    List <Budget_HeadCount> _HeadCountList = this._budget_HeadCountService.GetAll().Where(x => x.Account == _HeadCountHR.Account).ToList();
                    foreach (Budget_HeadCount h in _HeadCountList)
                    {
                        h.Account = headCountHR.Account;
                        this._budget_HeadCountService.Update(h);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            _Success = true;
            return(_Success);
        }