using Swift.DAL.Remittance; using Swift.DAL.SwiftDAL; using Swift.web.Component.Grid.gridHelper; using Swift.web.Library; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; namespace Swift.web.Component.Grid { public class SwiftGrid : GridDao { private ArrayList CheckBoxIds; private bool IdsAreParsed = false; public enum GridDS { AccountDB = 0, RemittanceDB = 1, }; #region Properties public bool EncodeJSInData = false; ////private string _extraConn=""; ////public string ExtraConn ////{ //// set { _extraConn = value; } //// get { return _extraConn; } ////} public string AddButtonCallBack { get; set; } public bool EnableProcessBar = false; private bool _hasFilter; private int _gridWidth = 700; public int GridWidth { set { _gridWidth = value; } get { return _gridWidth; } } private bool _isGridWidthInPercent; public bool IsGridWidthInPercent { set { _isGridWidthInPercent = value; } get { return _isGridWidthInPercent; } } private int _gridHeight = -1; public int GridHeight { set { _gridHeight = value; } get { return _gridHeight; } } private int _gridMinWidth = 700; public int GridMinWidth { set { _gridMinWidth = value; } get { return _gridMinWidth; } } private string _gridName = ""; public string GridName { set { _gridName = value; } get { return _gridName; } } private Boolean _showFilterForm; public Boolean ShowFilterForm { set { _showFilterForm = value; } get { return _showFilterForm; } } private Boolean _alwaysShowFilterForm = true; public Boolean AlwaysShowFilterForm { set { _alwaysShowFilterForm = value; } get { return _alwaysShowFilterForm; } } private Boolean _showPagingBar; public Boolean ShowPagingBar { set { _showPagingBar = value; } get { return _showPagingBar; } } private Boolean _showAddButton; public Boolean ShowAddButton { set { _showAddButton = value; } get { return _showAddButton; } } private Boolean _showPopUpWindowOnAddButtonClick; public Boolean ShowPopUpWindowOnAddButtonClick { set { _showPopUpWindowOnAddButtonClick = value; } get { return _showPopUpWindowOnAddButtonClick; } } private string _addButtonTitleText; public string AddButtonTitleText { set { _addButtonTitleText = value; } get { return _addButtonTitleText; } } private string _addPage; public string AddPage { set { _addPage = value; } get { return _addPage; } } private string _thisPage; public string ThisPage { set { _thisPage = value; } get { return _thisPage; } } private string _rootDir = ""; public string RootDir { set { _rootDir = value; } get { return _rootDir; } } private string _callBackFunction = ""; public string CallBackFunction { set { _callBackFunction = value; } get { return _callBackFunction; } } private Boolean _downlodable = true; public Boolean Downloadable { get { return _downlodable; } set { _downlodable = value; } } private Boolean _enablePdfDownload = true; public Boolean EnablePdfDownload { get { return _enablePdfDownload; } set { _enablePdfDownload = value; } } private Boolean _landscapeMode = true; public Boolean LandscapeMode { get { return _landscapeMode; } set { _landscapeMode = value; } } private int _pageSize; public int PageSize { get { return _pageSize; } set { _pageSize = value; } } private string[] _rowColoredByColValue1; public string[] RowColoredByColValue1 { get { return _rowColoredByColValue1; } set { _rowColoredByColValue1 = value; } } private string _rowColoredByColValue; public string RowColoredByColValue { get { return _rowColoredByColValue; } set { _rowColoredByColValue = value; } } private int _pageNumber; public int PageNumber { get { return _pageNumber; } set { _pageNumber = value; } } private string _sortOrder; public string SortOrder { get { return _sortOrder == "" ? "ASC" : _sortOrder; } set { _sortOrder = value; } } private string _sortBy = ""; public string SortBy { get { return _sortBy == "" ? RowIdField : _sortBy; } set { _sortBy = value; } } public bool LoadGridOnFilterOnly { get; set; } private bool _enableCookie = true; public bool EnableCookie { set { _enableCookie = value; } get { return _enableCookie; } } private bool _enableFilterCookie = true; public bool EnableFilterCookie { set { _enableFilterCookie = value; } get { return _enableFilterCookie; } } private string _uploadPage = ""; public string UploadPage { set { _uploadPage = value; } get { return _uploadPage; } } private string _comma = ""; public void SetComma() { _comma = ","; } private string _rowIdField; public string RowIdField { set { _rowIdField = value; } get { return _rowIdField ?? ""; } } private Boolean _showFilterLabel; public Boolean ShowFilterLabel { set { _showFilterLabel = true; } get { return _showFilterLabel; } } private string _showFilterLabelText; public string ShowFilterLabelText { set { _showFilterLabelText = value; } get { return _showFilterLabelText; } } private bool _enableToolTip; public bool EnableToolTip { set { _enableToolTip = value; } get { return _enableToolTip; } } private string _toolTipField; public string ToolTipField { set { _toolTipField = value; } get { return _toolTipField ?? ""; } } private string _fileType; public string FileType { set { _fileType = value; } get { return _fileType ?? ""; } } private string _fileDescription; public string FileDescription { set { _fileDescription = value; } get { return _fileDescription ?? ""; } } private Boolean _multiSelect; public Boolean MultiSelect { set { _multiSelect = value; } get { return _multiSelect; } } private Boolean _disableAuditWindow = false; public Boolean DisableAuditWindow { set { _disableAuditWindow = value; } get { return _disableAuditWindow; } } private Boolean _allowApprove; public Boolean AllowApprove { set { _allowApprove = value; } get { return _allowApprove; } } //private string _approveText = "\"View "; private string _approveText = " "; public string ApproveText { set { _approveText = value; } get { return _approveText; } } private string _viewFunctionId = ""; public string ViewFunctionId { set { _viewFunctionId = value; } get { return _viewFunctionId; } } private string _approveFunctionId = ""; public string ApproveFunctionId { set { _approveFunctionId = value; } get { return _approveFunctionId; } } private string _approveFunctionId2 = ""; public string ApproveFunctionId2 { set { _approveFunctionId2 = value; } get { return _approveFunctionId2; } } private string _popUpParam = "dialogHeight:800px;dialogWidth:1000px;dialogLeft:300;dialogTop:100;center:yes"; public string PopUpParam { set { _popUpParam = value; } get { return _popUpParam; } } //PopUp private Boolean _allowEdit; public Boolean AllowEdit { set { _allowEdit = value; } get { return _allowEdit; } } //private string _editText = ""; private string _editText = " "; public string EditText { set { _editText = value; } get { return _editText; } } private Boolean _allowDelete; public Boolean AllowDelete { set { _allowDelete = value; } get { return _allowDelete; } } //private string _deleteText = ""; private string _deleteText = " "; public string DeleteText { set { _deleteText = value; } get { return _deleteText; } } private string _deleteTitle = "Delete"; public string DeleteTitle { set { _deleteTitle = value; } get { return _deleteTitle; } } private string _deleteAlertText = "Are you sure to delete selected record?"; public string DeleteAlertText { set { _deleteAlertText = value; } get { return _deleteAlertText; } } private Boolean _allowReject; public Boolean AllowReject { set { _allowReject = value; } get { return _allowReject; } } private string _rejectText = " "; public string RejectText { set { _rejectText = value; } get { return _rejectText; } } private string _rejectTitle = "Reject"; public string RejectTitle { set { _rejectTitle = value; } get { return _rejectTitle; } } private string _rejectAlertText = "Are you sure you want to reject the selected customer?"; public string RejectAlertText { set { _rejectAlertText = value; } get { return _rejectAlertText; } } private Boolean _allowCustomLink; public Boolean AllowCustomLink { set { _allowCustomLink = value; } get { return _allowCustomLink; } } private string _customLinkText = ""; public string CustomLinkText { set { _customLinkText = value; } get { return _customLinkText; } } private string _customLinkColumnHeader; public string CustomLinkColumnHeader { set { _customLinkColumnHeader = value; } get { return _customLinkColumnHeader; } } private Boolean _allowCustomLink1; public Boolean AllowCustomLink1 { set { _allowCustomLink1 = value; } get { return _allowCustomLink1; } } private string _customLinkText1 = ""; public string CustomLinkText1 { set { _customLinkText1 = value; } get { return _customLinkText1; } } private string _customLinkVariables = ""; public string CustomLinkVariables { set { _customLinkVariables = value; } get { return _customLinkVariables; } } private Boolean _showCheckBox; public Boolean ShowCheckBox { set { _showCheckBox = value; } get { return _showCheckBox; } } private int _inputPerRow = 1; public int InputPerRow { set { _inputPerRow = value; } get { return _inputPerRow; } } private bool _inputLabelOnLeftSide; public bool InputLabelOnLeftSide { set { _inputLabelOnLeftSide = value; } get { return _inputLabelOnLeftSide; } } //Added By Bijay private bool _allowFileView; public bool AllowFileView { set { _allowFileView = value; } get { return _allowFileView; } } private bool _allowGridFieldEdit; public bool AllowGridFieldEdit { set { _allowGridFieldEdit = value; } get { return _allowGridFieldEdit; } } private int _gridType = 2; public int GridType { set { _gridType = value; } get { return _gridType; } } private List _columnList; public List ColumnList { set { _columnList = value; } get { return _columnList; } } private List _filterList; public List FilterList { set { _filterList = value; } get { return _filterList; } } private bool _verifyMode; public Boolean VerifyMode { set { _verifyMode = value; } get { return _verifyMode; } } private int _fixePageSizeTo; public int FixePageSizeTo { set { _fixePageSizeTo = value; } get { return _fixePageSizeTo; } } private bool _disableSorting; public Boolean DisableSorting { set { _disableSorting = value; } get { return _disableSorting; } } private bool _disableJsFilter; public Boolean DisableJsFilter { set { _disableJsFilter = value; } get { return _disableJsFilter; } } private string _totalFields = ""; public string TotalFields { get { return _totalFields; } set { _totalFields = value; } } private int _totalFieldCol; public int TotalFieldCol { get { return _totalFieldCol; } set { _totalFieldCol = value; } } private string _editCallBackFunction; public string EditCallBackFunction { set { _editCallBackFunction = value; } get { return _editCallBackFunction; } } private string _selectionCheckBoxList = ""; public string SelectionCheckBoxList { set { _selectionCheckBoxList = value; } get { return _selectionCheckBoxList; } } public bool AllowRowDisable { get; set; } public String DisabledRowValueSourceField { get; set; } private Boolean _downlodExcel = false; [DefaultValue(false)] public Boolean DownloadAll { get { return _downlodExcel; } set { _downlodExcel = value; } } #endregion Properties #region Public Methods public GridDS GridDataSource { get; set; } public SwiftGrid() { LoadGridOnFilterOnly = false; PageSize = 10; PageNumber = 1; SortOrder = ""; } public string CreateGrid(string sql) { if (GetStatic.GetUser() == "") HttpContext.Current.Response.Redirect(GetStatic.GetLogoutPage()); LoadVariables(); var executeSql = ""; var fileterSql = GetFilterSql(); switch (GridType) { case 1: { //Based On SP executeSql = sql + fileterSql; } break; case 2: { //Based On Sql Statement var sqlHeader = "SELECT COUNT_BIG(*) totalRow FROM (" + sql + ") x WHERE 1 = 1 " + fileterSql; var sqlBody = "SELECT x.* FROM (SELECT x.*, ROW_NUMBER() OVER(ORDER BY " + SortBy + " " + SortOrder + ") rowNumberId FROM (" + sql + ") x WHERE 1 = 1 " + fileterSql + ") x"; sqlBody = sqlBody + " WHERE rowNumberId BETWEEN " + ((PageNumber - 1) * PageSize + 1) + " AND " + (PageNumber * PageSize); executeSql = sqlHeader + ";" + sqlBody; } break; } ArrayList gridSource; if (GridDS.RemittanceDB == GridDataSource) { var RemitGridDao = new RemittanceGridDao(); gridSource = RemitGridDao.GetGridDataSource(executeSql, _hasFilter, LoadGridOnFilterOnly); } else { gridSource = GetGridDataSource(executeSql, _hasFilter, LoadGridOnFilterOnly); } //gridSource = GetGridDataSource(executeSql, _hasFilter, LoadGridOnFilterOnly); HttpContext.Current.Session["exportSource"] = executeSql; HttpContext.Current.Session["grid_column"] = ColumnList; var totalRecord = Convert.ToInt32(gridSource[0].ToString()); var totalPage = totalRecord / PageSize; if ((totalPage * PageSize) < totalRecord) totalPage++; //var sortFunctionTmp = "SortGrid('" + GridName + "', '{sort_by}', '{sort_order}')"; var sortFunctionTmp = "SortGrid('" + GridName + "', '{sort_by}', '{sort_order}'" + ShowProcessBar() + ")"; string sortFunction; double total = 0.0; var html = new StringBuilder(""); if (GridHeight > -1) { html.AppendLine("
"); } var minWidth = "style=\"min-width: " + GridMinWidth + "px;\""; html.AppendLine("
"); html.AppendLine(""); html.AppendLine(""); var cssClass = ""; if (AllowCustomLink1) { html.AppendLine(""); } if (ShowCheckBox) { var headerFuntion = "SelectAll(this, '" + GridName + "'," + (MultiSelect ? "true" : "false") + ");" + CallBackFunction; html.AppendLine(""); } var colIndex = -1; foreach (var column in ColumnList) { var width = ""; cssClass = "hdtitle"; if ((column.Width) != "") width = "style= \"min-width : " + (column.Width) + "px;\""; if (column.Type.ToLower() == "nosort") { html.AppendLine(""); } else { var sortIcon = ""; var sortText = "" + column.Description + ""; var filterText = ""; if (!DisableSorting) { if (column.Key.ToLower() == SortBy.ToLower()) { sortFunction = sortFunctionTmp.Replace("{sort_order}", ReverseSortOrder(SortOrder)); sortIcon = " "; cssClass = "sortAsc"; } else { sortFunction = sortFunctionTmp.Replace("{sort_order}", "asc"); cssClass = ""; } sortFunction = sortFunction.Replace("{sort_by}", column.Key); sortText = "" + column.Description + " " + sortIcon + ""; } if (!DisableJsFilter) { var filterFunction = "ShowFilter(this, '" + GridName + "', " + (++colIndex + (ShowCheckBox ? 1 : 0)) + ");"; if (DisableSorting) { sortText = "" + column.Description + ""; filterText = ""; } else { filterText = DisableSorting ? "" : "
" + " "; } } html.AppendLine(""); } } if (AllowEdit || AllowDelete || AllowCustomLink || AllowApprove || AllowFileView || AllowReject) { html.AppendLine(""); } html.AppendLine(""); var cnt = 0; var checkBoxFunction = ""; if (ShowCheckBox) { checkBoxFunction = "ManageSelection(this, '" + GridName + "'," + (MultiSelect ? "true" : "false") + ");" + CallBackFunction; } if (LoadGridOnFilterOnly && !_hasFilter) { } else { foreach (var row in (List)gridSource[1]) { var editDeleteId = row[RowIdField.ToLower()].ToString(); if (EnableToolTip) { var toolTipMsg = row[ToolTipField].ToString(); html.AppendLine(++cnt % 2 == 1 ? "" : ""); } else { if (null != _rowColoredByColValue1 && _rowColoredByColValue1.Length > 0) { string[] colNval; string col = ""; string val = ""; string colorValue = ""; for (int i = 0; i < _rowColoredByColValue1.Length; i++) { colNval = _rowColoredByColValue1[i].Split(':'); col = row[colNval[0].ToLower().Trim()].ToString(); val = colNval[1].Trim(); colorValue = colNval[2]; if (col.ToLower() == val.ToLower()) break; } if (col.ToLower() == val.ToLower()) { html.AppendLine(""); } else { html.AppendLine(++cnt % 2 == 1 ? "" : ""); } } else if (!string.IsNullOrWhiteSpace(_rowColoredByColValue)) { string[] colNval = _rowColoredByColValue.Split(':'); string col = row[colNval[0].ToLower().Trim()].ToString(); string val = colNval[1].Trim(); if (col.ToLower() == val.ToLower()) { html.AppendLine(""); } else { html.AppendLine(++cnt % 2 == 1 ? "" : ""); } } else { html.AppendLine(++cnt % 2 == 1 ? "" : ""); } } if (AllowCustomLink1) { var customLinkVariableList = CustomLinkVariables.Split(','); var parsedCustomLinkText = CustomLinkText1; foreach (var variable in customLinkVariableList) { parsedCustomLinkText = parsedCustomLinkText.Replace("@" + variable, row[variable.ToLower().Trim()].ToString()); } html.AppendLine(""); } var disabled = ""; if (AllowRowDisable) { if (!string.IsNullOrWhiteSpace(DisabledRowValueSourceField)) { if (row[DisabledRowValueSourceField.ToLower()].ToString() == "1") { disabled = "disabled"; } } } if (ShowCheckBox) { if (AllowRowDisable) { if (row[DisabledRowValueSourceField.ToLower()].ToString() == "1") { disabled = "disabled"; } } if (disabled == "") { html.AppendLine(""); } else { html.AppendLine(""); } } if (!string.IsNullOrEmpty(TotalFields)) { total += Convert.ToDouble(row[TotalFields.ToLower()]); } foreach (var column in ColumnList) { var data = row[column.Key.ToLower()].ToString(); if (EncodeJSInData) { data = HttpUtility.JavaScriptStringEncode(data); } switch (column.Type.ToUpper()) { case "R": html.AppendLine(""); break; case "EXI": // FOR EXCHANGE SYSTEM IMAGE ONLY ADDED BY PRALHAD html.AppendLine(""); break; case "M": html.AppendLine( ""); break; case "D": html.AppendLine(""); break; case "DT": html.AppendLine(""); break; case "NOSORT": html.AppendLine(""); break; default: html.AppendLine(""); break; } } if (AllowEdit || AllowDelete || AllowCustomLink || AllowApprove || AllowFileView || AllowReject) { html.AppendLine(""); } html.AppendLine(""); } } if (!string.IsNullOrEmpty(_totalFields)) { html.AppendLine(""); html.AppendLine(""); html.AppendLine(""); html.Append(""); } html.AppendLine("
" + (MultiSelect ? "√" : "×") + "" + column.Description + "" + sortText + filterText + "" + (string.IsNullOrEmpty(CustomLinkColumnHeader) ? " " : CustomLinkColumnHeader) + "
" + parsedCustomLinkText + " " + FormatData(data, "") + "    " + FormatData(data, "") + "" + FormatData(data, "M") + "" + FormatData(data, "D") + "" + FormatData(data, "DT") + "" + FormatData(data, "") + "" + FormatData(data, "") + ""); if (AllowEdit) { if (disabled == "") { var customLinkVariableList = CustomLinkVariables.Split(','); var customVar = AddPage; if (customLinkVariableList[0] != "") { customVar = customLinkVariableList.Aggregate(customVar, (current, variable) => current.Replace("@" + variable, row[variable.ToLower().Trim()].ToString())); } var editLink = (customLinkVariableList[0] != "" ? customVar : AddPage) + (AddPage.IndexOf('?') > -1 ? "&" : "?") + RowIdField + "=" + editDeleteId + (VerifyMode ? "&mode=verify" : ""); if (ShowPopUpWindowOnAddButtonClick) { html.AppendLine("" + EditText + ""); } else { if (string.IsNullOrEmpty(EditCallBackFunction)) { html.AppendLine("" + EditText + ""); } else { html.AppendLine("" + EditText + ""); } } } } if (AllowDelete) { if (disabled == "") { var deleteLink = "onclick = \"DeleteRow('" + editDeleteId + "','" + GridName + "', '" + DeleteAlertText + "'" + ShowProcessBar() + ");"; //DeleteText = "\"Delete\""; html.AppendLine(" " + DeleteText + ""); } else { html.AppendLine(" "); } } if (AllowReject) { if (disabled == "") { var rejectLink = "onclick = \"DeleteRow('" + editDeleteId + "','" + GridName + "', '" + RejectAlertText + "'" + ShowProcessBar() + ");"; html.AppendLine(" " + RejectText + ""); } else { html.AppendLine(" "); } } if (AllowCustomLink) { var customLinkVariableList = CustomLinkVariables.Split(','); var parsedCustomLinkText = CustomLinkText; foreach (var variable in customLinkVariableList) { parsedCustomLinkText = parsedCustomLinkText.Replace("@" + variable, row[variable.ToLower().Trim()]. ToString()); } html.AppendLine(" " + parsedCustomLinkText); } if (AllowApprove) { if (row["haschanged"].ToString().ToUpper().Equals("Y")) { if (row["modifiedby"].ToString() == GetStatic.GetUser()) { var approveLink = "id=" + editDeleteId + "&functionId=" + (ApproveFunctionId2 == "" ? ApproveFunctionId : ApproveFunctionId2) + "&functionId2=" + ApproveFunctionId + "&modBy=" + row["modifiedby"]; var approvePage = GetStatic.GetUrlRoot() + "/ViewChanges.aspx?" + approveLink; var jsText = DisableAuditWindow ? "" : "onclick = \"PopUp('" + GridName + "','" + approvePage + "','" + PopUpParam + "');\""; html.AppendLine(" \"Waiting"); } else { var approveLink = "id=" + editDeleteId + "&functionId=" + (ApproveFunctionId2 == "" ? ApproveFunctionId : ApproveFunctionId2) + "&functionId2=" + ApproveFunctionId; var approvePage = GetStatic.GetUrlRoot() + "/ViewChanges.aspx?" + approveLink; var jsText = DisableAuditWindow ? "" : "onclick = \"PopUp('" + GridName + "','" + approvePage + "','" + PopUpParam + "');"; ApproveText = "\"Waiting"; html.AppendLine(" " + ApproveText + ""); } } } if (AllowFileView) { //var fn = row["filename"].ToString(); //var fileViewLink = " View "; //html.AppendLine(" " + fileViewLink); var fileLink = "id=" + editDeleteId + "&functionId=" + ViewFunctionId; var filePage = GetStatic.GetUrlRoot() + "/ShowFile.aspx?" + fileLink; var jsText = "onclick = \"PopUp('" + GridName + "','" + filePage + "','" + PopUpParam + "');\""; html.AppendLine(" View"); } html.AppendLine("
Total Amount" + GetStatic.ShowDecimal(total.ToString()) + "
"); html.AppendLine("
"); if (ShowPagingBar) { html.AppendLine(""); html.AppendLine(""); html.AppendLine(""); html.AppendLine("
Page " + PageNumber + " of " + totalPage + "
"); } html.AppendLine(""); if (GridHeight > -1) { html.AppendLine(""); } var filterFormHtml = ShowFilterForm ? MakeFilterForm() : ""; var pagingBarHtml = ShowPagingBar ? GetPagingBlock(totalRecord, totalPage) : ""; var completeScript = ""; if (EnableProcessBar) { var id = GridName + "_submitButton"; completeScript = @""; } return "
" + filterFormHtml + "
" + pagingBarHtml + "
" + html + "
" + CreateDefaultControl() + "
" + completeScript; } public string GetCurrentRowId(string gridName) { return GetStatic.ReadFormData(gridName + "_currentRowId", ""); } public string GetRowId(string gridName) { return GetStatic.ReadFormData(gridName + "_rowId", ""); } public string GetRowId() { return GetRowId(GridName); } public static string FormatData(string data, string dataType) { return GetStatic.FormatData(data, dataType); } public string GetGridInputValue(string key, string defaultValue) { return ReadData(key, defaultValue, true); } public string GetGridInputName(string inputName) { return GridName + "_" + inputName; } #endregion Public Methods #region Private Methods private string ShowProcessBar() { return (EnableProcessBar ? ",true" : ",false"); } private string GetPagingBlock(int totalRecord, int totalPage) { string[] pageSizeList = { "10", "20", "30", "40", "50", "100" }; var html = new StringBuilder(""); html.AppendLine("
"); html.AppendLine("
"); html.AppendLine("
"); html.AppendLine("
"); html.AppendLine("
"); html.AppendLine("Result :   records "); html.AppendLine("    per page"); html.AppendLine("  "); html.AppendLine("
"); html.AppendLine("
"); html.AppendLine("
"); if (PageNumber > 1) html.AppendLine("   "); else //html.AppendLine("   "); html.AppendLine(""); if (PageNumber * PageSize < totalRecord) html.AppendLine("   "); else //html.AppendLine("   "); html.AppendLine(" "); if (ShowAddButton) { if (ShowPopUpWindowOnAddButtonClick) { html.AppendLine(""); } else if (!string.IsNullOrEmpty(AddButtonCallBack)) { html.AppendLine(""); } else { html.AppendLine(""); } } if (_uploadPage != "") html.AppendLine("  "); if (Downloadable) { if (GridDS.RemittanceDB == GridDataSource) { html.AppendLine("     "); } else html.AppendLine("     "); } if (DownloadAll) { if (GridDS.RemittanceDB == GridDataSource) { html.AppendLine("     "); } else html.AppendLine("     "); } if (EnablePdfDownload) { var lm = LandscapeMode ? "1" : "0"; html.AppendLine("   "); } html.AppendLine("
"); html.AppendLine("
"); return html.ToString(); } private string MakeFilterForm() { var html = new StringBuilder("
"); if (!AlwaysShowFilterForm) { html.AppendLine(""); html.AppendLine("
"); //html.AppendLine(""); //html.AppendLine( // ""); } else { html.AppendLine(ShowFilterLabel == true ? "

" + ShowFilterLabelText + "

" : ""); html.AppendLine("
Filtered results   \"Show\" "); //html.AppendLine(""); //html.AppendLine("
"); } //else //{ // html.AppendLine(""); // html.AppendLine( // ""); //} //html.AppendLine(""); //html.AppendLine("
Filtered results"); // html.AppendLine(""); // html.AppendLine("
"); var user = GetStatic.GetUser(); var cnt = 0; foreach (var filter in FilterList) { cnt++; var childControl = ""; var readOnly = ""; var jsFunction = ""; if (cnt == 1) html.AppendLine(""); //html.AppendLine(""); //} //html.AppendLine(""); } else { var swiftLibrary = new SwiftLibrary(); html.AppendLine(swiftLibrary.CreateDynamicDropDownBox(ctlName, sp, "value", "text", defaultValue) + ""); } } break; case "2": html.Append(""); break; case "z": //if (defaultValue == "") // defaultValue = DateTime.Now.ToString("MM/dd/yyyy"); html.AppendLine("
"); html.AppendLine("" + childControl + "
"); break; case "i": html.AppendLine(Misc.MakeIntegerTextbox(ctlName, ctlName, defaultValue, "class=\"form-control\" style=\"width: 100%;\"", "") + ""); break; case "m": html.AppendLine(Misc.MakeFloatTextbox(ctlName, ctlName, defaultValue, "class=\"form-control\" style=\"width: 100%;\"", "") + ""); break; case "a": if (!string.IsNullOrWhiteSpace(filter.Category)) { html.AppendLine(MakeAutoCompleteControl(filter) + ""); } else { html.AppendLine("" + childControl + ""); } break; default: html.AppendLine("
"); html.AppendLine("" + childControl + "
"); break; } if (cnt % InputPerRow == 0) { html.AppendLine(""); cnt = 0; } } if (cnt != 0) { html.AppendLine(""); } html.AppendLine(""); if (InputLabelOnLeftSide) html.AppendLine(""); html.AppendLine("
" + filter.Description); html.AppendLine(""); html.AppendLine("
"); //if (InputLabelOnLeftSide) //{ // html.AppendLine("
"); // html.AppendLine("
"); var ctlName = GridName + "_" + filter.Key; var defaultValue = ""; var filterControlType = filter.Type.Substring(0, 1).ToLower(); // html.AppendLine("
"); if (!filterControlType.Equals("a") || string.IsNullOrWhiteSpace(filter.Category)) { if (EnableFilterCookie) { defaultValue = GetStatic.ReadCookie(ctlName + "_c_" + user, ""); defaultValue = GetStatic.ReadFormData(ctlName, defaultValue); defaultValue = defaultValue.Replace("'", "").Replace("'", ""); defaultValue = FilterStringGrid(defaultValue); defaultValue = defaultValue == "null" ? "" : defaultValue; GetStatic.WriteCookie(ctlName + "_c_" + user, defaultValue); } else { defaultValue = GetStatic.ReadFormData(ctlName, defaultValue); } } if (filterControlType == "d" || filterControlType == "z") { //jsFunction = "onchange=\"return DateValidation(" + "'" + GridName + "_fromDate','t','" + GridName + "_toDate'" + ")\" maxlength=\"10\""; //filter.DefaultValue = null; //readOnly = " readOnly = \"readOnly\""; html.Append(@""); } //html.AppendLine(InputLabelOnLeftSide ? "
":""); if (string.IsNullOrEmpty(defaultValue)) { defaultValue = filter.DefaultValue; } switch (filterControlType) { case "1": { var sp = filter.Type.Substring(2); if (GridDS.RemittanceDB == GridDataSource) { var remittanceLibrary = new RemittanceLibrary(); html.AppendLine(remittanceLibrary.CreateDynamicDropDownBox(ctlName, sp, "value", "text", defaultValue) + "
 
"); html.AppendLine("
"); html.AppendLine( ""); html.AppendLine(""); html.AppendLine("
"); html.AppendLine(""); var filterText = _hasFilter ? "style = 'background-color:yellow'" : ""; return html.ToString().Replace("{{style}}", filterText); } private void LoadVariables() { if (EnableCookie) { if (PageSize != -1) { PageNumber = Convert.ToInt16(GetStatic.ReadFormData(GridName + "_pageNumber", "1")); PageSize = Convert.ToInt16(ReadData2("pageSize", PageSize.ToString())); } SortOrder = ReadFormData("sortOrder", SortOrder); SortBy = ReadFormData("sortBy", SortBy); } if (GridWidth == -1) { GridWidth = Convert.ToInt16(GetStatic.ReadWebConfig("gridWidth", "-1")); if (GridWidth == -1) GridWidth = 700; } if (GridHeight == -1) { GridHeight = Convert.ToInt16(GetStatic.ReadWebConfig("gridHeight", "-1")); } } private string ReadFormData(string key, string defaultValue) { var user = GetStatic.GetUser(); var ctlName = GridName + "_" + key; defaultValue = GetStatic.ReadFormData(ctlName, defaultValue); return defaultValue; } private string ReadData(string key, string defaultValue) { return ReadData(key, defaultValue, true); } private string ReadData(string key, string defaultValue, bool writeCookie) { var user = GetStatic.GetUser(); var ctlName = GridName + "_" + key; defaultValue = GetStatic.ReadCookie(ctlName + "_c_" + user, defaultValue); defaultValue = GetStatic.ReadFormData(ctlName, defaultValue); if (!writeCookie || string.IsNullOrEmpty(defaultValue.Trim())) { GetStatic.DeleteCookie(ctlName + "_c_" + user); } else { GetStatic.WriteCookie(ctlName + "_c_" + user, defaultValue); } return defaultValue; } private string ReadData2(string key, string defaultValue) { return ReadData2(key, defaultValue, true); } private string ReadData2(string key, string defaultValue, bool writeCookie) { var user = GetStatic.GetUser(); var ctlName1 = key; var ctlName = GridName + "_" + key; defaultValue = GetStatic.ReadCookie(ctlName1 + "_c_" + user, defaultValue); defaultValue = GetStatic.ReadFormData(ctlName, defaultValue); if (!writeCookie || string.IsNullOrEmpty(defaultValue.Trim())) { GetStatic.DeleteCookie(ctlName1 + "_c_" + user); } else { GetStatic.WriteCookie(ctlName1 + "_c_" + user, defaultValue); } return defaultValue; } private string GetFilterSql() { var user = GetStatic.GetUser(); var sql = ""; switch (GridType) { case 1: sql = " " + _comma + "@pageNumber=" + FilterString(PageNumber.ToString()); sql += ", @pageSize=" + FilterString(PageSize.ToString()); sql += ", @sortBy=" + FilterString(SortBy); sql += ", @sortOrder=" + FilterString(SortOrder); sql += ", @user = " + FilterString(GetStatic.GetUser()); _comma = ", "; if (FilterList != null) { foreach (var filter in FilterList) { var defaultValue = ""; if (filter.Type.ToLower().Equals("a") && !string.IsNullOrWhiteSpace(filter.Category)) { defaultValue = GetAutoCompleteValue(filter); } else { var ctlName = GridName + "_" + filter.Key; defaultValue = GetStatic.ReadCookie(ctlName + "_c_" + user, ""); defaultValue = defaultValue.Replace("'", "").Replace("'", ""); defaultValue = GetStatic.ReadFormData(ctlName, defaultValue); } if (defaultValue.Trim() == "") continue; sql = sql + _comma + "@" + filter.Key + " = " + FilterString(defaultValue); _comma = ", "; _hasFilter = true; } } break; case 2: if (FilterList != null) { foreach (var filter in FilterList) { var defaultValue = ""; if (filter.Type.ToLower().Equals("a") && !string.IsNullOrWhiteSpace(filter.Category)) { defaultValue = GetAutoCompleteValue(filter); } else { var ctlName = GridName + "_" + filter.Key; defaultValue = GetStatic.ReadCookie(ctlName + "_c_" + user, ""); defaultValue = defaultValue.Replace("'", "").Replace("'", ""); defaultValue = GetStatic.ReadFormData(ctlName, defaultValue); } if (defaultValue.Trim() == "") continue; if (filter.Type.ToLower() == "lt") { sql = sql + " AND " + filter.Key + " LIKE '" + FilterString(defaultValue).Replace("'", "") + "%'"; } else { sql = sql + " AND " + filter.Key + " = " + FilterString(defaultValue); } _hasFilter = true; } } break; } return sql; } private static string ReverseSortOrder(string sortOrder) { return sortOrder.ToLower().Trim() == "asc" ? "desc" : "asc"; } private string CreateDefaultControl() { //grd_ssc_sch_sortBy var html = new StringBuilder(""); html.AppendLine(""); html.AppendLine(""); html.AppendLine(""); html.AppendLine(""); html.AppendLine(""); return html.ToString(); } private string AppendChkBoxProperties(string id) { if (!IdsAreParsed) { CheckBoxIds = new ArrayList(); var valueList = SelectionCheckBoxList.Split(','); foreach (var s in valueList) { CheckBoxIds.Add(s.Trim().ToUpper()); } IdsAreParsed = true; } if (CheckBoxIds.Contains(id.Trim().ToUpper())) { return "checked = \"checked\""; } else { return ""; } } private string MakeAutoCompleteControl(GridFilter f) { var url = GetStatic.GetUrlRoot() + "/Component/AutoComplete/DataSource.asmx/GetList" + GetSurfix(f); var usr = GetStatic.GetUser(); var sb = new StringBuilder(); var strClientID = GridName + "_" + f.Key; var ctlValue = strClientID + "_aValue"; var ctlText = strClientID + "_aText"; var ctlSearch = strClientID + "_aSearch"; var defValue = ""; if (EnableFilterCookie) { defValue = GetStatic.ReadCookie(ctlValue + "_c_" + usr, defValue); defValue = GetStatic.ReadFormData(ctlValue, defValue); defValue = defValue.Replace("'", "").Replace("'", ""); defValue = FilterStringGrid(defValue); defValue = defValue == "null" ? "" : defValue; GetStatic.WriteCookie(ctlValue + "_c_" + usr, defValue); } else { defValue = GetStatic.ReadFormData(ctlValue, defValue); } var defText = ""; if (EnableFilterCookie) { defText = GetStatic.ReadCookie(ctlText + "_c_" + usr, defText); defText = GetStatic.ReadFormData(ctlText, defText); defText = defText.Replace("'", "").Replace("'", ""); defText = FilterStringGrid(defText); defText = defText == "null" ? "" : defText; GetStatic.WriteCookie(ctlText + "_c_" + usr, defText); } else { defText = GetStatic.ReadFormData(ctlText + "_c_" + usr, defText); } //grdRole_gl_code_aText_c_admin////grdRole_gl_code_aSearch sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); return sb.ToString(); } private string InitFunction(GridFilter f, string url, string gridName, string width) { var strClientID = gridName + "_" + f.Key; var sb = new StringBuilder(); sb.Append("LoadAutoCompleteTextBox("); sb.Append(@"""" + url + @""""); sb.Append(@",""#" + strClientID + @""""); sb.Append(@",""" + width + @""""); sb.Append(@",""" + GetData(f) + @""");"); return sb.ToString(); } protected String GetData(GridFilter f) { var sb = new StringBuilder(); sb.Append("'category' : '" + f.Category.Replace("'", "").Replace(",", "") + "'"); if (!string.IsNullOrWhiteSpace(f.Param1)) { var data = ParseParam("param1", f.Param1); sb.Append("," + data); } if (!string.IsNullOrWhiteSpace(f.Param2)) { var data = ParseParam("param2", f.Param2); sb.Append("," + data); } if (!string.IsNullOrWhiteSpace(f.Param3)) { var data = ParseParam("param3", f.Param3); sb.Append("," + data); } return sb.ToString(); } private string ParseParam(string key, string data) { if (data.StartsWith("@")) { return @"'" + key + @"':'"" + " + data.Substring(1) + @" + ""'"; } else { return "'" + key + "':'" + data.Replace("'", "").Replace(",", "") + "'"; } } private string GetSurfix(GridFilter f) { string surfix = ""; if (!string.IsNullOrWhiteSpace(f.Param1)) { surfix = "1"; } if (!string.IsNullOrWhiteSpace(f.Param2)) { surfix = "2"; } if (!string.IsNullOrWhiteSpace(f.Param3)) { surfix = "3"; } return surfix; } private string GetAutoCompleteValue(GridFilter f) { var usr = GetStatic.GetUser(); var sb = new StringBuilder(); var strClientID = GridName + "_" + f.Key; var retVal = ""; if (f.Value) { var ctlValue = strClientID + "_aValue"; retVal = GetStatic.ReadCookie(ctlValue + "_c_" + usr, retVal); retVal = GetStatic.ReadFormData(ctlValue, retVal); } else { var ctlText = strClientID + "_aText"; retVal = GetStatic.ReadCookie(ctlText + "_c_" + usr, retVal); retVal = GetStatic.ReadFormData(ctlText, retVal); } return retVal; } #endregion Private Methods } }