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.SqlClient;

namespace amlakyar
{
    public partial class Frm_Forush : Form
    {
        static SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\amlak.mdf;integrated security=true;User Instance=True");
        SqlDataAdapter da = new SqlDataAdapter("", con);
        DataSet ds = new DataSet();
        DataSet ds2 = new DataSet();
        DataSet ds3 = new DataSet();
        DataSet ds4 = new DataSet();
        DataSet ds5 = new DataSet();
        DataSet ds6 = new DataSet();
        DataSet ds7 = new DataSet();
        DataSet ds8 = new DataSet();
        string a2,a1,a3,a4;
        public Frm_Forush()
        {
            InitializeComponent();
        }

        private void label9_Click(object sender, EventArgs e)
        {

           
        }

        

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frm_etelat_amlak vorod4 = new frm_etelat_amlak();
            vorod4.ShowDialog();
            
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frm_modirat_tabaghe vorod5 = new frm_modirat_tabaghe();
            vorod5.ShowDialog();
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frm_moderiat_nemaha vorod6 = new frm_moderiat_nemaha();
            vorod6.ShowDialog();
        }

        private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frm_moreriat_mantaghe vorod7 = new frm_moreriat_mantaghe();
            vorod7.ShowDialog();
        }

        private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frm_etelat_kharidar_va_foroshande  vorod8 = new frm_etelat_kharidar_va_foroshande();
            vorod8.ShowDialog();
        }

        private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frm_moderiat_saghf vorod9 = new frm_moderiat_saghf();
            vorod9.ShowDialog();
        }

        private void linkLabel7_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frm_moreriat_ashkal_zamin vorod10 = new frm_moreriat_ashkal_zamin();
            vorod10.ShowDialog();
        }

        private void Frm_Forush_Load(object sender, EventArgs e)
        {

            
            da.SelectCommand.CommandText = "select * from etelat_melk ";
            da.Fill(ds, "h");
            commelk.DataSource = ds;
            commelk.DisplayMember = "h.name_melk";
            commelk.Refresh();


            da.SelectCommand.CommandText = "select * from tabaghe ";
            da.Fill(ds3, "k");
            comtabaghe.DataSource = ds3;
            comtabaghe.DisplayMember = "k.name_tabaghe";

            


            da.SelectCommand.CommandText = "select * from nemaha ";
            da.Fill(ds, "f");
            comnema.DataSource = ds;
            comnema.DisplayMember = "f.name_nama";



            da.SelectCommand.CommandText = "select * from ashkalzamin ";
            da.Fill(ds, "e");
            comsheklzamin.DataSource = ds;
            comsheklzamin.DisplayMember = "e.name_shekl";
            comsheklzamin.Refresh();



            da.SelectCommand.CommandText = "select * from manategh ";
            da.Fill(ds, "g");
            commantaghe.DataSource = ds;
            commantaghe.DisplayMember = "g.mantaghe";


            da.SelectCommand.CommandText = "select * from saghfha ";
            da.Fill(ds, "j");
            comsaghf.DataSource = ds;
            comsaghf.DisplayMember = "j.name_saghf";


            da.SelectCommand.CommandText = "select * from kharidar_forushande ";
            da.Fill(ds, "z");
            
            comnamemalek.DataSource = ds;
            comnamemalek.DisplayMember = "z.name";



            timer1.Enabled = true;
            System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
            DateTime dt = new DateTime();
            dt = DateTime.Now;
            Class_date cdate = new Class_date();
            string date = dt.Year.ToString() + "/" + dt.Month.ToString() + "/" + dt.Day.ToString();

           



        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            
            if (checkBox1.Checked == true)
            {
                a1 = " آب";

            }
            else
                a1 = "";
          
        

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            
            if (checkBox2.Checked == true)
            {
                a2 = "برق ";

            }
            else
                a2 = "";
               
            
        }

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

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked == true)
            {
                a3 = "گاز";

            }
            else
                a3 ="";
               
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked == true)
            {
                a4 = "تلفن";

            }
            else
                a4 = "";
               
        }

        

        private void commelk_Enter(object sender, EventArgs e)
        {
            ds2.Clear();
            da.SelectCommand.CommandText = "select * from etelat_melk ";
            da.Fill(ds2, "h");
            commelk.DataSource = ds2;
            commelk.DisplayMember = "h.name_melk";

        }

        private void comtabaghe_Enter(object sender, EventArgs e)
        {
            ds3.Clear();
            da.SelectCommand.CommandText = "select * from tabaghe ";
            da.Fill(ds3, "k");
            comtabaghe.DataSource = ds3;
            comtabaghe.DisplayMember = "k.name_tabaghe";

        }

        private void comnema_Enter(object sender, EventArgs e)
        {
            ds4.Clear();
            da.SelectCommand.CommandText = "select * from nemaha ";
            da.Fill(ds4, "f");
            comnema.DataSource = ds4;
            comnema.DisplayMember = "f.name_nama";
        }

        private void commantaghe_Enter(object sender, EventArgs e)
        {
            ds5.Clear();
            da.SelectCommand.CommandText = "select * from manategh ";
            da.Fill(ds5, "g");
            commantaghe.DataSource = ds5;
            commantaghe.DisplayMember = "g.mantaghe";
        }

        private void comnamemalek_Enter(object sender, EventArgs e)
        {
            ds6.Clear();
            da.SelectCommand.CommandText = "select * from kharidar_forushande ";
            da.Fill(ds6, "z");

            comnamemalek.DataSource = ds6;
            comnamemalek.DisplayMember = "z.name";
        }

        private void comsaghf_Enter(object sender, EventArgs e)
        {

            ds7.Clear();
            da.SelectCommand.CommandText = "select * from saghfha ";
            da.Fill(ds7, "j");
            comsaghf.DataSource = ds7;
            comsaghf.DisplayMember = "j.name_saghf";
        }

        private void comsheklzamin_Enter(object sender, EventArgs e)
        {
            ds8.Clear();
            da.SelectCommand.CommandText = "select * from ashkalzamin ";
            da.Fill(ds8, "e");
            comsheklzamin.DataSource = ds8;
            comsheklzamin.DisplayMember = "e.name_shekl";
            
        }

        

        private void button2_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            string s;
            txtemk.Text = a4 + " " + a2 + " " + a3 + " " + a1;
            if (txtmetraj.Text != "" && txtprice.Text != "")
            {
                s = "insert into forosh(type,melk,tabaghe,ghedmat,vahed,metraj,address,emkanat,emkanat_ezafe,nema,mantaghe,tedad_otagh,price,name_malek,saghf,shekl_zamin,type_koche,vazeat) values ('" + comtype.Text + "','" + commelk.Text + "','" + comtabaghe.Text + "','" + txtghedmat.Text + "','" + txtvahed.Text + "','" + txtmetraj.Text + "','" + txtaddress.Text + "','" + txtemk.Text + "','" + txtemkanatezafe.Text + "','" + comnema.Text + "','" + commantaghe.Text + "','" + txttedadotagh.Text + "','" + txtprice.Text + "','" + comnamemalek.Text + "','" + comsaghf.Text + "','" + comsheklzamin.Text + "','" + txttypekoche.Text + "','" + txtvazeat.Text + "' )";
                SqlCommand cmd = new SqlCommand(s, con);

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                da.SelectCommand.CommandText = "select * from forosh";
                da.Fill(ds, "t1");
                MessageBox.Show("اطلاعات با موفقیت ثبت شد");


            }




            else { MessageBox.Show("لطفا فيلد هاي ستاره دار را به دقت وارد نماييد"); }
           

        }

        

        
    }
}