public void RoleArrToForm(Role role) { RoleArr roleArr = new RoleArr(); roleArr.Fill(); cmb_Role.DataSource = roleArr; cmb_Role.ValueMember = "Id"; cmb_Role.DisplayMember = "JobTitle"; if (role != null) { cmb_Role.SelectedValue = role.Id; } }
private void RoleArrToForm(Role curRole) { RoleArr roleArr = new RoleArr(); roleArr.Fill(); listbox_Role.DataSource = roleArr; listbox_Role.ValueMember = "Id"; listbox_Role.DisplayMember = "JobTitle"; if (curRole != null) { listbox_Role.SelectedValue = curRole.Id; } }
private void btn_Save_Click(object sender, EventArgs e) { if (CheckForm()) { Role role = new Role(); role = FormToRole(); RoleArr oldRoleArr = new RoleArr(); oldRoleArr.Fill(); if (!oldRoleArr.IsContain(role.JobTitle)) { if (role.Id == 0) { if (role.Insert()) { MessageBox.Show("Data saved successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearForm(); RoleArr roleArr = new RoleArr(); roleArr.Fill(); role = roleArr.GetRoleWithMaxId(); RoleArrToForm(role); } } else { if (role.Update()) { MessageBox.Show("Data updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearForm(); RoleArr roleArr = new RoleArr(); roleArr.Fill(); role = roleArr.GetRoleWithMaxId(); RoleArrToForm(role); } } } else { MessageBox.Show("Role already exsits", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ClearForm(); } } }