public async Task<ActionResult> List() { string staff_id = CommonHelper.GetValue(Request["staff_id"]); int month = CommonHelper.GetValue<int>(Request["month"], 0); int year = CommonHelper.GetValue<int>(Request["year"], 0); int pgnum = CommonHelper.GetValue<int>(Request["pgnum"], 1); int pgsize = CommonHelper.GetValue<int>(Request["pgsize"], 0); string sortcolumn = CommonHelper.GetValue(Request["sortcolumn"], PayrateHelper.DEFAULT_SORT_COLUMN); string sortdir = CommonHelper.GetValue(Request["sortdir"], PayrateHelper.DEFAULT_SORT_DIR); Sort sort = new Sort(sortcolumn, sortdir); Dictionary<string, object> filters = new Dictionary<string, object> { { "staff_id", staff_id }, { "month", month }, { "year", year } }; ListModel<Payrate> l = null; if (string.IsNullOrEmpty(staff_id) && month == 0 && year == 0) l = await PayrateHelper.GetAll(pgnum, pgsize, sort); else l = await PayrateHelper.GetFilterBy(filters, pgnum, pgsize, sort); return View("_list", l); }
public async Task<ActionResult> List() { DateTime work_date = CommonHelper.GetDateTime(Request["work_date"]); string employee = CommonHelper.GetValue(Request["employee"]); int pgnum = string.IsNullOrEmpty(Request["pgnum"]) ? 1 : Convert.ToInt32(Request["pgnum"]); int pgsize = string.IsNullOrEmpty(Request["pgsize"]) ? 0 : Convert.ToInt32(Request["pgsize"]); string sortcolumn = string.IsNullOrEmpty(Request["sortcolumn"]) ? EmployeeHelper.DEFAULT_SORT_COLUMN : Request["sortcolumn"]; string sortdir = string.IsNullOrEmpty(Request["sortdir"]) ? EmployeeHelper.DEFAULT_SORT_DIR : Request["sortdir"]; Sort sort = new Sort(sortcolumn, sortdir); Dictionary<string, object> filters = new Dictionary<string, object> { { "work_date", work_date }, { "employee", employee } }; ListModel<Attendance> l = null; if (work_date == default(DateTime) && string.IsNullOrEmpty(employee)) l = await AttendanceHelper.GetAll(pgnum, pgsize, sort); else l = await AttendanceHelper.GetFilterBy(filters, pgnum, pgsize, sort); return View("_list", l); }
public async Task<ActionResult> List() { string username = CommonHelper.GetValue(Request["username"]); int role = CommonHelper.GetValue<int>(Request["role"], 0); string employee = CommonHelper.GetValue(Request["employee"]); int status = CommonHelper.GetValue<int>(Request["status"], 0); int pgnum = CommonHelper.GetValue<int>(Request["pgnum"], 1); int pgsize = CommonHelper.GetValue<int>(Request["pgsize"], 0); string sortcolumn = CommonHelper.GetValue(Request["sortcolumn"], UserHelper.DEFAULT_SORT_COLUMN); string sortdir = CommonHelper.GetValue(Request["sortdir"], UserHelper.DEFAULT_SORT_DIR); Sort sort = new Sort(sortcolumn, sortdir); Dictionary<string, object> filters = new Dictionary<string, object> { { "username", username }, { "role", role }, { "employee", employee }, { "status", status } }; ListModel<Domain.Model.User> l = null; if (string.IsNullOrEmpty(username) && role == 0 && string.IsNullOrEmpty(employee) && status == 0) l = await UserHelper.GetAll(pgnum, pgsize, sort); else l = await UserHelper.GetFilterBy(filters, pgnum, pgsize, sort); return View("_list", l); }
public async Task<ActionResult> List() { string employee = CommonHelper.GetValue(Request["employee"]); string staff_id = CommonHelper.GetValue(Request["staff_id"]); int employment_status = CommonHelper.GetValue<int>(Request["employment_status"], 0); int designation = CommonHelper.GetValue<int>(Request["designation"], 0); int dept = CommonHelper.GetValue<int>(Request["dept"], 0); int pgnum = CommonHelper.GetValue<int>(Request["pgnum"], 1); int pgsize = CommonHelper.GetValue<int>(Request["pgsize"], 0); string sortcolumn = CommonHelper.GetValue(Request["sortcolumn"], EmployeeHelper.DEFAULT_SORT_COLUMN); string sortdir = CommonHelper.GetValue(Request["sortdir"], EmployeeHelper.DEFAULT_SORT_DIR); Sort sort = new Sort(sortcolumn, sortdir); Dictionary<string, object> filters = new Dictionary<string, object> { { "employee", employee }, { "staff_id", staff_id }, { "employment_status", employment_status }, { "designation", designation }, { "dept", dept } }; ListModel<Employee> l = null; if (string.IsNullOrEmpty(employee) && string.IsNullOrEmpty(staff_id) && employment_status == 0 && designation == 0 && dept == 0) l = await EmployeeHelper.GetAll(pgnum, pgsize, sort); else l = await EmployeeHelper.GetFilterBy(filters, pgnum, pgsize, sort); return View("_list", l); }
public async Task<ActionResult> List() { int year = CommonHelper.GetValue<int>(Request["year"], 0); int pgnum = CommonHelper.GetValue<int>(Request["pgnum"], 1); int pgsize = CommonHelper.GetValue<int>(Request["pgsize"], 0); string sortcolumn = CommonHelper.GetValue(Request["sortcolumn"], OvertimerateHelper.DEFAULT_SORT_COLUMN); string sortdir = CommonHelper.GetValue(Request["sortdir"], OvertimerateHelper.DEFAULT_SORT_DIR); Sort sort = new Sort(sortcolumn, sortdir); Dictionary<string, object> filters = new Dictionary<string, object> { { "year", year } }; ListModel<Overtimerate> l = null; if (year == 0) l = await OvertimerateHelper.GetAll(pgnum, pgsize, sort); else l = await OvertimerateHelper.GetFilterBy(filters, pgnum, pgsize, sort); return View("_list", l); }
public async Task<ActionResult> List() { string keyword = CommonHelper.GetValue(Request["keyword"]); int pgnum = CommonHelper.GetValue<int>(Request["pgnum"], 1); int pgsize = CommonHelper.GetValue<int>(Request["pgsize"], 0); string sortcolumn = CommonHelper.GetValue(Request["sortcolumn"], JobcategoryHelper.DEFAULT_SORT_COLUMN); string sortdir = CommonHelper.GetValue(Request["sortdir"], JobcategoryHelper.DEFAULT_SORT_DIR); Sort sort = new Sort(sortcolumn, sortdir); ListModel<Jobcategory> l = null; if (string.IsNullOrEmpty(keyword)) l = await JobcategoryHelper.GetAll(pgnum, pgsize, sort); else l = await JobcategoryHelper.GetFilterBy(keyword, pgnum, pgsize, sort); return View("_list", l); }
public static async Task<ListModel<Attendance>> GetFilterBy(Dictionary<string, object> filters, int pagenum = 1, int pagesize = Pager.DEFAULT_PAGE_SIZE, Sort sort = null) { ListModel<Attendance> l = new ListModel<Attendance>(); if (sort == null) sort = new Sort(DEFAULT_SORT_COLUMN, DEFAULT_SORT_DIR); ISession se = NHibernateHelper.CurrentSession; ICriteria cr = se.CreateCriteria<Attendance>("attendance"); GetFilterCriteria(cr, filters, sort); ICriteria crCount = se.CreateCriteria<Attendance>("attendance"); GetFilterCriteria(crCount, filters, sort); int total = crCount.SetProjection(Projections.Count(Projections.Id())).UniqueResult<int>(); Pager pager = new Pager(total, pagenum, pagesize); int has_next = pager.HasNext ? 1 : 0; int has_prev = pager.HasPrev ? 1 : 0; GetOrder(sort, cr); cr.SetFirstResult(pager.LowerBound); cr.SetMaxResults(pager.PageSize); IList<Attendance> list = await Task.Run(() => { return cr.List<Attendance>(); }); l.ItemMsg = pager.GetItemMessage(); l.HasNext = has_next; l.HasPrev = has_prev; l.NextPage = pager.PageNum + 1; l.PrevPage = pager.PageNum - 1; l.List = list; l.SortColumn = sort.Column; l.SortDir = sort.Direction; l.Page = pager.PageNum; l.TotalPage = pager.TotalPages; return l; }
public static async Task<ListModel<Employee>> GetAll(int pagenum = 1, int pagesize = Pager.DEFAULT_PAGE_SIZE, Sort sort = null) { ListModel<Employee> l = new ListModel<Employee>(); if (sort == null) sort = new Sort(DEFAULT_SORT_COLUMN, DEFAULT_SORT_DIR); ISession se = NHibernateHelper.CurrentSession; int total = await Task.Run(() => { return se.QueryOver<Employee>().Future().Count(); }); Pager pager = new Pager(total, pagenum, pagesize); int has_next = pager.HasNext ? 1 : 0; int has_prev = pager.HasPrev ? 1 : 0; ICriteria cr = se.CreateCriteria<Employee>("employee"); if (sort.Column == "d.Title" || sort.Column == "es.Name" || sort.Column == "dept.Name") SetJoinCriteria(cr, sort); GetOrder(sort, cr); cr.SetFirstResult(pager.LowerBound); cr.SetMaxResults(pager.PageSize); IList<Employee> list = await Task.Run(() => { return cr.List<Employee>(); }); l.ItemMsg = pager.GetItemMessage(); l.HasNext = has_next; l.HasPrev = has_prev; l.NextPage = pager.PageNum + 1; l.PrevPage = pager.PageNum - 1; l.List = list; l.SortColumn = sort.Column; l.SortDir = sort.Direction; l.Page = pager.PageNum; l.TotalPage = pager.TotalPages; return l; }
private static void SetJoinCriteria(ICriteria cr, Sort sort) { if (sort.Column == "e.Firstname") { ICriteria cre = cr.GetCriteriaByAlias("e"); if (cre == null) cr = cr.CreateCriteria("attendance.Employee", "e", JoinType.LeftOuterJoin); } }
private static void GetFilterCriteria(ICriteria cr, Dictionary<string, object> filters, Sort sort = null) { string employee = Convert.ToString(filters["employee"]); DateTime work_date = (DateTime)filters["work_date"]; if (!string.IsNullOrEmpty(employee)) { cr = cr.CreateCriteria("attendance.Employee", "e", JoinType.InnerJoin); AbstractCriterion a1 = Restrictions.InsensitiveLike("e.Firstname", employee, MatchMode.Anywhere); AbstractCriterion a2 = Restrictions.InsensitiveLike("e.Middlename", employee, MatchMode.Anywhere); AbstractCriterion a3 = Restrictions.InsensitiveLike("e.Lastname", employee, MatchMode.Anywhere); AbstractCriterion b1 = Restrictions.Or(a1, a2); AbstractCriterion b2 = Restrictions.Or(b1, a3); cr.Add(b2); } if (work_date != default(DateTime)) cr.Add(Restrictions.Eq("attendance.Workdate", work_date)); if (sort != null) SetJoinCriteria(cr, sort); }
private static void GetOrder(Sort sort, ICriteria cr) { bool sortDir = sort.Direction == "ASC" ? true : false; Order order = null; if (sort.Column.IndexOf(".", StringComparison.OrdinalIgnoreCase) >= 0) order = new Order(sort.Column, sortDir); else order = new Order(string.Format("attendance.{0}", sort.Column), sortDir); cr.AddOrder(order); }
private static void GetOrder(Sort sort, ICriteria cr) { bool sortDir = sort.Direction == "ASC" ? true : false; Order order = new Order(string.Format("dept.{0}", sort.Column), sortDir); cr.AddOrder(order); }
private static void SetJoinCriteria(ICriteria cr, Sort sort) { ICriteria crej = cr.GetCriteriaByAlias("ej"); if (sort.Column == "d.Title") { ICriteria crd = cr.GetCriteriaByAlias("d"); if (crej != null && crd == null) cr = crej.CreateCriteria("ej.Designation", "d", JoinType.LeftOuterJoin); else if (crej == null && crd == null) { crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin); cr = crej.CreateCriteria("ej.Designation", "d", JoinType.LeftOuterJoin); } } if (sort.Column == "es.Name") { ICriteria cres = cr.GetCriteriaByAlias("es"); if (crej != null && cres == null) cr = crej.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin); else if (crej == null && cres == null) { crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin); cr = crej.CreateCriteria("ej.Employmentstatus", "es", JoinType.LeftOuterJoin); } } if (sort.Column == "dept.Name") { ICriteria crdept = cr.GetCriteriaByAlias("dept"); if (crej != null && crdept == null) cr = crej.CreateCriteria("ej.Department", "dept", JoinType.LeftOuterJoin); else if (crej == null && crdept == null) { crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin); cr = crej.CreateCriteria("ej.Department", "dept", JoinType.LeftOuterJoin); } } }
private static void GetFilterCriteria(ICriteria cr, Dictionary<string, object> filters, Sort sort = null) { string employee = Convert.ToString(filters["employee"]); string staff_id = Convert.ToString(filters["staff_id"]); int employment_status = (int)filters["employment_status"]; int designation = (int)filters["designation"]; int dept = (int)filters["dept"]; if (!string.IsNullOrEmpty(employee)) { AbstractCriterion a1 = Restrictions.InsensitiveLike("employee.Firstname", employee, MatchMode.Anywhere); AbstractCriterion a2 = Restrictions.InsensitiveLike("employee.Middlename", employee, MatchMode.Anywhere); AbstractCriterion a3 = Restrictions.InsensitiveLike("employee.Lastname", employee, MatchMode.Anywhere); AbstractCriterion b1 = Restrictions.Or(a1, a2); AbstractCriterion b2 = Restrictions.Or(b1, a3); cr.Add(b2); } if (!string.IsNullOrEmpty(staff_id)) cr.Add(Restrictions.InsensitiveLike("employee.Staffid", staff_id, MatchMode.Anywhere)); if (employment_status != 0) { cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin); cr = cr.CreateCriteria("ej.Employmentstatus", "es", JoinType.InnerJoin); cr.Add(Restrictions.Eq("es.Id", employment_status)); } if (designation != 0) { ICriteria crej = cr.GetCriteriaByAlias("ej"); if (crej == null) cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin); else cr = crej; cr = cr.CreateCriteria("ej.Designation", "d", JoinType.InnerJoin); cr.Add(Restrictions.Eq("d.Id", designation)); } if (dept != 0) { ICriteria crej = cr.GetCriteriaByAlias("ej"); if (crej == null) cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin); else cr = crej; cr = cr.CreateCriteria("ej.Department", "dept", JoinType.InnerJoin); cr.Add(Restrictions.Eq("dept.Id", dept)); } if (sort != null) SetJoinCriteria(cr, sort); }