Example #1
0
        public ActionResult CreateLeave(VMCreateLeave vMCLeave)
        {
            //請假
            tLeave tLeave = new tLeave();

            tLeave.fEmployeeId = vMCLeave.employee.id;
            tLeave.fSort       = vMCLeave.leavesort;
            tLeave.fApplyDate  = DateTime.Now;
            tLeave.fActiveDate = vMCLeave.start;
            tLeave.fEndDate    = vMCLeave.end;
            tLeave.fTimeCount  = vMCLeave.timecount;
            tLeave.fReason     = vMCLeave.reason;

            db.tLeaves.Add(tLeave);
            db.SaveChanges();


            //簽核表
            tSignoff tSignoff = new tSignoff();

            tSignoff.fLeaveId = int.Parse(db.tLeaves
                                          .OrderByDescending(p => p.fId)
                                          .Select(r => r.fId)
                                          .First().ToString());
            tSignoff.fSupervisorId = Convert.ToInt32(vMCLeave.supervisorId);
            tSignoff.fApplyClass   = vMCLeave.leavesort;
            tSignoff.fStartdate    = DateTime.Now;
            tSignoff.fEnddate      = vMCLeave.start;

            db.tSignoffs.Add(tSignoff);
            db.SaveChanges();

            return(RedirectToAction("AttendIndex"));
        }
Example #2
0
        public ActionResult CreateLeave(VMLeave leave)
        {
            VMEmployee Emp = getLoginEmpData();

            //檢查時數是否超過
            var checkLeave = (new CLeaveHelper()).checkLeavehour(Emp.id, leave.leavesort, leave.timecount);

            if (checkLeave.isPass)
            {
                //請假儲存
                tLeave tLeave = new tLeave();
                tLeave.fEmployeeId = Emp.id;
                tLeave.fSort       = leave.leavesort;
                tLeave.fApplyDate  = DateTime.Now;
                tLeave.fActiveDate = leave.start;
                tLeave.fEndDate    = leave.end;
                tLeave.fTimeCount  = leave.timecount;
                tLeave.fReason     = leave.reason;

                db.tLeaves.Add(tLeave);
                db.SaveChanges();

                //簽核表
                tSignoff tSignoff = new tSignoff();
                tSignoff.fLeaveId = int.Parse(db.tLeaves
                                              .OrderByDescending(p => p.fId)
                                              .Select(r => r.fId)
                                              .First().ToString());
                tSignoff.fSupervisorId = leave.supervisorId;
                tSignoff.fApplyClass   = leave.leavesort;
                tSignoff.fStartdate    = DateTime.Now;
                tSignoff.fEnddate      = leave.start;

                db.tSignoffs.Add(tSignoff);
                db.SaveChanges();

                //通知
                //tNotify notify = new tNotify();
                //notify.fEmployeeId = Convert.ToInt32(leave.supervisorId);
                //notify.fTitle = "員工請假申請通知";
                //notify.fContent = "員工 " + Emp.name + " 申請" + leave.leavesort;
                //notify.fType = 0;
                //notify.fTime = DateTime.Now;
                //notify.fSort = leave.leavesort;

                //db.tNotifies.Add(notify);
                //db.SaveChanges();

                TempData["Attend_msg"] = leave.leavesort + " 申請成功";

                return(RedirectToAction("AttendIndex", "Attend"));
            }
            else
            {
                TempData["Attend_err_msg"] = checkLeave.err_msg;

                return(RedirectToAction("LeaveIndex", "Attend_Leave"));
            }
        }
Example #3
0
        public ActionResult Editpass(int id, int agree)
        {
            //資料庫更新
            tSignoff signoff = db.tSignoffs.Where(m => m.fId == id).FirstOrDefault();

            signoff.fIsAgreed = agree;        //通過 不通過
            signoff.fPassdate = DateTime.Now; //通過日期

            //list更新
            var target = list.Where(m => m.id == id).FirstOrDefault();

            target.isagreed = agree;
            target.passdate = DateTime.Now.ToString("yyyy-MM-dd hh:mm");

            //通過審核
            if (agree == 1)
            {
                if (target.catelog == "請假申請")
                {
                    //儲存假別紀錄
                    int    empId    = signoff.tLeave.fEmployeeId;
                    string sortName = signoff.tLeave.fSort;
                    double useTime  = signoff.tLeave.fTimeCount;
                    (new CLeaveHelper()).Leavecount(empId, sortName, useTime);

                    createNotifies(empId, "審核通過", "申請" + sortName + "已通過審核");
                }
                if (target.catelog == "補打卡申請")
                {
                    //儲存假別紀錄
                    int empId = signoff.tApplypunch.fEmployeeId;
                    //修改打卡紀錄
                    int    punchtimeId = signoff.tApplypunch.fPunchTimeId;
                    string status      = "已補打卡";

                    tPunchtime punchtime = db.tPunchtimes
                                           .Where(m => m.fId == punchtimeId)
                                           .FirstOrDefault();

                    punchtime.fstatus = status;

                    createNotifies(empId, "審核通過", "申請補打卡" + punchtime.fDatetime + "已通過審核");
                }
                if (target.catelog == "加班申請")
                {
                    //儲存假別紀錄
                    int    empId    = signoff.tOvertime.fEmployeeId;
                    string sortName = signoff.tOvertime.fSort;

                    createNotifies(empId, "審核通過", "申請" + sortName + "已通過審核");
                }
            }

            db.SaveChanges();

            return(Json("success", JsonRequestBehavior.AllowGet));
        }
        public string Create(tProjectDetail target)
        {
            TempData.Keep();
            var prjId = TempData["prjId"] as int?;

            if (target.fTaskName == null || target.fEmployeeId == null)
            {
                //任務名稱不為空
                return("error");
            }

            tProjectDetail prjDetail = new tProjectDetail();

            prjDetail.fProjectId  = target.fProjectId;
            prjDetail.fLevelId    = target.fLevelId;
            prjDetail.fTaskName   = target.fTaskName;
            prjDetail.fEmployeeId = target.fEmployeeId;
            prjDetail.fStatus     = target.fStatus;
            prjDetail.fStartTime  = target.fStartTime;
            prjDetail.fDeadline   = target.fDeadline;
            prjDetail.fRemarks    = target.fRemarks;
            prjDetail.fTimes      = 0;
            db.tProjectDetails.Add(prjDetail);
            db.SaveChanges();

            updateProgress(prjDetail.fProjectId);

            var startTime = prjDetail.fStartTime;
            var deadline  = prjDetail.fDeadline;

            //發通知給任務負責人
            tNotify notify = new tNotify();

            notify.fEmployeeId = Convert.ToInt32(prjDetail.fEmployeeId);
            notify.fTitle      = prjDetail.tProject.fProjectName;
            notify.fContent    = "請到我的任務查看新任務";
            notify.fType       = 0;
            notify.fTime       = DateTime.Now;
            db.tNotifies.Add(notify);
            db.SaveChanges();

            //存到行事曆上
            tCalendar task = new tCalendar();

            task.fEmployeeId = prjDetail.fEmployeeId;
            task.fStart      = Convert.ToDateTime(startTime).ToString("yyyy-MM-dd");
            task.fEnd        = Convert.ToDateTime(deadline).ToString("yyyy-MM-dd");
            task.fTitle      = db.tProjects.Where(p => p.fProjectId == prjDetail.fProjectId).FirstOrDefault().fProjectName;
            task.fContent    = prjDetail.fTaskName;
            task.fSort       = "1";
            db.tCalendars.Add(task);
            db.SaveChanges();

            return("success");
        }
Example #5
0
        public string InsertCalendar(string id, string start, string end, string title, string content)
        {
            HttpCookie     cookie = Request.Cookies["id"];
            int            empid  = Convert.ToInt32(cookie.Value);
            EIP_DBEntities db     = new EIP_DBEntities();
            string         json   = "";
            IQueryable     list;

            if (string.IsNullOrEmpty(id))
            {
                tCalendar tc = new tCalendar();
                tc.fTitle      = title;
                tc.fContent    = content;
                tc.fStart      = start;
                tc.fEnd        = end;
                tc.fEmployeeId = empid;
                tc.fSort       = "0";
                db.tCalendars.Add(tc);
                db.SaveChanges();
                list = from c in db.tCalendars
                       where c.fEmployeeId == tc.fEmployeeId
                       select new {
                    c.fId,
                    c.fTitle,
                    c.fStart,
                    c.fEnd,
                    c.fSort
                };
                json = JsonConvert.SerializeObject(list);
                return(json);
            }
            //現有行事曆
            int fid   = Convert.ToInt32(id);
            var listu = (db.tCalendars.Where(x => x.fId == fid)).FirstOrDefault();

            listu.fStart   = start;
            listu.fEnd     = end;
            listu.fTitle   = title;
            listu.fContent = content;
            db.SaveChanges();
            list = from c in db.tCalendars
                   where c.fEmployeeId == empid
                   select new
            {
                c.fId,
                c.fContent,
                c.fTitle,
                c.fStart,
                c.fEnd,
                c.fSort
            };
            json = JsonConvert.SerializeObject(list);
            return(json);
        }
Example #6
0
        public string InsertBoard(string id, string title, string content, string type)
        {
            string         json   = "";
            HttpCookie     cookie = Request.Cookies["id"];
            tBillboard     tb     = new tBillboard();
            IQueryable     list;
            EIP_DBEntities db = new EIP_DBEntities();

            if (string.IsNullOrEmpty(id))
            {
                tb.fContent    = content;
                tb.fTitle      = title;
                tb.fType       = type;
                tb.fPostTime   = DateTime.Now.ToString();
                tb.fEmployeeId = Convert.ToInt32(cookie.Value);
                db.tBillboards.Add(tb);
                db.SaveChanges();
                list = from b in db.tBillboards
                       select new
                {
                    b.fId,
                    b.fTitle,
                    b.fContent,
                    b.fPostTime,
                    b.fEmployeeId,
                    b.fType
                };
                json = JsonConvert.SerializeObject(list);
                return(json);
            }
            int fid   = Convert.ToInt32(id);
            var listu = (db.tBillboards.Where(x => x.fId == fid)).FirstOrDefault();

            listu.fContent  = content;
            listu.fTitle    = title;
            listu.fType     = type;
            listu.fPostTime = DateTime.Now.ToString();
            db.SaveChanges();
            list = from b in db.tBillboards
                   select new
            {
                b.fId,
                b.fTitle,
                b.fContent,
                b.fPostTime,
                b.fEmployeeId,
                b.fType
            };
            json = JsonConvert.SerializeObject(list);
            return(json);
        }
Example #7
0
        public string Create(tProject target)
        {
            //------新增專案-----------//
            tProject prj = new tProject();

            prj.fProjectId     = target.fProjectId;
            prj.fProjectName   = target.fProjectName;
            prj.fClient        = target.fClient;
            prj.fPrice         = target.fPrice;
            prj.fCreatdDate    = target.fCreatdDate;
            prj.fDateline      = target.fDateline;
            prj.fEmployeeId    = target.fEmployeeId;
            prj.fProgress      = 0;
            prj.fPaymentStatus = "未收款";

            db.tProjects.Add(prj);
            db.SaveChanges();

            //------新增專案預算書------//
            tBudget budget = new tBudget();

            budget.fProjectId = target.fProjectId;
            db.tBudgets.Add(budget);
            db.SaveChanges();

            //---------新增階段表------//
            //預設為三階段//
            //todo:讓使用者自訂階段數量及名稱

            tLevel level1 = new tLevel();

            level1.fProjectId    = prj.fProjectId;
            level1.fLevelName    = "規劃";
            level1.fEstimateTime = 0;

            tLevel level2 = new tLevel();

            level2.fProjectId    = prj.fProjectId;
            level2.fLevelName    = "開發";
            level2.fEstimateTime = 0;

            tLevel level3 = new tLevel();

            level3.fProjectId    = prj.fProjectId;
            level3.fLevelName    = "測試";
            level3.fEstimateTime = 0;

            db.tLevels.Add(level1);
            db.tLevels.Add(level2);
            db.tLevels.Add(level3);
            db.SaveChanges();

            return("success");
        }
Example #8
0
        public string InsertBell(string title, string content)
        {
            HttpCookie cookie = Request.Cookies["id"];
            int        fid    = Convert.ToInt32(cookie.Value);
            tNotify    tn     = new tNotify();

            tn.fContent    = content;
            tn.fTitle      = title;
            tn.fType       = 0;
            tn.fEmployeeId = 100;
            EIP_DBEntities db = new EIP_DBEntities();

            db.tNotifies.Add(tn);
            db.SaveChanges();
            var list = from n in db.tNotifies
                       where n.fEmployeeId == fid
                       select new
            {
                n.fTitle,
                n.fContent,
                n.fType
            };
            string json = JsonConvert.SerializeObject(list);

            return(json);
        }
Example #9
0
        public string RemoveCalendar(string id)
        {
            HttpCookie     cookie = Request.Cookies["id"];
            int            empid  = Convert.ToInt32(cookie.Value);
            int            fid    = Convert.ToInt32(id);
            string         json   = "";
            EIP_DBEntities db     = new EIP_DBEntities();
            var            del    = (from c in db.tCalendars
                                     where c.fId == fid
                                     select c).FirstOrDefault();

            db.tCalendars.Remove(del);
            db.SaveChanges();
            var list = from b in db.tCalendars
                       where b.fEmployeeId == empid
                       select new
            {
                b.fId,
                b.fContent,
                b.fStart,
                b.fEnd,
                b.fTitle,
            };

            json = JsonConvert.SerializeObject(list);
            return(json);
        }
Example #10
0
        public string RemoveBoard(string id)
        {
            HttpCookie     cookie = Request.Cookies["id"];
            int            fid    = Convert.ToInt32(id);
            string         json   = "";
            EIP_DBEntities db     = new EIP_DBEntities();
            var            del    = (from c in db.tBillboards
                                     where c.fId == fid
                                     select c).FirstOrDefault();

            db.tBillboards.Remove(del);
            db.SaveChanges();
            var list = from b in db.tBillboards
                       select new
            {
                b.fId,
                b.fContent,
                b.fTitle,
                b.fType,
                b.fEmployeeId,
                b.fPostTime
            };

            json = JsonConvert.SerializeObject(list);
            return(json);
        }
Example #11
0
        public string UpdateBell(string id)
        {
            HttpCookie     cookie      = Request.Cookies["id"];
            int            fEmployeeId = Convert.ToInt32(cookie.Value);
            int            fid         = Convert.ToInt32(id);
            EIP_DBEntities db          = new EIP_DBEntities();
            var            listt       = (from n in db.tNotifies
                                          where n.fId == fid
                                          select n).FirstOrDefault();

            listt.fType = 1;
            db.SaveChanges();
            var list = from n in db.tNotifies
                       where n.fEmployeeId == fEmployeeId
                       select new
            {
                n.fId,
                n.fType,
                n.fTitle,
                n.fContent,
                n.fTime
            };
            string json = JsonConvert.SerializeObject(list);

            return(json);
        }
Example #12
0
        public string UpdateBell(string type)
        {
            HttpCookie     cookie = Request.Cookies["id"];
            int            fid    = Convert.ToInt32(cookie.Value);
            EIP_DBEntities db     = new EIP_DBEntities();
            var            listt  = from n in db.tNotifies
                                    where n.fType == 0 && n.fEmployeeId == fid
                                    select n;

            foreach (var item in listt)
            {
                item.fType = Convert.ToInt32(type);
            }
            db.SaveChanges();
            var list = from n in db.tNotifies
                       where n.fEmployeeId == fid
                       select new
            {
                n.fType,
                n.fTitle,
                n.fContent
            };
            string json = JsonConvert.SerializeObject(list);

            return(json);
        }
Example #13
0
        public string InsertBell(string title, string content, string id)
        {
            int     fid = Convert.ToInt32(id);
            tNotify tn  = new tNotify();

            tn.fContent    = content;
            tn.fTitle      = title;
            tn.fType       = 0;
            tn.fTime       = DateTime.Now;
            tn.fEmployeeId = fid;
            EIP_DBEntities db = new EIP_DBEntities();

            db.tNotifies.Add(tn);
            db.SaveChanges();
            var list = from n in db.tNotifies
                       where n.fEmployeeId == fid
                       select new
            {
                n.fTime,
                n.fTitle,
                n.fContent,
                n.fType
            };
            string json = JsonConvert.SerializeObject(list);

            return(json);
        }
Example #14
0
        public ActionResult punchTimeApply(VMPunchtimeApply applyPunchtime)
        {
            VMEmployee Emp = getLoginEmpData();

            //用完申請紀錄
            if (EmpApplyPunchtimeCount(Emp.id) == 0)
            {
                return(Json("error", JsonRequestBehavior.AllowGet));
            }
            //重複申請
            if (db.tApplypunches.Where(m => m.fPunchTimeId == applyPunchtime.applyId).FirstOrDefault() != null)
            {
                return(Json("same", JsonRequestBehavior.AllowGet));
            }

            //申請補打卡
            tApplypunch Applypunch = new tApplypunch();

            Applypunch.fEmployeeId  = Emp.id;
            Applypunch.fPunchTimeId = applyPunchtime.applyId;
            Applypunch.fApplyDate   = DateTime.Now;
            Applypunch.fSort        = applyPunchtime.sort;
            Applypunch.fReason      = applyPunchtime.reason;

            db.tApplypunches.Add(Applypunch);
            db.SaveChanges();

            //簽核表 3天內審核完成
            tSignoff tSignoff = new tSignoff();

            tSignoff.fAlpplypunchId = int.Parse(db.tApplypunches
                                                .OrderByDescending(p => p.fId)
                                                .Select(r => r.fId)
                                                .First().ToString());
            tSignoff.fSupervisorId = applyPunchtime.supervisorId;
            tSignoff.fApplyClass   = applyPunchtime.sort;
            tSignoff.fStartdate    = DateTime.Now;
            tSignoff.fEnddate      = DateTime.Now.AddDays(3);

            db.tSignoffs.Add(tSignoff);
            db.SaveChanges();

            return(Json("success", JsonRequestBehavior.AllowGet));
        }
        //審核工時紀錄
        public ActionResult Edit(int recordId, int approve, string reason)
        {
            var record = db.tTimeRecords.Where(p => p.fTimeRecordId == recordId).FirstOrDefault();
            var task   = db.tProjectDetails.Where(p => p.fProjectDetailId == record.fProjectDetailId).FirstOrDefault();
            var level  = db.tLevels.Where(p => p.fLevelId == task.fLevelId).FirstOrDefault();

            if (approve == 1)
            {
                record.fApprove = "同意";
                //時數存入tProjectDetail
                task.fTimes += record.fTime;
                //人事成本存入tlevel
                level.fSpendCost += record.fTime * 200;
            }

            if (approve == 0)
            {
                record.fApprove = "不同意";
                record.fRemarks = reason;

                //發小鈴鐺訊息給員工
                tNotify notify = new tNotify();
                notify.fEmployeeId = record.fEmployeeId;
                notify.fTitle      = "工時紀錄審查不通過";
                notify.fContent    = "請盡快修正紀錄";
                notify.fType       = 0;
                notify.fTime       = DateTime.Now;
                db.tNotifies.Add(notify);
                db.SaveChanges();
            }

            db.SaveChanges();

            return(Json("success", JsonRequestBehavior.AllowGet));
        }
Example #16
0
        public ActionResult Create(tTimeRecord target)
        {
            //todo:若新增時輸入資料錯誤 驗證
            //var prj = db.tProjects.Where(p => p.fProjectId == target.fProjectId).FirstOrDefault();
            //if (prj == null)
            //    return RedirectToAction("Index");

            //新增
            //todo:改成當前員編
            tTimeRecord record = new tTimeRecord();

            record.fDate            = todayDate;
            record.fEmployeeId      = 100;
            record.fProjectId       = target.fProjectId;
            record.fProjectDetailId = target.fProjectDetailId;
            record.fTime            = target.fTime;
            //record.fApprove = "否";

            db.tTimeRecords.Add(record);
            db.SaveChanges();
            return(Json("success", JsonRequestBehavior.AllowGet));
        }
Example #17
0
        public string Create(tProjectDetail target)
        {
            TempData.Keep();
            var prjId = TempData["prjId"] as int?;

            tProjectDetail prjDetail = new tProjectDetail();

            prjDetail.fProjectId  = target.fProjectId;                //todo:改當前案號
            prjDetail.fLevelId    = target.fLevelId;
            prjDetail.fTaskName   = target.fTaskName;
            prjDetail.fEmployeeId = 100;                              //todo:改下拉式選單的員工(tmember)
            prjDetail.fStatus     = target.fStatus;
            prjDetail.fStartTime  = target.fStartTime;
            prjDetail.fDeadline   = target.fDeadline;
            prjDetail.fRemarks    = target.fRemarks;
            db.tProjectDetails.Add(prjDetail);
            db.SaveChanges();

            updateProgress(prjDetail.fProjectId);

            return("success");
        }
Example #18
0
        public ActionResult Create(tTimeRecord target)
        {
            //todo:若新增時輸入資料錯誤 驗證
            //var prj = db.tProjects.Where(p => p.fProjectId == target.fProjectId).FirstOrDefault();
            //if (prj == null)
            //    return RedirectToAction("Index");

            HttpCookie cookie = Request.Cookies["id"];
            int        user   = Convert.ToInt32(cookie.Value);

            tTimeRecord record = new tTimeRecord();

            record.fDate            = todayDate;
            record.fEmployeeId      = user;
            record.fProjectId       = target.fProjectId;
            record.fProjectDetailId = target.fProjectDetailId;
            record.fTime            = target.fTime;

            db.tTimeRecords.Add(record);
            db.SaveChanges();
            return(Json("success", JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(tMetting_date data)
        {
            var new_date = db.tMetting_date.FirstOrDefault(p => p.fId == data.fId);
            var old_time = db.tMetting_date.Where(p => p.fDate == data.fDate && p.fRoom == data.fRoom && p.fId != data.fId).Select(p => new { p.fStarttime, p.fEndtime });

            if (data == null)
            {
                return(RedirectToAction("Index"));
            }
            is_空白驗證(data);
            if (old_time.Count() != 0)
            {
                foreach (var old in old_time)
                {
                    if (data.fStarttime < old.fEndtime && data.fEndtime > old.fStarttime)
                    {
                        this.ModelState.AddModelError("fEndtime", "跟其他時間選擇衝突到,請重新選擇請選擇時間");
                        break;
                    }
                }
            }
            var b = Convert.ToDateTime(data.fDate).DayOfWeek.ToString();

            if (b == "Sunday" || b == "Saturday" || DateTime.Now.Date > Convert.ToDateTime(data.fDate))
            {
                this.ModelState.AddModelError("fDate", "請勿選六日時間");
            }

            if (this.ModelState.IsValid)
            {
                new_date.fDate      = data.fDate;
                new_date.fStarttime = data.fStarttime;
                new_date.fEndtime   = data.fEndtime;
                new_date.fReason    = data.fReason;
                db.SaveChanges();
                return(RedirectToAction("mettingIndex", new { message = "編輯成功", fid = data.fId }));
            }
            return(RedirectToAction("mettingIndex", new { message = "除前端還有後端驗證!!!!" }));
        }
        public ActionResult Edit(int recordId, int approve)
        {
            //修改審核狀態
            var record = db.tTimeRecords.Where(p => p.fTimeRecordId == recordId).FirstOrDefault();

            if (approve == 1)
            {
                record.fApprove = "同意";
            }

            if (approve == 0)
            {
                record.fApprove = "不同意";
            }

            db.SaveChanges();

            return(Json("success", JsonRequestBehavior.AllowGet));
        }
        public ActionResult Editpass(int id, int agree)
        {
            //資料庫更新
            tSignoff signoff = db.tSignoffs.Where(m => m.fId == id).FirstOrDefault();

            signoff.fIsAgreed = agree;        //通過 不通過
            signoff.fPassdate = DateTime.Now; //通過日期

            //更新員工假別紀錄


            //list更新
            var target = list.Where(m => m.id == id).FirstOrDefault();

            target.isagreed = agree;
            target.passdate = DateTime.Now.ToString("yyyy-MM-dd hh:mm");

            db.SaveChanges();

            return(Json("success", JsonRequestBehavior.AllowGet));
        }
Example #22
0
        public ActionResult submitRevoke(int id)
        {
            //移除資料
            tSignoff tSignoff = db.tSignoffs.Where(m => m.fId == id).FirstOrDefault();

            int attend_id = 0;

            if (tSignoff.fLeaveId != null)
            {
                //請假
                attend_id = (int)tSignoff.fLeaveId;
                db.tLeaves.Remove(db.tLeaves.Where(m => m.fId == attend_id).FirstOrDefault());
            }
            else if (tSignoff.fOvertimeId != null)
            {
                //加班
                attend_id = (int)tSignoff.fOvertimeId;
                db.tOvertimes.Remove(db.tOvertimes.Where(m => m.fId == attend_id).FirstOrDefault());
            }
            else
            {
                //補打卡
                attend_id = (int)tSignoff.fAlpplypunchId;
                db.tApplypunches.Remove(db.tApplypunches.Where(m => m.fId == attend_id).FirstOrDefault());
            }

            db.tSignoffs.Remove(tSignoff);
            db.SaveChanges();

            //Emp_list 移除資料
            var target = Emp_list.Where(m => m.id == id).FirstOrDefault();

            Emp_list.Remove(target);

            return(Json("success", JsonRequestBehavior.AllowGet));
        }
Example #23
0
        public ActionResult CreateOverTime(tOvertime o, tSignoff s, tEmployee t)
        {
            HttpCookie cookie = Request.Cookies["id"];
            int        u      = Convert.ToInt32(cookie.Value);
            int        fakeid = u;

            Emp = (new VMEmployee())
                  .convert(db.tEmployees
                           .Where(m => m.fEmployeeId == fakeid)
                           .FirstOrDefault());

            //ViewBag 傳前端
            ViewBag.emp = Newtonsoft.Json.JsonConvert.SerializeObject(Emp);
            //撈資料庫當月
            double TimeCountForMonth = (from a in db.tOvertimes.AsEnumerable()
                                        join ts4 in db.tSignoffs.AsEnumerable()
                                        on a.fId equals ts4.fOvertimeId
                                        where a.fActiveDate.Year == DateTime.Now.Year &&
                                        a.fActiveDate.Month == DateTime.Now.Month &&
                                        a.fEmployeeId == fakeid &&
                                        ts4.fIsAgreed == 1
                                        select a.fTimeCount).DefaultIfEmpty(0).Sum();

            ////撈資料庫上個月
            //double TimeCountLastMonth = (from a in db.tOvertimes.AsEnumerable()
            //                              where a.fActiveDate.Year == DateTime.Now.Year
            //                              && a.fActiveDate.Month == DateTime.Now.AddMonths(-1).Month
            //                              && a.fEmployeeId == fakeid
            //                              select a.fTimeCount).Sum();
            ////撈資料庫上上個月
            //double TimeCountBeforeLastMonth = (from a in db.tOvertimes.AsEnumerable()
            //                                   where a.fActiveDate.Year == DateTime.Now.Year
            //                                   && a.fActiveDate.Month == DateTime.Now.AddMonths(-2).Month
            //                                   && a.fEmployeeId == fakeid
            //                                   select a.fTimeCount).Sum();
            if (string.IsNullOrEmpty(o.fSort) || string.IsNullOrEmpty(o.fReason))
            {
                TempData["Attend_msg"] = "請輸入加班類別或原因";
                return(View());
            }
            //本日加班查詢
            int    NowDateMonth   = o.fActiveDate.Month;
            int    NowDate        = o.fActiveDate.Day;
            double TimeCountToday = (from a in db.tOvertimes.AsEnumerable()
                                     join ts5 in db.tSignoffs.AsEnumerable()
                                     on a.fId equals ts5.fOvertimeId
                                     where a.fActiveDate.Month == NowDateMonth &&
                                     a.fActiveDate.Day == NowDate &&
                                     a.fEmployeeId == fakeid &&
                                     ts5.fIsAgreed == 1
                                     select a.fTimeCount).DefaultIfEmpty().Sum() + o.fTimeCount;
            //三個月加班合計
            //本月
            double TimeCountOne = (from b in db.tOvertimes.AsEnumerable()
                                   join ts6 in db.tSignoffs.AsEnumerable()
                                   on b.fId equals ts6.fOvertimeId
                                   where b.fActiveDate.Year == DateTime.Now.Year &&
                                   b.fActiveDate.Month == DateTime.Now.Month &&
                                   b.fEmployeeId == fakeid &&
                                   ts6.fIsAgreed == 1
                                   select b.fTimeCount).Sum();
            //上月
            double TimeCountTwo = (from c in db.tOvertimes.AsEnumerable()
                                   join ts7 in db.tSignoffs.AsEnumerable()
                                   on c.fId equals ts7.fOvertimeId
                                   where c.fActiveDate.Year == DateTime.Now.Year &&
                                   c.fActiveDate.Month == DateTime.Now.AddMonths(-1).Month &&
                                   c.fEmployeeId == fakeid &&
                                   ts7.fIsAgreed == 1
                                   select c.fTimeCount).Sum();
            //上上月
            double TimeCountThree = (from d in db.tOvertimes.AsEnumerable()
                                     join ts8 in db.tSignoffs.AsEnumerable()
                                     on d.fId equals ts8.fOvertimeId
                                     where d.fActiveDate.Year == DateTime.Now.Year &&
                                     d.fActiveDate.Month == DateTime.Now.AddMonths(-2).Month &&
                                     d.fEmployeeId == fakeid &&
                                     ts8.fIsAgreed == 1
                                     select d.fTimeCount).Sum();

            double TimeCountThreeMonth = TimeCountOne + TimeCountTwo + TimeCountThree;

            //第一層判斷他目前是不是已經超過加班上限了
            //if (TimeCountForMonth > 46)
            //{
            //    TempData["message"] = "你太累瞜~~當月加班時數超過上限";
            //    return View();
            //}
            if (TimeCountThreeMonth > 138)
            {
                TempData["Attend_msg"] = "你太累瞜~~三個月內累計加班時數超過上限";
                return(View());
            }

            if (o.fTimeCount > 4 || TimeCountToday > 4)
            {
                if (o.fSort == "平日加班")
                {
                    TempData["Attend_msg"] = "你太累瞜~~平日加班時數超過上限";
                    return(View());
                }
                else if (TimeCountToday > 12)
                {
                    TempData["Attend_msg"] = "你太累瞜~~當日加班總時數超過上限";
                    return(View());
                }
            }
            //假設系統撈出來的資料目前都沒有超過上限
            //新增時共有兩個Table,一個是加班申請,一個是簽核表插入
            s.fOvertimeId = o.fId;                           //簽核表編號=加班申請fid
            s.fApplyClass = o.fSort;                         //簽核表種類=加班申請
            o.fSubmitDate = DateTime.Now /*.ToLocalTime()*/; //申請日期等於Now
            o.fActiveDate = o.fActiveDate /*.ToLocalTime()*/;
            s.fStartdate  = o.fActiveDate;                   //簽核表申請日期=現在加班申請日期

            //s.tEmployee.fEmployeeId = fakeid;//簽核表寫入員工編號
            o.fEmployeeId = fakeid;//加班表寫入員工編號

            //查詢部門別及權限用來判斷核決主管是誰
            var Check = (from b in db.tEmployees
                         where b.fEmployeeId == fakeid
                         select new { b.fDepartment, b.fAuth }).FirstOrDefault();
            //先把物件取出來,登入者的資訊物件

            //這個是登入者的部門
            string department = Check.fDepartment.ToString();
            //這個是登入者的權限
            int auth = Check.fAuth;

            //帶入主管編號
            var SupervisorIdCheckJunior = (from a in db.tEmployees
                                           where a.fAuth == 2 && a.fDepartment == department
                                           select new { a.fEmployeeId }).FirstOrDefault();
            var SupervisorIdCheckSenior = (from a in db.tEmployees
                                           where a.fAuth == 3 && a.fDepartment == department
                                           select new { a.fEmployeeId }).FirstOrDefault();
            //這個是一般主管的代號
            int SupervisorJunior = SupervisorIdCheckJunior.fEmployeeId;
            //這個是最高權限的代號
            int SupervisorIdSenior = SupervisorIdCheckSenior.fEmployeeId;

            //寫入相對應的主管編號
            if (auth == 1)
            {
                s.fSupervisorId = SupervisorJunior;//主管權限
            }
            else
            {
                s.fSupervisorId = SupervisorIdSenior;//最高權限編號
            }

            s.fIsAgreed  = null;                           //寫入是否同意,預設為null(待審核)
            s.fEnddate   = o.fActiveDate;
            o.fTimeCount = Convert.ToDouble(o.fTimeCount); //選單輸入的文字轉成加班的數字並存回加班表
            //很遺憾的,可能有超時狀況,進入細項判斷式
            if (o.fTimeCount + TimeCountForMonth > 46 || o.fTimeCount + TimeCountThreeMonth > 138)
            {
                //這個是申請當月的月份
                int NowMonth        = s.fStartdate.Month;
                int LastMonth       = s.fStartdate.Month - 1;
                int BeforeLastMonth = s.fStartdate.Month - 2;

                //申請加班開始日期的月份已經請的時數
                double now = (from to in db.tOvertimes.AsEnumerable()
                              join ts1 in db.tSignoffs.AsEnumerable()
                              on to.fId equals ts1.fOvertimeId
                              where to.fActiveDate.Year == DateTime.Now.Year &&
                              to.fActiveDate.Month == NowMonth &&
                              to.fEmployeeId == fakeid &&
                              ts1.fIsAgreed == 1
                              select to.fTimeCount).DefaultIfEmpty(0).Sum();


                //申請加班開始日期的上個月已經請的時數
                double Last = (from a in db.tOvertimes.AsEnumerable()
                               join ts2 in db.tSignoffs.AsEnumerable()
                               on a.fId equals ts2.fOvertimeId
                               where a.fActiveDate.Year == DateTime.Now.Year &&
                               a.fActiveDate.Month == LastMonth &&
                               a.fEmployeeId == fakeid &&
                               ts2.fIsAgreed == 1
                               select a.fTimeCount).DefaultIfEmpty(0).Sum();

                //申請加班開始日期的上上個月已經請的時數
                double BeforeLast = (from a in db.tOvertimes.AsEnumerable()
                                     join ts3 in db.tSignoffs.AsEnumerable()
                                     on a.fId equals ts3.fOvertimeId
                                     where a.fActiveDate.Year == DateTime.Now.Year &&
                                     a.fActiveDate.Month == BeforeLastMonth &&
                                     a.fEmployeeId == fakeid &&
                                     ts3.fIsAgreed == 1
                                     select a.fTimeCount).DefaultIfEmpty(0).Sum();

                //申請加班當月的時數已經超過上限
                if (now + o.fTimeCount > 46)
                {
                    TempData["Attend_msg"] = "你太累瞜~~當月加班時數超過上限";
                    return(View());
                }
                //申請加班的前三個月總時數已經超過上限
                else if (Last + BeforeLast + o.fTimeCount > 138)
                {
                    TempData["Attend_msg"] = "你太累瞜~~累計三個月內加班時數超過上限";
                    return(View());
                }
                //沒事,他有可能是申請上個月的加班,但是因為這個月已經滿了,才會進來這個鬼地方
                else
                {
                    //他可以出去判斷式了
                    db.tOvertimes.Add(o); //加入t物件(加班表)
                    db.tSignoffs.Add(s);  //加入s物件(簽核表)
                    db.SaveChanges();     //存檔
                    TempData["Attend_msg"] = "送出成功";
                    //return View();
                    return(RedirectToAction("AttendIndex", "Attend"));
                }
            }
            //他當月既沒有超過上限,三個月內也沒有超過上限
            db.tOvertimes.Add(o); //加入t物件(加班表)
            db.tSignoffs.Add(s);  //加入s物件(簽核表)
            db.SaveChanges();     //存檔
            TempData["Attend_msg"] = "送出成功";
            //return View();
            return(RedirectToAction("AttendIndex", "Attend"));
        }
Example #24
0
        public string Create(tProject target)
        {
            //------新增專案-----------//
            tProject prj = new tProject();

            prj.fProjectId   = target.fProjectId;
            prj.fProjectName = target.fProjectName;
            prj.fClient      = target.fClient;
            prj.fPrice       = target.fPrice;
            prj.fCreatdDate  = target.fCreatdDate;
            prj.fDateline    = target.fDateline;
            prj.fDepartment  = target.fDepartment;
            prj.fEmployeeId  = target.fEmployeeId;
            prj.fProgress    = 0;

            prj.fStatus = "進行中";

            db.tProjects.Add(prj);
            db.SaveChanges();

            //------新增專案預算書------//
            tBudget budget = new tBudget();

            budget.fProjectId        = target.fProjectId;
            budget.fManagementFeePct = 0.2;
            budget.fSalaryHour       = 200;
            budget.fagree            = "未申請";
            budget.fBudget           = 0;

            db.tBudgets.Add(budget);
            db.SaveChanges();

            //---------新增階段表------//
            //預設為三階段//
            //todo:讓使用者自訂階段數量及名稱

            tLevel level1 = new tLevel();

            level1.fProjectId    = prj.fProjectId;
            level1.fLevelName    = "規劃";
            level1.fEstimateTime = 0;
            level1.fSpendCost    = 0;

            tLevel level2 = new tLevel();

            level2.fProjectId    = prj.fProjectId;
            level2.fLevelName    = "開發";
            level2.fEstimateTime = 0;
            level2.fSpendCost    = 0;

            tLevel level3 = new tLevel();

            level3.fProjectId    = prj.fProjectId;
            level3.fLevelName    = "測試";
            level3.fEstimateTime = 0;
            level3.fSpendCost    = 0;

            db.tLevels.Add(level1);
            db.tLevels.Add(level2);
            db.tLevels.Add(level3);
            db.SaveChanges();

            return("success");
        }
        public ActionResult CreateOverTime(tOvertime o, tSignoff s)
        {
            //撈資料庫當月
            double TimeCountForMonth = (from a in db.tOvertimes
                                        where a.fActiveDate.Year == DateTime.Now.Year &&
                                        a.fActiveDate.Month == DateTime.Now.Month &&
                                        a.fEmployeeId == fakeid
                                        select a.fTimeCount).DefaultIfEmpty(0).Sum();
            ////撈資料庫上個月
            //double TimeCountLastMonth = (from a in db.tOvertimes.AsEnumerable()
            //                              where a.fActiveDate.Year == DateTime.Now.Year
            //                              && a.fActiveDate.Month == DateTime.Now.AddMonths(-1).Month
            //                              && a.fEmployeeId == fakeid
            //                              select a.fTimeCount).Sum();
            ////撈資料庫上上個月
            //double TimeCountBeforeLastMonth = (from a in db.tOvertimes.AsEnumerable()
            //                                   where a.fActiveDate.Year == DateTime.Now.Year
            //                                   && a.fActiveDate.Month == DateTime.Now.AddMonths(-2).Month
            //                                   && a.fEmployeeId == fakeid
            //                                   select a.fTimeCount).Sum();
            //三個月加班合計
            double TimeCountThreeMonth = (from a in db.tOvertimes.AsEnumerable()
                                          where a.fActiveDate.Year == DateTime.Now.Year

                                          && a.fActiveDate.Month == DateTime.Now.AddMonths(-2).Month ||
                                          a.fActiveDate.Month == DateTime.Now.AddMonths(-1).Month ||
                                          a.fActiveDate.Month == DateTime.Now.Month

                                          && a.fEmployeeId == fakeid
                                          select a.fTimeCount).DefaultIfEmpty(0).Sum();

            //第一層判斷他目前是不是已經超過加班上限了
            //if (TimeCountForMonth > 54)
            //{
            //    TempData["message"] = "你太累瞜~~當月加班時數超過上限";
            //    return View();
            //}
            if (TimeCountThreeMonth > 138)
            {
                TempData["message"] = "你太累瞜~~三個月內累計加班時數超過上限";
                return(View());
            }

            if (o.fTimeCount > 4)
            {
                TempData["message"] = "你太累瞜~~當日加班時數超過上限";
                return(View());
            }
            //假設系統撈出來的資料目前都沒有超過上限
            //新增時共有兩個Table,一個是加班申請,一個是簽核表插入
            s.fOvertimeId = o.fId;                            //簽核表編號=加班申請fid
            s.fApplyClass = "加班申請";                           //簽核表種類=加班申請
            o.fSubmitDate = DateTime.Now;                     //申請日期等於Now
            o.fActiveDate = o.fActiveDate;
            s.fStartdate  = o.fActiveDate;                    //簽核表申請日期=現在加班申請日期
            //s.tEmployee.fEmployeeId = fakeid;//簽核表寫入員工編號
            o.fEmployeeId   = fakeid;                         //加班表寫入員工編號
            s.fSupervisorId = 106;                            //主管編號
            s.fIsAgreed     = null;                           //寫入是否同意,預設為null(待審核)
            s.fEnddate      = o.fActiveDate;
            o.fTimeCount    = Convert.ToDouble(o.fTimeCount); //選單輸入的文字轉成加班的數字並存回加班表
            //很遺憾的,可能有超時狀況,進入細項判斷式
            if (o.fTimeCount + TimeCountForMonth > 54 || o.fTimeCount + TimeCountThreeMonth > 138)
            {
                //這個是申請當月的月份
                int NowMonth        = s.fStartdate.Month;
                int LastMonth       = s.fStartdate.Month - 1;
                int BeforeLastMonth = s.fStartdate.Month - 2;


                //申請加班開始日期的月份已經請的時數
                double now = (from a in db.tOvertimes
                              where a.fActiveDate.Year == DateTime.Now.Year &&
                              a.fActiveDate.Month == NowMonth &&
                              a.fEmployeeId == fakeid
                              select a.fTimeCount).DefaultIfEmpty(0).Sum();


                //申請加班開始日期的上個月已經請的時數
                double Last = (from a in db.tOvertimes
                               where a.fActiveDate.Year == DateTime.Now.Year &&
                               a.fActiveDate.Month == LastMonth &&
                               a.fEmployeeId == fakeid
                               select a.fTimeCount).DefaultIfEmpty(0).Sum();

                //申請加班開始日期的上上個月已經請的時數
                double BeforeLast = (from a in db.tOvertimes
                                     where a.fActiveDate.Year == DateTime.Now.Year &&
                                     a.fActiveDate.Month == BeforeLastMonth &&
                                     a.fEmployeeId == fakeid
                                     select a.fTimeCount).DefaultIfEmpty(0).Sum();

                //申請加班當月的時數已經超過上限
                if (now + o.fTimeCount > 54)
                {
                    TempData["message"] = "你太累瞜~~當月加班時數超過上限";
                    return(View());
                }
                //申請加班的前三個月總時數已經超過上限
                else if (Last + BeforeLast + o.fTimeCount > 138)
                {
                    TempData["message"] = "你太累瞜~~累計三個月內加班時數超過上限";
                    return(View());
                }
                //沒事,他有可能是申請上個月的加班,但是因為這個月已經滿了,才會進來這個鬼地方
                else
                {
                    //他可以出去判斷式了
                    db.tOvertimes.Add(o); //加入t物件(加班表)
                    db.tSignoffs.Add(s);  //加入s物件(簽核表)
                    db.SaveChanges();     //存檔
                    return(RedirectToAction("CreateOverTime"));
                }
            }
            //他當月既沒有超過上限,三個月內也沒有超過上限
            db.tOvertimes.Add(o); //加入t物件(加班表)
            db.tSignoffs.Add(s);  //加入s物件(簽核表)
            db.SaveChanges();     //存檔
            return(RedirectToAction("CreateOverTime"));
        }
Example #26
0
        public ActionResult Create(tEmployee target)
        {
            if (target.fEmployeeId > 0)
            {
                //修改
                DateTime  Now       = DateTime.Now;
                tEmployee updateEmp = db.tEmployees.Where(emp => emp.fEmployeeId == target.fEmployeeId).FirstOrDefault();
                //updateEmp.fEmployeeId = target.fEmployeeId;
                updateEmp.fName          = target.fName;
                updateEmp.fIdent         = target.fIdent;
                updateEmp.fPassword      = target.fPassword;
                updateEmp.fDepartment    = target.fDepartment;
                updateEmp.fTitle         = target.fTitle;
                updateEmp.fEmail         = target.fEmail;
                updateEmp.fBirth         = target.fBirth;
                updateEmp.fPhonePersonal = target.fPhonePersonal;
                updateEmp.fHireDate      = target.fHireDate;
                updateEmp.fState         = target.fState;
                updateEmp.fAuth          = Convert.ToInt32(target.fAuth);
                updateEmp.fSalaryMonth   = target.fSalaryMonth;
                updateEmp.fSalaryHour    = target.fSalaryMonth / 30 / 8;
                updateEmp.fPhoneHouse    = target.fPhoneHouse;
                updateEmp.fCountry       = target.fCountry;
                updateEmp.fBirthPlace    = target.fBirthPlace;
                updateEmp.fEducation     = target.fEducation;
                updateEmp.fAddressNow    = target.fAddressNow;
                updateEmp.fAddressOrigin = target.fAddressOrigin;
                updateEmp.fEngyName      = target.fEngyName;
                updateEmp.fEngyPhone     = target.fEngyPhone;
                TimeSpan fOld = Now.Subtract(updateEmp.fHireDate);
                updateEmp.fOld      = Math.Round(fOld.TotalDays, 1);
                updateEmp.fFireDate = target.fFireDate;
                updateEmp.fBackDate = target.fBackDate;
                updateEmp.fLBI      = LBI(target.fSalaryMonth);
                updateEmp.fHI       = HI(target.fSalaryMonth);
                db.SaveChanges();
            }
            else
            {
                //身分證驗證(資料倒入)

                if (target.fName == null)
                {
                    return(Json("empty", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    string idcheck = target.fIdent;
                    bool   regId   = Regex.IsMatch(idcheck, @"^[A-Za-z]{1}[1-2]{1}[0-9]{8}$");
                    //密碼驗證(資料倒入)///////
                    string pwdcheck = target.fPassword;
                    bool   regPwd   = Regex.IsMatch(pwdcheck, @"^.*(?=.{6,})(?=.*\d)(?=.*[a-zA-Z]).*$");
                    if (regId && regPwd)
                    {
                        //新增
                        DateTime  Now = DateTime.Now;
                        tEmployee emp = new tEmployee();
                        //emp.fEmployeeId = target.fEmployeeId;
                        emp.fName          = target.fName;
                        emp.fName          = target.fName;
                        emp.fIdent         = target.fIdent;
                        emp.fPassword      = target.fPassword;
                        emp.fDepartment    = target.fDepartment;
                        emp.fTitle         = target.fTitle;
                        emp.fEmail         = target.fEmail;
                        emp.fBirth         = target.fBirth;
                        emp.fPhonePersonal = target.fPhonePersonal;
                        emp.fHireDate      = target.fHireDate;
                        emp.fState         = target.fState;
                        emp.fAuth          = Convert.ToInt32(target.fAuth);
                        emp.fSalaryMonth   = target.fSalaryMonth;
                        emp.fSalaryHour    = target.fSalaryMonth / 30 / 8;
                        emp.fPhoneHouse    = target.fPhoneHouse;
                        emp.fCountry       = target.fCountry;
                        emp.fBirthPlace    = target.fBirthPlace;
                        emp.fEducation     = target.fEducation;
                        emp.fAddressNow    = target.fAddressNow;
                        emp.fAddressOrigin = target.fAddressOrigin;
                        emp.fEngyName      = target.fEngyName;
                        emp.fEngyPhone     = target.fEngyPhone;
                        TimeSpan fOld = Now.Subtract(emp.fHireDate);
                        emp.fOld      = Math.Round(fOld.TotalDays, 1);
                        emp.fFireDate = target.fFireDate;
                        emp.fBackDate = target.fBackDate;
                        emp.fLBI      = LBI(target.fSalaryMonth);
                        emp.fHI       = HI(target.fSalaryMonth);
                        db.tEmployees.Add(emp);
                        db.SaveChanges();
                    }
                    else
                    {
                        return(Json("error", JsonRequestBehavior.AllowGet));
                    }
                }
            }

            return(Json("success", JsonRequestBehavior.AllowGet));
        }
Example #27
0
        public ActionResult Create(tEmployee target)
        {
            if (target.fEmployeeId > 0)
            {
                //修改
                DateTime  Now       = DateTime.Now;
                tEmployee updateEmp = db.tEmployees.Where(emp => emp.fEmployeeId == target.fEmployeeId).FirstOrDefault();
                //updateEmp.fEmployeeId = target.fEmployeeId;
                updateEmp.fName          = target.fName;
                updateEmp.fIdent         = target.fIdent;
                updateEmp.fPassword      = target.fPassword;
                updateEmp.fDepartment    = target.fDepartment;
                updateEmp.fTitle         = target.fTitle;
                updateEmp.fEmail         = target.fEmail;
                updateEmp.fBirth         = target.fBirth;
                updateEmp.fPhonePersonal = target.fPhonePersonal;
                updateEmp.fHireDate      = target.fHireDate;
                updateEmp.fState         = target.fState;
                updateEmp.fAuth          = Convert.ToInt32(target.fAuth);
                updateEmp.fSalaryMonth   = target.fSalaryMonth;
                updateEmp.fSalaryHour    = target.fSalaryMonth / 30 / 8;
                updateEmp.fPhoneHouse    = target.fPhoneHouse;
                updateEmp.fCountry       = target.fCountry;
                updateEmp.fBirthPlace    = target.fBirthPlace;
                updateEmp.fEducation     = target.fEducation;
                updateEmp.fAddressNow    = target.fAddressNow;
                updateEmp.fAddressOrigin = target.fAddressOrigin;
                updateEmp.fEngyName      = target.fEngyName;
                updateEmp.fEngyPhone     = target.fEngyPhone;
                TimeSpan fOld = Now.Subtract(updateEmp.fHireDate);
                updateEmp.fOld      = Math.Round(fOld.TotalDays, 1);
                updateEmp.fFireDate = target.fFireDate;
                updateEmp.fBackDate = target.fBackDate;

                db.SaveChanges();
            }
            else
            {
                //身分證驗證(資料倒入)
                string idcheck = target.fIdent;
                bool   regId   = Regex.IsMatch(idcheck, @"^[A-Za-z]{1}[1-2]{1}[0-9]{8}$");
                //密碼驗證(資料倒入)///////
                string pwdcheck = target.fPassword;
                bool   regPwd   = Regex.IsMatch(pwdcheck, @"^.*(?=.{6,})(?=.*\d)(?=.*[a-zA-Z]).*$");
                //email驗證(資料倒入)
                //string emailcheck = target.fEmail;
                //bool regemail = Regex.IsMatch(emailcheck, @"^[A-Za-z0-9!#$%&’ /=?^_`{|}~-](.[A-Za-z0-9!#$%&’ /=?^_`{|}~-])*@([A-Za-z0-9](?:-[A-Za-z0-9])?.)[A-Za-z0-9](-[A-Za-z0-9] )?$");
                //開始驗證,如果三者皆為Ture
                if (regId && regPwd /*&& regemail*/)
                {
                    //新增
                    DateTime  Now = DateTime.Now;
                    tEmployee emp = new tEmployee();
                    //emp.fEmployeeId = target.fEmployeeId;
                    emp.fName          = target.fName;
                    emp.fName          = target.fName;
                    emp.fIdent         = target.fIdent;
                    emp.fPassword      = target.fPassword;
                    emp.fDepartment    = target.fDepartment;
                    emp.fTitle         = target.fTitle;
                    emp.fEmail         = target.fEmail;
                    emp.fBirth         = target.fBirth;
                    emp.fPhonePersonal = target.fPhonePersonal;
                    emp.fHireDate      = target.fHireDate;
                    emp.fState         = "試用期";
                    emp.fAuth          = Convert.ToInt32(target.fAuth);
                    emp.fSalaryMonth   = target.fSalaryMonth;
                    emp.fSalaryHour    = target.fSalaryMonth / 30 / 8;
                    emp.fPhoneHouse    = target.fPhoneHouse;
                    emp.fCountry       = target.fCountry;
                    emp.fBirthPlace    = target.fBirthPlace;
                    emp.fEducation     = target.fEducation;
                    emp.fAddressNow    = target.fAddressNow;
                    emp.fAddressOrigin = target.fAddressOrigin;
                    emp.fEngyName      = target.fEngyName;
                    emp.fEngyPhone     = target.fEngyPhone;
                    TimeSpan fOld = Now.Subtract(emp.fHireDate);
                    emp.fOld      = Math.Round(fOld.TotalDays, 1);
                    emp.fFireDate = target.fFireDate;
                    emp.fBackDate = target.fBackDate;

                    db.tEmployees.Add(emp);
                    db.SaveChanges();
                }
                //else
                //{
                //    TempData["message"] = "請輸入正確身分證\n請輸入正確信箱或密碼\n密碼為英數混和共6碼!";
                //    return View();
                //}
            }

            return(Json("success", JsonRequestBehavior.AllowGet));
        }