using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components;
using System.Diagnostics;
using System.Globalization;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
using Microsoft.JSInterop;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Net.Http;
using System.Data.SqlClient;
using System.Data;
using static Todo.Pages.LoginCheck;
namespace Todo.Pages
{
    public class Projes3
    {
        public int proje_id {get;set;}
        public string proje_adi {get;set;}
        public string proje_baslangic {get;set;}
        public string proje_bitis {get;set;}
        public int bolum_id{get;set;}
}
    public class Gorevs2{
     public int gorev_id{get;set;}
     public int proje_id{get;set;}
     public string gorev {get;set;}
     public int bolum_id{get;set;}
     public int gorev_durum{get;set;}
    }
    public class Bolums2{
     public int bolum_id{get;set;}
     public string bolum_adi {get;set;}
    }
    public class GorevGuncelleAtaBase:ComponentBase
    {
    [Inject]
    public NavigationManager NavigationManager { get; set; }
    public List<Projes3> projes=new List<Projes3>();
    public List<Gorevs2> gorevs=new List<Gorevs2>();
    public List<Bolums2> bolums=new List<Bolums2>();
    public string Gorevsilid{get;set;}
    public string Gorevguncid{get;set;}
    public string Gorevyeni{get;set;}


     protected override async Task OnInitializedAsync()
    {
        if(Loginclass.m1=="NULL" && Loginclass.m2=="NULL")
        {
            NavigationManager.NavigateTo("/");
        }
        else
        {
        if(Loginclass.rol_id_tut=="1"){
        projes.Clear();
        gorevs.Clear();
        bolums.Clear();
        projes=Projegoster();
        gorevs=Gorevgoster();
        bolums=Bolumgoster();
    }
        }
    }



    public List<Gorevs2> Gorevgoster(){
        string db = @"workstation id=blazortodos.mssql.somee.com;packet size=4096;user id=latral4_SQLLogin_1;pwd=516swqticy;data source=blazortodos.mssql.somee.com;persist security info=False;initial catalog=blazortodos";
       SqlConnection baglanti = new SqlConnection(db);
       string sql = "select *from Gorev";
       SqlDataAdapter daps= new SqlDataAdapter (sql,baglanti);
        DataSet dsps = new DataSet();
       try
        {
        daps.Fill(dsps, "gorevs");
        for (int i = 0; i < dsps.Tables[0].Rows.Count; i++)  
        { 
        Gorevs2 pm = new Gorevs2();
        pm.gorev_id = Int32.Parse(dsps.Tables[0].Rows[i]["gorev_id"].ToString());  
        pm.proje_id = Int32.Parse(dsps.Tables[0].Rows[i]["proje_id"].ToString());
        pm.gorev = dsps.Tables[0].Rows[i]["gorev"].ToString();
        pm.bolum_id = Int32.Parse(dsps.Tables[0].Rows[i]["bolum_id"].ToString());
        pm.gorev_durum = Int32.Parse(dsps.Tables[0].Rows[i]["gorev_durum"].ToString());
        gorevs.Add(pm);  
        }
        }
        catch (Exception ex)
        {
        Console.WriteLine(ex.Message);
        }
        return gorevs;
     }



     public List<Bolums2> Bolumgoster(){
        string db = @"workstation id=blazortodos.mssql.somee.com;packet size=4096;user id=latral4_SQLLogin_1;pwd=516swqticy;data source=blazortodos.mssql.somee.com;persist security info=False;initial catalog=blazortodos";
       SqlConnection baglanti = new SqlConnection(db);
       string sql = "select *from Bolum";
       SqlDataAdapter daps= new SqlDataAdapter (sql,baglanti);
        DataSet dsps = new DataSet();
       try
        {
        daps.Fill(dsps, "bolums");
        for (int i = 0; i < dsps.Tables[0].Rows.Count; i++)  
        { 
        Bolums2 pm = new Bolums2();
        pm.bolum_id = Int32.Parse(dsps.Tables[0].Rows[i]["bolum_id"].ToString());  
        pm.bolum_adi = dsps.Tables[0].Rows[i]["bolum_adi"].ToString();
        bolums.Add(pm);  
        }
        }
        catch (Exception ex)
        {
        Console.WriteLine(ex.Message);
        }
        return bolums;
     }



     public List<Projes3> Projegoster(){
     string db = @"workstation id=blazortodos.mssql.somee.com;packet size=4096;user id=latral4_SQLLogin_1;pwd=516swqticy;data source=blazortodos.mssql.somee.com;persist security info=False;initial catalog=blazortodos";
       SqlConnection baglanti = new SqlConnection(db);
       string sql = "select *from Proje";
       SqlDataAdapter daps= new SqlDataAdapter (sql,baglanti);
        DataSet dsps = new DataSet();
            try
            {
            daps.Fill(dsps, "projes");
            for (int i = 0; i < dsps.Tables[0].Rows.Count; i++)  
            { 
            Projes3 pm = new Projes3();
                 pm.proje_id =  Int32.Parse(dsps.Tables[0].Rows[i]["proje_id"].ToString());  
                 pm.proje_adi = dsps.Tables[0].Rows[i]["proje_adi"].ToString();
                 pm.proje_baslangic = dsps.Tables[0].Rows[i]["proje_baslangic"].ToString();
                 pm.proje_bitis = dsps.Tables[0].Rows[i]["proje_bitis"].ToString();
                 pm.bolum_id = Int32.Parse(dsps.Tables[0].Rows[i]["bolum_id"].ToString());
            projes.Add(pm);
            }
            }
            catch (Exception ex)
            {
             Console.WriteLine(ex.Message);
            }
        return projes;
    }


    public void gorevsil(){
    string db = @"workstation id=blazortodos.mssql.somee.com;packet size=4096;user id=latral4_SQLLogin_1;pwd=516swqticy;data source=blazortodos.mssql.somee.com;persist security info=False;initial catalog=blazortodos";
    SqlConnection baglanti = new SqlConnection(db);
    baglanti.Open();
    SqlCommand cmd = baglanti.CreateCommand();
    cmd.CommandText =  "delete from gorev where gorev_id="+Int32.Parse(Gorevsilid)+"";
    Console.WriteLine(cmd.CommandText);
    cmd.ExecuteNonQuery();
    baglanti.Close();
    }


    public void gorevguncelle(){
    string db = @"workstation id=blazortodos.mssql.somee.com;packet size=4096;user id=latral4_SQLLogin_1;pwd=516swqticy;data source=blazortodos.mssql.somee.com;persist security info=False;initial catalog=blazortodos";
    SqlConnection baglanti = new SqlConnection(db);
    baglanti.Open();
    SqlCommand cmd = baglanti.CreateCommand();
    cmd.CommandText =  "update gorev set gorev='"+Gorevyeni+"' where gorev_id="+Int32.Parse(Gorevguncid)+"";
    Console.WriteLine(cmd.CommandText);
    cmd.ExecuteNonQuery();
    baglanti.Close();
    }


    }
}


