Você está na página 1de 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 frmdelivery : Form
{
public frmdelivery()
{
InitializeComponent();
}
String connstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + App
lication.StartupPath + "\\CuttingToolsStock.accdb;";
String mahangtemp;
private void frmdelivery_Load(object sender, EventArgs e)
{
loaddulieu();
}
private void loaddulieu()
{
OleDbConnection conn = new OleDbConnection(connstr);
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM chitietphieuxuat;
", conn);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dgvdeliverycontrol.DataSource = bs;
da.Update(dt);
conn.Close();
int stt = 0;
for (int i = 0; i < dgvdeliverycontrol.Rows.Count; i++)
{
stt++;
dgvdeliverycontrol.Rows[i].Cells[0].Value = stt;
}
}
private void dgvdeliverycontrol_CellContentClick(object sender, DataGrid
ViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dgvdeliverycontrol.Rows[e.RowIndex];
txtmaphieuxuat.Text = row.Cells[1].Value.ToString();
txtmahangxuat.Text = row.Cells[2].Value.ToString();
txttenhangxuat.Text = row.Cells[3].Value.ToString();
txtsoluongxuat.Text = row.Cells[4].Value.ToString();

txtngaythangxuat.Text = row.Cells[5].Value.ToString();
txtjobnumber.Text = row.Cells[6].Value.ToString();
txtghichu.Text = row.Cells[9].Value.ToString();
mahangtemp = row.Cells[2].Value.ToString();
txtsoluongxuat.Enabled = false;
}
}
private void capnhatdulieu()
{
String capnhat = "UPDATE chitietphieuxuat SET mahang='" + txttimkiem
.Text + "', tenhangxuat='" + txttenhangxuat.Text + "', jobnumber='" + txtjobnumb
er.Text + "', soluongxuat='" + txtsoluongxuat.Text + "', ghichu='" + txtghichu.T
ext + "' 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 = "";
txtmaphieuxuat.Text = "";
txttenhangxuat.Text = "";
txtsoluongxuat.Text = "";
txtjobnumber.Text = "";
txtngaythangxuat.Text = "";
txtghichu.Text = "";
}
private void txttimkiem_KeyPress(object sender, KeyPressEventArgs e)
{
OleDbConnection conn = new OleDbConnection(connstr);
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM chitietphieuxuat
WHERE mahangxuat 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;
dgvdeliverycontrol.DataSource = bs;
da.Update(dt);
conn.Close();
int stt = 0;
for (int i = 0; i < dgvdeliverycontrol.Rows.Count; i++)
{
stt++;
dgvdeliverycontrol.Rows[i].Cells[0].Value = stt;
}
}
private void bntexit_Click(object sender, EventArgs e)
{
{
this.Close();
}
}

}
}

Você também pode gostar