Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private void Setup_grd_person_organisation()
        {
            if (cmb_type.SelectedItem == null)
            {
                return;
            }

            grd_main.DataSource = null;

            if (cmb_type.SelectedItem.ToString().ToUpper() == "PERSON")
            {
                grd_main.DataSource = Person_ds.Select_person_simplified();
            }
            else
            {
                grd_main.DataSource = Organisation_branch_ds.Select_organisation_simplified();
            }

            Class_datagridview.Hide_columns(grd_main, "person", "organisation_branch", "organisation");

            grd_main.AutoResizeColumns();

            Apply_filter_grd();
        }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
        private void Btn_ok_Click(object sender, EventArgs e)
        {
            if (!Program.System_user.Has_permission(Class_enum.User_permission.ADD_EDIT_PERSON))
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
                return;
            }

            if (txt_name.Text.Trim() == "" || txt_ic_no.Text.Trim() == "")
            {
                MessageBox.Show("Name and IC no. are required.", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Person_contact_ds.sp_select_person_contactDataTable dttable_contact = (Person_contact_ds.sp_select_person_contactDataTable)grd_contact.DataSource;
            dttable_contact.AcceptChanges();

            // must use row["remark"] instead of row.remark because row.remarks is string type and cannot be dbnull. row["remark"] is object type and can be dbnull
            var query_check_empty = from row in dttable_contact
                                    where row.contact.Trim() == "" && (row["remark"] != DBNull.Value && row.remark.Trim() != "")
                                    select row;

            if (query_check_empty.Count() > 0)
            {
                MessageBox.Show("Contact cannot be empty. Please check and retry.",
                                "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var query_contact = from row in dttable_contact
                                group row by row.contact into grp
                                where grp.Count() > 1
                                select grp.Key;

            if (query_contact.Count() > 0)
            {
                MessageBox.Show("Duplicate contact detected. Please check and retry.",
                                "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // set byte image to null if no image. null value will set db column to null
            byte[] byte_image = null;
            if (picbox_image.Image != null)
            {
                Image img = picbox_image.Image;
                using (MemoryStream ms = new MemoryStream())
                {
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte_image = ms.ToArray();
                }
            }

            if (PersonID == 0)
            {
                // insert
                PersonID = Person_ds.Insert_person(txt_name.Text.Trim(), txt_ic_no.Text.Trim(),
                                                   byte_image, (int)cmb_type.SelectedValue, txt_driving_license.Text.Trim(),
                                                   (cmb_gender.SelectedValue.ToString() == "MALE"), (int)cmb_race.SelectedValue,
                                                   txt_address.Text.Trim(), txt_city.Text.Trim(), txt_state.Text.Trim(),
                                                   txt_postcode.Text.Trim(), (short)cmb_country.SelectedValue, txt_occupation.Text.Trim(),
                                                   txt_company.Text.Trim(), txt_url.Text.Trim());
            }
            else
            {
                // update
                Person_ds.Update_person(PersonID, txt_name.Text.Trim(), txt_ic_no.Text.Trim(),
                                        byte_image, (int)cmb_type.SelectedValue, txt_driving_license.Text.Trim(),
                                        (cmb_gender.SelectedValue.ToString() == "MALE"), (int)cmb_race.SelectedValue,
                                        txt_address.Text.Trim(), txt_city.Text.Trim(), txt_state.Text.Trim(),
                                        txt_postcode.Text.Trim(), (short)cmb_country.SelectedValue, txt_occupation.Text.Trim(),
                                        txt_company.Text.Trim(), txt_url.Text.Trim());
            }
            // at this point, personID must be positive integer.
            if (PersonID == 0)
            {
                MessageBox.Show("An error has occurred.", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // upload contact information
            DataColumn dt_col1 = new DataColumn("modified_by", typeof(int))
            {
                DefaultValue = Program.System_user.UserID
            };

            dttable_contact.Columns.Add(dt_col1);

            Bulkcopy_table_ds.Delete_by_user();

            using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.VehicleDealershipConnectionString))
            {
                conn.Open();

                using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn))
                {
                    bulkCopy.DestinationTableName = "[misc].[bulkcopy_table]";

                    try
                    {
                        bulkCopy.ColumnMappings.Add("contact", "nvarchar1");
                        bulkCopy.ColumnMappings.Add("remark", "nvarchar2");
                        bulkCopy.ColumnMappings.Add("modified_by", "created_by");
                        bulkCopy.WriteToServer(dttable_contact);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("An error has occurred. Vehicle groups cannot be updated. \n\n Message: " +
                                        ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                conn.Close();
            }

            Person_contact_ds.Update_insert_person_contact(PersonID);

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 5
0
        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();
        }