C#温度报警
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.Drawing; //展示端口
namespace TemperatureSytem
{
static class ShowPortIsOrNo
{
/// <summary>
/// 显示可用端口,和提示
/// </summary>
/// <param name="combox">显示端口</param>
/// <param name="lab">提示</param>
public static void FromLoadPort(ComboBox combox,Label lab)
{
ArrayList alPort = PortCheckAndSeting.PortSeting();
if (alPort.Count < )
{
lab.Text = "未检测到可用串口!!!";
lab.ForeColor = Color.Red;
return;
}
else
{
foreach (string sPort in alPort)
{
combox.Items.Add(sPort);
combox.Text = sPort;
}
}
}
}
}
ShowPortIsOrNo.cs
//串口检测
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO.Ports;
using System.Windows.Forms; namespace TemperatureSytem
{
static class PortCheckAndSeting
{
/// <summary>
/// 加载的有串口
/// </summary>
/// <returns>返回一个串口动态数组</returns>
public static ArrayList PortSeting()
{
ArrayList alPort = new ArrayList();
foreach (string sPort in SerialPort.GetPortNames())
{
alPort.Add(sPort);
}
return alPort;
}
/// <summary>
/// 新串口检测设置
/// </summary>
/// <param name="alOlePort"></param>
/// <returns></returns>
public static string NewPortSeting(ComboBox comBox)
{
//存在
ArrayList alOldPort = new ArrayList();//保存旧串口号的
foreach (string strOldPort in comBox.Items)//遍历旧的保存在动态数组里
{
alOldPort.Add(strOldPort);
}
foreach (string sPort in SerialPort.GetPortNames())
{
bool exists = ((IList)alOldPort).Contains(sPort);
if (!exists)//在旧的串口里是否包含新检测的,不包含则返回这个新检测的
return sPort;
}
return "";
}
}
}
PortCheckAndSeting.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; namespace TemperatureSytem
{
class Sound
{
[DllImport("winmm.dll")]
public static extern long PlaySound(String fileName, long a, long b); [DllImport("winmm.dll")]
public static extern long mciSendString(string lpstrCommand, string lpstrReturnString, long length, long hwndcallback); /// <summary>
/// 播放音乐文件(重复)
/// </summary>
/// <param name="p_FileName">音乐文件名称</param>
public static void PlayMusic_Repeat(string p_FileName)
{
try
{
mciSendString(@"close temp_music", " ", , );
mciSendString(@"open " + p_FileName + " alias temp_music", " ", , );
mciSendString(@"play temp_music repeat", " ", , );
}
catch
{ }
} /// <summary>
/// 播放音乐文件
/// </summary>
/// <param name="p_FileName">音乐文件名称</param>
public static void PlayMusic(string p_FileName)
{
try
{
mciSendString(@"close temp_music", " ", , );
mciSendString(@"open " + p_FileName + " alias temp_music", " ", , );
mciSendString(@"play temp_music", " ", , );
}
catch
{ }
} /// <summary>
/// 停止当前音乐播放
/// </summary>
/// <param name="p_FileName">音乐文件名称</param>
public static void StopMusic(string p_FileName)
{
try
{
mciSendString(@"close " + p_FileName, " ", , );
}
catch { }
} }
}
Sound.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Collections;
using System.Data.SqlClient;
using System.Diagnostics; namespace SqlOperate
{
class SqlHelpers
{
public bool bl = true;
public static string sql;
public static string userName;
public static string userPwd;
public static string sqlDatabase;
public static string strConn; public string Sql
{
get { return sql; }
set { sql = value; }
}
public string UserName
{
get { return userName; }
set { userName = value; }
}
public string UserPwd
{
get { return userPwd; }
set { userPwd = value; }
}
public string SqlDataBase
{
get { return sqlDatabase; }
set { sqlDatabase = value; }
} public string StrrConn
{
get { return strConn; }
set { strConn = value; }
}
OleDbConnection con;
OleDbDataAdapter adp;
//连接
public string StrConnString()
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\data.mdb";
return strConn;
}
public void Conn()
{
// string sqlconn = "server=" + sql + ";database="+sqlDatabase+";uid=" + userName + ";pwd=" + userPwd + ";";
con = new OleDbConnection(StrConnString());
try
{
con.Open();
bl = true;
}
catch (Exception)
{ bl = false;
}
}
#region 返回DataTable
/// <summary>
/// 返回DataTable
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public DataTable datatable(string sqlxx)
{
DataSet dataset = new DataSet();
try
{
adp = new OleDbDataAdapter(sqlxx, StrConnString());
adp.Fill(dataset, "table1"); }
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return dataset.Tables["table1"];
}
#endregion #region 返回DATASET
/// <summary>
/// 返回DataTable
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public DataSet dataSet(string sqlxx)
{
DataSet dataset = new DataSet();
try
{
adp = new OleDbDataAdapter(sqlxx, StrConnString());
adp.Fill(dataset, "table1"); }
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return dataset;
} public DataSet dataSet(ArrayList sqlxx)
{
DataSet dataset = new DataSet();
int i = ;
try
{
foreach (string item in sqlxx)
{
adp = new OleDbDataAdapter(item, StrConnString());
adp.Fill(dataset,i.ToString());
i++;
} }
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return dataset;
}
#endregion #region 返回一个动态数组
/// <summary>
/// 返回一个动态数组
/// </summary>
/// <param name="sql"></param>
/// <param name="ziduan"></param>
/// <param name="combox"></param>
public ArrayList pinyin(string sql, string ziduan)
{ OleDbConnection con = new OleDbConnection(StrConnString());
OleDbDataAdapter adp = new OleDbDataAdapter(sql, con);
DataTable dt = new DataTable();
adp.Fill(dt);
ArrayList al = new ArrayList(); for (int i = ; i < dt.Rows.Count; i++)
{
DataRow dr2 = dt.Rows[i];
string username = Convert.ToString(dr2[ziduan]);
bool rep = false;
foreach (string str in al)
{
if (username == str)
{
rep = true;
break;
}
}
if (!rep)
{
al.Add(username);
}
}
return al; }
#endregion #region 普通ExecuteNonQuery
/// <summary>
/// 普通ExecuteNonQuery
/// </summary>
/// <param name="sql"></param>
public void ExecuteNonQuery(string sqlxx)
{
try
{
OleDbConnection con = new OleDbConnection(StrConnString());
con.Open();
OleDbCommand cmd = new OleDbCommand(sqlxx, con);
cmd.ExecuteNonQuery();
con.Close();
}
catch {throw new Exception(); } }
#endregion #region 普通ExecuteNonQuery
/// <summary>
/// 数组ExecuteNonQuery
/// </summary>
/// <param name="sql"></param>
public void ExecuteNonQuery(ArrayList sqlxx)
{
try
{
OleDbConnection con = new OleDbConnection(StrConnString());
con.Open();
foreach (string item in sqlxx)
{
OleDbCommand cmd = new OleDbCommand(item, con);
cmd.ExecuteNonQuery();
} con.Close();
}
catch { throw new Exception(); } }
#endregion #region ComboBox下拉选择
/// <summary>
/// ComboBox下拉选择
/// </summary>
/// <param name="sql"></param>
/// <param name="ziduan"></param>
/// <param name="combox"></param>
public void Combox(string sql, string ziduan, ComboBox combox, int j)
{
combox.Items.Clear();
OleDbConnection con = new OleDbConnection(StrConnString());
OleDbDataAdapter adp = new OleDbDataAdapter(sql, con);
DataTable dt = new DataTable();
adp.Fill(dt);
ArrayList al = new ArrayList(); for (int i = ; i < dt.Rows.Count; i++)
{
DataRow dr2 = dt.Rows[i];
string username = Convert.ToString(dr2[ziduan]);
bool rep = false;
foreach (string str in al)
{
if (username == str)
{
rep = true;
break;
}
}
if (!rep)
{
al.Add(username);
combox.Items.Add(username);
}
}
if (al.Count < )
{
combox.Text = "";
}
else
{
if (j == )
{
combox.AutoCompleteCustomSource.AddRange((string[])al.ToArray(typeof(string))); //ArryList转为string[]
combox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
combox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
}
else
{
combox.Text = al[].ToString();
combox.AutoCompleteCustomSource.AddRange((string[])al.ToArray(typeof(string))); //ArryList转为string[]
combox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
combox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
} }
}
#endregion #region 返回一个动态数组
/// <summary>
/// 返回一个动态数组含两个字段
/// </summary>
/// <param name="sql"></param>
/// <param name="ziduan"></param>
/// <param name="combox"></param>
public ArrayList TwoZiduan(string sql, string ziduan, string ziduan2)
{ OleDbConnection con = new OleDbConnection(StrConnString());
OleDbDataAdapter adp = new OleDbDataAdapter(sql, con);
DataTable dt = new DataTable();
adp.Fill(dt);
ArrayList al = new ArrayList(); for (int i = ; i < dt.Rows.Count; i++)
{
DataRow dr2 = dt.Rows[i];
string username = Convert.ToString(dr2[ziduan]);
string phonenumber = Convert.ToString(dr2[ziduan2]);
string xx = username + "--" + phonenumber;
bool rep = false;
foreach (string str in al)
{
if (xx == str)
{
rep = true;
break;
}
}
if (!rep)
{
al.Add(xx);
}
}
return al; }
#endregion #region 提取一个字段int
/// <summary>
/// 提取一个字段int
/// </summary>
/// <param name="sql"></param>
/// <param name="ziduan"></param>
/// <returns>int</returns>
public int ReturnValue(string sql, string ziduan)
{
int IdValude = ;
OleDbConnection con = new OleDbConnection(StrConnString());
OleDbDataAdapter adp = new OleDbDataAdapter(sql, con);
DataTable dt = new DataTable();
adp.Fill(dt);
if (dt.Rows.Count > )
{
DataRow dr2 = dt.Rows[];
IdValude = Convert.ToInt32(dr2[ziduan]);
return IdValude;
}
else
{
IdValude = -;
return IdValude;
}
} #endregion #region 提取一个字段string
//提取一个字段string
public string TextBox(string sql, string ziduan)
{ try
{
OleDbConnection con = new OleDbConnection(StrConnString());
OleDbDataAdapter adp = new OleDbDataAdapter(sql, con);
DataTable dt = new DataTable();
adp.Fill(dt);
if (dt.Rows.Count > )
{
DataRow dr2 = dt.Rows[];
return Convert.ToString(dr2[]);
}
else
{
return "";
} }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return "";
}
}
#endregion #region dataGridView美化
/// <summary>
/// dataGridView美化
/// </summary>
/// <param name="dataGridView"></param>
public void dataGridView(DataGridView dataGridView)
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridViewCellStyle1.BackColor = System.Drawing.Color.LightCyan;
dataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
dataGridView.BackgroundColor = System.Drawing.Color.White;
dataGridView.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
dataGridView.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;//211, 223, 240
dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)()));
dataGridViewCellStyle2.ForeColor = System.Drawing.Color.Navy;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.EnableHeadersVisualStyles = false;
dataGridView.GridColor = System.Drawing.SystemColors.GradientInactiveCaption;
dataGridView.ReadOnly = false ;
dataGridView.RowHeadersVisible = false;
dataGridView.RowTemplate.Height = ;
dataGridView.RowTemplate.ReadOnly = false ;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
#endregion private void pilian(string tableName,string[] aa,string[] bb)
{ Stopwatch sw = new Stopwatch();
OleDbConnection con = new OleDbConnection(StrConnString());
OleDbCommand sqlComm = new OleDbCommand();
sqlComm.CommandText = string.Format("insert into sz_tb (UserName,Pwd)values(@p0,@p1,@p2)");//参数化SQL
sqlComm.Parameters.Add("@p0", SqlDbType.Int);
sqlComm.Parameters.Add("@p1", SqlDbType.NVarChar);
sqlComm.Parameters.Add("@p2", SqlDbType.VarChar);
sqlComm.CommandType = CommandType.Text;
sqlComm.Connection = con;
con.Open();
try
{
//循环插入100万条数据,每次插入10万条,插入10次。
for (int multiply = ; multiply < ; multiply++)
{
for (int count = multiply * ; count < (multiply + ) * ; count++)
{ sqlComm.Parameters["@p0"].Value = count;
sqlComm.Parameters["@p1"].Value = string.Format("User-{0}", count * multiply);
sqlComm.Parameters["@p2"].Value = string.Format("Pwd-{0}", count * multiply);
sw.Start();
sqlComm.ExecuteNonQuery();
sw.Stop();
}
//每插入10万条数据后,显示此次插入所用时间
// Console.WriteLine(string.Format("Elapsed Time is {0} Milliseconds", sw.ElapsedMilliseconds));
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
} Console.ReadLine();
}
}
}
SqlHelpers.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using SqlOperate;
using System.Threading;
using System.Runtime.InteropServices;
using GSMMODEM; namespace TemperatureSytem
{
public partial class Form1 : Form
{ #region 窗体闪烁API
[DllImport("user32.dll", EntryPoint = "FlashWindow")]
public static extern bool FlashWindow(IntPtr handle, bool bInvert);
[DllImport("user32.dll", EntryPoint = "AnimateWindow")]
public static extern bool AnimateWindow(IntPtr handle, int dwTime, int dwFlags); public const Int32 AW_HOR_POSITIVE = 0x00000001; //从左向右显示
public const Int32 AW_HOR_NEGATIVE = 0x00000002; //从右到左显示
public const Int32 AW_VER_POSITIVE = 0x00000004; //从上到下显示
public const Int32 AW_VER_NEGATIVE = 0x00000008; //从下到上显示
public const Int32 AW_CENTER = 0x00000010; //若使用了AW_HIDE标志,则使窗口向内重叠,即收缩窗口;否则使窗口向外扩展,即展开窗口
public const Int32 AW_HIDE = 0x00010000; //隐藏窗口,缺省则显示窗口
public const Int32 AW_ACTIVATE = 0x00020000; //激活窗口。在使用了AW_HIDE标志后不能使用这个标志
public const Int32 AW_SLIDE = 0x00040000; //使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略
public const Int32 AW_BLEND = 0x00080000;
#endregion public Form1()
{
InitializeComponent();
} SqlHelpers sqlHelpers = new SqlHelpers();//数据库类实例化
delegate void set_Text(string s); //定义委托
set_Text Set_Text; //定义委托
double WoringTmp = ;//临界温度
bool bl = false;//奇偶次
GsmModem gm = new GsmModem();//短信猫实例化 private void Form1_Load(object sender, EventArgs e)
{
FromLoadSeting();
Set_Text = new set_Text(set_lableText); //实例化
}
private void set_lableText(string s) //主线程调用的函数
{
txt_nowTem.Text = s;
}
//窗体加载函数
public void FromLoadSeting()
{
//ShowPortIsOrNo.FromLoadPort(cmb_Port, lab_ProtWoring);//温度感应器
//ShowPortIsOrNo.FromLoadPort(cmb_sms_port, lab_sms_ProtWoring);//短信猫
} #region 温度感应器配置
//感应器串口检测
private void timer_port_Tick(object sender, EventArgs e)
{
cmb_Port.Text = PortCheckAndSeting.NewPortSeting(cmb_Port);
if (cmb_Port.Text == "")
{
lab_ProtWoring.Text = "未检测到可用串口!!!";
lab_ProtWoring.ForeColor = Color.Red;
}
else
{
lab_ProtWoring.Text = "";
lab_ProtWoring.ForeColor = Color.Red;
}
} //打开温度感应器串口
private void btn_link_Click(object sender, EventArgs e)
{ OpenCgq();
// timer1.Start();
} /// <summary>
/// 打开温度传感器
/// </summary>
private void OpenCgq()
{
if (cmb_Port.Text.Trim() == "")
{
MessageBox.Show("端口号不能为空");
return;
}
btn_Close.Enabled = true;//关闭按钮可操作
btn_link.Enabled = false;//打开按钮不可操作
timer_port.Stop();//自动检测串口打开
string CommNum = this.cmb_Port.Text;
int IntBdr = Convert.ToInt32(this.cmb_rate.Text);//将串口号和波特率存起来
if (!selPort.IsOpen) //如果串口是关闭的
{
selPort.PortName = CommNum;
selPort.BaudRate = IntBdr; //设定串口号和波特率
try //try:尝试下面的代码,如果错误就跳出来执行catch里面代码
{
selPort.Open(); //打开串口
cmb_Port.Enabled = false;
cmb_rate.Enabled = false; //将串口号与波特率选择控件关闭
}
catch
{
MessageBox.Show("串口打开失败!\n\n可能是串口已被占用。");
}
}
else//如果串口是打开的
{
selPort.Close(); //关闭串口;
cmb_Port.Enabled = true;
cmb_rate.Enabled = true; //将串口号与波特率选择控件打开
// hScrollBar1.Enabled = false;
}
} //关闭温度感应器串口;
private void btn_Close_Click(object sender, EventArgs e)
{
btn_link.Enabled = true;//打开按钮可操作
btn_Close.Enabled = false;//关闭按钮不可操作
timer_port.Start();//自动检测串口打开
}
#endregion #region 短信猫配置
//短信猫 串口检测
private void timer_sms_port_Tick(object sender, EventArgs e)
{
cmb_sms_port.Text = PortCheckAndSeting.NewPortSeting(cmb_Port);
if (cmb_Port.Text == "")
{
lab_sms_ProtWoring.Text = "未检测到可用串口!!!";
lab_sms_ProtWoring.ForeColor = Color.Red;
}
else
{
lab_sms_ProtWoring.Text = "";
lab_sms_ProtWoring.ForeColor = Color.Red;
}
} private void btn_sms_link_Click(object sender, EventArgs e)
{
btn_sms_close.Enabled = true;//关闭按钮可操作
btn_sms_link.Enabled = false;//打开按钮不可操作
timer_sms_port.Stop();//自动检测串口打开
} private void btn_sms_close_Click(object sender, EventArgs e)
{
btn_sms_link.Enabled = true;//打开按钮可操作
btn_sms_close.Enabled = false;//关闭按钮不可操作
timer_sms_port.Start();//自动检测串口打开
}
#endregion string[] time = new string[];
float[] temper = new float[];
int hight = ;
private void button1_Click(object sender, EventArgs e)
{
BushImg();
} private void BushImg()
{
//画图初始化
Bitmap bmap = new Bitmap(, );
Graphics gph = Graphics.FromImage(bmap);
gph.Clear(Color.White); PointF cpt = new PointF(, );//中心点
PointF[] xpt = new PointF[] { new PointF(cpt.Y + , cpt.Y), new PointF(cpt.Y, cpt.Y - ), new PointF(cpt.Y, cpt.Y + ) };//x轴三角形
PointF[] ypt = new PointF[] { new PointF(cpt.X, cpt.X - ), new PointF(cpt.X - , cpt.X), new PointF(cpt.X + , cpt.X) };//y轴三角形
gph.DrawString("温度分析折线图", new Font("宋体", ), Brushes.Black, new PointF(cpt.X + , cpt.X));//图表标题
//画x轴
gph.DrawLine(Pens.Black, cpt.X, cpt.Y, cpt.Y, cpt.Y);
gph.DrawPolygon(Pens.Black, xpt);
gph.FillPolygon(new SolidBrush(Color.Black), xpt);
gph.DrawString("次", new Font("宋体", ), Brushes.Black, new PointF(cpt.Y + , cpt.Y + ));
//画y轴
gph.DrawLine(Pens.Black, cpt.X, cpt.Y, cpt.X, cpt.X);
gph.DrawPolygon(Pens.Black, ypt);
gph.FillPolygon(new SolidBrush(Color.Black), ypt);
gph.DrawString("温度(°C)", new Font("宋体", ), Brushes.Black, new PointF(, ));
for (int i = ; i <= ; i++)
{
//画y轴刻度
if (i < )
{
gph.DrawString((i * ).ToString(), new Font("宋体", ), Brushes.Black, new PointF(cpt.X - , cpt.Y - i * - ));
gph.DrawLine(Pens.Black, cpt.X - , cpt.Y - i * , cpt.X, cpt.Y - i * );
} //画x轴项目
gph.DrawString(time[i - ], new Font("宋体", ), Brushes.Black, new PointF(cpt.X + i * - , cpt.Y + ));
// gph.DrawString(time[i - 1], new Font("宋体", 11), Brushes.Black, new PointF(cpt.X + i * 30 - 5, cpt.Y + 20));
if (time[i - ].Length > ) gph.DrawString(time[i - ].Substring(, ), new Font("宋体", ), Brushes.Black, new PointF(cpt.X + i * - , cpt.Y + ));
//画点
gph.DrawEllipse(Pens.Black, cpt.X + i * - 1.5f, cpt.Y - temper[i - ] * hight - 1.5f, , );
gph.FillEllipse(new SolidBrush(Color.Black), cpt.X + i * - 1.5f, cpt.Y - temper[i - ] * hight - 1.5f, , );
//画数值
gph.DrawString(temper[i - ].ToString(), new Font("宋体",), Brushes.Black, new PointF(cpt.X + i * , cpt.Y - temper[i - ] * hight));
//画折线
if (i > ) gph.DrawLine(Pens.Red, cpt.X + (i - ) * , cpt.Y - temper[i - ] * hight, cpt.X + i * , cpt.Y - temper[i - ] * hight);
}
//保存输出图片
//bmap.Save(Response.OutputStream, ImageFormat.Gif);
pictureBox1.Image = bmap;
} private void button2_Click(object sender, EventArgs e)
{
GetTimes();
GetTimp();
} //得到时间
private void GetTimes()
{
for (int i = ; i < ; i++)
{
time[i-] = i.ToString();
}
} private void GetTimp()
{
DataTable dt = sqlHelpers.datatable("select top 10 temper from temp_tb order by id desc");
for (int i = ; i < dt.Rows.Count; i++)
{
temper[i] = float.Parse( dt.Rows[i][].ToString());
}
for (int i = dt.Rows.Count; i < ; i++)
{
temper[i] = ;
} } int[] SDateTemp = new int[];
int cs = ;
private void timer1_Tick(object sender, EventArgs e)
{
run(); } //获得温度的并保存
private void run()
{
while (true)
{
int temp = this.selPort.ReadByte();
if (temp>||bl)
{
bl = true;
SDateTemp[cs] = temp;
cs++;
if (cs > )
{
string Temp = SDateTemp[].ToString() + "." + SDateTemp[].ToString();
sqlHelpers.ExecuteNonQuery("insert into temp_tb(temper)values(" + Temp + ")");
SDateTemp[] = ;
SDateTemp[] = ;
cs = ; txt_nowTem.Invoke(Set_Text, new object[] { Temp }); //通过调用委托,来改变TextBox的值
}
}
}
}
Thread thread1;
private void button3_Click(object sender, EventArgs e)
{ thread1 = new Thread(new ThreadStart(run));
thread1.Start();
timer_woring.Start();
} //刷新折线图
private void timer_sx_Tick(object sender, EventArgs e)
{
GetTimes();
GetTimp();
BushImg();
} //设置临界值
private void btn_setTem_Click(object sender, EventArgs e)
{
WoringTmp = Convert.ToDouble(txt_worT.Text.Trim());
} private void timer_woring_Tick(object sender, EventArgs e)
{
if (txt_nowTem.Text.Trim()!="")
{
if (Convert.ToDouble(txt_worT.Text.Trim()) < Convert.ToDouble(txt_nowTem.Text.Trim()))
{
Sound.PlayMusic(Application.StartupPath + "\\woring.mp3");
timer_woring.Stop();
timer_ss.Start();
label7.Text = "温度过高!!!!";
string pic1 = Application.StartupPath + "\\1.gif";
this.pictureBox2.Image = Image.FromFile(pic1);
if (gm.IsOpen && txt_phoneNumber.Text != "" && txt_messages.Text!="")
{
gm.SendMsg(txt_phoneNumber.Text, txt_messages.Text);
}
}
}
} //解除警报
private void btn_reaWoring_Click(object sender, EventArgs e)
{
Sound.PlayMusic(Application.StartupPath + "\\woring.mp");
timer_woring.Start();
timer_ss.Stop();
label7.Text = "";
string pic1 = Application.StartupPath + "\\2.jpg";
this.pictureBox2.Image = Image.FromFile(pic1);
}
//窗体闪烁
private void timer_ss_Tick(object sender, EventArgs e)
{
FlashWindow(this.Handle, true);
} }
}
From Code
C#温度报警的更多相关文章
- 电动车智能充电桩温度报警方案:SI24R2F
由于现在电动自行车便捷不少民众的出行都选择这种交通工具出行,随着越来越多人都使用电动自行车,智能电动车充电桩的需求也在慢慢的变多,电动车智能充电桩的安全性也慢慢成为市场的焦点,对此SI24R ...
- 基于ARM-LINUX的温度传感器驱动-DS18B20
转载:http://blog.csdn.net/ayangke/article/details/6883244 作者:冯建,华清远见嵌入式学院讲师. DS18B20数字温度传感器接线方便,封装成后可应 ...
- 基于ARM-LINUX的温度传感器驱动(DS18B20) .
DS18B20数字温度传感器接线方便,封装成后可应用于多种场合,如管道式,螺纹式,磁铁吸附式,不锈钢封装式,型号多种多样,有LTM8877,LTM8874等等.主要根据应用场合的不同而改变其外观.封装 ...
- 单片机C语言实现的采用DS18B20的温度检测装置
这几天老师布置了一个课程设计题目:采用51单片机控制的DS18B20温度检测系统.大概花了我一个礼拜的时间,幸好我的C语言学得还可以,最后还是让我搞出来了,真是高兴,我是采用STC-52单片机和DS1 ...
- arduino驱动dbs820温度
https://blog.csdn.net/Naisu_kun/article/details/88420357 超过温度报警 // #include <OneWire.h> //可以不引 ...
- 机械革命X5(MECHREVO MR-X5)开包检验
不废话.直接的问题,左右X5没有更具体的信息.为了通过有机会了解后续的选择,具体的数据被释放约: 首先看包装: 1.快递包裹,基于卖方这可以是不同的,包装各不相同 watermark/2/text/a ...
- Atitit.软件GUIbutton和仪表板(01)--警报系统--
Atitit.软件GUIbutton和仪表板(01)--警报系统-- 1. 温度报警防区(鲁大师,360taskman) 1 2. os-区-----cpu_mem_io资源占用监測 1 3. Vm区 ...
- STM32驱动DS18B20
DS18B20 是由 DALLAS 半导体公司推出的一种的“一线总线”接口的温度传感器.与传 统的热敏电阻等测温元件相比,它是一种新型的体积小.适用电压宽.与微处理器接口简单的 数字化温度传感器.一线 ...
- Jace Config
一.jace配置 1.按照Jace 的默认IP配置自己电脑的IP网段(同一个网段),连接上之后使用默认的密码登录,导入tridiumEMEA…..的授权文件,之后创建Station,选择需要的协议驱动 ...
随机推荐
- Sticky footer经典布局--绝对底部布局
原文转载于:https://cnodejs.org/topic/56ebdf2db705742136388f71 何为Sticky footer布局? 我们常见的网页布局方式一般分为header(页头 ...
- JavaScript 的类型
var a ="111"; console.log(a.constructor);//function String() { [native code]} var b= Strin ...
- [luoguP1273] 有线电视网(DP)
传送门 f[i][j]表示节点i选j个用户的最大收益 #include <cstdio> #include <cstring> #include <iostream> ...
- 选课(codevs 1378)
题目描述 Description 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校开设了N(N<300)门的选修课程,每个学生可选课程的数量M是给定的.学生选修 ...
- 下载整个网页的方法,包括样式、图片、和js
扒别人网站,不一定是要干邪恶的事(当然也有干的).有时候我们看到别人网站的功能很酷,想要自己试着实现一下.我们就需要扒一下这个页面,一方面可以线下修改学习,另一方面不会浪费时间在设计页面上,可以更关心 ...
- 远程连接mongodb时,27017端口连接不上的解决办法
一.背景描述: 我在linux RED7上安装了mongodb,并没有修改mongodb的配置文件.然后通过另外一台电脑用pymongo连接mongodb时,报错:timeout. ping IP ...
- SGU 104 Little shop of flowers【DP】
浪(吃)了一天,水道题冷静冷静.... 题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=104 题意: 给定每朵花放在每个花盆的值, ...
- delphi操作xml学习笔记 之一 入门必读
Delphi 对XML的支持---TXMLDocument类 Delphi7 支持对XML文档的操作,可以通过TXMLDocument类来实现对XML文档的读写.可以利用TXMLDocum ...
- Codeforces554E:Love Triangles
There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves B ...
- linux字符驱动之poll机制按键驱动
在上一节中,我们讲解了如何自动创建设备节点,实现一个中断方式的按键驱动.虽然中断式的驱动,效率是蛮高的,但是大家有没有发现,应用程序的死循环里的读函数是一直在读的:在实际的应用场所里,有没有那么一种情 ...