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 shop
{
    public partial class ghore : Form
    {
        public ghore()
        {
            InitializeComponent();
        }

        public void rand(out int x)
        {
            Random r = new Random();
            x = r.Next(100);
        }

        public void bank()
        {
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbCommand com = new OleDbCommand();
            com.Connection = con;
            com.CommandText = "select * from saghf where ID='" + txt1.Text + "'";
            OleDbDataReader dr;
            con.Open();
            dr = com.ExecuteReader();
            if (dr.Read())
            {
                lblid.Text = dr["ID"].ToString();
                lblnam1.Text = dr["nam"].ToString();
                lblfamili1.Text = dr["famili"].ToString();
                lblcod1.Text = dr["cod"].ToString();
                lbltel1.Text = dr["tel"].ToString();
                lblmablagh.Text = dr["mablagh"].ToString();
            }
            else
            {
                MessageBox.Show("!كد مورد نظر موجود نيست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "")
            {
                MessageBox.Show("لطفا اعداد قرعه كشي را وارد كنيد.");
            }
            else
            {
                int a = int.Parse(textBox1.Text);
                int b = int.Parse(textBox2.Text);
                Random r = new Random();
                int x;
                x = r.Next(a, b + 1);
                txt1.Text = x.ToString();
            }
            bank();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "")
            {
                MessageBox.Show("لطفا اعداد قرعه كشي را وارد كنيد.");
            }
            else
            {
                int a = int.Parse(textBox1.Text);
                int b = int.Parse(textBox2.Text);
                Random r = new Random();
                int x;
                x = r.Next(a, b + 1);
                txt2.Text = x.ToString();
                btn1.Enabled = false;
            }
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbCommand com = new OleDbCommand();
            com.Connection = con;
            com.CommandText = "select * from saghf where ID='" + txt2.Text + "'";
            OleDbDataReader dr;
            con.Open();
            dr = com.ExecuteReader();
            if (dr.Read())
            {
                lblid2.Text = dr["ID"].ToString();
                lblnam2.Text = dr["nam"].ToString();
                lblfamili2.Text = dr["famili"].ToString();
                lblcod2.Text = dr["cod"].ToString();
                lbltel2.Text = dr["tel"].ToString();
                lblmablagh2.Text = dr["mablagh"].ToString();
            }
            else
            {
                MessageBox.Show("!كد مورد نظر موجود نيست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "")
            {
                MessageBox.Show("لطفا اعداد قرعه كشي را وارد كنيد.");
            }
            else
            {
                int a = int.Parse(textBox1.Text);
                int b = int.Parse(textBox2.Text);
                Random r = new Random();
                int x;
                x = r.Next(a, b + 1);
                txt3.Text = x.ToString();
                btn1.Enabled = false;
            }
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbCommand com = new OleDbCommand();
            com.Connection = con;
            com.CommandText = "select * from saghf where ID='" + txt3.Text + "'";
            OleDbDataReader dr;
            con.Open();
            dr = com.ExecuteReader();
            if (dr.Read())
            {
                lblid3.Text = dr["ID"].ToString();
                lblnam3.Text = dr["nam"].ToString();
                lblfamili3.Text = dr["famili"].ToString();
                lblcod3.Text = dr["cod"].ToString();
                lbltel3.Text = dr["tel"].ToString();
                lblmablagh3.Text = dr["mablagh"].ToString();
            }
            else
            {
                MessageBox.Show("!كد مورد نظر موجود نيست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "")
            {
                MessageBox.Show("لطفا اعداد قرعه كشي را وارد كنيد.");
            }
            else
            {
                int a = int.Parse(textBox1.Text);
                int b = int.Parse(textBox2.Text);
                Random r = new Random();
                int x;
                x = r.Next(a, b + 1);
                txt4.Text = x.ToString();
                btn1.Enabled = false;
            }
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbCommand com = new OleDbCommand();
            com.Connection = con;
            com.CommandText = "select * from saghf where ID='" + txt4.Text + "'";
            OleDbDataReader dr;
            con.Open();
            dr = com.ExecuteReader();
            if (dr.Read())
            {
                lblid4.Text = dr["ID"].ToString();
                lblnam4.Text = dr["nam"].ToString();
                lblfamili4.Text = dr["famili"].ToString();
                lblcod4.Text = dr["cod"].ToString();
                lbltel4.Text = dr["tel"].ToString();
                lblmablagh4.Text = dr["mablagh"].ToString();
            }
            else
            {
                MessageBox.Show("!كد مورد نظر موجود نيست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "")
            {
                MessageBox.Show("لطفا اعداد قرعه كشي را وارد كنيد.");
            }
            else
            {
                int a = int.Parse(textBox1.Text);
                int b = int.Parse(textBox2.Text);
                Random r = new Random();
                int x;
                x = r.Next(a, b + 1);
                txt5.Text = x.ToString();
                btn1.Enabled = false;
            }
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbCommand com = new OleDbCommand();
            com.Connection = con;
            com.CommandText = "select * from saghf where ID='" + txt5.Text + "'";
            OleDbDataReader dr;
            con.Open();
            dr = com.ExecuteReader();
            if (dr.Read())
            {
                lblid5.Text = dr["ID"].ToString();
                lblnam5.Text = dr["nam"].ToString();
                lblfamili5.Text = dr["famili"].ToString();
                lblcod5.Text = dr["cod"].ToString();
                lbltel5.Text = dr["tel"].ToString();
                lblmablagh5.Text = dr["mablagh"].ToString();
            }
            else
            {
                MessageBox.Show("!كد مورد نظر موجود نيست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar)))
            {
                e.Handled = true;
            }
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar)))
            {
                e.Handled = true;
            }
        }
    }
}
