Ejemplo n.º 1
0
        /// <summary>
        /// **************** TODO: COMPLETE DOCUMENTATION *****************
        ///
        /// Whenever the value of a cell is edited, update the database entry and the corresponding DataSet value.
        /// Updat the grid to reflect these changes.
        /// </summary>
        private void databaseGrid_RecordValueChanged(object sender, RecordValueChangedEventArgs e)
        {
            // Object that holds the values of the record that the edited cell belongs to.
            DataRowView drv = e.Record.GetData() as DataRowView;

            // If the cell's record belongs to the Employee table
            if (e.Record.ParentChildTable.Name == "Employees")
            {
                ThreadPool.QueueUserWorkItem(state => {
                    DatabaseWorker.EditEmployee(Convert.ToInt32(drv[0]), drv[1].ToString(),
                                                drv[2].ToString(), drv[3].ToString(),
                                                drv[4].ToString());

                    string[] updatedEmployeeValues = DatabaseWorker.GetEmployeeEntryNoId(Convert.ToInt32(drv[0]));

                    int index = databaseGrid.GetTable("Employees").UnsortedRecords.IndexOf(e.Record);

                    e.Record.UpdateValues(updatedEmployeeValues);

                    databaseGrid.GetTable("Employee Schedule").UnsortedRecords[index].SetValue("Name", drv[1].ToString());
                }
                                             );
            }

            // If the cell's record belongs to the Employee Schedule table
            else if (e.Record.ParentChildTable.Name == "Employee Schedule")
            {
                string[] scheduleValues = new string[7];

                for (int i = 2; i < 9; i++)
                {
                    scheduleValues[i - 2] = drv[i].ToString();
                }

                ThreadPool.QueueUserWorkItem(state => {
                    DatabaseWorker.EditEmployeeSchedule(Convert.ToInt32(drv[0]), scheduleValues);

                    string[] updatedScheduleValues = DatabaseWorker.GetEmployeeScheduleEntry(Convert.ToInt32(drv[0]));
                    e.Record.UpdateValues(updatedScheduleValues);
                }
                                             );
            }

            // If the cell's record belongs to the Customer table
            else if (e.Record.ParentChildTable.Name == "Customers")
            {
                ThreadPool.QueueUserWorkItem(state => {
                    DatabaseWorker.EditCustomer(Convert.ToInt32(drv[0]), drv[1].ToString(), drv[2].ToString(), drv[3].ToString());

                    string[] updatedCustomerValues = DatabaseWorker.GetCustomerEntryNoId(Convert.ToInt32(drv[0]));

                    int index = databaseGrid.GetTable("Customers").UnsortedRecords.IndexOf(e.Record);

                    e.Record.UpdateValues(updatedCustomerValues);

                    databaseGrid.GetTable("Customer Attendance").UnsortedRecords[index].SetValue("Name", drv[1].ToString());
                }
                                             );
            }

            // If the cell's record belongs the Customer Attendance table.
            else if (e.Record.ParentChildTable.Name == "Customer Attendance")
            {
                string[] attendanceValues = new string[7];

                for (int i = 2; i < 9; i++)
                {
                    attendanceValues[i - 2] = drv[i].ToString();
                }

                ThreadPool.QueueUserWorkItem(state => {
                    DatabaseWorker.EditCustomerAttendance(Convert.ToInt32(drv[0]), attendanceValues);

                    string[] updatedAttendanceValues = DatabaseWorker.GetCustomerAttendanceEntry(Convert.ToInt32(drv[0]));
                    e.Record.UpdateValues(updatedAttendanceValues);
                }
                                             );
            }
        }