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();
//========== Bind Data
bindProjects();
}
}
}
//======= 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 += "
errCnt++;
}
if (txtProjectNoteDescription.Text == string.Empty)
{
errMsg += "
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" %>
<%--
<%--
Note Title*
Note Description*
Attach File*
ErrorMessage="Please select the File to upload." SetFocusOnError="true">
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">
<%-- --%>
Attachment*
Sno | Notes Title | Notes Description | FileName | Actions |
<%#(((RepeaterItem)Container).ItemIndex+1).ToString()%> | <%#Eval("projNote_Title") %> | <%#Eval("projNote_Note") %> | <%#Eval("projNote_FileAttached") %> |
DynamicServicePath="" Enabled="True">
Width="650px">
Note Title
<%#Eval("projNote_title")%>
Note Description
<%#Eval("projNote_Note")%>
Note Attachment
<%#Eval("projNote_FileAttached")%>
<%--
--%>
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
vaibhav bhargavPosted Jan 31, 2012, 1:25 AM