예제 #1
0
        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);
            }
        }
예제 #2
0
        /// <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 = 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;
            }
        }
        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;
            }
        }
예제 #5
0
        //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);
            }
        }
예제 #6
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            errorProviderClient.SetError(buttonOK, string.Empty);

            if (IsAddClient) // AddClient Dialog
            {
                Client dialogNewClient = ClientVM.GetDisplayClient();

                if (!ClientVM.Clients.ContainsClientCode(dialogNewClient))
                {
                    int rowsAffected = ClientValidation.AddClient(dialogNewClient);

                    if (rowsAffected == 0)
                    {
                        errorProviderClient.SetError(buttonOK, "No DB changes were made");
                    }
                    else if (rowsAffected < 0)
                    {
                        errorProviderClient.SetError(buttonOK, ClientValidation.ErrorMessage);
                    }
                    else
                    {
                        DialogResult = DialogResult.OK;
                    }
                }
                else
                {
                    errorProviderClient.SetError(buttonOK, "The ClientCode already exists");
                }
            }
            else // EditClient Dialog
            {
                Client dialogUpdatedClient = ClientVM.GetDisplayClient();
                int    rowsAffected        = ClientValidation.UpdateClient(dialogUpdatedClient);

                if (rowsAffected == 0)
                {
                    errorProviderClient.SetError(buttonOK, "No DB changes were made");
                }
                else if (rowsAffected < 0)
                {
                    errorProviderClient.SetError(buttonOK, ClientValidation.ErrorMessage);
                }
                else
                {
                    DialogResult = DialogResult.OK;
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Method to add a client with validation
        /// </summary>
        public void AddMode()
        {
            int    index        = listBoxClients.SelectedIndex;
            Client client       = clientVM.GetDisplayClient();
            int    rowsAffected = 0;
            string errorMessage;

            errorProviderMain.Clear();

            try
            {
                rowsAffected = ClientValidation.AddClient(client);
            }
            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);
            }

            if (rowsAffected > 0)
            {
                clientVM.Clients                = ClientValidation.GetClients();
                listBoxClients.DataSource       = clientVM.Clients;
                listBoxClients.DisplayMember    = "ClientCode";
                listBoxClients.SelectedIndex    = index;
                toolStripStatusLabelStatus.Text = "Client successfully added";
            }
            else
            {
                errorProviderMain.Clear();

                if (rowsAffected == 0)
                {
                    errorMessage = "No DB changes were made";
                }
                else
                {
                    errorMessage = ClientValidation.ErrorMessage;
                }

                errorProviderMain.SetError(buttonSave, errorMessage);
                toolStripStatusLabelStatus.Text = "Client has not been added";
            }
        }
예제 #8
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            errorProvider.SetError(buttonOk, "");
            Client client = new Client();

            try
            {
                client = ClientVM.GetDisplayClient();
                int rowsAffected = 0;

                if (Mode.Equals(Mode.Edit))
                {
                    rowsAffected = ClientValidation.UpdateClient(client);
                }
                else
                {
                    rowsAffected = ClientValidation.AddClient(client);
                }

                if (rowsAffected > 0)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    if (rowsAffected == -1)
                    {
                        errorProvider.SetError(buttonOk, ClientValidation.ErrorMessage);
                    }
                    else
                    {
                        errorProvider.SetError(buttonOk, "No DB changes were made");
                    }
                }
            }
            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);
            }
        }
예제 #9
0
파일: MainForm.cs 프로젝트: voicu/CSharp
        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)
                //if we had any errors we display them, if not we refresh the data
                if (ClientValidation.ErrorList.Count > 0)
                {
                    //MessageBox.Show(ClientValidation.ErrorList.ErrorMessages, "Validation Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    errorProviderMainForm.SetIconAlignment(buttonSaveClient, ErrorIconAlignment.MiddleLeft);
                    errorProviderMainForm.SetError(buttonSaveClient, ClientValidation.ErrorList.ErrorMessages);
                }
                else
                {
                    errorProviderMainForm.SetError(buttonSaveClient, string.Empty);
                    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);
            }
        }
예제 #10
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            Client cl;
            string errorMessage = String.Empty;

            errorProvider.SetIconAlignment(buttonOK, ErrorIconAlignment.MiddleLeft);
            errorProvider.SetError(buttonOK, "");

            try
            {
                cl = ClientVM.GetDisplayClient();

                int rowsAffected = 0;

                if (callingButton != null && callingButton.Contains("New"))
                {
                    rowsAffected = ClientValidation.AddClient(cl);
                }
                else
                {
                    rowsAffected = ClientValidation.UpdateClient(cl);
                }

                if (rowsAffected < 0)
                {
                    errorMessage      = ClientValidation.ErrorMessage;
                    this.DialogResult = DialogResult.None;
                }

                errorProvider.SetError(buttonOK, errorMessage);
            }
            catch (Exception)
            {
                throw;
            }

            if (DialogResult == DialogResult.OK)
            {
                this.Close();
                this.Dispose();
            }
        }
        /// <summary>
        /// Method to add a client with validation
        /// </summary>
        public void AddMode()
        {
            int    index        = listBoxClients.SelectedIndex;
            Client client       = clientVM.GetDisplayClient();
            int    rowsAffected = 0;
            string errorMessage;

            try
            {
                rowsAffected = ClientValidation.AddClient(client);

                if (rowsAffected > 0)
                {
                    clientVM.Clients             = ClientValidation.GetClients();
                    listBoxClients.DataSource    = clientVM.Clients;
                    listBoxClients.DisplayMember = "ClientCode";
                    listBoxClients.SelectedIndex = index;
                }
                else
                {
                    if (rowsAffected == 0)
                    {
                        errorMessage = "No DB changes were made";
                    }
                    else
                    {
                        errorMessage = ClientValidation.ErrorMessage;
                    }

                    MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            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);
            }
        }
예제 #12
0
        private void buttonNewRecord_Click(object sender, EventArgs e)
        {
            int    index        = dataGridViewClients.CurrentRow.Index;
            int    rowsAffected = 0;
            string errorMessage;

            clientVM.SetDisplayClient(new Client());

            ClientEditDialog dialog = new ClientEditDialog();

            dialog.ClientVM = clientVM;


            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)  // ok button was clicked
            {
                Client client = clientVM.GetDisplayClient();
                rowsAffected     = ClientValidation.AddClient(client); //verification method
                clientVM.Clients = ClientValidation.GetAllClients();
                dataGridViewClients.DataSource = clientVM.Clients;
            }

            if (rowsAffected == 0)
            {
                errorMessage = "No DB changes were made";
                MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (rowsAffected < 0) // if there was an error in validation
            {
                errorMessage = ClientValidation.ErrorMessage;
                MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            dialog.Dispose();
        }