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



       void display1()
        {
            OleDbConnection con1 = new OleDbConnection();
            con1.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=amlak.mdb";
            OleDbDataAdapter da = new OleDbDataAdapter("select * from zamin", con1);
            DataSet ds = new DataSet();
            da.Fill(ds, "zamin");
            dataGridView1.DataSource = ds.Tables["zamin"].DefaultView;
            con1.Close();
        }

   



     
        private void rec_Load(object sender, EventArgs e)
        {   
            // TODO: This line of code loads data into the 'amlakDataSet.zamin' table. You can move, or remove it, as needed.
            this.zaminTableAdapter.Fill(this.amlakDataSet.zamin);



                                            
        }





  

        // شروع بخش دستورات زمین



        private void pictureBox3_Click(object sender, EventArgs e)
        {
            //اضافه - زمین
            OleDbConnection f1 = new OleDbConnection();
            f1.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=amlak.mdb";
            OleDbCommand f2 = new OleDbCommand();
            f2.CommandText = "insert into zamin(idz,metr,sahebzamin,mablagh,address,tozihat) values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "')";
           f1.Open();
            f2.Connection = f1;
            f2.ExecuteNonQuery();
            f1.Close();
            display1();
            MessageBox.Show("با موفقیت ثبت شد", "پیام", MessageBoxButtons.OK, MessageBoxIcon.Information);
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox4.Clear();
            textBox5.Clear();
            textBox6.Clear();
            
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            //حذف - زمین
            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='" + textBox7.Text + "'";
            f7.Open();
            item = (int)f8.ExecuteScalar();
            f7.Close();
            if (item != 0)
            {
                f8.CommandText = "delete from zamin where idz='" +textBox7.Text + "'";
                f7.Open();
                f8.ExecuteNonQuery();
                f7.Close();
                display1();
            }
            else
                MessageBox.Show("!كد شناسایی مورد نظر موجود نيست", "خطا",MessageBoxButtons.OK, MessageBoxIcon.Error);
       
        }


        private void pictureBox1_Click(object sender, EventArgs e)
        {
            // ویرایش -زمین
         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='" + textBox7.Text + "'";
            OleDbDataReader re;
            f5.Open();
            re = f6.ExecuteReader();
            if (re.Read())
            {
                textBox1.Text = re["idz"].ToString();
                textBox2.Text = re["metr"].ToString();
                textBox3.Text = re["sahebzamin"].ToString();
                textBox4.Text = re["mablagh"].ToString();
                textBox5.Text = re["address"].ToString();
                textBox6.Text = re["tozihat"].ToString();
                
               
           }
            else
                MessageBox.Show("!كد شناسایی مورد نظر موجود نيست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);

        }

        private void textBox7_TextChanged(object sender, EventArgs e)
        {

        }

    
     






// پایان دستورات بخش زمین


    }
}
