private void Setup_form_person() { lbl_ic_reg.Text = "IC no.:"; split_cont_person_org.Panel2Collapsed = true; Person_ds.sp_select_personDataTable dttable_person = Person_ds.Select_person(_person_orgbranch_id); if (dttable_person.Rows.Count > 0) { txt_name.Text = dttable_person[0].name; txt_ic_reg.Text = dttable_person[0].ic_no; txt_type.Text = dttable_person[0].person_type_description; txt_driving_license.Text = dttable_person[0].driving_license; txt_gender.Text = dttable_person[0].gender ? "MALE" : "FEMALE"; txt_race.Text = dttable_person[0].race_description; txt_address.Text = dttable_person[0].address; txt_city.Text = dttable_person[0].city; txt_state.Text = dttable_person[0].state; txt_postcode.Text = dttable_person[0].postcode; txt_country.Text = dttable_person[0].country_name; link_lbl_url.Text = dttable_person[0].url; } grd_contact.DataSource = null; grd_contact.DataSource = Person_contact_ds.Select_person_contact(_person_orgbranch_id); }
private void Form_person_Shown(object sender, EventArgs e) { if (!Program.System_user.Has_permission(Class_enum.User_permission.VIEW_PERSON) && !Program.System_user.Has_permission(Class_enum.User_permission.ADD_EDIT_PERSON)) { MessageBox.Show("You do not have sufficient permission to perform this action!", "ACCESS DENIED", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } grd_contact.DataSource = Person_contact_ds.Select_person_contact(PersonID); grd_contact.AutoResizeColumns(); // database column nvarchar length is 100 Class_datagridview.Set_max_length_grd_col_same_with_datatable_col(grd_contact, "contact", "remark"); // allow dbnull because user is ((DataTable)grd_contact.DataSource).Columns["remark"].AllowDBNull = true; Class_combobox.Setup_combobox(cmb_type, Person_type_ds.Select_person_type(), "person_type_description", "person_type"); cmb_type.SelectedValue = 1; // set default to INDIVIDUAL Class_combobox.Setup_combobox(cmb_race, Race_ds.Select_race(), "race_description", "race"); Class_combobox.Setup_combobox(cmb_country, Country_ds.Select_country(), "country_name", "country"); cmb_country.SelectedValue = 133; // set default to malaysia DataTable dttable_gender = new DataTable(); dttable_gender.Columns.Add("display"); dttable_gender.Columns.Add("value"); dttable_gender.Rows.Add("MALE", "MALE"); dttable_gender.Rows.Add("FEMALE", "FEMALE"); Class_combobox.Setup_combobox(cmb_gender, dttable_gender, "display", "value"); if (PersonID == 0) { return; // if zero means adding new person instead of editing } using (Person_ds.sp_select_personDataTable dttable_person = Person_ds.Select_person(PersonID)) { if (dttable_person.Rows.Count == 0) { return; } txt_name.Text = dttable_person[0].name; txt_ic_no.Text = dttable_person[0].ic_no; if (dttable_person.Rows[0]["image"] != DBNull.Value) { picbox_image.Image = Image.FromStream(new MemoryStream(dttable_person[0].image)); } cmb_type.SelectedValue = dttable_person[0].person_type; txt_driving_license.Text = dttable_person[0].driving_license; cmb_gender.SelectedValue = (dttable_person[0].gender) ? "MALE" : "FEMALE"; cmb_race.SelectedValue = dttable_person[0].race; txt_address.Text = dttable_person[0].address; txt_city.Text = dttable_person[0].city; txt_state.Text = dttable_person[0].state; txt_postcode.Text = dttable_person[0].postcode; cmb_country.SelectedValue = dttable_person[0].country; txt_occupation.Text = dttable_person[0].occupation; txt_company.Text = dttable_person[0].company; txt_url.Text = dttable_person[0].url; } }
private void Setup_grd_main(int int_id = 0) { grd_main.DataSource = null; switch (_select_for) { case "": if (cmb_type.ComboBox.SelectedItem.ToString() == "PERSON") { grd_main.DataSource = Person_ds.Select_person(-1); Class_datagridview.Hide_columns(grd_main, new string[] { "person", "image", "person_type", "gender", "race", "country" }); } else { grd_main.DataSource = Organisation_branch_ds.Select_organisation_branch_with_org_details(-1); Class_datagridview.Hide_columns(grd_main, new string[] { "organisation", "organisation_type", "country" }); } break; case "SALESPERSON": if (cmb_type.ComboBox.SelectedItem.ToString() == "PERSON") { grd_main.DataSource = Person_ds.Select_person_not_salesperson(); } else { grd_main.DataSource = Organisation_branch_ds.Select_organisation_not_salesperson(); } break; case "FINANCE": cmb_type.ComboBox.SelectedValue = "ORGANISATION"; cmb_type.Enabled = false; // ONLY organisation allowed for finance grd_main.DataSource = Organisation_branch_ds.Select_organisation_not_finance(); break; case "INSURANCE": cmb_type.ComboBox.SelectedValue = "ORGANISATION"; cmb_type.Enabled = false; // ONLY organisation allowed for insurance grd_main.DataSource = Organisation_branch_ds.Select_organisation_not_insurance(); break; case "LOAN": cmb_type.ComboBox.SelectedValue = "ORGANISATION"; cmb_type.Enabled = false; // ONLY organisation allowed for loan grd_main.DataSource = Organisation_branch_ds.Select_organisation_not_loan(); break; } if (cmb_type.ComboBox.SelectedItem.ToString() == "PERSON") { Class_datagridview.Hide_columns(grd_main, new string[] { "person" }); if (int_id != 0) { Class_datagridview.Select_row_by_value(grd_main, "person", int_id); } btn_add.Enabled = Program.System_user.Has_permission(Class_enum.User_permission.ADD_EDIT_PERSON); addToolStripMenuItem.Enabled = Program.System_user.Has_permission(Class_enum.User_permission.ADD_EDIT_PERSON); btn_edit.Enabled = Program.System_user.Has_permission(Class_enum.User_permission.ADD_EDIT_PERSON) || Program.System_user.Has_permission(Class_enum.User_permission.VIEW_PERSON); } else { Class_datagridview.Hide_columns(grd_main, new string[] { "organisation_branch", "organisation" }); if (int_id != 0) { Class_datagridview.Select_row_by_value(grd_main, "organisation", int_id); } btn_add.Enabled = Program.System_user.Has_permission(Class_enum.User_permission.ADD_EDIT_ORGANISATION); addToolStripMenuItem.Enabled = Program.System_user.Has_permission(Class_enum.User_permission.ADD_EDIT_ORGANISATION); btn_edit.Enabled = Program.System_user.Has_permission(Class_enum.User_permission.ADD_EDIT_ORGANISATION) || Program.System_user.Has_permission(Class_enum.User_permission.VIEW_ORGANISATION); } Class_datagridview.Convert_column_to_link_column(grd_main, "url", "url"); grd_main.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True; grd_main.AutoResizeColumns(); grd_main.AutoResizeRows(); Apply_search_filter_to_grd_main(); }