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

namespace Javaher
{
    public partial class EditCustomer : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=javaher;Integrated Security=True");
        SqlCommand cmd = new SqlCommand();
        DataTable dt = new DataTable();
        public EditCustomer()
        {
            InitializeComponent();
        }

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

        void showgrid()
        {
            con.Open();
            dt.Clear();
            cmd.Connection = con;
            cmd.CommandText = "select * from [customer]";
            cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            Form4.dv.DataSource = dt;
            con.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtname.Text == "" || txttel.Text == "")
                MessageBox.Show("فیلدهای نام و تلفن نمی توانند خالی باشند", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else
            {
                con.Open();
                cmd.Connection = con;
                cmd.CommandText = "update [customer] set name='"+txtname.Text.Trim()+"' , fathername='"+txtfather.Text.Trim()+"' , iid='"+txtiid.Text.Trim()+"' , mellicode='"+txtmellicode.Text.Trim()+"' , tel='"+txttel.Text.Trim()+"' , adress='"+txtadress.Text.Trim()+"' where id='"+txtcode.Text+"'";
                cmd.ExecuteNonQuery();
                MessageBox.Show("ویرایش با موفقیت انجام شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                con.Close();
                this.Close();
                showgrid();
            }
        }
    }
}
