Exemplo n.º 1
0
        private void AddDelivererToSelectedYearTableButton_Click(object sender, RoutedEventArgs e)
        {
            if (mMode == DelivererMode.DatabaseDeliverersTableDuplicates || mMode == DelivererMode.DatabaseDeliverersTableUpdateDeliverer || mMode == DelivererMode.DatabaseDeliverersTableAddDeliverer)
            {
                int    rowToInsert      = -1;
                int    selectedRowCount = 0;
                string DelivererID      = "";
                string firstName        = "";
                string lastName         = "";

                //See see if only 1 row is selected and get that row number
                for (int i = 0; i < mDatabaseDeliverersTable.Rows.Count; i++)
                {
                    if (DelivererBottomTable.IsSelected(i))
                    {
                        rowToInsert = i;
                        selectedRowCount++;
                    }
                }

                //See see if only 1 row is selected
                if (selectedRowCount > 1)
                {
                    System.Windows.MessageBox.Show("Only Select 1 Deliverer");
                    return;
                }

                //See if we should insert the Deliverer into the mSelectedYear table
                if (rowToInsert != -1)
                {
                    //Get information to display to the user for confirmation
                    DelivererID = mDatabaseDeliverersTable.Rows[rowToInsert]["Deliverer_ID"].ToString();
                    lastName    = mDatabaseDeliverersTable.Rows[rowToInsert]["Last_Name"].ToString();
                    firstName   = mDatabaseDeliverersTable.Rows[rowToInsert]["First_Name"].ToString();

                    //Update Access Database
                    string insertCommand = "INSERT INTO " + Main.mSelectedYear + "_Deliverers" + " (Deliverer_ID) VALUES (" + mDatabaseDeliverersTable.Rows[rowToInsert]["Deliverer_ID"] + ")";
                    Main.mChristmasBasketsAccessDatabase.ExecuteNonQuery(insertCommand);
                }

                //Update data grid display
                DelivererTopTable.Refresh();
                DelivererBottomTable.Refresh();

                if (rowToInsert != -1)
                {
                    //Show status message box
                    System.Windows.MessageBox.Show("Deliverer:  " + DelivererID + " - " + lastName + ", " + firstName + " ADDED in " + Main.mSelectedYear + "_Deliverers" + " Table");

                    //Close the Import Helper
                    this.Close();
                }
            }
        }
Exemplo n.º 2
0
        private void DeleteSelectedDelivererButton_Click(object sender, RoutedEventArgs e)
        {
            if (mMode == DelivererMode.DatabaseDeliverersTableDuplicates || mMode == DelivererMode.DatabaseDeliverersTableUpdateDeliverer || mMode == DelivererMode.DatabaseDeliverersTableAddDeliverer || mMode == DelivererMode.DatabaseDeliverersTableAddDeliverer)
            {
                int    rowToDelete      = -1;
                int    selectedRowCount = 0;
                string DelivererID      = "";
                string firstName        = "";
                string lastName         = "";

                //See see if only 1 row is selected and get that row number
                for (int i = 0; i < mDatabaseDeliverersTable.Rows.Count; i++)
                {
                    if (DelivererBottomTable.IsSelected(i))
                    {
                        rowToDelete = i;
                        selectedRowCount++;
                    }
                }

                //See see if only 1 row is selected
                if (selectedRowCount > 1)
                {
                    System.Windows.MessageBox.Show("Only Select 1 Deliverer");
                    return;
                }

                //See if we should delete the Deliverer into the Deliverers table
                if (rowToDelete != -1)
                {
                    //Get information to display to the user for confirmation
                    DelivererID = mDatabaseDeliverersTable.Rows[rowToDelete]["Deliverer_ID"].ToString();
                    lastName    = mDatabaseDeliverersTable.Rows[rowToDelete]["Last_Name"].ToString();
                    firstName   = mDatabaseDeliverersTable.Rows[rowToDelete]["First_Name"].ToString();

                    //Update Access Database
                    string deleteCommand = "DELETE FROM Deliverers WHERE Deliverer_ID = " + mDatabaseDeliverersTable.Rows[rowToDelete]["Deliverer_ID"];
                    Main.mChristmasBasketsAccessDatabase.ExecuteNonQuery(deleteCommand);

                    //Update data grid source
                    mDatabaseDeliverersTable.Rows.RemoveAt(rowToDelete);
                }

                //Update data grid display
                DelivererTopTable.Refresh();
                DelivererBottomTable.Refresh();

                if (rowToDelete != -1)
                {
                    //Show status message box
                    System.Windows.MessageBox.Show("Deliverer:  " + DelivererID + " - " + lastName + ", " + firstName + " DELETED from Deliverers Table");
                }
            }
        }
Exemplo n.º 3
0
        private void AddSelectedDelivererToDeliverersAndSelectedYearTableButton_Click(object sender, RoutedEventArgs e)
        {
            int    rowToAdd         = -1;
            int    selectedRowCount = 0;
            string DelivererID      = "";
            string firstName        = "";
            string lastName         = "";

            if (mMode == DelivererMode.DatabaseDeliverersTableAddDeliverer)
            {
                //Check for null values
                for (int i = 0; i < mExcelDeliverersTable.Rows.Count; i++)
                {
                    if (DelivererTopTable.IsSelected(i))
                    {
                        rowToAdd = i;
                        selectedRowCount++;
                    }
                }

                //Add the record into the Deliverers Table

                //See see if only 1 row is selected
                if (selectedRowCount > 1)
                {
                    System.Windows.MessageBox.Show("Only Select 1 Deliverer");
                    return;
                }

                //See if we should add the Deliverer to the Deliverers table
                if (rowToAdd != -1)
                {
                    //Check for null values
                    foreach (DataColumn column in mExcelDeliverersTable.Columns)
                    {
                        if (mExcelDeliverersTable.Rows[rowToAdd][column.ColumnName].ToString() == "")
                        {
                            if (column.ColumnName == "Capacity_" + Main.mSelectedYear || column.ColumnName == "Assigned_" + Main.mSelectedYear)
                            {
                                mExcelDeliverersTable.Rows[rowToAdd][column.ColumnName] = "0";
                            }
                            else
                            {
                                mExcelDeliverersTable.Rows[rowToAdd][column.ColumnName] = "null";
                            }
                        }
                    }

                    //Update Access Database
                    string insertCommand = "INSERT INTO Deliverers (Last_Name,First_Name,Home_Phone,Work_Phone,Capacity,Assigned,Occupation_Status,Comments)" +
                                           " VALUES (" +
                                           "'" + mExcelDeliverersTable.Rows[rowToAdd]["Last_Name"].ToString() + "'," +
                                           "'" + mExcelDeliverersTable.Rows[rowToAdd]["First_Name"].ToString() + "'," +
                                           "'" + mExcelDeliverersTable.Rows[rowToAdd]["Home_Phone"].ToString() + "'," +
                                           "'" + mExcelDeliverersTable.Rows[rowToAdd]["Work_Phone"].ToString() + "'," +
                                           "" + mExcelDeliverersTable.Rows[rowToAdd]["Capacity"] + "," +
                                           "" + mExcelDeliverersTable.Rows[rowToAdd]["Assigned"] + "," +
                                           "'" + mExcelDeliverersTable.Rows[rowToAdd]["Occupation_Status"].ToString() + "'," +
                                           "'" + mExcelDeliverersTable.Rows[rowToAdd]["Comments"].ToString() + "')";

                    Main.mChristmasBasketsAccessDatabase.ExecuteNonQuery(insertCommand);

                    //Figure out what the Deliverer_ID was assigned
                    string selectCommand = "SELECT * FROM Deliverers WHERE " +
                                           "Last_Name = '" + mExcelDeliverersTable.Rows[rowToAdd]["Last_Name"].ToString() + "' AND " +
                                           "First_Name = '" + mExcelDeliverersTable.Rows[rowToAdd]["First_Name"].ToString() + "'";


                    DataSet Deliverer = Main.mChristmasBasketsAccessDatabase.PerformSelectQuery(selectCommand, "Deliverers");

                    if (Deliverer != null)
                    {
                        //Get the record information to display to the user
                        DelivererID = Deliverer.Tables[0].Rows[0]["Deliverer_ID"].ToString();
                        lastName    = mExcelDeliverersTable.Rows[rowToAdd]["Last_Name"].ToString();
                        firstName   = mExcelDeliverersTable.Rows[rowToAdd]["First_Name"].ToString();

                        System.Windows.MessageBox.Show("Deliverer:  " + DelivererID + " - " + lastName + ", " + firstName + " ADDED in Deliverers Table");

                        //Copy Record over into mDatabaseDeliverersTable
                        mDatabaseDeliverersTable.Rows.Add();
                        foreach (DataColumn column in mExcelDeliverersTable.Columns)
                        {
                            mDatabaseDeliverersTable.Rows[0][column.ColumnName] = mExcelDeliverersTable.Rows[0][column.ColumnName];
                        }

                        mDatabaseDeliverersTable.Rows[0]["Deliverer_ID"] = DelivererID;

                        //Insert the record to the Table
                        string insertCommandTwo = "INSERT INTO " + Main.mSelectedYear + "_Deliverers" + " (Deliverer_ID) VALUES (" + DelivererID + ")";
                        Main.mChristmasBasketsAccessDatabase.ExecuteNonQuery(insertCommandTwo);

                        //Show status message box
                        System.Windows.MessageBox.Show("Deliverer:  " + DelivererID + " - " + lastName + ", " + firstName + " ADDED in " + Main.mSelectedYear + "_Deliverers" + " Table");

                        //Close the Import Helper
                        this.Close();
                    }

                    DelivererTopTable.Refresh();
                    DelivererBottomTable.Refresh();
                }
            }
        }
Exemplo n.º 4
0
        private void UpdateDelivererInformationButton_Click(object sender, RoutedEventArgs e)
        {
            if (mMode == DelivererMode.DatabaseDeliverersTableDuplicates || mMode == DelivererMode.DatabaseDeliverersTableUpdateDeliverer || mMode == DelivererMode.DatabaseDeliverersTableAddDeliverer)
            {
                int    rowToUpdate      = -1;
                int    selectedRowCount = 0;
                string DelivererID      = "";
                string firstName        = "";
                string lastName         = "";

                //See see if only 1 row is selected and get that row number
                for (int i = 0; i < mDatabaseDeliverersTable.Rows.Count; i++)
                {
                    if (DelivererBottomTable.IsSelected(i))
                    {
                        rowToUpdate = i;
                        selectedRowCount++;
                    }
                }

                //See see if only 1 row is selected
                if (selectedRowCount > 1)
                {
                    System.Windows.MessageBox.Show("Only Select 1 Deliverer");
                    return;
                }

                //See if we should update the Deliverer in the Deliverers table
                if (rowToUpdate != -1)
                {
                    //Get information to display to the user for confirmation
                    DelivererID = mDatabaseDeliverersTable.Rows[rowToUpdate]["Deliverer_ID"].ToString();
                    lastName    = mDatabaseDeliverersTable.Rows[rowToUpdate]["Last_Name"].ToString();
                    firstName   = mDatabaseDeliverersTable.Rows[rowToUpdate]["First_Name"].ToString();

                    //Check for null values
                    foreach (DataColumn column in mDatabaseDeliverersTable.Columns)
                    {
                        if (mDatabaseDeliverersTable.Rows[rowToUpdate][column.ColumnName].ToString() == "")
                        {
                            mDatabaseDeliverersTable.Rows[rowToUpdate][column.ColumnName] = "null";
                        }
                    }

                    string updateCommand = "UPDATE Deliverers SET Last_Name = '" + mDatabaseDeliverersTable.Rows[rowToUpdate]["Last_Name"].ToString() + "', " +
                                           "First_Name = '" + mDatabaseDeliverersTable.Rows[rowToUpdate]["First_Name"].ToString() + "', " +
                                           "Home_Phone = '" + mDatabaseDeliverersTable.Rows[rowToUpdate]["Home_Phone"].ToString() + "', " +
                                           "Work_Phone = '" + mDatabaseDeliverersTable.Rows[rowToUpdate]["Work_Phone"].ToString() + "', " +
                                           "Capacity = " + mDatabaseDeliverersTable.Rows[rowToUpdate]["Capacity"] + ", " +
                                           "Assigned = " + mDatabaseDeliverersTable.Rows[rowToUpdate]["Assigned_" + Main.mSelectedYear.ToString()].ToString() + ", " +
                                           "Occupation_Status = '" + mDatabaseDeliverersTable.Rows[rowToUpdate]["Occupation_Status"].ToString() + "', " +
                                           "Comments = '" + mDatabaseDeliverersTable.Rows[rowToUpdate]["Comments"].ToString() + "'" +
                                           " WHERE Deliverer_ID = " + mDatabaseDeliverersTable.Rows[rowToUpdate]["Deliverer_ID"].ToString();

                    Main.mChristmasBasketsAccessDatabase.ExecuteNonQuery(updateCommand);
                }

                //Update data grid display
                DelivererTopTable.Refresh();
                DelivererBottomTable.Refresh();

                if (rowToUpdate != -1)
                {
                    //Show Status message box
                    System.Windows.MessageBox.Show("Deliverer:  " + DelivererID + " - " + lastName + ", " + firstName + " UPDATED in Deliverers Table");
                }
            }
        }