diff --git a/QueueSys/frmEmployeeView.cs b/QueueSys/frmEmployeeView.cs index 6554459..b7bfed6 100644 --- a/QueueSys/frmEmployeeView.cs +++ b/QueueSys/frmEmployeeView.cs @@ -75,10 +75,15 @@ namespace QueueSys tbEmployeeName.Text = ""; MessageBox.Show("Customer has been added!", "Queue System", MessageBoxButtons.OK, MessageBoxIcon.Information); + + RefreshEmployeeView(); } private void RefreshEmployeeView() { + dgvEmployeeView.Rows.Clear(); + dgvEmployeeView.Refresh(); + // Build the row. SqliteDataAccess sdaEvView = new SqliteDataAccess(); List evList = new List(); @@ -113,7 +118,7 @@ namespace QueueSys //Select the id column from the current row. foreach(DataGridViewRow row in dgvEmployeeView.Rows) { - cxStatus = sdaEvView.GetCxStatus(Int32.Parse(dgvEmployeeView.CurrentRow.Cells[0].Value.ToString())); + cxStatus = sdaEvView.GetCxStatus(Int32.Parse(dgvEmployeeView.Rows[row.Index].Cells[0].Value.ToString())); row.Cells[2].Value = cxStatus[0].status; } @@ -127,13 +132,83 @@ namespace QueueSys dgvEmployeeView.Columns.Add(btn); } + private void dgvEmployeeView_CellClick(object sender, DataGridViewCellEventArgs e) { + //The delete button was clicked. if (e.ColumnIndex == 3) { - MessageBox.Show("Row"+e.RowIndex); + //Sanity check, per option. + if (Properties.Settings.Default.ConfirmDelete) + { + DialogResult result = MessageBox.Show("Are you sure you want to delete this customer?", "Queue System", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); + + if (result == DialogResult.No) + { + MessageBox.Show("Customer was not deleted.", "Queue System", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } + } + + SqliteDataAccess sdaEvView = new SqliteDataAccess(); + + EmployeeView evCustomer = new EmployeeView(); + evCustomer.id = Int32.Parse(dgvEmployeeView.CurrentRow.Cells[0].Value.ToString()); + + sdaEvView.ArchiveCustomer(evCustomer); + RefreshEmployeeView(); + + //Invoke the delegate to update customer view with updated data. + OnSendMessage?.Invoke(this, e); + + MessageBox.Show("Customer has been removed from the queue", "Queue System", MessageBoxButtons.OK, MessageBoxIcon.Information); } } + + // This event hooks the status combobox into the change commit event + private void dgvEmployeeView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) + { + if (dgvEmployeeView.CurrentCell.ColumnIndex == 2) + { + ComboBox combo = e.Control as ComboBox; + + if(combo != null) + { + combo.SelectionChangeCommitted += new EventHandler(dgvCbStatus_SelectionChangeCommitted); + } + } + } + + /* This event fires when the "status" combo box was changed + * and that change was "committed" + * This is needed to update the backend SQL db on demand, + * then update the customer view screen. + */ + private void dgvCbStatus_SelectionChangeCommitted(object sender, EventArgs e) + { + DataGridViewComboBoxEditingControl dgvcbec = sender as DataGridViewComboBoxEditingControl; + int CustomerId = Int32.Parse(dgvcbec.EditingControlDataGridView.CurrentRow.Cells[0].Value.ToString()); + + string new_status = dgvcbec.Text; + + //Check to see if we need an update. + SqliteDataAccess sdaEvView = new SqliteDataAccess(); + + List cxStatus = new List(); + cxStatus = sdaEvView.GetCxStatus(CustomerId); + + // Update not required. + if (cxStatus[0].status == new_status) + return; + + /* Update of the backend DB required beyond this point + * Update the customer status on the backend db. + */ + sdaEvView.UpdateCustomerStatus(CustomerId, new_status); + + //Invoke the delegate to update customer view with updated data. + OnSendMessage?.Invoke(this, e); + } } }