Esempio n. 1
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            var json = new WebClient().DownloadString("http://localhost:1908/Mahasiswa");
            var data = JsonConvert.DeserializeObject <List <Mahasiswa> >(json);

            if (textBoxNIM.Text != "" &&
                textBoxNama.Text != "" &&
                textBoxProdi.Text != "" &&
                textBoxAngkatan.Text != "")
            {
                if (textBoxNIM.Text.Length <= 12 &&
                    textBoxAngkatan.Text.Length <= 4 &&
                    textBoxProdi.Text.Length <= 30 &&
                    textBoxNama.Text.Length <= 20)
                {
                    try
                    {
                        Mahasiswa mhs = new Mahasiswa();
                        mhs.nim      = textBoxNIM.Text;
                        mhs.nama     = textBoxNama.Text;
                        mhs.prodi    = textBoxProdi.Text;
                        mhs.angkatan = textBoxAngkatan.Text;

                        ClassData classData = new ClassData();
                        classData.updateDatabase(mhs);
                        MessageBox.Show("Data successfuly updated");

                        dtMahasiswa.DataSource = classData.getAllData();
                        TampilData();
                    }
                    catch
                    {
                    }
                }
                else
                {
                    MessageBox.Show("Please check your data");
                }
            }
            else
            {
                MessageBox.Show("Please check your data");
            }
        }
Esempio n. 2
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            var json = new WebClient().DownloadString("http://localhost:1908/Mahasiswa");
            var data = JsonConvert.DeserializeObject <List <Mahasiswa> >(json);

            if (MessageBox.Show("Are you sure you want to delete", "DeleteMahasiswa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    ClassData classData = new ClassData();
                    classData.deleteMahasiswa(textBoxNIM.Text);
                    dtMahasiswa.DataSource = classData.getAllData();
                    MessageBox.Show("Data successfuly deleted");
                    ClientB home = new ClientB();
                    this.Hide();
                    home.Show();
                }
                catch (Exception ex)
                {
                }
            }
        }