// Membuka menu Home jika di-klik
        private void button4_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            Home home = new Home();

            home.ShowDialog();
        }
Beispiel #2
0
 // Mencari data user berdasarkan username jika password benar
 private void roundButton1_Click(object sender, EventArgs e)
 {
     if (unameBox.Text == "" || passBox.Text == "")
     {
         MessageBox.Show("Masukkan username dan password terlebih dahulu!", "Informasi Login kosong", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         using (var db = new DBModel())
         {
             var query = (from akun in db.Akun where akun.Uname == unameBox.Text select akun).FirstOrDefault();
             if (query == null) //check if query null
             {
                 MessageBox.Show("Data tidak ada!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 unameBox.Text = "";
                 passBox.Text  = "";
             }
             else if ((query.Uname == unameBox.Text) && (query.Pass == passBox.Text)) // masih error di sini buat login. coba pakai try except
             {
                 Data data = new Data();
                 data.dataProfil(query.First_Name, query.Last_Name, query.Email, (query.Id).ToString(), query.Phone, query.Uname);
                 this.Visible = false;
                 Home dashboard = new Home();
                 dashboard.ShowDialog();
             }
             else if ((query.Uname == unameBox.Text) && (query.Pass != passBox.Text))
             {
                 MessageBox.Show("Password yang dimasukkan salah!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 passBox.Text = "";
             }
         }
     }
 }
        // Membuka form EditForm jika button edit di-klik dengan syarat event sudah di "add to task"
        private void button3_Click(object sender, EventArgs e)
        {
            EditForm edit = new EditForm(lblName.Text, lblNote.Text, lblStatus.Text, "Event");

            edit.ShowDialog();

            if (Data.selesai) // tanda kegiatannya sudah diselesaikan
            {
                this.Close();
                Home home = new Home();
                home.ShowDialog();
            }
            else
            {
                lblStatus.Text = DataTasks.e_status; lblNote.Text = DataTasks.e_note;
            }
        }
        // Memproses data pengubahan yang di-input user
        private void BtnSave_Click(object sender, EventArgs e)
        {
            long    nomor    = 0;
            Boolean progress = true;

            // Pengecekan isi textbox
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
            {
                MessageBox.Show("Informasi tidak boleh ada yang kosong!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // Cek apakah format nomor telepon sudah benar
                try
                {
                    nomor = long.Parse(textBox2.Text);
                }

                catch (FormatException)
                {
                    MessageBox.Show($"Nomor hanya boleh mengandung angka!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    progress = false;
                }

                // Cek apakah format E-mail sudah benar
                try
                {
                    var addr = new System.Net.Mail.MailAddress(textBox4.Text);
                }
                catch
                {
                    MessageBox.Show("Format E-mail tidak benar!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    progress = false;
                }

                // Memulai proses edit jika semua format pengisian sudah benar
                if (progress == true)
                {
                    Data data = new Data();
                    using (var db = new DBModel())
                    {
                        var profil = db.Akun.SingleOrDefault(k => k.Uname == Data.uname);
                        var ex     = db.Experience.SingleOrDefault(k => k.Akun == Data.uname);
                        profil.First_Name = textBox1.Text;
                        profil.Last_Name  = textBox3.Text;
                        profil.Phone      = textBox2.Text;
                        profil.Email      = textBox4.Text;
                        db.SaveChanges();
                        var query = (from akun in db.Akun where akun.Uname == Data.uname select akun).FirstOrDefault();
                        data.dataProfil(query.First_Name, query.Last_Name, query.Email, (query.Id).ToString(), query.Phone, query.Uname);
                    }
                    MessageBox.Show("Pergantian data berhasil!", "Notifikasi", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.Visible = false;
                    Profile propil = new Profile();
                    Home    home   = new Home();
                    propil.Visible = false;
                    home.ShowDialog();
                }
            }
        }