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 Form_organisation_Shown(object sender, EventArgs e) { if (!Program.System_user.Has_permission(Class_enum.User_permission.VIEW_ORGANISATION) && !Program.System_user.Has_permission(Class_enum.User_permission.ADD_EDIT_ORGANISATION)) { MessageBox.Show("You do not have sufficient permission to perform this action!", "ACCESS DENIED", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } // ##################### GRD_CONTACT ##################### grd_contact.DataSource = Organisation_contact_ds.Select_organisation_contact(OrganisationID); 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 empty string will enter dbnull to datagridviewcolumn ((DataTable)grd_contact.DataSource).Columns["remark"].AllowDBNull = true; // ##################### END GRD_CONTACT ##################### Country_ds.sp_select_countryDataTable dttable_country = Country_ds.Select_country(); // ##################### GRD_BRANCH ##################### Organisation_branch_ds.sp_select_organisation_branch_by_orgDataTable dttable_branch = Organisation_branch_ds.Select_organisation_branch_by_org(OrganisationID); dttable_branch.Columns["address"].AllowDBNull = true; dttable_branch.Columns["city"].AllowDBNull = true; dttable_branch.Columns["state"].AllowDBNull = true; dttable_branch.Columns["postcode"].AllowDBNull = true; dttable_branch.Columns.Remove("modified_by"); // no need show this grd_branch.DataSource = dttable_branch; grd_branch.Columns["organisation_branch"].Visible = false; grd_branch.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True; grd_branch.AutoResizeColumns(); grd_branch.AutoResizeRows(); Class_datagridview.Set_max_length_grd_col_same_with_datatable_col(grd_branch, "branch_name", "address", "city", "state", "postcode"); Class_datagridview.Replace_column_with_combobox_column(grd_branch, "country", dttable_country.Copy(), "country_name", "country"); grd_branch.Columns["address"].DefaultCellStyle.WrapMode = DataGridViewTriState.True; // ##################### END GRD_BRANCH ##################### Class_combobox.Setup_combobox(cmb_type, Organisation_type_ds.Select_organisation_type(), "organisation_type_description", "organisation_type"); cmb_type.SelectedValue = 1; // set default value to CORPORATE Class_combobox.Setup_combobox(cmb_country, dttable_country.Copy(), "country_name", "country"); cmb_country.SelectedValue = 133; // set default to malaysia if (OrganisationID == 0) { return; // zero means adding new org } Organisation_ds.sp_select_organisationDataTable dttable_org = Organisation_ds.Select_organisation(OrganisationID); if (dttable_org.Rows.Count == 0) { return; } txt_name.Text = dttable_org[0].name; txt_registration_no.Text = dttable_org[0].registration_no; cmb_country.SelectedValue = dttable_org[0].country; cmb_type.SelectedValue = dttable_org[0].organisation_type; txt_url.Text = dttable_org[0].url; }