private void button1_Click(object sender, EventArgs e) { if (button1.Tag == null) { brands.Insert(textBox1.Text); } else { brands.Update(textBox1.Text, int.Parse(button1.Tag.ToString())); } dataGridView1.AutoGenerateColumns = false; dataGridView1.DataSource = brands.SelectAll(); textBox1.Text = ""; button1.Tag = null; }
private void Validation(out int?catID, out int?ads, out int?_areaID, out int?branchID) { if (cb_City.SelectedIndex == -1 && cb_City.Text != "") { city.Insert(cb_City.Text); #region City cb_City.DataSource = city.SelectAll(); cb_City.DisplayMember = "CityName"; cb_City.ValueMember = "ID"; cb_City.SelectedIndex = -1; #endregion cb_City.SelectedValue = (int)city.SelectAll().Last().ID; } if (cb_area.SelectedIndex == -1 && cb_area.Text != "") { area.Insert(cb_area.Text, int.Parse(cb_City.SelectedValue.ToString())); #region Area cb_area.DataSource = area.SelectAll(); cb_area.DisplayMember = "AreaName"; cb_area.ValueMember = "ID"; cb_area.SelectedIndex = -1; #endregion cb_area.SelectedValue = (int)area.SelectAll().Last().ID; } if (cb_cat.SelectedIndex == -1 && cb_cat.Text != "") { cat.Insert(cb_cat.Text); #region client Category // ComboBox cb_CarBrand = this.Owner.Controls.Find("cb_cat", true).First() as ComboBox; cb_cat.DataSource = cat.SelectAll(); cb_cat.DisplayMember = "Client_Category"; cb_cat.ValueMember = "ID"; cb_cat.SelectedIndex = -1; #endregion cb_cat.SelectedValue = (int)cat.SelectAll().Last().ID; } if (cb_branches.SelectedIndex == -1 && cb_branches.Text != "") { branch.Insert(cb_branches.Text, int.Parse(cb_City.SelectedValue.ToString())); #region branches cb_branches.DataSource = branch.SelectAllByCity(int.Parse(cb_City.SelectedValue.ToString())); cb_branches.DisplayMember = "BranchName"; cb_branches.ValueMember = "ID"; cb_branches.SelectedIndex = -1; #endregion cb_branches.SelectedValue = (int)branch.SelectAll().Last().ID; } if (cmb_ads.SelectedIndex == -1 && cmb_ads.Text != "") { how.Insert(cmb_ads.Text); #region ads cmb_ads.DataSource = how.SelectAll(); cmb_ads.DisplayMember = "HowDidYouUS"; cmb_ads.ValueMember = "ID"; cmb_ads.SelectedIndex = -1; #endregion cmb_ads.SelectedValue = (int)how.SelectAll().Last().ID; } if (cb_CarBrand.SelectedIndex == -1 && cb_CarBrand.Text != "") { brands.Insert(cb_CarBrand.Text); #region cars brand cb_CarBrand.DataSource = brands.SelectAll(); cb_CarBrand.DisplayMember = "BrandName"; cb_CarBrand.ValueMember = "ID"; cb_CarBrand.SelectedIndex = -1; #endregion cb_CarBrand.SelectedValue = (int)brands.SelectAll().Last().ID; } if (cb_model.SelectedIndex == -1 && cb_model.Text != "") { model.Insert(cb_model.Text, int.Parse(cb_CarBrand.SelectedValue.ToString()), "", ""); #region cars brand cb_CarBrand.DataSource = brands.SelectAll(); cb_CarBrand.DisplayMember = "BrandName"; cb_CarBrand.ValueMember = "ID"; cb_CarBrand.SelectedIndex = -1; #endregion cb_CarBrand.SelectedValue = (int)brands.SelectAll().Last().ID; } if (cb_colors.SelectedIndex == -1 && cb_colors.Text != "") { colors.Insert(cb_colors.Text); #region Colors cb_colors.DataSource = colors.SelectAll(); cb_colors.DisplayMember = "ColorName"; cb_colors.ValueMember = "ID"; cb_colors.SelectedIndex = -1; #endregion cb_colors.SelectedValue = (int)colors.SelectAll().Last().ID; } int?areaID; if (cb_area.SelectedIndex != -1) { areaID = int.Parse(cb_area.SelectedValue.ToString()); } int?CityID = null; if (cb_City.SelectedIndex != -1) { CityID = int.Parse(cb_City.SelectedValue.ToString()); } catID = null; if (cb_cat.SelectedIndex != -1) { catID = int.Parse(cb_cat.SelectedValue.ToString()); } ads = null; if (cmb_ads.SelectedIndex != -1) { ads = int.Parse(cmb_ads.SelectedValue.ToString()); } _areaID = null; if (cb_area.SelectedIndex != -1) { _areaID = int.Parse(cb_area.SelectedValue.ToString()); } branchID = null; if (cb_branches.SelectedIndex != -1) { branchID = int.Parse(cb_branches.SelectedValue.ToString()); } }