using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QW2021C.Administration
{
    public partial class AppParameter : System.Web.UI.Page
    {
        clsDB db = new clsDB();
        Helper.Log log = new Helper.Log();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Session["LoggedIn"].ToString() == "False")
                {
                    Response.Redirect("~/default.aspx");
                    return;
                }
            }
            catch
            {
                Response.Redirect("~/default.aspx");
                return;

            }
            if (!IsPostBack)
            { 
            db.Get_Tabledata("Select * from applikation", false, true);
            this.chkUserAnmeldung.Checked = Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["Useranmelungmoeglich"]);
            this.chkRunde1.Checked = Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["Anmelderunde1"]);
            this.chkRunde2.Checked = Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["Anmelderunde2"]);
            this.chkRunde3.Checked = Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["Anmelderunde3"]);
            this.chkRunde4.Checked = Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["Anmelderunde4"]);
            this.ftbtitel.Text= db.dsdaten.Tables[0].Rows[0]["CenterTitle"].ToString();
            this.ftbtext.Text = db.dsdaten.Tables[0].Rows[0]["CenterText"].ToString();
            this.ftbnews.Text = db.dsdaten.Tables[0].Rows[0]["RightNews"].ToString();
            }
            if (Session["LoggedIn"].ToString() == "False")
            {
                Response.Redirect("~/default.aspx");
                return;
            }
        }

        protected void ToggleButton1_Click(object Sender, Syncfusion.JavaScript.Web.ToggleButtonEventArgs e)
        {
            //string demo;
            //demo = this.chkOnOff.Checked.ToString();
        }

        protected void btnSave_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)
        {
            
            db.Get_Tabeldata_for_Update("select * from applikation", false, true);
            db.dsdaten.Tables[0].Rows[0]["Useranmelungmoeglich"] = this.chkUserAnmeldung.Checked;
            db.dsdaten.Tables[0].Rows[0]["Anmelderunde1"] = this.chkRunde1.Checked;
            db.dsdaten.Tables[0].Rows[0]["Anmelderunde2"] = this.chkRunde2.Checked;
            db.dsdaten.Tables[0].Rows[0]["Anmelderunde3"] = this.chkRunde3.Checked;
            db.dsdaten.Tables[0].Rows[0]["Anmelderunde4"] = this.chkRunde4.Checked;
            db.dsdaten.Tables[0].Rows[0]["CenterTitle"] = this.ftbtitel.Text;
            db.dsdaten.Tables[0].Rows[0]["CenterText"] = this.ftbtext.Text;
            //db.dsdaten.Tables[0].Rows[0]["RightNews"] = this.txtNews.Text;
            db.dsdaten.Tables[0].Rows[0]["RightNews"] = this.ftbnews.Text;
            db.Update_Tabeldata();
            log.insert_entry(2, Convert.ToInt32(Session["UserID"]), "Parameter gespeichert");

        }

        protected void btndelete_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)
        {
            if (this.chkDelAnmeldung.Checked == true) db.truncate_table("Anmeldung");
            if (this.chkdelteilnehmer.Checked == true) db.Get_Tabledata("delete from teilnehmer where teilnehmernr > -999999", false, true);
            if (this.chkdelathleten.Checked == true) db.truncate_table("base_athlete");
            if (this.chkdelvereine.Checked == true) db.truncate_table("base_account");
            if (this.ChkDelMannschaften.Checked==true) db.Get_Tabledata("delete from mannschaft where mannschaftsnr > -1", false, true);
            this.chkdelathleten.Checked = false;
            this.chkdelteilnehmer.Checked = false;
            this.chkdelvereine.Checked = false;
            this.chkDelAnmeldung.Checked = false;
            this.ChkDelMannschaften.Checked = false;
            log.insert_entry(2, Convert.ToInt32(Session["UserID"]), "Daten gelöscht: Anmeldung"+this.chkDelAnmeldung.Checked.ToString()+" Teilnehmer:"+this.chkdelteilnehmer.Checked.ToString()+" Athleten:"+this.chkdelathleten.Checked.ToString()+" Vereine:"+chkdelvereine.Checked.ToString()+" Mannschaften:"+this.ChkDelMannschaften.Checked.ToString());

        }
    }
}