Example #1
0
        private void tsbSave_Click(object sender, EventArgs e)
        {
            if (cboUser.Text == "")
            {
                MessageBox.Show("Pilih user terlebih dahulu", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (cboFormReport.Text == "")
            {
                MessageBox.Show("Pilih Form/Report", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (chkOpen.Checked == false && chkAdd.Checked == false && chkEdit.Checked == false && chkDelete.Checked == false)
            {
                MessageBox.Show("Pilih salah satu hak akses", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                var userAccess = new UserAccess();

                userAccess.UserId = new Guid(txtUserId.Text);

                if (rbForm.Checked)
                {
                    userAccess.ObjectType = 1;
                }
                else
                {
                    userAccess.ObjectType = 2;
                }
                userAccess.ObjectName = cboFormReport.Text;
                userAccess.IsOpen     = chkOpen.Checked;
                userAccess.IsAdd      = chkAdd.Checked;
                userAccess.IsEdit     = chkEdit.Checked;
                userAccess.IsDelete   = chkDelete.Checked;

                if (formMode == FormMode.Add)
                {
                    if (userAccessRepository.IsUserAccessExist(cboUser.Text, cboFormReport.Text))
                    {
                        MessageBox.Show("User '" + cboUser.Text + "' sudah diberi hak akses untuk '" + cboFormReport.Text + "'",
                                        "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        userAccessRepository.Save(userAccess);
                        GetLastUserAccess();
                    }
                }
                else if (formMode == FormMode.Edit)
                {
                    userAccess.ID = new Guid(txtID.Text);
                    userAccessRepository.Update(userAccess);
                }

                LoadUserAccess();
                DisableForm();

                formMode  = FormMode.View;
                this.Text = "Hak Akses User";
            }
        }