using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using FarsiMsgBox;

namespace ajans
{
    public partial class form_request : Form
    {
        PersianCalendar PersianDateTime = new PersianCalendar();

        DataView objdv;

        public form_request()
        {
            InitializeComponent();
        }

        private void binding()
        {
            lbldatedel.DataBindings.Clear();
            lblname.DataBindings.Clear();
            lbltimedel.DataBindings.Clear();

            lbldatedel.Text = "";
            lblname.Text = "";
            lbltimedel.Text = "";

            lbldatedel.DataBindings.Add("text", objdv, "تاریخ");
            lbltimedel.DataBindings.Add("text", objdv, "ساعت");
            lblname.DataBindings.Add("text", objdv, "نام مشتری");
        }
        private void list_Click(object sender, EventArgs e)
        {
            if (this.Height <= 90)
            {
                panel1.Visible = true;
                panel2.Visible = false;
                timer1.Enabled = true;
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
            }
            else
            {
                timer2.Enabled = true;
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
                panel1.Visible = false;
                panel2.Visible = false;
            }
        }

        private void req_cus1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (!static_variables.form_customer_request1_show)
            {
                form_customer_request1 frm_cus_req1 = new form_customer_request1();
                frm_cus_req1.Show();
                static_variables.form_customer_request1_show = true;
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (!static_variables.form_customer_request2_show)
            {
                form_customer_request2 frm_cus_req2 = new form_customer_request2();
                frm_cus_req2.Show();
                static_variables.form_customer_request2_show = true;
            }
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (!static_variables.form_customer_request3_show)
            {
                form_customer_request3 frm_cus_req3 = new form_customer_request3();
                frm_cus_req3.Show();
                static_variables.form_customer_request3_show = true;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Height = this.Height + 10;
            if (this.Height >= 450) timer1.Enabled = false;
        }

        private void delete_Click(object sender, EventArgs e)
        {
            if (this.Height <= 90)
            {
                panel1.Visible = false;
                panel2.Visible = true;
                timer3.Enabled = true;
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
            }
            else
            {
                timer4.Enabled = true;
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
                panel2.Visible = false;
                panel1.Visible = false;
            }
        }

        private void exit_Click(object sender, EventArgs e)
        {
            this.Opacity = 1;
            for (int i = 100; i > 1; i--)
            {
                this.Opacity -= 0.01;
                Application.DoEvents();
            }
            this.Close(); ;
        }

        private void form_request_FormClosed(object sender, FormClosedEventArgs e)
        {
            static_variables.form_request_show = false;
        }

        private void search_Click(object sender, EventArgs e)
        {
            if (rdb3.Checked == true)
            {
                request Request = new request();
                if (chk1.Checked == true)
                {
                    dgListRequest.DataSource = Request.SelectRequestCHK1();
                    dgListRequest.DataMember = "request";
                }
                if (chk2.Checked == true)
                {
                    dgListRequest.DataSource = Request.SelectRequestCHK2();
                    dgListRequest.DataMember = "request";
                }
                if (chk3.Checked == true)
                {
                    dgListRequest.DataSource = Request.SelectRequestCHK3();
                    dgListRequest.DataMember = "request";
                }
            }
            else if (txtsearch.Text == "")
            {
                FarsiMessage.ShowMessageBox(lblSearch.Text, "هشدار", ShowButton.تائید_تنها, MsgIcon.Warning);
                txtsearch.Focus();
            }
            else
            {
                request Request = new request();
                if (rdb2.Checked == true)
                {
                    dgListRequest.DataSource = Request.SelectRequest(txtsearch.Text);
                    dgListRequest.DataMember = "request";
                }
                else if (rdb1.Checked == true)
                {
                    dgListRequest.DataSource = Request.SelectRequest2(txtsearch.Text);
                    dgListRequest.DataMember = "request";

                }
            }
        }

        private void chk1_CheckedChanged(object sender, EventArgs e)
        {
            if (chk1.Checked == true)
            {
                chk2.Checked = false;
                chk3.Checked = false;
            }
        }

        private void chk2_CheckedChanged(object sender, EventArgs e)
        {
            if (chk2.Checked == true)
            {
                chk1.Checked = false;
                chk3.Checked = false;
            }
        }

        private void chk3_CheckedChanged(object sender, EventArgs e)
        {
            if (chk3.Checked == true)
            {
                chk2.Checked = false;
                chk1.Checked = false;
            }
        }

        private void rdb2_CheckedChanged(object sender, EventArgs e)
        {
            if (rdb2.Checked == true)
            {
                lblSearch.Text = "لطفا کد درخواست را وارد نمایید";
                txtsearch.Text = "";
                txtsearch.Visible = true;
                chk3.Visible = false;
                chk2.Visible = false;
                chk1.Visible = false;
                label22.Left = 378;
            }
        }

        private void rdb1_CheckedChanged(object sender, EventArgs e)
        {
            if (rdb1.Checked == true)
            {
                lblSearch.Text = "لطفا نام مشتری را وارد نمایید";
                txtsearch.Text = "";
                txtsearch.Visible = true;
                chk3.Visible = false;
                chk2.Visible = false;
                chk1.Visible = false;
                label22.Left = 368;
            }
        }

        private void rdb3_CheckedChanged(object sender, EventArgs e)
        {
            if (rdb3.Checked == true)
            {
                lblSearch.Text = "لطفا نوع درخواست را انتخاب نمایید";
                txtsearch.Visible = false;
                chk3.Visible = true;
                chk2.Visible = true;
                chk1.Visible = true;
                label22.Left = 392;
            }
        }

        private void txtsearch_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (rdb2.Checked)
            {
                int i = e.KeyChar;
                if (i < 8 || 8 < i && i < 48 || i > 57)
                {
                    e.Handled = true;
                    err.Clear();
                    err.SetError(txtsearch, lblSearch.Text);
                    System.Console.Beep();
                }
                else err.Clear();
            }
            else
                e.Handled = false;
        }

        private void txtsearch_Leave(object sender, EventArgs e)
        {
            err.Clear();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            request Request = new request();
            dgListRequest.DataSource = Request.SelectRequest();
            dgListRequest.DataMember = "request";
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Height = this.Height - 10;
            if (this.Height <= 90) timer2.Enabled = false;
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            this.Height = this.Height + 10;
            if (this.Height >= 250) timer3.Enabled = false;
        }

        private void timer4_Tick(object sender, EventArgs e)
        {
            this.Height = this.Height - 10;
            if (this.Height <= 90) timer4.Enabled = false;
        }

        private void txtiddel_KeyPress(object sender, KeyPressEventArgs e)
        {
            int i = e.KeyChar;
            if (i < 8 || 8 < i && i < 48 || i > 57)
            {
                e.Handled = true;
                System.Console.Beep();
            }
        }

        private void txtiddel_TextChanged(object sender, EventArgs e)
        {
            request Request = new request();
            objdv = new DataView(Request.SelectRequest(txtiddel.Text).Tables["request"]);
            binding();
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (txtiddel.Text == "")
            {
                FarsiMessage.ShowMessageBox("لطفا کد درخواست را وارد نمایید.", "هشدار", ShowButton.تائید_تنها, MsgIcon.Warning);
                txtiddel.Focus();
            }
            else if (txtiddel.Text != "" && lbltimedel.Text == "")
            {
                FarsiMessage.ShowMessageBox("درخواستی با این کد یافت نشد.", "پیغام", ShowButton.تائید_تنها, MsgIcon.Information_1);
            }
            else
            {
                service Service = new service();
                objdv = new DataView(Service.SelectRequestService(txtiddel.Text).Tables["service"]);

                txtstatusdel.DataBindings.Clear();
                txtstatusdel.Text = "";
                txtstatusdel.DataBindings.Add("text", objdv, "وضعیت");

                if (Int16.Parse(txtstatusdel.Text) > 0)
                {
                    FarsiMessage.ShowMessageBox("در حال حاضر به ایت درخواست سرویس اختصاص داده شده است و لغو درخواست امکان پذیر نمی باشد.", "پیغام", ShowButton.تائید_تنها, MsgIcon.Information_1);
                }
                else
                {
                    request Request = new request();
                    FarsiMessage.ShowMessageBox("آیا میخواهید درخواست مورد نظر را لغو نمایید؟", "هشدار", ShowButton.بله_خیر, MsgIcon.Warning);
                    if (FarsiMessage.ClickButton == ButtonClicked.بله)
                    {
                        Request.SetReqID(txtiddel.Text);
                        Request.DeleteRequest();
                        FarsiMessage.ShowMessageBox("درخواست مورد نظر لغو گردید", "پیغام", ShowButton.تائید_تنها, MsgIcon.Information_1);
                        txtiddel.Text = "";
                        lblname.Text = "";
                        lbldatedel.Text = "";
                        lbltimedel.Text = "";
                    }
                }
            }
        }

        private void btncancleall_Click(object sender, EventArgs e)
        {
            service Service = new service();
            objdv = new DataView(Service.SelectRequestService().Tables["service"]);
            txtstatusdel.DataBindings.Clear();
            txtstatusdel.Text = "";
            txtstatusdel.DataBindings.Add("text", objdv, "وضعیت");

            if (Int16.Parse(txtstatusdel.Text) > 0)
            {
                FarsiMessage.ShowMessageBox("شما قادر به لغو کردن کل درخواستها نیستید. چون به برخی از درخواستها سرویس اختصاص داده شده است.", "پیغام", ShowButton.تائید_تنها, MsgIcon.Information_1);
            }
            else
            {
                request Request = new request();
                FarsiMessage.ShowMessageBox("آیا میخواهید کل درخواستها را لغو نمایید؟", "هشدار", ShowButton.بله_خیر, MsgIcon.Warning);
                if (FarsiMessage.ClickButton == ButtonClicked.بله)
                {
                    Request.DeleteRequest();
                    FarsiMessage.ShowMessageBox("کل درخواستها لغو گردیدند.", "پیغام", ShowButton.تائید_تنها, MsgIcon.Information_1);
                    txtiddel.Text = "";
                    lblname.Text = "";
                    lbldatedel.Text = "";
                    lbltimedel.Text = "";
                }
            }
        }
    }
}
