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 Form7 : Form
    {
        public Form7()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.IO.File.WriteAllText("rozane.xyz", textBox1.Text.Trim());
            System.IO.File.WriteAllText("saati.xyz", textBox2.Text.Trim());
            this.ClientSize = new System.Drawing.Size(552, 371);
            this.groupBox2.Size = new System.Drawing.Size(520, 81);
        }

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

        private void Form7_Load(object sender, EventArgs e)
        {
            string k = System.IO.File.ReadAllText("rozane.xyz");
            string x = System.IO.File.ReadAllText("saati.xyz");
            string o = System.IO.File.ReadAllText("otagh.xyz");
            string t = System.IO.File.ReadAllText("tabaghe.xyz");
            textBox1.Text = k;
            textBox2.Text = x;
            textBox5.Text = o;
            textBox7.Text = t;

        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            this.ClientSize = new System.Drawing.Size(544, 552);
            this.groupBox2.Size = new System.Drawing.Size(520, 296);
            panel2.Visible = false;
            panel1.Visible = true;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.ClientSize = new System.Drawing.Size(544, 552);
            this.groupBox2.Size = new System.Drawing.Size(520, 296);
            panel1.Visible = false;
            panel2.Visible = true;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Class1 c1 = new Class1();
            string sel = "select * from login";
            Boolean flag = false;

            if (textBox3.Text != "" || textBox4.Text != "")
            {
                sel += " where ";
                if (textBox1.Text != "")
                {
                    sel += "user='" + textBox3.Text + "'";
                    flag = true;

                }
                if (textBox4.Text != "")
                {
                    if (flag)
                        sel += " and ";
                    sel += "pass='" + textBox4.Text + "'";
                    flag = true;

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


                if (ds.Tables["t1"].Rows.Count == 1)
                { 
                    if(textBox3.Text==""||textBox4.Text==""||textBox6.Text=="")
                    {
                        MessageBox.Show("کاربر گرامی لطفا فیلد ها را پر کنبید","خطا",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    }
                    else
                    {
                    string text;
                    string a = "provider=microsoft.jet.oledb.4.0;data source =hotel12.mdb";
                  
                    text = "update login set pass='" + textBox6.Text + "'" +  " where user='" + textBox3.Text+"'";

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

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                    Hide();
                    }
                }
                else
                {
                    MessageBox.Show("کاربری با اینuserid و password وجود ندارد","خطا",MessageBoxButtons.OK,MessageBoxIcon.Error);
                }

            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (textBox10.Text == "" || textBox9.Text == "")
            {
                MessageBox.Show("کاربر گرامی لطفا فیلد ها را پر کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string text;
                Class1 c2 = new Class1();
                text = "insert into login values('" + textBox10.Text;
                text += "','" + textBox9.Text + "')";
                c2.insert(text);
                Close();
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (textBox5.Text == "" || textBox7.Text == "")
            {
                MessageBox.Show("کاربر گرامی لطفا فیلد مربوط به اتاق و طبقه را وارد کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                System.IO.File.WriteAllText("otagh.xyz", textBox5.Text.Trim());
                System.IO.File.WriteAllText("tabaghe.xyz", textBox7.Text.Trim());
                this.ClientSize = new System.Drawing.Size(552, 371);
                this.groupBox2.Size = new System.Drawing.Size(520, 81);
                if (textBox5.Text == "0" || textBox7.Text == "0")
                {
                    MessageBox.Show("برابر صفر است");
                }
                else
                {
                    Form8 f8 = new Form8();
                    f8.otagh = textBox5.Text;
                    f8.ShowDialog();
                }
            }
        }
    }
}