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 Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }
        int date;
         string money;
            
            

        private void Form4_Load(object sender, EventArgs e)
        {
            money = textBox10.Text;
            System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();

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


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

            date = p.GetYear(DateTime.Now);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try{
            if (Convert.ToInt32(textBox3.Text) > date)
                textBox3.Text = "";
            else
            {
                int s;
                s = date - Convert.ToInt32(textBox3.Text);
                
                if (s < 18)
                    MessageBox.Show("کاربر گرامی شما مجاز به ثبت اطلاعات افراد زیر 18 سال نیستید");

                else
                {

                    Class1 c1 = new Class1();
                    string sel = "select * from moshtari";
                  
                            sel += " where codemeli='" + textBox7.Text + "'";
                        
                        
                        DataSet ds = new DataSet();
                        ds = c1.select(sel);


                        if (ds.Tables["t1"].Rows.Count == 1)
                        {
                            MessageBox.Show("کاربر گرامی فردی با این کد ملی قبلا در سیستم ثبت شده است", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {

                            string text, date1;
                            date1 = textBox3.Text + "/" + comboBox3.Text + "/" + comboBox4.Text;
                            Class1 c2 = new Class1();
                            text = "insert into moshtari values('" + textBox1.Text;
                            text += "','" + textBox2.Text + "','" + date1 + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox9.Text + "','" + textBox11.Text + "','" + textBox8.Text + "'," + textBox10.Text + ",'" + comboBox1.Text + "','" + comboBox2.Text + "','" + 0+ "')";

                            c2.insert(text);
                            Form3 f3 = new Form3();
                            f3.ShowDialog();
                            Close();
                        }
                   
                           
                               
                            
                        }

                    }
            }

               catch{
                        MessageBox.Show("خطا در ورود اطلاعات لطفا اطلاعات صحیح وارد کنید","خطا",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
                    }  
            
               
            
        }

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

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

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


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

        }

        private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar >= 48) && (e.KeyChar <= 57))
                e.Handled = false;
            else
                e.Handled = true;
        }

        private void textBox7_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar >= 48) && (e.KeyChar <= 57))
                e.Handled = false;
            else
                e.Handled = true;
        }

        private void textBox6_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar >= 48) && (e.KeyChar <= 57))
                e.Handled = false;
            else
                e.Handled = true;
        }

        private void textBox10_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar >= 48) && (e.KeyChar <= 57))
                e.Handled = false;
            else
                e.Handled = true;
        }

        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar >= 48) && (e.KeyChar <= 57))
                e.Handled = false;
            else
                e.Handled = true;
        }

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

            sel += " where codemeli='" + textBox7.Text + "'";


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


            if (ds.Tables["t1"].Rows.Count == 1)
            {
                MessageBox.Show("کاربر گرامی فردی با این کد ملی قبلا در سیستم ثبت شده است", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (textBox3.Text == "")
                {
                    MessageBox.Show("کاربر گرامی لطفا تاریخ را وارد کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    string text, date1;
                    string a = "provider=microsoft.jet.oledb.4.0;data source =hotel12.mdb";
                    date1 = textBox3.Text + "/" + comboBox3.Text + "/" + comboBox4.Text;

                    text = "update moshtari set name='" + textBox1.Text + "'" + ",lastname='" + textBox2.Text + "'" + ",datet='" + date1 + "'" + ",mtavalod='" + textBox4.Text + "'" + ",shsh='" + textBox5.Text + "'" + ",shravadid='" + textBox6.Text + "'" + ",codemeli='" + textBox7.Text + "'" + ",timev='" + textBox11.Text + "'" + ",shahr='" + textBox8.Text + "'" + ",nop='" + comboBox1.Text + "'" + ",tedadham='" + comboBox2.Text + "'" + ",hazf='" + 0 + "'" + " where money=" + money;

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

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


            }
        }
    }
}