Esempio n. 1
0
        //********************************************* Methods interacting with the Database *******************************************

        //It inserts the new Schedules for the selected Date and all the Instructors
        private void insertNewSchedulesForInstructor(string instructor, string[][] schedules)
        {
            //It checks the data from the matrix coming from the ListView
            for (int i = 1; i < schedules.Length - 1; i++)  //days
            {
                string myDate = listViewWeek.Columns[i].Text;
                for (int j = 0; j < schedules[0].Length - 1; j++)   //hours
                {
                    //The information to proceed with the INSERT query
                    string myTime = timesOfDate[j];
                    string value  = schedules[i][j];
                    int    slotId = 1;
                    //IT checks that value=1
                    if (value != "0")
                    {
                        if (!DBData.checkExistingAppointment(instructor, myDate, myTime))
                        {
                            var insertQuery = $"INSERT INTO Appointments (usernameInstructor, idTimeSlot, slotDate, slotTime) VALUES('{instructor}', {slotId}, '{ControlFunctions.formatToSQLDate(DateTime.Parse(myDate))}', '{myTime}')";
                            SQL.executeQuery(insertQuery);
                        }
                    }
                }
            }
            MessageBox.Show("Instructors Schedules saved successfully.");
        }
Esempio n. 2
0
 //It inserts the new Schedules for the selected Date and all the Instructors confirming the Schedules
 private void insertNewSchedules(string myDate, string[][] schedules)
 {
     //It checks the data from the matrix coming from the ListView
     for (int i = 1; i < schedules.Length - 1; i++)
     {
         for (int j = 0; j < schedules[0].Length - 1; j++)
         {
             //The information to proceed with the INSERT query
             string instructor         = instructorsUserNames[i - 1];
             string carAssignedForWeek = getCarsAssignedToInstructor(instructor, firstDayOfWeek, lastDayOfWeek);
             //string carLicense = cars[i - 1];
             string myTime = timesOfDate[j];
             string value  = schedules[i][j];
             int    slotId = 1;
             //IT checks that value=1
             if (value != "0")
             {
                 if (!DBData.checkExistingAppointment(instructor, myDate, myTime))
                 {
                     var insertQuery = "";
                     if (carAssignedForWeek == "")
                     {
                         insertQuery = $"INSERT INTO Appointments (usernameInstructor, idTimeSlot, slotDate, slotTime, confirmed) VALUES('{instructor}', {slotId}, '{ControlFunctions.formatToSQLDate(DateTime.Parse(myDate))}', '{myTime}', 1)";
                     }
                     else
                     {
                         insertQuery = $"INSERT INTO Appointments (usernameInstructor, idTimeSlot, slotDate, slotTime, carLicense, confirmed) VALUES('{instructor}', {slotId}, '{ControlFunctions.formatToSQLDate(DateTime.Parse(myDate))}', '{myTime}', '{carAssignedForWeek}', 1)";
                     }
                     SQL.executeQuery(insertQuery);
                 }
             }
         }
     }
     MessageBox.Show("Instructors Schedules saved successfully. Now assign a car to the required Instructors.");
 }