using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public byte [] rec1;
public object rec;
public int a;
public Form1()
{
InitializeComponent();
}
private void button1_Click_1(object sender, EventArgs e)
{
string aa = "Data Source=(local);Initial Catalog=ab;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = aa;
string cmdText = "SELECT * FROM 温湿度 where 时间='" + textBox2.Text + "'";
//MessageBox.Show(cmdText);
SqlDataAdapter da = new SqlDataAdapter(cmdText, con);
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds);
foreach (DataRow row in ds.Tables[0].Rows)
{
textBox1.Text = textBox2.Text;
textBox3.Text = row["温度"].ToString();
textBox4.Text = row["湿度"].ToString();
}
}
catch (Exception)
{
MessageBox.Show("对不起!查询失败!", "提示");
}
finally
{
con.Close();
}
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
{
string aa = "Data Source=(local);Initial Catalog=ab;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = aa;
string cmdText = "SELECT * FROM 温湿度";
SqlDataAdapter da = new SqlDataAdapter(cmdText, con);
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds);
}
catch (Exception)
{
MessageBox.Show("对不起!查询失败!", "提示");
}
finally
{
con.Close();
}
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
string aa = "Data Source=(local);Initial Catalog=ab;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = aa;
string cmdText = "insert into 温湿度(时间,温度,湿度) values ('"+textBox1.Text +"','"+textBox3.Text+"','"+textBox4.Text +"')";
SqlCommand cmd = new SqlCommand(cmdText ,con);
try
{
con.Open();
cmd.ExecuteNonQuery();
qingkong();
}
catch (Exception)
{
MessageBox.Show("对不起!保存数据失败!", "提示");
}
finally
{
con.Close();
}
shuaxin();
}
void qingkong()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
void shuaxin()
{
string aa = "Data Source=(local);Initial Catalog=ab;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = aa;
string cmdText = "SELECT * FROM 温湿度";
SqlDataAdapter da = new SqlDataAdapter(cmdText, con);
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds);
}
catch (Exception)
{
MessageBox.Show("对不起!查询失败!", "提示");
}
finally
{
con.Close();
}
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
private void axMSComm1_OnComm(object sender, EventArgs e)
{
//byte[] rec1;
//if (axMSComm1.CommEvent== ComEvReceive)
//axMSComm1.CommEvent == 1;
//if (axMSComm1.CommEvent.Equals(1))
//rec= Convert.ToByte(axMSComm1.Input);
//c =axMSComm1.Input;
//b = (byte)rec;
timer1.Enabled = true;
rec= axMSComm1.Input;
rec1= (byte[] )rec;
rec1[0] = (byte)(rec1[0] - 100);
rec1[1] = (byte)(rec1[1] - 200);
textBox5.Text = Convert.ToString(rec1[0])+"℃";
textBox6.Text = Convert.ToString(rec1[1])+"%";
listBox1.Items.Add(textBox5.Text);
textBox7.Text =Convert.ToString (DateTime.Now);
//textBox7.Text = Convert.ToString(a);
// a++;
}
private void button2_Click(object sender, EventArgs e)
{
axMSComm1.InBufferCount = 0;
axMSComm1.PortOpen = true;
//axMSComm1.Output = 0x12;
if (axMSComm1.PortOpen==true)
MessageBox.Show("串口已打开!", "提示");
//timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
axMSComm1.PortOpen = false;
//textBox7.Text=DateTime.Now.ToString();
//textBox5.Text = "12";
//textBox6.Text = "162";
string aa = "Data Source=(local);Initial Catalog=ab;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = aa;
string cmdText = "insert into 温湿度(时间,温度,湿度) values ('" + textBox7.Text + "','" + textBox5.Text + "','" + textBox6.Text + "')";
SqlCommand cmd = new SqlCommand(cmdText, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
qingkong();
}
catch (Exception)
{
timer1.Enabled = false;
MessageBox.Show("对不起!保存数据失败!", "提示");
}
finally
{
con.Close();
}
shuaxin();
timer1.Enabled = false;
axMSComm1.PortOpen = true;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void groupBox3_Enter(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
axMSComm1.PortOpen = false;
timer1.Enabled = false;
}
}
}
邓凌佳
- 粉丝: 76
- 资源: 1万+
最新资源
- C语言-leetcode题解之34-search-for-a-range.c
- C语言-leetcode题解之33-search-in-rotated-sorted-array.c
- C语言-leetcode题解之32-longest-valid-parentheses.c
- 798225560046179月圆之夜v1.5.9修改版.apk
- 40个Python可视化图表案例(含源码)
- 343366978633126base.apk
- map_mode_escape_1.28.13.12700.pak
- androidx.multidex.MultiDexApplication.apk.1
- 丑子金装美化32(1).zip
- 基于Visual Basic .Net及Python技术的学校需求解决方案设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈