//private readonly Regex r = new Regex("^/tieu-de/(.*)$", RegexOptions.IgnoreCase); //Regex regJS = new Regex("^(.*)([.]v[0-9]+)([.](js|css))$", RegexOptions.IgnoreCase); //Context.RewritePath(string.Format("{0}{1}", matchJS.Groups[1].Value, matchJS.Groups[3].Value)); public static void OnBeginRequest(object sender, System.EventArgs e) { HttpApplication app = sender as HttpApplication; HttpContext Context = app.Context; StreamReader readerInput = null; string path = Context.Request.Url.AbsolutePath.Split('?')[0].ToLower(), sResult = string.Empty, msg_ = string.Empty, sessionid_ = string.Empty, mid_ = string.Empty, key_ = string.Empty, control_ = string.Empty, tab = string.Empty, action = string.Empty; decimal msg_id = 0; switch (path) { case "/msg/get": Context.Response.Cache.SetCacheability(HttpCacheability.NoCache); Context.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); Context.Response.Cache.SetNoStore(); Context.Response.Cache.SetNoServerCaching(); msg_ = Global.msg_Get(); Context.Response.Write(msg_); Context.Response.End(); break; case "/favicon.ico": Context.Response.End(); break; case "/": case "/default.aspx": RenderHome(Context, "/index.htm"); break; case "/admin.html": case "/admin": response_Admin(Context); break; case "/message": msgSSE.Connect(Context); break; case "/socket": socket.response_Port(Context); break; case "/proxy": proxy.response_Forward(sender); break; case "/excel-temp": key_ = Context.Request["key"]; db <omKeyword> .get_Excel_Temp(Context.Response); break; case "/excel-export": key_ = Context.Request["key"]; db <omKeyword> .get_Excel_Temp(Context.Response); break; case "/excel-import": #region HttpPostedFile file = Context.Request.Files["file"]; if (file != null && file.ContentLength > 0) { string api = Context.Request["api"]; sessionid_ = Context.Request.Cookies["sessionid"] == null ? string.Empty : Context.Request.Cookies["sessionid"].Value; //file.SaveAs(Context.Server.MapPath(Path.Combine("~/App_Data/", fname))); msg m = new msg(msLAYER.FILE_UPLOAD_IMPORT, msLAYOUT.NONE, msCONTROL.NONE, msGRID.NONE, string.Empty); msg_id = m.ID; string fname = msg_id.ToString() + sessionid_ + "," + api + "," + Path.GetFileName(file.FileName); cacheHashtable.Set(msg_id.ToString(), fname); cacheHashtable.Set(fname, file.InputStream); socket.Send(msg_id, sessionid_, true); Context.Response.Write(fname); } Context.Response.End(); #endregion break; case "/upload/photo": #region HttpPostedFile photo = Context.Request.Files["file"]; if (photo != null && photo.ContentLength > 0) { string model = Context.Request["model"]; string viewid = Context.Request["viewid"]; sessionid_ = Context.Request.Cookies["sessionid"] == null ? string.Empty : Context.Request.Cookies["sessionid"].Value; string dir = Context.Server.MapPath("~/Views/Page/" + viewid + "/upload/" + model); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string fname = Context.Server.MapPath(Path.Combine("~/Views/Page/" + viewid + "/upload/" + model, photo.FileName)); photo.SaveAs(fname); Context.Response.Write(viewid + "/upload/" + model + "/" + photo.FileName); } Context.Response.End(); #endregion break; case "/data/file": #region tab = Context.Request["tab"]; if (!string.IsNullOrEmpty(tab)) { string model = tab.model_Format(), viewid = Context.Request["viewid"]; sResult = "[]"; string fi = string.Format(@"{0}page\{1}\upload\{2}", dbVidew.PathRoot, viewid, model); new Switch("om" + model) .Case <omEmail_temp>(it => { var afi = Directory.GetFiles(fi).Select(x => x.ToLower()).ToArray(); var ai = db <omEmail_temp> .All().Where(x => afi.Any(o => o.Contains(x.title.ToLower()))).ToArray(); sResult = JsonConvert.SerializeObject(ai); }); Context.Response.Write(sResult); } Context.Response.End(); #endregion break; case "/data/grid": #region tab = Context.Request["tab"]; string json = string.Empty; if (!string.IsNullOrEmpty(tab)) { readerInput = new StreamReader(HttpContext.Current.Request.InputStream); string s = readerInput.ReadToEnd(); if (!string.IsNullOrEmpty(s) && s.Length > 8) { s = HttpUtility.UrlDecode(s); s = s.Substring(8, s.Length - 8); w2uiGridRequest o = JsonConvert.DeserializeObject <w2uiGridRequest>(s); int page_number = 0, page_size = 50; if (o.offset > 0) { page_number = o.offset / page_size + 1; } string textSearch = Context.Request.Cookies["search_page_tabgrid_" + tab] == null ? string.Empty : Context.Request.Cookies["search_page_tabgrid_" + tab].Value; json = db.queryJson(page_number, page_size, tab, textSearch); } } if (string.IsNullOrEmpty(json)) { json = @"{ status: ""error"", message: ""Không có dữ liệu"", postData: [] }"; } Context.Response.ContentType = "application/json; charset=utf-8"; Context.Response.Write(json); Context.Response.End(); #endregion break; case "/api/link": #region readerInput = new StreamReader(HttpContext.Current.Request.InputStream); msg_ = readerInput.ReadToEnd(); sResult = string.Empty; if (!string.IsNullOrEmpty(msg_)) { try { omAction o = JsonConvert.DeserializeObject <omAction>(msg_); if (o._type == "link") { string model = o._model.model_Format(); o._model = model; sResult = view.get_config_Grid(o._viewid, "tab", o._model, true); new Switch("om" + model) .Case <omEmail_temp>(x => { }); } } catch { } } Context.Response.ContentType = "text/plain; charset=utf-8"; Context.Response.Write(sResult); Context.Response.End(); #endregion break; case "/api/action": #region readerInput = new StreamReader(HttpContext.Current.Request.InputStream); msg_ = readerInput.ReadToEnd(); sResult = string.Empty; if (!string.IsNullOrEmpty(msg_)) { try { omAction o = JsonConvert.DeserializeObject <omAction>(msg_); if (o._type == "action") { string fi = string.Empty; if (string.IsNullOrEmpty(o.command)) { } else { fi = string.Format(@"{0}page\{1}\admin\action\_cmd\{2}.js", dbVidew.PathRoot, o._viewid, o.command); } if (File.Exists(fi)) { sResult = File.ReadAllText(fi); } else { } } sResult = sResult .Replace("[model_key]", o._model); } catch { } } Context.Response.ContentType = "text/plain; charset=utf-8"; Context.Response.Write(sResult); Context.Response.End(); #endregion break; case "/api": #region msg_ = Context.Request["msg"]; // vid,sid,mid,control,action,base64 // 0 , 1 , 2 , 3 , 4 , 5 if (!string.IsNullOrEmpty(msg_)) { string[] a = msg_.Split(','); if (a.Length > 5) { string mid = a[2]; if (decimal.TryParse(mid, out msg_id)) { Global.msg_Add(msg_); cacheHashtable.Set(mid, msg_); sessionid_ = Context.Request.Cookies["sessionid"] == null ? string.Empty : Context.Request.Cookies["sessionid"].Value; socket.Send(msg_id, sessionid_, true); //omApiLog.Create(viewID, sessionid_, msg_id, Context.Request.UrlReferrer, msg_); } } } Context.Response.End(); #endregion break; default: #region if (path.Contains(".html")) { int viewID = dbVidew.domain_GetView(Context.Request.Url.Host); Context.Items[_const.viewID] = viewID; RenderPage(Context, viewID, path); //socket.Send(new wsData(wsType.USER_LOG, )) } else { int viewID = dbVidew.domain_GetView(Context.Request.Url.Host); Context.Items[_const.viewID] = viewID; string fi = string.Format("/views/page/{0}", viewID); Context.RewritePath(fi + path); } #endregion break; } }
public static string get_config_Grid(string viewid, string folder, string file, bool isPopup = false) { string s_grid = "", model = file.model_Format(), ___model = db.m_split_controlAction + file; string filePath = string.Format(@"{0}page\{1}\admin\{2}\{3}.js", dbVidew.PathRoot, viewid, folder, model); if (File.Exists(filePath)) { s_grid = File.ReadAllText(filePath); } else { #region var acol = db <omColumn> .Query(x => x._tabname == model && x._w2ui == true).OrderBy(x => x._order).ToArray(); string jcol = JsonConvert.SerializeObject(acol, Formatting.Indented); if (acol.Length == 0) { jcol = "[]"; } string jButton = "[]"; var bar = new List <omAction>() { }; var input_search = new omAction() { type = "html", id = "page_tabgridsearch_" + ___model, html = @"<div style='padding: 3px 10px;'> SEARCH " + @"<input size='10' placeholder='enter to search' onkeyup=""api.admin_tab_grid_search(event," + @"'page_tabgrid" + ___model + @"','" + ___model + @"',this.value)"" id='search_page_tabgrid" + ___model + @"'/></div>" }; if (bar.Count == 0) { bar.Add(input_search); } else { bar.Insert(0, input_search); } // LINK var alink = db.m_arrayModel.Where(x => x.StartsWith("om" + model + "_")).Select(x => x.Substring(2, x.Length - 2)).ToArray(); for (int k = 0; k < alink.Length; k++) { string name = alink[k].model_Format(); bar.Add(new omAction() { _model = name, _type = "link", _sessionid = "0", _viewid = "0", type = "button", id = name, caption = name.Replace('_', ' '), icon = "" }); } // ACTION bar.Add(new omAction() { type = "spacer" }); var mi = db <omAction> .All() .Where(x => x._status == oItemStatus.ACTIVED) .Select((x, k) => { x._model = model; x._type = "action"; x._sessionid = "0"; x._viewid = "0"; string cmd = x.id; x.tag = cmd; x.id = (k + 1).ToString(); return(x); }) .ToArray(); var mn = new omAction() { type = "menu", caption = "Action", icon = "fa-wrench", items = mi }; bar.Add(mn); for (int k = 0; k < jButton.Length; k++) { bar[k].position = 1; } jButton = JsonConvert.SerializeObject(bar, Formatting.Indented); #endregion #region [ SCRIPT GRID ] string url_api = "/data/grid?tab=" + model; var ai = db <omApi_model> .Query(x => x.model == model); if (ai.Length > 0) { url_api = ai[0].api + model; } s_grid = @" var v_page_tabgrid" + ___model + @" = { name: 'page_tabgrid" + ___model + @"', autoLoad: true, limit: 50, disableCVS: true, url : '" + url_api + @"', show: { toolbar: true, footer: true, lineNumbers: true, selectColumn: true, toolbarSearch: false, toolbarInput: false, searchAll: false, }, sortData: [{ field: 'recid', direction: 'asc' }], columns: " + jcol + @", onClick: function (event) { var record = this.get(event.recid); var sr = record.recid + ' | ' + record.fname + ' | ' + record.lname + ' | ' + record.email + ' | ' + record.sdate; //w2alert(sr); //setTimeout(function () { // w2ui['grid2'].clear(); // this.selectNone(); // this.remove(event.recid); //}, 150); }, toolbar: { items: " + jButton + @", onClick: function (target, eventData) { api.admin_grid_toolbar__click(target, eventData); } }, records: [ ], onRender: function(event) { event.onComplete = function () { api.admin_tab_grid_search_text_set(this.name); w2ui['page_tabgrid" + ___model + @"'].toggleColumn('recid'); w2ui['page_tabgrid" + ___model + @"'].toggleColumn('_key'); } } }; $().w2grid(v_page_tabgrid" + ___model + @"); function tab" + ___model + @"_reload(objectAPI) { var o = objectAPI; w2ui['main_layout'].content('main', w2ui['page_tabgrid" + ___model + @"']); } "; if (isPopup) { s_grid += @" api.popup({ name: 'popup_login', height: 480, width: 800, title: '" + model.Replace('_', ' ') + @"', bg: false, closeshow: true, close: function (pid) { }, open: function (pid) { api.log(pid); }, grid: v_page_tabgrid" + ___model + @" }); "; } #endregion } string js = db.text_EncodeHtml(s_grid); js.Replace("&", "&"); js.Replace("'", "'"); js.Replace("'", "'"); js.Replace("/", "/"); js.Replace("'", "'"); js.Replace("/", "/"); js.Replace("<", "<"); js.Replace(">", ">"); js.Replace(" ", " "); js.Replace(""", @""""); return(js); }