001.
<script runat=
"server"
>
002.
003.
String strConnString = WebConfigurationManager.ConnectionStrings[
"MDSConnectionString"
].ConnectionString;
004.
005.
protected
void
Page_Load(
object
sender, EventArgs e)
006.
{
007.
if
(Session[
"strUser"
] ==
null
)
008.
{
009.
Response.Redirect(
"~/index.aspx"
);
010.
Response.End();
011.
}
012.
else
if
(!IsPostBack)
013.
{
014.
lblIDser.Text = Request.QueryString[
"id_nob"
];
015.
BindContrydropdown1();
016.
BindContrydropdown2();
017.
BindData();
018.
this
.btnOK = btnOK;
019.
}
020.
}
021.
022.
protected
void
BindContrydropdown1()
023.
{
024.
using
(SqlConnection con =
new
SqlConnection(strConnString))
025.
{
026.
con.Open();
027.
028.
SqlCommand cmd =
new
SqlCommand(
"Select id_itemtype,itemtype FROM dbo.tbl_itemtype WHERE archive_date IS NULL"
, con);
029.
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
030.
DataSet ds =
new
DataSet();
031.
da.Fill(ds);
032.
033.
ddlDep.DataSource = ds;
034.
ddlDep.DataTextField =
"itemtype"
;
035.
ddlDep.DataValueField =
"id_itemtype"
;
036.
ddlDep.DataBind();
037.
con.Close();
038.
}
039.
}
040.
041.
protected
void
BindContrydropdown2()
042.
{
043.
using
(SqlConnection con =
new
SqlConnection(strConnString))
044.
{
045.
con.Open();
046.
string
sqlStatement =
"SELECT id_item + ' / ' + item AS item, id_item FROM dbo.tbl_item WHERE archive_date IS NULL"
;
047.
SqlCommand cmd =
new
SqlCommand(sqlStatement, con);
048.
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
049.
DataSet ds =
new
DataSet();
050.
da.Fill(ds);
051.
052.
ddlMachine.DataSource = ds;
053.
ddlMachine.DataTextField =
"item"
;
054.
ddlMachine.DataValueField =
"id_item"
;
055.
ddlMachine.DataBind();
056.
con.Close();
057.
}
058.
}
059.
060.
protected
void
BindData()
061.
{
062.
DataTable dt =
new
DataTable();
063.
SqlConnection con =
new
SqlConnection(strConnString);
064.
con.Open();
065.
SqlCommand cmd =
new
SqlCommand(
"SELECT dt_to,id_cu,id_item,txt,dt_sa,ti_sa from dbo.tbl_blue WHERE id_nob = '"
+ lblIDser.Text +
"'"
, con);
066.
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
067.
068.
da.Fill(dt);
069.
if
(dt.Rows.Count > 0)
070.
{
071.
lblDate.Text = dt.Rows[0][
"dt_to"
].ToString();
072.
lblDate.Text = dt.Rows[0].Field<DateTime>(0).ToString(
"yyyy-MM-dd"
);
073.
txtSerList.Text = dt.Rows[0][
"txt"
].ToString();
074.
ddlDep.SelectedValue = dt.Rows[0][
"id_cu"
].ToString();
075.
ddlMachine.SelectedValue = dt.Rows[0][
"id_item"
].ToString();
076.
txtDtsa.Text = dt.Rows[0][
"dt_sa"
].ToString();
077.
txtDtsa.Text = dt.Rows[0].Field<DateTime>(4).ToString(
"yyyy-MM-dd"
);
078.
txtTisa.Text = dt.Rows[0][
"ti_sa"
].ToString();
079.
}
080.
con.Close();
081.
}
082.
void
btnOK_Click(Object sender, EventArgs e)
083.
{
084.
085.
SqlConnection con =
new
SqlConnection(strConnString);
086.
SqlCommand cmd =
new
SqlCommand();
087.
String strSQL;
088.
089.
strSQL =
"UPDATE dbo.tbl_blue SET "
+
090.
" id_cu = '"
+ ddlDep.SelectedItem.Value +
"'"
+
091.
" ,id_item = '"
+ ddlMachine.SelectedItem.Value +
"'"
+
092.
" ,txt = '"
+ txtSerList.Text +
"'"
+
093.
" ,dt_sa = '"
+ txtDtsa.Text +
"'"
+
094.
" ,ti_sa = '"
+ txtTisa.Text +
"'"
+
095.
" WHERE id_nob = '"
+ lblIDser.Text +
"'"
;
096.
097.
Session[
"strIDser"
] = lblIDser.Text;
098.
Session[
"strDep"
] = ddlDep.SelectedItem.Text;
099.
Session[
"strMachine"
] = ddlMachine.SelectedItem.Text;
100.
Session[
"strSerlist"
] = txtSerList.Text;
101.
Session[
"strDtsa"
] = txtDtsa.Text;
102.
Session[
"strTisa"
] = txtTisa.Text;
103.
104.
con.ConnectionString = strConnString;
105.
con.Open();
106.
cmd.Connection = con;
107.
cmd.CommandText = strSQL;
108.
cmd.CommandType = CommandType.Text;
109.
110.
try
111.
{
112.
cmd.ExecuteNonQuery();
113.
Response.Redirect(
"~/service/fr_eservice2.aspx"
);
114.
115.
116.
}
117.
catch
(Exception ex)
118.
{
119.
this
.lblStatus.Visible =
true
;
120.
this
.lblStatus.Text =
"Record can not insert Error ("
+ ex.Message +
")"
;
121.
}
122.
123.
con.Close();
124.
con =
null
;
125.
126.
}
127.
128.
protected
void
btnDel_Click(
object
sender, EventArgs e)
129.
{
130.
String strSQL;
131.
strSQL =
"SELECT b.id_nob INTO #RecordsToDelete FROM dbo.tbl_blue b JOIN dbo.tbl_yellow y ON b.id_nob = y.id_noy WHERE b.id_nob = '"
+ lblIDser.Text +
"' DELETE FROM dbo.tbl_blue WHERE id_nob IN (SELECT id_nob FROM #RecordsToDelete) DELETE FROM dbo.tbl_yellow WHERE id_noy IN (SELECT id_nob FROM #RecordsToDelete)"
;
132.
SqlConnection con =
new
SqlConnection(strConnString);
133.
SqlCommand cmd =
new
SqlCommand(strSQL, con);
134.
135.
try
136.
{
137.
con.Open();
138.
cmd.ExecuteNonQuery();
139.
this
.lblStatus.Visible =
true
;
140.
this
.lblStatus.Text =
"Record deleted."
;
141.
}
142.
catch
(Exception ex)
143.
{
144.
this
.lblStatus.Visible =
true
;
145.
this
.lblStatus.Text =
"Record can not delete Error ("
+ ex.Message +
")"
;
146.
}
147.
148.
con.Close();
149.
con =
null
;
150.
}
151.
</script>