コード例 #1
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);
            }
        }
コード例 #2
0
        private void buttonShowEditDialog_Click(object sender, EventArgs e)
        {
            try
            {
                int index = dataGridViewClients.CurrentRow.Index;

                Client client = clientVM.Clients[index];
                clientVM.SetDisplayClient(client);

                EditDialog dialog = new EditDialog();
                dialog.ClientVM   = clientVM;
                dialog.IsEditable = false;
                dialog.Mode       = Mode.Edit;

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    //After a successful update, show all the clients in the dataGrid, and the updated row will keep selected
                    client           = clientVM.GetDisplayClient();
                    clientVM.Clients = ClientValidation.GetClients();
                    clientVM.Clients.ResetItem(index);
                    dataGridViewClients.DataSource           = clientVM.Clients;
                    dataGridViewClients.Rows[index].Selected = true;

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