Exemplo n.º 1
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            FeedBack objFeedBack = new FeedBack();

            objFeedBack.MemberID = Session["LoginID"].ToString();
            objFeedBack.Title    = TitleFeedBack.Text;
            objFeedBack.Message  = FeedBackMsg.Text;

            int errorCode = objFeedBack.ConfirmAdd();

            if (errorCode == 0)
            {
                int PhotoFeedbackID = -1;
                if (UploadFeedbackPhoto.HasFile == true)
                {
                    // find the filename extension of the file to be uploaded
                    string fileExtension = Path.GetExtension(UploadFeedbackPhoto.FileName);

                    // find FeedbackID of this image so that it can be used as Image name
                    PhotoFeedbackID = objFeedBack.FindFeedbackID();

                    // Image name to be saved in 'Images' folder
                    string FileSavePath = MapPath("~/Images/Feedback/" + "images-" + PhotoFeedbackID.ToString() + fileExtension);

                    // Save image in application 'Images' folder
                    UploadFeedbackPhoto.SaveAs(FileSavePath);


                    // to View image in Webpage using Image Control
                    //FeedbackImage.ImageUrl = "~/Images/Feedback/" + UploadFeedbackPhoto;


                    objFeedBack.ImageFileName = "images-" + PhotoFeedbackID.ToString() + fileExtension;
                    objFeedBack.FeedbackID    = PhotoFeedbackID;

                    // use an UPDATE SQL line to update the existing feedback record to add the image name
                    int errorCode2 = objFeedBack.updatePicture();
                    if (errorCode2 == 0)
                    {
                        Response.Redirect("ViewResponse.aspx");
                    }
                    else
                    {
                        Message.Text = "Update was unsuccessful, Picture was not updated into Database";
                    }
                }
                else
                {
                    Response.Redirect("ViewResponse.aspx");
                }
            }
            else
            {
                Message.Text = "Update was unsuccessful, did you key in the right details?";
            }
        }