001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.ComponentModel;
004.
using
System.Data.SqlClient;
005.
using
System.Data;
006.
using
System.Drawing;
007.
using
System.Linq;
008.
using
System.Text;
009.
using
System.Threading.Tasks;
010.
using
System.Windows.Forms;
011.
012.
namespace
test2
013.
{
014.
public
partial
class
add_receive : Form
015.
{
016.
017.
public
add_receive()
018.
{
019.
InitializeComponent();
020.
}
021.
022.
023.
024.
025.
026.
private
void
add_receive_Load(
object
sender, EventArgs e)
027.
{
028.
029.
030.
031.
032.
033.
034.
035.
SqlConnection conn =
new
SqlConnection(
"Data Source=ADMIN;Initial Catalog=BTEC_MANAGEMENT;User ID=Programmer;Password=1234"
);
036.
SqlDataAdapter da =
new
SqlDataAdapter(
"select private_code, product_code, serial,name, unit_name, description, remark, add_date FROM products"
, conn);
037.
DataTable dt =
new
DataTable();
038.
da.Fill(dt);
039.
040.
foreach
(DataRow item
in
dt.Rows)
041.
{
042.
int
n = dataGridView1.Rows.Add();
043.
dataGridView1.Rows[n].Cells[1].Value = item[
"private_code"
].ToString();
044.
dataGridView1.Rows[n].Cells[2].Value = item[
"product_code"
].ToString();
045.
dataGridView1.Rows[n].Cells[3].Value = item[
"serial"
].ToString();
046.
dataGridView1.Rows[n].Cells[4].Value = item[
"name"
].ToString();
047.
dataGridView1.Rows[n].Cells[5].Value = item[
"unit_name"
].ToString();
048.
dataGridView1.Rows[n].Cells[6].Value = item[
"description"
].ToString();
049.
dataGridView1.Rows[n].Cells[7].Value = item[
"remark"
].ToString();
050.
dataGridView1.Rows[n].Cells[8].Value = item[
"add_date"
].ToString();
051.
dataGridView1.Rows[n].Cells[0].Value =
false
;
052.
053.
}
054.
055.
056.
057.
}
058.
private
void
simpleButton2_Click(
object
sender, EventArgs e)
059.
{
060.
061.
this
.Close();
062.
}
063.
064.
private
void
ok_receive_Click(
object
sender, EventArgs e)
065.
{
066.
foreach
(DataGridViewRow dr
in
dataGridView1.Rows)
067.
{
068.
if
((
bool
)dr.Cells[0].Value ==
true
)
069.
{
070.
label1.Text = dr.Cells[0].RowIndex.ToString();
071.
072.
073.
074.
}
075.
076.
077.
078.
079.
080.
081.
082.
083.
084.
085.
086.
}
087.
}
088.
089.
090.
private
void
dataGridView1_CellContentClick_1(
object
sender, DataGridViewCellEventArgs e)
091.
{
092.
if
(e.RowIndex == -1)
093.
return
;
094.
else
095.
{
096.
dataGridView1.Rows[e.RowIndex].Selected =
true
;
097.
098.
}
099.
}
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
}
110.
}