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 EditFrm : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=javaher;Integrated Security=True");
        SqlCommand cmd = new SqlCommand();
        DataTable dt = new DataTable();
        public EditFrm()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Close();
        }

        void showgrid()
        {
            dt.Clear();
            con.Open();
            cmd.Connection = con;
            cmd.CommandText = "select * from javaher";
            cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            Form2.dv.DataSource = dt;
            con.Close();
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (txtType.Text == "")
            {
                MessageBox.Show("Error","",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
            else
            {
                con.Open();
                cmd.Connection = con;
                cmd.CommandText = "update javaher set type='" + txtType.Text.Trim() + "' where id='" + txtCode.Text.Trim() + "'";
                cmd.ExecuteNonQuery();
                MessageBox.Show("ویرایش با موفقیت انجام شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                con.Close();
                this.Close();
                showgrid();
            }
        }
    }
}
