Exemplo n.º 1
0
    protected void ButtonUploadSingleImage_Click(object sender, EventArgs e)
    {
        if (FileUploadSingleImage.HasFile)
        {
            using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
            {
                PenggunaLogin PenggunaLogin = (PenggunaLogin)Session["PenggunaLogin"];

                string Folder = Server.MapPath("/images/PostDetail/");

                if (!Directory.Exists(Folder))
                {
                    Directory.CreateDirectory(Folder);
                }

                Post_Class Post_Class = new Post_Class(db);
                TBPost     Post       = Post_Class.GetData(Request.QueryString["id"].ToInt());

                PostDetail_Class PostDetail_Class = new PostDetail_Class(db);
                TBPostDetail     PostDetail       = null;
                if (string.IsNullOrEmpty(HiddenFieldIDPostDetail.Value))
                {
                    PostDetail = PostDetail_Class.InsertData(Post.IDPost, PenggunaLogin.IDPengguna, Post.TBPostDetails.Count + 1, DateTime.Now, TextBoxDetailNama.Text, DropDownListDetailJenis.SelectedValue.ToInt(), (DropDownListDetailJenis.SelectedValue.ToInt() == (int)EnumJenisPostDetail.Text ? TextBoxDetailKonten.Text : null));
                    db.SubmitChanges();
                }
                else
                {
                    PostDetail = PostDetail_Class.GetData(HiddenFieldIDPostDetail.Value.ToInt());
                }

                PostDetailImage_Class PostDetailImage_Class = new PostDetailImage_Class(db);
                TBPostDetailImage     PostDetailImage       = PostDetail.TBPostDetailImages.FirstOrDefault();
                if (PostDetailImage == null)
                {
                    PostDetailImage = PostDetailImage_Class.InsertData(PostDetail.IDPostDetail, 0, string.Empty, null, null, null, null);
                    db.SubmitChanges();
                }

                FileUploadSingleImage.SaveAs(Folder + (PostDetailImage.IDPostDetail + "-" + PostDetailImage.IDPostDetailImage) + ".jpg");

                PostDetailImage.DefaultURL = "/images/PostDetail/" + (PostDetailImage.IDPostDetail + "-" + PostDetailImage.IDPostDetailImage) + ".jpg";

                db.SubmitChanges();

                HiddenFieldIDPostDetail.Value   = PostDetail.IDPostDetail.ToString();
                DropDownListDetailJenis.Enabled = false;
            }

            LoadDataFoto();
        }
    }
Exemplo n.º 2
0
    protected void ButtonUploadMultipleImage_Click(object sender, EventArgs e)
    {
        using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
        {
            PenggunaLogin PenggunaLogin = (PenggunaLogin)Session["PenggunaLogin"];

            string Folder = Server.MapPath("/images/PostDetail/");

            if (!Directory.Exists(Folder))
            {
                Directory.CreateDirectory(Folder);
            }

            Post_Class Post_Class = new Post_Class(db);
            TBPost     Post       = Post_Class.GetData(Request.QueryString["id"].ToInt());

            PostDetail_Class PostDetail_Class = new PostDetail_Class(db);
            TBPostDetail     PostDetail       = null;
            if (string.IsNullOrEmpty(HiddenFieldIDPostDetail.Value))
            {
                PostDetail = PostDetail_Class.InsertData(Post.IDPost, PenggunaLogin.IDPengguna, Post.TBPostDetails.Count + 1, DateTime.Now, TextBoxDetailNama.Text, DropDownListDetailJenis.SelectedValue.ToInt(), (DropDownListDetailJenis.SelectedValue.ToInt() == (int)EnumJenisPostDetail.Text ? TextBoxDetailKonten.Text : null));
                db.SubmitChanges();
            }
            else
            {
                PostDetail = PostDetail_Class.GetData(HiddenFieldIDPostDetail.Value.ToInt());
            }

            PostDetailImage_Class PostDetailImage_Class = new PostDetailImage_Class(db);
            TBPostDetailImage     PostDetailImage       = null;

            if (ButtonUploadMultipleImage.Text == "Tambah")
            {
                PostDetailImage = PostDetailImage_Class.InsertData(PostDetail.IDPostDetail, PostDetail.TBPostDetailImages.Count + 1, string.Empty, TextBoxImageJudul.Text, HttpUtility.HtmlDecode(TextBoxImageDeskripsi.Text), TextBoxImageLink.Text, TextBoxImageAlt.Text);
            }
            else
            {
                PostDetailImage           = PostDetailImage_Class.GetData(HiddenFieldPostDetailImage.Value.ToInt());
                PostDetailImage.Judul     = TextBoxImageJudul.Text;
                PostDetailImage.Deskripsi = HttpUtility.HtmlDecode(TextBoxImageDeskripsi.Text);
                PostDetailImage.Link      = TextBoxImageLink.Text;
                PostDetailImage.Alt       = TextBoxImageAlt.Text;
            }

            db.SubmitChanges();

            if (FileUploadMultipleImage.HasFile)
            {
                FileUploadMultipleImage.SaveAs(Folder + (PostDetailImage.IDPostDetail + "-" + PostDetailImage.IDPostDetailImage) + ".jpg");
            }

            PostDetailImage.DefaultURL = "/images/PostDetail/" + (PostDetailImage.IDPostDetail + "-" + PostDetailImage.IDPostDetailImage) + ".jpg";

            db.SubmitChanges();

            HiddenFieldIDPostDetail.Value    = PostDetail.IDPostDetail.ToString();
            HiddenFieldPostDetailImage.Value = string.Empty;
            DropDownListDetailJenis.Enabled  = false;
            TextBoxImageJudul.Text           = string.Empty;
            TextBoxImageLink.Text            = string.Empty;
            TextBoxImageAlt.Text             = string.Empty;
            TextBoxImageDeskripsi.Text       = string.Empty;

            ButtonUploadMultipleImage.Text = "Tambah";
        }

        LoadDataFoto();
    }