Ejemplo n.º 1
0
    protected void ButtonDetailSimpan_Click(object sender, EventArgs e)
    {
        using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
        {
            PenggunaLogin PenggunaLogin = (PenggunaLogin)Session["PenggunaLogin"];

            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);
            if (string.IsNullOrEmpty(HiddenFieldIDPostDetail.Value))
            {
                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));
            }
            else
            {
                TBPostDetail PostDetail = PostDetail_Class.GetData(HiddenFieldIDPostDetail.Value.ToInt());
                PostDetail.Nama = TextBoxDetailNama.Text;
                if (DropDownListDetailJenis.SelectedValue.ToInt() == (int)EnumJenisPostDetail.Text)
                {
                    PostDetail.Konten = HttpUtility.HtmlDecode(TextBoxDetailKonten.Text);
                }
            }
            db.SubmitChanges();

            MultiViewPage.SetActiveView(ViewPost);

            LoadPost();
        }
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
            {
                MultiViewPage.SetActiveView(ViewPost);

                //PageTemplate_Class PageTemplate_Class = new PageTemplate_Class(db);
                //PageTemplate_Class.DropDownList(DropDownListTemplate, "-Pilih Template-");

                if (string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    LabelKeterangan.Text = "Tambah";
                }
                else
                {
                    TBPost Post = db.TBPosts.FirstOrDefault(item => item.IDPost == Request.QueryString["id"].ToInt());

                    TextBoxJudul.Text = Post.Judul;
                    DropDownListAlign.SelectedValue = Post.Align.ToString();
                    TextBoxDeskripsi.Text           = Post.Deskripsi;

                    DivDetail.Visible = true;

                    LoadPost();

                    LabelKeterangan.Text = "Ubah";
                }
            }
        }

        Page.Form.Attributes.Add("enctype", "multipart/form-data");
    }
Ejemplo n.º 3
0
    protected void ButtonTambahPostDetail_Click(object sender, EventArgs e)
    {
        MultiViewPage.SetActiveView(ViewPostDetail);

        DivKonten.Visible        = true;
        DivSingleImage.Visible   = false;
        DivMultipleImage.Visible = false;

        HiddenFieldIDPostDetail.Value         = string.Empty;
        TextBoxDetailNama.Text                = string.Empty;
        DropDownListDetailJenis.Enabled       = true;
        DropDownListDetailJenis.SelectedValue = "1";
        TextBoxDetailKonten.Text              = string.Empty;

        ButtonUploadMultipleImage.Text = "Tambah";
    }
Ejemplo n.º 4
0
    protected void RepeaterPostDetail_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Ubah")
        {
            using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
            {
                MultiViewPage.SetActiveView(ViewPostDetail);

                HiddenFieldIDPostDetail.Value = e.CommandArgument.ToString();
                PostDetail_Class PostDetail_Class = new PostDetail_Class(db);
                TBPostDetail     PostDetail       = PostDetail_Class.GetData(HiddenFieldIDPostDetail.Value.ToInt());
                TextBoxDetailNama.Text = PostDetail.Nama;
                DropDownListDetailJenis.SelectedValue = PostDetail.Jenis.ToString();
                TextBoxDetailKonten.Text = PostDetail.Konten;

                if (DropDownListDetailJenis.SelectedValue.ToInt() == (int)EnumJenisPostDetail.Text)
                {
                    DivKonten.Visible        = true;
                    DivSingleImage.Visible   = false;
                    DivMultipleImage.Visible = false;
                }
                else if (DropDownListDetailJenis.SelectedValue.ToInt() == (int)EnumJenisPostDetail.SingleImage)
                {
                    DivKonten.Visible        = false;
                    DivSingleImage.Visible   = true;
                    DivMultipleImage.Visible = false;

                    LoadDataFoto();
                }
                else
                {
                    DivKonten.Visible        = false;
                    DivSingleImage.Visible   = false;
                    DivMultipleImage.Visible = true;

                    LoadDataFoto();
                }
                DropDownListDetailJenis.Enabled = false;
            }
        }
        else
        {
            using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
            {
                PostDetail_Class PostDetail_Class = new PostDetail_Class(db);
                TBPostDetail     PostDetail       = PostDetail_Class.GetData(e.CommandArgument.ToInt());

                if (PostDetail.Jenis == (int)EnumJenisPostDetail.Text)
                {
                    PostDetail_Class.DeleteData(PostDetail);
                }
                else
                {
                    PostDetailImage_Class PostDetailImage_Class = new PostDetailImage_Class(db);
                    TBPostDetailImage[]   ListPostDetailImage   = PostDetailImage_Class.GetAll().Where(item => item.IDPostDetail == e.CommandArgument.ToInt()).ToArray();

                    foreach (var item in ListPostDetailImage)
                    {
                        FileInfo file = new FileInfo(Server.MapPath("/images/PostDetail/") + (item.IDPostDetail + "-" + item.IDPostDetailImage) + ".jpg");
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }

                    PostDetailImage_Class.DeleteAllData(ListPostDetailImage);
                    PostDetail_Class.DeleteData(e.CommandArgument.ToInt());
                }

                db.SubmitChanges();
            }

            LoadPost();
        }
    }
Ejemplo n.º 5
0
    protected void ButtonDetailKembali_Click(object sender, EventArgs e)
    {
        MultiViewPage.SetActiveView(ViewPost);

        LoadPost();
    }