コード例 #1
0
        public ActionResult Login(string EmpID = "", string EmpPwd = "")
        {
            ECSEntities db = new ECSEntities();

            if (!string.IsNullOrWhiteSpace(EmpID))
            {
                var ED = db.EmpData.Where(x => x.EmpID == EmpID).FirstOrDefault();
                if (ED != null)
                {
                    if (EmpID == ED.EmpID && EmpPwd == ED.EmpPwd)
                    {
                        Session["SessionEmpID"]    = ED.EmpID;
                        Session["SessionEmpPwd"]   = ED.EmpPwd;
                        Session["SessionEmpName"]  = ED.EmpName;
                        Session["SessionEmpDept"]  = ED.EmpDept;
                        Session["SessionEmpState"] = ED.EmpState;
                        Session["SessionRole"]     = ED.Role;
                        if (ED.Role == "Admin" || ED.Role == "Manage")
                        {
                            return(RedirectToAction("Reserve", "Borrow"));
                        }
                        else if (ED.Role == "User")
                        {
                            return(RedirectToAction("UserReserve", "User"));
                        }
                    }
                    else
                    {
                        ViewBag.Message = false;
                    }
                }
                else
                {
                    ViewBag.Message = false;
                }
            }
            return(View());
        }
コード例 #2
0
        public ActionResult Record(int page = 1, String datetimesd = "", String datetimeed = "", string empid = "", string empsn = "", string empdept = "", string cardid = "")
        {
            ECSEntities db = new ECSEntities();
            //分頁
            int pageSize    = 10;
            int currentPage = page < 1 ? 1 : page;

            //搜尋欄位存值
            Session["Searchdatetimesd"] = datetimesd;
            Session["Searchdatetimeed"] = datetimeed;
            Session["Searchempid"]      = empid;
            Session["Searchempsn"]      = empsn;
            Session["Searchempdept"]    = empdept;
            Session["Searchcardid"]     = cardid;

            FormViewModel RecordList = new FormViewModel();
            //Timesd & Timeed 初始值
            DateTime Timesd = Convert.ToDateTime("0001-01-01");
            DateTime Timeed = Convert.ToDateTime("9999-01-01");
            //當月時間
            string   First    = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).ToShortDateString();
            string   Last     = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddMonths(1).ToShortDateString();
            DateTime FirstDay = Convert.ToDateTime(First);
            DateTime LastDay  = Convert.ToDateTime(Last);

            //Timesd & Timeed 使用者輸入值
            if (!string.IsNullOrWhiteSpace(datetimesd))
            {
                Timesd = Convert.ToDateTime(datetimesd);
            }
            if (!string.IsNullOrWhiteSpace(datetimeed))
            {
                Timeed = Convert.ToDateTime(datetimeed);
            }
            //判斷管理者部門
            string role = Session["SessionRole"].ToString();

            if (role == "Manage")
            {
                empdept = Session["SessionEmpDept"].ToString();
            }
            //Search當月的資料
            if (string.IsNullOrWhiteSpace(empid) && string.IsNullOrWhiteSpace(empsn) && string.IsNullOrWhiteSpace(empdept) && string.IsNullOrWhiteSpace(cardid) && string.IsNullOrWhiteSpace(datetimesd) && string.IsNullOrWhiteSpace(datetimeed))
            {
                RecordList.ExportData = (from R in db.RecordData
                                         join E in db.EmpData on R.EmpID equals E.EmpID
                                         join C in db.CardData on R.CardID equals C.CardID
                                         where R.Disable == "N" && /*&& R.TimeLend >= FirstDay && R.TimeLend < LastDay*/
                                         (!string.IsNullOrEmpty(empdept) ? E.EmpDept == empdept : true)
                                         orderby R.RecordNumber descending /*降冪排序*/
                                         select new ExportDataViewModel
                {
                    RecordNumber = R.RecordNumber,
                    EmpID = E.EmpID,
                    EmpName = E.EmpName,
                    EmpDept = E.EmpDept,
                    CardID = C.CardID,
                    CardName = C.CardName,
                    CardDept = C.CardDept,
                    TimeLend = R.TimeLend,
                    TimeReturn = R.TimeReturn,
                    RecordState = R.RecordState,
                    UseDay = R.UseDay,
                    CardAmount = C.CardAmount,
                    TotalSpent = R.TotalSpent
                }).ToList();
                ViewBag.Message           = true;
                Session["SessionECSdata"] = RecordList.ExportData;
            }
            //Search輸入條件的所有資料
            else
            {
                RecordList.ExportData = (from R in db.RecordData
                                         join E in db.EmpData on R.EmpID equals E.EmpID
                                         join C in db.CardData on R.CardID equals C.CardID
                                         where R.Disable == "N" && (!string.IsNullOrEmpty(empid) ? E.EmpID == empid : true) &&
                                         (!string.IsNullOrEmpty(empsn) ? E.EmpSN == empsn : true) &&
                                         (!string.IsNullOrEmpty(empdept) ? E.EmpDept == empdept : true) &&
                                         (!string.IsNullOrEmpty(cardid) ? C.CardID == cardid : true) &&
                                         (!string.IsNullOrEmpty(datetimesd) ? R.TimeLend >= Timesd : true) &&
                                         (!string.IsNullOrEmpty(datetimeed) ? R.TimeLend <= Timeed : true)
                                         orderby R.RecordNumber descending /*降冪排序*/
                                         select new ExportDataViewModel
                {
                    RecordNumber = R.RecordNumber,
                    EmpID = E.EmpID,
                    EmpName = E.EmpName,
                    EmpDept = E.EmpDept,
                    CardID = C.CardID,
                    CardName = C.CardName,
                    CardDept = C.CardDept,
                    TimeLend = R.TimeLend,
                    TimeReturn = R.TimeReturn,
                    RecordState = R.RecordState,
                    UseDay = R.UseDay,
                    CardAmount = C.CardAmount,
                    TotalSpent = R.TotalSpent
                }).ToList();
                ViewBag.Message           = true;
                Session["SessionECSdata"] = RecordList.ExportData;
                //Search不到資料
                if (RecordList.ExportData.Count == 0)
                {
                    ViewBag.Message = false;
                }
            }
            //return View(RecordList);
            return(View(RecordList.ExportData.ToPagedList(currentPage, pageSize)));  //分頁
        }