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_darkhast_kharid : 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 dsk = new DataSet();
        
        public frm_darkhast_kharid()
        {
            InitializeComponent();
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

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

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

        private void frm_darkhast_kharid_Load(object sender, EventArgs e)
        {
            da.SelectCommand.CommandText = "select * from manategh ";
            da.Fill(ds, "g");
            commanategh.DataSource = ds;
            commanategh.DisplayMember = "g.mantaghe";


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


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

            comkharidar .DataSource = ds;
            comkharidar .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 button3_Click(object sender, EventArgs e)
        {
            
        

        }

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

            comkharidar.DataSource = dsk;
            comkharidar.DisplayMember = "z.name";
        }

        

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

        private void button3_Click_1(object sender, EventArgs e)
        {
            string c;


            //SqlDataAdapter da = new SqlDataAdapter("", con);
            if (txtmablagh.Text != "")
            {

                ds.Clear();
                c = "insert into darkhast_kharid(typemelk,hododmetraj,namekharidar,emkanat,tozihezafe,mablaghkharid,tedadotagh,mantaghe,ghedmat) values ('" + comtype.Text + "','" + txthododmetraj.Text + "', '" + comkharidar.Text + "', '" + txtemkanat.Text + "', '" + txttozihat.Text + "', '" + txtmablagh.Text + "', '" + txttedadotagh.Text + "', '" + commanategh.Text + "', '" + txtghedmat.Text + "' )";
                SqlCommand cmd = new SqlCommand(c, con);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد");


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