private void CreateYear_Click(object sender, RoutedEventArgs e) { //Define local variables string yearToCreate = "Year_" + YearToCreateTextBox.Text; //Create the createYearCommandText - Creates a Year_selectedYear table in the database string createClientYearCommandText = "CREATE TABLE " + yearToCreate + " (Box_Number INTEGER, Client_ID INTEGER, Assigned_Status TEXT)"; //Create the Year_yearToCreate table in the database Main.mChristmasBasketsAccessDatabase.ExecuteNonQuery(createClientYearCommandText); //Create the createDelivererYearCommandText - Creates a Year_yearToCreate_Deliverers table in the database string createDelivererYearCommandText = "CREATE TABLE " + yearToCreate + "_Deliverers" + " (Deliverer_ID INTEGER, Clients TEXT)"; //Create the Year_yearToCreate_Deliverers table in the database Main.mChristmasBasketsAccessDatabase.ExecuteNonQuery(createDelivererYearCommandText); //Create the createFoodYearCommandText - Creates a Year_selectedYear_Food table in the database string createFoodYearCommandText = "CREATE TABLE " + yearToCreate + "_Food" + " (Food_Name TEXT, Food_Number_To_Put_In_Box INTEGER)"; //Create the Year_yearToCreate_Food table in the database Main.mChristmasBasketsAccessDatabase.ExecuteNonQuery(createFoodYearCommandText); //Update the YearsListBox YearsListBox.Items.Add(yearToCreate); YearsListBox.SelectedItem = yearToCreate; YearsListBox.ScrollIntoView(yearToCreate); //Create insertStatusYearCommand to insert and initialize yearToCreate_Status's yearToCreate Record database item string insertStatusYearCommand = "INSERT INTO Status (Year_ID, " + "Step_1_Year_Created_In_Database, " + "Step_2_Clients_Imported, " + "Step_2_a_Check_For_Client_Duplicates, " + "Step_3_Green_Cards_Generated, " + "Step_4_Deliverers_Imported, " + "Step_5_Clients_Assigned_To_Deliverers, " + "Step_6_Generated_Deliverer_Maps, " + "Step_7_Day_Of_Event, " + "Step_7_a_Generate_Unassigned_Clients_Map, " + "Step_7_b_Generate_Client_Lists, " + "Step_7_c_Generate_Food_Signs, " + "Step_7_d_Generate_Box_Labels) " + "VALUES ('" + yearToCreate + "', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0')"; //insert and initialize yearToCreate_Status's yearToCreate Record database item Main.mChristmasBasketsAccessDatabase.ExecuteNonQuery(insertStatusYearCommand); //Update Main.mSelectedYearStatus Main.mSelectedYearStatus[(int)Main.mSelectedYearStatusEnum.Step_1_Year_Created_In_Database] = true; }
public WindowSelectYear() { InitializeComponent(); //Define local variables DataTable userTables = null; // We only want user tables, not system tables string[] restrictions = new string[4]; restrictions[3] = "Table"; //See if we have an Access database if (Main.mChristmasBasketsAccessDatabase != null) { // Get list of user tables userTables = Main.mChristmasBasketsAccessDatabase.GetSchema("Tables", restrictions); } // Add list of table names to listBox for (int i = 0; i < userTables.Rows.Count; i++) { //Only add the Tables formatted as Year_ if (userTables.Rows[i][2].ToString().Contains("Year_") && (!userTables.Rows[i][2].ToString().Contains("Deliverers") && !userTables.Rows[i][2].ToString().Contains("Food"))) { YearsListBox.Items.Add(userTables.Rows[i][2].ToString()); } } //Highlight the selected item if it exists already if (Main.mSelectedYear != "NONE") { // Find the string in ListBox2. int index = YearsListBox.Items.IndexOf(Main.mSelectedYear); // If the item was found in ListBoxOfYears select it in ListBoxOfYears. if (index != -1) { YearsListBox.SelectedIndex = index; YearsListBox.ScrollIntoView(Main.mSelectedYear); } } }