Exemple #1
0
        private ListPengguna()
        {
            InitializeComponent();
            penggunaService = new PenggunaService();

            dataGridViewPengguna.DataSource         = penggunaService.FindWithRole();
            dataGridViewPengguna.Columns[0].Visible = false;
        }
Exemple #2
0
        private void btnHapus_Click(object sender, EventArgs e)
        {
            int id       = int.Parse(dataGridViewPengguna.SelectedRows[0].Cells[0].Value.ToString());
            var pengguna = penggunaService.Get(id);

            DialogResult result = MessageBox.Show("Hapus data " + pengguna.Nama + " ?", "Hapus", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result == DialogResult.OK)
            {
                penggunaService.Delete(pengguna);
                dataGridViewPengguna.DataSource = penggunaService.FindWithRole();
            }
        }
Exemple #3
0
        private void btnSimpan_Click(object sender, EventArgs e)
        {
            StringBuilder sb     = new StringBuilder();
            bool          IsPass = true;

            if (string.IsNullOrEmpty(textBoxNamaPengguna.Text))
            {
                IsPass = false;
                sb.Append("- Nama Pengguna harus diisi \n");
            }

            if (string.IsNullOrEmpty(textBoxUsername.Text))
            {
                IsPass = false;
                sb.Append("- Username harus diisi \n");
            }

            if (string.IsNullOrEmpty(textBoxPassword.Text))
            {
                IsPass = false;
                sb.Append("- Password harus diisi \n");
            }

            if (comboBoxRole.SelectedValue == null)
            {
                IsPass = false;
                sb.Append("- Role harus diisi \n");
            }

            if (!IsPass)
            {
                MessageBox.Show(sb.ToString(), "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var role = roleService.Get(int.Parse(comboBoxRole.SelectedValue.ToString()));

            var pengguna = new Pengguna()
            {
                Nama     = textBoxNamaPengguna.Text,
                Username = textBoxUsername.Text,
                Password = textBoxPassword.Text,
                RoleId   = role.Id
            };

            penggunaService.Post(pengguna);

            this.ParentForm.dataGridViewPengguna.DataSource = penggunaService.FindWithRole();
            this.Dispose();
        }