-
Notifications
You must be signed in to change notification settings - Fork 0
/
Year1.cs
151 lines (137 loc) · 6.46 KB
/
Year1.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using MySql.Data.MySqlClient;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Text.RegularExpressions;
namespace SEGP
{
public partial class Year1 : DevExpress.XtraEditors.XtraUserControl
{
String oldUob, oldname;
ContextMenu contextmenu = new ContextMenu();
MenuItem menuMail = new MenuItem("Mail");
MenuItem menuPDF = new MenuItem("Generate PDF");
MenuItem menudelete = new MenuItem("Delete Data");
MenuItem menuedit = new MenuItem("Save Data");
static String connectionString = "Server=localhost; Database=segp; Uid=root; pwd=";
MySqlConnection conn = new MySqlConnection(connectionString);
String ss = "select UoB,Name,FatherName,Programme,EmailAddress,Contact,PAT,Image from Students where Year='Year-1'";
public Year1()
{
InitializeComponent();
contextmenu.MenuItems.AddRange(new MenuItem[] { menuMail, menudelete, menuedit ,menuPDF});
gggcy1.ContextMenu = contextmenu;
menudelete.Click += new System.EventHandler(this.menudeleteClick);
menuedit.Click += new System.EventHandler(this.menueditClick);
menuPDF.Click += new System.EventHandler(this.menuPDFClick);
menuMail.Click += new System.EventHandler(this.menuMailClick);
}
private void menuMailClick(object sender, System.EventArgs e)
{
MailGoogle m = new MailGoogle();
System.Data.DataRow row = layoutView1.GetDataRow(layoutView1.FocusedRowHandle);
String tomail = row[4].ToString();
m.Totxt.Text = tomail;
m.Show();
}
private void menudeleteClick(object sender, System.EventArgs e)
{
System.Data.DataRow row = layoutView1.GetDataRow(layoutView1.FocusedRowHandle);
String Uob = row[0].ToString();
DataOperations d = new DataOperations();
d.deleterow(Uob);
layoutView1.DeleteRow(layoutView1.FocusedRowHandle);
}
private void menuPDFClick(object sender, System.EventArgs e)
{
Document doc = new Document(iTextSharp.text.PageSize.LETTER,10,10,42,35);
PdfWriter writer = PdfWriter.GetInstance(doc,new FileStream("Year1.pdf",FileMode.Create));
doc.Open();
PdfPTable table = new PdfPTable(dataGridView1.Columns.Count);
PdfPCell cell = new PdfPCell(new Phrase("Year-1", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLUE)));
cell.Colspan = 8;
cell.BackgroundColor = new iTextSharp.text.BaseColor(Color.Coral);
cell.HorizontalAlignment = 1;
table.AddCell(cell);
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
table.AddCell(new Phrase(dataGridView1.Columns[i].HeaderText, new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 7f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.GRAY)));
}
table.HeaderRows = 1 ;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
if (dataGridView1[j, i].Value != null)
{
table.AddCell(new Phrase(dataGridView1[j, i].Value.ToString(), new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 6f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLUE)));
}
}
}
doc.Add(table);
doc.Close();
}
private void menueditClick(object sender, System.EventArgs e)
{
System.Data.DataRow row = layoutView1.GetDataRow(layoutView1.FocusedRowHandle);
String Uob = row[0].ToString();
String Name = row[1].ToString();
String FName = row[2].ToString();
String Programme = row[3].ToString();
String Email = row[4].ToString();
String Contact = row[5].ToString();
String PAT = row[6].ToString();
var validatorUoB = new Regex("^1[0-9]{7}$");
var validatorEmail = new Regex("^([a-z]+[0-9]+[@]{1}namal.edu.pk)$");
var validatorContact = new Regex("^[0-9]{4}-[0-9]{7}$");
var validatorName = new Regex("^[a-zA-Z\\s]+$");
if (validatorUoB.IsMatch(Uob) && validatorName.IsMatch(Name) && validatorName.IsMatch(FName) && validatorName.IsMatch(Programme) && validatorEmail.IsMatch(Email) && validatorContact.IsMatch(Contact) && validatorName.IsMatch(PAT))
{
DataOperations d = new DataOperations();
d.edit(Uob, Name, FName, Programme, Email, Contact, PAT, oldUob, oldname);
}
else
{
MessageBox.Show("Your Input Is Not Correct");
}
}
private void Year1_Load(object sender, EventArgs e)
{
try
{
MySqlDataAdapter dataadapter = new MySqlDataAdapter(ss, conn);
MySqlCommandBuilder mscb = new MySqlCommandBuilder(dataadapter);
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataadapter.Fill(table);
BindingSource bindingSource1 = new BindingSource();
bindingSource1.DataSource = table;
gggcy1.DataSource = bindingSource1;
dataGridView1.DataSource = bindingSource1;
}
catch (Exception a)
{
MessageBox.Show("Something is Wrong"+a.ToString());
}
}
private void layoutView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
System.Data.DataRow row = layoutView1.GetDataRow(layoutView1.FocusedRowHandle);
oldUob = row[0].ToString();
oldname = row[1].ToString();
contextmenu.Show(gggcy1, new Point(e.X, e.Y));
}
}
}
}