using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.IO;using System.Data;using Indivar;using System.Configuration;
public partial class ProjectPlanner_CreateProjectNotes : BasePage{ clsManageNotes obj; string fn , v_fileattached,v_fileguid; int vproject_Id = 1; int vcreatedby = 1;
protected void Page_Load(object sender, EventArgs e) { trhreflink.Visible = false; if (!Page.IsPostBack) { //=============To show the active tab on postback tabContainerProjects.ActiveTabIndex = Convert.ToInt32(hfCurrentTab.Value);
bindProjects(); } }
//public void Downloadfile() protected void btnMethodOne_Click(object sender, EventArgs e) { Response.AppendHeader("content-disposition", "attachment; filename=" + v_fileguid); Response.TransmitFile(Server.MapPath("~/Documents/" + v_fileguid)); Response.End();
}
//======= Save Project Notes ======== protected void btnSaveProject_Click(object sender, EventArgs e) { int errStatus = validateInputFields(); if (errStatus == 0) { obj = new clsManageNotes(); obj.projNote_ProjectId = vproject_Id; obj.projNote_Title = txtProjectNoteTitle.Text; obj.projNote_Note = txtProjectNoteDescription.Text; obj.projNote_FileAttached = fuUploadFile.PostedFile.FileName; obj.projNote_CreatedBy = vcreatedby;
fn = Guid.NewGuid().ToString() + fuUploadFile.FileName.Substring(fuUploadFile.FileName.LastIndexOf(".")); obj.projNote_FileId = fn; UploadDocument(); int status = clsManageNoteMethods.addProject(obj); if (status == 0)//=======If query Successfully Executed { clearInputFields();
//========== Bind Data bindProjects(); } } }
//======= Update Project ======== protected void btnUpdateProject_Click(object sender, EventArgs e) { int errStatus = validateInputFields(); if (errStatus == 0) { obj = new clsManageNotes(); obj.projNote_Title = txtProjectNoteTitle.Text; obj.projNote_Note = txtProjectNoteDescription.Text; obj.projNote_CreatedBy = 1;
obj.projNote_Id = Convert.ToInt32(hfSelectedRecord.Value);
UploadDocument(); int status = clsManageNoteMethods.updateProject(obj);
if (status == 0)//=======If query Successfully Executed { clearInputFields();
//======= Cancel Project ======== protected void btnCancelProject_Click(object sender, EventArgs e) { clearInputFields(); btnSaveProject.Visible = true; btnUpdateProject.Visible = false; }
//============= Repeater Command Events ===================== protected void repProjects_ItemCommand(object source, RepeaterCommandEventArgs e) { lblInfoMessage.Text = string.Empty; divMessage.Style.Add("display", "none"); if (e.CommandName == "Edit") { hfCurrentTab.Value = (0).ToString();//======= To show the add tabcontainer on postback hfSelectedRecord.Value = e.CommandArgument.ToString();
bindProjectRecordsToEdit(Convert.ToInt32(e.CommandArgument)); tabContainerProjects.ActiveTabIndex = 0; btnSaveProject.Visible = false; btnUpdateProject.Visible = true;
} else if (e.CommandName == "View")//====== To show the complete details of the project. { repProjectDetails.DataSource = clsManageNoteMethods.getProjectNoteDetail(Convert.ToInt32(e.CommandArgument)); repProjectDetails.DataBind(); mpeProjectDetails.Show(); } }
#region Methods //=-=-=-= To Clear Input fields of project form =-=-=-= public void clearInputFields() { txtProjectNoteTitle.Text = string.Empty; txtProjectNoteDescription.Text = string.Empty; }
//=== Validate Fields===== public int validateInputFields() { int errCnt = 0; string errMsg = ""; if (txtProjectNoteTitle.Text == string.Empty) { errMsg += "<li>Please enter discussion title.</li>"; errCnt++; } if (txtProjectNoteDescription.Text == string.Empty) { errMsg += "<li>Please enter message description.</li>"; errCnt++; } return errCnt; }
//====== To bind data ========== public void bindProjects() { repProjects.DataSource = clsManageNoteMethods.getProjectNoteToDisplay(vproject_Id); repProjects.DataBind(); }
//======= To bind values to the fields to edit a record public void bindProjectRecordsToEdit(int projNote_Id) { obj = new clsManageNotes(); SqlDataReader dr = clsManageNoteMethods.getProjectToEdit(projNote_Id); if (dr.HasRows) { dr.Read(); txtProjectNoteTitle.Text = dr["projNote_Title"].ToString(); txtProjectNoteDescription.Text = dr["projNote_Note"].ToString(); v_fileattached = dr["projnote_fileattached"].ToString(); v_fileguid = dr["projnote_fileid"].ToString();
if (v_fileattached !="") { trAttach.Visible = false; trhreflink.Visible = true;
lnkAttachment.Text = v_fileattached; } else { trAttach.Visible = true; trhreflink.Visible = false; } } }
public void UploadDocument() { if (fuUploadFile.PostedFile.ContentLength > 0) { string Apath = Server.MapPath("~/Documents/") ; if (!Directory.Exists(Apath)) { Directory.CreateDirectory(Apath); string virtualpath = Server.MapPath("~/Documents" + "\\" + fn); fuUploadFile.PostedFile.SaveAs(virtualpath); //FileUpload1.PostedFile property Holds client side path } else { string virtualpath = Server.MapPath("~/Documents" + "\\" + fn); fuUploadFile.PostedFile.SaveAs(virtualpath); //FileUpload1.PostedFile property Holds client side path } } }
#endregion}
Aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/ProjectPlanner/projPlannerMaster.master" AutoEventWireup="true" CodeFile="CreateProjectNotes.aspx.cs" Inherits="ProjectPlanner_CreateProjectNotes" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <script type="text/javascript" language="javascript"> function manageActiveTab() { var selectedTab = $find('<%=tabContainerProjects.ClientID%>').get_activeTabIndex();
//store the value of active tab into hidden field. var hfCurrentTab = document.getElementById("<%=hfCurrentTab.ClientID%>"); hfCurrentTab.value = selectedTab;
//=========== To hide the error message on Tab changed============= document.getElementById("<%=divMessage.ClientID%>").style.display = 'none'; document.getElementById("<%=lblInfoMessage.ClientID%>").innerHTML = ''; } </script>
</asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"><%-- <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate>--%>
<%--<div style="text-align:center"> <asp:Label ID="lblHeader" runat="server"></asp:Label> <asp:GridView ID="grdFiles" runat="server"> </asp:GridView> </div>--%>
<asp:HiddenField ID="hidRowId" runat="server" /> <asp:HiddenField ID="hidImgId" runat="server" />
<asp:HiddenField ID="hfSelectedRecord" runat="server" /> <asp:HiddenField ID="hfCurrentTab" Value="0" runat="server" /> <ajaxToolkit:TabContainer OnClientActiveTabChanged="manageActiveTab" runat="server" ID="tabContainerProjects" ActiveTabIndex="1"> <ajaxToolkit:TabPanel runat="server" ID="tabPanelCreateProject" HeaderText="Create Project Notes"> <ContentTemplate> <div id="divMessage" runat="server" style="display: none;"> <asp:Label ID="lblInfoMessage" runat="server"></asp:Label> </div> <table border="0" cellpadding="5px" cellspacing="0" width="100%"> <tr> <td style="width: 20%;"> Note Title<span style="color: Red;">*</span> </td> <td style="width: 80%;"> <asp:TextBox ID="txtProjectNoteTitle" Width="500px" runat="server"></asp:TextBox> </td> </tr> <tr> <td style="vertical-align: top;"> Note Description<span style="color: Red;">*</span> </td> <td> <asp:TextBox ID="txtProjectNoteDescription" TextMode="MultiLine" Height="80px" Width="500px" runat="server"></asp:TextBox> </td> </tr>
<tr runat="server" id="trAttach"> <td style="vertical-align: top;" > Attach File<span style="color: Red;">*</span> </td> <td> <asp:FileUpload ID="fuUploadFile" runat="server" class="multi" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic" ValidationGroup="UploadFile" ControlToValidate="fuUploadFile" Font-Bold="true" ErrorMessage="Please select the File to upload." SetFocusOnError="true"> </asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationGroup="UploadFile" ErrorMessage="Only Doc, Xls, Txt files are allowed to be uploaded!" ValidationExpression="[a-zA-Z0_9].*\b(.Doc|.DOC|.doc|.Xls|.xls|.XLS|.Txt|.TXT|.txt)\b" Display="Dynamic" ControlToValidate="fuUploadFile" SetFocusOnError="true"> </asp:RegularExpressionValidator> </td> <%--<td> <asp:Button ID="BtnDelete" runat="server" Text="Delete File" /> </td>--%> </tr>
<tr runat="server" id="trhreflink"> <td style="vertical-align: top;" > Attachment<span style="color: Red;">*</span> </td> <td> <asp:LinkButton ID="lnkAttachment" runat="server" Text="Attachment" OnClick="btnMethodOne_Click"></asp:LinkButton> </td> <td> </td> <td> <asp:Button ID="BtnDelete" runat="server" Text="Delete File" /> </td> </tr>
<tr> <td> </td> <td> <asp:Button ID="btnSaveProject" runat="server" Text="Post Message" OnClick="btnSaveProject_Click" /> <asp:Button ID="btnUpdateProject" runat="server" Text="Update" Visible="false" OnClick="btnUpdateProject_Click" /> <asp:Button ID="btnCancelProject" runat="server" Text="Cancel" OnClick="btnCancelProject_Click" /> </td> </tr> </table> </ContentTemplate> </ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel runat="server" ID="tabPanelViewDiscussions" HeaderText="View Notes"> <ContentTemplate>
<table class="showData" border="0" cellpadding="5px" width="100%" cellspacing="0"> <tr id="headerRow"> <td> Sno </td> <td> Notes Title </td> <td> Notes Description </td> <td> FileName </td> <td> Actions </td> </tr> <asp:Repeater ID="repProjects" runat="server" OnItemCommand="repProjects_ItemCommand"> <ItemTemplate> <tr id="<%#(Convert.ToInt32(((RepeaterItem)Container).ItemIndex+1)%2==0?"ContentMainRow":"ContentAlternateRow")%>"> <td> <%#(((RepeaterItem)Container).ItemIndex+1).ToString()%> </td> <td> <%#Eval("projNote_Title") %> </td> <td> <%#Eval("projNote_Note") %> </td> <td> <%#Eval("projNote_FileAttached") %> </td> <td> <asp:ImageButton ID="imgBtnEdit" CommandName="Edit" ToolTip="Edit a record." CommandArgument='<%#Eval("projNote_Id") %>' runat="server" ImageUrl="~/resources/Images/edit.png" /> <asp:ImageButton ToolTip="View Details." ID="imgBtnViewProjectDetails" CommandName="View" CommandArgument='<%#Eval("projNote_Id") %>' runat="server" ImageUrl="~/resources/Images/viewDetails_Icon.png" /> </td> </tr> </ItemTemplate> </asp:Repeater> </table>
<div> <ajaxToolkit:ModalPopupExtender ID="mpeProjectDetails" runat="server" TargetControlID="btnDemoPopupOpen" PopupControlID="pnlProjectDetails" BackgroundCssClass="modalBackground" CancelControlID="imgBtnPopupClose" DynamicServicePath="" Enabled="True"> </ajaxToolkit:ModalPopupExtender> <asp:Panel ID="pnlProjectDetails" Style="display: none;" runat="server" CssClass="popupContainer" Width="650px"> <div id="popuPHeader"> <asp:ImageButton ID="imgBtnPopupClose" ImageUrl="~/resources/Images/delete.png" runat="server" /></div> <div id="content" style="height: 400px; overflow: auto;"> <asp:Repeater ID="repProjectDetails" runat="server"> <ItemTemplate> <table border="1" style="border: 1px solid #4a6491; border-collapse: collapse;" cellpadding="5px" cellspacing="0" width="100%"> <tr> <td style="width: 25%;"> <b>Note Title</b> </td> <td style="width: 75%;"> <%#Eval("projNote_title")%> </td> </tr> <tr> <td valign="top"> <b>Note Description</b> </td> <td> <%#Eval("projNote_Note")%> </td> </tr> <tr> <td valign="top"> <b>Note Attachment</b> </td> <td> <%#Eval("projNote_FileAttached")%> </td> </tr> </table> </ItemTemplate> </asp:Repeater> </div> </asp:Panel> <asp:Button ID="btnDemoPopupOpen" Style="display: none;" runat="server" /> <asp:Button Style="display: none;" ID="btnDemoPopupClose" runat="server" /> </div> </ContentTemplate> </ajaxToolkit:TabPanel> </ajaxToolkit:TabContainer> <%--</ContentTemplate> </asp:UpdatePanel>--%></asp:Content>
What is happening when i click on lnkAttachment , btnmethodone_click gets fired . In v_fileguid it is giving null whereas it should give file Guid which i am storing in it . How to resolve this.
Thanx