private void btnNewDealer_Click(object sender, EventArgs e) { bool hasTheSaveButtonPressed = false; DealerBranch dealerBranch = new DealerBranch(); frmAddOrUpdateDealerBranch _frmAddOrUpdateDealerBranch = new frmAddOrUpdateDealerBranch(dealerBranch); _frmAddOrUpdateDealerBranch.TopMost = true; _frmAddOrUpdateDealerBranch.StartPosition = FormStartPosition.CenterParent; _frmAddOrUpdateDealerBranch.ShowDialog(); hasTheSaveButtonPressed = _frmAddOrUpdateDealerBranch.hasTheSaveButtonPressed; if (hasTheSaveButtonPressed == true) { Validation.LocalDatabaseConfig(true); //databaseViewModel = Services.GetDataFromDatabase(); dealerBranchesList = loadDealerBranches(); } dgvDealer.ClearSelection(); txtSearchDealer.Clear(); btnEditDealerBranch.Enabled = false; btnDeleteDealerBranch.Enabled = false; _frmAddOrUpdateDealerBranch.Dispose(); }
public static void DealerBranchLogger(DealerBranch dealerBranch, string action, string screenName, string UserId) { string fullFilePath = GetFilePath(screenName); try { if (!File.Exists(fullFilePath)) { FileStream file = File.Create(fullFilePath); file.Close(); } using (StreamWriter writer = File.AppendText(fullFilePath)) { PrintDefaultText(writer, fullFilePath, action, screenName, UserId); writer.WriteLine("DealerBranchId: " + dealerBranch.DealerBranchId); writer.WriteLine("DealerBranchName: " + dealerBranch.BranchName); writer.WriteLine("DealerId: " + dealerBranch.DealerId); writer.WriteLine("DealerName: " + dealerBranch.DealerName); writer.WriteLine("CountryId: " + dealerBranch.CountryId); writer.WriteLine("CTDI: " + dealerBranch.CTDI); writer.WriteLine("PhoneNumber: " + dealerBranch.PhoneNumber); writer.WriteLine("BaldoPartner: " + dealerBranch.BaldoPartner); writer.WriteLine("-------------------------------------------------------------------------------"); writer.Close(); } } catch (Exception ex) { throw ex; } }
private void btnDeleteDealer_Click(object sender, EventArgs e) { if (dgvDealer.Rows.Count > 0) { DealerBranch dealerBranch = new DealerBranch(); dealerBranch.DealerBranchId = Convert.ToInt32(dgvDealer.CurrentRow.Cells[0].Value.ToString()); dealerBranch.CTDI = Convert.ToInt32(dgvDealer.CurrentRow.Cells[1].Value.ToString()); dealerBranch.DealerName = dgvDealer.CurrentRow.Cells[2].Value.ToString(); dealerBranch.BranchName = dgvDealer.CurrentRow.Cells[3].Value.ToString(); dealerBranch.PhoneNumber = dgvDealer.CurrentRow.Cells[4].Value.ToString(); dealerBranch.BaldoPartner = dgvDealer.CurrentRow.Cells[5].Value.ToString(); dealerBranch.CountryId = Convert.ToInt32(dgvDealer.CurrentRow.Cells[6].Value.ToString()); dealerBranch.CountryName = dgvDealer.CurrentRow.Cells[7].Value.ToString(); dealerBranch.DealerId = Convert.ToInt32(dgvDealer.CurrentRow.Cells[8].Value.ToString()); if (MessageBox.Show("Are you sure you want to delete the Dealer Branch: " + dealerBranch.BranchName + "?", "Delete Dealer Branch", MessageBoxButtons.YesNo) == DialogResult.Yes) { DALHelpers.DeleteDealerBranch(dealerBranch.DealerBranchId); ActivityLog.DealerBranchLogger(dealerBranch, "DELETE", "Dealer Branch", Environment.UserName); Validation.LocalDatabaseConfig(true); dealerBranchesList = loadDealerBranches(); } dgvDealer.ClearSelection(); txtSearchDealer.Clear(); btnDeleteDealerBranch.Enabled = false; btnEditDealerBranch.Enabled = false; } }
public ActionResult DeleteConfirmed(int id) { DealerBranch dealerBranch = db.DealerBranches.Find(id); db.DealerBranches.Remove(dealerBranch); db.SaveChanges(); return(RedirectToAction("Index", "Manager")); }
public static bool DealerBranchDataValidation(DealerBranch dealerBranch) { bool IsEmpty = false; if ((dealerBranch.CountryName == string.Empty) || (dealerBranch.DealerName == string.Empty) || (dealerBranch.BranchName == string.Empty) || (dealerBranch.PhoneNumber == string.Empty) || (dealerBranch.CTDI > 0) || (dealerBranch.BaldoPartner == string.Empty)) { IsEmpty = true; } return(IsEmpty); }
public ActionResult Edit([Bind(Include = "BranchID,Address,OpenTime,CloseTime,TargetSalesYear,TargetSalesMonth")] DealerBranch dealerBranch) { if (ModelState.IsValid) { db.Entry(dealerBranch).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Manager")); } return(View(dealerBranch)); }
public ActionResult Create([Bind(Include = "BranchID,Address,OpenTime,CloseTime,TargetSalesYear,TargetSalesMonth")] DealerBranch dealerBranch) { if (ModelState.IsValid) { db.DealerBranches.Add(dealerBranch); db.SaveChanges(); return(RedirectToAction("Index", "Manager")); } return(View(dealerBranch)); }
// GET: DealerBranches/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DealerBranch dealerBranch = db.DealerBranches.Find(id); if (dealerBranch == null) { return(HttpNotFound()); } return(View(dealerBranch)); }
private void btnEditDealer_Click(object sender, EventArgs e) { if ((dgvDealer.Rows.Count > 0)) { DealerBranch dealerBranch = new DealerBranch(); bool hasTheSaveButtonPressed = false; dealerBranch.DealerBranchId = Convert.ToInt32(dgvDealer.CurrentRow.Cells[0].Value.ToString()); dealerBranch.CTDI = Convert.ToInt32(dgvDealer.CurrentRow.Cells[1].Value.ToString()); dealerBranch.DealerName = dgvDealer.CurrentRow.Cells[2].Value.ToString(); dealerBranch.BranchName = dgvDealer.CurrentRow.Cells[3].Value.ToString(); dealerBranch.PhoneNumber = dgvDealer.CurrentRow.Cells[4].Value.ToString(); dealerBranch.BaldoPartner = dgvDealer.CurrentRow.Cells[5].Value.ToString(); dealerBranch.CountryId = Convert.ToInt32(dgvDealer.CurrentRow.Cells[6].Value.ToString()); dealerBranch.CountryName = dgvDealer.CurrentRow.Cells[7].Value.ToString(); dealerBranch.DealerId = Convert.ToInt32(dgvDealer.CurrentRow.Cells[8].Value.ToString()); frmAddOrUpdateDealerBranch _frmAddOrUpdateDealerBranch = new frmAddOrUpdateDealerBranch(dealerBranch); this.TopMost = false; _frmAddOrUpdateDealerBranch.StartPosition = FormStartPosition.CenterParent; _frmAddOrUpdateDealerBranch.ShowDialog(); hasTheSaveButtonPressed = _frmAddOrUpdateDealerBranch.hasTheSaveButtonPressed; if (hasTheSaveButtonPressed == true) { Validation.LocalDatabaseConfig(true); //databaseViewModel = Services.GetDataFromDatabase(); dealerBranchesList = loadDealerBranches(); } dgvDealer.ClearSelection(); txtSearchDealer.Clear(); btnEditDealerBranch.Enabled = false; btnDeleteDealerBranch.Enabled = false; _frmAddOrUpdateDealerBranch.Dispose(); } }
public frmAddOrUpdateDealerBranch(DealerBranch dealerBranch) { InitializeComponent(); CountryId = dealerBranch.CountryId; DealerBranchId = dealerBranch.DealerBranchId; dealerBranchList = DALHelpers.GetDealerBranchs(); countryList = DALHelpers.GetCountries(); hasTheSaveButtonPressed = false; int counter = 0; if (dealerBranch.DealerBranchId != 0) { foreach (Country _country in countryList) { cmbCountries.Items.Add(_country.CountryName.ToString()); if (dealerBranch.CountryId == _country.CountryId) { cmbCountries.SelectedIndex = counter; dealerList = DALHelpers.GetDealersByCountry(_country.CountryId); } counter++; } counter = 0; foreach (Dealer dealer in dealerList) { cmbMainDealer.Items.Add(dealer.DealerName.ToString()); if (dealerBranch.CountryId == dealer.CountryId) { cmbMainDealer.SelectedIndex = counter; } counter++; } this.Text = "Update Dealer Branch"; txtBranchName.Text = dealerBranch.BranchName; txtPhoneNumber.Text = dealerBranch.PhoneNumber; txtCTDI.Text = dealerBranch.CTDI.ToString(); txtBaldoPartner.Text = dealerBranch.BaldoPartner; } else { foreach (Country country in countryList) { cmbCountries.Items.Add(country.CountryName.ToString()); } counter = 0; foreach (Dealer dealer in dealerList) { cmbMainDealer.Items.Add(dealer.DealerName.ToString()); if (dealerBranch.CountryId == dealer.CountryId) { cmbMainDealer.SelectedIndex = counter; } counter++; } this.Text = "New Dealer Brach"; } cmbCountries.Focus(); }
private void btnSave_Click(object sender, EventArgs e) { hasTheSaveButtonPressed = true; DealerBranch dealerBranch = new DealerBranch(); bool ok = false; if (txtCTDI.Text == "") { dealerBranch.CTDI = 0; } else { dealerBranch.CTDI = Convert.ToInt32(txtCTDI.Text); } dealerBranch.BranchName = txtBranchName.Text; dealerBranch.PhoneNumber = txtPhoneNumber.Text; dealerBranch.BaldoPartner = txtBaldoPartner.Text; foreach (Country country in countryList) { if (cmbCountries.Text == country.CountryName) { dealerBranch.CountryId = country.CountryId; } } foreach (Dealer dealer in dealerList) { if (cmbMainDealer.Text == dealer.DealerName) { dealerBranch.DealerId = dealer.DealerId; } } if (Validation.DealerBranchDataValidation(dealerBranch)) { MessageBox.Show("All fields are required."); return; } if (DealerBranchId != 0) { dealerBranch.DealerBranchId = DealerBranchId; //UPDATE ok = DALHelpers.UpdateDealerBranch(dealerBranch); if (ok == true) { MessageBox.Show("The record was successfully saved!"); } else { MessageBox.Show("Error: An error has ocurred when trying to update the Branch!"); } ActivityLog.DealerBranchLogger(dealerBranch, "UPDATE", "Dealer Branch", Environment.UserName); this.Close(); } else //NEW CONTACT { bool CTDI = false; bool BranchName = false; bool BaldoPartner = false; foreach (DealerBranch db in dealerBranchList) { if (dealerBranch.CTDI == db.CTDI) { CTDI = true; } if (dealerBranch.BranchName == db.BranchName) { BranchName = true; } if (dealerBranch.BaldoPartner == db.BaldoPartner) { BaldoPartner = true; } } if (CTDI == true || BranchName == true || BaldoPartner == true) { MessageBox.Show("Error: The Branch Name, CTDI or Baldo Partner already exists in the database!"); return; } else { ok = DALHelpers.AddDealerBranch(dealerBranch); if (ok == true) { MessageBox.Show("The record was successfully saved!"); } } ActivityLog.DealerBranchLogger(dealerBranch, "CREATE", "Dealer Branch", Environment.UserName); this.Close(); } }