private void buttonSaveClient_Click(object sender, EventArgs e) { try { Client client = clientVM.GetDisplayClient(); int rowsAffected; //checking if we are saving a new or existing client if (!clientVM.NewClient) { rowsAffected = ClientValidation.UpdateClient(client); } else { rowsAffected = ClientValidation.AddClient(client); } if (rowsAffected > 0) { clientVM.Clients = ClientValidation.GetAllClients(); listBoxClients.DataSource = clientVM.Clients; listBoxClients.DisplayMember = "ClientCode"; } } catch (SqlException ex) { Console.WriteLine("Data Access Error\n\n{0}", ex.Message); } catch (Exception ex) { Console.WriteLine("Processing Error\n\n{0}", ex.Message); } }
/// <summary> /// Button to delete a client or entered data /// </summary> /// <param name="sender">the control/object to set</param> /// <param name="e">the event data to set</param> private void buttonDelete_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(maskedTextBoxClientCode.Text)) { MessageBox.Show("Nothing to delete please select Client Code or create a new Client", "Select Client Code", MessageBoxButtons.OK, MessageBoxIcon.Warning); toolStripStatusLabelStatus.Text = "No Client selected to delete"; } else if (maskedTextBoxClientCode.Text.Length <= 5 && !maskedTextBoxClientCode.Text.Equals(listBoxClients.Text)) { DialogResult result = MessageBox.Show("Do you want to delete data entered in text fields?", "Delete Data Entered", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { toolStripStatusLabelStatus.Text = "Data entered deleted"; clearTextboxes(); maskedTextBoxClientCode.Focus(); } else { toolStripStatusLabelStatus.Text = "Data entered has not been deleted"; } } if (maskedTextBoxClientCode.Text.Equals(listBoxClients.Text)) { // Confirmation string creation string message = string.Format("{0} {1} {2}" , "Do you want to delete Client '" , clientVM.ClientCode.Trim() , "'? \r\nThis operation cannot be undone."); string caption = "Delete Client"; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { try { Client client = clientVM.GetDisplayClient(); ClientValidation.DeleteClient(client); clientVM.Clients = ClientValidation.GetClients(); listBoxClients.DataSource = clientVM.Clients; listBoxClients.DisplayMember = "ClientCode"; toolStripStatusLabelStatus.Text = "Client successfully deleted"; } catch (SqlException ex) { MessageBox.Show(ex.Message, "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { toolStripStatusLabelStatus.Text = "Client has not been deleted"; } } }
private void MainForm_Load(object sender, EventArgs e) { clientVM = new ClientViewModel(ClientValidation.GetAllClients()); // so there is no direct acces to the data setBindings(); setupDataGridView(); resetDisplay(); }
public DogNameEnum PlaceBetNoDogSelectedValidation(Label labelNotification, ComboBox comboBox) { object selectedItem = comboBox.SelectedItem; if (selectedItem != null) { DogNameEnum dogSelected = (DogNameEnum)selectedItem; if (dogSelected == 0) { labelNotification.Content = ClientValidation.BetValidationComboBoxNoDogSelectedWarning(); labelNotification.Foreground = NotificationColors.GetBrushColor(NotificationEnum.Warning); } else { var allDogs = Enum.GetValues(typeof(DogNameEnum)).Cast <DogNameEnum>().ToList(); var selectedDogName = allDogs.Where(a => a.ToString() == dogSelected.ToString()).FirstOrDefault(); return(selectedDogName); } } else { labelNotification.Content = ClientValidation.BetValidationComboBoxNoDogSelectedWarning(); labelNotification.Foreground = NotificationColors.GetBrushColor(NotificationEnum.Warning); } return(0); }
private void buttonAdd_Click(object sender, EventArgs e) { try { Client client = new Client(); clientVM.SetDisplayClient(client); EditDialog dialog = new EditDialog(); dialog.ClientVM = clientVM; dialog.Mode = Mode.Add; if (dialog.ShowDialog() == DialogResult.OK) { client = clientVM.GetDisplayClient(); clientVM.Clients = ClientValidation.GetClients(); dataGridViewClients.DataSource = clientVM.Clients; showCalculatedData(clientVM.Clients); } dialog.Dispose(); } catch (SqlException ex) { MessageBox.Show(ex.Message, "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public GuyNameEnum PlaceBetNoBettingGuySelectedValidation(Label labelNotification, ComboBox comboBox) { object selectedItem = comboBox.SelectedItem; if (selectedItem != null) { var guyBetting = (GuyNameEnum)selectedItem; if (guyBetting == 0) { labelNotification.Content = ClientValidation.BetValidationComboBoxNoGuySelectedWarning(); labelNotification.Foreground = NotificationColors.GetBrushColor(NotificationEnum.Warning); } else { var allGuys = Enum.GetValues(typeof(GuyNameEnum)).Cast <GuyNameEnum>().ToList(); var selectedGuyName = allGuys.Where(a => a.ToString() == guyBetting.ToString()).FirstOrDefault(); return(selectedGuyName); } } else { labelNotification.Content = ClientValidation.BetValidationComboBoxNoGuySelectedWarning(); labelNotification.Foreground = NotificationColors.GetBrushColor(NotificationEnum.Warning); } return(0); }
private void buttonOK_Click(object sender, EventArgs e) { client = ClientVM.DisplayClient; // If client code is already in the client view model or is not new, // replace the client information if (ClientVM.clients.Exists(x => x.ClientCode == OriginalClientCode) || !IsNew) { RowsAffected = ClientValidation.UpdateClient(client, OriginalClientCode); } else { RowsAffected = ClientValidation.AddClient(ref client); } if (RowsAffected == 0) { errorProviderClient.SetError(buttonOK, "No DB changed were made"); } else if (RowsAffected < 0) { errorProviderClient.SetError(buttonOK, ClientValidation.ErrorMessage); } // If all input data pass validation, then allow the EditDialog close with OK result if (RowsAffected >= 0) { DialogResult = DialogResult.OK; } }
/// <summary> /// Button to delete a client /// </summary> /// <param name="sender">the control/object to set</param> /// <param name="e">the event data to set</param> private void buttonDelete_Click(object sender, EventArgs e) { if (dataGridViewClients.Text.Equals(dataGridViewClients.Text)) { DialogResult result = MessageBox.Show("Delete selected Client?\r\nThis operation cannot be undone.", "Delete Client", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { try { int index = dataGridViewClients.CurrentRow.Index; ClientValidation.DeleteClient(clientVM.Clients[index]); clientVM.Clients = ClientValidation.GetClients(); dataGridViewClients.DataSource = clientVM.Clients; toolStripStatusMainLabelStatus.Text = "Client successfully deleted."; } catch (SqlException ex) { MessageBox.Show(ex.Message, "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { toolStripStatusMainLabelStatus.Text = "Client has not been deleted."; } } }
/// <summary> /// Method to generate YTDSales and CreditHoldCount Totals /// </summary> private void Totals() { ClientCollection totals = ClientValidation.GetClients(); textBoxTotalYTDSales.Text = totals.TotalYTDSales.ToString(); textBoxCreditHoldCount.Text = totals.CreditHoldCount.ToString(); }
/// <summary> /// Button to create a new client /// </summary> /// <param name="sender">the control/object to set</param> /// <param name="e">the event data to set</param> private void buttonNewClient_Click(object sender, EventArgs e) { try { Client client = new Client(); clientVM.SetDisplayClient(client); var dlg = new ClientDetailsDialog(); dlg.ClientVM = clientVM; if (dlg.ShowDialog() == DialogResult.OK) { ClientValidation.AddClient(clientVM.GetDisplayClient()); clientVM.Clients = ClientValidation.GetClients(); dataGridViewClients.DataSource = clientVM.Clients; toolStripStatusMainLabelStatus.Text = "Client successfully added."; } else { toolStripStatusMainLabelStatus.Text = "Client has not been added."; } dlg.Dispose(); } catch (SqlException ex) { MessageBox.Show(ex.Message, "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonOk_Click(object sender, EventArgs e) { Client client = ClientVM.GetDisplayClient(); string errorMessage; errorProvider.SetError(buttonOk, ""); // clear errors int affected = ClientValidation.UpdateClient(client); if (affected > 0) { this.DialogResult = DialogResult.OK; } else { if (affected == 0) { errorMessage = "No DB changes were made"; } else { errorMessage = ClientValidation.ErrorMessage; } errorProvider.SetError(buttonOk, errorMessage); } }
public void delete() { try { int index = dataGridViewClients.CurrentRow.Index; clientVM.SetDisplayClient(clientVM.Clients[index]); Client client = clientVM.GetDisplayClient(); ClientValidation.DeleteClient(client); clientVM.Clients = ClientValidation.GetAllClients(); dataGridViewClients.DataSource = clientVM.Clients; resetDisplay(); } catch (SqlException ex) { MessageBox.Show(ex.Message, "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Notification Execute(object obj = null) { Notification notification = new Notification(); BettingAccount bettingAccount = (BettingAccount)obj; GuyNameEnum betGuyName = bettingAccount.BettingAccountHolderName; DogNameEnum betDogName = bettingAccount.BettingDogNameSelected; int betAmount = bettingAccount.BettingAmount; IEnumerable <IGuy> allGuysInTheStadium = _dogRacePalaceStadium.GetAllGuysInTheStadium(); IGuy selectedGuyInStadium = allGuysInTheStadium.Where(a => a.Name == betGuyName).FirstOrDefault(); if (selectedGuyInStadium == null) { notification.Description = AllNotifications.NoGuyAddedToTheStadiumWarning(); notification.Code = NotificationEnum.Warning; } else { var guyCashBalance = selectedGuyInStadium.GetMoneyBalance(); if (guyCashBalance < betAmount) { notification.Description = AllNotifications.BetNotEnoughCashWarning(betGuyName.ToString(), betAmount, (int)guyCashBalance); notification.Code = NotificationEnum.Warning; } else { selectedGuyInStadium.WithdrawMoney(betAmount); _bettingBank.AddBettingAccountToBettingBank(bettingAccount); notification.Description = ClientValidation.StandardBettingNotification(); notification.Code = NotificationEnum.Ok; } } notification.Items = allGuysInTheStadium.Count(); return(notification); }
//Delete Button Behaviour private void mainDeleteButton_Click(object sender, EventArgs e) { Client client; //For instant deletion if (mainCheckBox.Checked == true) { client = clientVM.Clients.ElementAt(dataGridViewClients.CurrentRow.Index); ClientValidation.DeleteClient(client); } //Checked deletion else { const string message = "Are you sure you want to delete selected record?"; const string caption = "Confirm Deletion"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { client = clientVM.Clients.ElementAt(dataGridViewClients.CurrentRow.Index); ClientValidation.DeleteClient(client); } } clientVM.Clients = DataAccessObject.SelectAll(); dataGridViewClients.DataSource = clientVM.Clients; dataGridViewClients.Refresh(); setOutputLabel(); }
private void buttonEdit_Click(object sender, EventArgs e) { try { int index = dataGridViewClient.CurrentRow.Index; clientViewModel.SetDisplayClients(clientViewModel.Clients[index]); EditDialog dialog = new EditDialog(); dialog.clientViewModel = clientViewModel; dialog.isEdit = true; if (dialog.ShowDialog() == DialogResult.OK) { clientViewModel.Clients = ClientValidation.GetCustomer(); dataGridViewClient.DataSource = clientViewModel.Clients; dataGridViewClient.Rows[index].Selected = true; } dialog.Dispose(); GetInformation(); } catch (SqlException ex) { MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void DeleteClient() { int index = dataGridViewClient.CurrentRow.Index; ClientValidation.DeleteClient(clientViewModel.Clients[index]); clientViewModel.Clients = ClientValidation.GetCustomer(); dataGridViewClient.DataSource = clientViewModel.Clients; }
//my code is repeating here... private void buttonNewRecord_Click(object sender, EventArgs e) { int index = dataGridViewClients.CurrentRow.Index; string errorMessage; clientVM.SetDisplayClient(new Client()); ClientEditDialog dialog = new ClientEditDialog(); dialog.ClientVM = clientVM; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { clientVM.Clients = ClientValidation.GetAllClients(); dataGridViewClients.DataSource = clientVM.Clients; } if (ClientEditDialog.rowsAffected == 0) { errorMessage = "No DB changes were made"; MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } dialog.Dispose(); resetDisplay(); }
public int Register(Client client) { var repository = new ClientRepository(); var validation = new ClientValidation(); validation.Register(client); return(repository.Register(client)); }
/// <summary> /// Method to generate ClientCount, CreditHoldCount YTDSales Totals /// </summary> private void totals() { ClientCollection totals = ClientValidation.GetClients(); labelDisplayClientCount.Text = totals.ClientCount.ToString(); labelDisplayCreditHoldCount.Text = totals.CreditHoldCount.ToString(); labelDisplayYTDSalesTotal.Text = totals.TotalYTDSales.ToString(); }
private void SetStandardNotifications(List <Label> standardLabels) { foreach (var label in standardLabels) { label.Content = ClientValidation.StandardNotification(); label.Foreground = NotificationColors.GetBrushColor(NotificationEnum.Standard); } }
public ClientViewModel(SqlContext sqlContext, NotificationService notificationService) { IsLoaded = false; SqlContext = sqlContext; DialogIsOpenNewClient = false; NotificationService = notificationService; NouveauClient = new ClientValidation(); }
public OperationResponse <Client> SaveClient(Client clientEntity) { OperationResponse <Client> response = new OperationResponse <Client>(); try { if (clientEntity == null) { throw new Exception("Client nesnesi boş olamaz."); } //Validation. var valid = new ClientValidation().Validate(clientEntity); if (valid.IsValid == false) { string errorMessages = ""; foreach (var error in valid.Errors) { errorMessages += error.ErrorMessage + Environment.NewLine; } throw new Exception(errorMessages); } if (clientEntity.ClientId > 0) { //Update işlemi mi var existsClient = _unitOfWork.ClientRepository.GetById(clientEntity.ClientId); if (existsClient == null) { throw new Exception("Cari bulunamadı"); } } if (clientEntity.ClientId > 0) { clientEntity.UpdatedDateTime = DateTime.Now; _unitOfWork.ClientRepository.Update(clientEntity); } else { clientEntity.CreatedDateTime = DateTime.Now; _unitOfWork.ClientRepository.Insert(clientEntity); } response.Data = clientEntity; response.Status = true; } catch (Exception e) { response.Status = false; response.Message = e.Message; } return(response); }
public ClientViewModel() { clients = ClientValidation.GetClients(); ClientsSource = new BindingSource(); ClientsSource.DataSource = clients; ClientsSource.ListChanged += ClientSource_ListChanged; DisplayClient = new Client(); Invoices = new List <InvoiceLookupApi.Invoice>(); }
private void buttonOK_Click(object sender, EventArgs e) { errorProvider.SetError(buttonOK, string.Empty); Client client = ClientVM.GetDisplayClient(); if (isEditMode) { rowsAffected = ClientValidation.UpdateClient(client); } else { rowsAffected = ClientValidation.AddClient(client); } string regExClientCode = @"^[A-Z][A-Z][A-Z][A-Z][A-Z]$"; string regExProvince = @"^[A-Z][A-Z]$"; string regExCdnPostalCode = @"^[A-Z]\d[A-Z] \d[A-Z]\d$"; if (!Regex.IsMatch(maskedTextBoxClientCode.Text, regExClientCode)) { // errorProvider.SetError(buttonOK, "Client Code must be 5 characters, Ex: AAAAA"); errorMessage += "Client Code must be 5 characters, Ex: AAAAA\n"; } if (!Regex.IsMatch(maskedTextBoxProvince.Text, regExProvince)) { // errorProvider.SetError(buttonOK, "Province must be 2 characters, Ex: BC"); errorMessage += "Province must be 2 characters, Ex: BC\n"; } if (!Regex.IsMatch(maskedTextBoxPostalCode.Text, regExCdnPostalCode)) { // errorProvider.SetError(buttonOK, "Postal Code Format is Incorrect, Ex: V3G 1X5"); errorMessage += "Postal Code Format is Incorrect, Ex: V3G 1X5\n"; } if (rowsAffected < 0) // if there was an error in validation { errorMessage += ClientValidation.ErrorMessage; errorProvider.SetIconAlignment(buttonOK, ErrorIconAlignment.MiddleLeft); errorProvider.SetError(buttonOK, errorMessage); errorMessage = ""; } else { this.DialogResult = DialogResult.OK; } }
private void deleteClient(Client client) { //Delete the client from the database int rowsAffected = ClientValidation.DeleteClient(client); //If the delete was succesful, remove the client from the list if (rowsAffected > 0) { clientVM.ClientsSource.Remove(client); } }
public int PlaceBetMinimum2DogsInRacetrackValidation(Label labelNotification, ComboBox comboBox) { var dogsInRacetrackCount = comboBox.Items.Count; if (dogsInRacetrackCount < 2) { labelNotification.Content = ClientValidation.BetValidationLessThan2DogsInRacetrackWarning(); labelNotification.Foreground = NotificationColors.GetBrushColor(NotificationEnum.Warning); } return(dogsInRacetrackCount); }
/// <summary> /// Getting results from the background running thread; /// Hadling selected row possioning (vScrolling) after data reload (preserving vertical possition and currect cell possition) /// </summary> /// <param name="sender"></param> /// <param name="e">results of the background runnig thread</param> private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { resource = (ClientCollection)e.Result; clientVM = new ClientViewModel(ClientValidation.GetClients()); setupBindings(); refreshStatsPanel(); toolStripStatusLabelInfo.Text = "Loaded"; dataGridViewClients.ClearSelection(); dataGridViewClients.CurrentRow.Selected = false; dataGridViewClients.Rows[currentIndex].Selected = true; dataGridViewClients.CurrentCell = dataGridViewClients[0, currentIndex]; }
public ActionResult ClientSideValidation() { if (ModelState.IsValid) { ClientValidation emp = new ClientValidation(); UpdateModel(emp); ViewBag.emp1 = emp; return(View(emp)); } return(View()); }
/// <see cref="IClientViewModel.OnValidSubmit"/> public async void OnValidSubmit() { try { // Si contient déjà le même nom de client. if (AllClients.Any(x => x.NomClient == NouveauClient.NomClient)) { string msgWarn = $"Aucun ajout : {NouveauClient.NomClient} existe déjà"; NotificationMessage messWarn = new NotificationMessage() { Summary = "Attention", Detail = msgWarn, Duration = 3000, Severity = NotificationSeverity.Warning }; NotificationService.Notify(messWarn); return; } // Ajout dans la base de donnée. int idClient = await SqlContext.AddClient(NouveauClient.NomClient); Client nouveauClient = new Client() { IdClient = idClient, NomClient = NouveauClient.NomClient }; AllClients.Add(nouveauClient); await ClientGrid.Reload(); string message = $"Nouveau client : {nouveauClient.NomClient} ajouté"; NotificationMessage messNotif = new NotificationMessage() { Summary = "Sauvegarde OK", Detail = message, Duration = 3000, Severity = NotificationSeverity.Success }; NotificationService.Notify(messNotif); Log.Information("CLIENT - " + message); NouveauClient = new ClientValidation(); } catch (Exception ex) { Log.Error(ex, "ClientViewModel - OnValidSubmit"); } }
//Called everytime the OK button is clicked private void cButtonOk_Click(object sender, EventArgs e) { try { Client client = new Client(cMaskTextClientCode.Text , cTextCompanyName.Text , cTextAddress1.Text , cTextAddress2.Text , cTextCity.Text , cMaskTextProvince.Text , cMaskTextPostalCode.Text , Int32.Parse(cTextSales.Text) , cCheckBoxHold.Checked , cTextNotes.Text); int rowsAffected; string errorMessage; rowsAffected = ClientValidation.AddClient(client); if (rowsAffected > 0) { this.DialogResult = DialogResult.OK; } else { if (rowsAffected == 0) { errorMessage = "No DB changes were made"; } else { errorMessage = ClientValidation.ErrorMessage; } //Sets error next to the OK button errorProvider.SetError(cButtonOk, ClientValidation.ErrorMessage); } } catch (SqlException ex) { MessageBox.Show(ex.Message, "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }