protected void LoginClick(object sender, EventArgs e)
        {
            string username = Username.Value.ToString();
            string password = Password.Value.ToString();
            if (!ConnectionClass.FindUsername(username))
            {
                VUsername.Visible = true;
            }
            else
            {
                UserClass User = new UserClass();
                User = ConnectionClass.GetUserById(ConnectionClass.GetUserId(username));

                if (User.IsCorrectPassword(password))
                {
                    Session["User"] = User;
                    Response.Redirect("Program.aspx");

                }
                else
                {
                    VPassword.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();
        }
        protected void RegisterClick(object sender, EventArgs e)
        {
            string username = Username.Value.ToString();
            string password = Password.Value.ToString();
            string firstname = FirstName.Value.ToString();
            string lastname = LastName.Value.ToString();
            string type = sel1.SelectedIndex.ToString();

            if (ConnectionClass.FindUsername(username))
            {
                VforUn.Visible = true;
            }
            else
            {

                UserClass NewUser = new UserClass(username, password, firstname, lastname,Convert.ToInt32(type));
                NewUser.EncryptPassword();
                ConnectionClass.InsertNewUser(NewUser);
                Response.Redirect("Login.aspx");
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["User"] == null) Response.Redirect("Login.aspx");
     if (Request.QueryString["TId"] == null || !int.TryParse(Request.QueryString["TId"], out TrainingId) || !ConnectionClass.TrainingExists(TrainingId))
     {
         Response.Redirect("Program.aspx");
     }
     UserC = (UserClass)Session["User"];
     FillPanel(TrainingId);
 }
 public static void InsertNewUser(UserClass User)
 {
     Conn.Open();
         string query = String.Format("Insert into [dbo].[Users](Username,Password,Type,Firstname,Lastname) values('{0}','{1}',{2},'{3}','{4}')", User.GetUserName(), User.GetPassword(), User.GetTypeOfUser(), User.GetFirstname(), User.GetLastname());
         command = new SqlCommand(query, Conn);
         command.ExecuteNonQuery();
         Conn.Close();
 }
        public static UserClass GetUserById(int id)
        {
            UserClass Usr = new UserClass();

                Conn.Open();
                string query = String.Format("Select * from [dbo].[Users] where Id = {0}", id);
                command = new SqlCommand(query, Conn);
                SqlDataReader reader = command.ExecuteReader();
                reader.Read();
                Usr = new UserClass(Convert.ToInt32(reader["Id"]), reader["Username"].ToString(), reader["Password"].ToString(), reader["FirstName"].ToString(), reader["Lastname"].ToString(), Convert.ToInt32(reader["Type"]));
                Conn.Close();

            return Usr;
        }