-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbetGroupReport.aspx.cs
226 lines (191 loc) · 9.71 KB
/
AbetGroupReport.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
using System;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Collections.Generic;
public partial class AbetGroupReport : System.Web.UI.Page
{
DataTable dtPersonValuation,dtGroup,dtResult;
SqlDataReader drValuation,drGroup,drResult;
protected void Page_Load(object sender, EventArgs e)
{
SetFocus(txtYear);
imgbExport.Visible = false;
lblDL.Visible = false;
//********************
string CountPersonID = "";
CountPersonID = DB.ExecuteScalar("select count(PersonID) from Person").ToString();
//********************
SqlDataReader drPersonID;
drPersonID = DB.ExecuteReader("select PersonID from Person");
GridView2.DataSource = drPersonID;
GridView2.DataBind();
//********************
dtPersonValuation = new DataTable("tblPerson");
DataColumn dcPersonMelliCode = new DataColumn();
dcPersonMelliCode.DataType = typeof(String);
dcPersonMelliCode.ColumnName = "PersonMelliCode";
DataColumn dcPersonName = new DataColumn();
dcPersonName.DataType = typeof(String);
dcPersonName.ColumnName = "PersonName";
DataColumn dcPersonFamily = new DataColumn();
dcPersonFamily.DataType = typeof(String);
dcPersonFamily.ColumnName = "PersonFamily";
DataColumn dcValuationYear = new DataColumn();
dcValuationYear.DataType = typeof(String);
dcValuationYear.ColumnName = "ValuationYear";
DataColumn dcValuationGrade = new DataColumn();
dcValuationGrade.DataType = typeof(String);
dcValuationGrade.ColumnName = "ValuationGrade";
dtPersonValuation.Columns.Add(dcPersonMelliCode);
dtPersonValuation.Columns.Add(dcPersonName);
dtPersonValuation.Columns.Add(dcPersonFamily);
dtPersonValuation.Columns.Add(dcValuationYear);
dtPersonValuation.Columns.Add(dcValuationGrade);
//**********************************************
dtGroup = new DataTable("tblGroup");
DataColumn dcGMelliCode = new DataColumn();
dcGMelliCode.DataType = typeof(String);
dcGMelliCode.ColumnName = "MelliCode";
DataColumn dcGName = new DataColumn();
dcGName.DataType = typeof(String);
dcGName.ColumnName = "Name";
DataColumn dGFamily = new DataColumn();
dGFamily.DataType = typeof(String);
dGFamily.ColumnName = "Family";
DataColumn dcGDate = new DataColumn();
dcGDate.DataType = typeof(String);
dcGDate.ColumnName = "GroupDate";
DataColumn dGGrade = new DataColumn();
dGGrade.DataType = typeof(String);
dGGrade.ColumnName = "GroupGrade";
dtGroup.Columns.Add(dcGMelliCode);
dtGroup.Columns.Add(dcGName);
dtGroup.Columns.Add(dGFamily);
dtGroup.Columns.Add(dcGDate);
dtGroup.Columns.Add(dGGrade);
//*********************************************
}
protected void imgbHome_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("Home.aspx");
}
protected void imgbExit_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("ValuationReport.aspx");
}
protected void btnSearch_Click(object sender, EventArgs e)
{
imgbExport.Visible = true;
lblDL.Visible = true;
foreach (GridViewRow row2 in GridView2.Rows)
{
string CountID = "";
Dictionary<string, object> paramID = new Dictionary<string, object>();
paramID.Add("@Year", txtYear.Text);
paramID.Add("@Count", txtCount.Text);
paramID.Add("@Grade", txtGrade.Text);
paramID.Add("@PersonID", row2.Cells[0].Text);
//**********
CountID = DB.ExecuteScalar("SELECT count(*) FROM Valuation,Person WHERE ((Valuation.Year <= @Year) AND (Valuation.Year > ((@Year )-(@Count+0)))) AND (Valuation.PersonID=Person.PersonID) AND (Valuation.PersonID=@PersonID) AND (Valuation.Grade>=@Grade) ", paramID).ToString();
if (CountID == txtCount.Text)
{
//*********************Show Valuations on GridView1
drValuation = DB.ExecuteReader("SELECT Valuation.PersonID, Valuation.Year, Valuation.Grade, Person.Name, Person.Family, Person.MelliCode FROM Valuation,Person WHERE ((Valuation.Year <= @Year) AND (Valuation.Year > ((@Year )-(@Count+0)))) AND (Valuation.PersonID=Person.PersonID) AND (Valuation.PersonID=@PersonID) AND (Valuation.Grade>=@Grade) ORDER BY Valuation.Year ", paramID);
while (drValuation.Read()) dtPersonValuation.Rows.Add(drValuation["MelliCode"].ToString(), drValuation["Name"].ToString(), drValuation["Family"].ToString(), drValuation["Year"].ToString(), drValuation["Grade"].ToString());
GridView1.DataSource = dtPersonValuation.DefaultView;
GridView1.DataBind();
//********************Show * Groups on GridView3
drGroup = DB.ExecuteReader("select ClassDate,ClassGrade,Person.Name, Person.Family, Person.MelliCode from Groupe,Person where (Groupe.PersonID=@PersonID) AND (Groupe.PersonID=Person.PersonID) and (Groupe.ClassGrade='*' or Groupe.ClassGrade='**' or Groupe.ClassGrade='***')", paramID);
while (drGroup.Read()) dtGroup.Rows.Add(drGroup["MelliCode"].ToString(), drGroup["Name"].ToString(), drGroup["Family"].ToString(), drGroup["ClassDate"].ToString(), drGroup["ClassGrade"].ToString());
GridView3.DataSource = dtGroup.DefaultView;
GridView3.DataBind();
}
}
foreach (GridViewRow row3 in GridView3.Rows)
{
string r0 = "";
r0 = row3.Cells[3].Text + "";
int countResult1 = 0;
int countResult2 = 0;
string r1 = "";
r1 =row3.Cells[0].Text + "";
//********************************************
foreach (GridViewRow row1 in GridView1.Rows)
{
if (row1.Cells[0].Text == r1)
{
if (row1.Cells[3].Text != r0)
{
countResult1++;
if (countResult1 == int.Parse(txtCount.Text))
{
//********************Show Result on GridView4
Dictionary<string, object> paramM = new Dictionary<string, object>();
paramM.Add("@MCode", r1);
drResult = DB.ExecuteReader("select Name AS [نام],Family AS [نام خانوادگی],MelliCode AS[کدملی],CaseNumber AS [شماره پرونده],PersonelNumber AS [شماره کارمندی] from Person where MelliCode=@MCode", paramM);
GridView4.DataSource = drResult;
GridView4.DataBind();
}
}
}
else
{
countResult2++;
if (countResult2 == int.Parse(txtCount.Text))
{
//********************Show Result on GridView4
Dictionary<string, object> paramM = new Dictionary<string, object>();
paramM.Add("@MCode", row1.Cells[0].Text);
drResult = DB.ExecuteReader("select Name AS [نام],Family AS [نام خانوادگی],MelliCode AS[کدملی],CaseNumber AS [شماره پرونده],PersonelNumber AS [شماره کارمندی] from Person where MelliCode=@MCode", paramM);
GridView4.DataSource = drResult;
GridView4.DataBind();
}
}
}
}
}
public override void VerifyRenderingInServerForm(Control control)
{
//required to avoid the runtime error "
//Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
}
private void ExportGridToExcel()
{
Response.Clear();
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = "";
string FileName = "List" + DateTime.Now + ".xls";
StringWriter strwritter = new StringWriter();
HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
GridView4.GridLines = GridLines.Both;
GridView4.HeaderStyle.Font.Bold = true;
GridView4.RenderControl(htmltextwrtter);
Response.Write(strwritter.ToString());
Response.End();
}
protected void imgbExport_Click(object sender, ImageClickEventArgs e)
{
ExportGridToExcel();
}
protected void btnNew_Click(object sender, System.EventArgs e)
{
Response.Redirect("AbetGroupReport.aspx");
}
}