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

namespace moshaveramlak
{
    public partial class sale : Form
    {
        public sale()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "زمین")
            {
                groupBox2.Visible = true;
                groupBox3.Visible = true;
            }
            else if (comboBox1.Text == "خانه")
            {
                groupBox2.Visible = true;
                groupBox3.Visible = true;
            }
            else if (comboBox1.Text == "آپارتمان")
            {
                groupBox2.Visible = true;
                groupBox3.Visible = true;
            }

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "زمین")
            {
                OleDbConnection f5 = new OleDbConnection();
                f5.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=amlak.mdb";
                OleDbCommand f6 = new OleDbCommand();
                f6.Connection = f5;
                f6.CommandText = "select * from zamin where idz='" + textBox1.Text + "'";
                OleDbDataReader re;
                f5.Open();
                re = f6.ExecuteReader();
                if (re.Read())
                {
                    textBox2.Text = re["idz"].ToString();
                    textBox3.Text = "زمین";
                    textBox4.Text = re["sahebzamin"].ToString();
                    textBox5.Text = re["metr"].ToString();
                    textBox6.Text = re["mablagh"].ToString();
                    textBox7.Text = re["tozihat"].ToString();
                    textBox8.Text = re["address"].ToString();
                    textBox9.Text = "No phone";


                }
                else
                    MessageBox.Show("!كد شناسایی مورد نظر موجود نيست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            else if (comboBox1.Text == "خانه")
            {
                // ویرایش -خانه
                OleDbConnection f5 = new OleDbConnection();
                f5.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=amlak.mdb";
                OleDbCommand f6 = new OleDbCommand();
                f6.Connection = f5;
                f6.CommandText = "select * from khaneh where idk='" + textBox1.Text + "'";
                OleDbDataReader re;
                f5.Open();
                re = f6.ExecuteReader();
                if (re.Read())
                {
                    textBox2.Text = re["idk"].ToString();
                    textBox3.Text = re["tabagheh"].ToString();
                    textBox4.Text = re["sahebkhaneh"].ToString();
                    textBox5.Text = re["metr"].ToString();
                    textBox6.Text = re["mablagheh"].ToString();
                    textBox7.Text = re["tozihat"].ToString();
                    textBox8.Text = re["address"].ToString();
                    textBox9.Text = re["tell"].ToString();


                }
                else
                    MessageBox.Show("!كد شناسایی مورد نظر موجود نيست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            else if (comboBox1.Text == "آپارتمان")
            {
                // ویرایش -آپارتمان


                OleDbConnection f5 = new OleDbConnection();
                f5.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=amlak.mdb";
                OleDbCommand f6 = new OleDbCommand();
                f6.Connection = f5;
                f6.CommandText = "select * from aparteman where ida='" + textBox1.Text + "'";
                OleDbDataReader re;
                f5.Open();
                re = f6.ExecuteReader();
                if (re.Read())
                {
                    textBox2.Text = re["ida"].ToString();
                    textBox3.Text = re["tabagheh"].ToString();
                    textBox4.Text = re["sahebaparteman"].ToString();
                    textBox5.Text = re["metr"].ToString();
                    textBox6.Text = re["mablaghe"].ToString();
                    textBox7.Text = re["tozihat"].ToString();
                    textBox8.Text = re["address"].ToString();
                    textBox9.Text = re["tell"].ToString();
                }


                else
                    MessageBox.Show("!كد شناسایی مورد نظر موجود نيست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


        private void button2_Click(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=amlak.mdb";
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "insert into listsale(code,nohe,sahebmelk,metr,mablagheh,tozihat,address,tell) values ('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "')";
            con.Open();
            com.Connection = con;
            com.ExecuteNonQuery();
            con.Close();




            if (comboBox1.Text == "زمین")
            {
                OleDbConnection f7 = new OleDbConnection();
                f7.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=amlak.mdb";
                OleDbCommand f8 = new OleDbCommand();
                f8.Connection = f7;
                int item;
                f8.CommandText = "select count(idz) from zamin where idz='" + textBox1.Text + "'";
                f7.Open();
                item = (int)f8.ExecuteScalar();
                f7.Close();
                if (item != 0)
                {
                    f8.CommandText = "delete from zamin where idz='" + textBox1.Text + "'";
                    f7.Open();
                    f8.ExecuteNonQuery();
                    f7.Close();
                    
                }

                MessageBox.Show("با موفقیت ثبت شده است ", "پیام", MessageBoxButtons.OK, MessageBoxIcon.Information);


            }



            else if (comboBox1.Text == "خانه")
            {
                OleDbConnection aa = new OleDbConnection();
                aa.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=amlak.mdb";
                OleDbCommand bb = new OleDbCommand();
                bb.Connection = aa;
                int item;
                bb.CommandText = "select count(idk) from khaneh where idk='" + textBox1.Text + "'";
                aa.Open();
                item = (int)bb.ExecuteScalar();
                aa.Close();
                if (item != 0)
                {
                    bb.CommandText = "delete from khaneh where idk='" + textBox1.Text + "'";
                    aa.Open();
                    bb.ExecuteNonQuery();
                    aa.Close();
                   
                }

                MessageBox.Show("با موفقیت ثبت شده است ", "پیام", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }





            else if (comboBox1.Text == "آپارتمان")
            {
                OleDbConnection cc = new OleDbConnection();
                cc.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=amlak.mdb";
                OleDbCommand dd = new OleDbCommand();
                dd.Connection = cc;
                int item;
                dd.CommandText = "select count(ida) from aparteman where ida='" + textBox1.Text + "'";
               cc.Open();
                item = (int)dd.ExecuteScalar();
                cc.Close();
                if (item != 0)
                {
                    dd.CommandText = "delete from aparteman where ida='" + textBox1.Text + "'";
                    cc.Open();
                    dd.ExecuteNonQuery();
                    cc.Close();
                   
                }

                MessageBox.Show("با موفقیت ثبت شده است ", "پیام", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }


        }
    }
}
