public int UpdateInformation(EventPhotoObject eventPhotoObj)
        {
            SqlConnection con = GetConnection();

            con.Open();

            SqlCommand cmd = new SqlCommand("Update_EventPhoto", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@PhotoId", eventPhotoObj.PhotoId);
            cmd.Parameters.AddWithValue("@EventId", eventPhotoObj.EventId);
            cmd.Parameters.AddWithValue("@PhotoPath", eventPhotoObj.PhotoPath);
            cmd.Parameters.AddWithValue("@Status", eventPhotoObj.Status);

            try
            {
                return(cmd.ExecuteNonQuery());
            }
            catch
            {
                throw;
            }
            finally
            {
                cmd.Dispose();
                con.Close();
                con.Dispose();
            }
        }
        protected void btn_upload_Click(object sender, EventArgs e)
        {
            if (FileUploadEvent.HasFiles)
            {
                string photopath    = "";
                string uploadFolder = "~/Event_Photos/";

                DataTable dt = new DataTable();
                dt.Columns.Add("EventId");
                dt.Columns.Add("PhotoPath");
                dt.Columns.Add("Status");
                EventPhotoObject eventphotoObj = new EventPhotoObject();

                foreach (HttpPostedFile uploadedFile in FileUploadEvent.PostedFiles)
                {
                    string extension = Path.GetExtension(uploadedFile.FileName);
                    photopath = Guid.NewGuid().ToString() + extension;
                    uploadedFile.SaveAs(Server.MapPath(uploadFolder + photopath));


                    eventphotoObj.EventId   = Int32.Parse(tbxEventId.Text);
                    eventphotoObj.PhotoPath = photopath;

                    if (ddlPhotoStatus.SelectedValue == "1")
                    {
                        eventphotoObj.Status = true;
                    }
                    else if (ddlPhotoStatus.SelectedValue == "0")
                    {
                        eventphotoObj.Status = false;
                    }

                    dt.Rows.Add(new Object[] { eventphotoObj.EventId, eventphotoObj.PhotoPath, eventphotoObj.Status });
                }

                try
                {
                    dalEP.InsertInformation(dt);
                    LoadEvent();
                    LoadEventTitle();
                    LoadAllEventPhoto();

                    PanelSuccess.Visible = true;
                }
                catch
                {
                    PanelFaild.Visible = true;
                    throw;
                }
            }
        }
예제 #3
0
        protected void btn_update_Click(object sender, EventArgs e)
        {
            int       id = int.Parse(Session["EventPhoto_id"].ToString());
            DataTable dt = dal.SelectInformationById(id);

            EventPhotoObject photoObj = new EventPhotoObject();

            photoObj.PhotoId = int.Parse(Session["EventPhoto_id"].ToString());
            photoObj.EventId = Int32.Parse(dt.Rows[0]["EventId"].ToString());

            if (FileUpload.HasFile)
            {
                string extension    = Path.GetExtension(FileUpload.FileName);
                string photopath    = Guid.NewGuid().ToString() + extension;
                string uploadFolder = "~/Event_Photos/";
                FileUpload.SaveAs(Server.MapPath(uploadFolder + photopath));
                photoObj.PhotoPath = photopath;
                if (ddlPhotoStatus.SelectedValue == "1")
                {
                    photoObj.Status = true;
                }
                else if (ddlPhotoStatus.SelectedValue == "0")
                {
                    photoObj.Status = false;
                }

                try
                {
                    int result = dal.UpdateInformation(photoObj);
                    if (result == 1)
                    {
                        getPhotoById();
                        PanelSuccess.Visible = true;
                    }
                }
                catch
                {
                    throw;
                }
            }
            else
            {
                photoObj.PhotoPath = dt.Rows[0]["PhotoPath"].ToString();
                if (ddlPhotoStatus.SelectedValue == "1")
                {
                    photoObj.Status = true;
                }
                else if (ddlPhotoStatus.SelectedValue == "0")
                {
                    photoObj.Status = false;
                }

                try
                {
                    int result = dal.UpdateInformation(photoObj);
                    if (result == 1)
                    {
                        getPhotoById();
                        PanelSuccess.Visible = true;
                    }
                }
                catch
                {
                    throw;
                }
            }
        }