using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Rendering;
using System.IO;
using System.Data.SqlClient;
using System.Globalization;


namespace AzmoonGir
{
    public partial class FrmMain : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\DbAzmoon.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
        DataTable dtAllQuestion;
        DataTable dtQuestionNumber;
        string tarikh = "";
        string Matn = "";
        int i;
        int textid;
        Boolean Dowait = true;

        public FrmMain()
        {
            InitializeComponent();
            DateTime today = DateTime.Now;
            PersianCalendar pc = new PersianCalendar();

            tarikh = pc.GetYear(today).ToString("0000/") + pc.GetMonth(today).ToString("00/") + pc.GetDayOfMonth(today).ToString("00");
            

        }



        private void SetText()
        {


            switch (textid)
            {
                case 0:
                    {
                        Matn = "به سامانه برگزاری آزمون های چهارگزینه ای خوش آمدید";
                        textid = 1;
                        break;
                    }

                    case 1:
                    {
                        Matn = "از این که نرم افزار ما را انتخاب کردید متشکریم";
                        textid = 2;
                        break;
                    }

                    case 2:
                    {
                        Matn = "شما می توانید آزمون ها را به صورت کتبی و آنلاین برگزار نمایید";
                        textid = 3;
                        break;
                    }

                    case 3:
                    {
                        Matn = "بخش گزارشات میتواند اطلاعات جامعی به شما ارائه بدهد";
                        textid = 4;
                        break;
                    }

                    case 4:
                    {
                        Matn = "در صورت بروز هرگونه مشکل با پشتیبانی تماس بگیرید";
                        textid = 0;
                        break;
                    }






            }

        }




        private void SetStyle()
        {
            string strstyle="";
            try
            {
                // create reader & open file
                StreamReader tr = new StreamReader((Application.StartupPath + "\\Style.azm"));

                // read a line of text
                strstyle = tr.ReadLine().ToString();

                // close the stream
                tr.Close();
            }
            catch
            {

            }

            switch (strstyle)
            {

                case "office2007blue":

                    btnoffice2007blue_Click_1(null, null);
                    styleManager1.ManagerStyle = eStyle.Office2007Blue;
                    break;


                case "office2010blue":
                    buttonItem9_Click(null, null);
                    styleManager1.ManagerStyle = eStyle.Office2010Blue;
                    break;


                case "windows7":
                    buttonItem11_Click(null, null);
                    styleManager1.ManagerStyle = eStyle.Windows7Blue;
                    break;


                case "vista":
                    buttonItem12_Click(null, null);
                    styleManager1.ManagerStyle = eStyle.Office2007VistaGlass;
                    break;



                case "gray":
                    buttonItem13_Click(null, null);
                    styleManager1.ManagerStyle = eStyle.VisualStudio2010Blue;
                    break;



                default :
                    btnoffice2007blue_Click_1(null, null);
                    break;


            }

        }









        private void ثبتگروهامتحانیToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
             DateTime today = DateTime.Now;
            PersianCalendar pc = new PersianCalendar();

            SetStyle();
            SetText();

            lblyear.Text = pc.GetYear(today).ToString("0000");
            lblmonth.Text = pc.GetMonth(today).ToString("00");
            lblday.Text = pc.GetDayOfMonth(today).ToString("00");
            //MessageBox.Show(pc.GetDayOfWeek(today).ToString());
            switch (pc.GetDayOfWeek(today).ToString())
            {
                case "Saturday":
                    {
                        lbldayname.Text = "شنبه";
                        break;
                    }

                case "Sunday":
                    {
                        lbldayname.Text = "یکشنبه";
                        break;
                    }

                case "Monday":
                    {
                        lbldayname.Text = "دوشنبه";
                        break;
                    }
                case "Tuesday":
                    {
                        lbldayname.Text = "سه شنبه";
                        break;
                    }
                case "Wednesday":
                    {
                        lbldayname.Text = "چهارشنبه";
                        break;
                    }
                case "Thursday":
                    {
                        lbldayname.Text = "پنج شنبه";
                        break;
                    }
                case "Friday":
                    {
                        lbldayname.Text = "جمعه";
                        break;
                    }


            }

            analogClockControl1.Value = System.DateTime.Now;

        }
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();

        }



        private void Tab2_Click(object sender, EventArgs e)
        {

        }

        private void BtnAdd_Click_1(object sender, EventArgs e)
        {
            FrmGroup Fg = new FrmGroup();
            Fg.ShowDialog();
        }

        private void BtnEdit_Click(object sender, EventArgs e)
        {
            FrmEdit Fe = new FrmEdit();
            Fe.ShowDialog();
        }

        private void analogClockControl1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void ribbonControl1_Click(object sender, EventArgs e)
        {

        }

        private void btnaddquestion_Click(object sender, EventArgs e)
        {
            FrmQuestionAdd Fq = new FrmQuestionAdd();
            Fq.ShowDialog();
        }

        private void office2007StartButton1_Click(object sender, EventArgs e)
        {

        }

        private void btneditquestion_Click(object sender, EventArgs e)
        {
            FrmQuestionEdit fqe = new FrmQuestionEdit();
            fqe.ShowDialog();
        }

        private void BtnExit_Click(object sender, EventArgs e)
        {
            Frm_Message Fm = new Frm_Message();
            Fm.lbltext.Text = "آیا برای خروج اطمینان دارید؟";
            Fm.ImgClose.Visible = false;
            Fm.ImgYes.Visible = true;
            Fm.ImgNo.Visible = true;
            Fm.ShowDialog();

            if (Fm.resualt == true)
            {
                Application.Exit();
            }

        }

        

        private void Btnmanagement_Click(object sender, EventArgs e)
        {
            FrmAdmin Fa = new FrmAdmin();
            Fa.ShowDialog();
        }

        private void BtnExit_Click_1(object sender, EventArgs e)
        {
            Frm_Message Fm = new Frm_Message();
            Fm.lbltext.Text = "آیا برای خروج اطمینان دارید؟";
            Fm.ImgClose.Visible = false;
            Fm.ImgYes.Visible = true;
            Fm.ImgNo.Visible = true;
            Fm.ShowDialog();

            if (Fm.resualt == true)
            {
                Application.Exit();
            }
        }

        private void BtnExit_Click_2(object sender, EventArgs e)
        {
            Frm_Message Fm = new Frm_Message();
            Fm.lbltext.Text = "آیا برای خروج اطمینان دارید؟";
            Fm.ImgClose.Visible = false;
            Fm.ImgYes.Visible = true;
            Fm.ImgNo.Visible = true;
            Fm.ShowDialog();

            if (Fm.resualt == true)
            {
                Application.Exit();
            }
        }

        private void buttonItem7_Click_1(object sender, EventArgs e)
        {

        }

        private void btnoffice2007blue_Click(object sender, EventArgs e)
        {


        }

        private void btnoffice2007black_Click(object sender, EventArgs e)
        {

        }

        private void btnoffice2007silver_Click(object sender, EventArgs e)
        {

        }

        private void AppCommandTheme_Executed(object sender, EventArgs e)
        {
            ICommandSource source = sender as ICommandSource;
            if (source.CommandParameter is string)
            {
                eStyle style = (eStyle)Enum.Parse(typeof(eStyle), source.CommandParameter.ToString());
                // Using StyleManager change the style and color tinting
                StyleManager.ChangeStyle(style, Color.Empty);
                 if (style == eStyle.Office2007Black || style == eStyle.Office2007Blue || style == eStyle.Office2007Silver || style == eStyle.Office2007VistaGlass)
                   buttonFile.BackstageTabEnabled = false;
                else
                   buttonFile.BackstageTabEnabled = true;
                }
                 else if (source.CommandParameter is Color)
                   {
                      StyleManager.ColorTint = (Color)source.CommandParameter;
                  }
            }

        private void buttonFile_Click(object sender, EventArgs e)
        {

        }

        private void btnoffice2007blue_Click_1(object sender, EventArgs e)
        {
           

            buttonFile.Visible = true;
            // create a writer and open the file
            TextWriter tw = new StreamWriter((Application.StartupPath + "\\Style.azm"));

            // write a line of text to the file
            tw.WriteLine("office2007blue");

            // close the stream
            tw.Close();
        }

        private void buttonItem9_Click(object sender, EventArgs e)
        {
            buttonFile.Visible = false;

            // create a writer and open the file
            TextWriter tw = new StreamWriter((Application.StartupPath + "\\Style.azm"));

            // write a line of text to the file
            tw.WriteLine("office2010blue");

            // close the stream
            tw.Close();
        }

        private void buttonItem11_Click(object sender, EventArgs e)
        {
            buttonFile.Visible = false;
            // create a writer and open the file
            TextWriter tw = new StreamWriter((Application.StartupPath + "\\Style.azm"));

            // write a line of text to the file
            tw.WriteLine("windows7");

            // close the stream
            tw.Close();
        }

        private void buttonItem12_Click(object sender, EventArgs e)
        {
            buttonFile.Visible = true;
            // create a writer and open the file
            TextWriter tw = new StreamWriter((Application.StartupPath + "\\Style.azm"));

            // write a line of text to the file
            tw.WriteLine("vista");

            // close the stream
            tw.Close();
        }

        private void buttonItem13_Click(object sender, EventArgs e)
        {
            buttonFile.Visible = false;
            // create a writer and open the file
            TextWriter tw = new StreamWriter((Application.StartupPath + "\\Style.azm"));

            // write a line of text to the file
            tw.WriteLine("gray");

            // close the stream
            tw.Close();
        }

        private void BtnAzmoonOn_Click(object sender, EventArgs e)
        {
           FrmAzmoon Fa = new FrmAzmoon();
           Fa.ShowDialog();
       //     MPG_WinShutDowm.ShowShutForm sf = new MPG_WinShutDowm.ShowShutForm(new FrmAzmoon());
        }

        private void FrmMain_Activated(object sender, EventArgs e)
        {



        }

        private void btnbackup_Click(object sender, EventArgs e)
        {
            FrmBackUp fb = new FrmBackUp();
            fb.ShowDialog();

        }

        private void btnrestore_Click(object sender, EventArgs e)
        {
            FrmRestore fr = new FrmRestore();
            fr.ShowDialog();
        }

        private void BtnTozih_Click(object sender, EventArgs e)
        {
            FrmTozih ft = new FrmTozih();
            ft.ShowDialog();
        }

        private void btntime_Click(object sender, EventArgs e)
        {
            FrmTime fti = new FrmTime();
            fti.ShowDialog();
        }

        private void btnAllQuestion_Click(object sender, EventArgs e)
        {

            SqlDataAdapter da = new SqlDataAdapter("ReportAllQuestion", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            dtAllQuestion = new DataTable();
            da.Fill(dtAllQuestion);
            if (dtAllQuestion.Rows.Count == 0)
            {
                Frm_Message Fm = new Frm_Message();
                Fm.lbltext.Text = "سوالی ثبت نشده است";
                Fm.ImgClose.Visible = true;
                Fm.ImgYes.Visible = false;
                Fm.ImgNo.Visible = false;

                Fm.ShowDialog();
            }
            else
            {
            stiReportAllQuestion.Load("stiAllQuestion.mrt");
            stiReportAllQuestion.RegData(dtAllQuestion);
            stiReportAllQuestion.Show();
            }


        }

        private void btnQuestionByGroup_Click(object sender, EventArgs e)
        {
            FrmQreport fq = new FrmQreport();
            fq.ShowDialog();
        }

      
        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void ribbonTabItem3_Click(object sender, EventArgs e)
        {

        }

        private void btnQuestionByGroup_Click_1(object sender, EventArgs e)
        {
            FrmQreport fq = new FrmQreport();
            fq.ShowDialog();
        }

        private void btnQByGroup_Click(object sender, EventArgs e)
        {
          
        }

        private void btnQNumber_Click(object sender, EventArgs e)
        {
            //report Date
            DataTable dtDate = new DataTable();
            dtDate.Columns.Add("Date");
            dtDate.Rows.Add();
            dtDate.Rows[0]["Date"] = tarikh;

           



          //  ReportQuestionNumber

            SqlDataAdapter da = new SqlDataAdapter("ReportQuestionNumber", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            dtQuestionNumber = new DataTable();
            da.Fill(dtQuestionNumber);
            if (dtQuestionNumber.Rows.Count == 0)
            {
                Frm_Message Fm = new Frm_Message();
                Fm.lbltext.Text = "گروهی ثبت نشده است";
                Fm.ImgClose.Visible = true;
                Fm.ImgYes.Visible = false;
                Fm.ImgNo.Visible = false;

                Fm.ShowDialog();
            }
            else
            {
                DataSet ds = new DataSet();
                ds.Merge(dtDate);
                ds.Tables[0].TableName = "dtDate";
                ds.Merge(dtQuestionNumber);
                ds.Tables[1].TableName = "dtQuestionNumber";

                 
                stiReportAllQuestion.Load("stiAllQuestionNumber.mrt");
                stiReportAllQuestion.RegData(ds);
                stiReportAllQuestion.Show();
            }



        }

        private void timer2_Tick(object sender, EventArgs e)
        {

            label2.Text = Matn.Substring(0, i);
            i++;

            if (label2.Text == Matn)
            {
                i = 0;
                timer2.Stop();
                timer3.Start();
            }

        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            if (Dowait == false)
            {
                SetText();
                timer2.Enabled = true;
                Dowait = true;
                timer3.Enabled = false;
                
            }
            else
            {
                Dowait = false;
            }




        }

        private void BtnAzmoonCh_Click(object sender, EventArgs e)
        {

            FrmAzmoonKatbi fk = new FrmAzmoonKatbi();
            fk.ShowDialog();

        }

        private void buttonItem4_Click(object sender, EventArgs e)
        {
            FrmAbout fa = new FrmAbout();
            fa.ShowDialog();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            analogClockControl1.Value = System.DateTime.Now;
        }

        private void ribbonBar10_ItemClick(object sender, EventArgs e)
        {

        }

      
       
        }
    }
