-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddFaculty.cs
151 lines (140 loc) · 5.01 KB
/
AddFaculty.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.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Text.RegularExpressions;
namespace QuestionPaper_Genration
{
public partial class AddFaculty : Form
{
public AddFaculty()
{
InitializeComponent();
}
private void AddFaculty_Load(object sender, EventArgs e)
{
try
{
DtConnection.Con.Close();
SqlCommand cmd = new SqlCommand("select SubId, SubName from dbo.Subject_Master", DtConnection.Con);
DtConnection.Con.Open();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
DataRow row = dt.NewRow();
row["SubId"] = 0;
row["SubName"] = "--Select Subject--";
dt.Rows.InsertAt(row, 0);
ddlsubject.DataSource = dt;
ddlsubject.ValueMember = "SubId";
ddlsubject.DisplayMember = "SubName";
DtConnection.Con.Close();
}
catch (Exception)
{
throw;
}
}
private void btnsave_Click(object sender, EventArgs e)
{
try
{
if (txtfacultyname.Text == "")
{
MessageBox.Show("Enter Faculty Name.");
return;
}
if (txtphoneno.Text == "")
{
MessageBox.Show("Enter Your Phoneno.");
return;
}
if (txtemailid.Text == "")
{
MessageBox.Show("Enter your EmailId.");
return;
}
if (txtpassword.Text == "")
{
MessageBox.Show("Enter your Password.");
return;
}
SqlCommand cmd = new SqlCommand("Insert into Faculty_Master(FacultyName, PhoneNo, EmailId, SubId,Password) values(@FacultyName, @PhoneNo, @EmailId, @SubId,@Password)", DtConnection.Con);
DtConnection.Con.Open();
cmd.Parameters.AddWithValue("@FacultyName", txtfacultyname.Text.ToString().Trim());
cmd.Parameters.AddWithValue("@SubId", ddlsubject.SelectedValue);
cmd.Parameters.AddWithValue("@EmailId", txtemailid.Text.ToString().Trim());
cmd.Parameters.AddWithValue("@PhoneNo", txtphoneno.Text.ToString().Trim());
cmd.Parameters.AddWithValue("@Password", txtpassword.Text.ToString().Trim());
cmd.ExecuteNonQuery();
txtphoneno.Text = "";
txtfacultyname.Text = "";
txtemailid.Text = "";
txtpassword.Text = "";
DtConnection.Con.Close();
MessageBox.Show("Data Inserted Successfully.");
}
catch (Exception)
{
throw;
}
}
private void btncancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtphoneno_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsDigit(e.KeyChar) || (e.KeyChar == (char)Keys.Back)))
e.Handled = true;
}
private void txtemailid_Validating(object sender, CancelEventArgs e)
{
if (!isEmail(txtemailid.Text))
{
MessageBox.Show("EmailID Invalid.");
txtemailid.Focus();
return;
}
}
public static bool isEmail(string inputEmail)
{
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return (true);
else
return (false);
}
public static bool isPhone(string inputphone)
{
Regex re = new Regex(@"^(\([0-9]{3}\)|[0-9]{3}-)[0-9]{3}-[0-9]{4}|(\([0-9]{3}\)|[0-9]{3})[0-9]{3}[0-9]{4}$");
if (re.IsMatch(inputphone))
{
return true;
}
else
{
return false;
}
}
private void txtphoneno_Validating(object sender, CancelEventArgs e)
{
if (!isPhone(txtphoneno.Text))
{
MessageBox.Show("Invalid Phone Number.");
txtphoneno.Focus();
return;
}
}
}
}