/// <summary> /// Update data in session /// </summary> /// <param name="param"></param> /// <param name="key"></param> protected void UpdateScreenParameter(ScreenParameter param, string key = null) { try { string rkey = key; if (rkey == null) { rkey = GetCurrentKey(); } HttpCookie cookie = this.HttpContext.Request.Cookies[rkey]; if (cookie != null) { string screenID = string.Empty; string time = string.Empty; if (cookie.HasKeys) { screenID = cookie.Values["ScreenID"]; time = cookie.Values["TimeKey"]; } string skey = string.Format("{0}.{1}", screenID, time); CommonUtil.ScreenObject.SetScreenParameter(skey, param); } } catch (Exception) { throw; } }
/// <summary> /// Update selected data in session /// </summary> /// <param name="callerSessionKey"></param> /// <param name="contractCode"></param> /// <param name="productCode"></param> /// <param name="instructionDate"></param> /// <param name="maintDate"></param> /// <param name="expectedMaintDate"></param> public void CTS270_UpdateDataFromChildPage(string callerSessionKey, string contractCode, string productCode, DateTime?instructionDate, DateTime?maintDate, DateTime?expectedMaintDate) { CTS270_ScreenParameter CTS270Param = GetScreenObject <CTS270_ScreenParameter>(callerSessionKey); if (CTS270Param.data != null) { var objects = from l in CTS270Param.data.dtSearchResult where l.ContractCode == contractCode && l.ProductCode == productCode && l.InstructionDate == instructionDate.Value select l; foreach (dtSearchMACheckupResult obj in objects) { obj.MaintenanceDate = maintDate; obj.ExpectedMaintenanceDate = expectedMaintDate; } CTS270Param.IsLoaded = false; ScreenParameter oparam = (ScreenParameter)GetScreenObject <object>(); if (oparam != null) { CTS270Param.CallerScreenID = oparam.ScreenID; CTS270Param.CallerModule = oparam.Module; CTS270Param.CallerKey = oparam.Key; CTS270Param.BackStep = true; } UpdateScreenObject(CTS270Param, callerSessionKey); } }
/// <summary> /// Reset screen parameter. /// </summary> /// <returns></returns> public ActionResult IVS250_resetParam() { ObjectResultData res = new ObjectResultData(); try { IVS250_ScreenParameter prm = GetScreenObject <IVS250_ScreenParameter>(); IVS250_ScreenParameter nprm = (IVS250_ScreenParameter)ScreenParameter.ResetScreenParameter(prm); UpdateScreenObject(nprm); res.ResultData = true; //ScreenParameter param = GetScreenObject<object>() as ScreenParameter; //if (param != null) //{ // ScreenParameter nparam = ScreenParameter.ResetScreenParameter(param); // if (nparam != null) // { // nparam.IsLoaded = false; // UpdateScreenObject(nparam); // } //} return(Json(res)); } catch (Exception ex) { res.AddErrorMessage(ex); return(Json(res)); } }
/// <summary> /// Reset session data /// </summary> /// <returns></returns> public ActionResult ResetSessionData() { ObjectResultData res = new ObjectResultData(); try { ScreenParameter param = GetScreenObject <object>() as ScreenParameter; if (param != null) { ScreenParameter nparam = ScreenParameter.ResetScreenParameter(param); if (nparam != null) { UpdateScreenObject(nparam); } } res.ResultData = true; } catch (Exception ex) { res.AddErrorMessage(ex); } return(Json(res)); }
/// <summary> /// Clear data from session /// </summary> /// <returns></returns> public ActionResult ClearCurrentScreenSession() { try { ScreenParameter param = GetScreenObject <object>() as ScreenParameter; if (param != null) { string methodName = string.Format("{0}_ClearSession", param.ScreenID); MethodInfo method = this.GetType().GetMethod(methodName); if (method != null) { method.Invoke(this, null); } else { UpdateScreenObject(null); } } } catch (Exception) { } return(Json(this.HttpContext.Session.Keys.Count)); }
/// <summary> /// Store the screen-specific settings /// </summary> private void StoreScreenParameters() { if (ScreenParameter != null && ScreenName != null && ScreenParameter.ContainsKey(ScreenName)) { ScreenParameter[ScreenName].SaveScreen(); } }
/// <summary> /// Initial screen environment /// </summary> /// <typeparam name="T"></typeparam> /// <param name="action"></param> /// <param name="param"></param> /// <param name="result"></param> /// <returns></returns> protected ActionResult InitialScreenEnvironment <T>(string action, ScreenParameter param, ObjectResultData result = null) where T : new() { ObjectResultData res = result; if (res == null) { res = new ObjectResultData(); } try { if (res.IsError == false) { string key = null; if (action != SECOM_AJIS.Common.Util.ConstantValue.ScreenID.C_SCREEN_ID_MAIN) { #region Generate KEY key = CommonUtil.GetMD5Hash(action + DateTime.Now.Ticks.ToString()); #endregion #region Create Object for this session if (param == null) { param = new T() as ScreenParameter; } param.Key = key; param.Module = this.GetType().Name.Replace("Controller", ""); param.ScreenID = action; if (CommonUtil.IsNullOrEmpty(param.SubObjectID)) { param.SubObjectID = "0"; } CommonUtil.ScreenObject.SetScreenParameter(key, param); #endregion } #region Call screen URL res.ResultData = CallScreenURL(param); #endregion } } catch (Exception ex) { res.AddErrorMessage(ex); } return(Json(res)); }
public static void SetScreenParameter(string key, ScreenParameter param) { try { string sessionKey = string.Format("{0}.{1}", ConstantValue.CommonValue.SESSION_SCREEN_PARAMETER_KEY, key); SetSession(sessionKey, param); } catch (Exception) { throw; } }
/// <summary> /// Update selected data to session /// </summary> /// <param name="callerSessionKey"></param> /// <param name="quotationTargetCode"></param> /// <param name="contractCode"></param> /// <param name="approvalStatusCode"></param> public void CTS030_UpdateDataFromChildPage(string callerSessionKey, string quotationTargetCode, string contractCode, string approvalStatusCode) { try { CTS030_ScreenParameter CTS030Param = GetScreenObject <CTS030_ScreenParameter>(callerSessionKey); if (CTS030Param != null) { if (CTS030Param.data != null) { var objects = from l in CTS030Param.data.dtSearchResult where l.QuotationTargetCode == quotationTargetCode select l; foreach (dtSearchDraftContractResult obj in objects) { obj.ContractCode = contractCode; obj.ApprovalStatusCode = approvalStatusCode; if (!CommonUtil.IsNullOrEmpty(approvalStatusCode)) { //Convert approvalStatusName to current language CommonUtil.MappingObjectLanguage <tbs_MiscellaneousTypeCode>(CTS030Param.approvalStatus); tbs_MiscellaneousTypeCode misc = CTS030Param.approvalStatus.Find(i => i.ValueCode == approvalStatusCode); if (!CommonUtil.IsNullOrEmpty(misc)) { obj.ApprovalStatusName = misc.ValueDisplay; obj.ApprovalStatusNameEN = misc.ValueDisplayEN; obj.ApprovalStatusNameJP = misc.ValueDisplayJP; obj.ApprovalStatusNameLC = misc.ValueDisplayLC; } } } CTS030Param.IsLoaded = false; ScreenParameter oparam = (ScreenParameter)GetScreenObject <object>(); if (oparam != null) { CTS030Param.CallerScreenID = oparam.ScreenID; CTS030Param.CallerModule = oparam.Module; CTS030Param.CallerKey = oparam.Key; CTS030Param.BackStep = true; } UpdateScreenObject(CTS030Param, callerSessionKey); } } } catch (Exception) { throw; } }
/// <summary> /// Check URL is correct format /// </summary> /// <param name="filterContext"></param> /// <returns></returns> private bool CheckURLAction(ActionExecutingContext filterContext) { if (this.ScreenID != SECOM_AJIS.Common.Util.ConstantValue.ScreenID.C_SCREEN_ID_MAIN) { bool isFoundKey = false; bool isPopup = false; BaseController bController = filterContext.Controller as BaseController; if (bController != null) { ScreenParameter param = bController.GetScreenObject <object>() as ScreenParameter; if (param != null) { if (CommonUtil.IsNullOrEmpty(param.Key) == false && param.IsLoaded == false) { isFoundKey = true; param.IsLoaded = true; } isPopup = param.IsPopup; } } if (isFoundKey == false) { string url = CommonUtil.GenerateURL("Common", SECOM_AJIS.Common.Util.ConstantValue.ScreenID.C_SCREEN_ID_MAIN); if (isPopup == true) { RedirectObject o = new RedirectObject(); o.URL = url; JsonResult jRes = new JsonResult(); jRes.Data = o; filterContext.Result = jRes; } else { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Common", action = SECOM_AJIS.Common.Util.ConstantValue.ScreenID.C_SCREEN_ID_MAIN })); } return(false); } } return(true); }
/// <summary> /// Change current language and reload screen with selected language. /// </summary> /// <param name="lang"></param> /// <returns></returns> public void changeLanguageDsTransData(string lang) { try { if (!CommonUtil.IsNullOrEmpty(lang)) { dsTransDataModel dstrans = CommonUtil.dsTransData; lang = lang.ToLower(); if (lang == CommonValue.DEFAULT_SHORT_LANGUAGE_EN) { dstrans.dtTransHeader.Language = CommonValue.DEFAULT_LANGUAGE_EN; } else if (lang == CommonValue.DEFAULT_SHORT_LANGUAGE_JP) { dstrans.dtTransHeader.Language = CommonValue.DEFAULT_LANGUAGE_JP; } else { dstrans.dtTransHeader.Language = CommonValue.DEFAULT_LANGUAGE_LC; } //Update Language CommonUtil.MappingObjectLanguage <OfficeDataDo>(dstrans.dtOfficeData); CommonUtil.dsTransData = dstrans; //Update Language for menu list CommonUtil.MappingObjectLanguage <MenuName>(CommonUtil.MenuNameList); Session.Remove("Menu"); ScreenParameter param = GetScreenObject <object>() as ScreenParameter; if (param != null) { ScreenParameter nparam = ScreenParameter.ResetScreenParameter(param); if (nparam != null) { nparam.IsLoaded = false; nparam.BackStep = true; UpdateScreenObject(nparam); } } } } catch (Exception) { } }
/// <summary> /// Update data in session /// </summary> /// <param name="param"></param> /// <param name="key"></param> protected void UpdateScreenObject(ScreenParameter param, string key = null) { try { string rkey = key; if (rkey == null) { rkey = GetCurrentKey(); } if (CommonUtil.IsNullOrEmpty(rkey) == false) { CommonUtil.ScreenObject.SetScreenParameter(rkey, param); } } catch (Exception) { throw; } }
public ActionResult InitialDownloadFile() { ObjectResultData res = new ObjectResultData(); try { ScreenParameter param = GetScreenObject <object>() as ScreenParameter; if (param != null) { param.IsLoaded = false; param.BackStep = true; } res.ResultData = true; } catch { } return(Json(res)); }
/// <summary> /// Method for generate URL /// </summary> /// <param name="param"></param> /// <param name="CallerScreen"></param> /// <returns></returns> protected string CallScreenURL(ScreenParameter param, bool CallerScreen = false) { try { if (param == null) { return(null); } string key = param.Key; string module = param.Module; string screenID = param.ScreenID; if (CallerScreen == true) { key = param.CallerKey; module = param.CallerModule; screenID = param.CallerScreenID; } if (CommonUtil.IsNullOrEmpty(key) == false) { return(string.Format("/{0}/{1}?k={2}", module, screenID, key)); } else { return(string.Format("/{0}/{1}", module, screenID)); } } catch (Exception) { throw; } }
/// <summary> /// Check it has data in session? /// </summary> /// <returns></returns> public ActionResult CheckSession() { ObjectResultData res = new ObjectResultData(); try { ScreenParameter param = GetScreenObject <object>() as ScreenParameter; if (param != null) { if (param.BackStep == true) { param.BackStep = false; res.ResultData = true; } } } catch (Exception ex) { res.AddErrorMessage(ex); } return(Json(res)); }
/// <summary> /// Get data from session /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <returns></returns> public T GetScreenObject <T>(string key = null) where T : new() { try { string rkey = key; if (rkey == null) { rkey = GetCurrentKey(); } if (CommonUtil.IsNullOrEmpty(rkey) == false) { T obj = CommonUtil.ScreenObject.GetScreenParameter <T>(rkey); if (obj != null && obj is ScreenParameter) { ScreenParameter po = obj as ScreenParameter; if (po.CallerKey != null) { ScreenParameter cpo = (ScreenParameter)CommonUtil.ScreenObject.GetScreenParameter <object>(po.CallerKey); if (cpo != null) { cpo.IsLoaded = false; } } } return(obj); } return(default(T)); } catch (Exception) { throw; } }
/// <summary> /// Event on action executing for check session is expired? /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { try { bool checkScreenSession = true; string action = filterContext.RouteData.Values["action"].ToString(); if (action == "CMS000" || action == "CMS010" || action == "Login" || action == "CMS010_CHECK" || action == "CMS020_Retrive" || action == "GetMessage" || action == "changeLanguageDsTransData" || action == "Logout" || action == "GetLanguageMessage" || action == "ClearCurrentScreenSession" || action == "CMS000_RedirectScreen" || action.ToUpper().Contains("UPLOAD") || action.ToUpper().Contains("ATTACH")) { checkScreenSession = false; } dsTransDataModel dsTrans = CommonUtil.dsTransData; if (dsTrans == null) { //if (checkScreenSession) //{ //Check Action from ajax caller or load view string ajax = filterContext.HttpContext.Request["ajax"]; if ((ajax == "1") && action != "CMS010" && action != "CMS010_CHECK" && action != "Login") { RedirectObject o = new RedirectObject(); o.URL = CommonUtil.GenerateURL("Common", "CMS010") + "?timeout=1"; JsonResult jRes = new JsonResult(); jRes.Data = o; filterContext.Result = jRes; } else if (checkScreenSession == true) { bool skip = false; doDirectScreen dos = null; /* *** This method will only in case url has send parameter (expect "k" parameter). *** */ #region Initial redirect method if (action != "CMS020") { dos = new doDirectScreen(); dos.Controller = filterContext.RouteData.Values["controller"].ToString(); dos.ScreenID = action; foreach (string key in filterContext.HttpContext.Request.QueryString.AllKeys) { if (key == "k") { skip = true; break; } string val = filterContext.HttpContext.Request[key]; if (dos.Parameters == null) { dos.Parameters = new List <string>(); dos.Values = new List <string>(); } dos.Parameters.Add(key); dos.Values.Add(val); } } #endregion if (skip == false && dos != null) { CommonUtil.SetSession("DIRECT_SCREEN", dos); filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Common", action = "CMS000" })); } else { if (action == "CMS020") { BaseController bController = filterContext.Controller as BaseController; if (bController != null) { filterContext.Result = bController.RedirectToLogin(); } } else { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Common", action = "CMS010" })); } } } return; //} } else { BaseController bController = filterContext.Controller as BaseController; if (bController != null) { ScreenParameter param = bController.GetScreenObject <object>() as ScreenParameter; if (param != null) { dsTrans.dtTransHeader.ScreenID = param.ScreenID; } else if (checkScreenSession) { bool isInitial = false; MethodInfo method = bController.GetType().GetMethod(action); if (method != null) { if (method.GetCustomAttributes(typeof(InitializeAttribute), true).Length > 0) { isInitial = true; } } if (action.EndsWith("_Authority") || isInitial == true) { dsTrans.dtTransHeader.ScreenID = action.Replace("_Authority", ""); /* *** This method will only in case url has send parameter (expect "k" parameter). *** */ #region Initial redirect method if (action != "CMS020" && isInitial == true) { doDirectScreen dos = new doDirectScreen(); dos.Controller = filterContext.RouteData.Values["controller"].ToString(); dos.ScreenID = action; bool skip = false; foreach (string key in filterContext.HttpContext.Request.QueryString.AllKeys) { if (key == "k") { skip = true; break; } string val = filterContext.HttpContext.Request[key]; if (dos.Parameters == null) { dos.Parameters = new List <string>(); dos.Values = new List <string>(); } dos.Parameters.Add(key); dos.Values.Add(val); } if (skip == false) { CommonUtil.SetSession("DIRECT_SCREEN", dos); filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Common", action = "CMS000" })); } } #endregion } else { if (CommonUtil.dsTransData != null) { RedirectObject o = new RedirectObject(); o.URL = CommonUtil.GenerateURL("Common", "CMS020"); JsonResult jRes = new JsonResult(); jRes.Data = o; filterContext.Result = jRes; } else { RedirectObject o = new RedirectObject(); o.URL = CommonUtil.GenerateURL("Common", "CMS010") + "?timeout=1"; JsonResult jRes = new JsonResult(); jRes.Data = o; filterContext.Result = jRes; return; } } } } DateTime dateTime = DateTime.Now; dateTime = dateTime.AddTicks(-(dateTime.Ticks % TimeSpan.TicksPerSecond)); dsTrans.dtOperationData.ProcessDateTime = dateTime; dsTrans.dtOperationData.GUID = Guid.NewGuid().ToString().ToUpper(); CommonUtil.dsTransData = dsTrans; } string actionUpper = action.ToUpper(); if (actionUpper.Contains("EDIT") || actionUpper.Contains("SAVE") || actionUpper.Contains("UPDATE") || actionUpper.Contains("DELETE")) { string[] aItem = actionUpper.Split('_'); string screenID = aItem[0]; } base.OnActionExecuting(filterContext); } catch { } }
/// <summary> /// Event on action executing for initial screen information /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { try { if (CheckURLAction(filterContext) == false) { return; } dsTransDataModel dsTrans = CommonUtil.dsTransData; if (dsTrans == null) { return; } BaseController bController = filterContext.Controller as BaseController; #region Init Menu InitialMenu(filterContext); #endregion #region Screen ID //dsTrans.dtTransHeader.ScreenID = ScreenID; filterContext.Controller.ViewBag.ScreenCode = ScreenID; #endregion #region Screen Name string SubObjectID = "0"; if (bController != null) { ScreenParameter param = bController.GetScreenObject <object>() as ScreenParameter; if (param != null) { SubObjectID = param.SubObjectID; } } string strScreenName = null; //List<MenuName> mm = CommonUtil.MenuNameList; // Edit by Narupon W. : 1/Jan/2012 //List<MenuName> mm = CommonUtil.dsTransData.dtMenuNameList; List <MenuName> mm = new List <MenuName>(); if (CommonUtil.dsTransData != null) { if (CommonUtil.dsTransData.dtMenuNameList != null) { mm = CommonUtil.dsTransData.dtMenuNameList; } else { mm = CommonUtil.MenuNameList; } } else { mm = CommonUtil.MenuNameList; } if (!CommonUtil.IsNullOrEmpty(mm)) { IEnumerable <MenuName> ScrNameIEnum = (from c in mm where c.ObjectID == ScreenID && c.SubObjectID == SubObjectID select c); if (ScrNameIEnum != null && ScrNameIEnum.ToList().Count > 0) { CommonUtil.MappingObjectLanguage(ScrNameIEnum.ToList()[0]); strScreenName = ScrNameIEnum.ToList()[0].ObjectName; } } filterContext.Controller.ViewBag.ScreenName = strScreenName; #endregion #region Common search if (bController != null) { ScreenSearchParameter param = bController.GetScreenObject <object>() as ScreenSearchParameter; if (param != null) { if (param.CommonSearch != null) { filterContext.Controller.ViewBag.SearchContractCode = param.CommonSearch.ContractCode; filterContext.Controller.ViewBag.SearchProjectCode = param.CommonSearch.ProjectCode; } } } #endregion // Change title to {Screen Name} [SECOM-AJIS] ////filterContext.Controller.ViewBag.Title = CommonUtil.TextCodeName(ScreenID, strScreenName, "-"); //filterContext.Controller.ViewBag.Title = String.Format("{0} [SECOM-AJIS]", strScreenName); filterContext.Controller.ViewBag.Title = String.Format("{0} [SIMS]", strScreenName); //Modify by Jutarat A. on 21022013 filterContext.Controller.ViewBag.UserName = dsTrans.dtUserData.EmpFullName; filterContext.Controller.ViewBag.ROWS_PER_PAGE_FOR_SEARCHPAGE = CommonValue.ROWS_PER_PAGE_FOR_SEARCHPAGE; filterContext.Controller.ViewBag.ROWS_PER_PAGE_FOR_VIEWPAGE = CommonValue.ROWS_PER_PAGE_FOR_VIEWPAGE; filterContext.Controller.ViewBag.ROWS_PER_PAGE_FOR_INVENTORY_CHECKING = CommonValue.ROWS_PER_PAGE_FOR_INVENTORY_CHECKING; /* --- Update Data --- */ CommonUtil.dsTransData = dsTrans; base.OnActionExecuting(filterContext); } catch (Exception) { } }
/// <summary> /// Get data from session /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <returns></returns> protected T GetScreenParameter <T>(string key = null) where T : new() { try { T param = default(T); string rkey = key; if (rkey == null) { rkey = GetCurrentKey(); } HttpCookie cookie = this.HttpContext.Request.Cookies[rkey]; if (cookie != null) { string screenID = string.Empty; string subObjectID = "0"; string callerKey = string.Empty; string callerScreenID = string.Empty; string callerModule = string.Empty; bool isPopup = false; string time = string.Empty; if (cookie.HasKeys) { screenID = cookie.Values["ScreenID"]; callerModule = cookie.Values["CallerModule"]; callerScreenID = cookie.Values["CallerScreenID"]; callerKey = cookie.Values["CallerKey"]; isPopup = (cookie.Values["IsPopup"] == "1"); time = cookie.Values["TimeKey"]; if (CommonUtil.IsNullOrEmpty(cookie.Values["SubObjectID"]) == false) { subObjectID = cookie.Values["SubObjectID"]; } } if (CommonUtil.IsNullOrEmpty(screenID) == false && CommonUtil.IsNullOrEmpty(time) == false) { string skey = string.Format("{0}.{1}", screenID, time); param = CommonUtil.ScreenObject.GetScreenParameter <T>(skey); } if (param != null) { ScreenParameter sparam = param as ScreenParameter; if (sparam != null) { sparam.ScreenID = screenID; sparam.CallerScreenID = callerScreenID; sparam.CallerModule = callerModule; sparam.CallerKey = callerKey; sparam.IsPopup = isPopup; sparam.SubObjectID = subObjectID; } } } else if (rkey != null) { throw new Exception("Cookie is missing"); } return(param); } catch (Exception) { throw; } }