/// <summary> /// list utk license index /// </summary> /// <returns>JSON</returns> public JsonResult GetAssetSearchList(string sidx, string sord, int page, int rows, bool _search, string searchField, string searchOper, string searchString, int?asset_location_id = 0, int?category_id = 0, int?department_id = 0) { db.Configuration.ProxyCreationEnabled = false; #region MODEL printLabelViewModel model = new printLabelViewModel() { company_id = UserProfile.company_id, asset_reg_location_id = UserProfile.asset_reg_location_id, asset_location_id = asset_location_id, category_id = category_id, department_id = department_id }; model.company_id = UserProfile.company_id; model.company_list = db.ms_asmin_company.Where(c => c.fl_active == true && c.deleted_date == null).ToList <ms_asmin_company>(); model.company = db.ms_asmin_company.Find(UserProfile.company_id); model.asset_reg_location_id = UserProfile.asset_reg_location_id; model.asset_reg_location = db.ms_asset_register_location.Find(UserProfile.asset_reg_location_id); model.asset_reg_location_list = db.ms_asset_register_location.Where(c => c.fl_active == true && c.deleted_date == null).ToList <ms_asset_register_location>(); //Set Location List if (UserProfile.asset_reg_location_id == 1) { model.asset_location_list = (from m in db.ms_asset_location.Where(m => (m.fl_active == true && m.deleted_date == null)) select m).ToList(); } else //branch { model.asset_location_list = (from m in db.ms_asset_location.Where(m => (m.fl_active == true && m.deleted_date == null && m.asset_reg_location_id == UserProfile.asset_reg_location_id)) select m).ToList(); } model.asset_category_list = db.ms_asset_category.Where(c => c.fl_active == true && c.deleted_date == null).ToList <ms_asset_category>(); model.department_list = db.ms_department.Where(c => c.fl_active == true && c.deleted_date == null).ToList <ms_department>(); #endregion sord = (sord == null) ? "" : sord; int pageIndex = Convert.ToInt32(page) - 1; int pageSize = rows; var _qry = (from ar in db.tr_asset_registration where (ar.fl_active == true && ar.deleted_date == null && ar.asset_type_id == (int)Enum_asset_type_Key.AssetParent) && ar.company_id == model.company_id && ar.asset_reg_location_id == model.asset_reg_location_id join b in db.ms_asset_register_location on ar.asset_reg_location_id equals b.asset_reg_location_id where (b.fl_active == true && b.deleted_date == null) join e in db.ms_asset_category on ar.category_id equals e.category_id where (e.fl_active == true && e.deleted_date == null && (e.category_id == model.category_id || model.category_id == 0 || model.category_id == null)) join f in db.ms_asmin_company on ar.company_id equals f.company_id where (f.fl_active == true && f.deleted_date == null) join g in db.ms_department on ar.department_id equals g.department_id where (g.fl_active == true && g.deleted_date == null && (g.department_id == model.department_id || model.department_id == 0 || model.department_id == null)) join i in db.ms_asset_location on ar.location_id equals i.location_id where (i.fl_active == true && i.deleted_date == null && (i.location_id == model.asset_location_id)) select new Print_Asset_Items() { asset_id = ar.asset_id, asset_number = ar.asset_number, asset_name = ar.asset_name, category_id = ar.category_id, category_name = e.category_name, department_id = ar.department_id, department_name = g.department_name, Value = ar.asset_id.ToString(), Text = ar.asset_name, Checked = false }); //model.print_asset_items = _qry; if (_search) { switch (searchField) { case "asset_number": _qry = _qry.Where(t => t.asset_number.Contains(searchString)); break; case "asset_name": _qry = _qry.Where(t => t.asset_name.Contains(searchString)); break; case "department_name": _qry = _qry.Where(t => t.department_name.Contains(searchString)); break; case "employee_name": _qry = _qry.Where(t => t.category_name.Contains(searchString)); break; } } //calc paging int totalRecords = _qry.Count(); var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows); if (sord.ToUpper() == "DESC") { _qry = _qry.OrderByDescending(t => t.asset_name); _qry = _qry.Skip(pageIndex * pageSize).Take(pageSize); } else { _qry = _qry.OrderBy(t => t.asset_name); _qry = _qry.Skip(pageIndex * pageSize).Take(pageSize); } var jsonData = new { total = totalPages, page, records = totalRecords, rows = _qry }; return(Json(jsonData, JsonRequestBehavior.AllowGet)); }
public ActionResult Index(printLabelViewModel model) { sy_app_setting setting = app_setting.APPLICATION_SETTING.Where(a => a.app_key.ToUpper() == "PRINT_BASE_FOLDER").Single <sy_app_setting>(); if (string.IsNullOrWhiteSpace(setting.app_value)) { BASE_FOLDER = @"C:\ASM_PRINT\"; } else { BASE_FOLDER = setting.app_value.ToUpper(); } if (!Directory.Exists(BASE_FOLDER)) { Directory.CreateDirectory(BASE_FOLDER); } //printLabelViewModel model = new printLabelViewModel() //{ // company_id = UserProfile.company_id, // asset_reg_location_id = UserProfile.asset_reg_location_id //}; model.company_id = UserProfile.company_id; model.company_list = db.ms_asmin_company.Where(c => c.fl_active == true && c.deleted_date == null).ToList <ms_asmin_company>(); model.company = db.ms_asmin_company.Find(UserProfile.company_id); model.asset_reg_location_id = UserProfile.asset_reg_location_id; model.asset_reg_location = db.ms_asset_register_location.Find(UserProfile.asset_reg_location_id); model.asset_reg_location_list = db.ms_asset_register_location.Where(c => c.fl_active == true && c.deleted_date == null).ToList <ms_asset_register_location>(); //Set Location List if (UserProfile.asset_reg_location_id == 1) { model.asset_location_list = (from m in db.ms_asset_location.Where(m => (m.fl_active == true && m.deleted_date == null)) select m).ToList(); } else //branch { model.asset_location_list = (from m in db.ms_asset_location.Where(m => (m.fl_active == true && m.deleted_date == null && m.asset_reg_location_id == UserProfile.asset_reg_location_id)) select m).ToList(); } model.asset_category_list = db.ms_asset_category.Where(c => c.fl_active == true && c.deleted_date == null).ToList <ms_asset_category>(); model.department_list = db.ms_department.Where(c => c.fl_active == true && c.deleted_date == null).ToList <ms_department>(); if (model.asset_location_id != null && model.asset_location_id > 0) { var _qry = (from ar in db.tr_asset_registration where (ar.fl_active == true && ar.deleted_date == null && ar.asset_type_id == (int)Enum_asset_type_Key.AssetParent) && ar.company_id == model.company_id && ar.asset_reg_location_id == model.asset_reg_location_id join b in db.ms_asset_register_location on ar.asset_reg_location_id equals b.asset_reg_location_id where (b.fl_active == true && b.deleted_date == null) join e in db.ms_asset_category on ar.category_id equals e.category_id where (e.fl_active == true && e.deleted_date == null && (e.category_id == model.category_id || model.category_id == null || model.category_id == 0)) join f in db.ms_asmin_company on ar.company_id equals f.company_id where (f.fl_active == true && f.deleted_date == null) join g in db.ms_department on ar.department_id equals g.department_id where (g.fl_active == true && g.deleted_date == null && (g.department_id == model.department_id || model.department_id == null || model.department_id == 0)) join i in db.ms_asset_location on ar.location_id equals i.location_id where (i.fl_active == true && i.deleted_date == null && i.location_id == model.asset_location_id) select new Print_Asset_Items() { asset_id = ar.asset_id, asset_number = ar.asset_number, asset_name = ar.asset_name, category_id = ar.category_id, category_name = e.category_name, department_id = ar.department_id, department_name = g.department_name, Value = ar.asset_id.ToString(), Text = ar.asset_name, Checked = false }).ToList <Print_Asset_Items>(); model.print_asset_items = _qry; } return(View(model)); }