forked from EsaSalmik/IIO13200-OHJELMOINTIKOE
/
G2559_T3B_muokkaus.aspx.cs
178 lines (149 loc) · 5.2 KB
/
G2559_T3B_muokkaus.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class G2559_T3B_muokkaus : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataTable dt;
//dt = new DataTable();
ds.ReadXml(MapPath(ConfigurationManager.AppSettings["LogFilePath3"]));
dt = ds.Tables[0];
//kytketään kontrolliin
//GridView1.DataSource = ds; //toimii jos yksi taulu
grdtunnit.DataSource = dt;
grdtunnit.DataBind();
Label1.Text = "Tallennettu: " + grdtunnit.Rows.Count.ToString() + " tuntia";
if (!IsPostBack)
{
BindGrid();
ClearScreen();
DataTable ddt;
ddt = dt.DefaultView.ToTable(true, "koodaaja");
DataRow row2 = ddt.NewRow();
row2["koodaaja"] = "Kaikki";
ddt.Rows.InsertAt(row2, 0);
DataRow row = ddt.NewRow();
row["koodaaja"] = "-- Valitse --";
ddt.Rows.InsertAt(row, 0);
DropDownTyypit.DataSource = ddt.DefaultView;
DropDownTyypit.DataTextField = "koodaaja";
DropDownTyypit.DataBind();
}
}
private void BindGrid()
{
TunnitDAL objTuntiDAL = new TunnitDAL();
grdtunnit.DataSource = objTuntiDAL.GetAll();
grdtunnit.DataBind();
}
protected void grdViewTunti_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Attributes.Add("onclick", "return confirm('Are you sure want to delete?')");
}
}
protected void grdViewTunti_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdtunnit.PageIndex = e.NewPageIndex;
grdtunnit.SelectedIndex = -1;
BindGrid();
}
protected void grdViewTunti_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
hndId.Value = grdtunnit.Rows[e.NewSelectedIndex].Cells[2].Text.Trim();
if (hndId.Value.Length > 0)
{
TunnitDAL objTuntiDAL = new TunnitDAL();
BLTunnit tunti = objTuntiDAL.Get(hndId.Value);
txtkoodaaja.Text = tunti.koodaaja;
txtpvm.Text = tunti.paivamaara;
txttuntimaara.Text = tunti.tuntimaara;
txtminuutit.Text = tunti.minuutit;
lblMessage.Text = "";
}
}
protected void grdViewTunti_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
string strId = grdtunnit.Rows[e.RowIndex].Cells[2].Text.Trim();
if (strId.Length > 0)
{
TunnitDAL objTuntiDAL = new TunnitDAL();
objTuntiDAL.Delete(strId);
ClearScreen();
BindGrid();
lblMessage.Text = "Record deleted successfully";
}
}
catch (Exception ex)
{
lblMessage.Text = "There is an error occured while processing the request. Please verify the code!";
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
if (!Page.IsValid) return;
BLTunnit tunti = new BLTunnit();
tunti.koodaaja = txtkoodaaja.Text;
tunti.paivamaara = txtpvm.Text;
tunti.tuntimaara = txttuntimaara.Text;
tunti.minuutit = txtminuutit.Text;
tunti.id = Convert.ToInt64(hndId.Value);
TunnitDAL objTuntiDAL = new TunnitDAL();
if ((hndId.Value.Trim().Length > 0) &&
(Convert.ToInt64(hndId.Value) > 0))
objTuntiDAL.Update(tunti);
else
objTuntiDAL.Create(tunti);
ClearScreen();
BindGrid();
lblMessage.Text = "Record saved successfully";
}
catch (Exception ex)
{
lblMessage.Text = "There is an error occured while processing the request. Please verify the code!";
}
}
protected void btnClear_Click(object sender, EventArgs e)
{
ClearScreen();
}
private void ClearScreen()
{
txtid.Text = "tunti Generated";
txtkoodaaja.Text = "";
txtpvm.Text = "";
txttuntimaara.Text = "";
txtminuutit.Text = "";
hndId.Value = "0";
}
protected void DropDownTyypit_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownTyypit.SelectedValue == "-- Valitse --")
{
return;
}
DataTable dt;
DataSet ds = new DataSet();
ds.ReadXml(MapPath(ConfigurationManager.AppSettings["LogFilePath3"]));
dt = ds.Tables[0];
DataView dv = dt.DefaultView;
if (DropDownTyypit.SelectedValue != "Kaikki")
{
dv.RowFilter = string.Format("koodaaja like '%{0}%'", DropDownTyypit.SelectedValue);
}
grdtunnit.DataSource = dv;
grdtunnit.DataBind();
}
}