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

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

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

        private void btnEdit_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd.Connection = con;
            cmd.CommandText = "update [kala] set name='"+txtName.Text.Trim()+"',company='"+txtCompany.Text.Trim()+"',price='"+txtPrice.Text.Trim()+"' where id='"+lblID.Text+"'";
            cmd.ExecuteNonQuery();
            MessageBox.Show("ویرایش با موفقیت انجام شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            con.Close();
            this.Close();
            showgrid();
        }
    }
}
