using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace ajans.class_ajans
{
   public class ranande
    {

        public int id_ran;
        public string coderanande;
        public string n_ranande;
        public string l_ranande;
        public string t_estekhdam;
        public string codemeli;
        public string mob;
        public string tel_home;
        public Boolean moteahel;
        public string address;

        public void insert()
        {
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "insert into ranande(coderanande,n_ranande,l_ranande,t_estekhdam,codemeli,mob,tel_home,moteahel,address) values (@coderanande,@n_ranande,@l_ranande,@t_estekhdam,@codemeli,@mob,@tel_home,@moteahel,@address)";
            com.Parameters.AddWithValue("@coderanande", coderanande);
            com.Parameters.AddWithValue("@n_ranande", n_ranande);
            com.Parameters.AddWithValue("@l_ranande", l_ranande);
            com.Parameters.AddWithValue("@t_estekhdam", t_estekhdam);
            com.Parameters.AddWithValue("@codemeli", codemeli);
            com.Parameters.AddWithValue("@mob", mob);
            com.Parameters.AddWithValue("@tel_home", tel_home);
            com.Parameters.AddWithValue("@moteahel", moteahel);
            com.Parameters.AddWithValue("@address", address);
            database da = new database();
            da.connect();
            da.command(com);
            da.disconnect();

        }
        public void update()
        {
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "update ranande set coderanande=@coderanande,n_ranande=@n_ranande,l_ranande=@l_ranande,t_estekhdam=@t_estekhdam,codemeli=@codemeli,mob=@mob,tel_home=@tel_home,moteahel=@moteahel,address=@address where id_ran=@id_ran";
            com.Parameters.AddWithValue("@coderanande", coderanande);
            com.Parameters.AddWithValue("@n_ranande", n_ranande);
            com.Parameters.AddWithValue("@l_ranande", l_ranande);
            com.Parameters.AddWithValue("@t_estekhdam", t_estekhdam);
            com.Parameters.AddWithValue("@codemeli", codemeli);
            com.Parameters.AddWithValue("@mob", mob);
            com.Parameters.AddWithValue("@tel_home", tel_home);
            com.Parameters.AddWithValue("@moteahel", moteahel);
            com.Parameters.AddWithValue("@address", address);
            com.Parameters.AddWithValue("@id_ran", id_ran);
            database da = new database();
            da.connect();
            da.command(com);
            da.disconnect();

        }
        public void delete()
        {
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "delete from ranande where (coderanande=@coderanande)";

            com.Parameters.AddWithValue("@coderanande", coderanande);
            //com.Parameters.AddWithValue("@l_ranande", l_ranande);
            //com.Parameters.AddWithValue("@t_estekhdam", t_estekhdam);
            //com.Parameters.AddWithValue("@codemeli", codemeli);
            //com.Parameters.AddWithValue("@mob", mob);
            //com.Parameters.AddWithValue("@tel_home", tel_home);
            //com.Parameters.AddWithValue("@moteahel", moteahel);
            //com.Parameters.AddWithValue("@address", address);
            database da = new database();
            da.connect();
            da.command(com);
            da.disconnect();
        }
        public DataTable show()
        {
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "select * from ranande";
            database da = new database();
            da.connect();
            DataTable dt = da.docommand(com);
            da.disconnect();
            return dt;


        }
        public DataTable searchbynamevafamili()
        {
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "select * from ranande where n_ranande like @n_ranande and l_ranande like @l_ranande ";
            com.Parameters.AddWithValue("@n_ranande", "%" + n_ranande + "%");
            com.Parameters.AddWithValue("@l_ranande", "%" + l_ranande + "%");
            database da = new database();
            da.connect();
            DataTable dt = da.docommand(com);
            da.disconnect();
            return dt;


        }
        public DataTable searchbycodemeli()
        {
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "select * from ranande where codemeli like @codemeli";
            com.Parameters.AddWithValue("@codemeli", "%" + codemeli + "%");
            database da = new database();
            da.connect();
            DataTable dt = da.docommand(com);
            da.disconnect();
            return dt;


        }
        public DataTable searchbymob()
        {
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "select * from ranande where mob like @mob";
            com.Parameters.AddWithValue("@mob", "%" + mob + "%");
            database da = new database();
            da.connect();
            DataTable dt = da.docommand(com);
            da.disconnect();
            return dt;


        }
        public Boolean Exist()
        {
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "select * from ranande where codemeli=@codemeli";
            com.Parameters.AddWithValue("@codemeli", codemeli);
            database da = new database();
            da.connect();
            DataTable dt = da.docommand(com);
            da.disconnect();

            if (dt.Rows.Count > 0) return true;
            return false;

        }
    }
}
