Beispiel #1
0
    protected void ButtonSimpan_Click(object sender, EventArgs e)
    {
        try
        {
            using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
            {
                var Pengguna = (PenggunaLogin)Session["PenggunaLogin"];
                StokProduk_Class StokProduk_Class = new StokProduk_Class(db);

                //VALIDASI
                foreach (RepeaterItem item in RepeaterStokProduk.Items)
                {
                    Label   LabelIDStokProduk = (Label)item.FindControl("LabelIDStokProduk");
                    TextBox TextBoxDiscountStorePersentase       = (TextBox)item.FindControl("TextBoxDiscountStorePersentase");
                    TextBox TextBoxDiscountStoreNominal          = (TextBox)item.FindControl("TextBoxDiscountStoreNominal");
                    TextBox TextBoxDiscountConsignmentPersentase = (TextBox)item.FindControl("TextBoxDiscountConsignmentPersentase");
                    TextBox TextBoxDiscountConsignmentNominal    = (TextBox)item.FindControl("TextBoxDiscountConsignmentNominal");

                    if (!string.IsNullOrWhiteSpace(TextBoxDiscountStorePersentase.Text) && !string.IsNullOrWhiteSpace(TextBoxDiscountStoreNominal.Text))
                    {
                        WMSError.Pesan("Discount Store hanya boleh memilih antara Discount Persentase atau Nominal");
                    }

                    if (!string.IsNullOrWhiteSpace(TextBoxDiscountConsignmentPersentase.Text) && !string.IsNullOrWhiteSpace(TextBoxDiscountConsignmentNominal.Text))
                    {
                        WMSError.Pesan("Discount Consignment hanya boleh memilih antara Discount Persentase atau Nominal");
                    }

                    var StokProduk = db.TBStokProduks.FirstOrDefault(item2 => item2.IDStokProduk == LabelIDStokProduk.Text.ToInt());

                    if (!string.IsNullOrWhiteSpace(TextBoxDiscountStorePersentase.Text) && TextBoxDiscountStorePersentase.Text != "0")
                    {
                        StokProduk.EnumDiscountStore = (int)EnumDiscount.Persentase;
                        StokProduk.DiscountStore     = TextBoxDiscountStorePersentase.Text.ToDecimal();
                    }
                    else if (!string.IsNullOrWhiteSpace(TextBoxDiscountStoreNominal.Text) && TextBoxDiscountStoreNominal.Text != "0")
                    {
                        StokProduk.EnumDiscountStore = (int)EnumDiscount.Nominal;
                        StokProduk.DiscountStore     = TextBoxDiscountStoreNominal.Text.ToDecimal();
                    }
                    else
                    {
                        StokProduk.EnumDiscountStore = (int)EnumDiscount.TidakAda;
                        StokProduk.DiscountStore     = 0;
                    }

                    if (!string.IsNullOrWhiteSpace(TextBoxDiscountConsignmentPersentase.Text) && TextBoxDiscountConsignmentPersentase.Text != "0")
                    {
                        StokProduk.EnumDiscountKonsinyasi = (int)EnumDiscount.Persentase;
                        StokProduk.DiscountKonsinyasi     = TextBoxDiscountConsignmentPersentase.Text.ToDecimal();
                    }
                    else if (!string.IsNullOrWhiteSpace(TextBoxDiscountConsignmentNominal.Text) && TextBoxDiscountConsignmentNominal.Text != "0")
                    {
                        StokProduk.EnumDiscountKonsinyasi = (int)EnumDiscount.Nominal;
                        StokProduk.DiscountKonsinyasi     = TextBoxDiscountConsignmentNominal.Text.ToDecimal();
                    }
                    else
                    {
                        StokProduk.EnumDiscountKonsinyasi = (int)EnumDiscount.TidakAda;
                        StokProduk.DiscountKonsinyasi     = 0;
                    }
                }

                db.SubmitChanges();

                LoadData();
            }
        }
        catch (Exception ex)
        {
            AlertMessage_Class.ShowException(this, ex, Request.Url.PathAndQuery);
        }
    }
Beispiel #2
0
    protected void ButtonOk_Click(object sender, EventArgs e)
    {
        try
        {
            using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
            {
                PenggunaLogin Pengguna = (PenggunaLogin)Session["PenggunaLogin"];

                DiscountEvent_Class ClassDiscountEvent = new DiscountEvent_Class(db);

                if (ButtonOk.Text == "Tambah")
                {
                    var DiscountEvent = ClassDiscountEvent.Tambah(Pengguna.IDPengguna, DropDownListTempat.SelectedValue.ToInt(), TextBoxNama.Text, TextBoxTanggalAwal.Text.ToDateTime(), TextBoxTanggalAkhir.Text.ToDateTime(), (EnumStatusDiscountEvent)DropDownListEnumStatusDiscountEvent.SelectedValue.ToInt());
                    db.SubmitChanges();

                    Response.Redirect("Pengaturan.aspx?id=" + DiscountEvent.IDDiscountEvent);
                }
                else if (ButtonOk.Text == "Ubah")
                {
                    var DiscountEvent = ClassDiscountEvent.Ubah(Request.QueryString["id"].ToInt(), Pengguna.IDPengguna, DropDownListTempat.SelectedValue.ToInt(), TextBoxNama.Text, TextBoxTanggalAwal.Text.ToDateTime(), TextBoxTanggalAkhir.Text.ToDateTime(), (EnumStatusDiscountEvent)DropDownListEnumStatusDiscountEvent.SelectedValue.ToInt());

                    db.TBDiscounts.DeleteAllOnSubmit(DiscountEvent.TBDiscounts.ToArray());

                    //VALIDASI
                    foreach (RepeaterItem item in RepeaterStokProduk.Items)
                    {
                        Label   LabelIDStokProduk = (Label)item.FindControl("LabelIDStokProduk");
                        TextBox TextBoxDiscountStorePersentase       = (TextBox)item.FindControl("TextBoxDiscountStorePersentase");
                        TextBox TextBoxDiscountStoreNominal          = (TextBox)item.FindControl("TextBoxDiscountStoreNominal");
                        TextBox TextBoxDiscountConsignmentPersentase = (TextBox)item.FindControl("TextBoxDiscountConsignmentPersentase");
                        TextBox TextBoxDiscountConsignmentNominal    = (TextBox)item.FindControl("TextBoxDiscountConsignmentNominal");

                        if (!string.IsNullOrWhiteSpace(TextBoxDiscountStorePersentase.Text) && !string.IsNullOrWhiteSpace(TextBoxDiscountStoreNominal.Text))
                        {
                            WMSError.Pesan("Discount Store hanya boleh memilih antara Discount Persentase atau Nominal");
                        }

                        if (!string.IsNullOrWhiteSpace(TextBoxDiscountConsignmentPersentase.Text) && !string.IsNullOrWhiteSpace(TextBoxDiscountConsignmentNominal.Text))
                        {
                            WMSError.Pesan("Discount Consignment hanya boleh memilih antara Discount Persentase atau Nominal");
                        }

                        var StokProduk = db.TBStokProduks.FirstOrDefault(item2 => item2.IDStokProduk == LabelIDStokProduk.Text.ToInt());

                        var Discount = new TBDiscount
                        {
                            //IDDiscount
                            TBDiscountEvent = DiscountEvent,
                            TBStokProduk    = StokProduk
                        };

                        if (!string.IsNullOrWhiteSpace(TextBoxDiscountStorePersentase.Text) && TextBoxDiscountStorePersentase.Text != "0")
                        {
                            Discount.EnumDiscountStore = (int)EnumDiscount.Persentase;
                            Discount.DiscountStore     = TextBoxDiscountStorePersentase.Text.ToDecimal();
                        }
                        else if (!string.IsNullOrWhiteSpace(TextBoxDiscountStoreNominal.Text) && TextBoxDiscountStoreNominal.Text != "0")
                        {
                            Discount.EnumDiscountStore = (int)EnumDiscount.Nominal;
                            Discount.DiscountStore     = TextBoxDiscountStoreNominal.Text.ToDecimal();
                        }
                        else
                        {
                            Discount.EnumDiscountStore = (int)EnumDiscount.TidakAda;
                            Discount.DiscountStore     = 0;
                        }

                        if (!string.IsNullOrWhiteSpace(TextBoxDiscountConsignmentPersentase.Text) && TextBoxDiscountConsignmentPersentase.Text != "0")
                        {
                            Discount.EnumDiscountKonsinyasi = (int)EnumDiscount.Persentase;
                            Discount.DiscountKonsinyasi     = TextBoxDiscountConsignmentPersentase.Text.ToDecimal();
                        }
                        else if (!string.IsNullOrWhiteSpace(TextBoxDiscountConsignmentNominal.Text) && TextBoxDiscountConsignmentNominal.Text != "0")
                        {
                            Discount.EnumDiscountKonsinyasi = (int)EnumDiscount.Nominal;
                            Discount.DiscountKonsinyasi     = TextBoxDiscountConsignmentNominal.Text.ToDecimal();
                        }
                        else
                        {
                            Discount.EnumDiscountKonsinyasi = (int)EnumDiscount.TidakAda;
                            Discount.DiscountKonsinyasi     = 0;
                        }

                        if (Discount.EnumDiscountStore != (int)EnumDiscount.TidakAda || Discount.EnumDiscountKonsinyasi != (int)EnumDiscount.TidakAda)
                        {
                            db.TBDiscounts.InsertOnSubmit(Discount);
                        }
                    }

                    db.SubmitChanges();

                    Response.Redirect("Default.aspx");
                }
            }
        }
        catch (Exception ex)
        {
            AlertMessage_Class.ShowException(this, ex, Request.Url.PathAndQuery);
        }
    }