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

namespace QW2021C.Resultate
{
    public partial class Auswertungen : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Page.IsPostBack == false) return;
            //Ort_checkboxes();
        }

        //public void Ort_checkboxes()
        //{
        //    clsDB db = new clsDB();
        //    db.Get_Tabledata("select ortnr, ort from res_ort order by sort asc", false, true);
        //    int i;
        //    i = 0;
        //    this.CheckBox1.Visible = false;
        //    this.CheckBox2.Visible = false;
        //    this.CheckBox3.Visible = false;
        //    this.CheckBox4.Visible = false;
        //    this.CheckBox5.Visible = false;
        //    this.CheckBox6.Visible = false;
        //    this.CheckBox7.Visible = false;
        //    this.CheckBox8.Visible = false;

        //    foreach (DataRow r in db.dsdaten.Tables[0].Rows)
        //    {
        //        i += 1;


        //        switch (i)
        //        {
        //            case 1:
        //                this.CheckBox1.Text = r["ort"].ToString();
        //                this.CheckBox1.Visible = true;
        //                break;
        //            case 2:
        //                this.CheckBox2.Text = r["ort"].ToString();
        //                this.CheckBox2.Visible = true;
        //                break;
        //            case 3:
        //                this.CheckBox3.Text = r["ort"].ToString();
        //                this.CheckBox3.Visible = true;
        //                break;
        //            case 4:
        //                this.CheckBox4.Text = r["ort"].ToString();
        //                this.CheckBox4.Visible = true;
        //                break;
        //            case 5:
        //                this.CheckBox5.Text = r["ort"].ToString();
        //                this.CheckBox5.Visible = true;
        //                break;
        //            case 6:
        //                this.CheckBox6.Text = r["ort"].ToString();
        //                this.CheckBox6.Visible = true;
        //                break;
        //            case 7:
        //                this.CheckBox7.Text = r["ort"].ToString();
        //                this.CheckBox7.Visible = true;
        //                break;
        //            case 8:
        //                this.CheckBox8.Text = r["ort"].ToString();
        //                this.CheckBox8.Visible = true;

        //                break;
        //        }

        //    }
        //}

        private DataTable Get_Orttabelle(string orte)
        {
            DataTable ortdata = new DataTable();
            ortdata.Columns.Add("Ort");
            string[] Ortlist = orte.Split(';');
            for (int i = 0; i < Ortlist.Length; i = i + 1)
            {
                DataRow dr = ortdata.NewRow();
                dr[0] = Ortlist[i].ToString();
                ortdata.Rows.Add(dr);
            }
            return ortdata;
        }




        protected void btnAufbereiten_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)
        {
            string s = "";
            for (int i = 0; i < this.CheckBoxList1.Items.Count; i = i + 1)
            {
                if (this.CheckBoxList1.Items[i].Selected == true)
                {
                    if (s != "") s = s + ";";
                    s = s + this.CheckBoxList1.Items[i].Value.ToString();
                }
            }

            string orte = s;
            string  U1012 = "N";
            string erdgas = "N";
            string vierkampf = "N";
            int ortnr = 0;

            if (this.cbu10U12.Checked == true)
            {
                U1012 = "J";
            }

            DataSet ds = new DataSet();
            clsDB db = new clsDB();
            db.Get_Reportdata(orte, U1012, erdgas, vierkampf,ortnr);
            string dataname = DateTime.Now.ToString("ddMMyyyyHHmmss") + "_Rpt.xml";

            DataTable ortdata = Get_Orttabelle(orte);

            //ortdata.Columns.Add("Ort");
            //string[] Ortlist = orte.Split(';');
            //for (int i = 0;i < Ortlist.Length; i=i+1)
            //{
            //    DataRow dr = ortdata.NewRow();
            //    dr[0] = Ortlist[i].ToString();
            //    ortdata.Rows.Add(dr);
            //}
            db.dsdaten.Tables[0].TableName = "_data";
            ds.Tables.Add(ortdata);
            ds.Tables.Add(db.dsdaten.Tables[0].Copy());
            ds.WriteXml(Server.MapPath("~\\Workdir\\"+dataname));
            Session["ReportDaten"] = Server.MapPath("~\\Workdir\\" + dataname);
            Session["Report"] = "";

            this.pnlreports.Visible = true;
            string newpage ="~\\Resultate\\Report.aspx";
           
        }

        protected void btnAufbereitenEinzelort_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)
        {
            string U1012 = "N";
            string erdgas = "N";
            string vierkampf = "N";
            string s;
            string orte;
            int ortnr = 0;
            s = this.selEinzelauswertung.Text.ToString();
            clsDB db = new clsDB();
            db.Get_Tabledata("Select * from res_ort where ort='" + s.ToString() + "'", false, true);
            if (db.dsdaten.Tables[0].Rows.Count == 0) return;
            ortnr = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][0]);
            db.dsdaten.Tables.Clear();

            
         
            orte = s;
            DataTable ortdata = Get_Orttabelle(orte);
            if (this.cbu10u12Einzel.Checked == true) U1012 = "J";

            DataSet ds = new DataSet();
            //clsDB db = new clsDB();
            db.Get_Reportdata(orte, U1012, erdgas, vierkampf,ortnr);
            string dataname = DateTime.Now.ToString("ddMMyyyyHHmmss") + "_Rpt.xml";

            db.dsdaten.Tables[0].TableName = "_data";
            ds.Tables.Add(ortdata);
            ds.Tables.Add(db.dsdaten.Tables[0].Copy());
            ds.WriteXml(Server.MapPath("~\\Workdir\\" + dataname));
            Session["ReportDaten"] = Server.MapPath("~\\Workdir\\" + dataname);
            Session["Report"] = "";
            this.pnlEinzelreport.Visible = true;

        }

        protected void btnAufbereitenVierkampf_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)
        {
            Session["Kopfzeile1"] = this.Kopfzeile1.Text;
            Session["Titel"] = this.Titel.Text;
            Session["Stadion"] = this.Stadion.Text;
            Session["Organisator"] = this.Organisator.Text;
            Session["Datum"] = this.Datum.Text;
            Session["Wettkampfnr"] = this.Wettkampfnr.Text;
            string U1012 = "N";
            string erdgas = "N";
            string vierkampf = "J";
            string s;
            string orte;
            int ortnr = 0;
            s = this.selUBSErdgas.Value.ToString();
            if (s == "") return;

            clsDB db = new clsDB();
            db.Get_Tabledata("Select * from res_ort where ort='" + s.ToString() + "'", false, true);
            if (db.dsdaten.Tables[0].Rows.Count == 0) return;
            ortnr = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][0]);
            db.dsdaten.Tables.Clear();


            orte = s;
            DataTable ortdata = Get_Orttabelle(orte);
            if (this.cbu10u12Einzel.Checked == true) U1012 = "J";

            DataSet ds = new DataSet();
            db.Get_Reportdata(orte, U1012, erdgas, vierkampf,ortnr);
            string dataname = DateTime.Now.ToString("ddMMyyyyHHmmss") + "_Rpt.xml";

            db.dsdaten.Tables[0].TableName = "_mehrkampf";
            ds.Tables.Add(ortdata);
            ds.Tables.Add(db.dsdaten.Tables[0].Copy());
            ds.WriteXml(Server.MapPath("~\\Workdir\\" + dataname));
            Session["ReportDaten"] = Server.MapPath("~\\Workdir\\" + dataname);
            Session["Report"] = "";
            this.PnlVierkampfUBS.Visible = true;
        }

        protected void btnAufbereitenUKC_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)
        {
            Session["Kopfzeile1"] = this.Kopfzeile1.Text;
            Session["Titel"] = this.Titel.Text;
            Session["Stadion"] = this.Stadion.Text;
            Session["Organisator"] = this.Organisator.Text;
            Session["Datum"] = this.Datum.Text;
            Session["Wettkampfnr"] = this.Wettkampfnr.Text;
            string U1012 = "N";
            string erdgas = "J";
            string vierkampf = "N";
            string s;
            string orte;
            int ortnr = 0;
            s = this.selUBSErdgas.Text.ToString();
            clsDB db = new clsDB();
            db.Get_Tabledata("Select * from res_ort where ort='" + s.ToString() + "'", false, true);
            if (db.dsdaten.Tables[0].Rows.Count == 0) return;
            ortnr = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][0]);
            db.dsdaten.Tables.Clear();

            orte = s;
            DataTable ortdata = Get_Orttabelle(orte);
            if (this.cbu10u12Einzel.Checked == true) U1012 = "J";

            DataSet ds = new DataSet();
            
            db.Get_Reportdata(orte, U1012, erdgas, vierkampf,ortnr);
            string dataname = DateTime.Now.ToString("ddMMyyyyHHmmss") + "_Rpt.xml";

            db.dsdaten.Tables[0].TableName = "_data";
            ds.Tables.Add(ortdata);
            ds.Tables.Add(db.dsdaten.Tables[0].Copy());
            ds.WriteXml(Server.MapPath("~\\Workdir\\" + dataname));
            Session["ReportDaten"] = Server.MapPath("~\\Workdir\\" + dataname);
            Session["Report"] = "";
            this.PnlVierkampfUBS.Visible = true;
        }
    }


}