private void btnSaveExit_Click(object sender, RoutedEventArgs e)
 {
     SingleDay sd = new SingleDay(1, GlobalVars.SingleDayToEdit.Date);
     sd.Visits[GlobalVars.VisitToEditIndex].Pat = GlobalVars.PatientsList[dgPat.SelectedIndex];
     DBManager.UpdateTimeTable(GlobalVars.SingleDayToEdit, sd);
     Close();
 }
 public static int UpdateTimeTable(SingleDay iSDOld, SingleDay iSDNew)
 {
     RemoveSingleDay(iSDOld.Id);
     AddSingleDayVisit(iSDNew);
     return 0;
 }
 //Single day with visits - to edit
 public static int AddSingleDayVisit(SingleDay iDay)
 {
     SingleDay sd = new SingleDay(1, iDay.Date);
     sd.Visits = GlobalVars.SingleDayToEdit.Visits;
     sd.Visits[GlobalVars.VisitToEditIndex] = iDay.Visits[GlobalVars.VisitToEditIndex];
     GlobalVars.SingleDaysList.Add(sd);
     Serialize(GlobalVars.SingleDaysList, GlobalVars.SingleDaysDbName);
     CreatingDatabaseSelects.SingleDayInsert(sd);
     return 0;
 }
 public static int AddSingleDay(SingleDay iDay)
 {
     GlobalVars.SingleDaysList.Add(new SingleDay(++GlobalVars.SingleDaysIdCounter, iDay.Date));
     Serialize(GlobalVars.SingleDaysList, GlobalVars.SingleDaysDbName);
     CreatingDatabaseSelects.SingleDayInsert(iDay);
     return 0;
 }
        public static void SingleDayInsert(SingleDay iSD)
        {
            if (GlobalVars.ConnectedToDatabase)
            {
                MySqlConnection con = new MySqlConnection(MyConnectionString);
                con.Open();

                try
                {
                    MySqlCommand cmd = con.CreateCommand();
                    cmd.CommandText = "insert into timetable(id, date) values(" + iSD.Id + ",'" + iSD.Date.ToString()+"');";
                    cmd.ExecuteNonQuery();

                    foreach (SingleVisit s in iSD.Visits)
                    {
                        cmd.CommandText = "insert into singlevisit(id, day_id, minutes) values(" + s.Id + "," + iSD.Id + "," + s.Minutes + ");";
                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
                    }
                }
            }
        }
 /* -- TimeTable -- */
 public static void SingleDayUpdate(SingleDay iSD)
 {
     if (GlobalVars.ConnectedToDatabase)
     {
         SingleDayDelete(iSD.Id);
         SingleDayInsert(iSD);
     }
 }