public void CarColorArrToForm(CarColor curcarColor) { CarColorArr carColorArr = new CarColorArr(); carColorArr.Fill(); cmb_Color.DataSource = carColorArr; cmb_Color.ValueMember = "Id"; cmb_Color.DisplayMember = "Name"; if (curcarColor != null) { cmb_Color.SelectedValue = curcarColor.Id; } }
private void CarColorArrToForm(CarColor curCarColor) { CarColorArr carColorArr = new CarColorArr(); carColorArr.Fill(); listbox_CarColor.ValueMember = "Id"; listbox_CarColor.DisplayMember = "Name"; listbox_CarColor.DataSource = carColorArr; if (curCarColor != null) { listbox_CarColor.SelectedValue = curCarColor.Id; } }
private void btn_Save_Click(object sender, EventArgs e) { if (CheckForm()) { CarColor carColor = new CarColor(); carColor = FormToCarColor(); CarColorArr oldCarColorArr = new CarColorArr(); oldCarColorArr.Fill(); if (!oldCarColorArr.IsContain(carColor.Name)) { if (carColor.Id == 0) { if (carColor.Insert()) { MessageBox.Show("Data saved successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearForm(); CarColorArr carColorArr = new CarColorArr(); carColorArr.Fill(); carColor = carColorArr.GetColorWithMaxId(); CarColorArrToForm(carColor); } } else { if (carColor.Update()) { MessageBox.Show("Data updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearForm(); CarColorArr carColorArr = new CarColorArr(); carColorArr.Fill(); carColor = carColorArr.GetColorWithMaxId(); CarColorArrToForm(null); } } } else { MessageBox.Show("Car color already exsits", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ClearForm(); } } }