001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.ComponentModel;
004.
using
System.Data;
005.
using
System.Drawing;
006.
using
System.Data.SqlClient;
007.
using
System.Linq;
008.
using
System.Text;
009.
using
System.Windows.Forms;
010.
011.
namespace
WindowsFormsApplication1
012.
{
013.
public
partial
class
tire_fuse : Form
014.
{
015.
016.
private
SqlConnection connection;
017.
private
string
sql;
018.
private
SqlCommand sqlcmd;
019.
private
SqlDataAdapter da;
020.
private
DataSet ds;
021.
private
BindingSource bindingSrc;
022.
023.
public
tire_fuse()
024.
{
025.
InitializeComponent();
026.
this
.WindowState = FormWindowState.Maximized;
027.
028.
string
constr = @
"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\tatum\Documents\db_boon.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
;
029.
connection =
new
SqlConnection(constr);
030.
if
(connection.State == ConnectionState.Closed)
031.
{
032.
connection.Open();
033.
}
034.
}
035.
036.
private
void
button20_Click(
object
sender, EventArgs e)
037.
{
038.
039.
sql =
"SELECT cus_id,first_name,last_name,tel,truck_id FROM CUSTOMER"
;
040.
if
(comboBox18.SelectedIndex != 0)
041.
{
042.
if
(comboBox18.SelectedIndex == 1)
043.
{
044.
sql +=
" WHERE cus_id = '"
+ textBox8.Text +
"'"
;
045.
}
046.
if
(comboBox18.SelectedIndex == 2)
047.
{
048.
sql +=
" WHERE first_name = '"
+ textBox8.Text +
"'"
;
049.
}
050.
if
(comboBox18.SelectedIndex == 3)
051.
{
052.
sql +=
" WHERE truck_id = '"
+ textBox8.Text +
"'"
;
053.
}
054.
if
(comboBox18.SelectedIndex == 4)
055.
{
056.
sql +=
" WHERE tel ='"
+ textBox8.Text +
"'"
;
057.
}
058.
}
059.
sqlcmd =
new
SqlCommand(sql, connection);
060.
061.
da =
new
SqlDataAdapter(sqlcmd);
062.
da.SelectCommand = sqlcmd;
063.
064.
ds =
new
DataSet();
065.
da.Fill(ds,
"show_cus"
);
066.
dataGridView5.DataSource = ds.Tables[
"show_cus"
];
067.
068.
069.
070.
dataGridView5.Columns[0].Width = 70;
071.
dataGridView5.Columns[0].HeaderText =
"รหัสลูกค้า1"
;
072.
073.
dataGridView5.Columns[1].Width = 80;
074.
dataGridView5.Columns[1].HeaderText =
"ชื่อลูกค้า"
;
075.
076.
dataGridView5.Columns[2].Width = 80;
077.
dataGridView5.Columns[2].HeaderText =
"นามสกุล"
;
078.
079.
dataGridView5.Columns[3].Width = 40;
080.
dataGridView5.Columns[3].HeaderText =
"เบอร์โทรศัพท์"
;
081.
082.
dataGridView5.Columns[4].Width = 30;
083.
dataGridView5.Columns[4].HeaderText =
"ทะเบียนรถ"
;
084.
085.
}
086.
087.
private
void
button10_Click(
object
sender, EventArgs e)
088.
{
089.
090.
091.
sql =
"SELECT tire_id FROM TIRE_FUSE ORDER BY tire_id DESC"
;
092.
sqlcmd =
new
SqlCommand(sql, connection);
093.
094.
da =
new
SqlDataAdapter(sqlcmd);
095.
da.SelectCommand = sqlcmd;
096.
097.
ds =
new
DataSet();
098.
da.Fill(ds,
"t_id"
);
099.
100.
bindingSrc =
new
BindingSource();
101.
bindingSrc.DataSource = ds.Tables[
"t_id"
];
102.
string
idtf = ds.Tables[
"t_id"
].Rows[0].ItemArray[0].ToString();
103.
104.
105.
string
id_tfuse = idtf;
106.
107.
string
chr_id = id_tfuse.Substring(0, 1);
108.
string
num_id = id_tfuse.Substring(1, 5);
109.
110.
int
tid =
int
.Parse(num_id);
111.
int
pnum_idplus = tid + 1;
112.
113.
string
re_tid, use_tid;
114.
if
(pnum_idplus <= 9)
115.
{
116.
re_tid = Convert.ToString(pnum_idplus);
117.
use_tid = re_tid.Insert(0,
"F0000"
);
118.
}
119.
else
if
(pnum_idplus > 9)
120.
{
121.
re_tid = Convert.ToString(pnum_idplus);
122.
use_tid = re_tid.Insert(0,
"F000"
);
123.
}
124.
else
if
(pnum_idplus > 99)
125.
{
126.
re_tid = Convert.ToString(pnum_idplus);
127.
use_tid = re_tid.Insert(0,
"F00"
);
128.
}
129.
else
if
(pnum_idplus > 999)
130.
{
131.
re_tid = Convert.ToString(pnum_idplus);
132.
use_tid = re_tid.Insert(0,
"C0"
);
133.
}
134.
else
135.
{
136.
re_tid = Convert.ToString(pnum_idplus);
137.
use_tid = re_tid.Insert(0,
"C"
);
138.
}
139.
140.
141.
sql =
"INSERT INTO TIRE_FUSE(tire_id, cus_id, user_id, patt_name, size, brand_name, com_name, model, get_date)VALUES(@tid, @cid, @uid, @patt, @size, @brand, @com, @mod, @gdate)"
;
142.
sqlcmd =
new
SqlCommand(sql, connection);
143.
144.
sqlcmd.Parameters.Clear();
145.
sqlcmd.CommandText = sql;
146.
sqlcmd.Parameters.AddWithValue(
"tid"
, use_tid);
147.
sqlcmd.Parameters.AddWithValue(
"cid"
,textBox1.Text);
148.
sqlcmd.Parameters.AddWithValue(
"uid"
,
"US002"
);
149.
sqlcmd.Parameters.AddWithValue(
"patt"
, comboBox1.SelectedItem);
150.
sqlcmd.Parameters.AddWithValue(
"size"
, comboBox7.SelectedItem);
151.
sqlcmd.Parameters.AddWithValue(
"brand"
, comboBox5.SelectedItem);
152.
sqlcmd.Parameters.AddWithValue(
"com"
, comboBox6.SelectedItem);
153.
sqlcmd.Parameters.AddWithValue(
"mod"
, textBox3.Text);
154.
DateTime dget =
new
DateTime(DateTime.Now.Ticks);
155.
sqlcmd.Parameters.AddWithValue(
"gdate"
, dget);
156.
157.
int
chkins = sqlcmd.ExecuteNonQuery();
158.
if
(chkins == -1)
159.
{
160.
MessageBox.Show(
"เกิดข้อผิดพลาด"
);
161.
}
162.
else
163.
{
164.
MessageBox.Show(
"ทำการเพิ่มเรียบร้อยแล้ว"
);
165.
}
166.
167.
168.
169.
inyanglor();
170.
171.
172.
173.
}
174.
175.
private
void
inyanglor()
176.
{
177.
ds.Clear();
178.
179.
string
sqlse =
"SELECT tire_id, cus_id, patt_name, brand_name, com_name, get_date FROM TIRE_FUSE ORDER BY tire_id DESC"
;
180.
181.
sqlcmd =
new
SqlCommand(sqlse, connection);
182.
183.
da =
new
SqlDataAdapter(sqlcmd);
184.
185.
186.
ds =
new
DataSet();
187.
da.Fill(ds,
"show_check"
);
188.
189.
190.
191.
192.
dataGridView5.DataSource = ds.Tables[
"show_check"
];
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
}
214.
215.
private
void
dataGridView5_CellContentClick(
object
sender, DataGridViewCellEventArgs e)
216.
{
217.
if
(e.RowIndex == dataGridView5.RowCount - 1)
218.
{
219.
return
;
220.
}
221.
if
(e.RowIndex == -1)
222.
{
223.
return
;
224.
}
225.
226.
textBox1.Text = dataGridView5.Rows[e.RowIndex].Cells[
"cus_id"
].Value.ToString();
227.
}
228.
}
229.
}