using Common.Helper; using Repository.DAO; using Repository.DAO.SwiftDao; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web; using System.Web.UI.WebControls; namespace JMEAgentSystem.Library { public class SwiftLibrary : SwiftDao { public string CreateDynamicDropDownBox(string name, string sql, string valueField, string textField, string defaultValue) { var html = new StringBuilder(""); var width = ""; var dt = ExecuteDataSet(sql).Tables[0]; html.Append(""); return html.ToString(); } public void SetDefaultDdl(ref DropDownList ddl, string label, bool isClearItem) { if (isClearItem) ddl.Items.Clear(); var item = new ListItem(label, ""); ddl.Items.Add(item); } public void SetDDL(ref DropDownList ddl, string sql, string valueField, string textField, string valueToBeSelected, string label) { var ds = ExecuteDataSet(sql); ListItem item = null; if (ds.Tables.Count == 0) { if (label != "") { item = new ListItem(label, ""); ddl.Items.Add(item); } return; } var dt = ds.Tables[0]; ddl.Items.Clear(); if (label != "") { item = new ListItem(label, ""); ddl.Items.Add(item); } foreach (DataRow row in dt.Rows) { item = new ListItem(); item.Value = row[valueField].ToString(); item.Text = row[textField].ToString(); if (row[valueField].ToString().ToUpper() == valueToBeSelected.ToUpper()) item.Selected = true; ddl.Items.Add(item); } } public void SetDDL2(ref DropDownList ddl, string sql, string textField, string valueToBeSelected, string label) { var dt = ExecuteDataSet(sql).Tables[0]; ListItem item = null; ddl.Items.Clear(); if (label != "") { item = new ListItem(label, ""); ddl.Items.Add(item); } foreach (DataRow row in dt.Rows) { item = new ListItem(); item.Value = row[textField].ToString(); item.Text = row[textField].ToString(); if (row[textField].ToString().ToUpper() == valueToBeSelected.ToUpper()) item.Selected = true; ddl.Items.Add(item); } } public void SetDDLFromDT(ref DropDownList ddl, DataTable dataTable, string valueField, string textField, string valueToBeSelected, string label) { ListItem item = null; if (dataTable == null) return; if (dataTable.Rows.Count == 0) { if (label != "") { item = new ListItem(label, ""); ddl.Items.Add(item); } return; } var dt = dataTable; ddl.Items.Clear(); if (label != "") { item = new ListItem(label, ""); ddl.Items.Add(item); } foreach (DataRow row in dt.Rows) { item = new ListItem(); item.Value = row[valueField].ToString(); item.Text = row[textField].ToString(); if (row[valueField].ToString().ToUpper() == valueToBeSelected.ToUpper()) item.Selected = true; ddl.Items.Add(item); } } public void SetDDL3(ref DropDownList ddl, string sql, string valueField, string textField, string valueToBeSelected, string label) { var dt = ExecuteDataSet(sql).Tables[0]; ListItem item = null; ddl.Items.Clear(); if (label != "") { item = new ListItem(label, ""); ddl.Items.Add(item); } foreach (DataRow row in dt.Rows) { item = new ListItem(); item.Value = row[valueField].ToString(); item.Text = row[textField].ToString(); if (row[textField].ToString().ToUpper() == valueToBeSelected.ToUpper()) item.Selected = true; ddl.Items.Add(item); } } public void BeginForm(string formCaption) { var htmlCode = new StringBuilder(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); htmlCode.AppendLine(""); 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 void EndForm() { var htmlCode = new StringBuilder(""); htmlCode.AppendLine("
"); HttpContext.Current.Response.Write(htmlCode.ToString()); htmlCode.Clear(); } public 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 void BeginHeaderForGrid(string headerCaption) { BeginHeaderForGrid(headerCaption, "center"); } public void EndHeaderForGrid() { var htmlCode = new StringBuilder(""); htmlCode.AppendLine("
"); HttpContext.Current.Response.Write(htmlCode.ToString()); htmlCode.Clear(); } public void SetYearDdl(ref DropDownList ddl, int low, int high, string label) { ListItem item = null; if (!string.IsNullOrWhiteSpace(label)) { item = new ListItem { Value = "", Text = label }; ddl.Items.Add(item); } for (int i = low; i <= high; i++) { item = new ListItem { Value = i.ToString(), Text = i.ToString() }; ddl.Items.Add(item); } } public void SetMonthDdl(ref DropDownList ddl, string label) { ListItem item = null; if (!string.IsNullOrWhiteSpace(label)) { item = new ListItem { Value = "", Text = label }; ddl.Items.Add(item); } DateTime mnth = Convert.ToDateTime("1/1/2000"); for (int i = 0; i < 12; i++) { DateTime nextMnth = mnth.AddMonths(i); item = new ListItem { Text = nextMnth.ToString("MMMM"), Value = nextMnth.ToString("MM") }; ddl.Items.Add(item); } } public void SetDay(ref DropDownList ddl, string label) { ListItem item = null; if (!string.IsNullOrWhiteSpace(label)) { item = new ListItem { Value = "", Text = label }; ddl.Items.Add(item); } for (int i = 1; i <= 31; i++) { item = new ListItem { Text = i.ToString(), Value = i.ToString() }; ddl.Items.Add(item); } } #region Grid public string CreateGrid(string gridName, string gridWidth, string sql, string rowIdField, bool showCheckBox, bool multiSelect, string columns, string cssClass, string callBackFunction)//, string editPage, bool allowEdit, bool allowDelete, bool allowApprove, string customLink, string customVariableList) { if (string.IsNullOrEmpty(cssClass)) cssClass = "TBLReport"; var html = new StringBuilder(); var dt = ExecuteDataSet(sql).Tables[0]; var columnList = columns.Split(','); html.AppendLine( ""); if (showCheckBox) { var headerFuntion = "SelectAll(this, '" + gridName + "'," + (multiSelect ? "true" : "false") + ");" + callBackFunction; html.AppendLine(""); } var columnIndexArray = new ArrayList(); foreach (var str in columnList) { columnIndexArray.Add(str); } var columnArray = new ArrayList(); foreach (DataColumn col in dt.Columns) { columnArray.Add(col); } for (var i = 0; i < columnArray.Count; i++) { if (columns.Trim().Equals("")) { html.AppendLine(""); } else { if (columnIndexArray.Contains(i.ToString())) { html.AppendLine(""); } } } html.AppendLine(""); var checkBoxFunction = ""; if (showCheckBox) { checkBoxFunction = "ManageSelection(this, '" + gridName + "'," + (multiSelect ? "true" : "false") + ");" + callBackFunction; } foreach (DataRow row in dt.Rows) { html.AppendLine(""); if (showCheckBox) { html.AppendLine(""); } for (var i = 0; i < dt.Columns.Count; i++) { var data = row[i].ToString(); if (columns.Trim().Equals("")) { html.AppendLine(""); } else { if (columnIndexArray.Contains(i.ToString())) { html.AppendLine(""); } } } html.AppendLine(""); } html.AppendLine("
" + (multiSelect ? "√" : "×") + "" + columnArray[i] + "" + columnArray[i] + "
" + GetStatic.FormatData(data, "") + "" + GetStatic.FormatData(data, "") + "
"); return html.ToString(); } #endregion } }