protected void SubmitClick(object sender, EventArgs e)
        {
            UserClass Usr = (UserClass)Session["User"];
            int Time = Convert.ToInt32(HourOT.Value);
            string Day = DayOfTheWeek.SelectedValue.ToString();
            string Name = "TrainingName";
            Name = NameOfTraining.Value.ToString();
            int WarmingNumberOfSets = Convert.ToInt32(WrNOS.Value);
            int WarmingNumverOfExercices = Convert.ToInt32(WrNOE.Value);
            int WarmingExerciceId = Convert.ToInt32(WrTypeOfExercices.SelectedValue);
            int SkillNumberOfSets = Convert.ToInt32(SkNOS.Value);
            int SkillNumberOfExercices = Convert.ToInt32(SkNOE.Value);
            int SkillExerciceId = Convert.ToInt32(SkTypeOfExercices.SelectedValue);
            int WodNumberOfSets = Convert.ToInt32(WodNOS.Value);
            int WodNumberOfExercices = Convert.ToInt32(WodNOE.Value);
            int WodExerciceId = Convert.ToInt32(WodTypeOfExercicies.SelectedValue);

            TrainingClass NewTraining = new TrainingClass(Usr.GetId(), Name, Day, Time);
            if (ConnectionClass.IsFree(NewTraining))
            {
                ConnectionClass.InsertNewTraining(NewTraining);
                int id = ConnectionClass.GetTrainingIdFromDB(NewTraining);
                NewTraining.SetId(id);
                StagesClass Warming = new StagesClass(WarmingNumberOfSets, WarmingNumverOfExercices, WarmingExerciceId, NewTraining.GetTrainingId(), "Warming");
                StagesClass Skill = new StagesClass(SkillNumberOfSets, SkillNumberOfExercices, SkillExerciceId, NewTraining.GetTrainingId(), "Skill");
                StagesClass Wod = new StagesClass(WodNumberOfSets, WodNumberOfExercices, WodExerciceId, NewTraining.GetTrainingId(), "Wod");
                ConnectionClass.InsertStage(Warming);
                ConnectionClass.InsertStage(Skill);
                ConnectionClass.InsertStage(Wod);
                Response.Redirect("Program.aspx");

            }
            else
            { VforTime.Visible = true; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["TId"] == null || !int.TryParse(Request.QueryString["TId"], out TrainingId) || !ConnectionClass.TrainingExists(TrainingId))
            {
                Response.Redirect("Program.aspx");
            }
            UserC = (UserClass)Session["User"];
            Tr = ConnectionClass.GetTrainingById(TrainingId);
            Warming = ConnectionClass.GetStageByTrainingIdAndType(Tr.GetTrainingId(), "Warming");
            Skill = ConnectionClass.GetStageByTrainingIdAndType(Tr.GetTrainingId(), "Skill");
            Wod = ConnectionClass.GetStageByTrainingIdAndType(Tr.GetTrainingId(), "Wod");
            if (Tr.GetTrainerId() != UserC.GetId())
            {
                Response.Redirect("Program.aspx");

            }
            if (!IsPostBack)
                FillPanel();
        }
 public static void UpdateTraining(TrainingClass Tr)
 {
     Conn.Open();
     string Query = String.Format("Update [dbo].[Trainings] set Day='{0}', Hour='{1}' ,Trainer_id={2}, Name='{3}' where Id={4}", Tr.GetDay(), Tr.GetHour(), Tr.GetTrainerId(), Tr.GetTrainingName(), Tr.GetTrainingId());
     command = new SqlCommand(Query, Conn);
     command.ExecuteNonQuery();
     Conn.Close();
 }
 public static bool IsFree(TrainingClass Tr)
 {
     Conn.Open();
     string query = String.Format("Select count(*) from [dbo].[Trainings] where Day='{0}' and Hour={1} ", Tr.GetDay(),Tr.GetHour());
     command = new SqlCommand(query, Conn);
     int x = Convert.ToInt32(command.ExecuteScalar());
     Conn.Close();
     if (x >= 1)
         return false;
     return true;
 }
 public static void InsertNewTraining(TrainingClass Tr)
 {
     Conn.Open();
     string Query = String.Format("Insert into [dbo].[Trainings](Day,Hour,Trainer_id,Name) values ('{0}','{1}',{2},'{3}')", Tr.GetDay(), Tr.GetHour(), Tr.GetTrainerId(),Tr.GetTrainingName());
     command = new SqlCommand(Query, Conn);
     command.ExecuteNonQuery();
     Conn.Close();
 }
 public static int GetTrainingIdFromDB(TrainingClass Tr)
 {
     Conn.Open();
     string query = String.Format("Select Id from [dbo].[Trainings] where Day='{0}' and Hour='{1}'", Tr.GetDay(), Tr.GetHour());
     command = new SqlCommand(query, Conn);
     int x = Convert.ToInt32(command.ExecuteScalar());
        Conn.Close();
        return x;
 }
 public static TrainingClass GetTrainingById(int id)
 {
     TrainingClass Tr = new TrainingClass();
     Conn.Open();
     string query = String.Format("Select * from [dbo].[Trainings] where Id={0}", id);
     command = new SqlCommand(query, Conn);
     SqlDataReader reader = command.ExecuteReader();
     while (reader.Read())
     {
         Tr = new TrainingClass(Convert.ToInt32(reader["Id"]), reader["Name"].ToString(), Convert.ToInt32(reader["Trainer_id"]), reader["Day"].ToString(), Convert.ToInt32(reader["Hour"]));
     }
     Conn.Close();
     return Tr;
 }
        public static List<TrainingClass> GetListOfTrainings()
        {
            List<TrainingClass> List = new List<TrainingClass>();
            Conn.Open();
            string query = "Select * from [dbo].[Trainings]";
            command = new SqlCommand(query, Conn);
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                TrainingClass Tr = new TrainingClass(Convert.ToInt32(reader["Id"]),reader["Name"].ToString(),Convert.ToInt32(reader["Trainer_Id"]),reader["Day"].ToString(), Convert.ToInt32(reader["Hour"].ToString()));
                List.Add(Tr);
            }

            Conn.Close();
            return List;
        }