using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace hotel
{
    public partial class Form10 : Form
    {
        public Form10()
        {
            InitializeComponent();
        }
      

        private void timer1_Tick(object sender, EventArgs e)
        {
            System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();

            textBox9.Text = p.GetSecond(DateTime.Now) + " : " + p.GetMinute(DateTime.Now) + " : " + p.GetHour(DateTime.Now);
            timer1.Start();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            Class1 c1 = new Class1();
            string sel = "select * from rezerv";

            sel += " where noroom='" + textBox3.Text + "'";


            DataSet ds = new DataSet();
            ds = c1.select(sel);


            if (ds.Tables["t1"].Rows.Count == 1)
            {
                textBox6.DataBindings.Add("text", ds, "t1.codemeli");
                label14.DataBindings.Add("text", ds, "t1.modat");
                label16.DataBindings.Add("text", ds, "t1.noroom");
                string a = "provider=microsoft.jet.oledb.4.0;data source =hotel12.mdb";
                string sel11 = "select moshtari.name,moshtari.lastname,moshtari.datev,moshtari.timev,moshtari.money,moshtari.nop from moshtari";
                OleDbConnection con1 = new OleDbConnection(a);
                OleDbDataAdapter da1 = new OleDbDataAdapter(sel11, con1);
                DataSet ds11 = new DataSet();
                da1.Fill(ds11, "t3");
                textBox4.DataBindings.Add("text", ds11, "t3.name");
                textBox5.DataBindings.Add("text", ds11, "t3.lastname");
                textBox7.DataBindings.Add("text", ds11, "t3.datev");
                textBox8.DataBindings.Add("text", ds11, "t3.timev");
                textBox10.DataBindings.Add("text", ds11, "t3.money");
               label15.DataBindings.Add("text", ds11, "t3.nop");

                System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();

                textBox9.Text = p.GetSecond(DateTime.Now) + " : " + p.GetMinute(DateTime.Now) + " : " + p.GetHour(DateTime.Now);

                textBox3.Enabled = false;
            }
            else
            {
                MessageBox.Show("کاربر گرامی چنین اتاقی وجود ندارد یا چنین اتاقی رزرو نشده است");
                
            }
        }

        private void Form10_Load(object sender, EventArgs e)
        {
            textBox3.Enabled = true;
            
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            int x1, price, pricek;
            if (textBox4.Text == "")
                MessageBox.Show("کاربر گرامی شماره ی اتاق را وارد کنید");
            else
            {
                panel1.Visible = true;
                groupBox3.Visible = true;
                button4.Visible = true;
                string k = System.IO.File.ReadAllText("rozane.xyz");
                string x = System.IO.File.ReadAllText("saati.xyz");
                if (label15.Text == "ساعتی")
                {
                    x1 = (Convert.ToInt32(label14.Text) * 24);
                    price = (x1 * Convert.ToInt32(x));
                    label18.Text = Convert.ToString(price) + "ریال";
                    label19.Text = "حساب اتاق شماره" +" "+ label16.Text + ":" + " " + textBox5.Text +" - "+ textBox4.Text;
                    pricek=((price)-(Convert.ToInt32(textBox10.Text)));
                    if (pricek < 0)
                    {
                        label20.Text = "طلب کار:" + (Convert.ToString(pricek)) + "ریال";
                    }
                    else
                    {
                        label20.Text = "میلغ قابل پرداخت:" + (Convert.ToString(pricek)) + "ریال";
                    }
                }
                    else{
                        x1 = (Convert.ToInt32(label14.Text));
                    price = (x1 * Convert.ToInt32(x));
                    label18.Text = Convert.ToString(price) + "ریال";
                    label19.Text = "حساب اتاق شماره" +" "+ label16.Text + ":" + " " + textBox5.Text +" - "+ textBox4.Text;
                    pricek=((price)-(Convert.ToInt32(textBox10.Text)));
                    if (pricek < 0)
                    {
                        label20.Text = "طلب کار:" + (Convert.ToString(pricek)) + "ریال";
                    }
                    else
                    {
                        label20.Text = "میلغ قابل پرداخت:" + (Convert.ToString(pricek)) + "ریال";
                    }
                        }
                        string nootagh = "خالی";

                        string text1;
                        string a = "provider=microsoft.jet.oledb.4.0;data source =hotel12.mdb";

                        text1 = "update room set SS='" + nootagh + "'" + " where noroom='" + textBox3.Text + "'";

                        OleDbConnection con = new OleDbConnection(a);
                        OleDbCommand cmd = new OleDbCommand(text1, con);

                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        string ins = "delete from rezerv where noroom='" + textBox3.Text+ "'";
                    OleDbCommand cmd1 = new OleDbCommand(ins, con);
                    DataSet ds = new DataSet();
                    con.Open();
                    cmd1.ExecuteNonQuery();
                    con.Close();
                    Class1 c1 = new Class1();
                  
                    string sel = "select * from rezerv";
                        sel += " where ";
                            sel += "codemeli='" + textBox6.Text + "'";
                        ds = c1.select(sel);
                        if (ds.Tables["t1"].Rows.Count >= 1)
                        {
                          
                           
                        }
                        else if(ds.Tables["t1"].Rows.Count==0)
                        {

                            text1 = "update moshtari set codemeli='" + textBox6.Text + "'" + ",hazf='" + 1 + "'" + " where money=" + textBox10.Text;


                            OleDbCommand cmd2 = new OleDbCommand(text1, con);

                            con.Open();
                            cmd2.ExecuteNonQuery();
                            con.Close();
                            

                        }

                    }

                }

        private void button4_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }
            }
        }
 
