Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method that opens a ClientDetailsDialog
        /// </summary>
        /// <param name="sender">the control/object to set</param>
        /// <param name="e">the event data to set</param>
        private void dataGridViewClients_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                int index = dataGridViewClients.CurrentRow.Index;
                clientVM.SetDisplayClient(clientVM.Clients[index]);
                var dlg = new ClientDetailsDialog();
                dlg.ClientVM = clientVM;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    ClientValidation.UpdateClient(clientVM.GetDisplayClient());
                    clientVM.Clients = ClientValidation.GetClients();
                    clientVM.Clients.ResetItem(index);
                    dataGridViewClients.DataSource      = clientVM.Clients;
                    toolStripStatusMainLabelStatus.Text = "Client successfully edited.";
                }
                else
                {
                    DialogResult result = MessageBox.Show("You are about to leave Edit Client Details Dialog without saving.\r\nWould you like to save edited Client details?", "Edit Client", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (result == DialogResult.Yes)
                    {
                        ClientValidation.UpdateClient(clientVM.GetDisplayClient());
                        clientVM.Clients = ClientValidation.GetClients();
                        clientVM.Clients.ResetItem(index);
                        dataGridViewClients.DataSource      = clientVM.Clients;
                        toolStripStatusMainLabelStatus.Text = "Client successfully edited.";
                    }
                    else
                    {
                        toolStripStatusMainLabelStatus.Text = "Client has not been edited.";
                    }
                }

                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);
            }
        }