or
<ExportSettings Excel-Format="Html" ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true"> </ExportSettings><%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="Test2.aspx.cs" Inherits="mtc_knowledgebase.Test2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <style type="text/css"> span.riSingle { position: static; } </style> </head> <body class="BODY"> <form runat="server" id="mainForm" method="post"> <telerik:RadScriptManager runat="server" ID="RadScriptManager1" /> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadGrid1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" /> <telerik:RadGrid AllowSorting="True" AutoGenerateColumns="False" DataSourceID="DNDataSource" ID="DNGrid" runat="server" GridLines="Both" AllowPaging="true" AllowFilteringByColumn="true" CssClass="span.riSingle" OnItemCommand="DNGrid_OnItemCommand"> <MasterTableView CommandItemDisplay="Bottom" DataKeyNames="dn_hdr_id" EditMode="PopUp" Name="HeaderGrid" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"> <NestedViewTemplate> <asp:Panel runat="server" ID="InnerContainer"> <telerik:RadTabStrip runat="server" ID="TabStip1" MultiPageID="Multipage1" SelectedIndex="0" DataFieldParentID="dn_hdr_id"> <Tabs> <telerik:RadTab runat="server" Text="DN Items" PageViewID="ItemView"> </telerik:RadTab> <telerik:RadTab runat="server" Text="DN Approvals" PageViewID="ApprovalView"> </telerik:RadTab> </Tabs> </telerik:RadTabStrip> <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false"> <telerik:RadPageView runat="server" ID="ItemView"> <telerik:RadGrid AllowSorting="True" AutoGenerateColumns="False" DataSourceID="DNDtlDataSource" ID="DetailGrid" runat="server" GridLines="Both" CssClass="span.riSingle" BackColor="Azure" HeaderStyle-ForeColor="DimGray" HeaderStyle-BorderColor="DarkGoldenrod" HeaderStyle-BorderWidth="2px" OnInsertCommand="GridOnInsert" OnUpdateCommand="GridOnUpdate" OnItemCommand="GridGetId"> <MasterTableView CommandItemDisplay="Bottom" DataKeyNames="dn_dtl_id,dn_hdr.dn_hdr_id" EditMode="PopUp" Name="DetailGrid"> <CommandItemSettings ShowExportToExcelButton="false" ShowRefreshButton="false" AddNewRecordText="Add New Detail Record" /> <EditFormSettings EditColumn-ButtonType="PushButton" EditColumn-UpdateText="Process Update" PopUpSettings-Modal="true" PopUpSettings-Width="85%" /> <Columns> <telerik:GridBoundColumn UniqueName="DTL_DN_DTL_ID" DataField="dn_dtl_id" ReadOnly="true" Visible="false" /> <telerik:GridEditCommandColumn EditText="EDIT" UniqueName="btnEdit" ButtonType="PushButton" /> <telerik:GridAttachmentColumn DataSourceID="DNDtlDataSource2" MaxFileSize="10485760" EditFormHeaderTextFormat="Upload File:" HeaderText="Attachment" AttachmentDataField="dn_file_att" AttachmentKeyFields="dn_dtl_id" FileNameTextField="dn_file_nm" DataTextField="dn_file_nm" UniqueName="DTL_AttachmentColumn" AllowedFileExtensions=".pdf,.jpg" /> <telerik:GridBoundColumn UniqueName="DTL_CREAT_BY" HeaderText="Created By" DataField="creat_by" ReadOnly="true" /> <telerik:GridBoundColumn UniqueName="DTL_CREAT_DT" HeaderText="Date Created" DataField="creat_dt" ReadOnly="true" DataFormatString="{0:MM/dd/yy}" /> <telerik:GridBoundColumn UniqueName="DTL_UPDT_BY" HeaderText="Last Updated By" DataField="updt_by" ReadOnly="true" /> <telerik:GridBoundColumn UniqueName="DTL_UPDT_DT" HeaderText="Last Updated" DataField="updt_dt" DataFormatString="{0:MM/dd/yy}" ReadOnly="true" /> </Columns> </MasterTableView> </telerik:RadGrid> </telerik:RadPageView> <telerik:RadPageView runat="server" ID="ApprovalView"> <telerik:RadGrid AllowSorting="True" AutoGenerateColumns="False" ID="ApprovalGrid" DataSourceID="DNDataSource2" runat="server" GridLines="Both" CssClass="span.riSingle" BackColor="Azure" EnableViewState="true" HeaderStyle-ForeColor="DimGray" HeaderStyle-BorderColor="DarkGoldenrod" HeaderStyle-BorderWidth="2px"> <MasterTableView CommandItemDisplay="Bottom" DataKeyNames="dn_hdr_id" EditMode="PopUp" Name="ApprovalGridMaster"> <CommandItemSettings ShowExportToExcelButton="false" ShowRefreshButton="false" ShowAddNewRecordButton="false" /> <EditFormSettings EditColumn-ButtonType="PushButton" EditColumn-UpdateText="Process Update" PopUpSettings-Modal="true" PopUpSettings-Width="85%" /> <Columns> <telerik:GridEditCommandColumn EditText="EDIT" UniqueName="btnEdit" ButtonType="PushButton" /> <telerik:GridBoundColumn UniqueName="QR_NM" HeaderText="Quality Signoff" DataField="qr_nm" /> <telerik:GridDateTimeColumn UniqueName="QR_DT" HeaderText="Quality Signoff Date" DataField="qr_dt" DataFormatString="{0:MM/dd/yy}" /> </Columns> </MasterTableView> </telerik:RadGrid> </telerik:RadPageView> </telerik:RadMultiPage> </asp:Panel> </NestedViewTemplate> <Columns> <telerik:GridEditCommandColumn EditText="EDIT" UniqueName="btnEdit" ButtonType="PushButton" /> <telerik:GridBoundColumn UniqueName="dn_hdr_id" HeaderText="DN ID" DataField="dn_hdr_id" ReadOnly="true" /> <telerik:GridBoundColumn UniqueName="SUP_NM" HeaderText="Operator/Supervisor" DataField="sup_nm" /> <telerik:GridDateTimeColumn UniqueName="SUP_DT" HeaderText="O/S Date" DataField="sup_dt" DataFormatString="{0:MM/dd/yy}" /> </Columns> </MasterTableView> <ClientSettings AllowKeyboardNavigation="true"> <Scrolling AllowScroll="true" ScrollHeight="600px" /> </ClientSettings> <ExportSettings ExportOnlyData="true" IgnorePaging="true" /> </telerik:RadGrid> <asp:EntityDataSource ID="DNDataSource" runat="server" ConnectionString="name=mtc_kbaseEntities" DefaultContainerName="mtc_kbaseEntities" EntitySetName="dn_hdr" OrderBy="it.updt_dt" Include="cust, prt, orig_1" EnableInsert="true" EnableUpdate="true"> </asp:EntityDataSource> <asp:EntityDataSource ID="DNDataSource2" runat="server" ConnectionString="name=mtc_kbaseEntities" DefaultContainerName="mtc_kbaseEntities" EntitySetName="dn_hdr" EnableUpdate="true"> </asp:EntityDataSource> <asp:EntityDataSource ID="DNDtlDataSource2" runat="server" ConnectionString="name=mtc_kbaseEntities" DefaultContainerName="mtc_kbaseEntities" EntitySetName="dn_dtl"> </asp:EntityDataSource> <asp:EntityDataSource ID="DNDtlDataSource" runat="server" ConnectionString="name=mtc_kbaseEntities" DefaultContainerName="mtc_kbaseEntities" EntitySetName="dn_dtl" Include="orig_2"> </asp:EntityDataSource> </form> </body> </html> using System; using System.Data; using System.Linq; using System.Web; using Telerik.Web.UI; namespace mtc_knowledgebase { public partial class Test2 : System.Web.UI.Page { #region Variables private int _dnHdrId; private int _dnDtlId; private string _fileName; private byte[] _fileData; private string _curUser; private DateTime? _curDt; private int _errLevel; #endregion protected void Page_Load(object sender, EventArgs e) { DNDtlDataSource2.Where = "it.dn_dtl_id == 0"; } /// <summary> /// This will be used in place of the auto insert event based on File Attachment requirements /// </summary> /// <param name="sender"> /// This method is called on the Grid Insert Event /// </param> /// <param name="e"> /// The entire Inserted record will be passed /// </param> protected void GridOnInsert(object sender, GridCommandEventArgs e) { if ("DetailGrid".Equals(e.Item.OwnerTableView.Name)) { var editItem = e.Item as GridEditableItem; GetRecordInfo(editItem); if (_errLevel == 0) { try { using (var db = new mtc_kbaseEntities()) { var newDnDtl = new dn_dtl { dn_hdrReference = { EntityKey = new EntityKey("mtc_kbaseEntities.dn_hdr", "dn_hdr_id", _dnHdrId) }, dn_file_nm = _fileName, dn_file_att = _fileData, creat_by = _curUser, creat_dt = _curDt, updt_by = _curUser, updt_dt = _curDt }; db.AddTodn_dtl(newDnDtl); db.SaveChanges(); } } catch (Exception ex) { Response.Write("<script type=\"text/javascript\" language=\"javascript\">"); Response.Write("alert('" + ex.Message + "');"); Response.Write("</script>"); } } } } /// <summary> /// This will be used in place of the auto update event based on File Attachment requirements /// </summary> /// <param name="sender"> /// This method is called on the Grid Update Event /// </param> /// <param name="e"> /// The entire Updated record will be passed /// </param> protected void GridOnUpdate(object sender, GridCommandEventArgs e) { if ("DetailGrid".Equals(e.Item.OwnerTableView.Name)) { var editItem = e.Item as GridEditableItem; _dnDtlId = Convert.ToInt32((editItem.EditManager.GetColumnEditor("DTL_DN_DTL_ID") as GridTextBoxColumnEditor).Text); GetRecordInfo(editItem); if (_errLevel == 0) { try { using (var db = new mtc_kbaseEntities()) { var updDtl = db.dn_dtl.First(t => t.dn_dtl_id == _dnDtlId); updDtl.dn_file_nm = _fileName; updDtl.dn_file_att = _fileData; updDtl.updt_by = _curUser; updDtl.updt_dt = _curDt; db.SaveChanges(); } } catch (Exception ex) { Response.Write("<script type=\"text/javascript\" language=\"javascript\">"); Response.Write("alert('" + ex.Message + "');"); Response.Write("</script>"); } } } } /// <summary> /// If a request for the file download is initiated, this will update the datasource /// </summary> /// <param name="sender"> /// The datasource for the attachment requires the ID of the record /// </param> /// <param name="e"> /// Only fire the event if it's a download request /// </param> protected void GridGetId(object sender, GridCommandEventArgs e) { if (e.CommandName == "DownloadAttachment") { var args = e as GridDownloadAttachmentCommandEventArgs; _dnDtlId = (int)args.AttachmentKeyValues["dn_dtl_id"]; DNDtlDataSource2.Where = "it.dn_dtl_id == " + _dnDtlId; } } /// <summary> /// This is a common method for setting variables based on the attachment details /// </summary> /// <param name="editItem"> /// The edit item. /// </param> protected void GetRecordInfo(GridEditableItem editItem) { _errLevel = 0; RadUpload upload = ((GridAttachmentColumnEditor)editItem.EditManager.GetColumnEditor("DTL_AttachmentColumn")).RadUploadControl; if (upload.InvalidFiles.Count > 0) { _errLevel = 1; Response.Write("<script type=\"text/javascript\" language=\"javascript\">"); Response.Write("alert('Only PDF or JPG files smaller than 10MB are allowed');"); Response.Write("</script>"); return; } if (upload.UploadedFiles.Count != 0) { _fileName = upload.UploadedFiles[0].GetName(); _fileData = ((GridAttachmentColumnEditor)editItem.EditManager.GetColumnEditor("DTL_AttachmentColumn")).UploadedFileContent; } _curUser = HttpContext.Current.User.Identity.Name.ToString().Replace("MORGANGROUPPLC\\", string.Empty); _curDt = DateTime.Now; } protected void DNGrid_OnItemCommand(object sender, GridCommandEventArgs e) { GridDataItem grdDataitem = (GridDataItem)e.Item; if (e.CommandName == RadGrid.ExpandCollapseCommandName) { _dnHdrId = (int)grdDataitem.GetDataKeyValue("dn_hdr_id"); DNDtlDataSource.Where = "it.dn_hdr.dn_hdr_id == " + _dnHdrId; DNDataSource2.Where = "it.dn_hdr_id == " + _dnHdrId; } } } } <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="btnRefreshPosts" EventName="onclick"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="pnlPosts" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="repPosts" EventName="onitemcommand"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="pnlComments" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="repComments" EventName="onitemcommand"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="pnlComments" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager><asp:Panel ID="pnlPosts" runat="server"> <div id="Posts" style="padding:10px;margin:15px; width:700px;"> <asp:Repeater ID="repPosts" runat="server" onitemdatabound="repPosts_ItemDataBound" OnItemCommand="repPosts_ItemCommand"> <ItemTemplate> <div class="postitem" > <div class="sep"></div> <div class="postitem_name" > <asp:Literal ID="litName" runat="server" /> <asp:Literal ID="litCreated" runat="server" /> </div> <div class="postitem_content"> <asp:Button ID="btnDelete" runat="server" Text="" CssClass="btnDelete" /> <asp:Literal ID="litContent" runat="server" /> </div> </div> <div style="clear:both;"></div> <asp:Panel ID="pnlComments" runat="server"> <div class="CommentsWrapper"> <asp:Repeater ID="repComments" runat="server" OnItemDataBound="repComments_ItemDataBound" OnItemCommand="repComments_ItemCommand"> <HeaderTemplate> <h3>Comments</h3> </HeaderTemplate> <ItemTemplate> <div class="Comment"> <asp:Button ID="btnDelete" runat="server" Text="" CssClass="btnDelete" /> <asp:Literal ID="litComment" runat="server" /> </div> </ItemTemplate> </asp:Repeater> <div class="AddComment"> <asp:Panel ID="pnlAddComment" runat="server" DefaultButton="btnAddComment"> <asp:TextBox ID="txtComment" runat="server"></asp:TextBox> <asp:Button ID="btnAddComment" CssClass="common btnAddComment" runat="server" Text="Submit" /> </asp:Panel> </div> <div style="clear:both;"></div> </div> </asp:Panel> </ItemTemplate> </asp:Repeater> </div> </asp:Panel>protected void GetPosts() { repPosts.DataSource = WineclubManager.GetPosts(19,20); repPosts.DataBind(); } protected void repPosts_ItemDataBound(object sender, RepeaterItemEventArgs e) { if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { PostItem row = (PostItem)(e.Item.DataItem); CustomerItem customer = CustomerManager.GetCustomer(row.CustomerID); Repeater repComments = (Repeater)e.Item.FindControl("repComments"); Literal litName = (Literal)e.Item.FindControl("litName"); Literal litCreated = (Literal)e.Item.FindControl("litCreated"); Literal litContent = (Literal)e.Item.FindControl("litContent"); TextBox txtComment = (TextBox)e.Item.FindControl("txtComment"); Button btnAddComment = (Button)e.Item.FindControl("btnAddComment"); Button btnDelete = (Button)e.Item.FindControl("btnDelete"); if (row.CustomerID != 0) litName.Text = "<span>" + customer.Firstname + " " + customer.Lastname + "</span>"; else litName.Text = "<span>LabelWines</span>"; litCreated.Text = "<span class=\"date\">" + row.Created.ToString("dd.MM.yyyy HH:mm") + "</span>"; litContent.Text = row.Content; txtComment.Text = "Write a comment"; if (row.CustomerID == CustomerManager.GetCustomerID()) { btnDelete.CommandName = "Delete"; btnDelete.CommandArgument = row.ID.ToString(); btnDelete.Attributes.Add("onclick", "jConfirm('" + Resources.Language.Wineclub_PostPopupMessage.Replace(Environment.NewLine, "<br />") + "', '" + Resources.Language.Wineclub_PostPopupHeader + "', function(r) { if(r==true) __doPostBack(\"" + btnDelete.ClientID.Replace("_", "$") + "\", \"\"); }); return false;"); } else btnDelete.Visible = false; btnAddComment.CommandName = "AddComment"; btnAddComment.CommandArgument = row.ID.ToString(); BindInnerRepeaterComments(repComments, row.ID); } } protected void repPosts_ItemCommand(object source, RepeaterCommandEventArgs e) { switch (e.CommandName) { case "AddComment": CommentItem item = new CommentItem(); item.PostID = int.Parse(e.CommandArgument.ToString()); item.CustomerID = 2; TextBox txtComment = e.Item.FindControl("txtComment") as TextBox; if ((txtComment.Text.Length > 0) && (txtComment.Text != "Write a comment")) item.Comment = txtComment.Text; int id = WineclubManager.AddComment(item); txtComment.Text = Resources.Language.Wineclub_PostDefaultCommentText; Repeater repComments = (Repeater)e.Item.FindControl("repComments"); BindInnerRepeaterComments(repComments, int.Parse(e.CommandArgument.ToString())); RadAjaxManager ra = (RadAjaxManager)(Page.FindControl("RadAjaxManager1")); ra.ResponseScripts.Add("javascript:InitCommentTextFields();"); break; } switch (e.CommandName) { case "Delete": WineclubManager.DeletePost(int.Parse(e.CommandArgument.ToString())); GetPosts(); RadAjaxManager ra = (RadAjaxManager)(Page.FindControl("RadAjaxManager1")); ra.ResponseScripts.Add("javascript:InitCommentTextFields();"); ra.ResponseScripts.Add("javascript:YoutubePosts();"); break; } } private void BindInnerRepeaterComments(Repeater Rep, int PostID) { CommentCollection items = WineclubManager.GetComments(PostID, false); if (items.Count > 0) { Rep.DataSource = items; Rep.DataBind(); Rep.Visible = true; } else Rep.Visible = false; } protected void repComments_ItemDataBound(object sender, RepeaterItemEventArgs e) { if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { CommentItem row = (CommentItem)e.Item.DataItem; CustomerItem customer = CustomerManager.GetCustomer(row.CustomerID); Literal litComment = (Literal)e.Item.FindControl("litComment"); Button btnDelete = (Button)e.Item.FindControl("btnDelete"); litComment.Text = "<span class=\"commentname\">" + customer.Firstname + " " + customer.Lastname + " - </span><span class=\"commentdate\">" + row.Created.ToString("dd.MM.yyyy HH:mm") + "</span>" + "<span class=\"commentmessage\">" + row.Comment + "</span>"; if (row.CustomerID == 2) { btnDelete.CommandName = "Delete"; btnDelete.CommandArgument = row.ID.ToString(); btnDelete.Attributes.Add("onclick", "jConfirm('" + Resources.Language.Wineclub_PostCommentPopupMessage.Replace(Environment.NewLine, "<br />") + "', '" + Resources.Language.Wineclub_PostCommentPopupHeader + "', function(r) { if(r==true) __doPostBack(\"" + btnDelete.ClientID.Replace("_", "$") + "\", \"\"); }); return false;"); } else btnDelete.Visible = false; } } protected void repComments_ItemCommand(object source, RepeaterCommandEventArgs e) { CommentItem currentComment = WineclubManager.GetComment(int.Parse(e.CommandArgument.ToString())); Repeater currentRep = (Repeater)source; switch (e.CommandName) { case "Delete": WineclubManager.DeleteComment(int.Parse(e.CommandArgument.ToString())); //GetPosts(); BindInnerRepeaterComments(currentRep, currentComment.PostID); RadAjaxManager ra = (RadAjaxManager)(Page.FindControl("RadAjaxManager1")); ra.ResponseScripts.Add("javascript:InitCommentTextFields();"); break; } }var editedRowIndex;function RowDblClick(sender, eventArgs){ var gridMPA = $find("<%= gridMPA.ClientID %>"); var editedRow; if (editedRowIndex) { editedRow = gridMPA.get_masterTableView().get_dataItems()[editedRowIndex]; if (editedRow.get_isInEditMode()) { gridMPA.get_masterTableView().updateItem(editedRow.get_itemIndexHierarchical()); } } editedRowIndex = eventArgs.get_itemIndexHierarchical(); gridMPA.get_masterTableView().editItem(editedRowIndex);}