DevExpressGridHelper

 

using DevExpress.Utils;
using DevExpress.Web;
using DevExpress.Web.Mvc;
using DevExpress.Web.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Platform.Code.Helpers
{
    public enum NAPColumnType
    {
        Bound = 0,
        Integer = 1,
        Decimal = 2,
        DateTime = 3,
        String = 4,
        Boolean = 5,
        Object = 6,
        Date = 7,
    }



    public enum NAPColumnControlType
    {
        None = 0,
        Textbox = 1,
        DropDownList = 2,
        Checkbox = 3,
        Hyperlink = 4,
        Memo = 5,
        DateEdit = 6,
        IntEdit = 7,
        DecimalEdit = 8,
        DateTimeEdit = 9,
        Button = 10,
        DropDownListTextBoxGroup = 11,
        TextboxWithButton = 12,
        DateWithoutOption = 13,
        TextRange = 14
    }

    public class DevExpressGridHelper
    {
        private GridViewSettings _Settings;
        public string gs_EditField = "";
        public string gs_Fields = "";
        public string gs_MandatoryField = "";

        public DevExpressGridHelper(GridViewSettings settings)
        {
            this._Settings = settings;
        }

        public void GridSetting(string as_FunCode)
        {
            this._Settings.Width = Unit.Percentage(100);
            this._Settings.SettingsEditing.Mode = GridViewEditingMode.Batch;

            this._Settings.SettingsEditing.BatchEditSettings.EditMode = GridViewBatchEditMode.Cell;
            this._Settings.SettingsEditing.BatchEditSettings.StartEditAction = GridViewBatchStartEditAction.Click;

            this._Settings.Styles.BatchEditModifiedCell.BackColor = Utils.GetColor.BatchEditModifiedCell;
            this._Settings.Styles.BatchEditDeletedRow.BackColor = Utils.GetColor.DeleteColor;
            this._Settings.Styles.BatchEditCell.BackColor = Utils.GetColor.BatchEditCellColor;
            this._Settings.Styles.SelectedRow.BackColor = Utils.GetColor.BackColor;
            this._Settings.Styles.SelectedRow.ForeColor = Utils.GetColor.ForeColor;

            this._Settings.ClientSideEvents.CustomizationWindowCloseUp = Utils.GetTranslation("CustomizationWindowCloseUp");
            this._Settings.SettingsBehavior.EnableCustomizationWindow = true;
            this._Settings.SettingsBehavior.AllowSelectByRowClick = true;

            this._Settings.SettingsAdaptivity.AdaptivityMode = GridViewAdaptivityMode.Off;
            this._Settings.SettingsAdaptivity.AdaptiveColumnPosition = GridViewAdaptiveColumnPosition.Right;
            this._Settings.SettingsAdaptivity.AdaptiveDetailColumnCount = 1;
            this._Settings.SettingsAdaptivity.AllowOnlyOneAdaptiveDetailExpanded = false;
            this._Settings.SettingsAdaptivity.HideDataCellsAtWindowInnerWidth = 0;

            this._Settings.SettingsResizing.ColumnResizeMode = ColumnResizeMode.Control;
            this._Settings.SettingsText.EmptyDataRow = Utils.GetTranslation("No data to display");

            this._Settings.CellEditorInitialize = (sender, e) =>
            {
                ASPxEdit editor = (ASPxEdit)e.Editor;
                editor.ValidationSettings.Display = Display.Dynamic;
            };
            this._Settings.CustomJSProperties = (s, e) =>
            {
                e.Properties["cpPageSize"] = ((MVCxGridView)s).SettingsPager.PageSize;
                Dictionary<object, int> visibleIndices = new Dictionary<object, int>();
                var lo_GridView = s as MVCxGridView;
                if (lo_GridView != null)
                {
                    for (int i = 0; i < lo_GridView.VisibleRowCount; i++)
                    {
                        var ls_RowValue = lo_GridView.GetRowValues(i, lo_GridView.KeyFieldName);
                        if (!visibleIndices.ContainsKey(ls_RowValue))
                        {
                            visibleIndices.Add(ls_RowValue, i);
                        }
                    }
                }
                e.Properties["cpIndices"] = visibleIndices;
            };
            this._Settings.CustomColumnDisplayText = (sender, e) =>
            {
                if (e.Column.FieldName == "RowNo")
                {
                    if (e.VisibleIndex >= 0)
                    {
                        e.DisplayText = (e.VisibleIndex + 1).ToString();
                        e.Value = (e.VisibleIndex + 1).ToString();
                    }
                }
                this.FormatDisplayText(e);
            };
            this._Settings.PreRender = (sender, e) =>
            {
                ASPxGridView gridView = (ASPxGridView)sender;
                gridView.FilterExpression = string.Empty;
            };
            this._Settings.CommandButtonInitialize = (sender, e) =>
            {
                if ((e.ButtonType == ColumnCommandButtonType.Update) || (e.ButtonType == ColumnCommandButtonType.Cancel))
                {
                    e.Visible = false;
                }
            };
            this._Settings.ClientLayout = (sender, e) =>
            {
                if (e.LayoutMode == ClientLayoutMode.Saving)
                {
                    if ((string)HttpContext.Current.Request.Cookies["bSave" + as_FunCode + this._Settings.Name + "Layout"].Value == "1")
                    {
                        HttpContext.Current.Response.Cookies[as_FunCode + this._Settings.Name + "Layout"].Value = e.LayoutData;
                        Utils.SaveUserLayoutToDatabase(as_FunCode + this._Settings.Name, e.LayoutData);
                    }
                }
                else
                {
                    if (HttpContext.Current.Request.Cookies[as_FunCode + this._Settings.Name + "Layout"] == null || String.IsNullOrEmpty(HttpContext.Current.Request.Cookies[as_FunCode + this._Settings.Name + "Layout"].Value))
                    {
                        HttpContext.Current.Response.Cookies[as_FunCode + this._Settings.Name + "Layout"].Value = Utils.RestoreUserLayoutFromDatabase(as_FunCode + this._Settings.Name);

                    }
                    if (HttpContext.Current.Response.Cookies[as_FunCode + this._Settings.Name + "Layout"].Value != null && HttpContext.Current.Response.Cookies[as_FunCode + this._Settings.Name + "Layout"].Value != "")
                    {
                        e.LayoutData = HttpContext.Current.Response.Cookies[as_FunCode + this._Settings.Name + "Layout"].Value;
                    }
                    else
                    {
                        e.LayoutData = HttpContext.Current.Request.Cookies[as_FunCode + this._Settings.Name + "Layout"].Value;
                    }
                }
                HttpContext.Current.Response.Cookies["bSave" + as_FunCode + this._Settings.Name + "Layout"].Value = "0";
            };
            this._Settings.CustomActionRouteValues = "";
        }

        public void GridExportSetting(string as_FileName)
        {
            this._Settings.SettingsExport.Styles.Cell.Font.Name = "Calibri";
            this._Settings.SettingsExport.Styles.Header.Font.Name = "Calibri";
            this._Settings.SettingsExport.FileName = as_FileName + "_" + System.DateTime.Today.ToString("yyyyMMdd");
            this._Settings.SettingsExport.RenderBrick = (sender, e) =>
            {
                MVCxGridViewColumn col = e.Column as MVCxGridViewColumn;
                HyperLinkProperties properties = col.PropertiesEdit as HyperLinkProperties;

                if (properties != null)
                {
                    properties.NavigateUrlFormatString = "";
                    col.ColumnType = MVCxGridViewColumnType.TextBox;
                }
            };
        }

        public void AddSelectCheckboxColumn()
        {
            this._Settings.CommandColumn.Visible = true;
            this._Settings.CommandColumn.Width = 50;
            this._Settings.CommandColumn.ShowClearFilterButton = true;
            this._Settings.CommandColumn.ShowSelectCheckbox = true;
            this._Settings.CommandColumn.SelectAllCheckboxMode = GridViewSelectAllCheckBoxMode.Page;

        }

        public void AddSelectRadioButtonColumn()
        {
            this._Settings.CommandColumn.Visible = true;
            this._Settings.CommandColumn.Width = 50;
            this._Settings.CommandColumn.ShowClearFilterButton = true;
            this._Settings.SettingsBehavior.AllowSelectSingleRowOnly = true;
            this._Settings.CommandColumn.ShowSelectCheckbox = true;
            this._Settings.CommandColumn.FixedStyle = GridViewColumnFixedStyle.Left;
        }

        public void AddScrollbar(int ai_Height)
        {
            this._Settings.Settings.HorizontalScrollBarMode = ScrollBarMode.Visible;
            this._Settings.Settings.VerticalScrollBarMode = ScrollBarMode.Visible;
            this._Settings.Settings.VerticalScrollableHeight = ai_Height;
        }

        public void AddGroupPanel()
        {
            this._Settings.Settings.ShowGroupPanel = true;
            this._Settings.SettingsText.GroupPanel = Utils.GetTranslation("Drag a column header here to group by that column");
        }

        public void AddPaging(int ai_PageSize, bool ab_ShowPaging = true)
        {
            this._Settings.SettingsPager.Visible = ab_ShowPaging;
            if (ab_ShowPaging)
            {
                this._Settings.SettingsPager.PageSize = ai_PageSize;
                this._Settings.SettingsPager.Position = PagerPosition.Top;
                this._Settings.SettingsPager.FirstPageButton.Visible = true;
                this._Settings.SettingsPager.LastPageButton.Visible = true;
                this._Settings.SettingsPager.PageSizeItemSettings.Visible = true;
                this._Settings.SettingsPager.PageSizeItemSettings.Items = Utils.GetPageSize();
            }
            else
            {
                this._Settings.SettingsPager.Mode = GridViewPagerMode.ShowAllRecords;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="ab_Visible"></param>
        /// <param name="ao_GridViewNewItemRowPosition"></param>
        /// <param name="ab_HasRecover"></param>
        /// <param name="ab_ConfirmDelete"></param>
        /// <param name="as_ConfirmDeleteText"></param>
        public void AddCommandColumnButton(HtmlHelper helper
            , bool ab_Visible = true
            , GridViewNewItemRowPosition ao_GridViewNewItemRowPosition = GridViewNewItemRowPosition.Bottom
            , bool ab_HasRecover = true
            , bool ab_ConfirmDelete = false
            , int ai_CommandColumnWidth = 40
            , bool ab_HasAddButton = true
            , bool ab_HasDeleteButton = true)
        {
            this._Settings.CommandColumn.ShowClearFilterButton = true;
            this._Settings.CommandColumn.Visible = ab_Visible;
            this._Settings.CommandColumn.ShowDeleteButton = ab_HasDeleteButton;
            this._Settings.SettingsCommandButton.DeleteButton.Text = "-";
            this._Settings.SettingsCommandButton.DeleteButton.RenderMode = GridCommandButtonRenderMode.Button;
            this._Settings.SettingsCommandButton.DeleteButton.Styles.Style.Font.Underline = false;
            this._Settings.SettingsEditing.BatchEditSettings.HighlightDeletedRows = ab_HasRecover;
            this._Settings.SettingsBehavior.ConfirmDelete = ab_ConfirmDelete;

            if (ab_ConfirmDelete)
                this._Settings.SettingsText.ConfirmDelete = Utils.GetMessage("2002", "[" + Utils.GenerateJson("1", Utils.GetTranslation("delete"), "String") + "]");

            this._Settings.CommandColumn.ShowRecoverButton = ab_HasRecover;
            this._Settings.SettingsCommandButton.RecoverButton.Text = "+";
            this._Settings.SettingsCommandButton.RecoverButton.RenderMode = GridCommandButtonRenderMode.Button;
            this._Settings.SettingsCommandButton.RecoverButton.Styles.Style.Font.Underline = false;
            this._Settings.CommandColumn.FixedStyle = GridViewColumnFixedStyle.Left;
            this._Settings.CommandColumn.Width = ai_CommandColumnWidth;
            this._Settings.SettingsEditing.NewItemRowPosition = ao_GridViewNewItemRowPosition;

            if (ab_HasAddButton)
            {
                this._Settings.CommandColumn.SetHeaderTemplateContent(c =>
                {
                    helper.DevExpress().Button(btnSettings =>
                    {
                        btnSettings.Text = "+";
                        btnSettings.Name = "btnAdd" + this._Settings.Name;
                        btnSettings.RenderMode = ButtonRenderMode.Button;
                        btnSettings.ControlStyle.Font.Underline = false;
                        btnSettings.Width = Unit.Percentage(100);
                        btnSettings.ClientVisible = ab_Visible;
                        btnSettings.ClientSideEvents.Click = "function (s,e){ " + this._Settings.Name + "_AddNewRow();}";
                        btnSettings.UseSubmitBehavior = false;
                    }).Render();
                });
            }
            this._Settings.CommandColumn.HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
        }

        public void AddColumn(string as_FieldName, string as_Caption, NAPColumnType ao_ColumnType, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "", NAPColumnControlType ao_ControlType = NAPColumnControlType.None, object[] ao_Object = null)
        {
            this._Settings.Columns.Add(column =>
            {
                column.FieldName = as_FieldName;
                column.Caption = Utils.GetTranslation(as_Caption);
                this.ColumnSetting(column, ao_ColumnType, ai_Width, ab_EditFormSettingsVisible, as_DisplayFormatString, ao_ControlType, ao_Object);
            });

            if (ab_Editable)
                gs_EditField += as_FieldName + ",";

            gs_Fields += as_FieldName + ",";
        }

        public void ColumnSetting(MVCxGridViewColumn ao_Column, NAPColumnType ao_ColumnType, int ai_Width, bool ab_EditFormSettingsVisible, string as_DisplayFormatString, NAPColumnControlType ao_ControlType, object[] ao_Object)
        {
            switch (ao_ColumnType)
            {
                case NAPColumnType.DateTime:
                    ao_Column.Width = 120;
                    ao_Column.UnboundType = DevExpress.Data.UnboundColumnType.DateTime;
                    ao_Column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
                    break;
                case NAPColumnType.Integer:
                    ao_Column.Width = 80;
                    ao_Column.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
                    ao_Column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                    ao_Column.CellStyle.HorizontalAlign = HorizontalAlign.Right;
                    break;
                case NAPColumnType.Date:
                    ao_Column.Width = 90;
                    ao_Column.ColumnType = MVCxGridViewColumnType.DateEdit;
                    ao_Column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
                    //column.PropertiesEdit.DisplayFormatString = "yyyyMMdd";
                    break;
                case NAPColumnType.String:
                    ao_Column.Width = 50;
                    ao_Column.UnboundType = DevExpress.Data.UnboundColumnType.String;
                    ao_Column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
                    ao_Column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
                    break;
                case NAPColumnType.Object:
                    SetColumnControl(ao_Column, ao_ControlType, ao_Object);
                    break;
            }
            if (!string.IsNullOrWhiteSpace(as_DisplayFormatString))
            {
                ao_Column.PropertiesEdit.DisplayFormatString = as_DisplayFormatString;
            }
            if (ai_Width != 0)
                ao_Column.Width = ai_Width;
            if (ab_EditFormSettingsVisible)
                ao_Column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
            else
                ao_Column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
        }

        public void FormatDisplayText(ASPxGridViewColumnDisplayTextEventArgs e)
        {
            DateTime ldt_DtTmp; //TryParse
            decimal lde_DeTmp; //TryParse
            int li_ITmp; //TryParse

            var value = e.GetFieldValue(e.Column.FieldName);

            //there is no FormatString for string
            if (e.Column.UnboundType == DevExpress.Data.UnboundColumnType.String)
            {
                return;
            }
            if (value != null && e.DisplayText == null && string.IsNullOrWhiteSpace(value.ToString()))
            {
                return;
            }
            if (value == null && !string.IsNullOrWhiteSpace(e.DisplayText))
            {
                return;
            }
            //For ListDataSource to Show Text
            if (value != null && e.DisplayText != null && e.DisplayText != value.ToString())
            {
                return;
            }

            var formatString = e.Column.PropertiesEdit.DisplayFormatString;
            if (string.IsNullOrWhiteSpace(formatString) && value != null)
            {
                switch (e.Column.UnboundType)
                {
                    case DevExpress.Data.UnboundColumnType.DateTime:
                        formatString = Code.Utils.GetFormatString.DateTimeDisplay;
                        if (DateTime.TryParse(value.ToString(), out ldt_DtTmp))
                        {
                            e.DisplayText = string.Format("{0:" + formatString + "}", ldt_DtTmp);
                        }
                        break;
                    case DevExpress.Data.UnboundColumnType.Decimal:
                        formatString = Code.Utils.GetFormatString.DecimalDisplay;
                        if (decimal.TryParse(value.ToString(), out lde_DeTmp))
                        {
                            e.DisplayText = string.Format("{0:" + formatString + "}", lde_DeTmp);
                        }
                        break;
                    case DevExpress.Data.UnboundColumnType.Integer:
                        formatString = Code.Utils.GetFormatString.IntDisplay;
                        if (int.TryParse(value.ToString(), out li_ITmp))

                        {
                            e.DisplayText = string.Format("{0:" + formatString + "}", li_ITmp);
                        }
                        if (value == DBNull.Value)
                        {
                            e.DisplayText = "";
                        }
                        break;
                    case DevExpress.Data.UnboundColumnType.Bound:
                        if (((DevExpress.Web.Mvc.MVCxGridViewColumn)e.Column).ColumnType != MVCxGridViewColumnType.Default)
                        {
                            switch (((DevExpress.Web.Mvc.MVCxGridViewColumn)e.Column).ColumnType)
                            {
                                case MVCxGridViewColumnType.TextBox:
                                    break;
                                case MVCxGridViewColumnType.DateEdit:
                                    formatString = Code.Utils.GetFormatString.DateEdit;
                                    if (DateTime.TryParse(value.ToString(), out ldt_DtTmp))
                                    {
                                        e.DisplayText = string.Format("{0:" + formatString + "}", ldt_DtTmp);
                                    }
                                    break;
                                case MVCxGridViewColumnType.SpinEdit:
                                    break;
                                case MVCxGridViewColumnType.TimeEdit:
                                    break;
                            }
                        }
                        break;
                }
            }
        }

        public void SetColumnControl(MVCxGridViewColumn ao_Column, NAPColumnControlType ao_ControlType, object[] ao_Object)
        {
            bool lb_IsRequired;
            int li_MaxLength;
            string ls_Text;
            string ls_Value;
            string ls_ValidationEvent;
            string urlFormatString;
            object lo_Model;

            switch (ao_ControlType)
            {
                case NAPColumnControlType.Textbox:
                    li_MaxLength = Convert.ToInt32(ao_Object[0]);
                    lb_IsRequired = ao_Object[1] == null ? false : Convert.ToBoolean(ao_Object[1]);
                    ls_ValidationEvent = ao_Object[2] == null ? null : ao_Object[2].ToString();
                    ao_Column.EditorProperties().TextBox(p =>
                    {
                        p.MaxLength = li_MaxLength;
                        p.ValidationSettings.RequiredField.IsRequired = lb_IsRequired;
                        p.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(ao_Column.Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                        p.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(ao_Column.Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                        p.ValidationSettings.EnableCustomValidation = ls_ValidationEvent != null;
                        p.ClientSideEvents.Validation = ls_ValidationEvent;
                    });
                    break;

                case NAPColumnControlType.DropDownList:
                    lo_Model = ao_Object[0];
                    ls_Text = ao_Object[1].ToString();
                    ls_Value = ao_Object[2].ToString();
                    lb_IsRequired = ao_Object[3] == null ? false : Convert.ToBoolean(ao_Object[3]);
                    ls_ValidationEvent = ao_Object[4] == null ? null : ao_Object[4].ToString();
                    ao_Column.EditorProperties().ComboBox(p =>
                    {
                        p.TextField = ls_Text;
                        p.ValueField = ls_Value;
                        p.ValueType = typeof(string);
                        p.DataSource = lo_Model;
                        p.ValidationSettings.RequiredField.IsRequired = lb_IsRequired;
                        p.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(ao_Column.Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                        p.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(ao_Column.Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                        p.ValidationSettings.EnableCustomValidation = ls_ValidationEvent != null;
                        p.ClientSideEvents.Validation = ls_ValidationEvent;
                    });
                    break;

                case NAPColumnControlType.Hyperlink:
                    ao_Column.ColumnType = MVCxGridViewColumnType.HyperLink;
                    HyperLinkProperties properties = ao_Column.PropertiesEdit as HyperLinkProperties;
                    urlFormatString = ao_Object[0].ToString();
                    properties.NavigateUrlFormatString = HttpUtility.UrlDecode(urlFormatString);
                    properties.TextField = ao_Column.Caption;
                    properties.Target = "_blank";
                    break;

                case NAPColumnControlType.Memo:
                    ao_Column.ColumnType = MVCxGridViewColumnType.Memo;
                    break;
            }
        }

        public void SetColumnConditionalFormatting(string as_FieldName, string as_Condition, GridConditionHighlightFormat ao_HighlightFormat)
        {
            this._Settings.FormatConditions.AddHighlight(as_FieldName, as_Condition, ao_HighlightFormat);
        }

        public void CommonColumnSetting(MVCxGridViewColumn ao_Column, string as_FieldName, string as_Caption, int ai_Width, bool ab_Editable, bool ab_EditFormSettingsVisible, string as_DisplayFormatString = "", bool ab_IsRequired = false)
        {
            ao_Column.FieldName = as_FieldName;
            ao_Column.Caption = Utils.GetTranslation(as_Caption);
            ao_Column.HeaderStyle.Wrap = DefaultBoolean.True;

            if (!string.IsNullOrWhiteSpace(as_DisplayFormatString))
            {
                ao_Column.PropertiesEdit.DisplayFormatString = as_DisplayFormatString;
            }
            if (ai_Width != 0)
                ao_Column.Width = ai_Width;
            if (ab_EditFormSettingsVisible)
                ao_Column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
            else
                ao_Column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;

            ao_Column.CellStyle.BackColor = System.Drawing.Color.Transparent;
            if (ab_IsRequired)
                gs_MandatoryField += as_FieldName + ",";

            if (ab_Editable)
            {
                gs_EditField += as_FieldName + ",";
                ao_Column.CellStyle.BackColor = Utils.GetColor.EditableColor;
            }

            gs_Fields += as_FieldName + ",";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="as_FieldName">Field name</param>
        /// <param name="as_Caption">Column caption</param>
        /// <param name="ao_ColumnType">Column type</param>
        /// <param name="ai_Width">Column width</param>
        /// <param name="ab_Editable">Column editable</param>
        /// <param name="ab_EditFormSettingsVisible">Column edit form settings visible</param>
        /// <param name="as_DisplayFormatString">Column display format string. e.g: yyyyMMdd HH:mm:ss</param>
        public void AddNormalColumn(string as_FieldName, string as_Caption, NAPColumnType ao_ColumnType, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "")
        {
            this._Settings.Columns.Add(column =>
            {
                switch (ao_ColumnType)
                {
                    case NAPColumnType.DateTime:
                        column.Width = 120;
                        column.UnboundType = DevExpress.Data.UnboundColumnType.DateTime;
                        column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
                        break;
                    case NAPColumnType.Integer:
                        column.Width = 80;
                        column.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
                        column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                        column.CellStyle.HorizontalAlign = HorizontalAlign.Right;
                        break;
                    case NAPColumnType.Date:
                        column.Width = 90;
                        column.ColumnType = MVCxGridViewColumnType.DateEdit;
                        column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
                        //column.PropertiesEdit.DisplayFormatString = "yyyyMMdd";
                        break;
                    case NAPColumnType.String:
                        column.UnboundType = DevExpress.Data.UnboundColumnType.String;
                        column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
                        column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
                        break;
                }
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, as_DisplayFormatString);
            });

        }

        public void AddTextBoxColumn(string as_FieldName, string as_Caption, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "", int ai_MaxLength = 0, bool ab_IsRequired = false, string as_ValidationEvent = null, string as_Mask = null)
        {


            this._Settings.Columns.Add(column =>
        {
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, as_DisplayFormatString, ab_IsRequired);


            column.EditorProperties().TextBox(textBoxProperties =>
            {
                if (ai_MaxLength > 0) textBoxProperties.MaxLength = ai_MaxLength;
                if (!string.IsNullOrWhiteSpace(as_Mask))
                {
                    textBoxProperties.MaskSettings.Mask = as_Mask;
                    textBoxProperties.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.All;
                }
                if (ab_IsRequired)
                {
                    textBoxProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                    textBoxProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    textBoxProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                }
                if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                {
                    textBoxProperties.ValidationSettings.EnableCustomValidation = true;
                    textBoxProperties.ClientSideEvents.Validation = as_ValidationEvent;
                }

            });
        });

        }

        public void AddDateEditorColumn(string as_FieldName, string as_Caption, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "", string as_EditFormatString = "", DateTime? adt_MaxDate = null, DateTime? adt_MinDate = null, bool ab_IsRequired = false, string as_ValidationEvent = null, string as_DropDownEvent = null)
        {
            this._Settings.Columns.Add(column =>
            {
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, as_DisplayFormatString, ab_IsRequired);

                column.ColumnType = MVCxGridViewColumnType.DateEdit;
                column.EditorProperties().DateEdit(dateEditProperties =>
                {
                    dateEditProperties.UseMaskBehavior = true;
                    if (adt_MinDate != null) dateEditProperties.MinDate = (DateTime)adt_MinDate;
                    if (adt_MaxDate != null) dateEditProperties.MaxDate = (DateTime)adt_MaxDate;
                    //dateEditProperties.EditFormat = EditFormat.Date;
                    dateEditProperties.EditFormatString = as_EditFormatString;
                    dateEditProperties.DisplayFormatInEditMode = true;
                    dateEditProperties.EditFormat = EditFormat.Custom;
                    dateEditProperties.AllowUserInput = true;
                    dateEditProperties.AllowNull = true;
                    dateEditProperties.DisplayFormatString = as_DisplayFormatString;

                    if (ab_IsRequired)
                    {
                        dateEditProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                        dateEditProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                        dateEditProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    }
                    if (as_EditFormatString == Utils.GetFormatString.DateTimeEdit)
                    {
                        dateEditProperties.TimeSectionProperties.Visible = true;
                        dateEditProperties.TimeSectionProperties.TimeEditProperties.EditFormat = EditFormat.Custom;
                        dateEditProperties.TimeSectionProperties.ShowHourHand = true;
                        dateEditProperties.TimeSectionProperties.TimeEditProperties.EditFormatString = "HH:mm:ss";
                        dateEditProperties.CalendarProperties.FastNavProperties.EnablePopupAnimation = true;
                        dateEditProperties.ClientSideEvents.DropDown = as_DropDownEvent;
                        dateEditProperties.ClientSideEvents.CloseUp = "function(s,e){if(s.GetValue()==null||yyyy_MM_dd(s.GetValue(),'/')=='100/01/01') {s.GetTimeEdit().SetValue(null);s.SetValue(null);}}";
                        dateEditProperties.ClientSideEvents.ValueChanged = "function(s,e){if(s.GetValue()==null||yyyy_MM_dd(s.GetValue(),'/')=='100/01/01') {s.GetTimeEdit().SetValue(null);s.SetValue(null);}}";
                    }
                    if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                    {
                        dateEditProperties.ValidationSettings.EnableCustomValidation = true;
                        dateEditProperties.ClientSideEvents.Validation = as_ValidationEvent;
                    }
                });
            });

        }

        public void AddTimeEditorColumn(HtmlHelper helper, string as_FieldName, string as_Caption, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "", string as_EditFormatString = "", bool ab_IsRequired = false, string as_ValidationEvent = null)
        {
            this._Settings.Columns.Add(column =>
            {

                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, as_DisplayFormatString, ab_IsRequired);
                column.EditorProperties().TextBox(textBoxProperties =>
                {
                    textBoxProperties.MaxLength = 5;

                    textBoxProperties.MaskSettings.Mask = "00:00";
                    textBoxProperties.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.All;
                    if (ab_IsRequired)
                    {
                        textBoxProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                        textBoxProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                        textBoxProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    }
                    if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                    {
                        textBoxProperties.ValidationSettings.EnableCustomValidation = true;
                        textBoxProperties.ClientSideEvents.Validation = as_ValidationEvent;
                    }
                });


            });
        }

        public void AddComboboxColumn(string as_FieldName, string as_Caption, object ao_Model, string as_ValueFieldName, string as_TextFieldName, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null, string as_SelectChangedEvent = null, string as_Type = "Int", object ao_CallbackRouteValues = null, string as_BeginCallback = null, string as_EndCallback = null)
        {
            this._Settings.Columns.Add(column =>
            {
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);

                column.ColumnType = MVCxGridViewColumnType.ComboBox;
                column.EditorProperties().ComboBox(comboBoxProperties =>
                {
                    comboBoxProperties.TextField = as_TextFieldName;
                    comboBoxProperties.ValueField = as_ValueFieldName;
                    comboBoxProperties.ValueType = as_Type == "Int" ? typeof(int) : typeof(string);
                    comboBoxProperties.DataSource = ao_Model;
                    if (ao_CallbackRouteValues != null) comboBoxProperties.CallbackRouteValues = ao_CallbackRouteValues;
                    if (as_BeginCallback != null) comboBoxProperties.ClientSideEvents.BeginCallback = as_BeginCallback;
                    if (as_EndCallback != null) comboBoxProperties.ClientSideEvents.EndCallback = as_EndCallback;
                    if (ab_IsRequired)
                    {
                        comboBoxProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                        comboBoxProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                        comboBoxProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                        //if (!string.IsNullOrWhiteSpace(as_SelectChangedEvent))
                        //{
                        //    comboBoxProperties.ClientSideEvents.SelectedIndexChanged = as_SelectChangedEvent;
                        //}
                    }
                    if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                    {
                        comboBoxProperties.ValidationSettings.EnableCustomValidation = true;
                        comboBoxProperties.ClientSideEvents.Validation = as_ValidationEvent;

                    }
                    if (!string.IsNullOrWhiteSpace(as_SelectChangedEvent))
                    {
                        comboBoxProperties.ClientSideEvents.SelectedIndexChanged = as_SelectChangedEvent;
                    }
                    comboBoxProperties.EnableSynchronization = DefaultBoolean.True;
                });

            });

        }

        public void AddHyperlinkColumn(string as_FieldName, string as_Caption, string as_urlFormatString, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null)
        {
            this._Settings.Columns.Add(column =>
            {
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);

                column.ColumnType = MVCxGridViewColumnType.HyperLink;
                column.EditorProperties().HyperLink(hyperLinkProperties =>
                {
                    hyperLinkProperties.NavigateUrlFormatString = HttpUtility.UrlDecode(as_urlFormatString);
                    hyperLinkProperties.TextField = as_FieldName;
                    hyperLinkProperties.Target = "_blank";
                });

            });
        }

        public void AddMapHyperlinkColumn(HtmlHelper helper, string as_FieldName, string as_Caption, string as_urlFormatString, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = null, bool ab_IsRequired = false, string as_ValidationEvent = null, string as_LatFieldName = "", string as_LngFieldName = "")
        {
            this._Settings.Columns.Add(column =>
            {
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired, as_DisplayFormatString: as_DisplayFormatString);

                column.ColumnType = MVCxGridViewColumnType.HyperLink;
                column.SetDataItemTemplateContent(container =>
                {
                    if (container.VisibleIndex >= 0)
                    {

                        helper.DevExpress().HyperLink(hyperLinkProperties =>
                        {
                            var ls_KeyValue = container.KeyValue;
                            if (DataBinder.Eval(container.DataItem, as_FieldName) != DBNull.Value && DataBinder.Eval(container.DataItem, as_FieldName).ToString() != "")
                                if (as_DisplayFormatString == Utils.GetFormatString.DateTimeDisplay)
                                    hyperLinkProperties.Properties.Text = Convert.ToDateTime(DataBinder.Eval(container.DataItem, as_FieldName).ToString()).ToString(Utils.GetFormatString.DateTimeDisplay);
                                else
                                    hyperLinkProperties.Properties.Text = DataBinder.Eval(container.DataItem, as_FieldName).ToString();
                            hyperLinkProperties.Name = "lnk_" + as_FieldName + ls_KeyValue + Utils.GenerateRandom(4);
                            hyperLinkProperties.Properties.NavigateUrlFormatString = HttpUtility.UrlDecode(String.Format(as_urlFormatString, DataBinder.Eval(container.DataItem, as_LatFieldName), DataBinder.Eval(container.DataItem, as_LngFieldName)));
                            hyperLinkProperties.Properties.TextField = as_FieldName;
                            hyperLinkProperties.Properties.ClientSideEvents.Click = "function(s,e){window.open('" + hyperLinkProperties.Properties.NavigateUrlFormatString + "', '_blank')}";
                            hyperLinkProperties.Properties.Target = "_blank";
                        }).Render();
                    }
                    else
                    {
                        if (DataBinder.Eval(container.DataItem, as_FieldName) != null)
                            helper.ViewContext.Writer.Write(DataBinder.Eval(container.DataItem, as_FieldName).ToString());

                    }
                });



            });
        }

        public void AddMemoColumn(string as_FieldName, string as_Caption, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null)
        {
            this._Settings.Columns.Add(column =>
            {
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);

                column.ColumnType = MVCxGridViewColumnType.Memo;
                column.EditorProperties().Memo(memoProperties =>
                {
                    if (ab_IsRequired)
                    {
                        memoProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                        memoProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                        memoProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    }
                    if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                    {
                        memoProperties.ValidationSettings.EnableCustomValidation = true;
                        memoProperties.ClientSideEvents.Validation = as_ValidationEvent;
                    }
                });
            });
        }

        public void AddCheckBoxColumn(string as_FieldName, string as_Caption, object ao_ValueChecked, object ao_ValueUnchecked, Type ao_ValueType, string as_ValueCheckedString, string as_ValueUncheckedString, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null)
        {
            this._Settings.Columns.Add(column =>
            {
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);

                column.ColumnType = MVCxGridViewColumnType.CheckBox;
                var checkBoxProperties = column.PropertiesEdit as CheckBoxProperties;
                checkBoxProperties.ValueChecked = ao_ValueChecked;
                checkBoxProperties.ValueUnchecked = ao_ValueUnchecked;
                checkBoxProperties.ValueType = ao_ValueType;
                checkBoxProperties.ValueCheckedString = as_ValueCheckedString;
                checkBoxProperties.ValueUncheckedString = as_ValueUncheckedString;
            });
        }

        public void AddCheckBoxColumnWithinHeader(HtmlHelper helper, string as_FieldName, string as_Caption, object ao_ValueChecked, object ao_ValueUnchecked, Type ao_ValueType, string as_ValueCheckedString, string as_ValueUncheckedString, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null)
        {
            this._Settings.Columns.Add(column =>
            {
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);

                column.SetHeaderTemplateContent(c =>
                {
                    helper.DevExpress().CheckBox(chkSettings =>
                    {
                        chkSettings.Text = as_Caption;
                        chkSettings.Name = "chk" + this._Settings.Name + as_FieldName + "_SelectAll";
                        chkSettings.ControlStyle.Font.Underline = false;
                        chkSettings.Width = Unit.Percentage(100);
                        chkSettings.ControlStyle.HorizontalAlign = HorizontalAlign.Center;
                        chkSettings.Properties.ClientSideEvents.CheckedChanged = "function (s,e){ On" + chkSettings.Name + "(s,e);}";
                    }).Render();
                });
                column.ColumnType = MVCxGridViewColumnType.CheckBox;
                var checkBoxProperties = column.PropertiesEdit as CheckBoxProperties;
                checkBoxProperties.ValueChecked = ao_ValueChecked;
                checkBoxProperties.ValueUnchecked = ao_ValueUnchecked;
                checkBoxProperties.ValueType = ao_ValueType;
                checkBoxProperties.ValueCheckedString = as_ValueCheckedString;
                checkBoxProperties.ValueUncheckedString = as_ValueUncheckedString;
                column.Settings.AllowSort = DefaultBoolean.False;

            });
        }

        public void AddHyperlinkDynamicClientSideColumn(string as_FieldName, string as_Caption, HtmlHelper helper, string[] aa_DataFieldName, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = null, string as_ClientSideEventName = null)
        {
            this._Settings.Columns.Add(column =>
            {
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible);
                column.SetDataItemTemplateContent(container =>
                {
                    if (container.VisibleIndex < 0)
                        return;

                    object[] la_DataValue = new object[aa_DataFieldName.Length];
                    bool lb_Valid = true;
                    string ls_ValueString = "";
                    for (int i = 0; i < aa_DataFieldName.Length; i++)
                    {
                        if (!string.IsNullOrWhiteSpace(aa_DataFieldName[i]))
                        {
                            la_DataValue[i] = DataBinder.Eval(container.DataItem, aa_DataFieldName[i]);

                        }
                    }
                    for (int i = 0; i < la_DataValue.Length; i++)
                    {
                        if (la_DataValue[i] == null)
                        {
                            lb_Valid = false;
                        }
                        else
                        {
                            ls_ValueString = ls_ValueString + "'" + (la_DataValue[i] == DBNull.Value ? "" : la_DataValue[i].ToString()) + "',";


                        }
                    }

                    if (lb_Valid)
                    {

                        if (ls_ValueString != "")
                        {

                            ls_ValueString = ls_ValueString.Substring(0, ls_ValueString.Length - 1);
                            if (ls_ValueString != "''")
                            {
                                helper.DevExpress().HyperLink(hyperlink =>
                                {
                                    var ls_KeyValue = container.KeyValue;
                                    hyperlink.Name = "lnk_" + as_FieldName + ls_KeyValue + Utils.GenerateRandom(4);
                                    if (as_DisplayFormatString == Utils.GetFormatString.DateDisplay)
                                        hyperlink.Properties.Text = Convert.ToDateTime(DataBinder.Eval(container.DataItem, as_FieldName).ToString()).ToString(Utils.GetFormatString.DateDisplay);
                                    else
                                        hyperlink.Properties.Text = DataBinder.Eval(container.DataItem, as_FieldName).ToString();
                                    hyperlink.Properties.TextField = as_FieldName;
                                    hyperlink.Properties.ClientSideEvents.Click = "function (s,e){ " + as_ClientSideEventName + "(" + ls_ValueString + ");}";
                                    hyperlink.Properties.Target = "_blank";
                                }).Render();
                            }
                            else
                            {
                                helper.ViewContext.Writer.Write("");
                            }
                        }
                    }
                    else
                    {
                        if (DataBinder.Eval(container.DataItem, as_FieldName) != null)
                            helper.ViewContext.Writer.Write(DataBinder.Eval(container.DataItem, as_FieldName).ToString());

                    }


                });

            });
        }

        /// <summary>
        /// Only support decimal or Integer
        /// </summary>
        /// <param name="as_FieldName"></param>
        /// <param name="as_Caption"></param>
        /// <param name="ai_Width"></param>
        /// <param name="ab_Editable"></param>
        /// <param name="ab_EditFormSettingsVisible"></param>
        /// <param name="as_DisplayFormatString">Displayformat E.g n2,d</param>
        /// <param name="ao_NumberType">Decimal or Integer </param>
        /// <param name="afl_MinValue">Min value</param>
        /// <param name="afl_MaxValue">Max value</param>
        /// <param name="ab_IsRequired"></param>
        /// <param name="as_ValidationEvent"></param>
        public void AddNumberColumn(HtmlHelper helper, string as_FieldName, string as_Caption, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "", SpinEditNumberType ao_NumberType = SpinEditNumberType.Float, float? afl_MinValue = null, float? afl_MaxValue = null, bool ab_IsRequired = false, string as_ValidationEvent = null, DevExpress.Data.SummaryItemType ao_SummaryType = DevExpress.Data.SummaryItemType.None, bool ab_IsRealTimeCalTotalSum = false)
        {
            this._Settings.Columns.Add(column =>
            {
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, as_DisplayFormatString, ab_IsRequired: ab_IsRequired);

                column.ColumnType = MVCxGridViewColumnType.TextBox;
                column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                column.CellStyle.HorizontalAlign = HorizontalAlign.Right;
                column.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;

                column.EditorProperties().SpinEdit(spinEditProperties =>
                {
                    spinEditProperties.NumberFormat = SpinEditNumberFormat.Custom;
                    spinEditProperties.DisplayFormatString = as_DisplayFormatString;
                    spinEditProperties.DisplayFormatInEditMode = true;
                    spinEditProperties.NumberType = ao_NumberType;

                    //spinEditProperties.AllowNull = false;
                    spinEditProperties.SpinButtons.Visible = false;
                    spinEditProperties.SpinButtons.ShowLargeIncrementButtons = false;
                    spinEditProperties.SpinButtons.ShowIncrementButtons = false;
                    spinEditProperties.Increment = 0;
                    spinEditProperties.AllowMouseWheel = false;
                    if (afl_MinValue != null) spinEditProperties.MinValue = (decimal)afl_MinValue;
                    if (afl_MaxValue != null) spinEditProperties.MaxValue = (decimal)afl_MaxValue;
                    if (ab_IsRequired)
                    {
                        spinEditProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                        spinEditProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                        spinEditProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    }
                    if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                    {
                        spinEditProperties.ValidationSettings.EnableCustomValidation = true;
                        spinEditProperties.ClientSideEvents.Validation = as_ValidationEvent;
                    }
                });

                if (ab_IsRealTimeCalTotalSum)
                {
                    ASPxSummaryItem summaryItem = new ASPxSummaryItem(column.FieldName, DevExpress.Data.SummaryItemType.Sum);
                    summaryItem.Tag = "SummaryItem_Sum_" + column.FieldName;
                    this._Settings.TotalSummary.Add(summaryItem);
                    column.SetFooterTemplateContent(c =>
                    {

                        helper.DevExpress().Label(lbSettings =>
                        {
                            string fieldName = (c.Column as GridViewDataColumn).FieldName;
                            //c.data
                            lbSettings.Name = "lbl_Sum_" + fieldName;
                            lbSettings.Properties.EnableClientSideAPI = true;
                            ASPxSummaryItem summaryItem1 = c.Grid.TotalSummary.First(i => i.Tag == ("SummaryItem_Sum_" + fieldName));
                            lbSettings.Text = string.Format("{0:" + as_DisplayFormatString + "}", (c.Grid.GetTotalSummaryValue(summaryItem1) ?? 0));

                        }).Render();
                    });
                }
            });

            this._Settings.TotalSummary.Add(ao_SummaryType, as_FieldName).DisplayFormat = as_DisplayFormatString;
        }

        public void ChangeCellColor(dynamic ao_Model, ASPxGridViewTableDataCellEventArgs e)
        {
            //string[] la_Fields = this.gs_Fields.Split(',');
            //for (int i = 0; i < la_Fields.Count(); i++)
            //{
            for (int j = 0; j < ao_Model.Tables[0].Rows.Count; j++)
            {
                if (e.DataColumn.FieldName == ao_Model.Tables[0].Rows[j]["FieldName"].ToString())// && ao_Model.Tables[0].Rows[j]["FieldName"].ToString() == la_Fields[i].ToString())
                {
                    if (e.KeyValue != null && e.KeyValue.ToString() == ao_Model.Tables[0].Rows[j]["TableUID"].ToString() && ao_Model.Tables[0].Rows[j]["IsChanged"].ToString() == "1")
                    {
                        //if (e.DataColumn.FieldName == ao_Model.Tables[0].Rows[j][2].ToString())
                        //{
                        e.Cell.BackColor = Utils.GetColor.ChangedColor;
                        break;
                        //}
                    }
                }
            }
        }

        public void AddButtonColumn(HtmlHelper helper, string as_FieldName, string as_Caption, string as_ParamField, int ai_Width = 0,

            bool ab_EditFormSettingsVisible = false, string as_OnClickEvent = null)
        {
            this._Settings.Columns.Add(column =>
            {
                this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, false, ab_EditFormSettingsVisible, "", false);

                column.UnboundType = DevExpress.Data.UnboundColumnType.String;
                //column.EditorProperties().TextBox(textBoxProperties =>
                //{
                //    if (ai_MaxLength < 0) textBoxProperties.MaxLength = ai_MaxLength;
                //    if (!string.IsNullOrWhiteSpace(as_Mask))
                //    {
                //        textBoxProperties.MaskSettings.Mask = as_Mask;
                //        textBoxProperties.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.All;
                //    }
                //    if (ab_IsRequired)
                //    {
                //        textBoxProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                //        textBoxProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                //        textBoxProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                //    }
                //    if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                //    {
                //        textBoxProperties.ValidationSettings.EnableCustomValidation = true;
                //        textBoxProperties.ClientSideEvents.Validation = as_ValidationEvent;
                //    }

                //});
                column.SetDataItemTemplateContent(container =>
                {
                    if (container.VisibleIndex < 0)
                        return;

                    var ls_ParamValue = DataBinder.Eval(container.DataItem, as_ParamField).ToString();
                    helper.DevExpress().Button(buttonSetting =>
                    {
                        buttonSetting.Text = "View";
                        buttonSetting.Name = "btnView" + as_FieldName + container.VisibleIndex;
                        buttonSetting.Width = Unit.Percentage(100);
                        if (!string.IsNullOrWhiteSpace(as_OnClickEvent))
                        {
                            buttonSetting.ClientSideEvents.Click = "function(s,e){ " + as_OnClickEvent + "(" + ls_ParamValue + "); }";
                        }
                    }).Render();
                });


            });

        }


        #region Bank Column Setting
        public MVCxGridViewColumn AddBandNormalColumn(string as_FieldName, string as_Caption, NAPColumnType ao_ColumnType, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "")
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            switch (ao_ColumnType)
            {
                case NAPColumnType.DateTime:
                    column.Width = 120;
                    column.UnboundType = DevExpress.Data.UnboundColumnType.DateTime;
                    column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
                    break;
                case NAPColumnType.Integer:
                    column.Width = 80;
                    column.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
                    column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                    column.CellStyle.HorizontalAlign = HorizontalAlign.Right;
                    break;
                case NAPColumnType.Date:
                    column.Width = 90;
                    column.ColumnType = MVCxGridViewColumnType.DateEdit;
                    column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
                    //column.PropertiesEdit.DisplayFormatString = "yyyyMMdd";
                    break;
                case NAPColumnType.String:
                    column.UnboundType = DevExpress.Data.UnboundColumnType.String;
                    column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
                    column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
                    break;
            }
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, as_DisplayFormatString);

            return column;
        }
        public MVCxGridViewColumn AddBandTextBoxColumn(string as_FieldName, string as_Caption, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "", int ai_MaxLength = 0, bool ab_IsRequired = false, string as_ValidationEvent = null, string as_Mask = null)
        {

            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, as_DisplayFormatString, ab_IsRequired);
            column.EditorProperties().TextBox(textBoxProperties =>
            {
                if (ai_MaxLength > 0) textBoxProperties.MaxLength = ai_MaxLength;
                if (!string.IsNullOrWhiteSpace(as_Mask))
                {
                    textBoxProperties.MaskSettings.Mask = as_Mask;
                    textBoxProperties.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.All;
                }
                if (ab_IsRequired)
                {
                    textBoxProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                    textBoxProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    textBoxProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                }
                if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                {
                    textBoxProperties.ValidationSettings.EnableCustomValidation = true;
                    textBoxProperties.ClientSideEvents.Validation = as_ValidationEvent;
                }

            });
            return column;
        }
        public MVCxGridViewColumn AddBandDateEditorColumn(string as_FieldName, string as_Caption, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "", string as_EditFormatString = "", DateTime? adt_MaxDate = null, DateTime? adt_MinDate = null, bool ab_IsRequired = false, string as_ValidationEvent = null, string as_DropDownEvent = null)
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, as_DisplayFormatString, ab_IsRequired);
            column.ColumnType = MVCxGridViewColumnType.DateEdit;
            column.EditorProperties().DateEdit(dateEditProperties =>
            {
                dateEditProperties.UseMaskBehavior = true;
                if (adt_MinDate != null) dateEditProperties.MinDate = (DateTime)adt_MinDate;
                if (adt_MaxDate != null) dateEditProperties.MaxDate = (DateTime)adt_MaxDate;
                //dateEditProperties.EditFormat = EditFormat.Date;
                dateEditProperties.EditFormatString = as_EditFormatString;
                dateEditProperties.DisplayFormatInEditMode = true;
                dateEditProperties.EditFormat = EditFormat.Custom;
                dateEditProperties.AllowUserInput = true;
                dateEditProperties.AllowNull = true;
                dateEditProperties.DisplayFormatString = as_DisplayFormatString;

                if (ab_IsRequired)
                {
                    dateEditProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                    dateEditProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    dateEditProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                }
                if (as_EditFormatString == Utils.GetFormatString.DateTimeEdit)
                {
                    dateEditProperties.TimeSectionProperties.Visible = true;
                    dateEditProperties.TimeSectionProperties.TimeEditProperties.EditFormat = EditFormat.Custom;
                    dateEditProperties.TimeSectionProperties.ShowHourHand = true;
                    dateEditProperties.TimeSectionProperties.TimeEditProperties.EditFormatString = "HH:mm:ss";
                    dateEditProperties.CalendarProperties.FastNavProperties.EnablePopupAnimation = true;
                    dateEditProperties.ClientSideEvents.DropDown = as_DropDownEvent;
                    dateEditProperties.ClientSideEvents.CloseUp = "function(s,e){if(s.GetValue()==null||yyyy_MM_dd(s.GetValue(),'/')=='100/01/01') {s.GetTimeEdit().SetValue(null);s.SetValue(null);}}";
                    dateEditProperties.ClientSideEvents.ValueChanged = "function(s,e){if(s.GetValue()==null||yyyy_MM_dd(s.GetValue(),'/')=='100/01/01') {s.GetTimeEdit().SetValue(null);s.SetValue(null);}}";
                }
                if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                {
                    dateEditProperties.ValidationSettings.EnableCustomValidation = true;
                    dateEditProperties.ClientSideEvents.Validation = as_ValidationEvent;
                }
            });
            return column;

        }
        public MVCxGridViewColumn AddBandTimeEditorColumn(HtmlHelper helper, string as_FieldName, string as_Caption, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "", string as_EditFormatString = "", bool ab_IsRequired = false, string as_ValidationEvent = null)
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, as_DisplayFormatString, ab_IsRequired);
            column.EditorProperties().TextBox(textBoxProperties =>
            {
                textBoxProperties.MaxLength = 5;

                textBoxProperties.MaskSettings.Mask = "00:00";
                textBoxProperties.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.All;
                if (ab_IsRequired)
                {
                    textBoxProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                    textBoxProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    textBoxProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                }
                if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                {
                    textBoxProperties.ValidationSettings.EnableCustomValidation = true;
                    textBoxProperties.ClientSideEvents.Validation = as_ValidationEvent;
                }
            });
            return column;
        }
        public MVCxGridViewColumn AddBandComboboxColumn(string as_FieldName, string as_Caption, object ao_Model, string as_ValueFieldName, string as_TextFieldName, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null, string as_SelectChangedEvent = null, string as_Type = "Int", object ao_CallbackRouteValues = null, string as_BeginCallback = null, string as_EndCallback = null)
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);

            column.ColumnType = MVCxGridViewColumnType.ComboBox;
            column.EditorProperties().ComboBox(comboBoxProperties =>
            {
                comboBoxProperties.TextField = as_TextFieldName;
                comboBoxProperties.ValueField = as_ValueFieldName;
                comboBoxProperties.ValueType = as_Type == "Int" ? typeof(int) : typeof(string);
                comboBoxProperties.DataSource = ao_Model;
                if (ao_CallbackRouteValues != null) comboBoxProperties.CallbackRouteValues = ao_CallbackRouteValues;
                if (as_BeginCallback != null) comboBoxProperties.ClientSideEvents.BeginCallback = as_BeginCallback;
                if (as_EndCallback != null) comboBoxProperties.ClientSideEvents.EndCallback = as_EndCallback;
                if (ab_IsRequired)
                {
                    comboBoxProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                    comboBoxProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    comboBoxProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    //if (!string.IsNullOrWhiteSpace(as_SelectChangedEvent))
                    //{
                    //    comboBoxProperties.ClientSideEvents.SelectedIndexChanged = as_SelectChangedEvent;
                    //}
                }
                if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                {
                    comboBoxProperties.ValidationSettings.EnableCustomValidation = true;
                    comboBoxProperties.ClientSideEvents.Validation = as_ValidationEvent;

                }
                if (!string.IsNullOrWhiteSpace(as_SelectChangedEvent))
                {
                    comboBoxProperties.ClientSideEvents.SelectedIndexChanged = as_SelectChangedEvent;
                }
                comboBoxProperties.EnableSynchronization = DefaultBoolean.True;
            });
            return column;
        }
        public MVCxGridViewColumn AddBandHyperlinkColumn(string as_FieldName, string as_Caption, string as_urlFormatString, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null)
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);

            column.ColumnType = MVCxGridViewColumnType.HyperLink;
            column.EditorProperties().HyperLink(hyperLinkProperties =>
            {
                hyperLinkProperties.NavigateUrlFormatString = HttpUtility.UrlDecode(as_urlFormatString);
                hyperLinkProperties.TextField = as_FieldName;
                hyperLinkProperties.Target = "_blank";
            });
            return column;
        }
        public MVCxGridViewColumn AddBandMapHyperlinkColumn(HtmlHelper helper, string as_FieldName, string as_Caption, string as_urlFormatString, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = null, bool ab_IsRequired = false, string as_ValidationEvent = null, string as_LatFieldName = "", string as_LngFieldName = "")
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired, as_DisplayFormatString: as_DisplayFormatString);
            column.ColumnType = MVCxGridViewColumnType.HyperLink;
            column.SetDataItemTemplateContent(container =>
            {
                if (container.VisibleIndex >= 0)
                {
                    helper.DevExpress().HyperLink(hyperLinkProperties =>
                    {
                        var ls_KeyValue = container.KeyValue;
                        if (DataBinder.Eval(container.DataItem, as_FieldName) != DBNull.Value && DataBinder.Eval(container.DataItem, as_FieldName).ToString() != "")
                            if (as_DisplayFormatString == Utils.GetFormatString.DateTimeDisplay)
                                hyperLinkProperties.Properties.Text = Convert.ToDateTime(DataBinder.Eval(container.DataItem, as_FieldName).ToString()).ToString(Utils.GetFormatString.DateTimeDisplay);
                            else
                                hyperLinkProperties.Properties.Text = DataBinder.Eval(container.DataItem, as_FieldName).ToString();
                        hyperLinkProperties.Name = "lnk_" + as_FieldName + ls_KeyValue + Utils.GenerateRandom(4);
                        hyperLinkProperties.Properties.NavigateUrlFormatString = HttpUtility.UrlDecode(String.Format(as_urlFormatString, DataBinder.Eval(container.DataItem, as_LatFieldName), DataBinder.Eval(container.DataItem, as_LngFieldName)));
                        hyperLinkProperties.Properties.TextField = as_FieldName;
                        hyperLinkProperties.Properties.ClientSideEvents.Click = "function(s,e){window.open('" + hyperLinkProperties.Properties.NavigateUrlFormatString + "', '_blank')}";
                        hyperLinkProperties.Properties.Target = "_blank";
                    }).Render();
                }
                else
                {
                    if (DataBinder.Eval(container.DataItem, as_FieldName) != null)
                        helper.ViewContext.Writer.Write(DataBinder.Eval(container.DataItem, as_FieldName).ToString());
                }
            });
            return column;
        }
        public MVCxGridViewColumn AddBandMemoColumn(string as_FieldName, string as_Caption, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null)
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);

            column.ColumnType = MVCxGridViewColumnType.Memo;
            column.EditorProperties().Memo(memoProperties =>
            {
                if (ab_IsRequired)
                {
                    memoProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                    memoProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    memoProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                }
                if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                {
                    memoProperties.ValidationSettings.EnableCustomValidation = true;
                    memoProperties.ClientSideEvents.Validation = as_ValidationEvent;
                }
            });
            return column;
        }
        public MVCxGridViewColumn AddBandCheckBoxColumn(string as_FieldName, string as_Caption, object ao_ValueChecked, object ao_ValueUnchecked, Type ao_ValueType, string as_ValueCheckedString, string as_ValueUncheckedString, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null)
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);

            column.ColumnType = MVCxGridViewColumnType.CheckBox;
            var checkBoxProperties = column.PropertiesEdit as CheckBoxProperties;
            checkBoxProperties.ValueChecked = ao_ValueChecked;
            checkBoxProperties.ValueUnchecked = ao_ValueUnchecked;
            checkBoxProperties.ValueType = ao_ValueType;
            checkBoxProperties.ValueCheckedString = as_ValueCheckedString;
            checkBoxProperties.ValueUncheckedString = as_ValueUncheckedString;
            return column;
        }
        public MVCxGridViewColumn AddBandCheckBoxColumnWithinHeader(HtmlHelper helper, string as_FieldName, string as_Caption, object ao_ValueChecked, object ao_ValueUnchecked, Type ao_ValueType, string as_ValueCheckedString, string as_ValueUncheckedString, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null)
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);
            column.SetHeaderTemplateContent(c =>
            {
                helper.DevExpress().CheckBox(chkSettings =>
                {
                    chkSettings.Text = as_Caption;
                    chkSettings.Name = "chk" + this._Settings.Name + as_FieldName + "_SelectAll";
                    chkSettings.ControlStyle.Font.Underline = false;
                    chkSettings.Width = Unit.Percentage(100);
                    chkSettings.ControlStyle.HorizontalAlign = HorizontalAlign.Center;
                    chkSettings.Properties.ClientSideEvents.CheckedChanged = "function (s,e){ On" + chkSettings.Name + "(s,e);}";
                }).Render();
            });
            column.ColumnType = MVCxGridViewColumnType.CheckBox;
            var checkBoxProperties = column.PropertiesEdit as CheckBoxProperties;
            checkBoxProperties.ValueChecked = ao_ValueChecked;
            checkBoxProperties.ValueUnchecked = ao_ValueUnchecked;
            checkBoxProperties.ValueType = ao_ValueType;
            checkBoxProperties.ValueCheckedString = as_ValueCheckedString;
            checkBoxProperties.ValueUncheckedString = as_ValueUncheckedString;
            column.Settings.AllowSort = DefaultBoolean.False;

            return column;
        }
        public MVCxGridViewColumn AddBandHyperlinkDynamicClientSideColumn(string as_FieldName, string as_Caption, HtmlHelper helper, string[] aa_DataFieldName, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = null, string as_ClientSideEventName = null)
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible);
            column.SetDataItemTemplateContent(container =>
            {
                if (container.VisibleIndex < 0)
                    return;

                object[] la_DataValue = new object[aa_DataFieldName.Length];
                bool lb_Valid = true;
                string ls_ValueString = "";
                for (int i = 0; i < aa_DataFieldName.Length; i++)
                {
                    if (!string.IsNullOrWhiteSpace(aa_DataFieldName[i]))
                    {
                        la_DataValue[i] = DataBinder.Eval(container.DataItem, aa_DataFieldName[i]);

                    }
                }
                for (int i = 0; i < la_DataValue.Length; i++)
                {
                    if (la_DataValue[i] == null)
                    {
                        lb_Valid = false;
                    }
                    else
                    {
                        ls_ValueString = ls_ValueString + "'" + (la_DataValue[i] == DBNull.Value ? "" : la_DataValue[i].ToString()) + "',";


                    }
                }

                if (lb_Valid)
                {

                    if (ls_ValueString != "")
                    {

                        ls_ValueString = ls_ValueString.Substring(0, ls_ValueString.Length - 1);
                        if (ls_ValueString != "''")
                        {
                            helper.DevExpress().HyperLink(hyperlink =>
                            {
                                var ls_KeyValue = container.KeyValue;
                                hyperlink.Name = "lnk_" + as_FieldName + ls_KeyValue + Utils.GenerateRandom(4);
                                if (as_DisplayFormatString == Utils.GetFormatString.DateDisplay)
                                    hyperlink.Properties.Text = Convert.ToDateTime(DataBinder.Eval(container.DataItem, as_FieldName).ToString()).ToString(Utils.GetFormatString.DateDisplay);
                                else
                                    hyperlink.Properties.Text = DataBinder.Eval(container.DataItem, as_FieldName).ToString();
                                hyperlink.Properties.TextField = as_FieldName;
                                hyperlink.Properties.ClientSideEvents.Click = "function (s,e){ " + as_ClientSideEventName + "(" + ls_ValueString + ");}";
                                hyperlink.Properties.Target = "_blank";
                            }).Render();
                        }
                        else
                        {
                            helper.ViewContext.Writer.Write("");
                        }
                    }
                }
                else
                {
                    if (DataBinder.Eval(container.DataItem, as_FieldName) != null)
                        helper.ViewContext.Writer.Write(DataBinder.Eval(container.DataItem, as_FieldName).ToString());

                }


            });

            return column;
        }
        public MVCxGridViewColumn AddBandNumberColumn(HtmlHelper helper, string as_FieldName, string as_Caption, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, string as_DisplayFormatString = "", SpinEditNumberType ao_NumberType = SpinEditNumberType.Float, float? afl_MinValue = null, float? afl_MaxValue = null, bool ab_IsRequired = false, string as_ValidationEvent = null, DevExpress.Data.SummaryItemType ao_SummaryType = DevExpress.Data.SummaryItemType.None, bool ab_IsRealTimeCalTotalSum = false)
        {
            MVCxGridViewColumn column = new MVCxGridViewColumn();
            this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, as_DisplayFormatString, ab_IsRequired: ab_IsRequired);

            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
            column.CellStyle.HorizontalAlign = HorizontalAlign.Right;
            column.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
            column.EditorProperties().SpinEdit(spinEditProperties =>
            {
                spinEditProperties.NumberFormat = SpinEditNumberFormat.Custom;
                spinEditProperties.DisplayFormatString = as_DisplayFormatString;
                spinEditProperties.DisplayFormatInEditMode = true;
                spinEditProperties.NumberType = ao_NumberType;

                    //spinEditProperties.AllowNull = false;
                    spinEditProperties.SpinButtons.Visible = false;
                spinEditProperties.SpinButtons.ShowLargeIncrementButtons = false;
                spinEditProperties.SpinButtons.ShowIncrementButtons = false;
                spinEditProperties.Increment = 0;
                spinEditProperties.AllowMouseWheel = false;
                if (afl_MinValue != null) spinEditProperties.MinValue = (decimal)afl_MinValue;
                if (afl_MaxValue != null) spinEditProperties.MaxValue = (decimal)afl_MaxValue;
                if (ab_IsRequired)
                {
                    spinEditProperties.ValidationSettings.RequiredField.IsRequired = ab_IsRequired;
                    spinEditProperties.ValidationSettings.RequiredField.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                    spinEditProperties.ValidationSettings.ErrorText = Utils.GetMessage("1001", "[" + Utils.GenerateJson("1", Utils.GetTranslation(as_Caption), "String") + Utils.GenerateJson("2", " ", "String").Remove(Utils.GenerateJson("2", " ", "String").Length - 1) + "]");
                }
                if (!string.IsNullOrWhiteSpace(as_ValidationEvent))
                {
                    spinEditProperties.ValidationSettings.EnableCustomValidation = true;
                    spinEditProperties.ClientSideEvents.Validation = as_ValidationEvent;
                }
            });
            if (ab_IsRealTimeCalTotalSum)
            {
                ASPxSummaryItem summaryItem = new ASPxSummaryItem(column.FieldName, DevExpress.Data.SummaryItemType.Sum);
                summaryItem.Tag = "SummaryItem_Sum_" + column.FieldName;
                this._Settings.TotalSummary.Add(summaryItem);
                column.SetFooterTemplateContent(c =>
                {

                    helper.DevExpress().Label(lbSettings =>
                    {
                        string fieldName = (c.Column as GridViewDataColumn).FieldName;
                            //c.data
                            lbSettings.Name = "lbl_Sum_" + fieldName;
                        lbSettings.Properties.EnableClientSideAPI = true;
                        ASPxSummaryItem summaryItem1 = c.Grid.TotalSummary.First(i => i.Tag == ("SummaryItem_Sum_" + fieldName));
                        lbSettings.Text = string.Format("{0:" + as_DisplayFormatString + "}", (c.Grid.GetTotalSummaryValue(summaryItem1) ?? 0));

                    }).Render();
                });
            }
            this._Settings.TotalSummary.Add(ao_SummaryType, as_FieldName).DisplayFormat = as_DisplayFormatString;
            return column;
        }
        
        #endregion
    }
}

  

posted @ 2020-03-06 15:41  Jack He  阅读(625)  评论(0编辑  收藏  举报