public void BuildGrid()
        {
            this.Grid.ID = this.ID + "_Grid";

            // Create the grid headline by the given fields as language labels.
            GridHeadline gridHeadline = new GridHeadline(this.Grid);

            int i = 0;

            // Run through all grid field names in the sorting.
            foreach (string fieldName in this.GridFieldsSorting)
            {
                if (this.GridFields.ContainsKey(fieldName))
                {
                    GridHeadlineItemWidth fieldWidth = this.GridFields[fieldName];

                    // Create a new headline item.
                    GridHeadlineItem headlineItem = new GridHeadlineItem(
                        gridHeadline,
                        i++,
                        fieldName,
                        fieldWidth,
                        true
                        );

                    // Add the headline item to the grid headline.
                    gridHeadline.Items.Add(headlineItem);
                }
                else if (this.AdditionalFields.Find(x => x.Name == fieldName) != null)
                {
                    AdditionalField <T> field = this.AdditionalFields.Find(x => x.Name == fieldName);

                    if (!field.ShowInGrid)
                    {
                        continue;
                    }

                    gridHeadline.Items.Add(new GridHeadlineItem(
                                               gridHeadline,
                                               i++,
                                               field.Name,
                                               field.Width,
                                               true
                                               ));
                }
            }

            // Set the grids headline.
            this.Grid.GridHeadline = gridHeadline;

            // Run through all items.
            foreach (BaseItem <T> item in this.Items)
            {
                // Create a new grid row for the item.
                GridRow row = new GridRow(this.Grid, item.Id);

                // Run through all grid field names in the sorting.
                foreach (string fieldName in this.GridFieldsSorting)
                {
                    if (this.GridFields.ContainsKey(fieldName))
                    {
                        // Get the items value of the field.
                        object value = item.GetValue(fieldName);

                        // Add the formated value as grid row item to the row.
                        row.Items.Add(new GridRowItem(row, Format(value)));
                    }
                    else if (this.AdditionalFields.Find(x => x.Name == fieldName) != null)
                    {
                        AdditionalField <T> field = this.AdditionalFields.Find(x => x.Name == fieldName);

                        if (!field.ShowInGrid)
                        {
                            continue;
                        }

                        // Get the items value of the field.
                        object value = field.GetValue.Invoke(item);

                        // Create a new row item with the formated value.
                        GridRowItem rowItem = new GridRowItem(row, Format(value));

                        // Add the row item to the grid row.
                        row.Items.Add(rowItem);

                        // Check if a background is set for this row.
                        if (this.GridRowBackgrounds.ContainsKey(item.Id + field.Name))
                        {
                            // Set the row's background color.
                            //row.Style.Add("background", this.GridRowBackgrounds[item.Id]);
                            rowItem.Style.Add("background", this.GridRowBackgrounds[item.Id + field.Name]);
                            rowItem.Style.Add("color", "#000000");
                        }
                    }
                }

                // Add the row to the grid's rows.
                this.Grid.Rows.Add(row);
            }
        }
        private void CreateGridNews()
        {
            try
            {
                gridNews = new Grid {
                    ID = "gridNews"
                };

                GridHeadline headline = new GridHeadline(gridNews);
                headline.Items.Add(new GridHeadlineItem(headline, 0, "news heading", new GridHeadlineItemWidth(20)));
                headline.Items.Add(new GridHeadlineItem(headline, 1, "news description", new GridHeadlineItemWidth(60)));
                headline.Items.Add(new GridHeadlineItem(headline, 2, "created user", new GridHeadlineItemWidth(10)));
                headline.Items.Add(new GridHeadlineItem(headline, 3, "created date", new GridHeadlineItemWidth(10)));
                gridNews.GridHeadline = headline;

                NewsManager newsManager = new NewsManager();
                // Get the Clients XML file
                //string fileName = Path.Combine(Request.PhysicalApplicationPath, "App_Data", "News", "News.xml");
                string fileName = Path.Combine(Request.PhysicalApplicationPath, "Fileadmin", "News", Global.Core.ClientName + ".xml");
                newsManager.FileName = fileName;

                XmlNodeList xmlNewsList = newsManager.GetNewsAll(Global.Core.ClientName);

                if (xmlNewsList != null)
                {
                    foreach (XmlNode xn in xmlNewsList)
                    {
                        var xmlElement = xn;
                        if (xmlElement != null)
                        {
                            GridRow row = new GridRow(gridNews, xmlElement.Attributes["Id"].Value);

                            GridRowItem itemHeading = new GridRowItem(row, xmlElement.Attributes["Heading"].Value);
                            itemHeading.Width = 20;
                            GridRowItem itemDesc = new GridRowItem(row, xmlElement.Attributes["Description"].Value);
                            itemDesc.Width    = 40;
                            itemDesc.CssClass = "gridWrap";
                            string name = "";
                            if (xmlElement.Attributes["UserId"] != null)
                            {
                                User user = null;
                                user = Global.Core.Users.GetSingle(Guid.Parse(xmlElement.Attributes["UserId"].Value.Trim()));
                                if (user != null)
                                {
                                    name = user.FirstName + "&nbsp;" + user.LastName;
                                }
                            }
                            GridRowItem itemUser = new GridRowItem(row, name);
                            itemUser.Width = 20;

                            GridRowItem itemMc = xmlElement.Attributes["CreatedDate"] != null ? new GridRowItem(row, Convert.ToDateTime(xmlElement.Attributes["CreatedDate"].Value).ToString("MM-dd-yyyy")) : new GridRowItem(row, "");
                            itemMc.Width = 20;
                            row.Items.Add(itemHeading);
                            row.Items.Add(itemDesc);
                            row.Items.Add(itemUser);
                            row.Items.Add(itemMc);
                            gridNews.Rows.Add(row);
                        }
                    }
                }

                pnlnewsManagement.Controls.Add(gridNews);

                if (HttpContext.Current.Session["newsId"] != null)
                {
                    gridNews.SelectedItem = HttpContext.Current.Session["newsId"].ToString();
                }
                if (gridNews.SelectedItem == null || gridNews.SelectedItem.ToString() != string.Empty)
                {
                    if (gridNews.Rows.Count != 0)
                    {
                        gridNews.SelectedItem = gridNews.Rows[0].Identity;
                    }
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Session["Error"] = ex.Message;
                Response.Redirect("/Pages/ErrorPage.aspx");
            }
        }
示例#3
0
        private void GetUsers()
        {
            try
            {
                gridUsers = new Grid {
                    ID = "gridUsers"
                };

                var headline = new GridHeadline(gridUsers);

                headline.Items.Add(new GridHeadlineItem(headline, 0, "user name", new GridHeadlineItemWidth(20)));
                headline.Items.Add(new GridHeadlineItem(headline, 1, "email id", new GridHeadlineItemWidth(20)));
                headline.Items.Add(new GridHeadlineItem(headline, 2, "client", new GridHeadlineItemWidth(20)));
                headline.Items.Add(new GridHeadlineItem(headline, 3, "date", new GridHeadlineItemWidth(20)));
                headline.Items.Add(new GridHeadlineItem(headline, 4, "roles", new GridHeadlineItemWidth(10)));
                headline.Items.Add(new GridHeadlineItem(headline, 5, "browser", new GridHeadlineItemWidth(10)));


                gridUsers.GridHeadline = headline;

                ApplicationUtilities.UsageLogger logger = new ApplicationUtilities.UsageLogger(
                    Global.Core.ClientName,
                    Global.User
                    );
                //object[] user = logger.SelectSingle("SELECT Id FROM Variables WHERE Name={0}", "Users");
                //object[] email = logger.SelectSingle("SELECT Id FROM Variables WHERE Name={0}", "EmailId");
                //object[] login = logger.SelectSingle("SELECT Id FROM Variables WHERE Name={0}", "Login");
                //object[] client = logger.SelectSingle("SELECT Id FROM Variables WHERE Name={0}", "Clients");
                //object[] roles = logger.SelectSingle("SELECT Id FROM Variables WHERE Name={0}", "Roles");
                //object[] browsers = logger.SelectSingle("SELECT Id FROM Variables WHERE Name={0}", "Browser");
                List <object[]> respondent;
                if (ConfigurationManager.AppSettings["AdminPortal"] != null)
                {
                    if (Global.Core.ClientName.ToLower() == ConfigurationManager.AppSettings["AdminPortal"])
                    {
                        respondent = logger.ExecuteReader(string.Format(
                                                              @"SELECT  [Id] ,[UserName],[EmailId],[Client],CONVERT(varchar,[Login],103)+' '+CONVERT(char(8),[Login],108) AS [Date],[Role],[Browser] FROM UsageLog ORDER BY [Date]"));
                    }
                    else
                    {
                        respondent = logger.ExecuteReader(string.Format(
                                                              @"SELECT  [Id] ,[UserName],[EmailId],[Client],CONVERT(varchar,[Login],103)+' '+CONVERT(char(8),[Login],108) AS [Date],[Role],[Browser] FROM UsageLog WHERE [Client]='{0}' ORDER BY [Date] ", Global.Core.ClientName));
                    }
                }
                else
                {
                    respondent = logger.ExecuteReader(string.Format(
                                                          @"SELECT  [Id] ,[UserName],[EmailId],[Client],CONVERT(varchar,[Login],103)+' '+CONVERT(char(8),[Login],108) AS [Date],[Role],[Browser] FROM UsageLog WHERE [Client]='{0}' ORDER BY [Date] ", Global.Core.ClientName));
                }
                if (respondent != null)
                {
                    foreach (var useritem in respondent)
                    {
                        var row        = new GridRow(gridUsers, useritem[0]);
                        var name       = new GridRowItem(row, useritem[1].ToString());
                        var emailid    = new GridRowItem(row, useritem[2].ToString());
                        var clientname = new GridRowItem(row, useritem[3].ToString());
                        var date       = new GridRowItem(row, useritem[4].ToString());
                        var role       = new GridRowItem(row, useritem[5].ToString());
                        var browser    = new GridRowItem(row, useritem[6].ToString());

                        row.Items.Add(name);
                        row.Items.Add(emailid);
                        row.Items.Add(clientname);
                        row.Items.Add(date);
                        row.Items.Add(role);
                        row.Items.Add(browser);
                        gridUsers.Rows.Add(row);
                    }
                    pnlUserManagement.Controls.Add(gridUsers);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Session["Error"] = ex.Message;
                Response.Redirect("/Pages/ErrorPage.aspx");
            }
        }
        private void CreateGridUsers()
        {
            try
            {
                gridUsers = new Grid {
                    ID = "gridUsers"
                };

                var headline = new GridHeadline(gridUsers);
                headline.Items.Add(new GridHeadlineItem(headline, 0, "name", new GridHeadlineItemWidth(15)));
                headline.Items.Add(new GridHeadlineItem(headline, 1, "first name", new GridHeadlineItemWidth(20)));
                headline.Items.Add(new GridHeadlineItem(headline, 2, "last name", new GridHeadlineItemWidth(20)));
                headline.Items.Add(new GridHeadlineItem(headline, 3, "email", new GridHeadlineItemWidth(20)));
                headline.Items.Add(new GridHeadlineItem(headline, 4, "phone", new GridHeadlineItemWidth(15)));
                headline.Items.Add(new GridHeadlineItem(headline, 5, "user group", new GridHeadlineItemWidth(10)));
                gridUsers.GridHeadline = headline;

                var users = Global.Core.Users.Get();

                if (users != null)
                {
                    foreach (var useritem in users)
                    {
                        var userRole = Global.Core.UserRoles.GetSingle("IdUser", useritem.Id);
                        var role     = Global.Core.Roles.GetSingle("Id", userRole.IdRole);

                        object idRoleUser = Global.Core.UserRoles.GetValue("IdRole", "IdUser", Global.IdUser.Value);

                        if (idRoleUser == null)
                        {
                            idRoleUser = new Guid();
                        }

                        if (role.Hidden && (Guid)idRoleUser != role.Id)
                        {
                            continue;
                        }

                        var row   = new GridRow(gridUsers, useritem.Id);
                        var name  = new GridRowItem(row, useritem.Name);
                        var fName = new GridRowItem(row, useritem.FirstName);
                        var lName = new GridRowItem(row, useritem.LastName);
                        var eMail = new GridRowItem(row, useritem.Mail);
                        var phone = new GridRowItem(row, useritem.Phone);
                        row.Items.Add(name);
                        row.Items.Add(fName);
                        row.Items.Add(lName);
                        row.Items.Add(eMail);
                        row.Items.Add(phone);

                        if (userRole != null)
                        {
                            var itemrole = new GridRowItem(row, role.Name);
                            row.Items.Add(itemrole);
                        }
                        else
                        {
                            var itemrole = new GridRowItem(row, "not assigned");
                            row.Items.Add(itemrole);
                        }

                        gridUsers.Rows.Add(row);
                    }
                    pnlUserManagement.Controls.Add(gridUsers);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Session["Error"] = ex.Message;
                Response.Redirect("/Pages/ErrorPage.aspx");
            }
        }