//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();
        }
Exemplo n.º 2
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            int index = dataGridViewClients.CurrentRow.Index;

            clientVM.SetDisplayClient(clientVM.Clients[index]);

            ClientEditDialog dialog = new ClientEditDialog();

            dialog.ClientVM   = clientVM;
            dialog.isEditMode = true;
            string errorMessage;
            int    rowsAffected = 0;


            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)  // ok button was clicked
            {
                // this works whether it's dialog.ClientVM or just clientVM
                Client client = clientVM.GetDisplayClient(); // needs verification layer
                rowsAffected = ClientValidation.UpdateClient(client);
                //      clientVM.Clients = ClientRepository.GetAllClients();
                clientVM.Clients = ClientValidation.GetAllClients();
                dataGridViewClients.DataSource = clientVM.Clients;
                //how do I keep the last edited item selected ?
            }

            dialog.isEditMode = false;


            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();
        }
Exemplo n.º 3
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            int index = dataGridViewClients.CurrentRow.Index;

            clientVM.SetDisplayClient(clientVM.Clients[index]);

            ClientEditDialog dialog = new ClientEditDialog();

            dialog.ClientVM = clientVM;


            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)  // ok button was clicked
            {
                // this works wheter it's dialog.ClientVM or just clientVM
                clientVM.SaveProduct(index);
                clientVM.Clients.ResetItem(index);
            }

            dialog.Dispose();
        }
Exemplo n.º 4
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();
        }