private void button2_Click(object sender, EventArgs e) { label16.Visible = false; richTextBox1.Visible = false; if (VINtext.Text == "" || ModelText.Text == "" || MakeText.Text == "" || PriceText.Text == "" || YearText.Text == "") { label16.Visible = true; richTextBox1.Visible = true; } else { int stockID; string status; using (DataGridViewRow item = this.dataGridView1.SelectedRows[0]) { int i = item.Index; string oldVIN = dataGridView1.Rows[i].Cells[0].Value.ToString(); status = dataGridView1.Rows[i].Cells[5].Value.ToString(); stockID = DAT.DataAccess.GetStock().Where(o => o.VIN == oldVIN).FirstOrDefault().StockID; //MakeText.Text = dataGridView1.Rows[i].Cells[1].Value.ToString(); //ModelText.Text = dataGridView1.Rows[i].Cells[2].Value.ToString(); //YearText.Text = dataGridView1.Rows[i].Cells[3].Value.ToString(); //PriceText.Text = dataGridView1.Rows[i].Cells[4].Value.ToString(); } try { LTS.Stock newStock = new LTS.Stock(); newStock.StockID = stockID; newStock.Make = MakeText.Text; newStock.Model = ModelText.Text; newStock.Price = Decimal.Parse(PriceText.Text); newStock.VehicleStatus = status; newStock.VehicleYear = YearText.Text; newStock.VIN = VINtext.Text; bool updated = DAT.DataAccess.UpdateStock(newStock); if (updated) { if (DialogResult.OK == MessageBox.Show("Stock item edited successfully!")) { ((Form1)this.Parent.Parent).ChangeView <Stock1>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the stock item was not edited successfully!")) { ((Form1)this.Parent.Parent).ChangeView <Stock1>(); } } } catch (Exception ex) { label16.Visible = true; richTextBox1.Visible = true; } } }
private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows == null) { } else { if (MessageBox.Show("Are You sure you want to remove this reservation?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { string VIN; using (DataGridViewRow item = this.dataGridView1.SelectedRows[0]) { int i = item.Index; VIN = dataGridView1.Rows[i].Cells[0].Value.ToString(); int stockID = DAT.DataAccess.GetStock().Where(o => o.VIN == VIN).FirstOrDefault().StockID; int ID = DAT.DataAccess.GetReserve().Where(o => o.StockID == stockID).FirstOrDefault().ResID; dataGridView1.Rows.RemoveAt(i); bool removed = DAT.DataAccess.RemoveReserve(ID); try { LTS.Stock newStock = new LTS.Stock(); newStock.StockID = stockID; newStock.Make = DAT.DataAccess.GetStock().Where(o => o.StockID == stockID).FirstOrDefault().Make; newStock.Model = DAT.DataAccess.GetStock().Where(o => o.StockID == stockID).FirstOrDefault().Model; newStock.Price = DAT.DataAccess.GetStock().Where(o => o.StockID == stockID).FirstOrDefault().Price; newStock.VehicleStatus = "Available"; newStock.VehicleYear = DAT.DataAccess.GetStock().Where(o => o.StockID == stockID).FirstOrDefault().VehicleYear; newStock.VIN = DAT.DataAccess.GetStock().Where(o => o.StockID == stockID).FirstOrDefault().VIN; bool updated = DAT.DataAccess.UpdateStock(newStock); if (removed && updated) { if (DialogResult.OK == MessageBox.Show("Reservation removed successfully!")) { ((Form1)this.Parent.Parent).ChangeView <ReserveA>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Reservation was not removed successfully!")) { ((Form1)this.Parent.Parent).ChangeView <ReserveA>(); } } } catch (Exception ex) { } } } else { } } }
private void button2_Click(object sender, EventArgs e) { if (VIN.Text == "" || Make.Text == "" || Model.Text == "" || Year.Text == "" || Price.Text == "" || comboBox1.SelectedItem == null) { label12.Visible = true; richTextBox1.Visible = true; } else { if (DAT.DataAccess.GetStock().Where(i => i.VIN == VIN.Text).ToList().Count > 0) { label14.Visible = true; } else { try { label14.Visible = false; label12.Visible = false; richTextBox1.Visible = false; LTS.Stock stock = new LTS.Stock(); stock.VIN = VIN.Text.ToUpper(); stock.VehicleYear = Year.Text; stock.Model = Model.Text; stock.Make = Make.Text; stock.VehicleStatus = comboBox1.SelectedItem.ToString(); stock.Price = Decimal.Parse(Price.Text); int stockID = DAT.DataAccess.AddStock(stock); if (stockID == -1) { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Stock Item was not Added!")) { ((Form1)this.Parent.Parent).ChangeView <StockA>(); } } else { if (DialogResult.OK == MessageBox.Show("The Stock Item was added successfully!")) { ((Form1)this.Parent.Parent).ChangeView <StockA>(); } } } catch (Exception ex) { label12.Visible = true; richTextBox1.Visible = true; } } } }
public static LTS.Stock GetStockItemByID(int?StockID) { LTS.Stock stock = new LTS.Stock(); try { using (LTS.LTSBase access = new LTS.LTSDC()) { stock = access.Stock.Where(o => o.StockID == StockID).FirstOrDefault(); } } catch (Exception ex) { } return(stock); }
public static int AddStock(LTS.Stock stock) { int?StockID = -1; try { using (LTS.LTSBase access = new LTS.LTSDC()) { access.InsertStock(stock.Make, stock.Model, stock.Price, stock.VehicleStatus, stock.VehicleYear, stock.VIN, ref StockID); } } catch (Exception ex) { } return(StockID.Value); }
public static bool UpdateStock(LTS.Stock stock) { bool completed = false; try { using (LTS.LTSBase access = new LTS.LTSDC()) { access.UpdateStock(stock.Make, stock.Model, stock.Price, stock.VehicleStatus, stock.VehicleYear, stock.VIN, stock.StockID); completed = true; } } catch (Exception ex) { completed = false; } return(completed); }
private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows == null) { } else { if (MessageBox.Show("Are You sure you want to remove this sale Item?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { string VIN; using (DataGridViewRow item = this.dataGridView1.SelectedRows[0]) { int i = item.Index; VIN = dataGridView1.Rows[i].Cells[0].Value.ToString(); int StockID = DAT.DataAccess.GetStock().Where(o => o.VIN == VIN).FirstOrDefault().StockID; int saleID = DAT.DataAccess.GetSale().Where(o => o.StockID == StockID).FirstOrDefault().SaleID; bool removed = DAT.DataAccess.RemoveSale(saleID); LTS.Stock s = DAT.DataAccess.GetStock().Where(u => u.VIN == VIN).FirstOrDefault(); s.VehicleStatus = "Available"; bool updated = DAT.DataAccess.UpdateStock(s); if (removed && updated) { if (DialogResult.OK == MessageBox.Show("Sale item removed successfully!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the sale item was not removed successfully!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } } } else { } } }
private void button2_Click(object sender, EventArgs e) { if (comboBox1.SelectedItem == null || comboBox2.SelectedItem == null || (radioButton1.Checked == false && radioButton2.Checked == false)) { label22.Visible = true; richTextBox1.Visible = true; } else { if (radioButton1.Checked && NewNameC.Text != "" && NewSurnameC.Text != "" && newIDC.Text != "" && newCellC.Text != "" && newEmailC.Text != "" && newAddressC.Text != "") { IdentityNumber iN = new IdentityNumber(newIDC.Text); bool validID = iN.IsValid; if (validID) { label22.Visible = false; LTS.Customer c = new LTS.Customer(); c.Name = NewNameC.Text; c.Surname = NewSurnameC.Text; c.IDno = newIDC.Text; c.Email = newEmailC.Text; c.CellNo = newCellC.Text; c.CustAddress = newAddressC.Text; int custID = DAT.DataAccess.AddCustomer(c); if (custID != -1) { LTS.Sale s = new LTS.Sale(); s.EmpID = DAT.DataAccess.GetEmployee().ToList()[comboBox2.SelectedIndex].EmpID; s.SaleDate = DateTime.Now.Date; s.CustID = custID; if (comboBoxp.SelectedItem.ToString() == "Yes") { s.Paid = true; } else { s.Paid = false; } s.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID; int stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID; int saleID = DAT.DataAccess.AddSale(s); if (saleID == -1) { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!")) { ((Form1)this.Parent.Parent).ChangeView <Sale1>(); } } else { LTS.Stock res = new LTS.Stock(); res = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault(); res.VehicleStatus = "Sold"; bool updated = DAT.DataAccess.UpdateStock(res); if (updated) { if (DialogResult.OK == MessageBox.Show("The Sale Item was added successfully!")) { ((Form1)this.Parent.Parent).ChangeView <Sale1>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!")) { ((Form1)this.Parent.Parent).ChangeView <Sale1>(); } } } } } else { label22.Visible = true; richTextBox1.Visible = true; } } else if (radioButton2.Checked && oldNameC.Text != "" && oldSurnameC.Text != "" && comboBoxOldNameC.SelectedItem != null && oldCellC.Text != "" && oldEmailC.Text != "" && oldAddressC.Text != "") { label22.Visible = false; richTextBox1.Visible = false; LTS.Customer c = DAT.DataAccess.GetCustomer().Where(p => p.IDno == comboBoxOldNameC.SelectedItem.ToString()).FirstOrDefault(); c.Name = oldNameC.Text; c.Surname = oldSurnameC.Text; c.Email = oldEmailC.Text; c.CellNo = oldCellC.Text; c.CustAddress = oldAddressC.Text; bool custID = DAT.DataAccess.UpdateCustomer(c); if (custID) { LTS.Sale s = new LTS.Sale(); s.EmpID = DAT.DataAccess.GetEmployee().ToList()[comboBox2.SelectedIndex].EmpID; s.SaleDate = DateTime.Now.Date; s.CustID = c.CustID; if (comboBoxp.SelectedItem.ToString() == "Yes") { s.Paid = true; } else { s.Paid = false; } s.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID; int stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID; int saleID = DAT.DataAccess.AddSale(s); if (saleID == -1) { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!")) { ((Form1)this.Parent.Parent).ChangeView <Sale1>(); } } else { LTS.Stock res = new LTS.Stock(); res = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault(); res.VehicleStatus = "Sold"; bool updated = DAT.DataAccess.UpdateStock(res); if (updated) { if (DialogResult.OK == MessageBox.Show("The Sale Item was added successfully!")) { ((Form1)this.Parent.Parent).ChangeView <Sale1>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!")) { ((Form1)this.Parent.Parent).ChangeView <Sale1>(); } } } } } else { label22.Visible = true; richTextBox1.Visible = true; } } }
private void button2_Click(object sender, EventArgs e) { label17.Visible = false; richTextBox1.Visible = false; if (VID.SelectedItem == null || email.Text == "" || cell.Text == "" || PID.Text == "" || Surname.Text == "" || Pname.Text == "") { label17.Visible = true; richTextBox1.Visible = true; } else { ///////////////////////CHECKS////////////////// bool isEmail = Regex.IsMatch(email.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase); bool isCell = Regex.IsMatch(cell.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$"); bool name = Regex.IsMatch(Pname.Text, @"^[a-zA-Z ]+$"); bool sName = Regex.IsMatch(Surname.Text, @"^[a-zA-Z ]+$"); IdentityNumber id = new IdentityNumber(PID.Text); bool IDVALID = id.IsValid; //////////////////////CHECKS////////////////// if (!isEmail || !isCell || !name || !sName || !IDVALID) { label17.Visible = true; richTextBox1.Visible = true; } else { LTS.Reserve r = new LTS.Reserve(); r.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == VID.SelectedItem.ToString()).FirstOrDefault().StockID; r.Name = Pname.Text; r.Surname = Surname.Text; r.IDno = PID.Text; r.CellNo = cell.Text; r.Email = email.Text; r.ResDate = DateTime.Now; int RID = DAT.DataAccess.AddReserve(r); int stockID; string status; string oldVIN = VID.SelectedItem.ToString(); stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == VID.SelectedItem.ToString()).FirstOrDefault().StockID; try { LTS.Stock newStock = new LTS.Stock(); newStock.StockID = stockID; newStock.Make = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault().Make; newStock.Model = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault().Model; newStock.Price = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault().Price; newStock.VehicleStatus = "Reserved"; newStock.VehicleYear = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault().VehicleYear; newStock.VIN = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault().VIN; bool updated = DAT.DataAccess.UpdateStock(newStock); if (RID > 0 && updated == true) { if (DialogResult.OK == MessageBox.Show("The Reservation was made successfully!")) { ((Form1)this.Parent.Parent).ChangeView <Reserve1>(); } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Reservation was not made!")) { ((Form1)this.Parent.Parent).ChangeView <Reserve1>(); } } } } catch (Exception ex) { label17.Visible = true; richTextBox1.Visible = true; } } } }
private void button2_Click(object sender, EventArgs e) { label22.Visible = false; richTextBox1.Visible = false; if (comboBox1.SelectedItem == null || comboBox2.SelectedItem == null || (radioButton1.Checked == false && radioButton2.Checked == false)) { label22.Visible = true; richTextBox1.Visible = true; } else { if (radioButton1.Checked && NewNameC.Text != "" && NewSurnameC.Text != "" && newIDC.Text != "" && newCellC.Text != "" && newEmailC.Text != "" && newAddressC.Text != "") { ///////////////////////CHECKS////////////////// bool isEmail = Regex.IsMatch(newEmailC.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase); bool isCell = Regex.IsMatch(newCellC.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$"); bool name = Regex.IsMatch(NewNameC.Text, @"^[a-zA-Z ]+$"); bool sName = Regex.IsMatch(NewSurnameC.Text, @"^[a-zA-Z ]+$"); IdentityNumber id = new IdentityNumber(newIDC.Text); bool IDVALID = id.IsValid; int exist; exist = DAT.DataAccess.GetCustomer().Where(i => i.IDno == newIDC.Text).ToList().Count; //////////////////////CHECKS////////////////// if (!isEmail || !isCell || !name || !sName || !IDVALID || exist != 0) { label22.Visible = true; richTextBox1.Visible = true; } else { LTS.Customer c = new LTS.Customer(); c.Name = NewNameC.Text; c.Surname = NewSurnameC.Text; c.IDno = newIDC.Text; c.Email = newEmailC.Text; c.CellNo = newCellC.Text; c.CustAddress = newAddressC.Text; int custID = DAT.DataAccess.AddCustomer(c); if (custID != -1) { LTS.Sale s = new LTS.Sale(); s.EmpID = DAT.DataAccess.GetEmployee().ToList()[comboBox2.SelectedIndex].EmpID; s.SaleDate = DateTime.Now.Date; s.CustID = custID; if (comboBoxp.SelectedItem.ToString() == "Yes") { s.Paid = true; } else { s.Paid = false; } s.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID; int stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID; int saleID = DAT.DataAccess.AddSale(s); if (saleID == -1) { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } else { LTS.Stock res = new LTS.Stock(); res = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault(); res.VehicleStatus = "Sold"; bool updated = DAT.DataAccess.UpdateStock(res); if (updated) { if (DialogResult.OK == MessageBox.Show("The Sale Item was added successfully!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } } } } } else if (radioButton2.Checked && oldNameC.Text != "" && oldSurnameC.Text != "" && comboBoxOldNameC.SelectedItem != null && oldCellC.Text != "" && oldEmailC.Text != "" && oldAddressC.Text != "") { ///////////////////////CHECKS////////////////// bool isEmail = Regex.IsMatch(oldEmailC.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase); bool isCell = Regex.IsMatch(oldCellC.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$"); bool name = Regex.IsMatch(oldNameC.Text, @"^[a-zA-Z ]+$"); bool sName = Regex.IsMatch(oldSurnameC.Text, @"^[a-zA-Z ]+$"); //////////////////////CHECKS////////////////// if (!isEmail || !isCell || !name || !sName) { label22.Visible = true; richTextBox1.Visible = true; } else { richTextBox1.Visible = false; label22.Visible = false; LTS.Customer c = DAT.DataAccess.GetCustomer().Where(p => p.IDno == comboBoxOldNameC.SelectedItem.ToString()).FirstOrDefault(); c.Name = oldNameC.Text; c.Surname = oldSurnameC.Text; c.Email = oldEmailC.Text; c.CellNo = oldCellC.Text; c.CustAddress = oldAddressC.Text; bool custID = DAT.DataAccess.UpdateCustomer(c); if (custID) { LTS.Sale s = new LTS.Sale(); s.EmpID = DAT.DataAccess.GetEmployee().ToList()[comboBox2.SelectedIndex].EmpID; s.SaleDate = DateTime.Now.Date; s.CustID = c.CustID; if (comboBoxp.SelectedItem.ToString() == "Yes") { s.Paid = true; } else { s.Paid = false; } s.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID; int stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID; int saleID = DAT.DataAccess.AddSale(s); if (saleID == -1) { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } else { LTS.Stock res = new LTS.Stock(); res = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault(); res.VehicleStatus = "Sold"; bool updated = DAT.DataAccess.UpdateStock(res); if (updated) { if (DialogResult.OK == MessageBox.Show("The Sale Item was added successfully!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } } } } } else { label22.Visible = true; richTextBox1.Visible = true; } } }
private void button2_Click(object sender, EventArgs e) { bool edit; string oldVIN; if (dataGridView1.SelectedRows == null) { label15.Visible = true; richTextBox1.Visible = true; } else { if (comboBoxVINID.SelectedItem == null || dateTimePicker1.Value == null || comboBoxp.SelectedItem == null || comboBoxempID.SelectedItem == null || (radioButton1.Checked == false && radioButton2.Checked == false)) { label15.Visible = true; richTextBox1.Visible = true; } else { int sID = DAT.DataAccess.GetStock().Where(i => i.VIN == dataGridView1.SelectedRows[0].Cells[0].Value.ToString()).FirstOrDefault().StockID; LTS.Sale s = new LTS.Sale(); s = DAT.DataAccess.GetSale().Where(i => i.StockID == sID).FirstOrDefault(); if (radioButton2.Checked && comboBoxcusID.SelectedItem != null) { if (s.StockID == DAT.DataAccess.GetStock().Where(o => o.VIN == comboBoxVINID.SelectedItem.ToString()).FirstOrDefault().StockID) { } else { LTS.Stock old = DAT.DataAccess.GetStock().Where(u => u.StockID == s.StockID).FirstOrDefault(); old.VehicleStatus = "Available"; DAT.DataAccess.UpdateStock(old); s.StockID = DAT.DataAccess.GetStock().Where(o => o.VIN == comboBoxVINID.SelectedItem.ToString()).FirstOrDefault().StockID; LTS.Stock newer = DAT.DataAccess.GetStock().Where(u => u.StockID == s.StockID).FirstOrDefault(); newer.VehicleStatus = "Sold"; DAT.DataAccess.UpdateStock(newer); } s.SaleDate = dateTimePicker1.Value.Date; s.Paid = Convert.ToBoolean(comboBoxp.SelectedItem.ToString()); s.EmpID = Convert.ToInt32(comboBoxempID.SelectedItem.ToString()); s.CustID = DAT.DataAccess.GetCustomer().Where(o => o.IDno == comboBoxcusID.SelectedItem.ToString()).FirstOrDefault().CustID; edit = DAT.DataAccess.UpdateSale(s); if (edit) { if (DialogResult.OK == MessageBox.Show("Sale item edited successfully!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale item was not edited successfully!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } } else if (radioButton1.Checked && NewNameC.Text != "" && NewSurnameC.Text != "" && newIDC.Text != "" && newCellC.Text != "" && newEmailC.Text != "" && newAddressC.Text != "") { s.StockID = DAT.DataAccess.GetStock().Where(o => o.VIN == comboBoxVINID.SelectedItem.ToString()).FirstOrDefault().StockID; s.SaleDate = dateTimePicker1.Value.Date; s.Paid = Convert.ToBoolean(comboBoxp.SelectedItem.ToString()); s.EmpID = Convert.ToInt32(comboBoxempID.SelectedItem.ToString()); LTS.Customer c = new LTS.Customer(); c.Name = NewNameC.Text; c.Surname = NewSurnameC.Text; c.IDno = newIDC.Text; c.CellNo = newCellC.Text; c.Email = newEmailC.Text; c.CustAddress = newAddressC.Text; int CID = DAT.DataAccess.AddCustomer(c); if (CID == -1) { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale item was not edited successfully!")) { } } else { s.CustID = CID; edit = DAT.DataAccess.UpdateSale(s); if (edit) { if (DialogResult.OK == MessageBox.Show("Sale item edited successfully!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale item was not edited successfully!")) { ((Form1)this.Parent.Parent).ChangeView <AllSales1>(); } } } } else { label15.Visible = true; richTextBox1.Visible = true; } } } }