Ejemplo n.º 1
0
        private void employeeGrid_RecordValueChanged(object sender, RecordValueChangedEventArgs e)
        {
            DataRowView drv = e.Record.GetData() as DataRowView;

            XmlNode node = DatabaseWorker.FindEmployeeNode(temp);

            node["Name"].InnerText    = drv[0].ToString();
            node["Job"].InnerText     = drv[1].ToString();
            node["Address"].InnerText = drv[2].ToString();
            node["Phone"].InnerText   = drv[3].ToString();

            xmlDoc.Save("fec.xmldb");
            UpdateEmployeeGrid();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Whenever the value of a cell is edited, update the database entry and the corresponding DataSet value.
        /// Update the grid to reflect these changes.
        /// </summary>
        private void DatabaseGrid_RecordValueChanged(object sender, RecordValueChangedEventArgs e)
        {
            try {
                // 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")
                {
                    // Queue a 'Edit Employee' task to the Thread pool.
                    ThreadPool.QueueUserWorkItem(state => {
                        // Increments the job counter in a thread-safe manner.
                        Interlocked.Increment(ref jobCount);

                        string[] updatedValues = { drv[1].ToString(), drv[2].ToString(), drv[3].ToString(), drv[4].ToString() };

                        // Edit the database employee entry.
                        DatabaseWorker.EditEmployee(Convert.ToInt32(drv[0]), updatedValues[0],
                                                    updatedValues[1], updatedValues[2],
                                                    updatedValues[3]);

                        // Get the index of the grid entry.
                        int index = databaseGrid.GetTable("Employees").UnsortedRecords.IndexOf(e.Record);

                        // Set the 'Name' field in the employee schedule entry that has the same index.
                        databaseGrid.GetTable("Employee Schedule").UnsortedRecords[index].SetValue("Name", drv[1].ToString());

                        // Decrements the job counter in a thread-safe manner.
                        Interlocked.Decrement(ref jobCount);
                    }
                                                 );
                }

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

                    // Get updated schedule values.
                    for (int i = 2; i < 9; i++)
                    {
                        updatedScheduleValues[i - 2] = drv[i].ToString();
                    }

                    // Queue a 'Edit Employee Schedule' task to the thread pool.
                    ThreadPool.QueueUserWorkItem(state => {
                        // Increments the job counter in a thread-safe manner.
                        Interlocked.Increment(ref jobCount);

                        DatabaseWorker.EditEmployeeSchedule(Convert.ToInt32(drv[0]), updatedScheduleValues);

                        // Decrements the job counter in a thread-safe manner.
                        Interlocked.Decrement(ref jobCount);
                    }
                                                 );
                }

                // If the cell's record belongs to the Customer table
                else if (e.Record.ParentChildTable.Name == "Customers")
                {
                    // Queue a 'Edit Customer' task to the thread pool.
                    ThreadPool.QueueUserWorkItem(state => {
                        // Increments the job counter in a thread-safe manner.
                        Interlocked.Increment(ref jobCount);

                        string[] updatedValues = { drv[1].ToString(), drv[2].ToString(), drv[3].ToString() };

                        // Edit the customer database entry.
                        DatabaseWorker.EditCustomer(Convert.ToInt32(drv[0]), updatedValues[0], updatedValues[1], updatedValues[2]);

                        // Get the index of the grid entry.
                        int index = databaseGrid.GetTable("Customers").UnsortedRecords.IndexOf(e.Record);

                        // Set the 'Name' field in the customer attendance entry that has the same index.
                        databaseGrid.GetTable("Customer Attendance").UnsortedRecords[index].SetValue("Name", drv[1].ToString());

                        // Decrements the job counter in a thread-safe manner.
                        Interlocked.Decrement(ref jobCount);
                    }
                                                 );
                }

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

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

                    // Queue a 'Edit Customer Attendance' task to the thread pool
                    ThreadPool.QueueUserWorkItem(state => {
                        // Increments the job counter in a thread-safe manner.
                        Interlocked.Increment(ref jobCount);

                        DatabaseWorker.EditCustomerAttendance(Convert.ToInt32(drv[0]), updatedAttendanceValues);

                        // Decrements the job counter in a thread-safe manner.
                        Interlocked.Decrement(ref jobCount);
                    }
                                                 );
                }
            }
            catch (Exception) {
                MessageBoxAdv.Show(this, "Error editing value.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
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);
                }
                                             );
            }
        }