-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFurnitureDB.cs
210 lines (189 loc) · 5.83 KB
/
FurnitureDB.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Text.RegularExpressions;
namespace Furniture_System
{
class FurnitureDB
{
private static Random random = new Random();
private string rstr;
private double rdou;
private bool rboo;
private int i;
private DateTime? dt;
private SqlConnection con;
private SqlCommand cmd;
private SqlDataAdapter da;
private SqlDataReader dr;
public FurnitureDB()
{
con = new SqlConnection("Data Source=PaSaN;Initial Catalog=FurnitureDB;Integrated Security=True");
}
public void OpenCon()
{
con.Open();
}
public void CloseCon()
{
con.Close();
}
public int Insert_Update_Delete(string q)
{
OpenCon();
cmd = new SqlCommand(q, con);
i = cmd.ExecuteNonQuery();
CloseCon();
return i;
}
public bool readData(string q)
{
OpenCon();
cmd = new SqlCommand(q, con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
rboo = true;
}
else
{
rboo = false;
}
CloseCon();
return rboo;
}
public double readData(string q, string a)
{
OpenCon();
cmd = new SqlCommand(q, con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
rdou = Convert.ToDouble(dr[a]);
}
else
rdou = 0;
dr.Close();
CloseCon();
return rdou;
} //new
public string readData(string q, string a, string b)
{
OpenCon();
cmd = new SqlCommand(q, con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
rstr = Convert.ToString((dr[a]));
}
else
rstr = null;
dr.Close();
CloseCon();
return rstr;
}
public DataTable getData(string q)
{
OpenCon();
da = new SqlDataAdapter(q, con);
DataTable dt = new DataTable();
da.Fill(dt);
CloseCon();
return dt;
}
public DataSet getValue(string q)
{
OpenCon();
DataSet ds = new DataSet();
da = new SqlDataAdapter(q, con);
da.Fill(ds);
CloseCon();
return ds;
}
public int delData(string q,string w,string e)
{
cmd = new SqlCommand(q, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(w, e);
OpenCon();
cmd.ExecuteNonQuery();
i = cmd.ExecuteNonQuery();
CloseCon();
return i;
}
public DateTime? getDate(string q)
{
OpenCon();
cmd = new SqlCommand(q, con);
dr = cmd.ExecuteReader();
if (dr.Read())
dt = Convert.ToDateTime(dr[0]);
else
dt = null;
CloseCon();
return dt;
}
public string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
public int checkPass(string p)
{
if (Regex.IsMatch(p, @"^(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{6,}$"))
return 1;
else
return 0;
}
public int sendMail(string method,string code,string SID,string SNIC,string SNAME,string SACT)
{
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com",587);
SmtpServer.Timeout = 100000;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new NetworkCredential("[email protected]", "yourgmailpassword");
SmtpServer.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.To.Add("[email protected]");
mail.From = new MailAddress("[email protected]");
if (method == "NEW MEMBER REGISTRATION")
{
mail.Subject = method;
mail.Body = "Salesman ID : " + SID + "\nNIC : " + SNIC + "\nFull Name : " + SNAME + "\nAccount Type : " + SACT + "\nVerification Code : " + code + "\n\nMail sent by Ransilu Enterprises";
SmtpServer.Send(mail);
return 1;
}
else if (method == "PASSWORD RESETTING")
{
mail.Subject = method;
mail.Body = "Salesman ID : " + SID + "\nFull Name : " + SNAME + "\nAccount Type : " + SACT + "\nVerification Code : " + code + "\n\nMail sent by Ransilu Enterprises";
SmtpServer.Send(mail);
return 1;
}
else
return 0;
}
public bool ckLogin(string q)
{
OpenCon();
da = new SqlDataAdapter(q, con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count == 1)
rboo = true;
else
rboo = false;
CloseCon();
return rboo;
}
}
}