001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.ComponentModel;
004.
using
System.Data;
005.
using
System.IO;
006.
using
System.Drawing;
007.
using
System.Linq;
008.
using
System.Text;
009.
using
System.Windows.Forms;
010.
using
System.Data.SqlClient;
011.
012.
namespace
DecistionSupportApplication
013.
{
014.
public
partial
class
decistionForm : Form
015.
{
016.
public
decistionForm()
017.
{
018.
InitializeComponent();
019.
}
020.
private
void
decistionForm_Load(
object
sender, EventArgs e)
021.
{
022.
023.
}
024.
025.
private
void
exitButton_Click(
object
sender, EventArgs e)
026.
{
027.
if
(MessageBox.Show(
"คูณต้องการออกจากระบบใช่หรือไม่ ?"
,
"โปรดยืนยัน"
, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
028.
Application.Exit();
029.
}
030.
031.
private
void
seacthButton_Click(
object
sender, EventArgs e)
032.
{
033.
string
conStr = @"Data Source=ARMSPRITE-PC\SQLEXPRESS;
034.
Initial Catalog=master;
035.
Integrated Security=SSPI;";
036.
037.
SqlConnection connection =
new
SqlConnection(conStr);
038.
connection.Open();
039.
040.
string
sql =
"SELECT* FROM DecistionNotebook"
;
041.
int
nCheckCB = priceComboBox.SelectedIndex;
042.
if
(nCheckCB == -1)
043.
{
044.
MessageBox.Show(
"กรุณาเลือกราคาที่ต้องการ"
,
"เกิดข้อผิดพลาด"
, MessageBoxButtons.OK, MessageBoxIcon.Stop);
045.
return
;
046.
}
047.
switch
(priceComboBox.SelectedItem.ToString())
048.
{
049.
case
"ต่ำกว่า 10,000 บาท"
:
050.
sql +=
" WHERE price BETWEEN 0 AND 10000"
;
break
;
051.
case
"10,001 - 20,000 บาท"
:
052.
sql +=
" WHERE price BETWEEN 10001 AND 20000"
;
break
;
053.
case
"20,001 - 30,000 บาท"
:
054.
sql +=
" WHERE price BETWEEN 20001 AND 30000"
;
break
;
055.
case
"30,001 - 40,000 บาท"
:
056.
sql +=
" WHERE price BETWEEN 30001 AND 40000"
;
break
;
057.
case
"40,001 - 50,000 บาท"
:
058.
sql +=
" WHERE price BETWEEN 40001 AND 50000"
;
break
;
059.
case
"50,001 - 60,000 บาท"
:
060.
sql +=
" WHERE price BETWEEN 50001 AND 60000"
;
break
;
061.
case
"แสดงทั้งหมด"
:
062.
sql +=
" WHERE price BETWEEN 0 AND 100000 "
;
break
;
063.
}
064.
065.
int
nCheckCB2 = brandComboBox.SelectedIndex;
066.
if
(nCheckCB2 == -1)
067.
{
068.
MessageBox.Show(
"กรุณาเลือกยี่ห้อที่ต้องการ"
,
"เกิดข้อผิดพลาด"
, MessageBoxButtons.OK, MessageBoxIcon.Stop);
069.
return
;
070.
}
071.
switch
(brandComboBox.SelectedItem.ToString())
072.
{
073.
case
"Acer"
:
074.
sql +=
" AND brand = 'Acer'"
;
break
;
075.
case
"Asus"
:
076.
sql +=
" AND brand = 'Asus'"
;
break
;
077.
case
"Compaq"
:
078.
sql +=
" AND brand = 'Compaq'"
;
break
;
079.
case
"Dell"
:
080.
sql +=
" AND brand = 'Dell'"
;
break
;
081.
case
"Fujitsu"
:
082.
sql +=
" AND brand = 'Fujitsu'"
;
break
;
083.
case
"HP"
:
084.
sql +=
" AND brand = 'HP'"
;
break
;
085.
case
"Sony"
:
086.
sql +=
" AND brand = 'Sony'"
;
break
;
087.
case
"Sumsung"
:
088.
sql +=
" AND brand = 'Samsung'"
;
break
;
089.
case
"Toshiba"
:
090.
sql +=
" AND brand = 'Toshiba'"
;
break
;
091.
case
"แสดงทั้งหมด"
:
092.
sql +=
""
;
break
;
093.
}
094.
095.
if
(eVGARadioButton.Checked)
096.
{
097.
sql +=
" AND grapCard <> 'On Broad'"
;
098.
}
099.
else
if
(onBRadioButton.Checked)
100.
{
101.
sql +=
" AND grapCard = 'On Broad'"
;
102.
}
103.
104.
SqlCommand command =
new
SqlCommand(sql, connection);
105.
SqlDataAdapter adapter =
new
SqlDataAdapter(command);
106.
data =
new
DataSet();
107.
adapter.Fill(data,
"notebook"
);
108.
109.
numRows = data.Tables[
"notebook"
].Rows.Count;
110.
ShowData();
111.
connection.Close();
112.
}
113.
114.
private
DataSet data;
115.
private
int
curRow, numRows;
116.
private
void
ShowData()
117.
{
118.
DataTable DecistionNotebook = data.Tables[
"notebook"
];
119.
if
(DecistionNotebook.Rows.Count == 0)
120.
{
121.
MessageBox.Show(
"ไม่พบข้อมูลกรุณาเลือกใหม่อีกครั้ง"
,
"ขออภัย"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
122.
return
;
123.
}
124.
prodIDTextBox.Text = DecistionNotebook.Rows[curRow][
"prodID"
].ToString();
125.
brandTextBox.Text = DecistionNotebook.Rows[curRow][
"brand"
].ToString();
126.
modelTextBox.Text = DecistionNotebook.Rows[curRow][
"model"
].ToString();
127.
cpuTextBox.Text = DecistionNotebook.Rows[curRow][
"CPU"
].ToString();
128.
grapTextBox.Text = DecistionNotebook.Rows[curRow][
"grapCard"
].ToString();
129.
ramTextBox.Text = DecistionNotebook.Rows[curRow][
"RAM"
].ToString();
130.
harddiscTextBox.Text = DecistionNotebook.Rows[curRow][
"harddisk"
].ToString();
131.
priceTextBox.Text = DecistionNotebook.Rows[curRow][
"price"
].ToString();
132.
discDTextBox.Text = DecistionNotebook.Rows[curRow][
"discDrive"
].ToString();
133.
discPTextBox.Text = DecistionNotebook.Rows[curRow][
"display"
].ToString();
134.
wCamTextBox.Text = DecistionNotebook.Rows[curRow][
"web_camera"
].ToString();
135.
battTextBox.Text = DecistionNotebook.Rows[curRow][
"battery"
].ToString();
136.
wlanTextBox.Text = DecistionNotebook.Rows[curRow][
"wireless_lan"
].ToString();
137.
weightTextBox.Text = DecistionNotebook.Rows[curRow][
"weight"
].ToString();
138.
warranTextBox.Text = DecistionNotebook.Rows[curRow][
"warranty"
].ToString();
139.
usbTextBox.Text = DecistionNotebook.Rows[curRow][
"portUSB"
].ToString();
140.
141.
byte
[]pic = (
byte
[])data.Tables[
"notebook"
].Rows[0][
"img"
];
142.
MemoryStream streamPic =
new
MemoryStream(pic);
143.
picBox.Image = Bitmap.FromStream(streamPic);
144.
145.
CurRowlabel.Text =
"รายการที่ "
+ (curRow + 1) +
" จากรายการสินค้าทั้งหมด "
+ numRows +
" รายการ"
;
146.
}
147.
148.
private
void
firstButton_Click(
object
sender, EventArgs e)
149.
{
150.
curRow = 0;
151.
ShowData();
152.
}
153.
154.
private
void
backbutton_Click(
object
sender, EventArgs e)
155.
{
156.
if
(curRow > 0)
157.
{
158.
curRow -= 1;
159.
ShowData();
160.
}
161.
}
162.
163.
private
void
nextbutton_Click(
object
sender, EventArgs e)
164.
{
165.
if
(curRow < (numRows - 1))
166.
{
167.
curRow += 1;
168.
ShowData();
169.
}
170.
}
171.
172.
private
void
lastButton_Click(
object
sender, EventArgs e)
173.
{
174.
curRow = numRows - 1;
175.
ShowData();
176.
}
177.
}
178.
}