-
Notifications
You must be signed in to change notification settings - Fork 3
/
Class.cs
163 lines (136 loc) · 4.93 KB
/
Class.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Net.Mail;
using System.Net;
using System.Security.Cryptography;
using System.IO;
using System.Data.OleDb;
using System.Text.RegularExpressions;
using System.Diagnostics;
namespace CobasITMonitor
{
class Class
{
public class AccessDbClass1
{
public OleDbConnection Conn;
public string ConnString;
public string AccessDbClass2(string Dbpath)
{
ConnString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
ConnString += Dbpath;
Conn = new OleDbConnection(ConnString);
Conn.Open();
string b = "true";
return b;
}
public OleDbConnection DbConn()
{
Conn.Open();
return Conn;
}
public void Close()
{
Conn.Close();
}
public DataTable SelectToDataTable(string SQL)
{
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(SQL, Conn);
adapter.SelectCommand = command;
DataTable Dt = new DataTable();
adapter.Fill(Dt);
return Dt;
}
public DataSet SelectToDataSet(string SQL, string subtableName)
{
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(SQL, Conn);
adapter.SelectCommand = command;
DataSet Ds = new DataSet();
Ds.Tables.Add(subtableName);
adapter.Fill(Ds, subtableName);
return Ds;
}
public DataSet SelectToDataSet(string SQL, string subtableName, DataSet DataSetName)
{
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(SQL, Conn);
adapter.SelectCommand = command;
DataTable Dt = new DataTable();
DataSet Ds = new DataSet();
Ds = DataSetName;
adapter.Fill(DataSetName, subtableName);
return Ds;
}
public OleDbDataAdapter SelectToOleDbDataAdapter(string SQL)
{
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(SQL, Conn);
adapter.SelectCommand = command;
return adapter;
}
public bool ExecuteSQLNonquery(string SQL)
{
OleDbCommand cmd = new OleDbCommand(SQL, Conn);
try
{
cmd.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
}
}
public class SendMail
{
/// <summary>
/// 发送方邮箱
/// </summary>
public string sendFrom { get; set; }
/// <summary>
/// 密码
/// </summary>
public string mailPwd { get; set; }
/// <summary>
/// 接收方邮箱
/// </summary>
public string sendTo { get; set; }
/// <summary>
/// 邮箱主题
/// </summary>
public string subject { get; set; }
/// <summary>
/// 邮箱正文
/// </summary>
public string mailBody { get; set; }
public void send()
{
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(sendTo);
mailMessage.From = new MailAddress(sendFrom);
mailMessage.Subject = subject;
mailMessage.Body = mailBody;//可为html格式文本
mailMessage.BodyEncoding = Encoding.UTF8; ;//邮件内容编码
mailMessage.IsBodyHtml = true;//邮件内容是否为html格式
mailMessage.Priority = System.Net.Mail.MailPriority.High;//邮件的优先级:高
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "smtp." + mailMessage.From.Host;
smtpClient.Credentials = new NetworkCredential(mailMessage.From.Address, mailPwd);// 发件人用户名和密码
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; //通过网络发送到SMTP服务器
smtpClient.SendAsync(mailMessage, mailMessage.Body);//发送邮件
}
catch (Exception)
{
}
}
}
}
}