-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathStudent_Entry_Record.cs
258 lines (176 loc) · 7.6 KB
/
Student_Entry_Record.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using Excel = Microsoft.Office.Interop.Excel;
using System.IO;
namespace MultiFaceRec
{
public partial class Student_Entry_Record : Form
{
ConnectionString cs = new ConnectionString();
CommonClasses cc = new CommonClasses();
public Student_Entry_Record()
{
InitializeComponent();
}
public void GetData()
{
try
{
cc.con = new SqlConnection(cs.DBConn);
cc.con.Open();
cc.cmd = new SqlCommand("SELECT RTRIM(C_ID) as [ID],RTRIM(StudentID) as [Student ID],RTRIM(Name) as [Student Name],RTRIM(Year) as [Year],RTRIM(Term) as [Term],RTRIM(Subject) as [Contact No.],RTRIM(PresentAbsent) as [PresentAbsent],Photo from Student order by name", cc.con);
cc.da = new SqlDataAdapter(cc.cmd);
cc.ds = new DataSet();
cc.da.Fill(cc.ds, "Student");
dgw.DataSource = cc.ds.Tables["Student"].DefaultView;
cc.con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void txtGuestName_TextChanged(object sender, EventArgs e)
{
try
{
cc.con = new SqlConnection(cs.DBConn);
cc.con.Open();
cc.cmd = new SqlCommand("SELECT RTRIM(C_ID) as [ID],RTRIM(StudentID) as [Student ID],RTRIM(Name) as [Student Name],RTRIM(Year) as [Year],RTRIM(Term) as [Term],RTRIM(Subject) as [Contact No.],RTRIM(PresentAbsent) as [PresentAbsent],Photo from Student WHERE name like '" + txtStudentName.Text + "%' order by name", cc.con);
cc.da = new SqlDataAdapter(cc.cmd);
cc.ds = new DataSet();
cc.da.Fill(cc.ds, "Student");
dgw.DataSource = cc.ds.Tables["Student"].DefaultView;
cc.con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public void Reset()
{
txtStudentName.Text = "";
GetData();
}
private void btnReset_Click(object sender, EventArgs e)
{
Reset();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void dgw_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
string strRowNumber = (e.RowIndex + 1).ToString();
SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);
if (dgw.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
{
dgw.RowHeadersWidth = Convert.ToInt32((size.Width + 20));
}
Brush b = SystemBrushes.ControlText;
e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
}
private void dgw_MouseClick(object sender, MouseEventArgs e)
{
try
{
if (lblOperation.Text == "Student Master")
{
DataGridViewRow dr = dgw.SelectedRows[0];
this.Hide();
Student_Entry frm = new Student_Entry();
frm.Show();
frm.txtID.Text = dr.Cells[0].Value.ToString();
frm.txtStudentID.Text = dr.Cells[1].Value.ToString();
frm.txtStudentName.Text = dr.Cells[2].Value.ToString();
frm.txtYear.Text = dr.Cells[3].Value.ToString();
frm.txtTerm.Text = dr.Cells[4].Value.ToString();
frm.txtSubject.Text = dr.Cells[5].Value.ToString();
frm.txtPresentAbsent.Text = dr.Cells[6].Value.ToString();
byte[] data = (byte[])dr.Cells[7].Value;
MemoryStream ms = new MemoryStream(data);
frm.Picture.Image = Image.FromStream(ms);
frm.btnUpdate.Enabled = true;
//frm.btnDelete.Enabled = true;
//frm.btnSave.Enabled = false;
frm.lblUser.Text = lblUser.Text;
lblOperation.Text = "";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void frmStudentRecord_Load(object sender, EventArgs e)
{
GetData();
}
private void ExelBackUp_Click(object sender, EventArgs e)
{
SqlConnection cnn ;
string connectionString = null;
string sql = null;
string data = null;
int i = 0;
int j = 0;
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
// connectionString = "data source=servername;initial catalog=databasename;user id=username;password=password;";
connectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\EDUCATION\THEIRD YEAR\3rd year 2nd term\LAB\CSE-Web Programming Project-3200\FaceRecProOV (1)\FaceRecProOV\FaceRecProOV\FaceRecProOV\Attendance.mdf;Integrated Security=True";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "SELECT * FROM Student ";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
DataSet ds = new DataSet();
dscmd.Fill(ds);
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
for (j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
{
data = ds.Tables[0].Rows[i].ItemArray[j].ToString();
xlWorkSheet.Cells[i + 1, j + 1] = data;
}
}
xlWorkBook.SaveAs("KHULNA-UNIVERSITY-CLASS-ATTENDANCE.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
MessageBox.Show("Excel file created , you can find the file c:\\KHULNA-UNIVERSITY-CLASS-ATTENDANCE");
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
}
finally
{
GC.Collect();
}
}
}
}