001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.Data;
004.
using
System.Data.SqlClient;
005.
using
System.Linq;
006.
using
System.Web;
007.
using
System.Web.UI;
008.
using
System.Web.UI.WebControls;
009.
010.
namespace
Test
011.
{
012.
public
partial
class
TestEdit : System.Web.UI.Page
013.
{
014.
string
connectiondb = @
"Data Source=ARTEMIS\SQL2014;Initial Catalog=SvlITDB;User ID=it;Password=Tigers1234;"
;
015.
protected
void
Page_Load(
object
sender, EventArgs e)
016.
{
017.
018.
DateTime daValues = DateTime.Now;
019.
string
MyDt = daValues.ToString(
"dd-MM-yyyy HH:mm"
);
020.
TextBox3.Text = DateTime.Now.ToString(MyDt);
021.
022.
023.
024.
TextBox1.Text = Request.QueryString[
"CaseKey"
];
025.
TextBox2.Text = Request.QueryString[
"CaseCode"
];
026.
027.
028.
029.
using
(SqlConnection sqlcon =
new
SqlConnection(connectiondb))
030.
{
031.
sqlcon.Open();
032.
SqlDataAdapter sqlda =
new
SqlDataAdapter(
"SELECT LFET.CaseKey, LFET.CaseCode, ItCase.StaffName, ItCase.Solve, ItCase.Dates, ItCase.ExpectedDT, ItCase.DateHope FROM [Case] AS LFET INNER JOIN ItCase ON LFET.CaseKey = ItCase.CaseKey Order By ItCase.CaseKey DESC"
, sqlcon);
033.
DataTable aaa =
new
DataTable();
034.
sqlda.Fill(aaa);
035.
GridView1.DataSource = aaa;
036.
GridView1.DataBind();
037.
}
038.
039.
040.
}
041.
042.
#region Button1_Click
043.
protected
void
Button1_Click(
object
sender, EventArgs e)
044.
{
045.
046.
047.
if
(DropDownList4.Text ==
"0"
)
048.
{
049.
050.
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"Myscript"
,
"alert('กรุณากรอกข้อมุลให้ครบ')"
,
true
);
051.
}
052.
else
if
(DropDownList1.Text ==
"กำลังดำเนินการ"
)
053.
{
054.
055.
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"Myscript"
,
"alert('กรุณากรอกข้อมุลให้ครบ')"
,
true
);
056.
057.
058.
}
059.
060.
061.
else
if
(DropDownList5.Text ==
"0"
)
062.
{
063.
064.
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"Myscript"
,
"alert('กรุณากรอกข้อมุลให้ครบ')"
,
true
);
065.
066.
067.
}
068.
else
if
(Request.Form[
"Message"
] ==
null
)
069.
{
070.
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"Myscript"
,
"alert('กรุณากรอกข้อมุลให้ครบ')"
,
true
);
071.
}
072.
073.
else
074.
{
075.
SqlConnection conn =
new
SqlConnection(
"Data Source=ARTEMIS\\SQL2014;Initial Catalog=SvlITDB;User ID=it;Password=Tigers1234"
);
076.
conn.Open();
077.
SqlCommand sqlcom = conn.CreateCommand();
078.
SqlCommand sqlcom2 = conn.CreateCommand();
079.
sqlcom.CommandText =
"INSERT INTO [dbo].[ItCase] ([CaseKey], [Solve], [StaffName], [ExpectedDT], [CaseCode],[Dates],[DateHope]) VALUES ('"
+ TextBox1.Text +
"','"
+ Request.Form[
"Message"
].ToString() +
"', '"
+ DropDownList1.Text +
"', '"
+TextBox8.Text+
"','"
+TextBox2.Text+
"','"
+TextBox3.Text+
"','"
+DropDownList5.Text+
"')"
;
080.
sqlcom2.CommandText =
"Update [Case] set CaseStatusKey = '"
+ DropDownList4.Text +
"' where CaseKey = '"
+ TextBox1.Text +
"'"
;
081.
082.
083.
084.
sqlcom.CommandType = CommandType.Text;
085.
sqlcom2.CommandType = CommandType.Text;
086.
sqlcom2.ExecuteNonQuery();
087.
sqlcom.ExecuteNonQuery();
088.
conn.Close();
089.
090.
string
scriptText =
"alert('แก้ไขการแจ้งปัญหาสำเร็จ'); window.location='"
+ Request.ApplicationPath +
"TestEdit.aspx'"
;
091.
ScriptManager.RegisterStartupScript(
this
,
this
.GetType(),
"alertMessage"
, scriptText,
true
);
092.
}
093.
}
094.
095.
#endregion
096.
protected
void
Button2_Click(
object
sender, EventArgs e)
097.
{
098.
if
(DropDownList4.Text ==
"0"
)
099.
{
100.
101.
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"Myscript"
,
"alert('กรุณากรอกข้อมุลให้ครบ')"
,
true
);
102.
}
103.
else
if
(DropDownList1.Text ==
"กำลังดำเนินการ"
)
104.
{
105.
106.
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"Myscript"
,
"alert('กรุณากรอกข้อมุลให้ครบ')"
,
true
);
107.
108.
109.
}
110.
111.
112.
else
if
(DropDownList5.Text ==
"0"
)
113.
{
114.
115.
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"Myscript"
,
"alert('กรุณากรอกข้อมุลให้ครบ')"
,
true
);
116.
117.
118.
}
119.
else
if
(Request.Form[
"Message"
] ==
null
)
120.
{
121.
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"Myscript"
,
"alert('กรุณากรอกข้อมุลให้ครบ')"
,
true
);
122.
}
123.
else
if
(TextBox1.Text !=
""
)
124.
{
125.
SqlConnection conn =
new
SqlConnection(
"Data Source=ARTEMIS\\SQL2014;Initial Catalog=SvlITDB;User ID=it;Password=Tigers1234"
);
126.
conn.Open();
127.
SqlCommand sqlcom = conn.CreateCommand();
128.
SqlCommand sqlcom2 = conn.CreateCommand();
129.
130.
sqlcom.CommandText =
"Update [dbo].[ItCase] set Solve = '"
+ Request.Form[
"Message"
] +
"', StaffName = '"
+ DropDownList1.Text +
"', ExpectedDT = '"
+ TextBox8.Text +
"', DateHope = '"
+ DropDownList5.Text +
"' WHERE CaseKey='"
+ TextBox1.Text +
"'"
;
131.
sqlcom2.CommandText =
"Update [Case] set CaseStatusKey = '"
+ DropDownList4.Text +
"' where CaseKey = '"
+ TextBox1.Text +
"'"
;
132.
133.
sqlcom.CommandType = CommandType.Text;
134.
sqlcom.ExecuteNonQuery();
135.
sqlcom2.CommandType = CommandType.Text;
136.
sqlcom2.ExecuteNonQuery();
137.
conn.Close();
138.
string
scriptText =
"alert('แก้ไขการแจ้งปัญหาสำเร็จ'); window.location='"
+ Request.ApplicationPath +
"TestEdit.aspx'"
;
139.
ScriptManager.RegisterStartupScript(
this
,
this
.GetType(),
"alertMessage"
, scriptText,
true
);
140.
}
141.
}
142.
143.
144.
protected
void
GridView1_SelectedIndexChanged1(
object
sender, EventArgs e)
145.
{
146.
Response.RedirectPermanent(
"~/ShowIT.aspx"
);
147.
}
148.
}
149.
}