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


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

            string sel = "select * from moshtari ";
            sel += " where hazf='" + 0 + "'";
            OleDbConnection con = new OleDbConnection(a);
            OleDbDataAdapter da = new OleDbDataAdapter(sel, con);
            DataSet ds = new DataSet();
            da.Fill(ds, "t1");
            dataGrid1.DataSource = ds;
            dataGrid1.DataMember = "t1";
        }

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

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


            label1.Text = p.GetDayOfMonth(DateTime.Now) + " / " + p.GetMonth(DateTime.Now) + " / " + p.GetYear(DateTime.Now);
           
           
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form4 f4 = new Form4();
            Hide();
            f4.button2.Visible = false;
            f4.ShowDialog();
        }

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

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


            label1.Text = p.GetDayOfMonth(DateTime.Now) + " / " + p.GetMonth(DateTime.Now) + " / " + p.GetYear(DateTime.Now);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form5 f5 = new Form5();
            f5.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form4 f4 = new Form4();
            Hide();
           Class1 c1 = new Class1();
            string sel = "select * from moshtari";

            sel += " where hazf='" + 0 + "'";


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


            if (ds.Tables["t1"].Rows.Count > 0)
            {


                f4.textBox1.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 0]);
                f4.textBox2.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 1]);
                f4.textBox4.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 3]);
                f4.textBox5.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 4]);
                f4.textBox6.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 5]);
                f4.textBox7.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 6]);
                f4.textBox8.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 9]);

                f4.comboBox1.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 11]);
                f4.textBox10.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 10]);
                f4.comboBox2.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 12]);
                f4.button1.Visible = false;
                f4.textBox11.Visible = false;

                f4.textBox9.Visible = false;
                f4.label8.Visible = false;
                f4.label9.Visible = false;
                f4.label11.Visible = false;
                f4.textBox10.Visible = false;
                f4.Text = "ویرایش اطلاعات مشتری";
                f4.ShowDialog();
            }
            else
            {
                MessageBox.Show("کاربر گرامی هیچ اطلاعاتی برای ویرایش وجود ندارد", "اطلاع", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string code;
            int mon;
            code = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 6]);
            mon = Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex, 10]);

            if (MessageBox.Show("کاربر گرامی مطمئن به حذف مشتری با کدملی  " + code + " هستید ", "اخطار", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                string text;
                string a = "provider=microsoft.jet.oledb.4.0;data source =hotel12.mdb";
                //date1 = textBox3.Text + "/" + comboBox3.Text + "/" + comboBox4.Text;

                text = "update moshtari set codemeli='" + code + "'" + ",hazf='" + 1 + "'" + " where money=" + mon;

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

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                Hide();
                Form3 f3 = new Form3();
                f3.ShowDialog();
                
               
            }
        }

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

    }
}