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 pro_todo.Pages.Users;


namespace pro_todo.Pages{
    public class proje{
        
        public string proje_id{get;set;}
        public string proje_adi{get;set;}

        public string proje_bitis_tarihi{get;set;}
        public string proje_bolum_id{get;set;}
        public string proje_baskani{get;set;}
    }
    


    
        public  class BaskanPageBase:ComponentBase{
        [Inject]
        IJSRuntime JSRuntime { get; set; }
        static string BaglantiKodu="workstation id=protodo.mssql.somee.com;packet size=4096;user id=Ruveyda044_SQLLogin_1;pwd=xyzm27u3xo;data source=protodo.mssql.somee.com;persist security info=False;initial catalog=protodo";
        static  SqlConnection Baglanti = new SqlConnection(BaglantiKodu);
        static string KomutKodu = "select *from proje";
        static SqlDataAdapter ProjelerDataAdapter= new SqlDataAdapter (KomutKodu, Baglanti);
        SqlCommandBuilder ProjelerKomut = new SqlCommandBuilder(ProjelerDataAdapter);
        DataSet ProjelerDataSet = new DataSet();

   
       
        public List<proje> projeler=new List<proje>();

        public string inputadi{get;set;}
        public string inputid{get;set;}
        public static DateTime tarih{get;set;}

        public string inputbitistarihi{get;set;}
        public string inputbolumid{get;set;}
        public string projebaskani{get;set;}


       public async Task InsertData() 
       {           
       SqlCommand komut=Baglanti.CreateCommand();
       komut.CommandText="insert into proje(proje_adi,proje_bitiş_tarihi,bolum_id,proje_baskani) values('"+inputadi+"','"+inputbitistarihi+"',"+MyUser.kullanici_bolum+","+MyUser.kullanici_id+")";
       Baglanti.Open();
       komut.ExecuteNonQuery();
       Baglanti.Close();
       //RollerKomut.Dispose();
       //RollerDataSet.Tables["roller"].Clear();
       inputadi="";
       ProjelerKomut.Dispose();
       ProjelerDataSet.Tables["proje"].Clear();
       await OnInitializedAsync();
      }
        
      

       protected override async Task OnInitializedAsync() 
        {
            if(MyUser.kullanici_email != "NULL" && MyUser.kullanici_sifre != "NULL" && MyUser.kullanici_rol == "2" && MyUser.kullanici_bolum != "NULL" && MyUser.kullanici_id != "NULL")
            {
            projeler.Clear();
            projeler=ProjeGetir();
            }
            else
            {
            JSRuntime.InvokeVoidAsync("logingit");
            }
        }

        public List<proje> ProjeGetir(){
        try
            {
                ProjelerDataAdapter.Fill(ProjelerDataSet, "proje");
               
                for (int i = 0; i < ProjelerDataSet.Tables[0].Rows.Count; i++)  
                {  
                  proje pm = new proje();  
                  pm.proje_id =  ProjelerDataSet.Tables[0].Rows[i]["proje_id"].ToString();  
                  pm.proje_adi = ProjelerDataSet.Tables[0].Rows[i]["proje_adi"].ToString();  
                  pm.proje_bitis_tarihi = ProjelerDataSet.Tables[0].Rows[i]["proje_bitiş_tarihi"].ToString();  
                  pm.proje_bolum_id = ProjelerDataSet.Tables[0].Rows[i]["bolum_id"].ToString();  
                  pm.proje_baskani = ProjelerDataSet.Tables[0].Rows[i]["proje_baskani"].ToString();
                 projeler.Add(pm);  
                 }   
              }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        return projeler;
       }


       public void tarihgetir(ChangeEventArgs e){
        tarih=DateTime.Parse(e.Value.ToString());
        inputbitistarihi=tarih.ToString("dd/MM/yyyy");
       }




        }

      
         


}
