using System;
using System.Data.SqlClient;
using Microsoft.JSInterop;
using System.Threading.Tasks;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
using System.Data;
using Todo_App.Data;
using System.Text.Json;
using Todo_App.Data;
namespace Todo_App.Pages
{
    public partial class NormalUserPage
    {
        public class gelen_gorevler
        {
            public int task_id { get; set; }
        }
        SqlConnection baglanti = new SqlConnection("workstation id=BlazorOSM.mssql.somee.com;packet size=4096;user id=mssql_58_SQLLogin_1;pwd=ztdvdv9bog;data source=BlazorOSM.mssql.somee.com;persist security info=False;initial catalog=BlazorOSM");

        List<gelen_gorevler> gelen_gorevler_list = new List<gelen_gorevler>();
        public string kullanici_isim{get;set;}
        public string kullanici_soyisim{get;set;}
       
        protected override void OnInitialized()
        {
            kullanici_isim=Login_info.name;
            kullanici_soyisim=Login_info.surname;     
            try
            {
                System.Console.WriteLine(Login_info.id);
                SqlCommand cmd = new SqlCommand("Todo_Get_Gorev_NormalUser", baglanti);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@user_id", Int32.Parse(Login_info.id.ToString()));
                baglanti.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    gelen_gorevler_list.Add(new gelen_gorevler { task_id = Int32.Parse(dr["Task_ID"].ToString()) });
                }
                baglanti.Close();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }

        public string gelen_task_content{get;set;}
        public string gelen_task_id{get;set;}
        public string gelen_task_sender_id{get;set;}
        public string gelen_task_start_date{get;set;}
        public string gelen_task_finish_date{get;set;}
        public MarkupString result ;
        public void normal_gorev_getir(int a)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("Todo_Get_Gorev_NormalUser2", baglanti);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@task_id", Int32.Parse(a.ToString()));
                baglanti.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read()){
                    gelen_task_id=a.ToString();
                    result=new MarkupString(dr["Task_Content"].ToString());
                    gelen_task_content=result.ToString();
                    gelen_task_sender_id=dr["Task_sender_ID"].ToString();
                    gelen_task_start_date=dr["Task_start_date"].ToString();
                    gelen_task_finish_date=dr["Task_finish_date"].ToString();
                }
                baglanti.Close();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
    }
}