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 kullanici
      {
        public string kullanici_email {get;set;}
        public string kullanici_sifre {get;set;} 
      }
    

    public  class AdminPage3Base: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 kullanicilar";
        static SqlDataAdapter ProjelerDataAdapter= new SqlDataAdapter (KomutKodu, Baglanti);
        SqlCommandBuilder ProjelerKomut = new SqlCommandBuilder(ProjelerDataAdapter);
        DataSet ProjelerDataSet = new DataSet();

     public  List<kullanici> kullanicilar= new List<kullanici>();
    
     public  string error{get; set;}
      
      public string inputEmail{get; set;}
      public string inputSifre{get; set;} 
      
       public async Task SifreUpdateData()  
      { 
        SqlCommand komut=Baglanti.CreateCommand();
        komut.CommandText="update kullanicilar set kullanici_sifre='"+inputSifre+"' where kullanici_email='"+MyUser.kullanici_email+"'";
        Baglanti.Open();
        komut.ExecuteNonQuery();
        Baglanti.Close();

        inputSifre="";
        
        await OnInitializedAsync();
      }

      public async Task EmailUpdateData()  
      { 
        SqlCommand komut=Baglanti.CreateCommand();
        komut.CommandText="update kullanicilar set kullanici_email='"+inputEmail+"' where kullanici_email='"+MyUser.kullanici_email+"'";
        MyUser.kullanici_email=inputEmail;
        Baglanti.Open();
        komut.ExecuteNonQuery();
        Baglanti.Close();

        inputSifre="";
        inputEmail="";
        
        await OnInitializedAsync();
      }

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







    }


  }

  
     
   /*  public async Task UpdateData()  //güncelleme işlemi
    { 
       DataRowCollection itemColumns = dsps.Tables[0].Rows;
       for (int i = 0; i < dsps.Tables[0].Rows.Count; i++)  
       {  
         if(dsps.Tables[0].Rows[i]["kullanici_email"].ToString()==inputEmail)  
                 dsps.Tables[0].Rows[i]["kullanici_sifre"]=inputSifre;  
       }   
             
       daps.Update(dsps,"admin");
       cb.Dispose();
       dsps.Tables["admin"].Clear();
       
       inputEmail="";
       inputSifre="";
       
       await OnInitializedAsync();
    }  */
  /* protected override async Task OnInitializedAsync()
    {
        people.Clear();
        await selectproc();
          
    }
     public  Task selectproc()
    {
       return Task.Run(() =>
          {
      
            try
            {
                daps.Fill(dsps, "people");
                error+=dsps.Tables[0].Rows.Count.ToString();
                for (int i = 0; i < dsps.Tables[0].Rows.Count; i++)  
                {  
                 admin pm = new admin();  
                 pm.kullanici_email =  dsps.Tables[0].Rows[i]["kullanici_email"].ToString();  
                 pm.kullanici_sifre = dsps.Tables[0].Rows[i]["kullanici_sifre"].ToString();  
                 
                 people.Add(pm);  
                 }   
             
              }
            catch (Exception ex)
            {
                 error=ex.ToString();

            }
         });
    } */
          

  
      