
public partial class CustomFeedUserControl : UserControl { private const string ActivityName = "ActivityName"; private const string SiteName = "SiteName"; private const string Date = "Date"; private const string ActivitySummary = "ActivitySummary"; private DataTable sitedetailstable; private ActivityManager activityManager; private ActivityEventsCollection activityEvents; private Boolean error = false; private string errorText = ""; SyndicationItem syndicationItem; List<String> categories = new List<string>(); SPWebApplication webapp = SPContext.Current.Site.WebApplication; private String Email = ""; protected void Page_Load(object sender, EventArgs e) { //if (!Page.IsPostBack) Nothing here as i am creating the grid ondemand //{ // LoadData(); // RadGridSiteDetails.Visible = false; //} } void LoadData() { RadGridSiteDetails.DataSource = Sitedetailstable.DefaultView; } public void LoadDatasource(String userloginname) { string siteUrl = SPContext.Current.Site.Url; SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite site = new SPSite(siteUrl)) { try { SPServiceContext context = SPServiceContext.GetContext(site); UserProfileManager userProfileManager = new UserProfileManager(context); UserProfile profile = userProfileManager.GetUserProfile(userloginname); if (profile != null) { test.Text = profile.DisplayName; this.activityManager = new ActivityManager(profile); this.activityEvents = this.activityManager.GetActivitiesByUser(profile); } } catch (UserNotFoundException ex) { this.error = true; this.errorText = ex.Message; } catch (NullReferenceException ex) { this.error = true; this.errorText = ex.Message; } } }); } private DataTable ReturnUserDatadetails( ) { sitedetailstable = new DataTable(); string sitetitle = null; string summary; sitedetailstable.Columns.Add(ActivityName, System.Type.GetType("System.String")); sitedetailstable.Columns.Add(SiteName, System.Type.GetType("System.String")); sitedetailstable.Columns.Add(Date, System.Type.GetType("System.String")); sitedetailstable.Columns.Add(ActivitySummary, System.Type.GetType("System.String")); if (this.activityEvents.Count > 0) { foreach (ActivityEvent activityEvent in this.activityEvents) { syndicationItem = activityEvent.CreateSyndicationItem(this.activityManager.ActivityTypes, ContentType.Html); Sitetitle = syndicationItem.Summary.Text.ToString(); summary = Regex.Replace(syndicationItem.Summary.Text; if ((Sitetitle != null) && (Sitetitle != "")) { DataRow newrow = Sitedetailstable.NewRow(); newrow[ActivityName] = activityEvent.Name; newrow[SiteName] = Sitetitle; newrow[Date] = activityEvent.PublishDate.HasValue ? activityEvent.PublishDate.Value.ToLocalTime().ToString("dd MMM yyyy hh:mm tt") : string.Empty; newrow[ActivitySummary] = summary.Substring(summary.IndexOf(":") + 1); categories.Add(activityEvent.Name.ToString()); Sitedetailstable.Rows.Add(newrow); } } } return Sitedetailstable; } protected void RadGridSiteDetails_SortCommand(object sender, Telerik.Web.UI.GridSortCommandEventArgs e) { LoadData(); } // this is the button event that gets clicked from the user to generate reporty protected void UserReport_Click(object sender, EventArgs e) { Email = UserEmailInput.Text; SPPrincipalInfo user = SPUtility.ResolvePrincipal(webapp, null, Email, SPPrincipalType.User, SPPrincipalSource.All, true); if (user != null) { LoadDatasource(user.LoginName); LoadData(); RadGridSiteDetails.Visible = true; } else { test.Text = "No user Found with that Email Address"; } } protected void RadGridSiteDetails_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { LoadData(); } }using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Web.UI;using System.Data; namespace Project1{ public partial class frmUserGroupPrivillage : System.Web.UI.Page { private DataTable table; private bool displayNullDataSourceErrorMessage = false; // enable error message to // be hidden the first time the page is loaded private string groupID, groupName; protected void Page_Load(object sender, EventArgs e) { // reset error and status messages' visibility errorMessage.Visible = false; statusMessage.Visible = false; //get module authorization for the logged in user Authorization a = new Authorization(); bool[] authorization = a.GetModuleAuthorization(userID, "UserGroupPrivilege"); if (authorization != null) { // is the user is allowed to view this page? if (authorization[0]) { //the user is allowed to view this page DisplayUserContent(authorization); } else { // the user is not allowed to view this page. //Hence redirect user to main page Response.Redirect("Default.aspx"); } } else { //unable to get authorization information errorMessage.Text = a.authorizationErrorMessage; errorMessage.Visible = true; } } //Post: display or not display add, edit and delete buttons based on user's // privilege level private void DisplayUserContent(bool[] authorization) { // should update button inside edit form to be be displayed? if (authorization[2]) { GridColumn editColumn = RadGrid1.Columns.FindByUniqueName("EditCommandColumn"); editColumn.Visible = true; } } protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) { displayNullDataSourceErrorMessage = true; errorMessage.Visible = false; groupID = e.Value.Trim(); groupName = e.Text.Trim(); // rebind the grid if and only if the table is successfully populated if (PopulateTable(groupID, groupName)) { RadGrid1.Rebind(); // make the grid visible not that it has data to display RadGrid1.Visible = true; } } // pre: invoked by radgrid1 when when it found that there is no data source during data binding // post: returns the datasource for the grid protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { if (table != null) { RadGrid1.DataSource = table; } else { // do not display the error message when the user first viewed the module if (displayNullDataSourceErrorMessage) { // the data table is null errorMessage.Text = "Error. Unable to get grid data source from DataTable. The User Group Privilege cannot be displayed"; errorMessage.Visible = true; errorMessage.Focus(); } } } // pre: info: asuthorization information from database. // accessType: 1 to indicate view, 2 to indicate add, 3 to indicate edit, 4 to indicate delete // post: returns the boolen status for the view, add, edit, OR delete privilege private bool GetBoolStatus(string info, int accessType) { bool status = false; char[] c = info.ToCharArray(); switch (accessType) { case 1: { // caller method wants to know the View status status = (c[0] == '1'); break; } case 2: { // caller method wants to know the View status status = (c[2] == '1'); break; } case 3: { // caller method wants to know the View status status = (c[4] == '1'); break; } case 4: { // caller method wants to know the View status status = (c[6] == '1'); break; } default: { //should not get here break; } } return status; } protected void RadGrid1_EditCommand(object sender, GridCommandEventArgs e) { bool b = PopulateTable(groupID, groupName); } // post : return true if the table is successfully populated private bool PopulateTable(string userGroupID, string userGroupName) { string query = "SELECT RTRIM(user_group_id) AS user_group_id, RTRIM(user_group) AS user_group " + "WHERE user_group_id = '" + userGroupID + "'"; int recordCount = 0; db db = new db(); if (db.Load()) { // query record corresponding to the selected userID ONLY if (db.QuerySQL(query, ref recordCount) && recordCount == 1) { // create a new data table table = new DataTable(); // declare columns for table table.Columns.Add("Module Name", typeof(string)); table.Columns.Add("View", typeof(bool)); table.Columns.Add("Add", typeof(bool)); table.Columns.Add("Edit", typeof(bool)); table.Columns.Add("Delete", typeof(bool)); // get the number of columns in "records" table int tableColumnsCount = db.SqlDataSet.Tables["records"].Columns.Count; //get the selected group's privilege information DataRow tempRow = db.SqlDataSet.Tables["records"].Rows[0]; // add records to the table by iterating the tempRow DataColumn tempColumn; for (int i = 0; i < tableColumnsCount; i++) { //get the column in at position i inside table tempColumn = db.SqlDataSet.Tables["records"].Columns[i]; // get the COLUMN NAME for tempColumn DEBUG string moduleInfo = tempColumn.ColumnName.Trim(); switch (moduleInfo) { case "user_group": { // do nothing break; } case "user_group_id": { // do nothing break; } default: { // variables to hold the privilage information in bool type bool viewStatus = false; //dummy default value because the compiler refused to compile bool addStatus = false; //dummy default value because the compiler refused to compile bool editStatus = false; //dummy default value because the compiler refused to compile bool deleteStatus = false; //dummy default value because the compiler refused to compile // switch based on the COLUMN NAME for the columns with 0 is set to indicate true if (moduleInfo.Equals("reconcile") || moduleInfo.Equals("report") || moduleInfo.Equals("admin"))) { // get the value in tempRow at column position i. Set status to true if the value is "0" viewStatus = "0".Equals(tempRow[tempColumn].ToString().Trim()); } // switch based on the COLUMN NAME for the columns with 1 is set to indicate true if (moduleInfo.Equals("SpeedKey") || moduleInfo.Equals("WebReports")) { // get the value in the cell at tempRow and tempColumn. Set status to true if the value is "1" string info = tempRow[tempColumn].ToString().Trim(); viewStatus = GetBoolStatus(info, 1); addStatus = GetBoolStatus(info, 2); editStatus = GetBoolStatus(info, 3); deleteStatus = GetBoolStatus(info, 4); } //add a new row to table table.Rows.Add(moduleInfo, viewStatus, addStatus, editStatus, deleteStatus); break; } } } return true; } else { //either the connection cannot be opened or there is more than one record returned if (recordCount == 1 || recordCount == 0) { //connection could not be opened errorMessage.Text = db.LastError; errorMessage.Visible = true; errorMessage.Focus(); } else { // there is more than one record returned errorMessage.Text = "Error. There is more than one privilege information for UserGroup " + userGroupName + ". " + "Please ensure that there is only one privilege information per user group."; errorMessage.Visible = true; errorMessage.Focus(); } } return false; } else { // cannot load db errorMessage.Text = db.LastError; errorMessage.Visible = true; errorMessage.Focus(); return false; } } }}<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="frmUserGroupPrivilege.aspx.cs" Inherits="Project1.frmUserGroupPrivillage" %><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <style type="text/css"> .style1 { width: 98%; } </style></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="Title" runat="server"> User Group Privilege Management</asp:Content><asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server"> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadComboBox1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="errorMessage" /> <telerik:AjaxUpdatedControl ControlID="RadComboBox1" /> <telerik:AjaxUpdatedControl ControlID="statusMessage" /> <telerik:AjaxUpdatedControl ControlID="Label1" /> <telerik:AjaxUpdatedControl ControlID="Label2" /> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadGrid1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="errorMessage" /> <telerik:AjaxUpdatedControl ControlID="statusMessage" /> <telerik:AjaxUpdatedControl ControlID="Label1" /> <telerik:AjaxUpdatedControl ControlID="Label2" /> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager><br /> <table align="center" class="style1"> <tr> <td> <asp:Label ID="errorMessage" runat="server" Text="Error Message" Visible="False" CssClass="frmElement_ErrorText"></asp:Label> <br /> To begin, please select a user group from the combo box below:<br /> <br /> <telerik:RadComboBox ID="RadComboBox1" Runat="server" EmptyMessage="Select User Group to be viewed" Skin="Vista" DataSourceID="GroupNameDataSource" DataTextField="user_group" DataValueField="user_group_id" onselectedindexchanged="RadComboBox1_SelectedIndexChanged" AutoPostBack="True" Width="250px"> </telerik:RadComboBox><br /> <br /> <telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" GridLines="None" Skin="Vista" onneeddatasource="RadGrid1_NeedDataSource" AutoGenerateEditColumn="True" oneditcommand="RadGrid1_EditCommand" Visible="False"><MasterTableView AllowFilteringByColumn="True" AllowSorting="True" AutoGenerateColumns="True" AllowPaging="True" EditMode="InPlace"><CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings><RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"><HeaderStyle Width="20px"></HeaderStyle></RowIndicatorColumn><ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"><HeaderStyle Width="20px"></HeaderStyle></ExpandCollapseColumn> <Columns> <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="Images/Cancel.gif" EditImageUrl="Images/Edit.gif" FilterControlAltText="Filter EditCommandColumn column" InsertImageUrl="Images/Update.gif" UpdateImageUrl="Images/Update.gif" Visible="False"> <ItemStyle HorizontalAlign="Center" Width="30px" /> </telerik:GridEditCommandColumn> </Columns><EditFormSettings><EditColumn FilterControlAltText="Filter EditCommandColumn column" UniqueName="EditCommandColumn1"></EditColumn></EditFormSettings></MasterTableView><FilterMenu EnableImageSprites="False"></FilterMenu> </telerik:RadGrid> <br /> <asp:Label ID="statusMessage" runat="server" ForeColor="#006600" Text="StatusMessage" Visible="False"></asp:Label> <br /> <asp:Label ID="Label1" runat="server" Text="Label1"></asp:Label> <br /> <asp:Label ID="Label2" runat="server" Text="Label2"></asp:Label> </td> </tr> </table> <asp:SqlDataSource ID="GroupNameDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT RTRIM(user_group_id) AS user_group_id, RTRIM(user_group) AS user_groupFROM User_Group ORDER BY (user_group) "></asp:SqlDataSource><br /> </asp:Content><telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn column" HeaderText="Progress" UniqueName="StatusIndicator"> <ItemTemplate> <center> <telerik:RadLinearGauge runat="server" ID="RadLinearGauge1" Scale-Vertical="false" Scale-MajorTicks-Visible="false" Scale-Labels-Visible="false" Width="120px" Height="20px"> <Pointer Shape="BarIndicator"> <Track Opacity="0.4" /> </Pointer> <Scale Min="0" Max="100"> <Ranges> <telerik:GaugeRange Color="#c20000" From="0" To="100" /> </Ranges> </Scale> </telerik:RadLinearGauge> </center> </ItemTemplate> <HeaderStyle Width="100px" HorizontalAlign="Center" /> </telerik:GridTemplateColumn>protected void OnItemDataBound1(object sender, GridItemEventArgs e) { if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) { GridDataItem item = e.Item as GridDataItem; DataRowView currentRow = (DataRowView)item.DataItem; decimal currValue = decimal.Parse(currentRow.Row["pc"].ToString()); RadLinearGauge radialGauge1 = (RadLinearGauge)item.FindControl("RadLinearGauge1"); radialGauge1.Pointer.Value = currValue; } }<telerik:RadGrid ID="grdCaptDiaria" runat="server" AutoGenerateColumns="False"
AllowPaging="True" PageSize="10">
<HeaderStyle BorderStyle="Solid" BorderWidth="1px" Height="30px" HorizontalAlign="Center"
BorderColor="#B0B0B0" BackColor="#EBEBEB" Font-Bold="True" Font-Italic="False"
Font-Names="Arial,Helvetica,sans-serif" Font-Overline="False" Font-Size="10px"
Font-Strikeout="False" Font-Underline="False" ForeColor="#666666" Wrap="True" />
<ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" ForeColor="#999999" Wrap="True" />
<PagerStyle Mode="NumericPages" PagerTextFormat="{4}Página {0} de {1}, registros del {2} al {3} de {5}" />
<MasterTableView TableLayout="Fixed" NoMasterRecordsText="No existen Moliendas con los filtros proporcionados">
<Columns>
<telerik:GridBoundColumn HeaderText="Concepto" DataField="concepto" />
<telerik:GridTemplateColumn HeaderText="Unidad" HeaderStyle-Width="25%">
<ItemTemplate>
<asp:Label ID="lblUnidad" runat="server" Text="Ton"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Valor" DataField="valor" HeaderStyle-Width="25%">
<ItemTemplate>
<asp:TextBox ID="txtValor" runat="server"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="No Captura" HeaderStyle-Width="25%">
<ItemTemplate>
<asp:CheckBox ID="chkNoCaptura" Checked="false" OnChange="javascript:enableTextBox();" on runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
 
</MasterTableView>

<div style="display: none;"> <asp:TextBox ID="txtId" runat="server" /> <asp:TextBox ID="txtSecondaryId" runat="server" /> <asp:TextBox ID="txtCategory" runat="server"/> <asp:TextBox ID="txtSection" runat="server"/> <asp:HiddenField ID="hdnIsImageOnly" runat="server" Value="" ClientIDMode="Static" /></div><div id="editDiv" runat="server"> <div id="divUploadList"> <asp:GridView ID="grdAttachment" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#FFFFFF" BorderStyle="None" BorderWidth="" CellPadding="3" Width="90%" DataKeyNames="GlobalId" onrowdatabound="grdAttachment_RowDataBound" ShowHeader="false" onrowcommand="grdAttachment_RowCommand" GridLines="None"> <Columns> <asp:TemplateField HeaderText="File Name"> <ItemStyle Width="95%" /> <ItemTemplate> <asp:LinkButton runat="server" ID="lnkDelete" CommandArgument='<%# Eval("GlobalId") %>' CommandName="RemoveFile" OnClientClick="return confirm('Are you sure you want to remove this attachment?');" ><img style="border:none" src="../Images/eClose.png" /></asp:LinkButton> <asp:LinkButton runat="server" ID="lnkAttachment"><%# Eval("FileName") %></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <br /> <asp:ImageButton runat="server" ID="btnAttach" ImageUrl="~/Images/Buttons/Attachment.gif" OnClick="btnAttach_Click" /> </div> <div id="divUploader"> <telerik:RadWindow ID="uploadDialog" runat="server" Title="Upload Attachment" Height="400px" style="z-index: 99997;" OffsetElementID="grdAttachment" Width="600px" Left="150px" Behaviors="Close,Move,Resize" AutoSize="true" AutoSizeBehaviors="Height" ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" VisibleStatusbar="false" IconUrl="~/Images/GFLogo.png" EnableShadow="true" VisibleOnPageLoad="false"> <ContentTemplate> <span class="notes">maximum upload file size: 10MB</span> <br /> <div style="text-align: center;"> <telerik:RadUpload ID="uploadAttachment" MaxFileSize="300000000" runat="server" ClientIDMode="Static" InitialFileInputsCount="1"/> <%-- <telerik:RadProgressArea runat="server" id="RadProgressArea1" OnClientProgressUpdating="checkUploadedFilesSize" style="position: fixed; top: 50% !important; left: 50% !important; margin: -93px 0 0 -188px;"/> <telerik:RadProgressManager runat="server" id="RadProgressManager1" />--%> <br /> <asp:LinkButton runat="server" ID="btnUpload" CssClass="button" OnClick="btnUpload_Click" OnClientClick="return validateAttachment();"><span>Upload</span></asp:LinkButton> </div> </ContentTemplate> </telerik:RadWindow> </div></div><div id="viewDiv" runat="server"> <asp:Repeater runat="server" ID="repAttachment" OnItemDataBound="repAttachment_ItemDataBound"> <ItemTemplate> <asp:LinkButton CommandArgument='<%# Eval("GlobalId") %>' runat="server" ID="lnkAttachment"><%# Eval("FileName") %></asp:LinkButton><br /> </ItemTemplate> </asp:Repeater></div>