Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

using

using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.OleDb;

namespace CuttingToolsStock
{
public partial class frmreceive : Form
{
public frmreceive()
{
InitializeComponent();
}
String connstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + App
lication.StartupPath + "\\CuttingToolsStock.accdb;";
String mahangtemp;
private void frmreceive_Load(object sender, EventArgs e)
{
loaddulieu();
}
private void loaddulieu()
{
OleDbConnection conn = new OleDbConnection(connstr);
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM chitietphieunhap
ORDER BY ngaynhaphang ASC;", conn);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dgvreceivecontrol.DataSource = bs;
da.Update(dt);
conn.Close();
int stt = 0;
for (int i = 0; i < dgvreceivecontrol.Rows.Count; i++)
{
stt++;
dgvreceivecontrol.Rows[i].Cells[0].Value = stt;
}
}
private void dgvreceivecontrol_CellContentClick(object sender, DataGridV
iewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dgvreceivecontrol.Rows[e.RowIndex];
txtmaphieunhap.Text = row.Cells[1].Value.ToString();
txtmahangnhap.Text = row.Cells[2].Value.ToString();
txttenhangnhap.Text = row.Cells[3].Value.ToString();
txtsoluongnhap.Text = row.Cells[4].Value.ToString();

txtngaynhaphang.Text = row.Cells[5].Value.ToString();
txtbinno.Text = row.Cells[6].Value.ToString();
txtponumber.Text = row.Cells[7].Value.ToString();
txtprice.Text = row.Cells[8].Value.ToString();
txtghichu.Text = row.Cells[9].Value.ToString();
mahangtemp = row.Cells[2].Value.ToString();
txtsoluongnhap.Enabled = false;
}
}
private void capnhatdulieu()
{
String capnhat = "UPDATE chitietphieunhap SET mahang='" + txttimkiem
.Text + "', tenhangnhap='" + txttenhangnhap.Text + "', soluongnhap='" + txtsoluo
ngnhap.Text + "', ponumber='" + txtponumber.Text + "', price='" + txtprice.Text
+ "', ghichu='" + txtghichu.Text + "' WHERE mahang='" + mahangtemp + "';";
OleDbConnection conn = new OleDbConnection(connstr);
OleDbCommand cmd = new OleDbCommand(capnhat, conn);
conn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("C?p nh?t d? li?u thnh cng", "Thng Bo");
conn.Close();
loaddulieu();
txttimkiem.Text = "";
txtmaphieunhap.Text = "";
txttenhangnhap.Text = "";
txtsoluongnhap.Text = "";
txtponumber.Text = "";
txtprice.Text = "";
txtngaynhaphang.Text = "";
txtbinno.Text = "";
txtghichu.Text = "";
}
private void txttimkiem_KeyPress(object sender, KeyPressEventArgs e)
{
OleDbConnection conn = new OleDbConnection(connstr);
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM chitietphieunhap
WHERE mahangnhap LIKE('%" + txttimkiem.Text + "%') ;", conn);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dgvreceivecontrol.DataSource = bs;
da.Update(dt);
conn.Close();
int stt = 0;
for (int i = 0; i < dgvreceivecontrol.Rows.Count; i++)
{
stt++;
dgvreceivecontrol.Rows[i].Cells[0].Value = stt;
}
}
private void bntexit_Click(object sender, EventArgs e)
{

{
this.Close();
}
}
}
}

You might also like