using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Globalization;
using Stimulsoft.Report.Dictionary;
using Stimulsoft.Report;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Rendering;

namespace Library_Red_Diamonds
{
    public partial class main : Form
    {
        static SqlConnection con = new SqlConnection(Connection.con);
        public main()
        {
            InitializeComponent();
        }
        
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter adp = new SqlDataAdapter();
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        PersianCalendar pc = new PersianCalendar();
        MyDate md = new MyDate();
        Random rnd = new Random();

        public void theme()
        {
            cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            SqlDataReader Myreader1;
            cmd.CommandText = "select * from setting";
            con.Open();
            Myreader1 = cmd.ExecuteReader();
            if (Myreader1.Read())
            {
                try
                {
                    switch (Myreader1["theme"].ToString())
                    {
                        case "Office2007blue":
                            {
                                styleManager.ManagerStyle = eStyle.Office2007Blue;
                                break;
                            }
                        case "Office2007silver":
                            {
                                styleManager.ManagerStyle = eStyle.Office2007Silver;
                                break;
                            }


                        case "Office2007black":
                            {
                                styleManager.ManagerStyle = eStyle.Office2007Black;
                                break;
                            }

                        case "Office2010blue":
                            {
                                styleManager.ManagerStyle = eStyle.Office2010Blue;
                                break;
                            }

                        case "Office2010silver":
                            {
                                styleManager.ManagerStyle = eStyle.Office2010Silver;
                                break;
                            }



                        case "Office2010black":
                            {
                                styleManager.ManagerStyle = eStyle.Office2010Black;
                                break;
                            }



                        case "Office2013":
                            {
                                styleManager.ManagerStyle = eStyle.Office2013;
                                break;
                            }


                        case "Office2016":
                            {
                                styleManager.ManagerStyle = eStyle.Office2016;
                                break;
                            }


                        case "Officemob2014":
                            {
                                styleManager.ManagerStyle = eStyle.OfficeMobile2014;
                                break;
                            }


                        case "Office2007VistaGlass":
                            {
                                styleManager.ManagerStyle = eStyle.Office2007VistaGlass;
                                break;
                            }


                        case "VisualStudio2010Blue":
                            {
                                styleManager.ManagerStyle = eStyle.VisualStudio2010Blue;
                                break;
                            }

                        case "VisualStudio2012Light":
                            {
                                styleManager.ManagerStyle = eStyle.VisualStudio2012Light;
                                break;
                            }

                        case "VisualStudio2012Dark":
                            {
                                styleManager.ManagerStyle = eStyle.VisualStudio2012Dark;
                                break;
                            }



                        case "Windows7":
                            {
                                styleManager.ManagerStyle = eStyle.Windows7Blue;
                                break;
                            }
                    }
                }

                catch
                {
                    styleManager.ManagerStyle = eStyle.Office2007Blue;
                }

            }
            Myreader1.Close();
            con.Close();
        }


        public void loadinfo()
        {
            cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            SqlDataReader Myreader;
            cmd.CommandText = "select * from info";
            con.Open();
            Myreader = cmd.ExecuteReader();
            if (Myreader.Read())
            {
                lbl_code.Text = Myreader["code"].ToString();
                lbl_libraryname.Text = Myreader["libraryname"].ToString();
                lbl_owner.Text = Myreader["ownername"].ToString();
                lbl_tel.Text = Myreader["tel"].ToString();
                lbl_address.Text = Myreader["addres"].ToString();
            }

             Myreader.Close();
             con.Close();
        }

        public void clockstyle()
        {
            cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            SqlDataReader Myreader2;
            cmd.CommandText = "select * from setting";
            con.Open();
            Myreader2 = cmd.ExecuteReader();
            if (Myreader2.Read())
            switch (Myreader2["clockstyle"].ToString())
            {
                case "black":
                    {
                        vistaclock.Style = VistaClockPersian.Controls.VistaClock.VistaClockStyle.Black;
                        break;
                    }
                case "silver":
                    {
                        vistaclock.Style = VistaClockPersian.Controls.VistaClock.VistaClockStyle.Silver;
                        break;
                    }

                case "red":
                    {
                        vistaclock.Style = VistaClockPersian.Controls.VistaClock.VistaClockStyle.Red;
                        break;
                    }

                case "flower":
                    {
                        vistaclock.Style = VistaClockPersian.Controls.VistaClock.VistaClockStyle.Flower;
                        break;
                    }
            }
            Myreader2.Close();
            con.Close();
        }


        public void bgclock()
        {
            cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            SqlDataReader Myreader3;
            cmd.CommandText = "select * from setting";
            con.Open();
            Myreader3 = cmd.ExecuteReader();
            if (Myreader3.Read())
            switch (Myreader3["bgclock"].ToString())
            {
                case "پیش فرض":
                    {
                        gp_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Default;
                        break;
                    }
                case "سبز":
                    {
                        gp_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Green;
                        break;
                    }

                case "قرمز":
                    {
                        gp_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Red;
                        break;
                    }

                case "زرد":
                    {
                        gp_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Yellow;
                        break;
                    }
                case "نارنجی":
                    {
                        gp_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Orange;
                        break;
                    }

                case "بنفش":
                    {
                        gp_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Magenta;
                        break;
                    }
            }
            Myreader3.Close();
            con.Close();
        }

        public void bgdate()
        {
            cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            SqlDataReader Myreader4;
            cmd.CommandText = "select * from setting";
            con.Open();
            Myreader4 = cmd.ExecuteReader();
            if (Myreader4.Read())
            switch (Myreader4["bgdate"].ToString())
            {
                case "پیش فرض":
                    {
                        gp_date_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Default;
                        break;
                    }
                case "سبز":
                    {
                        gp_date_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Green;
                        break;
                    }

                case "قرمز":
                    {
                        gp_date_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Red;
                        break;
                    }

                case "زرد":
                    {
                        gp_date_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Yellow;
                        break;
                    }
                case "نارنجی":
                    {
                        gp_date_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Orange;
                        break;
                    }

                case "بنفش":
                    {
                        gp_date_time.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Magenta;
                        break;
                    }
            }
            Myreader4.Close();
            con.Close();
        }


        public void bginfo()
        {
            cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            SqlDataReader Myreader6;
            cmd.CommandText = "select * from setting";
            con.Open();
            Myreader6 = cmd.ExecuteReader();
            if (Myreader6.Read())
            switch (Myreader6["bginfo"].ToString())
            {
                case "پیش فرض":
                    {
                        gp_info.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Default;
                        break;
                    }
                case "سبز":
                    {
                        gp_info.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Green;
                        break;
                    }

                case "قرمز":
                    {
                        gp_info.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Red;
                        break;
                    }

                case "زرد":
                    {
                        gp_info.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Yellow;
                        break;
                    }
                case "نارنجی":
                    {
                        gp_info.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Orange;
                        break;
                    }

                case "بنفش":
                    {
                        gp_info.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Magenta;
                        break;
                    }
            }
            Myreader6.Close();
            con.Close();
        }

        public void bgamar()
        {
            cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            SqlDataReader Myreader7;
            cmd.CommandText = "select * from setting";
            con.Open();
            Myreader7 = cmd.ExecuteReader();
            if (Myreader7.Read())
            switch (Myreader7["bgamar"].ToString())
            {
                case "پیش فرض":
                    {
                        gp_amar.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Default;
                        break;
                    }
                case "سبز":
                    {
                        gp_amar.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Green;
                        break;
                    }

                case "قرمز":
                    {
                        gp_amar.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Red;
                        break;
                    }

                case "زرد":
                    {
                        gp_amar.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Yellow;
                        break;
                    }
                case "نارنجی":
                    {
                        gp_amar.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Orange;
                        break;
                    }

                case "بنفش":
                    {
                        gp_amar.ColorTable = DevComponents.DotNetBar.Controls.ePanelColorTable.Magenta;
                        break;
                    }
            }
            Myreader7.Close();
            con.Close();
        }

       

        private void count()
        {
            SqlCommand com = new SqlCommand("select count (*) from book", con);
            con.Open();
            lbl_books.Text = Convert.ToString((int)com.ExecuteScalar()) + "";
            con.Close();
            //--------------------------------------------------------------------------------------------
            SqlCommand com1 = new SqlCommand("select count (*) from borrowbooks", con);
            con.Open();
            lbl_borrow_book.Text = Convert.ToString((int)com1.ExecuteScalar()) + "";
            con.Close();
            //--------------------------------------------------------------------------------------------
            SqlCommand com2 = new SqlCommand("select count (*) from backbooks", con);
            con.Open();
            lbl_back_book.Text = Convert.ToString((int)com2.ExecuteScalar()) + "";
            con.Close();
            //--------------------------------------------------------------------------------------------
            SqlCommand com3 = new SqlCommand("select count (*) from members", con);
            con.Open();
            lbl_members.Text = Convert.ToString((int)com3.ExecuteScalar()) + "";
            con.Close();
            //--------------------------------------------------------------------------------------------
            SqlCommand com4 = new SqlCommand("select count (*) from users", con);
            con.Open();
            lbl_users.Text = Convert.ToString((int)com4.ExecuteScalar()) + "";
            con.Close();
            //--------------------------------------------------------------------------------------------
        }


        private void days()
        {
            try
            {
                lbl_day.Text = pc.GetDayOfMonth(DateTime.Now).ToString();
                switch (DateTime.Now.DayOfWeek)
                {
                    case DayOfWeek.Saturday:
                        lbl_day.Text = "شنبه";
                        break;
                    case DayOfWeek.Sunday:
                        lbl_day.Text = "بکشنبه";
                        break;
                    case DayOfWeek.Monday:
                        lbl_day.Text = "دوشنبه";
                        break;
                    case DayOfWeek.Tuesday:
                        lbl_day.Text = "سه شنبه";
                        break;
                    case DayOfWeek.Wednesday:
                        lbl_day.Text = "چهارشنبه";
                        break;
                    case DayOfWeek.Thursday:
                        lbl_day.Text = "پنج شنبه";
                        break;
                    case DayOfWeek.Friday:
                        lbl_day.Text = "جمعه";
                        break;
                }

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

            }
        }

        public void setaccess()
        {
            btn_book.Enabled = AccessLevel.books;
            btn_category.Enabled = AccessLevel.categorys;
            btn_member.Enabled = AccessLevel.members;
            btn_member_debit.Enabled = AccessLevel.memberdebits;
            btn_borrow_book.Enabled = AccessLevel.borrowbooks;
            btn_back_book.Enabled = AccessLevel.backbooks;
            btn_fine.Enabled = AccessLevel.fines;
            btn_users.Enabled = AccessLevel.users;
            btn_info.Enabled = AccessLevel.info;
            btn_backup.Enabled = AccessLevel.backups;
            btn_restore.Enabled = AccessLevel.restores;
        }

        private void btn_book_Click(object sender, EventArgs e)
        {
            book b = new book();
            b.ShowDialog();
        }

        private void btn_booklist_Click(object sender, EventArgs e)
        {
            booklist bl = new booklist();
            bl.ShowDialog();
        }

        private void btn_category_Click(object sender, EventArgs e)
        {
            category c = new category();
            c.ShowDialog();
        }

        private void btn_member_Click(object sender, EventArgs e)
        {
            registermember rgm = new registermember();
            rgm.ShowDialog();
        }

        private void btn_member_list_Click(object sender, EventArgs e)
        {
            listmembers lm = new listmembers();
            lm.ShowDialog();
        }

        private void btn_member_debit_Click(object sender, EventArgs e)
        {
            listfine lf = new listfine();
            lf.ShowDialog();
        }

        private void btn_borrow_book_Click(object sender, EventArgs e)
        {
            borrowbooks bb = new borrowbooks();
            bb.ShowDialog();
        }

        private void btn_back_book_Click(object sender, EventArgs e)
        {
            backbook bbk = new backbook();
            bbk.ShowDialog();
        }

        private void btn_book_borrow_list_Click(object sender, EventArgs e)
        {
            listborrowbooks lbb = new listborrowbooks();
            lbb.ShowDialog();
        }

        private void btn_back_book_list_Click(object sender, EventArgs e)
        {
            listbackbook lbbk = new listbackbook();
            lbbk.ShowDialog();
        }

        private void btn_fine_Click(object sender, EventArgs e)
        {
            finebooks fb = new finebooks();
            fb.ShowDialog();
        }

        private void btn_calc_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("calc");
        }

        private void btn_notepad_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("notepad");
        }

        private void btn_users_Click(object sender, EventArgs e)
        {
            users us = new users();
            us.ShowDialog();
        }

        private void btn_setting_Click(object sender, EventArgs e)
        {
            frmsetting fs = new frmsetting();
            fs.ShowDialog();
        }

        private void btn_info_Click(object sender, EventArgs e)
        {
            frmInfo fi = new frmInfo();
            fi.ShowDialog();
        }

        private void main_Load(object sender, EventArgs e)
        {
            //login fl = new login();
            //fl.ShowDialog();
            //if (fl.Result == false)
            //{
            //    Application.Exit();
            //}

            setaccess();
            theme();
            loadinfo();
            clockstyle();
            bgclock();
            bgdate();
            bginfo();
            bgamar();
            count();
            days();

            lbl_date.Text = md.alldate();
        }

        private void timer_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();

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

        private void btn_backup_Click(object sender, EventArgs e)
        {
            backup bk=new backup();
            bk.ShowDialog();
        }

        private void btn_restore_Click(object sender, EventArgs e)
        {
            restore rs = new restore();
            rs.ShowDialog();
        }

        private void btn_about_Click(object sender, EventArgs e)
        {
            about abt = new about();
            abt.ShowDialog();
        }

        private void btn_company_Click(object sender, EventArgs e)
        {
            aboutcompany abc = new aboutcompany();
            abc.ShowDialog();
        }

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

        private void btn_cards_Click(object sender, EventArgs e)
        {
            cards cd = new cards();
            cd.ShowDialog();
        }

        private void btn_cards_list_Click(object sender, EventArgs e)
        {
            listcards lsd = new listcards();
            lsd.ShowDialog();
        }
    }
}
