public static string GetClientArray <T>(IEnumerable <T> eValue, string VarName, bool AddScriptTag) { List <string> aStmt = new List <string>(); aStmt.Add("var " + VarName + " = [];"); int i = -1; foreach (T Value in eValue) { string Quot = ""; string ValueNew = ""; if (CLang.In(typeof(T), typeof(string), typeof(char))) { Quot = "\""; ValueNew = CScript.ReplaceForScriptVariable(Value.ToString()); } else if (typeof(T) == typeof(DateTime)) { ValueNew = CScript.GetJavaScriptDateTime(Convert.ToDateTime(Value)); } else { Quot = ""; ValueNew = Value.ToString(); } aStmt.Add(VarName + "[" + (++i).ToString() + "] = " + Quot + ValueNew + Quot + ";"); } return(CScript.GetScript(aStmt, AddScriptTag)); }
private static void AlertAndFocus(string Msg, string CtlClientID, Page p, Control ctl) { List <string> aStmt = new List <string>(); string Alert = CScript.GetScriptAlert(Msg); aStmt.Add(Alert); if (!string.IsNullOrEmpty(CtlClientID)) { string Focus = GetScriptFocus(CtlClientID); aStmt.Add(Focus); } string Stmt = CScript.GetScript(aStmt); if (p != null) { p.ClientScript.RegisterStartupScript(typeof(Page), "AlertAndFocus", Stmt, true); } else { ScriptManager.RegisterStartupScript(ctl, ctl.GetType(), "AlertAndFocus", Stmt, true); } }
public static string GetScriptAlert(string Msg, bool AddScriptTag) { string s = "alert(\"" + CScript.ReplaceForScriptVariable(Msg) + "\");"; s = CScript.GetScript(new string[] { s }, AddScriptTag); return(s); }
public static string GetScriptDocumentWrite(string Value, bool AddScriptTag) { string s = "document.write(\"" + CScript.ReplaceForScriptVariable(Value) + "\");"; s = CScript.GetScript(new string[] { s }, AddScriptTag); return(s); }
public static void Alert(string Msg, bool EndResponse, HttpContext ctx) { string Alert = CScript.GetScriptAlert(Msg); string s = CScript.GetScript(new string[] { Alert }, true); HttpContext.Current.Response.Write(s); if (EndResponse) { ctx.Response.End(); } }
public static void AlertAndClose(string Msg, bool EndResponse, HttpContext ctx) { string Alert = CScript.GetScriptAlert(Msg); string Close = "window.close();"; string s = CScript.GetScript(new string[] { Alert, Close }, true); ctx.Response.Write(s); if (EndResponse) { ctx.Response.End(); } }
public static void AlertAndBack(string Msg, bool EndResponse, HttpContext ctx) { string Alert = CScript.GetScriptAlert(Msg); string Back = "history.back();\r\n"; string s = CScript.GetScript(new string[] { Alert, Back }, true); ctx.Response.Write(s); if (EndResponse) { ctx.Response.End(); } }
public static void SubmitOpenerAndCloseWindow(string OpenerFrmName) { List <string> aStmt = new List <string>(); aStmt.Add("if (window.opener) {"); aStmt.Add(" window.opener.document.forms[\"" + OpenerFrmName + "\"].submit();"); aStmt.Add("}"); //팝업 띄운 창에서 window.close()를 쓰면 Chrome, Safari의 경우 fail 메세지 표시되고 안 닫히므로 타이머를 사용해 닫음. aStmt.Add("setTimeout(function () { window.close(); }, 100);"); string s = CScript.GetScript(aStmt, true); HttpContext.Current.Response.Write(s); HttpContext.Current.Response.End(); }
public static void AlertAndRedirectTo(string Msg, string Url, bool EndResponse, HttpContext ctx) { List <string> aStmt = new List <string>(); aStmt.Add(CScript.GetScriptAlert(Msg)); aStmt.Add("window.location.href = \"" + Url + "\";"); string s = CScript.GetScript(aStmt, true); ctx.Response.Write(s); if (EndResponse) { ctx.Response.End(); } }
public static void RedirectOpenerAndCloseWindow(string Url) { List <string> aStmt = new List <string>(); aStmt.Add("if (window.opener)"); aStmt.Add("{"); aStmt.Add(" window.opener.location.href = \"" + Url + "\";"); aStmt.Add("}"); //팝업 띄운 창에서 window.close()를 쓰면 Chrome, Safari의 경우 fail 메세지 표시되고 안 닫히므로 타이머를 사용해 닫음. aStmt.Add("setTimeout(function () { window.close(); }, 100);"); string s = CScript.GetScript(aStmt, true); HttpContext.Current.Response.Write(s); HttpContext.Current.Response.End(); }
public static string GetScriptWrite(string Version, int Width, int Height, FlashAllowScriptAccess AllowScriptAccess, FlashWmode Wmode, FlashSalign Salign, FlashScale Scale, Color BgColor, string FlashVars, string Movie, string FlashId, string DivIdForContainer) { string DivId = string.IsNullOrEmpty(DivIdForContainer) ? "div" + FlashId : DivIdForContainer; Dictionary <string, string> nv = new Dictionary <string, string>(); nv.Add("menu", "false"); nv.Add("allowScriptAccess", AllowScriptAccess.ToString()); nv.Add("wmode", Wmode.ToString()); nv.Add("salign", Salign.ToString()); nv.Add("scale", Scale.ToString()); nv.Add("bgcolor", CColorConv.GetHexaByColor(BgColor)); nv.Add("flashvars", FlashVars); string Params = CScript.GetScriptKeyValueByColon(nv, true); string s = ""; if (string.IsNullOrEmpty(DivIdForContainer)) { s += "<div id=\"" + DivId + "\">" + "<a href=\"http://www.adobe.com/go/getflashplayer\">" + "<img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" />" + "</a>" + "</div>\r\n"; } List <string> aStmt = new List <string>(); aStmt.Add("var flashvars = false;"); aStmt.Add("var params = { " + Params + " };"); aStmt.Add("var attributes = { id: \"" + FlashId + "\", name: \"" + FlashId + "\" };"); aStmt.Add("swfobject.embedSWF(\"" + Movie + "\", \"" + DivId + "\", \"" + Width.ToString() + "\", \"" + Height.ToString() + "\", \"" + Version + "\", \"\", flashvars, params, attributes);"); string s2 = CScript.GetScript(aStmt, true); return(s + s2); }
/// <summary> /// TextBox의 TextMode가 MultiLine이면 MaxLength가 먹히지 않아 사용함. /// </summary> /// <param name="txt"></param> public static void LimitToMaxLength(Page p, TextBox txt) { List <string> aStmt = new List <string>(); string TxtCliendID = txt.ClientID; int MaxLength = txt.MaxLength; aStmt.Add("var " + TxtCliendID + " = document.getElementById(\"" + TxtCliendID + "\");"); aStmt.Add("if (" + TxtCliendID + ") {"); aStmt.Add(" " + TxtCliendID + ".onkeyup = function (e) {"); aStmt.Add(" var e = window.event || e;"); aStmt.Add(" var src = e.srcElement || e.target;"); aStmt.Add(" var maxlength = "+ MaxLength.ToString() + ";"); aStmt.Add(" if (src.value.length > maxlength) {"); aStmt.Add(" alert(\"허용길이인 \" + maxlength + \"자를 초과했습니다.\");"); aStmt.Add(" src.value = src.value.substring(0, maxlength);"); aStmt.Add(" }"); aStmt.Add(" }"); aStmt.Add("}"); string Stmt = CScript.GetScript(aStmt); p.ClientScript.RegisterStartupScript(typeof(Page), "LimitToLength" + TxtCliendID, Stmt, true); }
/// <summary> /// ASP.Net에서 Cookie를 설정할 때 Domain 속성을 설정하면 실제로는 작동되지 않아 JScript로 Cookie를 설정함. /// </summary> /// <param name="Key"></param> /// <param name="Value"></param> /// <param name="ExpireDays"></param> /// <param name="Domain"></param> /// <returns></returns> public static string SetCookie(string Key, string Value, int ExpireDays, string Domain) { List <string> aStmt = new List <string>(); aStmt.Add("var Now = new Date();"); aStmt.Add("Now.setDate(Now.getDate() + " + ExpireDays.ToString() + ");"); aStmt.Add("var Cookie = \"" + Key + "=" + Value + ";\";"); aStmt.Add("Cookie += \"path=/;\";"); if (ExpireDays > 0) { aStmt.Add("Cookie += \"expires=\" + Now.toGMTString() + \";\";"); } if (Domain != "") { aStmt.Add("Cookie += \"domain=" + Domain + ";\";"); } aStmt.Add("document.cookie = Cookie;"); return(CScript.GetScript(aStmt, false)); }
public static string GetScript(string Source, string Id, SInfoSilverlightProperties Properties, SInfoSilverlightEvents Events, Dictionary <string, string> InitParams) { /* * <div id="silverlightControlHost"> * <script type="text/javascript"> * var source = "/ClientBin/RoundedBox.xap"; * var parentElement = silverlightControlHost; * var id = "slPlugin"; * var properties = { * width: "100", height: "100", * background: "white", alt: alt, * minRuntimeVersion: "2.0.30800.0" * }; * var events = { onError: onSLError, onLoad: onSLLoad }; * var initParams = "param1=value1,param2=value2"; * * Silverlight.createObject(source, parentElement, id, properties, events, initParams, ""); * </script> * </div> */ string DivId = "div" + Id; List <string> aStmt = new List <string>(); aStmt.Add("var source = \"" + Source + "\";"); aStmt.Add("var parentElement = " + DivId + ";"); aStmt.Add("var id = \"" + Id + "\";"); aStmt.Add("var properties = {"); Dictionary <string, string> dicProperties = new Dictionary <string, string>(); if (Properties.width != 0) { dicProperties.Add("width", Properties.width.ToString()); } if (Properties.height != 0) { dicProperties.Add("height", Properties.height.ToString()); } if (!string.IsNullOrEmpty(Properties.background)) { dicProperties.Add("background", Properties.background); } if (!string.IsNullOrEmpty(Properties.alt)) { dicProperties.Add("alt", Properties.alt); } if (!string.IsNullOrEmpty(Properties.minRuntimeVersion)) { dicProperties.Add("minRuntimeVersion", Properties.minRuntimeVersion); } aStmt.Add(CScript.GetScriptKeyValueByColon(dicProperties, true)); aStmt.Add("};"); aStmt.Add("var events = {"); Dictionary <string, string> dicEvents = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(Events.onError)) { dicEvents.Add("onError", Events.onError); } if (!string.IsNullOrEmpty(Events.onFullScreenChanged)) { dicEvents.Add("onFullScreenChanged", Events.onFullScreenChanged); } if (!string.IsNullOrEmpty(Events.onLoaded)) { dicEvents.Add("onLoaded", Events.onLoaded); } if (!string.IsNullOrEmpty(Events.onResized)) { dicEvents.Add("onResized", Events.onResized); } if (!string.IsNullOrEmpty(Events.onSourceDownloadComplete)) { dicEvents.Add("onSourceDownloadComplete", Events.onSourceDownloadComplete); } if (!string.IsNullOrEmpty(Events.onSourceDownloadProgressChanged)) { dicEvents.Add("onSourceDownloadProgressChanged", Events.onSourceDownloadProgressChanged); } aStmt.Add(CScript.GetScriptKeyValueByColon(dicEvents, true)); aStmt.Add("};"); aStmt.Add("var initParams = \"" + GetInitParams(InitParams) + "\";"); aStmt.Add("Silverlight.createObject(source, parentElement, id, properties, events, initParams, \"\");"); string Script = CScript.GetScript(aStmt, true); string s = "<div id=\"" + DivId + "\">" + Script + "</div>\r\n"; return(s); }
/// <summary> /// 서버의 DataTable을 클라이언트의 자바스크립트에서 쓸 수 있도록 변경함. /// </summary> /// <remarks>오라클의 경우는 필드 이름이 전부 대문자로 리턴되므로 소문자로 변경하려면 ColumnNameToLower 인수를 true로 할 것.</remarks> /// <returns></returns> public string ToClientScript() { List <string> aStmt = new List <string>(); if (_aDt.Count > 0) { if (!_Option.DontDeclareVariable) { if (_aDt.Count == 1) { aStmt.Add("var " + _Option.VariableName + " = new CDataTable();"); } else { aStmt.Add("var " + _Option.VariableName + " = [];"); } } for (int nTbl = 0; nTbl < _aDt.Count; nTbl++) { DataTable dt = _aDt[nTbl]; string VarNameCur = (_aDt.Count != 1) ? _Option.VariableName + "[" + nTbl + "]" : _Option.VariableName; aStmt = GetClientDataTableCommon(aStmt, dt, VarNameCur, _Option.ColumnNameToLower); } } if (_aDs.Count > 0) { /* * var ads = []; * * ads[0] = { Tables: [] }; * ads[0].Tables[0] = new CDataTable(); * ads[0].Tables[1] = new CDataTable(); * * ads[1] = { Tables: [] }; * ads[1].Tables[0] = new CDataTable(); * ads[1].Tables[1] = new CDataTable(); * * * var ds = { Tables: [] }; * ds.Tables[0] = new CDataTable(); * ds.Tables[1] = new CDataTable(); * */ if (!_Option.DontDeclareVariable) { if (_aDs.Count == 1) { aStmt.Add("var " + _Option.VariableName + " = { Tables: [] };"); } else { aStmt.Add("var " + _Option.VariableName + " = [];"); } } for (int nDs = 0; nDs < _aDs.Count; nDs++) { DataSet ds = _aDs[nDs]; if (_aDs.Count != 1) { aStmt.Add(_Option.VariableName + "[" + nDs + "] = { Tables: [] };"); } string VarNameCur = (_aDs.Count != 1) ? _Option.VariableName + "[" + nDs + "].Tables" : _Option.VariableName + ".Tables"; for (int nTbl = 0; nTbl < ds.Tables.Count; nTbl++) { DataTable dt = ds.Tables[nTbl]; string VarNameCur2 = VarNameCur + "[" + nTbl + "]"; aStmt = GetClientDataTableCommon(aStmt, dt, VarNameCur2, _Option.ColumnNameToLower); } } } string s = CScript.GetScript(aStmt, _Option.AddScriptTag); return(s); }
public static string GetScript(IEnumerable <string> aStmt) { return(CScript.GetScript(aStmt, false)); }
public static string GetScript(string Stmt, bool AddScriptTag) { return(CScript.GetScript(new string[] { Stmt }, AddScriptTag)); }