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.Globalization;
using FarsiMsgBox;
using System.Data.SqlClient;
using System.Management;

namespace ajans
{
    public partial class form_main : Form
    {

        DataView objdv;
        PersianCalendar PersianDateTime = new PersianCalendar();

        int o = 0;

        int a = 460, d = 800;
        int S = 1;

        public form_main()
        {
            InitializeComponent();
        }

        private void areabutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.form_area_show)
            {
                form_area frmArea = new form_area();
                frmArea.Show();
                static_variables.form_area_show = true;
            }
        }


        private void carbutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.form_car_show)
            {
                form_car frmCar = new form_car();
                frmCar.Show();
                static_variables.form_car_show = true;
            }
        }

        private void customerbutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.form_customer_show)
            {
                form_customer frmCustomer = new form_customer();
                frmCustomer.Show();
                static_variables.form_customer_show = true;
            }
        }

        private void requestbutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.form_request_show)
            {
                form_request frmRequest = new form_request();
                frmRequest.Show();
                static_variables.form_request_show = true;
            }
        }

        private void driverbutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.form_driver_show)
            {
                form_driver frmDriver = new form_driver();
                frmDriver.Show();
                static_variables.form_driver_show = true;
            }
        }

        private void servicebutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.form_service_show)
            {
                form_service frmService = new form_service();
                frmService.Show();
                static_variables.form_service_show = true;
            }
        }

        private void presentbutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.form_present_show)
            {
                form_present frmPresent = new form_present();
                frmPresent.Show();
                static_variables.form_present_show = true;
            }
        }

        private void accountbutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.Enter)
            {
                form_password frmPassword = new form_password();
                static_variables.accountKey = true;
                frmPassword.ShowDialog();
            }
            else if (static_variables.form_account_show == false)
            {
                form_account frmAccount = new form_account();
                frmAccount.Show();
                static_variables.form_account_show = true;
            }
            else
            {
            }
         }

        private void timer1_Tick(object sender, EventArgs e)
        {
            switch (o)
            {
                case 0:
                    label6.Text = label6.Text + "نرم  ";
                    break;
                case 1:
                    label6.Text = label6.Text + "افزار  ";
                    break;
                case 2:
                    label6.Text = label6.Text + "مدیریت  ";
                    break;
                case 3:
                    label6.Text = label6.Text + "تاکسی  ";
                    break;
                case 4:
                    label6.Text = label6.Text + "تلفنی  ";
                    break;
                case 5:
                    label6.ForeColor = System.Drawing.Color.Red;
                    break;
                case 6:
                    label6.ForeColor = System.Drawing.Color.Green;
                    break;
                case 7:
                    label6.ForeColor = System.Drawing.Color.Coral;
                    break;
                case 8:
                    label6.ForeColor = System.Drawing.Color.Blue;
                    break;
                case 9:
                    label6.ForeColor = System.Drawing.Color.BurlyWood;
                    break;
                case 10:
                    label6.ForeColor = System.Drawing.Color.Brown;
                    break;
            }
            o++;
            if (o == 10)
            {
                label6.Text = "";
                o = 0;
                label6.ForeColor = System.Drawing.Color.Black;
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
            MessageBox.Show(pc.ToDateTime(1389, 7, 18, 0, 0, 0, 0).ToString());
        }

        private void exitbutton_Click(object sender, EventArgs e)
        {
            FarsiMessage.ShowMessageBox("آیا می خواهید از برنامه خارج شوید؟", "هشدار", ShowButton.بله_خیر, MsgIcon.Warning);
            if (FarsiMessage.ClickButton == ButtonClicked.بله)
            {
                this.Opacity = 1;
                for (int i = 100; i > 1; i--)
                {
                    this.Opacity -= 0.01;
                    Application.DoEvents();
                }
                Application.Exit();
            }

        }

        private void time_Tick(object sender, EventArgs e)
        {
            MohammadDayyanCalendar.MDCalendar mdCalendar = new MohammadDayyanCalendar.MDCalendar();
            double IranTime = mdCalendar.Time() + (3.5 * 60 * 60);
            lbldate.Text = mdCalendar.Date("W D M Y", IranTime, true);

            DateTime dt = DateTime.Now;
            txtnow.Text = PersianDateTime.GetYear(dt).ToString() + "/" + PersianDateTime.GetMonth(dt).ToString("D2") + "/" + PersianDateTime.GetDayOfMonth(dt).ToString("D2") + "," + dt.Hour.ToString("D2") + ":" + dt.Minute.ToString("D2") + ":" + dt.Second.ToString("D2");
            lblstatus.Text = static_variables.statusOperator.ToString();
        }

        private void form_main_Load(object sender, EventArgs e)
        {
            login Login = new login();
            objdv=new DataView(Login.SelectAccount().Tables["ajans"]);
            l1.DataBindings.Clear();
            l2.DataBindings.Clear();
            l3.DataBindings.Clear();
            l4.DataBindings.Clear();
            l5.DataBindings.Clear();

            l1.Text = "";
            l2.Text = "";
            l3.Text = "";
            l4.Text = "";
            l5.Text = "";

            l1.DataBindings.Add("text", objdv, "ajans_name");
            l2.DataBindings.Add("text", objdv, "ajans_manage_name");
            l3.DataBindings.Add("text", objdv, "ajans_address");
            l4.DataBindings.Add("text", objdv, "ajans_tel1");
            l5.DataBindings.Add("text", objdv, "ajans_tel2");

            timer3.Enabled = true;
        }
        private void timer2_Tick_1(object sender, EventArgs e)
        {
            if (S == 1)
            {
                show.Location = new Point(a, 45);
                if (a < 800)
                    a += 10;
                if (a == 800)
                {
                    show.Location = new Point(800, 45);
                    a = (460);
                    timer2.Enabled = false;
                }

            }
            else if (S == 0)
            {

                show.Location = new Point(d, 45);

                d -= 10;
                if (d == (460))
                {
                    show.Location = new Point(460, 45);
                    d = 800;
                    timer2.Enabled = false;
                }
            }
        }

        private void btnshow_Click(object sender, EventArgs e)
        {
            if (S == 0)
            {
                S = 1;
                timer2.Enabled = true;
                btnshow.Text = "نمایش تمام امکانات";
                reportbutton.TabStop = false;
                settingbutton.TabStop = false;
                customerbutton.TabStop = false;
                driverbutton.TabStop = false;
                carbutton.TabStop = false;
                areabutton.TabStop = false;
                accountbutton.TabStop = false;
            }
            else if (S == 1)
            {
                S = 0;
                timer2.Enabled = true;
                btnshow.Text = "پنهان سازی";
                reportbutton.TabStop = true;
                settingbutton.TabStop = true;
                customerbutton.TabStop = true;
                driverbutton.TabStop = true;
                carbutton.TabStop = true;
                areabutton.TabStop = true;
                accountbutton.TabStop = true;
            }
        }

        private void reportbutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.Enter)
            {
                form_password frmPassword = new form_password();
                static_variables.reportKey = true;
                frmPassword.ShowDialog();
            }
            else if (static_variables.form_report_show == false)
            {
                form_report frmReport = new form_report();
                frmReport.Show();
                static_variables.form_report_show = true;
            }
            else
            {
            }
        }

        private void settingbutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.Enter)
            {
                form_password frmPassword = new form_password();
                static_variables.settingKey = true;
                frmPassword.ShowDialog();
            }
            else if (static_variables.form_setting_show == false)
            {
                form_setting frmSetting = new form_setting();
                frmSetting.Show();
                static_variables.form_setting_show = true;
            }
            else
            {
            }
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            form_about frmAbout = new form_about();
            frmAbout.ShowDialog();
        }

        private void form_main_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void toolsbutton_Click(object sender, EventArgs e)
        {
            if (!static_variables.form_tools_show)
            {
                form_tools frmTools = new form_tools();
                frmTools.Show();
                static_variables.form_tools_show= true;
            }
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            try
            {
                int C = string.Compare(txtqueue.Text, txtnow.Text);
                if (C > 0)
                {
                    lbldays.Text = (Convert.ToDateTime(txtqueue.Text) - Convert.ToDateTime(txtnow.Text)).Days.ToString();
                    lblhours.Text = (Convert.ToDateTime(txtqueue.Text) - Convert.ToDateTime(txtnow.Text)).Hours.ToString();
                    lblminutes.Text = (Convert.ToDateTime(txtqueue.Text) - Convert.ToDateTime(txtnow.Text)).Minutes.ToString();
                    lblsecondes.Text = (Convert.ToDateTime(txtqueue.Text) - Convert.ToDateTime(txtnow.Text)).Seconds.ToString();
                    label8.Text = "ثانیه مانده به اولین درخواست";
                }
                else
                {
                    lbldays.Text = (Convert.ToDateTime(txtnow.Text) - Convert.ToDateTime(txtqueue.Text)).Days.ToString();
                    lblhours.Text = (Convert.ToDateTime(txtnow.Text) - Convert.ToDateTime(txtqueue.Text)).Hours.ToString();
                    lblminutes.Text = (Convert.ToDateTime(txtnow.Text) - Convert.ToDateTime(txtqueue.Text)).Minutes.ToString();
                    lblsecondes.Text = (Convert.ToDateTime(txtnow.Text) - Convert.ToDateTime(txtqueue.Text)).Seconds.ToString();
                    label8.Text = "ثانیه گذشته از اولین درخواست";
                }
            }
            catch(FormatException ex)
            {
                return;
            }
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (!static_variables.form_queue_show)
            {
                form_queue frmQueue = new form_queue();
                frmQueue.Show();
                static_variables.form_queue_show = true;
            }
        }
        private void timer4_Tick(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;
            string str = PersianDateTime.GetYear(dt).ToString() + "/" + PersianDateTime.GetMonth(dt).ToString("D2") + "/" + PersianDateTime.GetDayOfMonth(dt).ToString("D2") + "," + dt.Hour.ToString("D2") + ":" + dt.Minute.ToString("D2") + ":" + dt.Second.ToString("D2");
            static_variables.txtTimeNow = (Convert.ToDateTime(str).AddMinutes(0)).ToString();
            for (int i = 0; i < static_variables.arrayQueue2.Count; i++)
            {
                if (static_variables.txtTimeNow.ToString() == static_variables.arrayQueue2[i].ToString())
                {
                    form_alarm frmAlarm = new form_alarm();
                    frmAlarm.lbl1.Text = static_variables.arrayQueue3[i].ToString();
                    frmAlarm.lbl3.Text = static_variables.arrayQueue[i].ToString();
                    frmAlarm.ShowDialog();
                }
            }

            request Request = new request();
            objdv = new DataView(Request.SelectQueue().Tables["request"]);
            txtqueue.DataBindings.Clear();
            txtqueue.Text = "";
            txtqueue.DataBindings.Add("text", objdv, "req_datetime");
        }

        private void lblstatus_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            static_variables.Enter = false;
            static_variables.statusOperator = "";
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (!static_variables.form_help_show)
            {
                form_help frmHelp = new form_help();
                frmHelp.Show();
                static_variables.form_help_show = true;
            }
        }
    }
}