コード例 #1
0
        //判斷請假時數是否正常
        public (bool isPass, string err_msg) checkLeavehour(int empId, string sortName, double usingtime)
        {
            //找這名員工假別紀錄
            tLeavecount lc_record = db.tLeavecounts
                                    .Where(m => m.fEmployeeId == empId && m.tleavesort.fLeavename == sortName)
                                    .FirstOrDefault();

            //判斷時數是否符合條件
            bool   isPass = true; string err_msg = "";
            double usedtime   = (lc_record == null) ? 0 : lc_record.fUesdtime;
            double remaintime = (lc_record == null) ? 0 : lc_record.fRemaintime;

            switch (sortName)
            {
            case "特休假":
                if ((usingtime + usedtime) >= remaintime)
                {
                    isPass = false; err_msg = "超過特休假上限";
                }
                break;

            case "事假":
                if ((usingtime + usedtime) >= hour_事假)
                {
                    isPass = false; err_msg = "超過事假上限";
                }
                break;

            case "普通傷病假":
                if ((usingtime + usedtime) >= hour_普通傷病假)
                {
                    isPass = false; err_msg = "超過普通傷病假上限";
                }
                break;

            case "婚假":
                if ((usingtime + usedtime) >= hour_婚假)
                {
                    isPass = false; err_msg = "超過婚假上限";
                }
                break;

            case "喪假":
                if ((usingtime + usedtime) >= hour_喪假)
                {
                    isPass = false;
                }
                else
                {
                    err_msg = "超過喪假上限";
                }
                break;

            case "公傷病假":
                isPass = false;
                break;
            }

            return(isPass, err_msg);
        }
コード例 #2
0
        //假別時數累加計算
        public void Leavecount(int empId, string sortName, double usetime)
        {
            //開始日期 = 入職當天
            DateTime startdate = db.tEmployees
                                 .Where(m => m.fEmployeeId == empId)
                                 .FirstOrDefault().fHireDate;

            int sortId = 0; int alltime = 0; DateTime enddate = new DateTime();

            switch (sortName)
            {
            case "特休假":
                sortId  = (int)LeaveSortName.特休假;
                alltime = getLeave_特休假hours(empId);
                enddate = DateTime.Now;
                break;

            case "事假":
                sortId  = (int)LeaveSortName.事假;
                alltime = hour_事假;
                enddate = startdate.AddYears(1);
                break;

            case "普通傷病假":
                sortId  = (int)LeaveSortName.普通傷病假;
                alltime = hour_普通傷病假;
                enddate = startdate.AddYears(1);
                break;

            case "婚假":
                sortId  = (int)LeaveSortName.婚假;
                alltime = hour_婚假;
                break;

            case "喪假":
                sortId  = (int)LeaveSortName.喪假;
                alltime = hour_喪假;
                break;

            case "公傷病假":
                sortId  = (int)LeaveSortName.公傷病假;
                alltime = 0;
                break;
            }

            tLeavecount lc = db.tLeavecounts.Where(m => m.fSortId == sortId && m.fEmployeeId == empId).FirstOrDefault();

            if (lc == null)
            {
                //建立員工假別新紀錄
                tLeavecount leavecount = new tLeavecount()
                {
                    fEmployeeId = empId,
                    fSortId     = sortId,
                    fAlltime    = alltime,
                    fUesdtime   = usetime,
                    fRemaintime = alltime - usetime,
                    fStartdate  = startdate,
                    fEnddate    = enddate
                };
                db.tLeavecounts.Add(leavecount);
                db.SaveChanges();
            }
            else
            {
                //累加上去
                double tmp_remain = lc.fRemaintime;
                double tmp_use    = lc.fUesdtime;
                lc.fUesdtime   = tmp_use + usetime;
                lc.fRemaintime = tmp_remain - usetime;
                db.SaveChanges();
            }
        }