using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnTap
{
public partial class fChuongTrinh : Form
{
SqlDataAdapter adapter;
public static string username;
public fChuongTrinh()
{
InitializeComponent();
this.tbGhiChu.AutoSize = false;
}
private void btnThoat_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void label7_Click(object sender, EventArgs e)
{
private void fChuongTrinh_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void fChuongTrinh_Load(object sender, EventArgs e)
{
fDangNhap frmDN = new fDangNhap();
frmDN.ShowDialog();
lbXinChao.Text = "Xin chào " + username;
SqlConnection conn = new SqlConnection("Data Source=DESKTOP-
171AVQP;Initial Catalog=DuLieu;Integrated Security=True");
try
{
DataTable dt = new DataTable();
conn.Open();
string sql = "select * from Mathang ";
adapter = new SqlDataAdapter(sql, conn);
adapter.Fill(dt);
conn.Close();
dgv1.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show(this, "Lỗi kết nối!", "Lỗi", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void textBox6_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar)== false) { e.Handled = true; }
}
private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == false) { e.Handled = true; }
}
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == false) { e.Handled = true; }
}
private void button4_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(dlg.FileName);
tbGhiChu.Text = dlg.FileName;
}
}
private void dgv1_CellClick(object sender, DataGridViewCellEventArgs e)
{
textBox1.Text = dgv1.CurrentRow.Cells[0].Value.ToString();
textBox2.Text = dgv1.CurrentRow.Cells[1].Value.ToString();
comboBox1.Text = dgv1.CurrentRow.Cells[2].Value.ToString();
textBox6.Text = dgv1.CurrentRow.Cells[3].Value.ToString();
textBox5.Text = dgv1.CurrentRow.Cells[4].Value.ToString();
textBox4.Text = dgv1.CurrentRow.Cells[5].Value.ToString();
private void button3_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=DESKTOP-
171AVQP;Initial Catalog=DuLieu;Integrated Security=True");
try
{
conn.Open();
string sql = "update MatHang SET MaHang = N'" + textBox1.Text + "',
TenHang = N'" + textBox2.Text
+ "', ChatLieu = N'" + comboBox1.Text + "', Soluong = N'"
+ textBox6.Text
+ "', DonGiaNhap = N'" + textBox5.Text + "', DonGiaBan =
N'" + textBox4.Text + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
conn.Open();
string sql1 = "select * from Mathang ";
adapter = new SqlDataAdapter(sql, conn);
adapter.Fill(dt);
conn.Close();
dgv1.DataSource = dt;
}
catch { }
}
}
}