Ejemplo n.º 1
0
        private void BindColumns(DataTable dt, string tableName, string primaryKeyId, bool hideData, bool isTesting, string[] validColumns, string userPreferenceCategory)
        {
            gridFormatdt = GetGridFormatSettings();

            // boolean values set for the fields and procedures in the GridView
            var procedureHide = hideData;
            var fieldHide     = false;

            // Create a string array for DataNavigationUrlFields
            var str = new string[2];

            str[0] = primaryKeyId;
            str[1] = dt.Columns[0].ColumnName;

            // Create rest of columns based on what user has access to ...
            var key         = "Default";
            var disableLink = hideData;

            var idColumn = new DataColumn(str[0]);

            if (idColumn != null)
            {
                for (var i = 0; i < validColumns.Length; i++)
                {
                    if (validColumns[i].Equals(idColumn.ColumnName))
                    {
                        if (!string.IsNullOrEmpty(GroupByField) || idColumn.ColumnName != GroupByField)
                        {
                            // dynamically add hyperlink fields from the data table
                            SetHyperLink(idColumn, str, tableName, disableLink);
                        }
                    }
                }
            }

            foreach (DataRow row in gridFormatdt.Rows)
            {
                //Considering all the columns have their width fixed from the Database
                totalGridColumnWidth += Double.Parse(row[FieldConfiguration.DataColumns.Width].ToString());
            }

            foreach (var t in validColumns)
            {
                // get the column from the data table
                if (!t.Equals(idColumn.ColumnName))
                {
                    var dataColumn = dt.Columns[t];
                    //var i = 0;
                    //str[0] = t;
                    //str[1] = t;
                    if (dataColumn != null)
                    {
                        if (string.IsNullOrEmpty(GroupByField) || dataColumn.ColumnName != GroupByField)
                        {
                            //if (dataColumn.ColumnName.ToLower() != idColumn.ColumnName.ToLower())
                            // dynamically add hyperlink fields from the data table
                            SetHyperLink(dataColumn, str, tableName, disableLink);
                        }
                    }
                }
            }

            if (SessionVariables.ApplicationUserRoles == null)
            {
                ApplicationCommon.SetApplicationUserRoles();
            }

            var roles = SessionVariables.ApplicationUserRoles;
            var role  = roles.Find(item => item.ApplicationRole == "System Coordinator");

            if (role != null)
            {
                disabledelete = false;
            }
            else
            {
                disabledelete = true;
            }

            // based on another bool parameters indicating if action buttons should show
            // add action button / links
            if (IsUpdateColumn)
            {
                var userDetailVisibility = ApplicationCommon.GetUserPreferenceByKeyAsBoolean(ApplicationCommon.GridDetailLinkVisibleKey, userPreferenceCategory);

                if (userDetailVisibility)
                {
                    var userAction = ApplicationCommon.GetUserPreferenceByKey(ApplicationCommon.GridDefaultClickActionKey);
                    //var userAction = ApplicationCommon.GetDefaultActionLink();
                    if (userAction == "update")
                    {
                        ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_DETAIL, tableName, procedureHide);
                    }
                    else
                    {
                        ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_UPDATE, tableName, procedureHide);
                    }
                }
            }

            if (IsDeleteColumn)
            {
                var userDeleteVisibility = ApplicationCommon.GetUserPreferenceByKeyAsBoolean(ApplicationCommon.GridDeleteLinkVisibleKey, userPreferenceCategory);
                if (userDeleteVisibility)
                {
                    ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_DELETE, tableName, procedureHide);
                }
            }
        }
Ejemplo n.º 2
0
        // reName to better
        private void SetHyperLink(DataColumn dataColumn, string[] str, string entity, bool enableLInk)
        {
            var hypField       = new HyperLinkField();
            var flagGridFormat = false;

            var totalColumnWidth = 0;
            var headerWidth      = "100%";
            var headerAlignment  = "Center";
            var headerTextValue  = "";
            var columnsExists    = false;
            //ConsoleColor headerColor	;

            //var imgArrowDown = Application["Branding"] + "/Images/arrow-down.jpg";
            //var imgArrowUp = Application["Branding"] + "/Images/arrow-up.jpg";
            var split = " ";

            if (dataColumn.ColumnName == "ApplicationId" && entity != "Application")
            {
                hypField.Visible = false;
            }

            //bool flagContainsDescriptionColumn = false;

            //no need to call on each dataColumn
            //var gridFormatdt = GetGridFormatSettings();

            foreach (DataRow row in gridFormatdt.Rows)
            {
                var headerTextName = row[FieldConfiguration.DataColumns.Name].ToString();

                headerTextValue = row[FieldConfiguration.DataColumns.Value].ToString();

                if (dataColumn.ColumnName == headerTextName)
                {
                    //Set the remaining width of the column to Description, Set 100 as width for Checkbox column
                    if (headerTextName == "Description" && (1000 - (totalGridColumnWidth + 100)) > 0)
                    {
                        headerWidth = (1000 - (totalGridColumnWidth + 100)).ToString();
                    }
                    else
                    {
                        headerWidth = row[FieldConfiguration.DataColumns.Width].ToString();
                    }

                    headerAlignment = row[FieldConfiguration.DataColumns.HorizontalAlignment].
                                      ToString();

                    //headerColor		= row[Framework.Components.UserPreference.FieldConfiguration.DataColumns.Formatting].
                    //ToString();

                    flagGridFormat = true;

                    //totalColumnWidth += int.Parse(headerWidth);
                    break;
                }
            }

            if (dataColumn.ColumnName.Contains("Name"))
            {
                split = dataColumn.ColumnName.Replace("Name", " Name");
                hypField.HeaderText = split;
            }
            else if (dataColumn.ColumnName.Contains("Id"))
            {
                split = dataColumn.ColumnName.Replace("Id", " Id");
                hypField.HeaderText = split;
                //flagGridFormat = true;
            }
            else
            {
                hypField.HeaderText = dataColumn.ColumnName;
                //hypField.HeaderStyle.ForeColor =
            }


            //if (flagGridFormat)
            //{
            if (!headerWidth.Contains('-'))
            {
                hypField.HeaderStyle.Width = Unit.Parse(headerWidth);
            }
            else
            {
                hypField.HeaderStyle.Width = '*';
            }

            //hypField.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
            hypField.ItemStyle.HorizontalAlign = ListHelperAlignment.GetHeaderAlignment(headerAlignment);
            //hypField.HeaderStyle.BackColor = System.Drawing.Color.Black;

            if (!string.IsNullOrEmpty(headerTextValue))
            {
                hypField.HeaderText = headerTextValue;
            }
            hypField.HeaderStyle.BorderColor = System.Drawing.Color.Black;
            hypField.HeaderStyle.BorderWidth = 1;
            //hypField.ItemStyle.HorizontalAlign = GetHeaderAlignment(headerAlignment);
            hypField.DataTextField = dataColumn.ColumnName;

            if (!enableLInk)
            {
                hypField.SortExpression = dataColumn.ColumnName;
                //hypField.HeaderText += "<img src='"+imgArrowDown+"' alt='' />";
                hypField.DataNavigateUrlFields = str;

                var userClickAction = string.Empty;
                userClickAction = ApplicationCommon.GetUserPreferenceByKey(ApplicationCommon.GridDefaultClickActionKey);
                userClickAction = userClickAction.ToLower();
                var actionPage = string.Empty;

                if (userClickAction == "detail")
                {
                    actionPage = "Details";
                }
                else if (userClickAction == "update")
                {
                    actionPage = "Update";
                }
                else if (userClickAction == "inlineupdate")
                {
                    actionPage = "Update";
                }
                else
                {
                    actionPage = "Details";
                }

                var userMode = string.Empty;

                if (!string.IsNullOrEmpty(Request.QueryString["user"]))
                {
                    userMode = "&user="******"user"];
                }

                hypField.DataNavigateUrlFormatString = Page.GetRouteUrl(entity + "EntityRoute", new { Action = actionPage }) + "/{0}" + userMode;
            }

            foreach (DataControlField column in MainGridView.Columns)
            {
                var headertext = column.HeaderText;

                if (headertext.EndsWith("&nbsp; &uarr;"))
                {
                    headertext = headertext.Replace("&nbsp; &uarr;", "");
                }
                else if (headertext.EndsWith("&nbsp; &darr;"))
                {
                    headertext = headertext.Replace("&nbsp; &darr;", "");
                }

                if (headertext.Equals(hypField.HeaderText))
                {
                    columnsExists = true;
                    break;
                }
            }

            if (!columnsExists)
            {
                MainGridView.Columns.Add(hypField);
            }
        }
Ejemplo n.º 3
0
        private void BindColumns(DataTable dt, string tableName, string primaryKeyId, bool hideData, bool isTesting)
        {
            gridFormatdt = GetGridFormatSettings();

            // if (IsPostBack) return;

            // Create Column 0 --> PrimaryKey

            // Declare the bound field and allocate memory for the bound field.
            // Initalize the DataField value.
            //var bfield = new BoundField { DataField = primaryKeyId };
            //bfield.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            //bfield.HeaderText = dt.Columns[0].ColumnName.Replace("Id", " Id");
            //bfield.Visible = isTesting;
            //// ConvertStringArrayToString(dt.Columns[0].ColumnName.Split(new char[] { 'I' }, 1));
            //// Add the newly created bound field to the GridView.
            //if(!dt.Columns[0].ColumnName.Equals("PersonId"))
            //MainGridView.Columns.Add(bfield);

            // boolean values set for the fields and procedures in the GridView
            var procedureHide = hideData;
            var fieldHide     = false;

            // Create a string array for DataNavigationUrlFields
            var str = new string[2];

            str[0] = primaryKeyId;
            str[1] = dt.Columns[0].ColumnName;

            // Create rest of columns based on what user has access to ...
            var key          = "Default";
            var disableLink  = hideData;
            var validColumns = _getColumnDelegate();

            //if (!string.IsNullOrEmpty(GroupByField) && validColumns.Contains(GroupByField))
            //{
            //    //validColumns.d
            //}

            var idColumn = new DataColumn(str[0]);

            if (idColumn != null)
            {
                for (var i = 0; i < validColumns.Length; i++)
                {
                    if (validColumns[i].Equals(idColumn.ColumnName))
                    {
                        if (!string.IsNullOrEmpty(GroupByField) || idColumn.ColumnName != GroupByField)
                        {
                            // dynamically add hyperlink fields from the data table
                            SetHyperLink(idColumn, str, tableName, disableLink);
                        }
                    }
                }
            }

            foreach (DataRow row in gridFormatdt.Rows)
            {
                //Considering all the columns have their width fixed from the Database
                totalGridColumnWidth += Double.Parse(row[FieldConfiguration.DataColumns.Width].ToString());
            }

            foreach (var t in validColumns)
            {
                // get the column from the data table
                if (!t.Equals(idColumn.ColumnName))
                {
                    var dataColumn = dt.Columns[t];
                    //var i = 0;
                    //str[0] = t;
                    //str[1] = t;
                    if (dataColumn != null)
                    {
                        if (string.IsNullOrEmpty(GroupByField) || dataColumn.ColumnName != GroupByField)
                        {
                            //if (dataColumn.ColumnName.ToLower() != idColumn.ColumnName.ToLower())
                            // dynamically add hyperlink fields from the data table
                            SetHyperLink(dataColumn, str, tableName, disableLink);
                        }
                    }
                }
            }

            if (SessionVariables.ApplicationUserRoles == null)
            {
                ApplicationCommon.SetApplicationUserRoles();
            }

            var roles = SessionVariables.ApplicationUserRoles;
            var role  = roles.Find(item => item.ApplicationRole == "System Coordinator");

            if (role != null)
            {
                disabledelete = false;
            }
            else
            {
                disabledelete = true;
            }

            // based on another bool parameters indicating if action buttons should show
            // add action button / links

            if (IsUpdateColumn)
            {
                var userDetailVisibility = ApplicationCommon.GetUserPreferenceByKeyAsBoolean(ApplicationCommon.GridDetailLinkVisibleKey, this.UserPreferenceCategory);

                if (userDetailVisibility)
                {
                    var userAction = ApplicationCommon.GetUserPreferenceByKey(ApplicationCommon.GridDefaultClickActionKey);
                    //var userAction = ApplicationCommon.GetDefaultActionLink();
                    if (userAction == "update")
                    {
                        ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_DETAIL, tableName, procedureHide);
                    }
                    else
                    {
                        ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_UPDATE, tableName, procedureHide);
                    }
                }
            }

            if (IsDeleteColumn)
            {
                var userDeleteVisibility = ApplicationCommon.GetUserPreferenceByKeyAsBoolean(ApplicationCommon.GridDeleteLinkVisibleKey, this.UserPreferenceCategory);
                if (userDeleteVisibility)
                {
                    ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_DELETE, tableName, procedureHide);
                }
            }
        }