using System.Data; using System.Text; using System.Web; namespace Swift.web.Library { public static class Misc { #region Methods public static string GetMessageForNoRecords() { return "No records"; } public static string DataTableToHtmlTable(ref DataTable dt) { var str = new StringBuilder(""); str.Append(""); var cols = dt.Columns.Count; for (var i = 0; i < cols; i++) { str.Append(""); } str.Append(""); foreach (DataRow dr in dt.Rows) { str.Append(""); for (var i = 0; i < cols; i++) { str.Append(""); } str.Append(""); } str.Append("
" + dt.Columns[i].ColumnName + "
" + dr[i] + "
"); return str.ToString(); } public static void BeginForm(string formCaption) { var htmlCode = new StringBuilder(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine("
" + formCaption + "
"); HttpContext.Current.Response.Write(htmlCode.ToString()); htmlCode.Clear(); } public static void EndForm() { var htmlCode = new StringBuilder(""); htmlCode.AppendLine("
"); HttpContext.Current.Response.Write(htmlCode.ToString()); htmlCode.Clear(); } public static void CreateBredCrom(string headerCaption) { var htmlCode = new StringBuilder(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine("
" + headerCaption + "
"); htmlCode.AppendLine("
"); HttpContext.Current.Response.Write(htmlCode.ToString()); htmlCode.Clear(); } public static void BeginHeaderForGrid(string headerCaption, string childAlign) { var htmlCode = new StringBuilder(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine("
"); htmlCode.AppendLine("
" + headerCaption + "
"); htmlCode.AppendLine("
"); HttpContext.Current.Response.Write(htmlCode.ToString()); htmlCode.Clear(); } public static void BeginHeaderForGrid(string headerCaption) { BeginHeaderForGrid(headerCaption, "center"); } public static void EndHeaderForGrid() { var htmlCode = new StringBuilder(""); htmlCode.AppendLine("
"); HttpContext.Current.Response.Write(htmlCode.ToString()); htmlCode.Clear(); } #region TrackChanges public static void EnableTrackChanges(ref System.Web.UI.WebControls.TextBox tb, string hddField) { tb.Attributes.Add("onkeyup", "return TrackChanges('" + hddField + "');"); tb.Attributes.Add("onpaste", "return TrackChanges('" + hddField + "');"); } public static void EnableTrackChanges(ref System.Web.UI.WebControls.DropDownList ddl, string hddField) { ddl.Attributes.Add("onchange", "return TrackChanges('" + hddField + "');"); ddl.Attributes.Add("onclick", "return TrackChanges('" + hddField + "');"); } #endregion TrackChanges #region MakeNumericTextbox public static void MakeAmountTextBox(ref System.Web.UI.WebControls.TextBox tb) { tb.Attributes.Add("onblur", "UpdateComma(this);"); } public static void MakeDisabledTextbox(ref System.Web.UI.WebControls.TextBox tb) { tb.Enabled = false; //tb.BackColor = System.Drawing.Color.Gray; } public static void MakeNumericTextbox(ref System.Web.UI.WebControls.TextBox tb) { tb.Attributes.Add("onfocus", "resetInput(this, '0', 1, true);"); tb.Attributes.Add("onblur", "resetInput(this, '0', 2, true);"); tb.Attributes.Add("onkeydown", "return numericOnly(this, (event?event:evt), true);"); tb.Attributes.Add("onpaste", "return manageOnPaste(this);"); } public static void MakeNumericTextbox(ref System.Web.UI.WebControls.TextBox tb, bool allowBlank) { MakeNumericTextbox(ref tb, allowBlank, false); } public static void MakeNumericTextbox(ref System.Web.UI.WebControls.TextBox tb, bool allowBlank, bool donotSupportNegative) { tb.Attributes.Add("onfocus", "resetInput(this, '0', 1, true);"); tb.Attributes.Add("onblur", "resetInput(this, '0', 2, true, " + (allowBlank ? "true" : "false") + ");"); tb.Attributes.Add("onkeydown", "return numericOnly(this, (event?event:evt), true, " + (donotSupportNegative ? "true" : "false") + ");"); tb.Attributes.Add("onpaste", "return manageOnPaste(this);"); } public static void DisableInput(ref System.Web.UI.WebControls.TextBox tb) { tb.Attributes.Add("onkeydown", "return false;"); tb.Attributes.Add("onpaste", "return false;"); } public static string MakeNumericTextbox() { return MakeNumericTextbox(""); } public static string MakeNumericTextbox(string id) { return MakeNumericTextbox(id, id); } public static string MakeNumericTextbox(object value) { return MakeNumericTextbox("", value); } public static string MakeNumericTextbox(string id, string name) { return MakeNumericTextbox(id, name, ""); } public static string MakeNumericTextbox(string id, object value) { return MakeNumericTextbox(id, "", value); } public static string MakeNumericTextbox(string id, string name, object value) { return MakeNumericTextbox(id, name, value, "", ""); } public static string MakeNumericTextbox(string id, string name, object value, string attributes, string callBackFunction) { if (string.IsNullOrEmpty(name)) name = id; var html = new StringBuilder(""); html.Append(""); return html.ToString(); } public static void MakeIntegerTextbox(ref System.Web.UI.WebControls.TextBox tb, bool allowBlank, bool donotSupportNegative) { tb.Attributes.Add("onfocus", "resetInput(this, '0', 1, true);"); tb.Attributes.Add("onblur", "resetInput(this, '0', 2, true, " + (allowBlank ? "true" : "false") + ");"); tb.Attributes.Add("onkeydown", "return numericOnly(this, (event?event:evt), false, " + (donotSupportNegative ? "true" : "false") + ");"); tb.Attributes.Add("onpaste", "return false;"); } public static string MakeIntegerTextbox(string id, string name, object value, string attributes, string callBackFunction) { if (string.IsNullOrEmpty(name)) name = id; var html = new StringBuilder(""); html.Append(""); return html.ToString(); } public static string MakeFloatTextbox(string id, string name, object value, string attributes, string callBackFunction) { if (string.IsNullOrEmpty(name)) name = id; var html = new StringBuilder(""); html.Append(""); return html.ToString(); } #endregion MakeNumericTextbox #region SwiftCloseButton public static void SwiftCloseButton() { SwiftCloseButton((object)null); } public static void SwiftCloseButton(object id) { SwiftCloseButton(id, "Close"); } public static void SwiftCloseButton(string text) { SwiftCloseButton(null, text); } public static void SwiftCloseButton(object id, string text) { var html = ""; if (id != null) { html += ""; } else { html += ""; } HttpContext.Current.Response.Write(html); } #endregion SwiftCloseButton #region SwiftBackButton public static void SwiftBackButton() { SwiftBackButton((object)null); } public static void SwiftBackButton(object id) { SwiftBackButton(id, "Back"); } public static void SwiftBackButton(string text) { SwiftBackButton(null, text); } public static void SwiftBackButton(object id, string text) { var html = ""; if (id != null) { html += ""; } else { html += ""; } HttpContext.Current.Response.Write(html); } #endregion SwiftBackButton #endregion Methods public static string GetIcon(string iconType) { switch (iconType.ToLower()) { case "edit": return "\"Edit\""; case "ba": return "\"Edit\""; case "delete": return "\"Delete\""; case "add": return "\"Add\""; case "wait": return "\"Waiting"; case "viewchanges": return "\"View"; case "vd": return "\"View"; case "file-format": return "\"File"; case "info": return "\"More"; default: return iconType; } } public static void DisableInput(ref System.Web.UI.WebControls.TextBox tb, string defVal) { tb.Attributes.Add("onkeydown", "return DisableInput(this, (event?event:evt));"); if (defVal != null) { tb.Attributes.Add("value", defVal); } tb.Attributes.Add("onpaste", "return false;"); } public static string GetIcon(string iconType, string onClickFunction) { var html = new StringBuilder(""); html.Append(GetIcon(iconType)); html.Append(""); return html.ToString(); } public static string JQueryCalUtil() { return @" "; } } }