예제 #1
0
        public Form_edit_vehicle_model(int int_group = 0, int int_model = 0)
        {
            InitializeComponent();

            cmb_brand.DisplayMember = "display";
            cmb_brand.ValueMember   = "value";
            cmb_brand.DataSource    = Combobox_options_ds.Option_vehicle_brand();

            cmb_fuel_type.DisplayMember = "display";
            cmb_fuel_type.ValueMember   = "value";
            cmb_fuel_type.DataSource    = Combobox_options_ds.Select_fuel_type();

            cmb_transmission.DisplayMember = "display";
            cmb_transmission.ValueMember   = "value";
            cmb_transmission.DataSource    = Combobox_options_ds.Select_transmission();

            if (int_group != 0)
            {
                Vehicle_brand_ds.vehicle_brandDataTable dttable_brand = Vehicle_brand_ds.Select_veh_brand_by_veh_group(int_group);

                if (dttable_brand.Rows.Count > 0)
                {
                    cmb_brand.SelectedValue = dttable_brand.Rows[0]["vehicle_brand"];
                }

                cmb_group.SelectedValue = int_group;
            }
            if (int_model != 0)
            {
                Model_id = int_model;
                Vehicle_model_ds.sp_select_vehicle_modelDataTable dttable = Vehicle_model_ds.
                                                                            Select_vehicle_model(-1, -1, -1, int_model);

                if (dttable.Rows.Count > 0)
                {
                    _str_ori_edit_model_name       = dttable.Rows[0]["vehicle_model_name"].ToString();
                    txt_model_name.Text            = dttable.Rows[0]["vehicle_model_name"].ToString();
                    cmb_brand.SelectedValue        = dttable.Rows[0]["vehicle_brand"].ToString();
                    txt_country.Text               = dttable.Rows[0]["country_name"].ToString();
                    cmb_group.SelectedValue        = dttable.Rows[0]["vehicle_group"].ToString();
                    num_engine.Value               = int.Parse(dttable.Rows[0]["engine_capacity"].ToString());
                    num_no_of_door.Value           = int.Parse(dttable.Rows[0]["no_of_door"].ToString());
                    num_seat_capacity.Value        = int.Parse(dttable.Rows[0]["seat_capacity"].ToString());
                    cmb_fuel_type.SelectedValue    = int.Parse(dttable.Rows[0]["fuel_type"].ToString());
                    cmb_transmission.SelectedValue = int.Parse(dttable.Rows[0]["transmission"].ToString());
                    txt_remarks.Text               = dttable.Rows[0]["Remarks"].ToString();
                }
            }

            this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.Initilise_grd_img);
        }
예제 #2
0
        private void Btn_ok_Click(object sender, EventArgs e)
        {
            // reset all grd_group rows back color
            foreach (DataGridViewRow grd_row in grd_main.Rows)
            {
                if (!grd_row.IsNewRow)
                {
                    grd_row.DefaultCellStyle.BackColor = Color.Empty;
                }
            }

            string str_brand_name = txt_name.Text.Trim();

            if (str_brand_name == "")
            {
                MessageBox.Show("Brand name is required!", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (cmb1.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a country.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int int_country = int.Parse(cmb1.SelectedValue.ToString());

            if (!Vehicle_brand_ds.Is_vehicle_brand_name_available(str_brand_name, _int_brand_id))
            {
                MessageBox.Show("Brand name already exists! Please input new brand name.",
                                "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DataTable dttable_vehicle_group = ((DataTable)grd_main.DataSource).Copy();

            if (dttable_vehicle_group.Rows.Count == 0)
            {
                MessageBox.Show("At least one vehicle group is required.", "Invalid input",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int distinct_group_name_count = (from DataRow row in dttable_vehicle_group.Rows
                                             select row["vehicle_group_name"].ToString().ToUpper()).Distinct().ToList().Count;

            if (distinct_group_name_count != dttable_vehicle_group.Rows.Count)
            {
                MessageBox.Show("Duplicate vehicle group found. Please check and retry.",
                                "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (_int_brand_id == 0)
            {
                _int_brand_id = Vehicle_brand_ds.Insert_vehicle_brand(str_brand_name, int_country);
            }
            else
            {
                Vehicle_brand_ds.Update_vehicle_brand(_int_brand_id, str_brand_name, int_country);
            }

            DataColumn dt_col1 = new DataColumn("Created_by", typeof(int))
            {
                DefaultValue = Program.System_user.UserID
            };

            dttable_vehicle_group.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("vehicle_group", "vehicle_group");
                        bulkCopy.ColumnMappings.Add("vehicle_group_name", "vehicle_group_name");
                        bulkCopy.ColumnMappings.Add("created_by", "created_by");
                        bulkCopy.WriteToServer(dttable_vehicle_group);
                    }
                    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();
            }

            Vehicle_group_ds.Update_insert_vehicle_group(_int_brand_id);

            this.DialogResult = DialogResult.OK;
            this.Close();
        }