using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Globalization;
using System.Data.SqlClient;



namespace academy
{
    public partial class login : DevComponents.DotNetBar.OfficeForm
    {
        static SqlConnection con = new SqlConnection("server=(local);database=school;integrated security=true");
        SqlDataAdapter da = new SqlDataAdapter("",con);
        DataSet ds = new DataSet();
        public login()
        {
            InitializeComponent();
            
        }

      

        private void login_Load(object sender, EventArgs e)
        {
            string year, month, day;
            
            PersianCalendar pc = new PersianCalendar();
            year = pc.GetYear(DateTime.Now).ToString();
            month = pc.GetMonth(DateTime.Now).ToString();
            day = pc.GetDayOfMonth(DateTime.Now).ToString();

            labelX1.Text = year + "/" + month + "/" + day.ToString();

            cmb_type.SelectedIndex = 0;

            try
            {
                System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();
                lbltoday.Text =


p.GetYear(DateTime.Now).ToString() + "/" + p.GetMonth(DateTime.Now).ToString("0#") + "/" + p.GetDayOfMonth(DateTime.Now).ToString("0#");

                switch (DateTime.Now.DayOfWeek)
                {
                    case DayOfWeek.Friday:
                        lbltoday.Text = "جمعه";
                        break;
                    case DayOfWeek.Monday:
                        lbltoday.Text = "دوشنبه";
                        break;
                    case DayOfWeek.Saturday:
                        lbltoday.Text = "شنبه";
                        break;
                    case DayOfWeek.Sunday:
                        lbltoday.Text = "یکشنبه";
                        break;
                    case DayOfWeek.Thursday:
                        lbltoday.Text = "پنجشنبه";
                        break;
                    case DayOfWeek.Tuesday:
                        lbltoday.Text = "سه شنبه";
                        break;
                    case DayOfWeek.Wednesday:
                        lbltoday.Text = "چهارشنبه";
                        break;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "خطا");
            }


        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            string hours, minutes, seconds;
            hours = DateTime.Now.TimeOfDay.Hours.ToString();
            minutes = DateTime.Now.TimeOfDay.Minutes.ToString();
            seconds = DateTime.Now.TimeOfDay.Seconds.ToString();

            labelX2.Text = hours + ":" + minutes + ":" + seconds.ToString();
         

            
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
          
            string type;
            if (cmb_type.SelectedIndex == 0) type = "admin";
            else type = "limit";
            string s = "select password from login where type='" + type + "'and username='" + txt_username.Text + "' and password='" + txt_password.Text + "' ";
            SqlDataAdapter da = new SqlDataAdapter(s, con);
            da.Fill(ds, "t1");
            if (ds.Tables["t1"].Rows.Count > 0)
            {
                if (cmb_type.SelectedIndex == 0)
                    variable.i = 1;
                else
                    variable.i = 2;
                this.Hide();
                main m = new main();
                m.Show();
            }

            else
            {
                MessageBox.Show("نام کاربری یا رمز عبور و یا سطح دسترسی اشتباه است", "اخطار");
            }

          


        }       

        
    }
}