예제 #1
0
        private void button2_Click(object sender, EventArgs e) // Button Simpan
        {
            if (flagperintah == 1)                             //tambah data
            {
                //txtKodePro.ReadOnly = false;
                if (cektxt() == true)
                {
                    //errorProvider1.Clear();

                    //iNBC.Entity.Promo Pro = new Entity.Promo(txtKodePro.Text,txtNama.Text,float.Parse(txtDiskon.Text),DateTime.Parse(dateStart.Text),DateTime.Parse(dateEnd.Text),cmbStatusPro.Text,1);


                    try
                    {
                        //PRO_C.addPromo(Pro);
                        clearall();
                        this.Hide();
                        PengelolaanPromo myParent = (PengelolaanPromo)this.Parent;
                        myParent.enable();
                        myParent.Show();
                    }
                    catch (SqlException ex)
                    {
                        if (ex.Number == 2627)
                        {
                            DialogResult drErrorSQL = MessageBox.Show("Kode Promo Tersebut sudah pernah digunakan, silahkan inputkan kode promo yang lain", "iNBC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
            }
            else
            {
                //txtKodePro.ReadOnly = true;
                if (cektxt() == true)
                {
                    if (System.DateTime.Now.Year - DateTime.Parse(dateBirth.Text).Year < 13)
                    {
                        DialogResult dr = MessageBox.Show("Umur customer minimal adalah 13 tahun, silahkan periksa kembali data yang dimasukan", "iNBC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        errorProvider1.Clear();

                        iNBC.Entity.Customer Cus = new Entity.Customer(txtID.Text, txtNama.Text, DateTime.Parse(dateBirth.Text), cmbJK.Text, txtAlamat.Text, txtTelpon.Text, txtEmail.Text, txtAlergi.Text, System.DateTime.Now, 0, txtPass.Text, 1);

                        DialogResult dr = MessageBox.Show("Apakah anda yakin ingin mengubah data customer " + temp_customer, "iNBC",
                                                          MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);

                        if (dr == DialogResult.Yes)
                        {
                            CUS_C.editCustomer(Cus, txtID.Text);

                            DialogResult drX = MessageBox.Show("Data Customer berhasil diubah", "iNBC", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        clearall();
                        this.Hide();
                        PengelolaanCustomer myParent = (PengelolaanCustomer)this.Parent;
                        myParent.Enableedit();
                    }
                }
            }
        }