diff --git a/README.md b/README.md index 2a0f0fd..3456c68 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ Docker Compose,HTTPS 由服务器上的 Nginx Proxy Manager 负责。推送到 已完成: - **虚拟实训台**:按教材实训台布局图排列(红外对射、警示灯、LED 屏、照明灯、人体红外、温湿度、光照、烟雾、火焰、ADAM 模块)。每个浏览器会话一台,状态由服务器统一保存:传感器读数由网页上的滑块和开关设定,经服务器推给学生程序;灯、继电器、LED 屏由学生程序控制。 -- 新控件:CheckBox、RadioButton(事件顺序与 WinForms 一致)、ListBox、PictureBox、DataGridView、DateTimePicker、TrackBar、Windows Media Player,教材控件库的 Lamp、Alarm。 -- 示例工程(按书上代码整理):项目 1 任务 1–2、项目 2 任务 1–3、项目 3 任务 1–2、项目 4 任务 1–3、项目 5 任务 1–3、项目 6 任务 2–3、项目 7 任务 1–3,共 18 个(项目 6 任务 1 在数据库页面上完成)。网址带 `?sample=示例编号` 可直接打开指定示例。 +- 新控件:CheckBox、RadioButton(事件顺序与 WinForms 一致)、ListBox、PictureBox、DataGridView、DateTimePicker、TrackBar、Windows Media Player、Chart(图表),教材控件库的 Lamp、Alarm;Panel 停靠布局、背景图片、无边框窗体。 +- 示例工程(按书上代码整理):项目 1 任务 1–2、项目 2 任务 1–3、项目 3 任务 1–2、项目 4 任务 1–3、项目 5 任务 1–3、项目 6 任务 2–3、项目 7 任务 1–3、项目 8 任务 1–5,共 23 个(项目 6 任务 1 在数据库页面上完成)。网址带 `?sample=示例编号` 可直接打开指定示例。 - 代码编辑器(Monaco):C# 高亮、编译错误波浪线、点错误跳到对应行、F5 运行 / Shift+F5 停止、草稿自动保存在浏览器本地。 - 窗体设计器(仿 VS,界面中文):工具箱、拖放与改大小、属性窗口、事件窗口、双击生成事件处理方法、撤销 / 重做;读写 VS 格式的 Designer.cs。 - 多窗体:新建、删除窗体;运行时多个窗口可切换前后。 diff --git a/docs/设计方案.md b/docs/设计方案.md index 8991a3e..983fbde 100644 --- a/docs/设计方案.md +++ b/docs/设计方案.md @@ -215,7 +215,7 @@ IOT/ | 5 灾情监测 | 火焰(Timer)、烟雾(Thread)、灾情记录与推送 | Thread(含 Suspend / Resume / Abort)、跨线程改界面、ListBox、FormClosing | 已完成 | | 6 数据存储 | 建库建表、采集入库与增删改、按时间段查询 | SQL 窗口(代替 SSMS)、SqlClient 仿冒(SQLite)、DataGridView、DateTimePicker | 已完成 | | 7 情景控制 | 智慧教室、寝室、会议室三种情景联动 | TrackBar、资源图片、PictureBox 当按钮、mp3 播放、虚拟时钟 | 已完成 | -| 8 管理平台 | 主界面、校园环境(自动控制、7 天温度图表)、校园安防(抓拍入库、历史图片) | Panel Dock、无边框窗体、透明背景、Chart、ShowDialog、图片存数据库 | | +| 8 管理平台 | 主界面、校园环境(自动控制、7 天温度图表)、校园安防(抓拍入库、历史图片) | Panel Dock、无边框窗体、透明背景、Chart、ShowDialog、图片存数据库 | 已完成 | 每个实验以数据形式存放(目前在 `samples/`,以后迁到 `content/`),由以下部分组成: @@ -237,7 +237,7 @@ flowchart TB P0["阶段 0 · 技术验证(已完成 2026-10-22)
教材项目 2 任务 1 原样运行;实测编译、延迟、内存"] P1["阶段 1 · MVP(进行中,约 3 个月)
虚拟实训台 ✔、代码编辑器 ✔、窗体设计器 ✔、多窗体 ✔
教材示例:项目 1–3 全部 ✔,项目 4–5 中平台已支持的 3 个任务 ✔
部署(沙箱、Docker Compose、GitHub Actions)✔"] P2["阶段 2 · 教学闭环(进行中,约 2 个月)
账号与班级 ✔、作品保存在服务器 ✔、自动评分 ✔、布置与提交作业 ✔
评阅(看代码、运行、老师评分、评语)✔、成绩表与导出 ✔;一个班试用"] - P3["阶段 3 · 扩展(进行中)
教材项目 4–8:摄像头 ✔、线程 ✔、SQLite 模拟数据库 ✔、虚拟时钟 ✔、图表"] + P3["阶段 3 · 扩展(进行中)
教材项目 4–8:摄像头 ✔、线程 ✔、SQLite 模拟数据库 ✔、虚拟时钟 ✔、图表 ✔"] P4["阶段 4 · 进阶(之后)
校园街景场景、故障注入题库、导出 VS 工程"] P0 -->|"关口:链路跑通,延迟和资源占用可接受"| P1 P1 -->|"关口:教材项目 1–3 能在平台上完整做完"| P2 @@ -298,6 +298,19 @@ flowchart TB - **TrackBar**:拖动、点轨道(LargeChange)、方向键(SmallChange),先 ValueChanged 再 Scroll,竖向时最小值在下面;设计器工具箱加"滑动条""媒体播放器"。评分规则加 `value`(滑动条的值)、`media`(播放了某个文件)检查。 - 示例:书上任务 1 手动开关灯的判断写反(参考工程是对的),任务 3 漏了填充串口列表,示例里都已改正;任务 3 的"每 5 分钟整点拍照"依赖定时器正好在 0 秒触发,自动评分不检查这一项,由老师评阅。编译检查修正:`System.AppDomain.CurrentDomain.BaseDirectory`(带命名空间)也放行。 +- 2026-10-23:项目 8 智慧校园管理平台(5 个任务,每个任务一个示例,代码逐个累加),至此教材 8 个项目全部完成,共 23 个示例。 + - **新建类**:实验页"+ 新建类",可以带文件夹(`SQLHelpers/SQLBLL`),文件夹成为命名空间的一段,模板和 VS 2012 一样;可以删除自己建的类。 + - **停靠布局**:Dock(上、下、左、右、填充)和 WinForms 一样按 Controls 倒序依次停靠,Panel 的边框、GroupBox 的标题占的地方扣掉;窗体改大小、控件显示隐藏、加入移出时重新布局。设计器里改了停靠或大小也立即按同样的规则排好。 + - **背景图片**:BackgroundImage + BackgroundImageLayout(平铺、居中、拉伸、缩放),窗体、面板、图片框都可以设,设计器里从项目资源选。**背景色沿用父控件**:没设置背景色的标签、面板、分组框等画父控件的背景色(不是父控件的背景图片),和 WinForms 一样,所以书上要把放在背景图上的控件设成 Transparent。分组框的标题处边框断开、透出背景(书上分组框放在深色背景上、标题是白字)。文本框的 BackColor 生效。 + - **无边框窗体**:FormBorderStyle = None 时没有标题栏;**运行区自动缩放**:窗体比运行区大时(项目 8 的窗体有 1043×791)整体按比例缩小,右上角显示缩放比例;"放大"让运行区占满整个网页(窗体在左、实训台在右),Esc 还原。 + - **图表**(`System.Windows.Forms.DataVisualization.Charting.Chart`):ChartAreas、Legends、Series(AddXY、Points、ChartType 等)、DataSource + DataBind(DataTable / DataView / DataSet,按 XValueMember、YValueMembers 取列),浏览器用 Chart.js 画,配色是 WinForms 默认的 BrightPastel。设计器工具箱加"图表"(和 VS 一样带 ChartArea1、Legend1、Series1),属性窗口"系列和图例"打开对话框编辑系列(名称、图表类型、图例、图例文字、X / Y 值字段)和图例,按 VS 的格式和顺序写回 Designer.cs,对话框不管的属性原样保留。 + - **路径的反斜杠**:书上写 `BaseDirectory + "Camera\\"`,Linux 上反斜杠会成为文件名的一部分。编译时把传给 System.IO(File、Directory、Path、各种 Stream)和 Image / Bitmap 读写文件方法的路径参数包上 `WindowsPaths.Fix`,反斜杠换成斜杠(和线程、时钟的改写一样不换行、编辑器里看到的是原代码)。 + - **其他**:Paint 事件(VS 双击面板生成的空 `panel1_Paint` 能编译,平台不触发);图片框把鼠标按下、松开发给程序(书上方向键按下时转动摄像机、换成按下的图片);数据库里参数化的日期字符串比较时也转换格式(书上拼出的 `"2024/1/23 23:59:59"` 有两个空格)。 + - **素材**:项目 8 用到的 20 多张图片(标题、校园背景、三个入口图标、亮灯 / 灭灯的路灯场景、面板背景、监控图标、方向盘和方向键、翻页箭头、关闭按钮)全部自绘,名字和尺寸与教材一致(`runtime/Sim.WinForms/Resources/project8.py` 生成 SVG,`build-gallery.sh` 渲染成 PNG)。 + - **数据库 WisdomCampus**:平台按教材的表结构建(EnvironmentData、SecurityData、Users),预置 7 天环境数据,"数据分析"的图表一打开就有内容。学生第一次运行带预置数据库的实验时自动建好自己还没有的库(已有的库不动)。 + - **评分规则**新增:`visible`(连同所在容器都可见)、`window`(某个窗体打开着 / 已关闭)、`exited`(程序已退出)、`image` / `background` 写素材名(如 `background: day_01`,按图片内容核对显示的是不是这张素材)、`points`(图表每个系列的数据点数);"点击"图片框时和浏览器一样先发鼠标按下、松开。 + - **示例**:书上任务 3 第 23 步把"自动推送火情"的处理写到了 ch_autoLamp 上,参考工程里"推送LED信息""自动控制"是空方法、"自动推送火情"没有绑定事件,示例按书的意思补全;任务 5 每次查询前清空 Keys(书上没清空,重复查询时照片和时间对不上)。任务 2 只做界面,为了能看效果加上了打开、返回窗体。 + **其他改进**: - 2026-10-22:代码编辑器的语言功能:代码补全(输入 `btn_Open.` 列出按钮的属性、方法、事件,只列出平台仿真了的成员)、悬停提示、参数提示(`MessageBox.Show(` 列出重载,标出正在填的参数)、停止输入 1 秒后自动检查编译错误(提示和点"运行"时一样)。语言服务是一个常驻进程,每个浏览器标签页一份工程,只更新有变化的文件。实测(限制 2 核):50 个标签页同时检查 1.2 秒内全部完成,同时补全 0.7 秒;内存约 260 MB。 diff --git a/runtime/Sim.WinForms/Resources/README.md b/runtime/Sim.WinForms/Resources/README.md index 668d4eb..501d895 100644 --- a/runtime/Sim.WinForms/Resources/README.md +++ b/runtime/Sim.WinForms/Resources/README.md @@ -1,7 +1,7 @@ # 项目资源素材库 -学生在"项目资源"里添加的图片和声音(`Properties.Resources.xxx`),名字和教材一致,全部由平台自绘或合成(不使用教材配套资料里的素材)。 +学生在"项目资源"里添加的图片和声音(`Properties.Resources.xxx`),名字和尺寸与教材一致,全部由平台自绘或合成(不使用教材配套资料里的素材)。 - `gallery/`:发布给运行器和网页的文件,`index.json` 是清单(名字、文件、中文说明、类型)。 -- `*.svg`:图片的源文件,改了以后用 `rsvg-convert xxx.svg -o gallery/xxx.png` 重新生成。 +- `svg/`:图片的源文件;`project8.py` 生成项目 8 的那些 SVG。改了以后运行 `python3 project8.py && sh build-gallery.sh` 重新生成 PNG(需要 rsvg-convert 和思源黑体)。 - `gallery/ring.mp3`:用 ffmpeg 合成的门铃声(叮—咚),命令见提交记录。 diff --git a/runtime/Sim.WinForms/Resources/build-gallery.sh b/runtime/Sim.WinForms/Resources/build-gallery.sh new file mode 100644 index 0000000..32adb61 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/build-gallery.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# 把 svg/ 下的素材渲染成 gallery/ 下的 PNG(尺寸取 SVG 自己的 width / height)。需要 rsvg-convert 和思源黑体等中文字体。 +cd "$(dirname "$0")" +for f in svg/*.svg; do + rsvg-convert "$f" -o "gallery/$(basename "$f" .svg).png" +done diff --git a/runtime/Sim.WinForms/Resources/gallery/arrow_left_normal.png b/runtime/Sim.WinForms/Resources/gallery/arrow_left_normal.png new file mode 100644 index 0000000..ae79c8b Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/arrow_left_normal.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/arrow_right_normal.png b/runtime/Sim.WinForms/Resources/gallery/arrow_right_normal.png new file mode 100644 index 0000000..e9536e9 Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/arrow_right_normal.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/bg_from1.png b/runtime/Sim.WinForms/Resources/gallery/bg_from1.png new file mode 100644 index 0000000..8a3b58f Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/bg_from1.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/bg_from2.png b/runtime/Sim.WinForms/Resources/gallery/bg_from2.png new file mode 100644 index 0000000..6f95b81 Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/bg_from2.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/bg_home.png b/runtime/Sim.WinForms/Resources/gallery/bg_home.png new file mode 100644 index 0000000..ebc2a3f Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/bg_home.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/btn_arrow_down_normal.png b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_down_normal.png new file mode 100644 index 0000000..b0d338b Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_down_normal.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/btn_arrow_down_press.png b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_down_press.png new file mode 100644 index 0000000..413961e Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_down_press.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/btn_arrow_left_normal.png b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_left_normal.png new file mode 100644 index 0000000..21fe7d0 Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_left_normal.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/btn_arrow_left_press.png b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_left_press.png new file mode 100644 index 0000000..790c73b Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_left_press.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/btn_arrow_right_normal.png b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_right_normal.png new file mode 100644 index 0000000..6be3ff7 Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_right_normal.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/btn_arrow_right_press.png b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_right_press.png new file mode 100644 index 0000000..f71714b Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_right_press.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/btn_arrow_up_normal.png b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_up_normal.png new file mode 100644 index 0000000..a474d86 Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_up_normal.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/btn_arrow_up_press.png b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_up_press.png new file mode 100644 index 0000000..572bcea Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/btn_arrow_up_press.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/day_01.png b/runtime/Sim.WinForms/Resources/gallery/day_01.png new file mode 100644 index 0000000..4bd420f Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/day_01.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/day_02.png b/runtime/Sim.WinForms/Resources/gallery/day_02.png new file mode 100644 index 0000000..b3bf704 Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/day_02.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/ico_title.png b/runtime/Sim.WinForms/Resources/gallery/ico_title.png new file mode 100644 index 0000000..260b874 Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/ico_title.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/icon_02.png b/runtime/Sim.WinForms/Resources/gallery/icon_02.png new file mode 100644 index 0000000..7d54f28 Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/icon_02.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/icon_03.png b/runtime/Sim.WinForms/Resources/gallery/icon_03.png new file mode 100644 index 0000000..e5cae4c Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/icon_03.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/icon_04.png b/runtime/Sim.WinForms/Resources/gallery/icon_04.png new file mode 100644 index 0000000..a970acb Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/icon_04.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/icon_monitor.png b/runtime/Sim.WinForms/Resources/gallery/icon_monitor.png new file mode 100644 index 0000000..6ac99e4 Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/icon_monitor.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/index.json b/runtime/Sim.WinForms/Resources/gallery/index.json index bcac970..3f1d233 100644 --- a/runtime/Sim.WinForms/Resources/gallery/index.json +++ b/runtime/Sim.WinForms/Resources/gallery/index.json @@ -1,5 +1,27 @@ [ { "name": "switch_on", "file": "switch_on.png", "label": "开关:开", "kind": "image" }, { "name": "switch_off", "file": "switch_off.png", "label": "开关:关", "kind": "image" }, - { "name": "ring", "file": "ring.mp3", "label": "铃声", "kind": "audio" } + { "name": "ring", "file": "ring.mp3", "label": "铃声", "kind": "audio" }, + { "name": "ico_title", "file": "ico_title.png", "label": "标题:智慧校园", "kind": "image" }, + { "name": "bg_home", "file": "bg_home.png", "label": "主界面背景:校园", "kind": "image" }, + { "name": "icon_02", "file": "icon_02.png", "label": "图标:校园环境", "kind": "image" }, + { "name": "icon_03", "file": "icon_03.png", "label": "图标:校园安防", "kind": "image" }, + { "name": "icon_04", "file": "icon_04.png", "label": "图标:退出", "kind": "image" }, + { "name": "day_01", "file": "day_01.png", "label": "路灯场景:亮灯", "kind": "image" }, + { "name": "day_02", "file": "day_02.png", "label": "路灯场景:灭灯", "kind": "image" }, + { "name": "bg_from1", "file": "bg_from1.png", "label": "面板背景(宽)", "kind": "image" }, + { "name": "bg_from2", "file": "bg_from2.png", "label": "面板背景(窄)", "kind": "image" }, + { "name": "icon_monitor", "file": "icon_monitor.png", "label": "监控:无画面", "kind": "image" }, + { "name": "panel_video_ctrl", "file": "panel_video_ctrl.png", "label": "监控:方向盘底座", "kind": "image" }, + { "name": "btn_arrow_up_normal", "file": "btn_arrow_up_normal.png", "label": "方向键:上", "kind": "image" }, + { "name": "btn_arrow_up_press", "file": "btn_arrow_up_press.png", "label": "方向键:上(按下)", "kind": "image" }, + { "name": "btn_arrow_down_normal", "file": "btn_arrow_down_normal.png", "label": "方向键:下", "kind": "image" }, + { "name": "btn_arrow_down_press", "file": "btn_arrow_down_press.png", "label": "方向键:下(按下)", "kind": "image" }, + { "name": "btn_arrow_left_normal", "file": "btn_arrow_left_normal.png", "label": "方向键:左", "kind": "image" }, + { "name": "btn_arrow_left_press", "file": "btn_arrow_left_press.png", "label": "方向键:左(按下)", "kind": "image" }, + { "name": "btn_arrow_right_normal", "file": "btn_arrow_right_normal.png", "label": "方向键:右", "kind": "image" }, + { "name": "btn_arrow_right_press", "file": "btn_arrow_right_press.png", "label": "方向键:右(按下)", "kind": "image" }, + { "name": "arrow_left_normal", "file": "arrow_left_normal.png", "label": "翻页:上一张", "kind": "image" }, + { "name": "arrow_right_normal", "file": "arrow_right_normal.png", "label": "翻页:下一张", "kind": "image" }, + { "name": "windowstate_closed_hover", "file": "windowstate_closed_hover.png", "label": "关闭按钮", "kind": "image" } ] diff --git a/runtime/Sim.WinForms/Resources/gallery/panel_video_ctrl.png b/runtime/Sim.WinForms/Resources/gallery/panel_video_ctrl.png new file mode 100644 index 0000000..117831a Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/panel_video_ctrl.png differ diff --git a/runtime/Sim.WinForms/Resources/gallery/windowstate_closed_hover.png b/runtime/Sim.WinForms/Resources/gallery/windowstate_closed_hover.png new file mode 100644 index 0000000..358cb88 Binary files /dev/null and b/runtime/Sim.WinForms/Resources/gallery/windowstate_closed_hover.png differ diff --git a/runtime/Sim.WinForms/Resources/project8.py b/runtime/Sim.WinForms/Resources/project8.py new file mode 100644 index 0000000..bf7c28c --- /dev/null +++ b/runtime/Sim.WinForms/Resources/project8.py @@ -0,0 +1,170 @@ +#!/usr/bin/env python3 +""" +生成教材项目 8(智慧校园管理平台)用到的素材 SVG:名字和尺寸与教材配套资源一致,内容全部自绘(扁平插画)。 +运行后用 build-gallery.sh 渲染成 PNG:python3 project8.py && sh build-gallery.sh +""" +from pathlib import Path + +OUT = Path(__file__).parent / "svg" +OUT.mkdir(exist_ok=True) +FONT = "Source Han Sans CN, Noto Sans CJK SC, sans-serif" + + +def save(name, width, height, body): + (OUT / f"{name}.svg").write_text( + f'\n{body}\n\n', + encoding="utf-8", + ) + + +# ---------- 标题图:智慧校园 ---------- +save("ico_title", 226, 54, f""" + + + + + + + 智慧校园 +""") + +# ---------- 校园建筑:主界面背景、路灯场景共用的元素 ---------- +def building(x, y, w, h, color, window="#cfe3f5", rows=4, cols=6, roof="#b36b45"): + parts = [f'', + f''] + gap_x = w / cols + gap_y = (h - 30) / rows + for r in range(rows): + for c in range(cols): + parts.append(f'') + return "\n".join(parts) + + +def tree(x, y, s=1.0, color="#4f9a45"): + return (f'' + f'' + f'') + + +save("bg_home", 1440, 748, f""" + + + + + + + + + + + + + + {building(380, 260, 680, 300, "#f2e3c9")} + + + + {building(1080, 360, 220, 200, "#e8d6bd", rows=3, cols=4)} + {building(150, 380, 210, 180, "#e8d6bd", rows=3, cols=4)} + + + {tree(120, 600, 1.1)}{tree(330, 620, 0.9)}{tree(1130, 610, 1.0)}{tree(1350, 600, 1.2)} + +""") + + +def street(lit): + sky = ('' if lit + else '') + window = "#ffd37a" if lit else "#cfe3f5" + lamps = [] + for x in (180, 520, 860, 1200): + lamps.append(f'' + f'' + f'') + if lit: + lamps.append(f'' + f'') + else: + lamps.append(f'') + return f""" + {sky} + + {'' if lit else ''} + {building(80, 220, 560, 330, "#e9d8bf", window=window, rows=5, cols=7)} + {building(760, 260, 580, 290, "#dcc7a8", window=window, rows=4, cols=7)} + + + {''.join(f'' for x in range(30, 1440, 140))} + {''.join(lamps)} + {tree(700, 560, 0.8, "#3f7f45")}{tree(1390, 560, 0.9, "#3f7f45")} +""" + + +save("day_01", 1440, 716, street(lit=True)) +save("day_02", 1440, 716, street(lit=False)) + +# ---------- 主界面的三个功能图标 ---------- +def tile(name, color, icon, label): + save(name, 180, 210, f""" + + + {icon} + {label} +""") + + +tile("icon_02", "#2e9e5b", """ + + + """, "校园环境") +tile("icon_03", "#2f7fe0", """ + + """, "校园安防") +tile("icon_04", "#e2803a", """ + + """, "退 出") + +# ---------- 面板背景(半透明深蓝) ---------- +for name, width in (("bg_from1", 555), ("bg_from2", 425)): + save(name, width, 670, f""" + + + +""") + +# ---------- 监控:无画面时的图标、方向盘底座、方向键 ---------- +save("icon_monitor", 280, 280, """ + + + + + + +""") + +save("panel_video_ctrl", 500, 500, """ + + + + +""") + +ROTATE = {"up": 0, "right": 90, "down": 180, "left": 270} +for direction, angle in ROTATE.items(): + for state, (fill, stroke) in {"normal": ("#ffffff", "#5b6472"), "press": ("#2f7fe0", "#ffffff")}.items(): + save(f"btn_arrow_{direction}_{state}", 28, 28, f""" + + +""") + +for direction, angle in (("left", 270), ("right", 90)): + save(f"arrow_{direction}_normal", 60, 60, f""" + + +""") + +save("windowstate_closed_hover", 36, 36, """ + + +""") diff --git a/runtime/Sim.WinForms/Resources/svg/arrow_left_normal.svg b/runtime/Sim.WinForms/Resources/svg/arrow_left_normal.svg new file mode 100644 index 0000000..f62878e --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/arrow_left_normal.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/arrow_right_normal.svg b/runtime/Sim.WinForms/Resources/svg/arrow_right_normal.svg new file mode 100644 index 0000000..711557f --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/arrow_right_normal.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/bg_from1.svg b/runtime/Sim.WinForms/Resources/svg/bg_from1.svg new file mode 100644 index 0000000..c4454a1 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/bg_from1.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/bg_from2.svg b/runtime/Sim.WinForms/Resources/svg/bg_from2.svg new file mode 100644 index 0000000..4d7feee --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/bg_from2.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/bg_home.svg b/runtime/Sim.WinForms/Resources/svg/bg_home.svg new file mode 100644 index 0000000..9bc0a17 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/bg_home.svg @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/btn_arrow_down_normal.svg b/runtime/Sim.WinForms/Resources/svg/btn_arrow_down_normal.svg new file mode 100644 index 0000000..4eb09ad --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/btn_arrow_down_normal.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/btn_arrow_down_press.svg b/runtime/Sim.WinForms/Resources/svg/btn_arrow_down_press.svg new file mode 100644 index 0000000..208587d --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/btn_arrow_down_press.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/btn_arrow_left_normal.svg b/runtime/Sim.WinForms/Resources/svg/btn_arrow_left_normal.svg new file mode 100644 index 0000000..cc40767 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/btn_arrow_left_normal.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/btn_arrow_left_press.svg b/runtime/Sim.WinForms/Resources/svg/btn_arrow_left_press.svg new file mode 100644 index 0000000..aec3fa1 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/btn_arrow_left_press.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/btn_arrow_right_normal.svg b/runtime/Sim.WinForms/Resources/svg/btn_arrow_right_normal.svg new file mode 100644 index 0000000..9da15cc --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/btn_arrow_right_normal.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/btn_arrow_right_press.svg b/runtime/Sim.WinForms/Resources/svg/btn_arrow_right_press.svg new file mode 100644 index 0000000..2a25d34 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/btn_arrow_right_press.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/btn_arrow_up_normal.svg b/runtime/Sim.WinForms/Resources/svg/btn_arrow_up_normal.svg new file mode 100644 index 0000000..c58eb21 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/btn_arrow_up_normal.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/btn_arrow_up_press.svg b/runtime/Sim.WinForms/Resources/svg/btn_arrow_up_press.svg new file mode 100644 index 0000000..2b22a43 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/btn_arrow_up_press.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/day_01.svg b/runtime/Sim.WinForms/Resources/svg/day_01.svg new file mode 100644 index 0000000..540d394 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/day_01.svg @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/day_02.svg b/runtime/Sim.WinForms/Resources/svg/day_02.svg new file mode 100644 index 0000000..1635baa --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/day_02.svg @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/ico_title.svg b/runtime/Sim.WinForms/Resources/svg/ico_title.svg new file mode 100644 index 0000000..a6db8c0 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/ico_title.svg @@ -0,0 +1,11 @@ + + + + + + + + + 智慧校园 + + diff --git a/runtime/Sim.WinForms/Resources/svg/icon_02.svg b/runtime/Sim.WinForms/Resources/svg/icon_02.svg new file mode 100644 index 0000000..b5090ce --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/icon_02.svg @@ -0,0 +1,11 @@ + + + + + + + + + 校园环境 + + diff --git a/runtime/Sim.WinForms/Resources/svg/icon_03.svg b/runtime/Sim.WinForms/Resources/svg/icon_03.svg new file mode 100644 index 0000000..4510677 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/icon_03.svg @@ -0,0 +1,10 @@ + + + + + + + + 校园安防 + + diff --git a/runtime/Sim.WinForms/Resources/svg/icon_04.svg b/runtime/Sim.WinForms/Resources/svg/icon_04.svg new file mode 100644 index 0000000..a27efdc --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/icon_04.svg @@ -0,0 +1,10 @@ + + + + + + + + 退 出 + + diff --git a/runtime/Sim.WinForms/Resources/svg/icon_monitor.svg b/runtime/Sim.WinForms/Resources/svg/icon_monitor.svg new file mode 100644 index 0000000..dab38b8 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/icon_monitor.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/runtime/Sim.WinForms/Resources/svg/panel_video_ctrl.svg b/runtime/Sim.WinForms/Resources/svg/panel_video_ctrl.svg new file mode 100644 index 0000000..629f50c --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/panel_video_ctrl.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/runtime/Sim.WinForms/Resources/switch_off.svg b/runtime/Sim.WinForms/Resources/svg/switch_off.svg similarity index 100% rename from runtime/Sim.WinForms/Resources/switch_off.svg rename to runtime/Sim.WinForms/Resources/svg/switch_off.svg diff --git a/runtime/Sim.WinForms/Resources/switch_on.svg b/runtime/Sim.WinForms/Resources/svg/switch_on.svg similarity index 100% rename from runtime/Sim.WinForms/Resources/switch_on.svg rename to runtime/Sim.WinForms/Resources/svg/switch_on.svg diff --git a/runtime/Sim.WinForms/Resources/svg/windowstate_closed_hover.svg b/runtime/Sim.WinForms/Resources/svg/windowstate_closed_hover.svg new file mode 100644 index 0000000..be70646 --- /dev/null +++ b/runtime/Sim.WinForms/Resources/svg/windowstate_closed_hover.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/samples/p8-t1-主界面/Main.Designer.cs b/samples/p8-t1-主界面/Main.Designer.cs new file mode 100644 index 0000000..4a5eed4 --- /dev/null +++ b/samples/p8-t1-主界面/Main.Designer.cs @@ -0,0 +1,142 @@ +namespace 智慧校园 +{ + partial class Main + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.pic_exit = new System.Windows.Forms.PictureBox(); + this.pic_security = new System.Windows.Forms.PictureBox(); + this.pic_environment = new System.Windows.Forms.PictureBox(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_exit)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_security)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_environment)).BeginInit(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(53)))), ((int)(((byte)(147)))), ((int)(((byte)(237))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1018, 100); + this.panel1.TabIndex = 0; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(57, 23); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(197, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel2 + // + this.panel2.BackgroundImage = global::智慧校园.Properties.Resources.bg_home; + this.panel2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel2.Controls.Add(this.pic_exit); + this.panel2.Controls.Add(this.pic_security); + this.panel2.Controls.Add(this.pic_environment); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 100); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(1018, 516); + this.panel2.TabIndex = 1; + this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint); + // + // pic_exit + // + this.pic_exit.BackColor = System.Drawing.Color.Transparent; + this.pic_exit.Image = global::智慧校园.Properties.Resources.icon_04; + this.pic_exit.Location = new System.Drawing.Point(660, 124); + this.pic_exit.Name = "pic_exit"; + this.pic_exit.Size = new System.Drawing.Size(180, 210); + this.pic_exit.TabIndex = 6; + this.pic_exit.TabStop = false; + this.pic_exit.Click += new System.EventHandler(this.pic_exit_Click); + // + // pic_security + // + this.pic_security.BackColor = System.Drawing.Color.Transparent; + this.pic_security.Image = global::智慧校园.Properties.Resources.icon_03; + this.pic_security.Location = new System.Drawing.Point(404, 124); + this.pic_security.Name = "pic_security"; + this.pic_security.Size = new System.Drawing.Size(180, 210); + this.pic_security.TabIndex = 5; + this.pic_security.TabStop = false; + // + // pic_environment + // + this.pic_environment.BackColor = System.Drawing.Color.Transparent; + this.pic_environment.Image = global::智慧校园.Properties.Resources.icon_02; + this.pic_environment.Location = new System.Drawing.Point(133, 124); + this.pic_environment.Name = "pic_environment"; + this.pic_environment.Size = new System.Drawing.Size(180, 210); + this.pic_environment.TabIndex = 4; + this.pic_environment.TabStop = false; + // + // Main + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1018, 616); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Main"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pic_exit)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_security)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_environment)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.PictureBox pic_exit; + private System.Windows.Forms.PictureBox pic_security; + private System.Windows.Forms.PictureBox pic_environment; + } +} + diff --git a/samples/p8-t1-主界面/Main.cs b/samples/p8-t1-主界面/Main.cs new file mode 100644 index 0000000..ff92a94 --- /dev/null +++ b/samples/p8-t1-主界面/Main.cs @@ -0,0 +1,34 @@ +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; +namespace 智慧校园 +{ + public partial class Main : Form + { + public Main() + { + InitializeComponent(); + } + + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void panel2_Paint(object sender, PaintEventArgs e) + { + + } + + private void pic_exit_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/samples/p8-t1-主界面/Program.cs b/samples/p8-t1-主界面/Program.cs new file mode 100644 index 0000000..2fd691b --- /dev/null +++ b/samples/p8-t1-主界面/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 智慧校园 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Main()); + } + } +} diff --git a/samples/p8-t1-主界面/Properties/Resources.Designer.cs b/samples/p8-t1-主界面/Properties/Resources.Designer.cs new file mode 100644 index 0000000..fcccaeb --- /dev/null +++ b/samples/p8-t1-主界面/Properties/Resources.Designer.cs @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// +// 项目资源(平台素材库)。在"项目资源"里添加或移除,不要手动修改这个文件。 +// +//------------------------------------------------------------------------------ + +namespace 智慧校园.Properties { + + /// + /// 项目资源:Properties.Resources.资源名 + /// + internal class Resources { + + /// 标题:智慧校园 + internal static System.Drawing.Bitmap ico_title { + get { return global::Sim.Host.ProjectResources.Image("ico_title.png"); } + } + + /// 主界面背景:校园 + internal static System.Drawing.Bitmap bg_home { + get { return global::Sim.Host.ProjectResources.Image("bg_home.png"); } + } + + /// 图标:校园环境 + internal static System.Drawing.Bitmap icon_02 { + get { return global::Sim.Host.ProjectResources.Image("icon_02.png"); } + } + + /// 图标:校园安防 + internal static System.Drawing.Bitmap icon_03 { + get { return global::Sim.Host.ProjectResources.Image("icon_03.png"); } + } + + /// 图标:退出 + internal static System.Drawing.Bitmap icon_04 { + get { return global::Sim.Host.ProjectResources.Image("icon_04.png"); } + } + } +} diff --git a/samples/p8-t1-主界面/checks.yaml b/samples/p8-t1-主界面/checks.yaml new file mode 100644 index 0000000..b562e3a --- /dev/null +++ b/samples/p8-t1-主界面/checks.yaml @@ -0,0 +1,14 @@ +# 评分规则:书上评价表的功能项。每项单独启动一次程序,按步骤操作,核对结果。 +# 格式说明见 server/src/grading/checks.ts +- title: 主界面显示标题和三个功能入口 + steps: + - expect: { control: pictureBox1, image: ico_title, desc: 显示"智慧校园"标题图(ico_title) } + - expect: { control: panel2, background: bg_home, desc: 背景是校园图片(bg_home) } + - expect: { control: pic_environment, image: icon_02, desc: 显示"校园环境"图标(icon_02) } + - expect: { control: pic_security, image: icon_03, desc: 显示"校园安防"图标(icon_03) } + - expect: { control: pic_exit, image: icon_04, desc: 显示"退出"图标(icon_04) } + +- title: 实现退出功能 + steps: + - click: pic_exit + - expect: { exited: true, desc: 点"退出"后关闭主窗体、程序退出 } diff --git a/samples/p8-t1-主界面/meta.json b/samples/p8-t1-主界面/meta.json new file mode 100644 index 0000000..48957c3 --- /dev/null +++ b/samples/p8-t1-主界面/meta.json @@ -0,0 +1,4 @@ +{ + "title": "项目8 任务1 制作管理平台的主界面", + "source": "教材书 p157–159,界面和代码取自配套参考工程;图片是平台素材库里自绘的同名素材(尺寸和教材一致)" +} diff --git a/samples/p8-t2-校园环境界面/Environment.Designer.cs b/samples/p8-t2-校园环境界面/Environment.Designer.cs new file mode 100644 index 0000000..5ac17cc --- /dev/null +++ b/samples/p8-t2-校园环境界面/Environment.Designer.cs @@ -0,0 +1,545 @@ +namespace 智慧校园 +{ + partial class Environment + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Legend legend4 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.panel_bg = new System.Windows.Forms.Panel(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.panel_form = new System.Windows.Forms.Panel(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.pic_lampOpen = new System.Windows.Forms.PictureBox(); + this.label10 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.txt_autoLight = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.ch_autoLamp = new System.Windows.Forms.CheckBox(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.btn_ledEnvironment2 = new System.Windows.Forms.Button(); + this.ch_autoLedFire = new System.Windows.Forms.CheckBox(); + this.btn_ledSendMsg = new System.Windows.Forms.Button(); + this.txt_ledMsg = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.panel5 = new System.Windows.Forms.Panel(); + this.btn_dataAnalyse = new System.Windows.Forms.Button(); + this.btn_ledEnvironment1 = new System.Windows.Forms.Button(); + this.label6 = new System.Windows.Forms.Label(); + this.txt_humidity = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.txt_fire = new System.Windows.Forms.TextBox(); + this.txt_temperature = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.txt_smoke = new System.Windows.Forms.TextBox(); + this.txt_light = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.panel3 = new System.Windows.Forms.Panel(); + this.lb_return = new System.Windows.Forms.Label(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel2.SuspendLayout(); + this.panel_bg.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + this.panel_form.SuspendLayout(); + this.groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_lampOpen)).BeginInit(); + this.groupBox3.SuspendLayout(); + this.panel5.SuspendLayout(); + this.panel3.SuspendLayout(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(116)))), ((int)(((byte)(133))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1043, 100); + this.panel1.TabIndex = 0; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(44, 12); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(226, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel2 + // + this.panel2.Controls.Add(this.panel_bg); + this.panel2.Controls.Add(this.panel3); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 100); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(1043, 691); + this.panel2.TabIndex = 1; + // + // panel_bg + // + this.panel_bg.BackgroundImage = global::智慧校园.Properties.Resources.day_02; + this.panel_bg.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel_bg.Controls.Add(this.chart1); + this.panel_bg.Controls.Add(this.panel_form); + this.panel_bg.Controls.Add(this.panel5); + this.panel_bg.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel_bg.Location = new System.Drawing.Point(0, 39); + this.panel_bg.Name = "panel_bg"; + this.panel_bg.Size = new System.Drawing.Size(1043, 652); + this.panel_bg.TabIndex = 1; + // + // chart1 + // + chartArea2.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea2); + legend3.Name = "MaxLegend"; + legend3.TitleForeColor = System.Drawing.Color.DimGray; + legend4.Name = "AVGLegend"; + legend4.TitleForeColor = System.Drawing.Color.DimGray; + this.chart1.Legends.Add(legend3); + this.chart1.Legends.Add(legend4); + this.chart1.Location = new System.Drawing.Point(44, 172); + this.chart1.Name = "chart1"; + series3.ChartArea = "ChartArea1"; + series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series3.Legend = "MaxLegend"; + series3.LegendText = "最大值"; + series3.Name = "MaxSeries"; + series3.XValueMember = "_Time"; + series3.YValueMembers = "MaxTemperature"; + series4.ChartArea = "ChartArea1"; + series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series4.Legend = "AVGLegend"; + series4.LegendText = "平均值"; + series4.Name = "AVGSeries"; + series4.XValueMember = "_Time"; + series4.YValueMembers = "AVGTemperature"; + this.chart1.Series.Add(series3); + this.chart1.Series.Add(series4); + this.chart1.Size = new System.Drawing.Size(455, 327); + this.chart1.TabIndex = 3; + this.chart1.Text = "chart1"; + // + // panel_form + // + this.panel_form.BackColor = System.Drawing.Color.Transparent; + this.panel_form.BackgroundImage = global::智慧校园.Properties.Resources.bg_from2; + this.panel_form.Controls.Add(this.groupBox2); + this.panel_form.Controls.Add(this.groupBox3); + this.panel_form.Dock = System.Windows.Forms.DockStyle.Right; + this.panel_form.Location = new System.Drawing.Point(617, 0); + this.panel_form.Name = "panel_form"; + this.panel_form.Size = new System.Drawing.Size(426, 552); + this.panel_form.TabIndex = 2; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.pic_lampOpen); + this.groupBox2.Controls.Add(this.label10); + this.groupBox2.Controls.Add(this.label9); + this.groupBox2.Controls.Add(this.txt_autoLight); + this.groupBox2.Controls.Add(this.label7); + this.groupBox2.Controls.Add(this.ch_autoLamp); + this.groupBox2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.groupBox2.ForeColor = System.Drawing.Color.White; + this.groupBox2.Location = new System.Drawing.Point(22, 21); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(392, 150); + this.groupBox2.TabIndex = 3; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "路灯控制"; + // + // pic_lampOpen + // + this.pic_lampOpen.BackgroundImage = global::智慧校园.Properties.Resources.switch_off; + this.pic_lampOpen.Location = new System.Drawing.Point(103, 103); + this.pic_lampOpen.Name = "pic_lampOpen"; + this.pic_lampOpen.Size = new System.Drawing.Size(48, 24); + this.pic_lampOpen.TabIndex = 5; + this.pic_lampOpen.TabStop = false; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(33, 105); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(59, 17); + this.label10.TabIndex = 4; + this.label10.Text = "灯光控制:"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(278, 58); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(17, 17); + this.label9.TabIndex = 3; + this.label9.Text = "lx"; + // + // txt_autoLight + // + this.txt_autoLight.Location = new System.Drawing.Point(128, 55); + this.txt_autoLight.Name = "txt_autoLight"; + this.txt_autoLight.Size = new System.Drawing.Size(144, 23); + this.txt_autoLight.TabIndex = 2; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(33, 58); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(92, 17); + this.label7.TabIndex = 1; + this.label7.Text = "设定开灯光照值"; + // + // ch_autoLamp + // + this.ch_autoLamp.AutoSize = true; + this.ch_autoLamp.Location = new System.Drawing.Point(35, 30); + this.ch_autoLamp.Name = "ch_autoLamp"; + this.ch_autoLamp.Size = new System.Drawing.Size(75, 21); + this.ch_autoLamp.TabIndex = 0; + this.ch_autoLamp.Text = "自动控制"; + this.ch_autoLamp.UseVisualStyleBackColor = true; + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.btn_ledEnvironment2); + this.groupBox3.Controls.Add(this.ch_autoLedFire); + this.groupBox3.Controls.Add(this.btn_ledSendMsg); + this.groupBox3.Controls.Add(this.txt_ledMsg); + this.groupBox3.Controls.Add(this.label8); + this.groupBox3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.groupBox3.ForeColor = System.Drawing.Color.White; + this.groupBox3.Location = new System.Drawing.Point(22, 209); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(392, 316); + this.groupBox3.TabIndex = 4; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "LED推送"; + // + // btn_ledEnvironment2 + // + this.btn_ledEnvironment2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(86)))), ((int)(((byte)(149)))), ((int)(((byte)(212))))); + this.btn_ledEnvironment2.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledEnvironment2.Location = new System.Drawing.Point(234, 217); + this.btn_ledEnvironment2.Name = "btn_ledEnvironment2"; + this.btn_ledEnvironment2.Size = new System.Drawing.Size(145, 32); + this.btn_ledEnvironment2.TabIndex = 11; + this.btn_ledEnvironment2.Text = "推送天气信息"; + this.btn_ledEnvironment2.UseVisualStyleBackColor = false; + // + // ch_autoLedFire + // + this.ch_autoLedFire.AutoSize = true; + this.ch_autoLedFire.Location = new System.Drawing.Point(265, 35); + this.ch_autoLedFire.Name = "ch_autoLedFire"; + this.ch_autoLedFire.Size = new System.Drawing.Size(99, 21); + this.ch_autoLedFire.TabIndex = 4; + this.ch_autoLedFire.Text = "自动推送火情"; + this.ch_autoLedFire.UseVisualStyleBackColor = true; + // + // btn_ledSendMsg + // + this.btn_ledSendMsg.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(168)))), ((int)(((byte)(255))))); + this.btn_ledSendMsg.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledSendMsg.Location = new System.Drawing.Point(26, 217); + this.btn_ledSendMsg.Name = "btn_ledSendMsg"; + this.btn_ledSendMsg.Size = new System.Drawing.Size(145, 32); + this.btn_ledSendMsg.TabIndex = 2; + this.btn_ledSendMsg.Text = "推送LED信息"; + this.btn_ledSendMsg.UseVisualStyleBackColor = false; + // + // txt_ledMsg + // + this.txt_ledMsg.Location = new System.Drawing.Point(23, 62); + this.txt_ledMsg.Multiline = true; + this.txt_ledMsg.Name = "txt_ledMsg"; + this.txt_ledMsg.Size = new System.Drawing.Size(356, 130); + this.txt_ledMsg.TabIndex = 1; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(20, 36); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(54, 17); + this.label8.TabIndex = 0; + this.label8.Text = "LED信息"; + // + // panel5 + // + this.panel5.Controls.Add(this.btn_dataAnalyse); + this.panel5.Controls.Add(this.btn_ledEnvironment1); + this.panel5.Controls.Add(this.label6); + this.panel5.Controls.Add(this.txt_humidity); + this.panel5.Controls.Add(this.label1); + this.panel5.Controls.Add(this.label5); + this.panel5.Controls.Add(this.txt_fire); + this.panel5.Controls.Add(this.txt_temperature); + this.panel5.Controls.Add(this.label2); + this.panel5.Controls.Add(this.label4); + this.panel5.Controls.Add(this.txt_smoke); + this.panel5.Controls.Add(this.txt_light); + this.panel5.Controls.Add(this.label3); + this.panel5.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel5.Location = new System.Drawing.Point(0, 552); + this.panel5.Name = "panel5"; + this.panel5.Size = new System.Drawing.Size(1043, 100); + this.panel5.TabIndex = 1; + // + // btn_dataAnalyse + // + this.btn_dataAnalyse.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(168)))), ((int)(((byte)(255))))); + this.btn_dataAnalyse.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_dataAnalyse.Location = new System.Drawing.Point(792, 35); + this.btn_dataAnalyse.Name = "btn_dataAnalyse"; + this.btn_dataAnalyse.Size = new System.Drawing.Size(119, 32); + this.btn_dataAnalyse.TabIndex = 23; + this.btn_dataAnalyse.Text = "数据分析"; + this.btn_dataAnalyse.UseVisualStyleBackColor = false; + // + // btn_ledEnvironment1 + // + this.btn_ledEnvironment1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(86)))), ((int)(((byte)(149)))), ((int)(((byte)(212))))); + this.btn_ledEnvironment1.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledEnvironment1.Location = new System.Drawing.Point(910, 35); + this.btn_ledEnvironment1.Name = "btn_ledEnvironment1"; + this.btn_ledEnvironment1.Size = new System.Drawing.Size(121, 32); + this.btn_ledEnvironment1.TabIndex = 15; + this.btn_ledEnvironment1.Text = "推送天气信息"; + this.btn_ledEnvironment1.UseVisualStyleBackColor = false; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("微软雅黑", 18F); + this.label6.Location = new System.Drawing.Point(12, 31); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(110, 31); + this.label6.TabIndex = 11; + this.label6.Text = "环境数据"; + // + // txt_humidity + // + this.txt_humidity.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_humidity.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_humidity.Location = new System.Drawing.Point(716, 36); + this.txt_humidity.Name = "txt_humidity"; + this.txt_humidity.Size = new System.Drawing.Size(70, 32); + this.txt_humidity.TabIndex = 22; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label1.Location = new System.Drawing.Point(132, 38); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(50, 25); + this.label1.TabIndex = 12; + this.label1.Text = "火焰"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label5.Location = new System.Drawing.Point(660, 39); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(50, 25); + this.label5.TabIndex = 21; + this.label5.Text = "湿度"; + // + // txt_fire + // + this.txt_fire.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_fire.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_fire.Location = new System.Drawing.Point(188, 35); + this.txt_fire.Name = "txt_fire"; + this.txt_fire.Size = new System.Drawing.Size(70, 32); + this.txt_fire.TabIndex = 13; + // + // txt_temperature + // + this.txt_temperature.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_temperature.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_temperature.Location = new System.Drawing.Point(584, 35); + this.txt_temperature.Name = "txt_temperature"; + this.txt_temperature.Size = new System.Drawing.Size(70, 32); + this.txt_temperature.TabIndex = 20; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label2.Location = new System.Drawing.Point(264, 36); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(50, 25); + this.label2.TabIndex = 14; + this.label2.Text = "烟雾"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label4.Location = new System.Drawing.Point(528, 38); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(50, 25); + this.label4.TabIndex = 19; + this.label4.Text = "温度"; + // + // txt_smoke + // + this.txt_smoke.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_smoke.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_smoke.Location = new System.Drawing.Point(320, 33); + this.txt_smoke.Name = "txt_smoke"; + this.txt_smoke.Size = new System.Drawing.Size(70, 32); + this.txt_smoke.TabIndex = 16; + // + // txt_light + // + this.txt_light.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_light.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_light.Location = new System.Drawing.Point(452, 32); + this.txt_light.Name = "txt_light"; + this.txt_light.Size = new System.Drawing.Size(70, 32); + this.txt_light.TabIndex = 18; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label3.Location = new System.Drawing.Point(396, 35); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(50, 25); + this.label3.TabIndex = 17; + this.label3.Text = "光照"; + // + // panel3 + // + this.panel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(229)))), ((int)(((byte)(229))))); + this.panel3.Controls.Add(this.lb_return); + this.panel3.Dock = System.Windows.Forms.DockStyle.Top; + this.panel3.Location = new System.Drawing.Point(0, 0); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(1043, 39); + this.panel3.TabIndex = 0; + this.panel3.Paint += new System.Windows.Forms.PaintEventHandler(this.panel3_Paint); + // + // lb_return + // + this.lb_return.AutoSize = true; + this.lb_return.Location = new System.Drawing.Point(25, 12); + this.lb_return.Name = "lb_return"; + this.lb_return.Size = new System.Drawing.Size(83, 12); + this.lb_return.TabIndex = 0; + this.lb_return.Text = "< 返回主窗体"; + this.lb_return.Click += new System.EventHandler(this.lb_return_Click); + // + // Environment + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1043, 791); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Environment"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Environment"; + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel2.ResumeLayout(false); + this.panel_bg.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + this.panel_form.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_lampOpen)).EndInit(); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.panel5.ResumeLayout(false); + this.panel5.PerformLayout(); + this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Label lb_return; + private System.Windows.Forms.Panel panel_bg; + private System.Windows.Forms.Panel panel5; + private System.Windows.Forms.Panel panel_form; + private System.Windows.Forms.Button btn_dataAnalyse; + private System.Windows.Forms.Button btn_ledEnvironment1; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox txt_humidity; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txt_fire; + private System.Windows.Forms.TextBox txt_temperature; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox txt_smoke; + private System.Windows.Forms.TextBox txt_light; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.PictureBox pic_lampOpen; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.TextBox txt_autoLight; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.CheckBox ch_autoLamp; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.Button btn_ledEnvironment2; + private System.Windows.Forms.CheckBox ch_autoLedFire; + private System.Windows.Forms.Button btn_ledSendMsg; + private System.Windows.Forms.TextBox txt_ledMsg; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + } +} \ No newline at end of file diff --git a/samples/p8-t2-校园环境界面/Environment.cs b/samples/p8-t2-校园环境界面/Environment.cs new file mode 100644 index 0000000..9b386a7 --- /dev/null +++ b/samples/p8-t2-校园环境界面/Environment.cs @@ -0,0 +1,35 @@ +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; + +namespace 智慧校园 +{ + public partial class Environment : Form + { + public Environment() + { + InitializeComponent(); + } + + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void lb_return_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void panel3_Paint(object sender, PaintEventArgs e) + { + + } + } +} diff --git a/samples/p8-t2-校园环境界面/Main.Designer.cs b/samples/p8-t2-校园环境界面/Main.Designer.cs new file mode 100644 index 0000000..4b2afe5 --- /dev/null +++ b/samples/p8-t2-校园环境界面/Main.Designer.cs @@ -0,0 +1,143 @@ +namespace 智慧校园 +{ + partial class Main + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.pic_exit = new System.Windows.Forms.PictureBox(); + this.pic_security = new System.Windows.Forms.PictureBox(); + this.pic_environment = new System.Windows.Forms.PictureBox(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_exit)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_security)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_environment)).BeginInit(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(53)))), ((int)(((byte)(147)))), ((int)(((byte)(237))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1018, 100); + this.panel1.TabIndex = 0; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(57, 23); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(197, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel2 + // + this.panel2.BackgroundImage = global::智慧校园.Properties.Resources.bg_home; + this.panel2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel2.Controls.Add(this.pic_exit); + this.panel2.Controls.Add(this.pic_security); + this.panel2.Controls.Add(this.pic_environment); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 100); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(1018, 516); + this.panel2.TabIndex = 1; + this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint); + // + // pic_exit + // + this.pic_exit.BackColor = System.Drawing.Color.Transparent; + this.pic_exit.Image = global::智慧校园.Properties.Resources.icon_04; + this.pic_exit.Location = new System.Drawing.Point(660, 124); + this.pic_exit.Name = "pic_exit"; + this.pic_exit.Size = new System.Drawing.Size(180, 210); + this.pic_exit.TabIndex = 6; + this.pic_exit.TabStop = false; + this.pic_exit.Click += new System.EventHandler(this.pic_exit_Click); + // + // pic_security + // + this.pic_security.BackColor = System.Drawing.Color.Transparent; + this.pic_security.Image = global::智慧校园.Properties.Resources.icon_03; + this.pic_security.Location = new System.Drawing.Point(404, 124); + this.pic_security.Name = "pic_security"; + this.pic_security.Size = new System.Drawing.Size(180, 210); + this.pic_security.TabIndex = 5; + this.pic_security.TabStop = false; + // + // pic_environment + // + this.pic_environment.BackColor = System.Drawing.Color.Transparent; + this.pic_environment.Image = global::智慧校园.Properties.Resources.icon_02; + this.pic_environment.Location = new System.Drawing.Point(133, 124); + this.pic_environment.Name = "pic_environment"; + this.pic_environment.Size = new System.Drawing.Size(180, 210); + this.pic_environment.TabIndex = 4; + this.pic_environment.TabStop = false; + this.pic_environment.Click += new System.EventHandler(this.pic_environment_Click); + // + // Main + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1018, 616); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Main"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pic_exit)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_security)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_environment)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.PictureBox pic_exit; + private System.Windows.Forms.PictureBox pic_security; + private System.Windows.Forms.PictureBox pic_environment; + } +} + diff --git a/samples/p8-t2-校园环境界面/Main.cs b/samples/p8-t2-校园环境界面/Main.cs new file mode 100644 index 0000000..094140b --- /dev/null +++ b/samples/p8-t2-校园环境界面/Main.cs @@ -0,0 +1,46 @@ +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; +namespace 智慧校园 +{ + public partial class Main : Form + { + public Main() + { + InitializeComponent(); + } + + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void pic_environment_Click(object sender, EventArgs e) + { + try + { + new Environment().Show(); + + } + catch + { + } + } + + private void panel2_Paint(object sender, PaintEventArgs e) + { + + } + + private void pic_exit_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/samples/p8-t2-校园环境界面/Program.cs b/samples/p8-t2-校园环境界面/Program.cs new file mode 100644 index 0000000..2fd691b --- /dev/null +++ b/samples/p8-t2-校园环境界面/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 智慧校园 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Main()); + } + } +} diff --git a/samples/p8-t2-校园环境界面/Properties/Resources.Designer.cs b/samples/p8-t2-校园环境界面/Properties/Resources.Designer.cs new file mode 100644 index 0000000..b8bb5c1 --- /dev/null +++ b/samples/p8-t2-校园环境界面/Properties/Resources.Designer.cs @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// 项目资源(平台素材库)。在"项目资源"里添加或移除,不要手动修改这个文件。 +// +//------------------------------------------------------------------------------ + +namespace 智慧校园.Properties { + + /// + /// 项目资源:Properties.Resources.资源名 + /// + internal class Resources { + + /// 标题:智慧校园 + internal static System.Drawing.Bitmap ico_title { + get { return global::Sim.Host.ProjectResources.Image("ico_title.png"); } + } + + /// 主界面背景:校园 + internal static System.Drawing.Bitmap bg_home { + get { return global::Sim.Host.ProjectResources.Image("bg_home.png"); } + } + + /// 图标:校园环境 + internal static System.Drawing.Bitmap icon_02 { + get { return global::Sim.Host.ProjectResources.Image("icon_02.png"); } + } + + /// 图标:校园安防 + internal static System.Drawing.Bitmap icon_03 { + get { return global::Sim.Host.ProjectResources.Image("icon_03.png"); } + } + + /// 图标:退出 + internal static System.Drawing.Bitmap icon_04 { + get { return global::Sim.Host.ProjectResources.Image("icon_04.png"); } + } + + /// 路灯场景:灭灯 + internal static System.Drawing.Bitmap day_02 { + get { return global::Sim.Host.ProjectResources.Image("day_02.png"); } + } + + /// 面板背景(窄) + internal static System.Drawing.Bitmap bg_from2 { + get { return global::Sim.Host.ProjectResources.Image("bg_from2.png"); } + } + + /// 开关:关 + internal static System.Drawing.Bitmap switch_off { + get { return global::Sim.Host.ProjectResources.Image("switch_off.png"); } + } + } +} diff --git a/samples/p8-t2-校园环境界面/checks.yaml b/samples/p8-t2-校园环境界面/checks.yaml new file mode 100644 index 0000000..a26c7ff --- /dev/null +++ b/samples/p8-t2-校园环境界面/checks.yaml @@ -0,0 +1,38 @@ +# 评分规则:书上评价表的功能项。每项单独启动一次程序,按步骤操作,核对结果。 +# 格式说明见 server/src/grading/checks.ts +- title: 主界面能打开"校园环境"界面 + steps: + - click: pic_environment + - expect: { window: Environment, desc: 点"校园环境"打开 Environment 窗体 } + - expect: { control: panel_bg, background: day_02, desc: 背景是路灯场景(day_02) } + +- title: 界面有环境数据栏 + steps: + - click: pic_environment + - expect: { control: txt_fire, visible: true } + - expect: { control: txt_smoke, visible: true } + - expect: { control: txt_light, visible: true } + - expect: { control: txt_temperature, visible: true } + - expect: { control: txt_humidity, visible: true } + - expect: { control: btn_dataAnalyse, text: 数据分析 } + - expect: { control: btn_ledEnvironment1, text: 推送天气信息 } + +- title: 界面有路灯控制、LED 推送和图表 + steps: + - click: pic_environment + - expect: { control: ch_autoLamp, text: 自动控制 } + - expect: { control: txt_autoLight, visible: true } + - expect: { control: pic_lampOpen, background: switch_off, desc: 灯光控制显示"关"的开关图片(switch_off) } + - expect: { control: ch_autoLedFire, text: 自动推送火情 } + - expect: { control: txt_ledMsg, visible: true } + - expect: { control: btn_ledSendMsg, text: 推送LED信息 } + - expect: { control: btn_ledEnvironment2, text: 推送天气信息 } + - expect: { control: chart1, visible: true } + +- title: 能返回主窗体 + steps: + - click: pic_environment + - expect: { window: Environment } + - click: lb_return + - expect: { window: Environment, open: false, desc: 点"<返回主窗体"关闭 Environment 窗体 } + - expect: { window: Main, desc: 主窗体还在 } diff --git a/samples/p8-t2-校园环境界面/meta.json b/samples/p8-t2-校园环境界面/meta.json new file mode 100644 index 0000000..618662c --- /dev/null +++ b/samples/p8-t2-校园环境界面/meta.json @@ -0,0 +1,4 @@ +{ + "title": "项目8 任务2 制作\"校园环境\"界面", + "source": "教材书 p159–164,界面和代码取自配套参考工程;图片是平台素材库里自绘的同名素材(尺寸和教材一致);本任务只做界面,为了能看效果,加上了主界面\"校园环境\"打开窗体和\"<返回主窗体\"关闭窗体(书上在任务 3 第 10、22 步)" +} diff --git a/samples/p8-t3-环境采集与分析/AppSet.cs b/samples/p8-t3-环境采集与分析/AppSet.cs new file mode 100644 index 0000000..394d13f --- /dev/null +++ b/samples/p8-t3-环境采集与分析/AppSet.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 智慧校园 +{ + class AppSet + { + //串口设置 + public static string ADAM4017_COM = "COM2"; + public static string ADAM4150_COM = "COM3"; + public static string LED_COM = "COM5"; + public static string ZigBee_COM = "COM4"; + + //摄像机参数 + public static string Camera_Ip = "192.168.1.100"; + public static string Camera_Uid = "admin"; + public static string Camera_Pwd = ""; + + //数据库连接字符串 + public static string SqlConn = "Data Source=.;Initial Catalog=WisdomCampus;User ID=sa;Password=123"; + } +} diff --git a/samples/p8-t3-环境采集与分析/Environment.Designer.cs b/samples/p8-t3-环境采集与分析/Environment.Designer.cs new file mode 100644 index 0000000..856107d --- /dev/null +++ b/samples/p8-t3-环境采集与分析/Environment.Designer.cs @@ -0,0 +1,555 @@ +namespace 智慧校园 +{ + partial class Environment + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Legend legend4 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.panel_bg = new System.Windows.Forms.Panel(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.panel_form = new System.Windows.Forms.Panel(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.pic_lampOpen = new System.Windows.Forms.PictureBox(); + this.label10 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.txt_autoLight = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.ch_autoLamp = new System.Windows.Forms.CheckBox(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.btn_ledEnvironment2 = new System.Windows.Forms.Button(); + this.ch_autoLedFire = new System.Windows.Forms.CheckBox(); + this.btn_ledSendMsg = new System.Windows.Forms.Button(); + this.txt_ledMsg = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.panel5 = new System.Windows.Forms.Panel(); + this.btn_dataAnalyse = new System.Windows.Forms.Button(); + this.btn_ledEnvironment1 = new System.Windows.Forms.Button(); + this.label6 = new System.Windows.Forms.Label(); + this.txt_humidity = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.txt_fire = new System.Windows.Forms.TextBox(); + this.txt_temperature = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.txt_smoke = new System.Windows.Forms.TextBox(); + this.txt_light = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.panel3 = new System.Windows.Forms.Panel(); + this.lb_return = new System.Windows.Forms.Label(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel2.SuspendLayout(); + this.panel_bg.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + this.panel_form.SuspendLayout(); + this.groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_lampOpen)).BeginInit(); + this.groupBox3.SuspendLayout(); + this.panel5.SuspendLayout(); + this.panel3.SuspendLayout(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(116)))), ((int)(((byte)(133))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1043, 100); + this.panel1.TabIndex = 0; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(44, 12); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(226, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel2 + // + this.panel2.Controls.Add(this.panel_bg); + this.panel2.Controls.Add(this.panel3); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 100); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(1043, 691); + this.panel2.TabIndex = 1; + // + // panel_bg + // + this.panel_bg.BackgroundImage = global::智慧校园.Properties.Resources.day_02; + this.panel_bg.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel_bg.Controls.Add(this.chart1); + this.panel_bg.Controls.Add(this.panel_form); + this.panel_bg.Controls.Add(this.panel5); + this.panel_bg.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel_bg.Location = new System.Drawing.Point(0, 39); + this.panel_bg.Name = "panel_bg"; + this.panel_bg.Size = new System.Drawing.Size(1043, 652); + this.panel_bg.TabIndex = 1; + // + // chart1 + // + chartArea2.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea2); + legend3.Name = "MaxLegend"; + legend3.TitleForeColor = System.Drawing.Color.DimGray; + legend4.Name = "AVGLegend"; + legend4.TitleForeColor = System.Drawing.Color.DimGray; + this.chart1.Legends.Add(legend3); + this.chart1.Legends.Add(legend4); + this.chart1.Location = new System.Drawing.Point(44, 172); + this.chart1.Name = "chart1"; + series3.ChartArea = "ChartArea1"; + series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series3.Legend = "MaxLegend"; + series3.LegendText = "最大值"; + series3.Name = "MaxSeries"; + series3.XValueMember = "_Time"; + series3.YValueMembers = "MaxTemperature"; + series4.ChartArea = "ChartArea1"; + series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series4.Legend = "AVGLegend"; + series4.LegendText = "平均值"; + series4.Name = "AVGSeries"; + series4.XValueMember = "_Time"; + series4.YValueMembers = "AVGTemperature"; + this.chart1.Series.Add(series3); + this.chart1.Series.Add(series4); + this.chart1.Size = new System.Drawing.Size(455, 327); + this.chart1.TabIndex = 3; + this.chart1.Text = "chart1"; + // + // panel_form + // + this.panel_form.BackColor = System.Drawing.Color.Transparent; + this.panel_form.BackgroundImage = global::智慧校园.Properties.Resources.bg_from2; + this.panel_form.Controls.Add(this.groupBox2); + this.panel_form.Controls.Add(this.groupBox3); + this.panel_form.Dock = System.Windows.Forms.DockStyle.Right; + this.panel_form.Location = new System.Drawing.Point(617, 0); + this.panel_form.Name = "panel_form"; + this.panel_form.Size = new System.Drawing.Size(426, 552); + this.panel_form.TabIndex = 2; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.pic_lampOpen); + this.groupBox2.Controls.Add(this.label10); + this.groupBox2.Controls.Add(this.label9); + this.groupBox2.Controls.Add(this.txt_autoLight); + this.groupBox2.Controls.Add(this.label7); + this.groupBox2.Controls.Add(this.ch_autoLamp); + this.groupBox2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.groupBox2.ForeColor = System.Drawing.Color.White; + this.groupBox2.Location = new System.Drawing.Point(22, 21); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(392, 150); + this.groupBox2.TabIndex = 3; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "路灯控制"; + // + // pic_lampOpen + // + this.pic_lampOpen.BackgroundImage = global::智慧校园.Properties.Resources.switch_off; + this.pic_lampOpen.Location = new System.Drawing.Point(103, 103); + this.pic_lampOpen.Name = "pic_lampOpen"; + this.pic_lampOpen.Size = new System.Drawing.Size(48, 24); + this.pic_lampOpen.TabIndex = 5; + this.pic_lampOpen.TabStop = false; + this.pic_lampOpen.Click += new System.EventHandler(this.pic_lampOpen_Click); + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(33, 105); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(59, 17); + this.label10.TabIndex = 4; + this.label10.Text = "灯光控制:"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(278, 58); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(17, 17); + this.label9.TabIndex = 3; + this.label9.Text = "lx"; + // + // txt_autoLight + // + this.txt_autoLight.Location = new System.Drawing.Point(128, 55); + this.txt_autoLight.Name = "txt_autoLight"; + this.txt_autoLight.Size = new System.Drawing.Size(144, 23); + this.txt_autoLight.TabIndex = 2; + this.txt_autoLight.TextChanged += new System.EventHandler(this.txt_autoLight_TextChanged); + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(33, 58); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(92, 17); + this.label7.TabIndex = 1; + this.label7.Text = "设定开灯光照值"; + // + // ch_autoLamp + // + this.ch_autoLamp.AutoSize = true; + this.ch_autoLamp.Location = new System.Drawing.Point(35, 30); + this.ch_autoLamp.Name = "ch_autoLamp"; + this.ch_autoLamp.Size = new System.Drawing.Size(75, 21); + this.ch_autoLamp.TabIndex = 0; + this.ch_autoLamp.Text = "自动控制"; + this.ch_autoLamp.UseVisualStyleBackColor = true; + this.ch_autoLamp.CheckedChanged += new System.EventHandler(this.ch_autoLamp_CheckedChanged); + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.btn_ledEnvironment2); + this.groupBox3.Controls.Add(this.ch_autoLedFire); + this.groupBox3.Controls.Add(this.btn_ledSendMsg); + this.groupBox3.Controls.Add(this.txt_ledMsg); + this.groupBox3.Controls.Add(this.label8); + this.groupBox3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.groupBox3.ForeColor = System.Drawing.Color.White; + this.groupBox3.Location = new System.Drawing.Point(22, 209); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(392, 316); + this.groupBox3.TabIndex = 4; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "LED推送"; + // + // btn_ledEnvironment2 + // + this.btn_ledEnvironment2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(86)))), ((int)(((byte)(149)))), ((int)(((byte)(212))))); + this.btn_ledEnvironment2.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledEnvironment2.Location = new System.Drawing.Point(234, 217); + this.btn_ledEnvironment2.Name = "btn_ledEnvironment2"; + this.btn_ledEnvironment2.Size = new System.Drawing.Size(145, 32); + this.btn_ledEnvironment2.TabIndex = 11; + this.btn_ledEnvironment2.Text = "推送天气信息"; + this.btn_ledEnvironment2.UseVisualStyleBackColor = false; + this.btn_ledEnvironment2.Click += new System.EventHandler(this.btn_ledEnvironment2_Click); + // + // ch_autoLedFire + // + this.ch_autoLedFire.AutoSize = true; + this.ch_autoLedFire.Location = new System.Drawing.Point(265, 35); + this.ch_autoLedFire.Name = "ch_autoLedFire"; + this.ch_autoLedFire.Size = new System.Drawing.Size(99, 21); + this.ch_autoLedFire.TabIndex = 4; + this.ch_autoLedFire.Text = "自动推送火情"; + this.ch_autoLedFire.UseVisualStyleBackColor = true; + this.ch_autoLedFire.CheckedChanged += new System.EventHandler(this.ch_autoLedFire_CheckedChanged); + // + // btn_ledSendMsg + // + this.btn_ledSendMsg.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(168)))), ((int)(((byte)(255))))); + this.btn_ledSendMsg.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledSendMsg.Location = new System.Drawing.Point(26, 217); + this.btn_ledSendMsg.Name = "btn_ledSendMsg"; + this.btn_ledSendMsg.Size = new System.Drawing.Size(145, 32); + this.btn_ledSendMsg.TabIndex = 2; + this.btn_ledSendMsg.Text = "推送LED信息"; + this.btn_ledSendMsg.UseVisualStyleBackColor = false; + this.btn_ledSendMsg.Click += new System.EventHandler(this.btn_ledSendMsg_Click); + // + // txt_ledMsg + // + this.txt_ledMsg.Location = new System.Drawing.Point(23, 62); + this.txt_ledMsg.Multiline = true; + this.txt_ledMsg.Name = "txt_ledMsg"; + this.txt_ledMsg.Size = new System.Drawing.Size(356, 130); + this.txt_ledMsg.TabIndex = 1; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(20, 36); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(54, 17); + this.label8.TabIndex = 0; + this.label8.Text = "LED信息"; + // + // panel5 + // + this.panel5.Controls.Add(this.btn_dataAnalyse); + this.panel5.Controls.Add(this.btn_ledEnvironment1); + this.panel5.Controls.Add(this.label6); + this.panel5.Controls.Add(this.txt_humidity); + this.panel5.Controls.Add(this.label1); + this.panel5.Controls.Add(this.label5); + this.panel5.Controls.Add(this.txt_fire); + this.panel5.Controls.Add(this.txt_temperature); + this.panel5.Controls.Add(this.label2); + this.panel5.Controls.Add(this.label4); + this.panel5.Controls.Add(this.txt_smoke); + this.panel5.Controls.Add(this.txt_light); + this.panel5.Controls.Add(this.label3); + this.panel5.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel5.Location = new System.Drawing.Point(0, 552); + this.panel5.Name = "panel5"; + this.panel5.Size = new System.Drawing.Size(1043, 100); + this.panel5.TabIndex = 1; + // + // btn_dataAnalyse + // + this.btn_dataAnalyse.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(168)))), ((int)(((byte)(255))))); + this.btn_dataAnalyse.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_dataAnalyse.Location = new System.Drawing.Point(792, 35); + this.btn_dataAnalyse.Name = "btn_dataAnalyse"; + this.btn_dataAnalyse.Size = new System.Drawing.Size(119, 32); + this.btn_dataAnalyse.TabIndex = 23; + this.btn_dataAnalyse.Text = "数据分析"; + this.btn_dataAnalyse.UseVisualStyleBackColor = false; + this.btn_dataAnalyse.Click += new System.EventHandler(this.btn_dataAnalyse_Click); + // + // btn_ledEnvironment1 + // + this.btn_ledEnvironment1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(86)))), ((int)(((byte)(149)))), ((int)(((byte)(212))))); + this.btn_ledEnvironment1.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledEnvironment1.Location = new System.Drawing.Point(910, 35); + this.btn_ledEnvironment1.Name = "btn_ledEnvironment1"; + this.btn_ledEnvironment1.Size = new System.Drawing.Size(121, 32); + this.btn_ledEnvironment1.TabIndex = 15; + this.btn_ledEnvironment1.Text = "推送天气信息"; + this.btn_ledEnvironment1.UseVisualStyleBackColor = false; + this.btn_ledEnvironment1.Click += new System.EventHandler(this.btn_ledEnvironment1_Click); + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("微软雅黑", 18F); + this.label6.Location = new System.Drawing.Point(12, 31); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(110, 31); + this.label6.TabIndex = 11; + this.label6.Text = "环境数据"; + // + // txt_humidity + // + this.txt_humidity.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_humidity.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_humidity.Location = new System.Drawing.Point(716, 36); + this.txt_humidity.Name = "txt_humidity"; + this.txt_humidity.Size = new System.Drawing.Size(70, 32); + this.txt_humidity.TabIndex = 22; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label1.Location = new System.Drawing.Point(132, 38); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(50, 25); + this.label1.TabIndex = 12; + this.label1.Text = "火焰"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label5.Location = new System.Drawing.Point(660, 39); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(50, 25); + this.label5.TabIndex = 21; + this.label5.Text = "湿度"; + // + // txt_fire + // + this.txt_fire.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_fire.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_fire.Location = new System.Drawing.Point(188, 35); + this.txt_fire.Name = "txt_fire"; + this.txt_fire.Size = new System.Drawing.Size(70, 32); + this.txt_fire.TabIndex = 13; + // + // txt_temperature + // + this.txt_temperature.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_temperature.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_temperature.Location = new System.Drawing.Point(584, 35); + this.txt_temperature.Name = "txt_temperature"; + this.txt_temperature.Size = new System.Drawing.Size(70, 32); + this.txt_temperature.TabIndex = 20; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label2.Location = new System.Drawing.Point(264, 36); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(50, 25); + this.label2.TabIndex = 14; + this.label2.Text = "烟雾"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label4.Location = new System.Drawing.Point(528, 38); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(50, 25); + this.label4.TabIndex = 19; + this.label4.Text = "温度"; + // + // txt_smoke + // + this.txt_smoke.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_smoke.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_smoke.Location = new System.Drawing.Point(320, 33); + this.txt_smoke.Name = "txt_smoke"; + this.txt_smoke.Size = new System.Drawing.Size(70, 32); + this.txt_smoke.TabIndex = 16; + // + // txt_light + // + this.txt_light.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_light.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_light.Location = new System.Drawing.Point(452, 32); + this.txt_light.Name = "txt_light"; + this.txt_light.Size = new System.Drawing.Size(70, 32); + this.txt_light.TabIndex = 18; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label3.Location = new System.Drawing.Point(396, 35); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(50, 25); + this.label3.TabIndex = 17; + this.label3.Text = "光照"; + // + // panel3 + // + this.panel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(229)))), ((int)(((byte)(229))))); + this.panel3.Controls.Add(this.lb_return); + this.panel3.Dock = System.Windows.Forms.DockStyle.Top; + this.panel3.Location = new System.Drawing.Point(0, 0); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(1043, 39); + this.panel3.TabIndex = 0; + this.panel3.Paint += new System.Windows.Forms.PaintEventHandler(this.panel3_Paint); + // + // lb_return + // + this.lb_return.AutoSize = true; + this.lb_return.Location = new System.Drawing.Point(25, 12); + this.lb_return.Name = "lb_return"; + this.lb_return.Size = new System.Drawing.Size(83, 12); + this.lb_return.TabIndex = 0; + this.lb_return.Text = "< 返回主窗体"; + this.lb_return.Click += new System.EventHandler(this.lb_return_Click); + // + // Environment + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1043, 791); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Environment"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Environment"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Environment_FormClosed); + this.Load += new System.EventHandler(this.Environment_Load); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel2.ResumeLayout(false); + this.panel_bg.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + this.panel_form.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_lampOpen)).EndInit(); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.panel5.ResumeLayout(false); + this.panel5.PerformLayout(); + this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Label lb_return; + private System.Windows.Forms.Panel panel_bg; + private System.Windows.Forms.Panel panel5; + private System.Windows.Forms.Panel panel_form; + private System.Windows.Forms.Button btn_dataAnalyse; + private System.Windows.Forms.Button btn_ledEnvironment1; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox txt_humidity; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txt_fire; + private System.Windows.Forms.TextBox txt_temperature; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox txt_smoke; + private System.Windows.Forms.TextBox txt_light; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.PictureBox pic_lampOpen; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.TextBox txt_autoLight; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.CheckBox ch_autoLamp; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.Button btn_ledEnvironment2; + private System.Windows.Forms.CheckBox ch_autoLedFire; + private System.Windows.Forms.Button btn_ledSendMsg; + private System.Windows.Forms.TextBox txt_ledMsg; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + } +} \ No newline at end of file diff --git a/samples/p8-t3-环境采集与分析/Environment.cs b/samples/p8-t3-环境采集与分析/Environment.cs new file mode 100644 index 0000000..c136074 --- /dev/null +++ b/samples/p8-t3-环境采集与分析/Environment.cs @@ -0,0 +1,279 @@ +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 DeviceCtrlLibrary; +using DeviceCtrlLibrary.Model; +using 智慧校园.SQLHelpers; +using System.Threading; + +namespace 智慧校园 +{ + public partial class Environment : Form + { + public Environment() + { + InitializeComponent(); + } + //用于各类耗时长的操作(SQL、数据采集、设备控制等) + Thread thread; + //用于异步通行 + SynchronizationContext _main; + //结果模型 + ADAM4017ResModel ResModel_4017; + ADAM4150ResModel ResModel_4150; + //设置自动控制路灯的光照值 + double environmentLight, setLight; + //按钮状态标志 + bool IsAuto_Lamp = false; + bool IsAuto_FireMsg = false; + bool IsLampOpen = false; + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void lb_return_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void Environment_Load(object sender, EventArgs e) + { + try + { + + //隐藏曲线图 + chart1.Visible = false; + thread = new Thread(new ThreadStart(Tick)); + _main = WindowsFormsSynchronizationContext.Current; + thread.Start(); + } + catch + { + } + + } + private void Tick() + { + try + { + while (true) + { + //数据采集 + ResModel_4017 = DeviceCtrlHelper.adam4017Helper.SetData(); + Thread.Sleep(500); + ResModel_4150 = DeviceCtrlHelper.adam4150Helper.SetData(); + + //UI显示数据 + + _main.Send(_ => + { + try //防止无数据出错 + { + txt_fire.Text = (ResModel_4150.fireValue ? "发生火情" : "正常"); + txt_smoke.Text = (ResModel_4150.smokeValue ? "发生烟情" : "正常"); + txt_light.Text = ResModel_4017.lightValue; + txt_temperature.Text = ResModel_4017.temperatureValue; + txt_humidity.Text = ResModel_4017.humidityValue; + } + catch { } + }, null); + + //自动路灯控制 + double.TryParse(ResModel_4017.lightValue, out environmentLight); + if (IsAuto_Lamp && environmentLight < setLight) + { + LampOnOff(1, true); + } + else if (IsAuto_Lamp && !(environmentLight < setLight)) + { + LampOnOff(1, false); + } + + //自动推送火情LED信息控制 + if (IsAuto_FireMsg) + { + if (ResModel_4150.fireValue && ResModel_4150.smokeValue) + DeviceCtrlHelper.ledHelper.SendLedString("发生严重火灾 "); + else if (ResModel_4150.fireValue) + DeviceCtrlHelper.ledHelper.SendLedString("发现火情 "); + else if (ResModel_4150.smokeValue) + DeviceCtrlHelper.ledHelper.SendLedString("发现烟情 "); + } + + //执行数据上传 + SQLBLL.EnvironmentUpData(ResModel_4150.fireValue, ResModel_4150.smokeValue, ResModel_4017.lightValue, ResModel_4017.temperatureValue, ResModel_4017.humidityValue); + + Thread.Sleep(5000); + } + } + catch + { + } + } + private void LampOnOff(int RelayNum, bool IsOpen) + { + try + { + //开启路灯 + DeviceCtrlHelper.zigBeeHelper.OnOff(RelayNum, IsOpen); + + //切换UI背景 + _main.Send(_ => + { + if (IsOpen) + { + pic_lampOpen.BackgroundImage = Properties.Resources.switch_on; + panel_bg.BackgroundImage = Properties.Resources.day_01; + } + else + { + panel_bg.BackgroundImage = Properties.Resources.day_02; + pic_lampOpen.BackgroundImage = Properties.Resources.switch_off; + } + }, null); + } + catch + { + } + } + + private void Environment_FormClosed(object sender, FormClosedEventArgs e) + { + try + { + thread.Suspend(); + thread = null; + + } + catch + { + } + + + } + + private void btn_dataAnalyse_Click(object sender, EventArgs e) + { + try + { + if (btn_dataAnalyse.Text.Equals("数据分析")) + { + //绑定图标数据 + chart1.DataSource = SQLBLL.GetEnvironmentGraphData(); + //更新图标数据 + chart1.DataBind(); + chart1.Visible = true; + btn_dataAnalyse.Text = "关闭图表"; + } + else if (btn_dataAnalyse.Text.Equals("关闭图表")) + { + chart1.Visible = false; + btn_dataAnalyse.Text = "数据分析"; + } + } + catch + { + } + + } + + private void pic_lampOpen_Click(object sender, EventArgs e) + { + //手动路灯控制 + try + { + if (!IsLampOpen) + { + LampOnOff(1, true); + + } + else + { + LampOnOff(1, false); + + } + + IsLampOpen = !IsLampOpen; + } + catch + { + } + } + + private void btn_ledEnvironment1_Click(object sender, EventArgs e) + { + try + { + //推送LED天气信息 + if (ResModel_4017 != null && ResModel_4150 != null) + DeviceCtrlHelper.ledHelper.SendLedString("当前温度:" + ResModel_4017.temperatureValue + "℃ 湿度:" + ResModel_4017.humidityValue + "%"); + } + catch + { + } + } + + private void btn_ledEnvironment2_Click(object sender, EventArgs e) + { + try + { + //推送LED天气信息 + if (ResModel_4017 != null && ResModel_4150 != null) + DeviceCtrlHelper.ledHelper.SendLedString("当前温度:" + ResModel_4017.temperatureValue + "℃ 湿度:" + ResModel_4017.humidityValue + "%"); + } + catch + { + } + } + + private void panel3_Paint(object sender, PaintEventArgs e) + { + + } + + private void txt_autoLight_TextChanged(object sender, EventArgs e) + { + try + { + //获取光照比较值 + double.TryParse(txt_autoLight.Text,out setLight); + + } + + catch + { + } + } + + private void btn_ledSendMsg_Click(object sender, EventArgs e) + { + try + { + //推送LED信息 + DeviceCtrlHelper.ledHelper.SendLedString(txt_ledMsg.Text); + } + catch + { + } + } + + private void ch_autoLamp_CheckedChanged(object sender, EventArgs e) + { + //自动控制路灯 + IsAuto_Lamp = ch_autoLamp.Checked; + } + + private void ch_autoLedFire_CheckedChanged(object sender, EventArgs e) + { + //自动推送火情 + IsAuto_FireMsg = ch_autoLedFire.Checked; + } + } +} diff --git a/samples/p8-t3-环境采集与分析/Main.Designer.cs b/samples/p8-t3-环境采集与分析/Main.Designer.cs new file mode 100644 index 0000000..d3e22a1 --- /dev/null +++ b/samples/p8-t3-环境采集与分析/Main.Designer.cs @@ -0,0 +1,144 @@ +namespace 智慧校园 +{ + partial class Main + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.pic_exit = new System.Windows.Forms.PictureBox(); + this.pic_security = new System.Windows.Forms.PictureBox(); + this.pic_environment = new System.Windows.Forms.PictureBox(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_exit)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_security)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_environment)).BeginInit(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(53)))), ((int)(((byte)(147)))), ((int)(((byte)(237))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1018, 100); + this.panel1.TabIndex = 0; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(57, 23); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(197, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel2 + // + this.panel2.BackgroundImage = global::智慧校园.Properties.Resources.bg_home; + this.panel2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel2.Controls.Add(this.pic_exit); + this.panel2.Controls.Add(this.pic_security); + this.panel2.Controls.Add(this.pic_environment); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 100); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(1018, 516); + this.panel2.TabIndex = 1; + this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint); + // + // pic_exit + // + this.pic_exit.BackColor = System.Drawing.Color.Transparent; + this.pic_exit.Image = global::智慧校园.Properties.Resources.icon_04; + this.pic_exit.Location = new System.Drawing.Point(660, 124); + this.pic_exit.Name = "pic_exit"; + this.pic_exit.Size = new System.Drawing.Size(180, 210); + this.pic_exit.TabIndex = 6; + this.pic_exit.TabStop = false; + this.pic_exit.Click += new System.EventHandler(this.pic_exit_Click); + // + // pic_security + // + this.pic_security.BackColor = System.Drawing.Color.Transparent; + this.pic_security.Image = global::智慧校园.Properties.Resources.icon_03; + this.pic_security.Location = new System.Drawing.Point(404, 124); + this.pic_security.Name = "pic_security"; + this.pic_security.Size = new System.Drawing.Size(180, 210); + this.pic_security.TabIndex = 5; + this.pic_security.TabStop = false; + // + // pic_environment + // + this.pic_environment.BackColor = System.Drawing.Color.Transparent; + this.pic_environment.Image = global::智慧校园.Properties.Resources.icon_02; + this.pic_environment.Location = new System.Drawing.Point(133, 124); + this.pic_environment.Name = "pic_environment"; + this.pic_environment.Size = new System.Drawing.Size(180, 210); + this.pic_environment.TabIndex = 4; + this.pic_environment.TabStop = false; + this.pic_environment.Click += new System.EventHandler(this.pic_environment_Click); + // + // Main + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1018, 616); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Main"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Main_Load); + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pic_exit)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_security)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_environment)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.PictureBox pic_exit; + private System.Windows.Forms.PictureBox pic_security; + private System.Windows.Forms.PictureBox pic_environment; + } +} + diff --git a/samples/p8-t3-环境采集与分析/Main.cs b/samples/p8-t3-环境采集与分析/Main.cs new file mode 100644 index 0000000..4265988 --- /dev/null +++ b/samples/p8-t3-环境采集与分析/Main.cs @@ -0,0 +1,60 @@ +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 DeviceCtrlLibrary; +namespace 智慧校园 +{ + public partial class Main : Form + { + public Main() + { + InitializeComponent(); + } + + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void pic_environment_Click(object sender, EventArgs e) + { + try + { + new Environment().Show(); + + } + catch + { + } + } + + private void panel2_Paint(object sender, PaintEventArgs e) + { + + } + + private void Main_Load(object sender, EventArgs e) + { + try + { + //实例化工具类 + DeviceCtrlHelper.adam4017Helper.Open(AppSet.ADAM4017_COM); + DeviceCtrlHelper.adam4150Helper.Open(AppSet.ADAM4150_COM); + DeviceCtrlHelper.zigBeeHelper.Open(AppSet.ZigBee_COM); + DeviceCtrlHelper.ledHelper.OpenLedCom(AppSet.LED_COM); + } + catch { } + } + + private void pic_exit_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/samples/p8-t3-环境采集与分析/Program.cs b/samples/p8-t3-环境采集与分析/Program.cs new file mode 100644 index 0000000..2fd691b --- /dev/null +++ b/samples/p8-t3-环境采集与分析/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 智慧校园 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Main()); + } + } +} diff --git a/samples/p8-t3-环境采集与分析/Properties/Resources.Designer.cs b/samples/p8-t3-环境采集与分析/Properties/Resources.Designer.cs new file mode 100644 index 0000000..e666e83 --- /dev/null +++ b/samples/p8-t3-环境采集与分析/Properties/Resources.Designer.cs @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// 项目资源(平台素材库)。在"项目资源"里添加或移除,不要手动修改这个文件。 +// +//------------------------------------------------------------------------------ + +namespace 智慧校园.Properties { + + /// + /// 项目资源:Properties.Resources.资源名 + /// + internal class Resources { + + /// 标题:智慧校园 + internal static System.Drawing.Bitmap ico_title { + get { return global::Sim.Host.ProjectResources.Image("ico_title.png"); } + } + + /// 主界面背景:校园 + internal static System.Drawing.Bitmap bg_home { + get { return global::Sim.Host.ProjectResources.Image("bg_home.png"); } + } + + /// 图标:校园环境 + internal static System.Drawing.Bitmap icon_02 { + get { return global::Sim.Host.ProjectResources.Image("icon_02.png"); } + } + + /// 图标:校园安防 + internal static System.Drawing.Bitmap icon_03 { + get { return global::Sim.Host.ProjectResources.Image("icon_03.png"); } + } + + /// 图标:退出 + internal static System.Drawing.Bitmap icon_04 { + get { return global::Sim.Host.ProjectResources.Image("icon_04.png"); } + } + + /// 路灯场景:亮灯 + internal static System.Drawing.Bitmap day_01 { + get { return global::Sim.Host.ProjectResources.Image("day_01.png"); } + } + + /// 路灯场景:灭灯 + internal static System.Drawing.Bitmap day_02 { + get { return global::Sim.Host.ProjectResources.Image("day_02.png"); } + } + + /// 面板背景(窄) + internal static System.Drawing.Bitmap bg_from2 { + get { return global::Sim.Host.ProjectResources.Image("bg_from2.png"); } + } + + /// 开关:开 + internal static System.Drawing.Bitmap switch_on { + get { return global::Sim.Host.ProjectResources.Image("switch_on.png"); } + } + + /// 开关:关 + internal static System.Drawing.Bitmap switch_off { + get { return global::Sim.Host.ProjectResources.Image("switch_off.png"); } + } + } +} diff --git a/samples/p8-t3-环境采集与分析/SQLHelpers/SQLBLL.cs b/samples/p8-t3-环境采集与分析/SQLHelpers/SQLBLL.cs new file mode 100644 index 0000000..c737537 --- /dev/null +++ b/samples/p8-t3-环境采集与分析/SQLHelpers/SQLBLL.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 智慧校园.SQLHelpers +{ + class SQLBLL + { + + public static SQLRes SecurityUpData(Image img)//把图片保存到数据库 + { + SQLRes sqlRes = new SQLRes(); + byte[] imgByte = null; + + using (MemoryStream ms = new MemoryStream())//图片转换为二进制数组 + { + img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); + imgByte = new byte[ms.Length]; + imgByte = ms.ToArray(); + } + + string sqlStr = "INSERT INTO SecurityData (EvenTime,EvenImage) VALUES (@time,@img)"; + SqlParameter[] sqlParameter = new SqlParameter[] { new SqlParameter("time", DateTime.Now.ToString()), new SqlParameter("img", imgByte) }; + + if (SQLHelper.Exec(sqlStr, sqlParameter) >= 1) + { + sqlRes.Result = true; + sqlRes.Msg = "成功!"; + } + else + { + sqlRes.Result = false; + sqlRes.Msg = "失败!"; + } + + return sqlRes; + } + + public static Dictionary GetSecurityData(DateTime startDate, DateTime endDate) + { + Dictionary ImgDictionary = new Dictionary(); + + if (string.IsNullOrWhiteSpace(startDate.Month.ToString()) && string.IsNullOrWhiteSpace(endDate.Month .ToString())) + { + return ImgDictionary; + } + //选择查询日期日期 + string sql = "SELECT * FROM SecurityData WHERE EvenTime between @time_start and @time_end"; + SqlParameter[] sqlParameter = new SqlParameter[] { new SqlParameter("time_start", startDate.Year + "/" + startDate.Month + "/" + startDate.Day), new SqlParameter("time_end", endDate.Year + "/" + endDate.Month + "/" + endDate.Day+" 23:59:59" )}; + + DataSet ds = SQLHelper.getData(sql, sqlParameter); + + for (int i = 0; i < ds.Tables[0].Rows.Count; i++) + { + ImgDictionary.Add(ds.Tables[0].Rows[i]["EvenTime"].ToString(), Image.FromStream(new MemoryStream((byte[])ds.Tables[0].Rows[i]["EvenImage"]))); + } + + return ImgDictionary; + } + + public static SQLRes EnvironmentUpData(bool fire, bool smoke, string light, string temperature, string humidity) + { + + SQLRes sqlRes = new SQLRes(); + + string sqlStr = "INSERT INTO EnvironmentData (Fire ,Smoke ,Temperature ,Humidity , Light, _Time) VALUES (@fire,@smoke,@temperature,@humidity,@light,@time)"; + SqlParameter[] sqlParameter = new SqlParameter[] { new SqlParameter("time", DateTime.Now.ToString()), new SqlParameter("fire", fire), new SqlParameter("smoke", smoke), new SqlParameter("temperature", temperature), new SqlParameter("humidity", humidity), new SqlParameter("light", light) }; + + if (SQLHelper.Exec(sqlStr, sqlParameter) >= 1) + { + sqlRes.Result = true; + sqlRes.Msg = "成功!"; + } + else + { + sqlRes.Result = false; + sqlRes.Msg = "失败!"; + } + + return sqlRes; + + } + + public static DataTable GetEnvironmentGraphData() + { + string sqlStr = "SELECT TOP 7 CONVERT(varchar(10),_Time,120) AS _Time, ROUND(Max(Temperature),2) AS MaxTemperature, ROUND(AVG(Temperature),2) AS AVGTemperature FROM EnvironmentData GROUP BY CONVERT(varchar(10),_Time,120) ORDER BY CONVERT(varchar(10),_Time,120) DESC "; + return SQLHelper.getData(sqlStr, null).Tables[0]; + } + + + } + + class SQLRes + { + public string Msg { get; set; } + public bool Result { get; set; } + } + + } + diff --git a/samples/p8-t3-环境采集与分析/SQLHelpers/SQLHelper.cs b/samples/p8-t3-环境采集与分析/SQLHelpers/SQLHelper.cs new file mode 100644 index 0000000..d37157e --- /dev/null +++ b/samples/p8-t3-环境采集与分析/SQLHelpers/SQLHelper.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 智慧校园.SQLHelpers +{ + class SQLHelper + { + public static string strConn = AppSet.SqlConn; + + public static bool SaveData(string sql, DataTable dt) + { + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + SqlDataAdapter sda = new SqlDataAdapter(sql, conn); + SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(sda); + sda.Update(dt); + conn.Close(); + return true; + } + catch (Exception e) + { + string Error = e.Message; + return false; + } + } + + public static DataSet getData(string sql, params SqlParameter[] para) + { + DataSet ds = new DataSet(); + + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + SqlCommand cmd = new SqlCommand(sql, conn); + if (para != null) + { + foreach (SqlParameter item in para) + { + cmd.Parameters.Add(item); + } + } + SqlDataAdapter sda = new SqlDataAdapter(cmd); + sda.Fill(ds); + cmd.Parameters.Clear(); + conn.Close(); + } + catch(Exception e) + { + string Error = e.Message; + } + + return ds; + } + + public static DataSet getData(SqlCommand cmd) + { + DataSet ds = new DataSet(); + + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + cmd.Connection = conn; + + SqlDataAdapter sda = new SqlDataAdapter(cmd); + sda.Fill(ds); + cmd.Parameters.Clear(); + conn.Close(); + } + catch (Exception e) + { + string Error = e.Message; + } + + return ds; + } + + public static int Exec(string sql, params SqlParameter[] para) + { + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + SqlCommand cmd = new SqlCommand(sql, conn); + if (para != null) + { + foreach (SqlParameter item in para) + { + cmd.Parameters.Add(item); + } + } + int iRsult = cmd.ExecuteNonQuery(); + conn.Close(); + return iRsult; + } + catch (Exception e) + { + string Error = e.Message; + return -1; + } + } + } + } + diff --git a/samples/p8-t3-环境采集与分析/checks.yaml b/samples/p8-t3-环境采集与分析/checks.yaml new file mode 100644 index 0000000..67646a9 --- /dev/null +++ b/samples/p8-t3-环境采集与分析/checks.yaml @@ -0,0 +1,71 @@ +# 评分规则:书上评价表的功能项。每项单独启动一次程序,按步骤操作,核对结果。 +# 格式说明见 server/src/grading/checks.ts +# 采集线程每 5.5 秒左右采集一次,所以等待时间写 8s。 +- title: 能实时显示环境数据和火情、烟情 + steps: + - click: pic_environment + - board: { temperature: 28, humidity: 55, light: 650 } + - expect: { control: txt_temperature, text: '28', within: 8s } + - expect: { control: txt_humidity, text: '55', within: 8s } + - expect: { control: txt_light, text: '650', within: 8s } + - expect: { control: txt_fire, text: 正常, within: 8s } + - board: { fire: true, smoke: true } + - expect: { control: txt_fire, text: 发生火情, within: 8s } + - expect: { control: txt_smoke, text: 发生烟情, within: 8s } + +- title: 路灯能手动控制 + steps: + - click: pic_environment + - click: pic_lampOpen + - expect: { zigbee: 1, on: true, desc: 点灯光开关打开路灯 } + - expect: { control: pic_lampOpen, background: switch_on, desc: 开关换成"开"的图片(switch_on) } + - expect: { control: panel_bg, background: day_01, desc: 背景换成亮灯的场景(day_01) } + - click: pic_lampOpen + - expect: { zigbee: 1, on: false, desc: 再点一次关闭路灯 } + - expect: { control: pic_lampOpen, background: switch_off } + - expect: { control: panel_bg, background: day_02 } + +- title: 路灯能根据光照度自动控制 + steps: + - click: pic_environment + - text: { control: txt_autoLight, value: '400' } + - click: ch_autoLamp + - board: { light: 200 } + - expect: { zigbee: 1, on: true, within: 8s, desc: 光照低于设定值 400 时自动打开路灯 } + - expect: { control: panel_bg, background: day_01 } + - board: { light: 800 } + - expect: { zigbee: 1, on: false, within: 8s, desc: 光照高于设定值时自动关闭路灯 } + +- title: 能推送天气信息和自定义信息到 LED 屏 + steps: + - board: { temperature: 26, humidity: 50 } + - click: pic_environment + - expect: { control: txt_temperature, text: '26', within: 8s } + - click: btn_ledEnvironment1 + - expect: { led: 当前温度:26℃ 湿度:50%, desc: 显示"当前温度:26℃ 湿度:50%"(点下方的"推送天气信息") } + - text: { control: txt_ledMsg, value: 欢迎参观智慧校园 } + - click: btn_ledSendMsg + - expect: { led: 欢迎参观智慧校园, desc: 显示输入的文字(点"推送LED信息") } + - click: btn_ledEnvironment2 + - expect: { led: 当前温度:26℃, desc: 显示天气信息(点右边的"推送天气信息") } + +- title: 能自动推送火情到 LED 屏 + steps: + - click: pic_environment + - click: ch_autoLedFire + - board: { fire: true } + - expect: { led: 发现火情, within: 8s, desc: 显示"发现火情"(勾选"自动推送火情"后有火焰) } + - board: { smoke: true } + - expect: { led: 发生严重火灾, within: 8s, desc: 显示"发生严重火灾"(火焰和烟雾都有) } + +- title: 图表能正确显示数据 + steps: + - click: pic_environment + - expect: { control: chart1, visible: false, desc: 刚打开时图表隐藏 } + - click: btn_dataAnalyse + - expect: { control: chart1, visible: true, desc: 点"数据分析"显示图表 } + - expect: { control: chart1, points: 7, desc: 显示最近 7 天的最高温度和平均温度 } + - expect: { control: btn_dataAnalyse, text: 关闭图表 } + - click: btn_dataAnalyse + - expect: { control: chart1, visible: false, desc: 点"关闭图表"隐藏图表 } + - expect: { control: btn_dataAnalyse, text: 数据分析 } diff --git a/samples/p8-t3-环境采集与分析/database.sql b/samples/p8-t3-环境采集与分析/database.sql new file mode 100644 index 0000000..2e5eeba --- /dev/null +++ b/samples/p8-t3-环境采集与分析/database.sql @@ -0,0 +1,54 @@ +-- 实验的初始数据库 WisdomCampus(教材"综合实训"附带的库):环境数据表 EnvironmentData、报警图片表 SecurityData、用户表 Users。 +-- EnvironmentData 预置了 7 天的历史数据,"数据分析"的图表一打开就有内容;SecurityData 是空的,拍照或有人入侵时才有记录。 +-- 学生可以在数据库页面"恢复实验初始数据";评分时每个检查项用一份新的。 +CREATE DATABASE WisdomCampus +GO +USE WisdomCampus +GO +CREATE TABLE Users (Id int IDENTITY(1,1) PRIMARY KEY, UserName nvarchar(50) NOT NULL, Password nvarchar(50) NOT NULL) +CREATE TABLE EnvironmentData (Id int IDENTITY(1,1) PRIMARY KEY, Fire bit NOT NULL, Smoke bit NOT NULL, Temperature float NULL, Humidity float NULL, Light float NULL, _Time datetime NOT NULL) +CREATE TABLE SecurityData (Id int IDENTITY(1,1) PRIMARY KEY, EvenTime datetime NOT NULL, EvenImage image NOT NULL) +GO +INSERT INTO Users (UserName, Password) VALUES ('admin', '123') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.9, 58, 258, '2026-10-14 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.1, 53, 475, '2026-10-14 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.8, 51, 761, '2026-10-14 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 22.5, 49, 733, '2026-10-14 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 54, 528, '2026-10-14 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.1, 57, 283, '2026-10-14 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.9, 59, 261, '2026-10-15 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.6, 53, 499, '2026-10-15 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.8, 52, 764, '2026-10-15 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 23.5, 47, 778, '2026-10-15 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.8, 52, 503, '2026-10-15 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.6, 56, 218, '2026-10-15 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 13.9, 63, 258, '2026-10-16 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.6, 60, 477, '2026-10-16 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.8, 51, 741, '2026-10-16 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 20.5, 54, 796, '2026-10-16 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 55, 488, '2026-10-16 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.6, 59, 214, '2026-10-16 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 11.9, 67, 234, '2026-10-17 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.1, 63, 544, '2026-10-17 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.3, 60, 804, '2026-10-17 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.5, 54, 801, '2026-10-17 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.8, 59, 524, '2026-10-17 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.1, 58, 286, '2026-10-17 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.4, 59, 250, '2026-10-18 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.6, 55, 533, '2026-10-18 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.3, 50, 749, '2026-10-18 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 24, 48, 766, '2026-10-18 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 20.8, 54, 534, '2026-10-18 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.1, 53, 241, '2026-10-18 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.4, 54, 253, '2026-10-19 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.1, 50, 474, '2026-10-19 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 22.3, 48, 778, '2026-10-19 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 26, 46, 783, '2026-10-19 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 23.3, 50, 520, '2026-10-19 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 20.6, 50, 213, '2026-10-19 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.9, 62, 230, '2026-10-20 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.6, 52, 471, '2026-10-20 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 53, 751, '2026-10-20 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.5, 48, 747, '2026-10-20 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 55, 527, '2026-10-20 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.1, 57, 220, '2026-10-20 18:00:00') diff --git a/samples/p8-t3-环境采集与分析/meta.json b/samples/p8-t3-环境采集与分析/meta.json new file mode 100644 index 0000000..0cd6ae3 --- /dev/null +++ b/samples/p8-t3-环境采集与分析/meta.json @@ -0,0 +1,4 @@ +{ + "title": "项目8 任务3 实现\"校园环境\"数据采集及数据分析功能", + "source": "教材书 p164–174,界面和代码取自配套参考工程;图片是平台素材库里自绘的同名素材(尺寸和教材一致);按书补全了参考工程里空着的\"推送LED信息\"\"自动控制\",给\"自动推送火情\"复选框加上 CheckedChanged(书上第 23 步把控件名写成了 ch_autoLamp);数据库 WisdomCampus 是平台按教材的表结构建的,预置 7 天环境数据" +} diff --git a/samples/p8-t4-校园安防/AppSet.cs b/samples/p8-t4-校园安防/AppSet.cs new file mode 100644 index 0000000..394d13f --- /dev/null +++ b/samples/p8-t4-校园安防/AppSet.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 智慧校园 +{ + class AppSet + { + //串口设置 + public static string ADAM4017_COM = "COM2"; + public static string ADAM4150_COM = "COM3"; + public static string LED_COM = "COM5"; + public static string ZigBee_COM = "COM4"; + + //摄像机参数 + public static string Camera_Ip = "192.168.1.100"; + public static string Camera_Uid = "admin"; + public static string Camera_Pwd = ""; + + //数据库连接字符串 + public static string SqlConn = "Data Source=.;Initial Catalog=WisdomCampus;User ID=sa;Password=123"; + } +} diff --git a/samples/p8-t4-校园安防/Environment.Designer.cs b/samples/p8-t4-校园安防/Environment.Designer.cs new file mode 100644 index 0000000..856107d --- /dev/null +++ b/samples/p8-t4-校园安防/Environment.Designer.cs @@ -0,0 +1,555 @@ +namespace 智慧校园 +{ + partial class Environment + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Legend legend4 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.panel_bg = new System.Windows.Forms.Panel(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.panel_form = new System.Windows.Forms.Panel(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.pic_lampOpen = new System.Windows.Forms.PictureBox(); + this.label10 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.txt_autoLight = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.ch_autoLamp = new System.Windows.Forms.CheckBox(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.btn_ledEnvironment2 = new System.Windows.Forms.Button(); + this.ch_autoLedFire = new System.Windows.Forms.CheckBox(); + this.btn_ledSendMsg = new System.Windows.Forms.Button(); + this.txt_ledMsg = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.panel5 = new System.Windows.Forms.Panel(); + this.btn_dataAnalyse = new System.Windows.Forms.Button(); + this.btn_ledEnvironment1 = new System.Windows.Forms.Button(); + this.label6 = new System.Windows.Forms.Label(); + this.txt_humidity = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.txt_fire = new System.Windows.Forms.TextBox(); + this.txt_temperature = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.txt_smoke = new System.Windows.Forms.TextBox(); + this.txt_light = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.panel3 = new System.Windows.Forms.Panel(); + this.lb_return = new System.Windows.Forms.Label(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel2.SuspendLayout(); + this.panel_bg.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + this.panel_form.SuspendLayout(); + this.groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_lampOpen)).BeginInit(); + this.groupBox3.SuspendLayout(); + this.panel5.SuspendLayout(); + this.panel3.SuspendLayout(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(116)))), ((int)(((byte)(133))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1043, 100); + this.panel1.TabIndex = 0; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(44, 12); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(226, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel2 + // + this.panel2.Controls.Add(this.panel_bg); + this.panel2.Controls.Add(this.panel3); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 100); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(1043, 691); + this.panel2.TabIndex = 1; + // + // panel_bg + // + this.panel_bg.BackgroundImage = global::智慧校园.Properties.Resources.day_02; + this.panel_bg.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel_bg.Controls.Add(this.chart1); + this.panel_bg.Controls.Add(this.panel_form); + this.panel_bg.Controls.Add(this.panel5); + this.panel_bg.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel_bg.Location = new System.Drawing.Point(0, 39); + this.panel_bg.Name = "panel_bg"; + this.panel_bg.Size = new System.Drawing.Size(1043, 652); + this.panel_bg.TabIndex = 1; + // + // chart1 + // + chartArea2.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea2); + legend3.Name = "MaxLegend"; + legend3.TitleForeColor = System.Drawing.Color.DimGray; + legend4.Name = "AVGLegend"; + legend4.TitleForeColor = System.Drawing.Color.DimGray; + this.chart1.Legends.Add(legend3); + this.chart1.Legends.Add(legend4); + this.chart1.Location = new System.Drawing.Point(44, 172); + this.chart1.Name = "chart1"; + series3.ChartArea = "ChartArea1"; + series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series3.Legend = "MaxLegend"; + series3.LegendText = "最大值"; + series3.Name = "MaxSeries"; + series3.XValueMember = "_Time"; + series3.YValueMembers = "MaxTemperature"; + series4.ChartArea = "ChartArea1"; + series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series4.Legend = "AVGLegend"; + series4.LegendText = "平均值"; + series4.Name = "AVGSeries"; + series4.XValueMember = "_Time"; + series4.YValueMembers = "AVGTemperature"; + this.chart1.Series.Add(series3); + this.chart1.Series.Add(series4); + this.chart1.Size = new System.Drawing.Size(455, 327); + this.chart1.TabIndex = 3; + this.chart1.Text = "chart1"; + // + // panel_form + // + this.panel_form.BackColor = System.Drawing.Color.Transparent; + this.panel_form.BackgroundImage = global::智慧校园.Properties.Resources.bg_from2; + this.panel_form.Controls.Add(this.groupBox2); + this.panel_form.Controls.Add(this.groupBox3); + this.panel_form.Dock = System.Windows.Forms.DockStyle.Right; + this.panel_form.Location = new System.Drawing.Point(617, 0); + this.panel_form.Name = "panel_form"; + this.panel_form.Size = new System.Drawing.Size(426, 552); + this.panel_form.TabIndex = 2; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.pic_lampOpen); + this.groupBox2.Controls.Add(this.label10); + this.groupBox2.Controls.Add(this.label9); + this.groupBox2.Controls.Add(this.txt_autoLight); + this.groupBox2.Controls.Add(this.label7); + this.groupBox2.Controls.Add(this.ch_autoLamp); + this.groupBox2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.groupBox2.ForeColor = System.Drawing.Color.White; + this.groupBox2.Location = new System.Drawing.Point(22, 21); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(392, 150); + this.groupBox2.TabIndex = 3; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "路灯控制"; + // + // pic_lampOpen + // + this.pic_lampOpen.BackgroundImage = global::智慧校园.Properties.Resources.switch_off; + this.pic_lampOpen.Location = new System.Drawing.Point(103, 103); + this.pic_lampOpen.Name = "pic_lampOpen"; + this.pic_lampOpen.Size = new System.Drawing.Size(48, 24); + this.pic_lampOpen.TabIndex = 5; + this.pic_lampOpen.TabStop = false; + this.pic_lampOpen.Click += new System.EventHandler(this.pic_lampOpen_Click); + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(33, 105); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(59, 17); + this.label10.TabIndex = 4; + this.label10.Text = "灯光控制:"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(278, 58); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(17, 17); + this.label9.TabIndex = 3; + this.label9.Text = "lx"; + // + // txt_autoLight + // + this.txt_autoLight.Location = new System.Drawing.Point(128, 55); + this.txt_autoLight.Name = "txt_autoLight"; + this.txt_autoLight.Size = new System.Drawing.Size(144, 23); + this.txt_autoLight.TabIndex = 2; + this.txt_autoLight.TextChanged += new System.EventHandler(this.txt_autoLight_TextChanged); + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(33, 58); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(92, 17); + this.label7.TabIndex = 1; + this.label7.Text = "设定开灯光照值"; + // + // ch_autoLamp + // + this.ch_autoLamp.AutoSize = true; + this.ch_autoLamp.Location = new System.Drawing.Point(35, 30); + this.ch_autoLamp.Name = "ch_autoLamp"; + this.ch_autoLamp.Size = new System.Drawing.Size(75, 21); + this.ch_autoLamp.TabIndex = 0; + this.ch_autoLamp.Text = "自动控制"; + this.ch_autoLamp.UseVisualStyleBackColor = true; + this.ch_autoLamp.CheckedChanged += new System.EventHandler(this.ch_autoLamp_CheckedChanged); + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.btn_ledEnvironment2); + this.groupBox3.Controls.Add(this.ch_autoLedFire); + this.groupBox3.Controls.Add(this.btn_ledSendMsg); + this.groupBox3.Controls.Add(this.txt_ledMsg); + this.groupBox3.Controls.Add(this.label8); + this.groupBox3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.groupBox3.ForeColor = System.Drawing.Color.White; + this.groupBox3.Location = new System.Drawing.Point(22, 209); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(392, 316); + this.groupBox3.TabIndex = 4; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "LED推送"; + // + // btn_ledEnvironment2 + // + this.btn_ledEnvironment2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(86)))), ((int)(((byte)(149)))), ((int)(((byte)(212))))); + this.btn_ledEnvironment2.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledEnvironment2.Location = new System.Drawing.Point(234, 217); + this.btn_ledEnvironment2.Name = "btn_ledEnvironment2"; + this.btn_ledEnvironment2.Size = new System.Drawing.Size(145, 32); + this.btn_ledEnvironment2.TabIndex = 11; + this.btn_ledEnvironment2.Text = "推送天气信息"; + this.btn_ledEnvironment2.UseVisualStyleBackColor = false; + this.btn_ledEnvironment2.Click += new System.EventHandler(this.btn_ledEnvironment2_Click); + // + // ch_autoLedFire + // + this.ch_autoLedFire.AutoSize = true; + this.ch_autoLedFire.Location = new System.Drawing.Point(265, 35); + this.ch_autoLedFire.Name = "ch_autoLedFire"; + this.ch_autoLedFire.Size = new System.Drawing.Size(99, 21); + this.ch_autoLedFire.TabIndex = 4; + this.ch_autoLedFire.Text = "自动推送火情"; + this.ch_autoLedFire.UseVisualStyleBackColor = true; + this.ch_autoLedFire.CheckedChanged += new System.EventHandler(this.ch_autoLedFire_CheckedChanged); + // + // btn_ledSendMsg + // + this.btn_ledSendMsg.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(168)))), ((int)(((byte)(255))))); + this.btn_ledSendMsg.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledSendMsg.Location = new System.Drawing.Point(26, 217); + this.btn_ledSendMsg.Name = "btn_ledSendMsg"; + this.btn_ledSendMsg.Size = new System.Drawing.Size(145, 32); + this.btn_ledSendMsg.TabIndex = 2; + this.btn_ledSendMsg.Text = "推送LED信息"; + this.btn_ledSendMsg.UseVisualStyleBackColor = false; + this.btn_ledSendMsg.Click += new System.EventHandler(this.btn_ledSendMsg_Click); + // + // txt_ledMsg + // + this.txt_ledMsg.Location = new System.Drawing.Point(23, 62); + this.txt_ledMsg.Multiline = true; + this.txt_ledMsg.Name = "txt_ledMsg"; + this.txt_ledMsg.Size = new System.Drawing.Size(356, 130); + this.txt_ledMsg.TabIndex = 1; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(20, 36); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(54, 17); + this.label8.TabIndex = 0; + this.label8.Text = "LED信息"; + // + // panel5 + // + this.panel5.Controls.Add(this.btn_dataAnalyse); + this.panel5.Controls.Add(this.btn_ledEnvironment1); + this.panel5.Controls.Add(this.label6); + this.panel5.Controls.Add(this.txt_humidity); + this.panel5.Controls.Add(this.label1); + this.panel5.Controls.Add(this.label5); + this.panel5.Controls.Add(this.txt_fire); + this.panel5.Controls.Add(this.txt_temperature); + this.panel5.Controls.Add(this.label2); + this.panel5.Controls.Add(this.label4); + this.panel5.Controls.Add(this.txt_smoke); + this.panel5.Controls.Add(this.txt_light); + this.panel5.Controls.Add(this.label3); + this.panel5.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel5.Location = new System.Drawing.Point(0, 552); + this.panel5.Name = "panel5"; + this.panel5.Size = new System.Drawing.Size(1043, 100); + this.panel5.TabIndex = 1; + // + // btn_dataAnalyse + // + this.btn_dataAnalyse.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(168)))), ((int)(((byte)(255))))); + this.btn_dataAnalyse.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_dataAnalyse.Location = new System.Drawing.Point(792, 35); + this.btn_dataAnalyse.Name = "btn_dataAnalyse"; + this.btn_dataAnalyse.Size = new System.Drawing.Size(119, 32); + this.btn_dataAnalyse.TabIndex = 23; + this.btn_dataAnalyse.Text = "数据分析"; + this.btn_dataAnalyse.UseVisualStyleBackColor = false; + this.btn_dataAnalyse.Click += new System.EventHandler(this.btn_dataAnalyse_Click); + // + // btn_ledEnvironment1 + // + this.btn_ledEnvironment1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(86)))), ((int)(((byte)(149)))), ((int)(((byte)(212))))); + this.btn_ledEnvironment1.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledEnvironment1.Location = new System.Drawing.Point(910, 35); + this.btn_ledEnvironment1.Name = "btn_ledEnvironment1"; + this.btn_ledEnvironment1.Size = new System.Drawing.Size(121, 32); + this.btn_ledEnvironment1.TabIndex = 15; + this.btn_ledEnvironment1.Text = "推送天气信息"; + this.btn_ledEnvironment1.UseVisualStyleBackColor = false; + this.btn_ledEnvironment1.Click += new System.EventHandler(this.btn_ledEnvironment1_Click); + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("微软雅黑", 18F); + this.label6.Location = new System.Drawing.Point(12, 31); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(110, 31); + this.label6.TabIndex = 11; + this.label6.Text = "环境数据"; + // + // txt_humidity + // + this.txt_humidity.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_humidity.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_humidity.Location = new System.Drawing.Point(716, 36); + this.txt_humidity.Name = "txt_humidity"; + this.txt_humidity.Size = new System.Drawing.Size(70, 32); + this.txt_humidity.TabIndex = 22; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label1.Location = new System.Drawing.Point(132, 38); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(50, 25); + this.label1.TabIndex = 12; + this.label1.Text = "火焰"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label5.Location = new System.Drawing.Point(660, 39); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(50, 25); + this.label5.TabIndex = 21; + this.label5.Text = "湿度"; + // + // txt_fire + // + this.txt_fire.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_fire.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_fire.Location = new System.Drawing.Point(188, 35); + this.txt_fire.Name = "txt_fire"; + this.txt_fire.Size = new System.Drawing.Size(70, 32); + this.txt_fire.TabIndex = 13; + // + // txt_temperature + // + this.txt_temperature.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_temperature.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_temperature.Location = new System.Drawing.Point(584, 35); + this.txt_temperature.Name = "txt_temperature"; + this.txt_temperature.Size = new System.Drawing.Size(70, 32); + this.txt_temperature.TabIndex = 20; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label2.Location = new System.Drawing.Point(264, 36); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(50, 25); + this.label2.TabIndex = 14; + this.label2.Text = "烟雾"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label4.Location = new System.Drawing.Point(528, 38); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(50, 25); + this.label4.TabIndex = 19; + this.label4.Text = "温度"; + // + // txt_smoke + // + this.txt_smoke.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_smoke.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_smoke.Location = new System.Drawing.Point(320, 33); + this.txt_smoke.Name = "txt_smoke"; + this.txt_smoke.Size = new System.Drawing.Size(70, 32); + this.txt_smoke.TabIndex = 16; + // + // txt_light + // + this.txt_light.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_light.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_light.Location = new System.Drawing.Point(452, 32); + this.txt_light.Name = "txt_light"; + this.txt_light.Size = new System.Drawing.Size(70, 32); + this.txt_light.TabIndex = 18; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label3.Location = new System.Drawing.Point(396, 35); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(50, 25); + this.label3.TabIndex = 17; + this.label3.Text = "光照"; + // + // panel3 + // + this.panel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(229)))), ((int)(((byte)(229))))); + this.panel3.Controls.Add(this.lb_return); + this.panel3.Dock = System.Windows.Forms.DockStyle.Top; + this.panel3.Location = new System.Drawing.Point(0, 0); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(1043, 39); + this.panel3.TabIndex = 0; + this.panel3.Paint += new System.Windows.Forms.PaintEventHandler(this.panel3_Paint); + // + // lb_return + // + this.lb_return.AutoSize = true; + this.lb_return.Location = new System.Drawing.Point(25, 12); + this.lb_return.Name = "lb_return"; + this.lb_return.Size = new System.Drawing.Size(83, 12); + this.lb_return.TabIndex = 0; + this.lb_return.Text = "< 返回主窗体"; + this.lb_return.Click += new System.EventHandler(this.lb_return_Click); + // + // Environment + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1043, 791); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Environment"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Environment"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Environment_FormClosed); + this.Load += new System.EventHandler(this.Environment_Load); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel2.ResumeLayout(false); + this.panel_bg.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + this.panel_form.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_lampOpen)).EndInit(); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.panel5.ResumeLayout(false); + this.panel5.PerformLayout(); + this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Label lb_return; + private System.Windows.Forms.Panel panel_bg; + private System.Windows.Forms.Panel panel5; + private System.Windows.Forms.Panel panel_form; + private System.Windows.Forms.Button btn_dataAnalyse; + private System.Windows.Forms.Button btn_ledEnvironment1; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox txt_humidity; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txt_fire; + private System.Windows.Forms.TextBox txt_temperature; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox txt_smoke; + private System.Windows.Forms.TextBox txt_light; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.PictureBox pic_lampOpen; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.TextBox txt_autoLight; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.CheckBox ch_autoLamp; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.Button btn_ledEnvironment2; + private System.Windows.Forms.CheckBox ch_autoLedFire; + private System.Windows.Forms.Button btn_ledSendMsg; + private System.Windows.Forms.TextBox txt_ledMsg; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + } +} \ No newline at end of file diff --git a/samples/p8-t4-校园安防/Environment.cs b/samples/p8-t4-校园安防/Environment.cs new file mode 100644 index 0000000..c136074 --- /dev/null +++ b/samples/p8-t4-校园安防/Environment.cs @@ -0,0 +1,279 @@ +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 DeviceCtrlLibrary; +using DeviceCtrlLibrary.Model; +using 智慧校园.SQLHelpers; +using System.Threading; + +namespace 智慧校园 +{ + public partial class Environment : Form + { + public Environment() + { + InitializeComponent(); + } + //用于各类耗时长的操作(SQL、数据采集、设备控制等) + Thread thread; + //用于异步通行 + SynchronizationContext _main; + //结果模型 + ADAM4017ResModel ResModel_4017; + ADAM4150ResModel ResModel_4150; + //设置自动控制路灯的光照值 + double environmentLight, setLight; + //按钮状态标志 + bool IsAuto_Lamp = false; + bool IsAuto_FireMsg = false; + bool IsLampOpen = false; + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void lb_return_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void Environment_Load(object sender, EventArgs e) + { + try + { + + //隐藏曲线图 + chart1.Visible = false; + thread = new Thread(new ThreadStart(Tick)); + _main = WindowsFormsSynchronizationContext.Current; + thread.Start(); + } + catch + { + } + + } + private void Tick() + { + try + { + while (true) + { + //数据采集 + ResModel_4017 = DeviceCtrlHelper.adam4017Helper.SetData(); + Thread.Sleep(500); + ResModel_4150 = DeviceCtrlHelper.adam4150Helper.SetData(); + + //UI显示数据 + + _main.Send(_ => + { + try //防止无数据出错 + { + txt_fire.Text = (ResModel_4150.fireValue ? "发生火情" : "正常"); + txt_smoke.Text = (ResModel_4150.smokeValue ? "发生烟情" : "正常"); + txt_light.Text = ResModel_4017.lightValue; + txt_temperature.Text = ResModel_4017.temperatureValue; + txt_humidity.Text = ResModel_4017.humidityValue; + } + catch { } + }, null); + + //自动路灯控制 + double.TryParse(ResModel_4017.lightValue, out environmentLight); + if (IsAuto_Lamp && environmentLight < setLight) + { + LampOnOff(1, true); + } + else if (IsAuto_Lamp && !(environmentLight < setLight)) + { + LampOnOff(1, false); + } + + //自动推送火情LED信息控制 + if (IsAuto_FireMsg) + { + if (ResModel_4150.fireValue && ResModel_4150.smokeValue) + DeviceCtrlHelper.ledHelper.SendLedString("发生严重火灾 "); + else if (ResModel_4150.fireValue) + DeviceCtrlHelper.ledHelper.SendLedString("发现火情 "); + else if (ResModel_4150.smokeValue) + DeviceCtrlHelper.ledHelper.SendLedString("发现烟情 "); + } + + //执行数据上传 + SQLBLL.EnvironmentUpData(ResModel_4150.fireValue, ResModel_4150.smokeValue, ResModel_4017.lightValue, ResModel_4017.temperatureValue, ResModel_4017.humidityValue); + + Thread.Sleep(5000); + } + } + catch + { + } + } + private void LampOnOff(int RelayNum, bool IsOpen) + { + try + { + //开启路灯 + DeviceCtrlHelper.zigBeeHelper.OnOff(RelayNum, IsOpen); + + //切换UI背景 + _main.Send(_ => + { + if (IsOpen) + { + pic_lampOpen.BackgroundImage = Properties.Resources.switch_on; + panel_bg.BackgroundImage = Properties.Resources.day_01; + } + else + { + panel_bg.BackgroundImage = Properties.Resources.day_02; + pic_lampOpen.BackgroundImage = Properties.Resources.switch_off; + } + }, null); + } + catch + { + } + } + + private void Environment_FormClosed(object sender, FormClosedEventArgs e) + { + try + { + thread.Suspend(); + thread = null; + + } + catch + { + } + + + } + + private void btn_dataAnalyse_Click(object sender, EventArgs e) + { + try + { + if (btn_dataAnalyse.Text.Equals("数据分析")) + { + //绑定图标数据 + chart1.DataSource = SQLBLL.GetEnvironmentGraphData(); + //更新图标数据 + chart1.DataBind(); + chart1.Visible = true; + btn_dataAnalyse.Text = "关闭图表"; + } + else if (btn_dataAnalyse.Text.Equals("关闭图表")) + { + chart1.Visible = false; + btn_dataAnalyse.Text = "数据分析"; + } + } + catch + { + } + + } + + private void pic_lampOpen_Click(object sender, EventArgs e) + { + //手动路灯控制 + try + { + if (!IsLampOpen) + { + LampOnOff(1, true); + + } + else + { + LampOnOff(1, false); + + } + + IsLampOpen = !IsLampOpen; + } + catch + { + } + } + + private void btn_ledEnvironment1_Click(object sender, EventArgs e) + { + try + { + //推送LED天气信息 + if (ResModel_4017 != null && ResModel_4150 != null) + DeviceCtrlHelper.ledHelper.SendLedString("当前温度:" + ResModel_4017.temperatureValue + "℃ 湿度:" + ResModel_4017.humidityValue + "%"); + } + catch + { + } + } + + private void btn_ledEnvironment2_Click(object sender, EventArgs e) + { + try + { + //推送LED天气信息 + if (ResModel_4017 != null && ResModel_4150 != null) + DeviceCtrlHelper.ledHelper.SendLedString("当前温度:" + ResModel_4017.temperatureValue + "℃ 湿度:" + ResModel_4017.humidityValue + "%"); + } + catch + { + } + } + + private void panel3_Paint(object sender, PaintEventArgs e) + { + + } + + private void txt_autoLight_TextChanged(object sender, EventArgs e) + { + try + { + //获取光照比较值 + double.TryParse(txt_autoLight.Text,out setLight); + + } + + catch + { + } + } + + private void btn_ledSendMsg_Click(object sender, EventArgs e) + { + try + { + //推送LED信息 + DeviceCtrlHelper.ledHelper.SendLedString(txt_ledMsg.Text); + } + catch + { + } + } + + private void ch_autoLamp_CheckedChanged(object sender, EventArgs e) + { + //自动控制路灯 + IsAuto_Lamp = ch_autoLamp.Checked; + } + + private void ch_autoLedFire_CheckedChanged(object sender, EventArgs e) + { + //自动推送火情 + IsAuto_FireMsg = ch_autoLedFire.Checked; + } + } +} diff --git a/samples/p8-t4-校园安防/Main.Designer.cs b/samples/p8-t4-校园安防/Main.Designer.cs new file mode 100644 index 0000000..dc4cf19 --- /dev/null +++ b/samples/p8-t4-校园安防/Main.Designer.cs @@ -0,0 +1,145 @@ +namespace 智慧校园 +{ + partial class Main + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.pic_exit = new System.Windows.Forms.PictureBox(); + this.pic_security = new System.Windows.Forms.PictureBox(); + this.pic_environment = new System.Windows.Forms.PictureBox(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_exit)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_security)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_environment)).BeginInit(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(53)))), ((int)(((byte)(147)))), ((int)(((byte)(237))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1018, 100); + this.panel1.TabIndex = 0; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(57, 23); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(197, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel2 + // + this.panel2.BackgroundImage = global::智慧校园.Properties.Resources.bg_home; + this.panel2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel2.Controls.Add(this.pic_exit); + this.panel2.Controls.Add(this.pic_security); + this.panel2.Controls.Add(this.pic_environment); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 100); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(1018, 516); + this.panel2.TabIndex = 1; + this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint); + // + // pic_exit + // + this.pic_exit.BackColor = System.Drawing.Color.Transparent; + this.pic_exit.Image = global::智慧校园.Properties.Resources.icon_04; + this.pic_exit.Location = new System.Drawing.Point(660, 124); + this.pic_exit.Name = "pic_exit"; + this.pic_exit.Size = new System.Drawing.Size(180, 210); + this.pic_exit.TabIndex = 6; + this.pic_exit.TabStop = false; + this.pic_exit.Click += new System.EventHandler(this.pic_exit_Click); + // + // pic_security + // + this.pic_security.BackColor = System.Drawing.Color.Transparent; + this.pic_security.Image = global::智慧校园.Properties.Resources.icon_03; + this.pic_security.Location = new System.Drawing.Point(404, 124); + this.pic_security.Name = "pic_security"; + this.pic_security.Size = new System.Drawing.Size(180, 210); + this.pic_security.TabIndex = 5; + this.pic_security.TabStop = false; + this.pic_security.Click += new System.EventHandler(this.pic_security_Click); + // + // pic_environment + // + this.pic_environment.BackColor = System.Drawing.Color.Transparent; + this.pic_environment.Image = global::智慧校园.Properties.Resources.icon_02; + this.pic_environment.Location = new System.Drawing.Point(133, 124); + this.pic_environment.Name = "pic_environment"; + this.pic_environment.Size = new System.Drawing.Size(180, 210); + this.pic_environment.TabIndex = 4; + this.pic_environment.TabStop = false; + this.pic_environment.Click += new System.EventHandler(this.pic_environment_Click); + // + // Main + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1018, 616); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Main"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Main_Load); + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pic_exit)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_security)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_environment)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.PictureBox pic_exit; + private System.Windows.Forms.PictureBox pic_security; + private System.Windows.Forms.PictureBox pic_environment; + } +} + diff --git a/samples/p8-t4-校园安防/Main.cs b/samples/p8-t4-校园安防/Main.cs new file mode 100644 index 0000000..075f2c6 --- /dev/null +++ b/samples/p8-t4-校园安防/Main.cs @@ -0,0 +1,72 @@ +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 DeviceCtrlLibrary; +namespace 智慧校园 +{ + public partial class Main : Form + { + public Main() + { + InitializeComponent(); + } + + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void pic_environment_Click(object sender, EventArgs e) + { + try + { + new Environment().Show(); + + } + catch + { + } + } + + private void panel2_Paint(object sender, PaintEventArgs e) + { + + } + + private void Main_Load(object sender, EventArgs e) + { + try + { + //实例化工具类 + DeviceCtrlHelper.adam4017Helper.Open(AppSet.ADAM4017_COM); + DeviceCtrlHelper.adam4150Helper.Open(AppSet.ADAM4150_COM); + DeviceCtrlHelper.zigBeeHelper.Open(AppSet.ZigBee_COM); + DeviceCtrlHelper.ledHelper.OpenLedCom(AppSet.LED_COM); + } + catch { } + } + + private void pic_security_Click(object sender, EventArgs e) + { + try + { + new Security().Show(); + + } + catch + { + } + } + + private void pic_exit_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/samples/p8-t4-校园安防/Program.cs b/samples/p8-t4-校园安防/Program.cs new file mode 100644 index 0000000..2fd691b --- /dev/null +++ b/samples/p8-t4-校园安防/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 智慧校园 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Main()); + } + } +} diff --git a/samples/p8-t4-校园安防/Properties/Resources.Designer.cs b/samples/p8-t4-校园安防/Properties/Resources.Designer.cs new file mode 100644 index 0000000..8b526eb --- /dev/null +++ b/samples/p8-t4-校园安防/Properties/Resources.Designer.cs @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// 项目资源(平台素材库)。在"项目资源"里添加或移除,不要手动修改这个文件。 +// +//------------------------------------------------------------------------------ + +namespace 智慧校园.Properties { + + /// + /// 项目资源:Properties.Resources.资源名 + /// + internal class Resources { + + /// 标题:智慧校园 + internal static System.Drawing.Bitmap ico_title { + get { return global::Sim.Host.ProjectResources.Image("ico_title.png"); } + } + + /// 主界面背景:校园 + internal static System.Drawing.Bitmap bg_home { + get { return global::Sim.Host.ProjectResources.Image("bg_home.png"); } + } + + /// 图标:校园环境 + internal static System.Drawing.Bitmap icon_02 { + get { return global::Sim.Host.ProjectResources.Image("icon_02.png"); } + } + + /// 图标:校园安防 + internal static System.Drawing.Bitmap icon_03 { + get { return global::Sim.Host.ProjectResources.Image("icon_03.png"); } + } + + /// 图标:退出 + internal static System.Drawing.Bitmap icon_04 { + get { return global::Sim.Host.ProjectResources.Image("icon_04.png"); } + } + + /// 路灯场景:亮灯 + internal static System.Drawing.Bitmap day_01 { + get { return global::Sim.Host.ProjectResources.Image("day_01.png"); } + } + + /// 路灯场景:灭灯 + internal static System.Drawing.Bitmap day_02 { + get { return global::Sim.Host.ProjectResources.Image("day_02.png"); } + } + + /// 面板背景(窄) + internal static System.Drawing.Bitmap bg_from2 { + get { return global::Sim.Host.ProjectResources.Image("bg_from2.png"); } + } + + /// 开关:开 + internal static System.Drawing.Bitmap switch_on { + get { return global::Sim.Host.ProjectResources.Image("switch_on.png"); } + } + + /// 开关:关 + internal static System.Drawing.Bitmap switch_off { + get { return global::Sim.Host.ProjectResources.Image("switch_off.png"); } + } + + /// 监控:无画面 + internal static System.Drawing.Bitmap icon_monitor { + get { return global::Sim.Host.ProjectResources.Image("icon_monitor.png"); } + } + + /// 监控:方向盘底座 + internal static System.Drawing.Bitmap panel_video_ctrl { + get { return global::Sim.Host.ProjectResources.Image("panel_video_ctrl.png"); } + } + + /// 方向键:上 + internal static System.Drawing.Bitmap btn_arrow_up_normal { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_up_normal.png"); } + } + + /// 方向键:上(按下) + internal static System.Drawing.Bitmap btn_arrow_up_press { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_up_press.png"); } + } + + /// 方向键:下 + internal static System.Drawing.Bitmap btn_arrow_down_normal { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_down_normal.png"); } + } + + /// 方向键:下(按下) + internal static System.Drawing.Bitmap btn_arrow_down_press { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_down_press.png"); } + } + + /// 方向键:左 + internal static System.Drawing.Bitmap btn_arrow_left_normal { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_left_normal.png"); } + } + + /// 方向键:左(按下) + internal static System.Drawing.Bitmap btn_arrow_left_press { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_left_press.png"); } + } + + /// 方向键:右 + internal static System.Drawing.Bitmap btn_arrow_right_normal { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_right_normal.png"); } + } + + /// 方向键:右(按下) + internal static System.Drawing.Bitmap btn_arrow_right_press { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_right_press.png"); } + } + } +} diff --git a/samples/p8-t4-校园安防/SQLHelpers/SQLBLL.cs b/samples/p8-t4-校园安防/SQLHelpers/SQLBLL.cs new file mode 100644 index 0000000..c737537 --- /dev/null +++ b/samples/p8-t4-校园安防/SQLHelpers/SQLBLL.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 智慧校园.SQLHelpers +{ + class SQLBLL + { + + public static SQLRes SecurityUpData(Image img)//把图片保存到数据库 + { + SQLRes sqlRes = new SQLRes(); + byte[] imgByte = null; + + using (MemoryStream ms = new MemoryStream())//图片转换为二进制数组 + { + img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); + imgByte = new byte[ms.Length]; + imgByte = ms.ToArray(); + } + + string sqlStr = "INSERT INTO SecurityData (EvenTime,EvenImage) VALUES (@time,@img)"; + SqlParameter[] sqlParameter = new SqlParameter[] { new SqlParameter("time", DateTime.Now.ToString()), new SqlParameter("img", imgByte) }; + + if (SQLHelper.Exec(sqlStr, sqlParameter) >= 1) + { + sqlRes.Result = true; + sqlRes.Msg = "成功!"; + } + else + { + sqlRes.Result = false; + sqlRes.Msg = "失败!"; + } + + return sqlRes; + } + + public static Dictionary GetSecurityData(DateTime startDate, DateTime endDate) + { + Dictionary ImgDictionary = new Dictionary(); + + if (string.IsNullOrWhiteSpace(startDate.Month.ToString()) && string.IsNullOrWhiteSpace(endDate.Month .ToString())) + { + return ImgDictionary; + } + //选择查询日期日期 + string sql = "SELECT * FROM SecurityData WHERE EvenTime between @time_start and @time_end"; + SqlParameter[] sqlParameter = new SqlParameter[] { new SqlParameter("time_start", startDate.Year + "/" + startDate.Month + "/" + startDate.Day), new SqlParameter("time_end", endDate.Year + "/" + endDate.Month + "/" + endDate.Day+" 23:59:59" )}; + + DataSet ds = SQLHelper.getData(sql, sqlParameter); + + for (int i = 0; i < ds.Tables[0].Rows.Count; i++) + { + ImgDictionary.Add(ds.Tables[0].Rows[i]["EvenTime"].ToString(), Image.FromStream(new MemoryStream((byte[])ds.Tables[0].Rows[i]["EvenImage"]))); + } + + return ImgDictionary; + } + + public static SQLRes EnvironmentUpData(bool fire, bool smoke, string light, string temperature, string humidity) + { + + SQLRes sqlRes = new SQLRes(); + + string sqlStr = "INSERT INTO EnvironmentData (Fire ,Smoke ,Temperature ,Humidity , Light, _Time) VALUES (@fire,@smoke,@temperature,@humidity,@light,@time)"; + SqlParameter[] sqlParameter = new SqlParameter[] { new SqlParameter("time", DateTime.Now.ToString()), new SqlParameter("fire", fire), new SqlParameter("smoke", smoke), new SqlParameter("temperature", temperature), new SqlParameter("humidity", humidity), new SqlParameter("light", light) }; + + if (SQLHelper.Exec(sqlStr, sqlParameter) >= 1) + { + sqlRes.Result = true; + sqlRes.Msg = "成功!"; + } + else + { + sqlRes.Result = false; + sqlRes.Msg = "失败!"; + } + + return sqlRes; + + } + + public static DataTable GetEnvironmentGraphData() + { + string sqlStr = "SELECT TOP 7 CONVERT(varchar(10),_Time,120) AS _Time, ROUND(Max(Temperature),2) AS MaxTemperature, ROUND(AVG(Temperature),2) AS AVGTemperature FROM EnvironmentData GROUP BY CONVERT(varchar(10),_Time,120) ORDER BY CONVERT(varchar(10),_Time,120) DESC "; + return SQLHelper.getData(sqlStr, null).Tables[0]; + } + + + } + + class SQLRes + { + public string Msg { get; set; } + public bool Result { get; set; } + } + + } + diff --git a/samples/p8-t4-校园安防/SQLHelpers/SQLHelper.cs b/samples/p8-t4-校园安防/SQLHelpers/SQLHelper.cs new file mode 100644 index 0000000..d37157e --- /dev/null +++ b/samples/p8-t4-校园安防/SQLHelpers/SQLHelper.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 智慧校园.SQLHelpers +{ + class SQLHelper + { + public static string strConn = AppSet.SqlConn; + + public static bool SaveData(string sql, DataTable dt) + { + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + SqlDataAdapter sda = new SqlDataAdapter(sql, conn); + SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(sda); + sda.Update(dt); + conn.Close(); + return true; + } + catch (Exception e) + { + string Error = e.Message; + return false; + } + } + + public static DataSet getData(string sql, params SqlParameter[] para) + { + DataSet ds = new DataSet(); + + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + SqlCommand cmd = new SqlCommand(sql, conn); + if (para != null) + { + foreach (SqlParameter item in para) + { + cmd.Parameters.Add(item); + } + } + SqlDataAdapter sda = new SqlDataAdapter(cmd); + sda.Fill(ds); + cmd.Parameters.Clear(); + conn.Close(); + } + catch(Exception e) + { + string Error = e.Message; + } + + return ds; + } + + public static DataSet getData(SqlCommand cmd) + { + DataSet ds = new DataSet(); + + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + cmd.Connection = conn; + + SqlDataAdapter sda = new SqlDataAdapter(cmd); + sda.Fill(ds); + cmd.Parameters.Clear(); + conn.Close(); + } + catch (Exception e) + { + string Error = e.Message; + } + + return ds; + } + + public static int Exec(string sql, params SqlParameter[] para) + { + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + SqlCommand cmd = new SqlCommand(sql, conn); + if (para != null) + { + foreach (SqlParameter item in para) + { + cmd.Parameters.Add(item); + } + } + int iRsult = cmd.ExecuteNonQuery(); + conn.Close(); + return iRsult; + } + catch (Exception e) + { + string Error = e.Message; + return -1; + } + } + } + } + diff --git a/samples/p8-t4-校园安防/Security.Designer.cs b/samples/p8-t4-校园安防/Security.Designer.cs new file mode 100644 index 0000000..ef0de05 --- /dev/null +++ b/samples/p8-t4-校园安防/Security.Designer.cs @@ -0,0 +1,296 @@ +namespace 智慧校园 +{ + partial class Security + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel3 = new System.Windows.Forms.Panel(); + this.lb_return = new System.Windows.Forms.Label(); + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel_bg_video = new System.Windows.Forms.Panel(); + this.btn_history = new System.Windows.Forms.Button(); + this.btn_camera = new System.Windows.Forms.Button(); + this.panel_video_ctrl = new System.Windows.Forms.Panel(); + this.pic_left = new System.Windows.Forms.PictureBox(); + this.pic_right = new System.Windows.Forms.PictureBox(); + this.pic_down = new System.Windows.Forms.PictureBox(); + this.pic_up = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.lb_infrared = new System.Windows.Forms.Label(); + this.pic_video = new System.Windows.Forms.PictureBox(); + this.panel3.SuspendLayout(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel_bg_video.SuspendLayout(); + this.panel_video_ctrl.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_left)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_right)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_down)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_up)).BeginInit(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_video)).BeginInit(); + this.SuspendLayout(); + // + // panel3 + // + this.panel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(229)))), ((int)(((byte)(229))))); + this.panel3.Controls.Add(this.lb_return); + this.panel3.Dock = System.Windows.Forms.DockStyle.Top; + this.panel3.Location = new System.Drawing.Point(0, 100); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(1081, 39); + this.panel3.TabIndex = 1; + // + // lb_return + // + this.lb_return.AutoSize = true; + this.lb_return.Location = new System.Drawing.Point(25, 12); + this.lb_return.Name = "lb_return"; + this.lb_return.Size = new System.Drawing.Size(83, 12); + this.lb_return.TabIndex = 0; + this.lb_return.Text = "< 返回主窗体"; + this.lb_return.Click += new System.EventHandler(this.lb_return_Click); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(116)))), ((int)(((byte)(133))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1081, 100); + this.panel1.TabIndex = 2; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(44, 12); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(226, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel_bg_video + // + this.panel_bg_video.BackColor = System.Drawing.Color.White; + this.panel_bg_video.Controls.Add(this.btn_history); + this.panel_bg_video.Controls.Add(this.btn_camera); + this.panel_bg_video.Controls.Add(this.panel_video_ctrl); + this.panel_bg_video.Controls.Add(this.panel2); + this.panel_bg_video.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel_bg_video.Location = new System.Drawing.Point(0, 139); + this.panel_bg_video.Name = "panel_bg_video"; + this.panel_bg_video.Size = new System.Drawing.Size(1081, 499); + this.panel_bg_video.TabIndex = 3; + this.panel_bg_video.Paint += new System.Windows.Forms.PaintEventHandler(this.panel_bg_video_Paint); + // + // btn_history + // + this.btn_history.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(143)))), ((int)(((byte)(213)))), ((int)(((byte)(122))))); + this.btn_history.Font = new System.Drawing.Font("微软雅黑", 14F); + this.btn_history.Location = new System.Drawing.Point(804, 410); + this.btn_history.Name = "btn_history"; + this.btn_history.Size = new System.Drawing.Size(160, 49); + this.btn_history.TabIndex = 10; + this.btn_history.Text = "查看历史图像"; + this.btn_history.UseVisualStyleBackColor = false; + // + // btn_camera + // + this.btn_camera.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(200)))), ((int)(((byte)(81))))); + this.btn_camera.Font = new System.Drawing.Font("微软雅黑", 16F); + this.btn_camera.Location = new System.Drawing.Point(804, 326); + this.btn_camera.Name = "btn_camera"; + this.btn_camera.Size = new System.Drawing.Size(160, 49); + this.btn_camera.TabIndex = 9; + this.btn_camera.Text = "拍照"; + this.btn_camera.UseVisualStyleBackColor = false; + this.btn_camera.Click += new System.EventHandler(this.btn_camera_Click); + // + // panel_video_ctrl + // + this.panel_video_ctrl.BackgroundImage = global::智慧校园.Properties.Resources.panel_video_ctrl; + this.panel_video_ctrl.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel_video_ctrl.Controls.Add(this.pic_left); + this.panel_video_ctrl.Controls.Add(this.pic_right); + this.panel_video_ctrl.Controls.Add(this.pic_down); + this.panel_video_ctrl.Controls.Add(this.pic_up); + this.panel_video_ctrl.Location = new System.Drawing.Point(741, 15); + this.panel_video_ctrl.Name = "panel_video_ctrl"; + this.panel_video_ctrl.Size = new System.Drawing.Size(328, 294); + this.panel_video_ctrl.TabIndex = 1; + // + // pic_left + // + this.pic_left.BackgroundImage = global::智慧校园.Properties.Resources.btn_arrow_left_normal; + this.pic_left.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.pic_left.Location = new System.Drawing.Point(63, 116); + this.pic_left.Name = "pic_left"; + this.pic_left.Size = new System.Drawing.Size(39, 54); + this.pic_left.TabIndex = 6; + this.pic_left.TabStop = false; + this.pic_left.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_left_MouseDown); + this.pic_left.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_left_MouseUp); + // + // pic_right + // + this.pic_right.BackgroundImage = global::智慧校园.Properties.Resources.btn_arrow_right_normal; + this.pic_right.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.pic_right.Location = new System.Drawing.Point(223, 116); + this.pic_right.Name = "pic_right"; + this.pic_right.Size = new System.Drawing.Size(39, 54); + this.pic_right.TabIndex = 5; + this.pic_right.TabStop = false; + this.pic_right.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_right_MouseDown); + this.pic_right.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_right_MouseUp); + // + // pic_down + // + this.pic_down.BackgroundImage = global::智慧校园.Properties.Resources.btn_arrow_down_normal; + this.pic_down.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.pic_down.Location = new System.Drawing.Point(143, 202); + this.pic_down.Name = "pic_down"; + this.pic_down.Size = new System.Drawing.Size(39, 54); + this.pic_down.TabIndex = 4; + this.pic_down.TabStop = false; + this.pic_down.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_down_MouseDown); + this.pic_down.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_down_MouseUp); + // + // pic_up + // + this.pic_up.BackgroundImage = global::智慧校园.Properties.Resources.btn_arrow_up_normal; + this.pic_up.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.pic_up.Location = new System.Drawing.Point(142, 20); + this.pic_up.Name = "pic_up"; + this.pic_up.Size = new System.Drawing.Size(39, 54); + this.pic_up.TabIndex = 1; + this.pic_up.TabStop = false; + this.pic_up.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_up_MouseDown); + this.pic_up.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_up_MouseUp); + // + // panel2 + // + this.panel2.BackColor = System.Drawing.Color.DimGray; + this.panel2.Controls.Add(this.label2); + this.panel2.Controls.Add(this.lb_infrared); + this.panel2.Controls.Add(this.pic_video); + this.panel2.Location = new System.Drawing.Point(69, 15); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(666, 472); + this.panel2.TabIndex = 0; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.BackColor = System.Drawing.Color.Transparent; + this.label2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label2.ForeColor = System.Drawing.Color.White; + this.label2.Location = new System.Drawing.Point(545, 91); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(46, 21); + this.label2.TabIndex = 12; + this.label2.Text = "入侵:"; + // + // lb_infrared + // + this.lb_infrared.AutoSize = true; + this.lb_infrared.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.lb_infrared.ForeColor = System.Drawing.Color.White; + this.lb_infrared.Location = new System.Drawing.Point(597, 91); + this.lb_infrared.Name = "lb_infrared"; + this.lb_infrared.Size = new System.Drawing.Size(41, 21); + this.lb_infrared.TabIndex = 11; + this.lb_infrared.Text = "N/A"; + // + // pic_video + // + this.pic_video.BackColor = System.Drawing.Color.DarkGray; + this.pic_video.BackgroundImage = global::智慧校园.Properties.Resources.icon_monitor; + this.pic_video.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + this.pic_video.Location = new System.Drawing.Point(32, 38); + this.pic_video.Name = "pic_video"; + this.pic_video.Size = new System.Drawing.Size(478, 322); + this.pic_video.TabIndex = 0; + this.pic_video.TabStop = false; + this.pic_video.Click += new System.EventHandler(this.pictureBox2_Click); + // + // Security + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1081, 638); + this.Controls.Add(this.panel_bg_video); + this.Controls.Add(this.panel3); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Security"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Security"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Security_FormClosed); + this.Load += new System.EventHandler(this.Security_Load); + this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel_bg_video.ResumeLayout(false); + this.panel_video_ctrl.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pic_left)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_right)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_down)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_up)).EndInit(); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_video)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Label lb_return; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel_bg_video; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.PictureBox pic_video; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label lb_infrared; + private System.Windows.Forms.Button btn_history; + private System.Windows.Forms.Button btn_camera; + private System.Windows.Forms.Panel panel_video_ctrl; + private System.Windows.Forms.PictureBox pic_left; + private System.Windows.Forms.PictureBox pic_right; + private System.Windows.Forms.PictureBox pic_down; + private System.Windows.Forms.PictureBox pic_up; + } +} \ No newline at end of file diff --git a/samples/p8-t4-校园安防/Security.cs b/samples/p8-t4-校园安防/Security.cs new file mode 100644 index 0000000..3b410f5 --- /dev/null +++ b/samples/p8-t4-校园安防/Security.cs @@ -0,0 +1,240 @@ +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.IO; +using System.Threading; + +using DeviceCtrlLibrary; +using 智慧校园.SQLHelpers; + +namespace 智慧校园 +{ + public partial class Security : Form + { //显示图像 + Image img = null; + //入侵标识 + bool IsInfrared = false; + //图像文件夹路径 + string ImgDir = AppDomain.CurrentDomain.BaseDirectory + "Camera\\"; + //用于数据采集和SQL操作 + Thread thread; + SynchronizationContext _main; + public Security() + { + InitializeComponent(); + } + void ipCameraHelper_ImageRead(ImageReadEvenArgs e) + { + img = e.img; + pic_video.Image = e.img; + } + void tick() + { + try + { + while (true) + { + try + { + //采集入侵状态 + IsInfrared = DeviceCtrlHelper.adam4150Helper.SetData().infraredValue; + //UI显示入侵状态 + _main.Send(_ => + { + lb_infrared.Text = IsInfrared ? "发现入侵" : "正常"; + }, null); + + if (IsInfrared) + { + if (img != null) + //上传报警信息 + SQLBLL.SecurityUpData(img); + } + } + catch + { + } + + Thread.Sleep(1000); + } + } + catch + { + } + } + private void pictureBox2_Click(object sender, EventArgs e) + { + + } + + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void panel_bg_video_Paint(object sender, PaintEventArgs e) + { + + } + + private void Security_Load(object sender, EventArgs e) + { + try + { + + + //实例化摄像头控制类 + DeviceCtrlHelper.ipCameraHelper.Open(AppSet.Camera_Ip, AppSet.Camera_Uid, AppSet.Camera_Pwd); + DeviceCtrlHelper.ipCameraHelper.ImageRead += ipCameraHelper_ImageRead; + DeviceCtrlHelper.ipCameraHelper.Start(); + + thread = new Thread(new ThreadStart(tick)); + _main = WindowsFormsSynchronizationContext.Current; + thread.Start(); + + if (!Directory.Exists(ImgDir)) + //创建文件夹 + Directory.CreateDirectory(ImgDir); + } + catch + { + } + } + + private void Security_FormClosed(object sender, FormClosedEventArgs e) + { + try + { + DeviceCtrlHelper.ipCameraHelper.Stop(); + DeviceCtrlHelper.ipCameraHelper.Close(); + thread.Suspend(); + thread = null; + + } + catch + { + } + + } + + private void btn_camera_Click(object sender, EventArgs e) + { + try + { + pic_video.Image.Save(ImgDir + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".jpg"); + SQLBLL.SecurityUpData(pic_video.Image); + } + catch + { + } + + } + + private void pic_up_MouseDown(object sender, MouseEventArgs e) + { + try + { + pic_up.BackgroundImage = Properties.Resources.btn_arrow_up_press; + DeviceCtrlHelper.ipCameraHelper.PanUp(); + } + catch + { + } + } + + private void pic_up_MouseUp(object sender, MouseEventArgs e) + { + try + { + pic_up.BackgroundImage = Properties.Resources.btn_arrow_up_normal; + DeviceCtrlHelper.ipCameraHelper.PanUp(); + } + catch + { + } + } + + private void pic_down_MouseDown(object sender, MouseEventArgs e) + { + try + { + pic_down.BackgroundImage = Properties.Resources.btn_arrow_down_press; + DeviceCtrlHelper.ipCameraHelper.PanDown(); + } + catch + { + } + } + + private void pic_down_MouseUp(object sender, MouseEventArgs e) + { + try + { + pic_down.BackgroundImage = Properties.Resources.btn_arrow_down_normal; + DeviceCtrlHelper.ipCameraHelper.PanDown(); + } + catch + { + } + } + + private void pic_left_MouseDown(object sender, MouseEventArgs e) + { + try + { + pic_left.BackgroundImage = Properties.Resources.btn_arrow_left_press; + DeviceCtrlHelper.ipCameraHelper.PanLeft(); + } + catch + { + } + } + + private void pic_left_MouseUp(object sender, MouseEventArgs e) + { + try + { + pic_left.BackgroundImage = Properties.Resources.btn_arrow_left_normal; + DeviceCtrlHelper.ipCameraHelper.PanLeft(); + } + catch + { + } + } + + private void pic_right_MouseDown(object sender, MouseEventArgs e) + { + try + { + pic_right.BackgroundImage = Properties.Resources.btn_arrow_right_press; + DeviceCtrlHelper.ipCameraHelper.PanRight(); + } + catch + { + } + } + + private void pic_right_MouseUp(object sender, MouseEventArgs e) + { + try + { + pic_right.BackgroundImage = Properties.Resources.btn_arrow_right_normal; + DeviceCtrlHelper.ipCameraHelper.PanRight(); + } + catch + { + } + } + + private void lb_return_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/samples/p8-t4-校园安防/checks.yaml b/samples/p8-t4-校园安防/checks.yaml new file mode 100644 index 0000000..df7f18e --- /dev/null +++ b/samples/p8-t4-校园安防/checks.yaml @@ -0,0 +1,46 @@ +# 评分规则:书上评价表的功能项。每项单独启动一次程序,按步骤操作,核对结果。 +# 格式说明见 server/src/grading/checks.ts +- title: 摄像机能正常打开 + steps: + - click: pic_security + - expect: { window: Security, desc: 点"校园安防"打开 Security 窗体 } + - expect: { camera: on } + - expect: { control: pic_video, image: true, within: 3s, desc: 显示摄像机拍到的图像 } + +- title: 人体入侵有文字提示 + steps: + - click: pic_security + - board: { infrared: true } + - expect: { control: lb_infrared, text: 发现入侵, within: 3s, desc: 红外对射被遮挡时显示"发现入侵" } + - board: { infrared: false } + - expect: { control: lb_infrared, text: 正常, within: 3s } + +- title: 摄像机可以调整方向 + steps: + - click: pic_security + - click: pic_up + - expect: { camera: up, desc: 按"↑"向上转 } + - expect: { control: pic_up, background: btn_arrow_up_normal, desc: 松开后方向键换回原来的图片 } + - click: pic_left + - expect: { camera: left, desc: 按"←"向左转 } + - click: pic_down + - click: pic_down + - expect: { camera: down, desc: 按"↓"向下转 } + - click: pic_right + - click: pic_right + - expect: { camera: right, desc: 按"→"向右转 } + +- title: 摄像机能拍照并保存图片 + steps: + - click: pic_security + - expect: { control: pic_video, image: true, within: 3s } + - click: btn_camera + - expect: { savedImage: Camera/, desc: 把照片保存到 Camera 文件夹 } + +- title: 返回主窗体时关闭摄像机 + steps: + - click: pic_security + - expect: { camera: on } + - click: lb_return + - expect: { window: Security, open: false } + - expect: { camera: off } diff --git a/samples/p8-t4-校园安防/database.sql b/samples/p8-t4-校园安防/database.sql new file mode 100644 index 0000000..2e5eeba --- /dev/null +++ b/samples/p8-t4-校园安防/database.sql @@ -0,0 +1,54 @@ +-- 实验的初始数据库 WisdomCampus(教材"综合实训"附带的库):环境数据表 EnvironmentData、报警图片表 SecurityData、用户表 Users。 +-- EnvironmentData 预置了 7 天的历史数据,"数据分析"的图表一打开就有内容;SecurityData 是空的,拍照或有人入侵时才有记录。 +-- 学生可以在数据库页面"恢复实验初始数据";评分时每个检查项用一份新的。 +CREATE DATABASE WisdomCampus +GO +USE WisdomCampus +GO +CREATE TABLE Users (Id int IDENTITY(1,1) PRIMARY KEY, UserName nvarchar(50) NOT NULL, Password nvarchar(50) NOT NULL) +CREATE TABLE EnvironmentData (Id int IDENTITY(1,1) PRIMARY KEY, Fire bit NOT NULL, Smoke bit NOT NULL, Temperature float NULL, Humidity float NULL, Light float NULL, _Time datetime NOT NULL) +CREATE TABLE SecurityData (Id int IDENTITY(1,1) PRIMARY KEY, EvenTime datetime NOT NULL, EvenImage image NOT NULL) +GO +INSERT INTO Users (UserName, Password) VALUES ('admin', '123') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.9, 58, 258, '2026-10-14 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.1, 53, 475, '2026-10-14 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.8, 51, 761, '2026-10-14 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 22.5, 49, 733, '2026-10-14 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 54, 528, '2026-10-14 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.1, 57, 283, '2026-10-14 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.9, 59, 261, '2026-10-15 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.6, 53, 499, '2026-10-15 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.8, 52, 764, '2026-10-15 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 23.5, 47, 778, '2026-10-15 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.8, 52, 503, '2026-10-15 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.6, 56, 218, '2026-10-15 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 13.9, 63, 258, '2026-10-16 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.6, 60, 477, '2026-10-16 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.8, 51, 741, '2026-10-16 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 20.5, 54, 796, '2026-10-16 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 55, 488, '2026-10-16 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.6, 59, 214, '2026-10-16 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 11.9, 67, 234, '2026-10-17 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.1, 63, 544, '2026-10-17 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.3, 60, 804, '2026-10-17 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.5, 54, 801, '2026-10-17 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.8, 59, 524, '2026-10-17 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.1, 58, 286, '2026-10-17 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.4, 59, 250, '2026-10-18 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.6, 55, 533, '2026-10-18 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.3, 50, 749, '2026-10-18 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 24, 48, 766, '2026-10-18 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 20.8, 54, 534, '2026-10-18 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.1, 53, 241, '2026-10-18 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.4, 54, 253, '2026-10-19 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.1, 50, 474, '2026-10-19 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 22.3, 48, 778, '2026-10-19 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 26, 46, 783, '2026-10-19 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 23.3, 50, 520, '2026-10-19 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 20.6, 50, 213, '2026-10-19 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.9, 62, 230, '2026-10-20 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.6, 52, 471, '2026-10-20 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 53, 751, '2026-10-20 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.5, 48, 747, '2026-10-20 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 55, 527, '2026-10-20 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.1, 57, 220, '2026-10-20 18:00:00') diff --git a/samples/p8-t4-校园安防/meta.json b/samples/p8-t4-校园安防/meta.json new file mode 100644 index 0000000..654ef0f --- /dev/null +++ b/samples/p8-t4-校园安防/meta.json @@ -0,0 +1,4 @@ +{ + "title": "项目8 任务4 实现\"校园安防\"功能模块", + "source": "教材书 p174–180,界面和代码取自配套参考工程;图片是平台素材库里自绘的同名素材(尺寸和教材一致);\"查看历史图像\"在任务 5 做" +} diff --git a/samples/p8-t5-历史图片/AppSet.cs b/samples/p8-t5-历史图片/AppSet.cs new file mode 100644 index 0000000..394d13f --- /dev/null +++ b/samples/p8-t5-历史图片/AppSet.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 智慧校园 +{ + class AppSet + { + //串口设置 + public static string ADAM4017_COM = "COM2"; + public static string ADAM4150_COM = "COM3"; + public static string LED_COM = "COM5"; + public static string ZigBee_COM = "COM4"; + + //摄像机参数 + public static string Camera_Ip = "192.168.1.100"; + public static string Camera_Uid = "admin"; + public static string Camera_Pwd = ""; + + //数据库连接字符串 + public static string SqlConn = "Data Source=.;Initial Catalog=WisdomCampus;User ID=sa;Password=123"; + } +} diff --git a/samples/p8-t5-历史图片/Environment.Designer.cs b/samples/p8-t5-历史图片/Environment.Designer.cs new file mode 100644 index 0000000..856107d --- /dev/null +++ b/samples/p8-t5-历史图片/Environment.Designer.cs @@ -0,0 +1,555 @@ +namespace 智慧校园 +{ + partial class Environment + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Legend legend4 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.panel_bg = new System.Windows.Forms.Panel(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.panel_form = new System.Windows.Forms.Panel(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.pic_lampOpen = new System.Windows.Forms.PictureBox(); + this.label10 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.txt_autoLight = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.ch_autoLamp = new System.Windows.Forms.CheckBox(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.btn_ledEnvironment2 = new System.Windows.Forms.Button(); + this.ch_autoLedFire = new System.Windows.Forms.CheckBox(); + this.btn_ledSendMsg = new System.Windows.Forms.Button(); + this.txt_ledMsg = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.panel5 = new System.Windows.Forms.Panel(); + this.btn_dataAnalyse = new System.Windows.Forms.Button(); + this.btn_ledEnvironment1 = new System.Windows.Forms.Button(); + this.label6 = new System.Windows.Forms.Label(); + this.txt_humidity = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.txt_fire = new System.Windows.Forms.TextBox(); + this.txt_temperature = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.txt_smoke = new System.Windows.Forms.TextBox(); + this.txt_light = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.panel3 = new System.Windows.Forms.Panel(); + this.lb_return = new System.Windows.Forms.Label(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel2.SuspendLayout(); + this.panel_bg.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + this.panel_form.SuspendLayout(); + this.groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_lampOpen)).BeginInit(); + this.groupBox3.SuspendLayout(); + this.panel5.SuspendLayout(); + this.panel3.SuspendLayout(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(116)))), ((int)(((byte)(133))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1043, 100); + this.panel1.TabIndex = 0; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(44, 12); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(226, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel2 + // + this.panel2.Controls.Add(this.panel_bg); + this.panel2.Controls.Add(this.panel3); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 100); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(1043, 691); + this.panel2.TabIndex = 1; + // + // panel_bg + // + this.panel_bg.BackgroundImage = global::智慧校园.Properties.Resources.day_02; + this.panel_bg.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel_bg.Controls.Add(this.chart1); + this.panel_bg.Controls.Add(this.panel_form); + this.panel_bg.Controls.Add(this.panel5); + this.panel_bg.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel_bg.Location = new System.Drawing.Point(0, 39); + this.panel_bg.Name = "panel_bg"; + this.panel_bg.Size = new System.Drawing.Size(1043, 652); + this.panel_bg.TabIndex = 1; + // + // chart1 + // + chartArea2.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea2); + legend3.Name = "MaxLegend"; + legend3.TitleForeColor = System.Drawing.Color.DimGray; + legend4.Name = "AVGLegend"; + legend4.TitleForeColor = System.Drawing.Color.DimGray; + this.chart1.Legends.Add(legend3); + this.chart1.Legends.Add(legend4); + this.chart1.Location = new System.Drawing.Point(44, 172); + this.chart1.Name = "chart1"; + series3.ChartArea = "ChartArea1"; + series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series3.Legend = "MaxLegend"; + series3.LegendText = "最大值"; + series3.Name = "MaxSeries"; + series3.XValueMember = "_Time"; + series3.YValueMembers = "MaxTemperature"; + series4.ChartArea = "ChartArea1"; + series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series4.Legend = "AVGLegend"; + series4.LegendText = "平均值"; + series4.Name = "AVGSeries"; + series4.XValueMember = "_Time"; + series4.YValueMembers = "AVGTemperature"; + this.chart1.Series.Add(series3); + this.chart1.Series.Add(series4); + this.chart1.Size = new System.Drawing.Size(455, 327); + this.chart1.TabIndex = 3; + this.chart1.Text = "chart1"; + // + // panel_form + // + this.panel_form.BackColor = System.Drawing.Color.Transparent; + this.panel_form.BackgroundImage = global::智慧校园.Properties.Resources.bg_from2; + this.panel_form.Controls.Add(this.groupBox2); + this.panel_form.Controls.Add(this.groupBox3); + this.panel_form.Dock = System.Windows.Forms.DockStyle.Right; + this.panel_form.Location = new System.Drawing.Point(617, 0); + this.panel_form.Name = "panel_form"; + this.panel_form.Size = new System.Drawing.Size(426, 552); + this.panel_form.TabIndex = 2; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.pic_lampOpen); + this.groupBox2.Controls.Add(this.label10); + this.groupBox2.Controls.Add(this.label9); + this.groupBox2.Controls.Add(this.txt_autoLight); + this.groupBox2.Controls.Add(this.label7); + this.groupBox2.Controls.Add(this.ch_autoLamp); + this.groupBox2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.groupBox2.ForeColor = System.Drawing.Color.White; + this.groupBox2.Location = new System.Drawing.Point(22, 21); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(392, 150); + this.groupBox2.TabIndex = 3; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "路灯控制"; + // + // pic_lampOpen + // + this.pic_lampOpen.BackgroundImage = global::智慧校园.Properties.Resources.switch_off; + this.pic_lampOpen.Location = new System.Drawing.Point(103, 103); + this.pic_lampOpen.Name = "pic_lampOpen"; + this.pic_lampOpen.Size = new System.Drawing.Size(48, 24); + this.pic_lampOpen.TabIndex = 5; + this.pic_lampOpen.TabStop = false; + this.pic_lampOpen.Click += new System.EventHandler(this.pic_lampOpen_Click); + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(33, 105); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(59, 17); + this.label10.TabIndex = 4; + this.label10.Text = "灯光控制:"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(278, 58); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(17, 17); + this.label9.TabIndex = 3; + this.label9.Text = "lx"; + // + // txt_autoLight + // + this.txt_autoLight.Location = new System.Drawing.Point(128, 55); + this.txt_autoLight.Name = "txt_autoLight"; + this.txt_autoLight.Size = new System.Drawing.Size(144, 23); + this.txt_autoLight.TabIndex = 2; + this.txt_autoLight.TextChanged += new System.EventHandler(this.txt_autoLight_TextChanged); + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(33, 58); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(92, 17); + this.label7.TabIndex = 1; + this.label7.Text = "设定开灯光照值"; + // + // ch_autoLamp + // + this.ch_autoLamp.AutoSize = true; + this.ch_autoLamp.Location = new System.Drawing.Point(35, 30); + this.ch_autoLamp.Name = "ch_autoLamp"; + this.ch_autoLamp.Size = new System.Drawing.Size(75, 21); + this.ch_autoLamp.TabIndex = 0; + this.ch_autoLamp.Text = "自动控制"; + this.ch_autoLamp.UseVisualStyleBackColor = true; + this.ch_autoLamp.CheckedChanged += new System.EventHandler(this.ch_autoLamp_CheckedChanged); + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.btn_ledEnvironment2); + this.groupBox3.Controls.Add(this.ch_autoLedFire); + this.groupBox3.Controls.Add(this.btn_ledSendMsg); + this.groupBox3.Controls.Add(this.txt_ledMsg); + this.groupBox3.Controls.Add(this.label8); + this.groupBox3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.groupBox3.ForeColor = System.Drawing.Color.White; + this.groupBox3.Location = new System.Drawing.Point(22, 209); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(392, 316); + this.groupBox3.TabIndex = 4; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "LED推送"; + // + // btn_ledEnvironment2 + // + this.btn_ledEnvironment2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(86)))), ((int)(((byte)(149)))), ((int)(((byte)(212))))); + this.btn_ledEnvironment2.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledEnvironment2.Location = new System.Drawing.Point(234, 217); + this.btn_ledEnvironment2.Name = "btn_ledEnvironment2"; + this.btn_ledEnvironment2.Size = new System.Drawing.Size(145, 32); + this.btn_ledEnvironment2.TabIndex = 11; + this.btn_ledEnvironment2.Text = "推送天气信息"; + this.btn_ledEnvironment2.UseVisualStyleBackColor = false; + this.btn_ledEnvironment2.Click += new System.EventHandler(this.btn_ledEnvironment2_Click); + // + // ch_autoLedFire + // + this.ch_autoLedFire.AutoSize = true; + this.ch_autoLedFire.Location = new System.Drawing.Point(265, 35); + this.ch_autoLedFire.Name = "ch_autoLedFire"; + this.ch_autoLedFire.Size = new System.Drawing.Size(99, 21); + this.ch_autoLedFire.TabIndex = 4; + this.ch_autoLedFire.Text = "自动推送火情"; + this.ch_autoLedFire.UseVisualStyleBackColor = true; + this.ch_autoLedFire.CheckedChanged += new System.EventHandler(this.ch_autoLedFire_CheckedChanged); + // + // btn_ledSendMsg + // + this.btn_ledSendMsg.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(168)))), ((int)(((byte)(255))))); + this.btn_ledSendMsg.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledSendMsg.Location = new System.Drawing.Point(26, 217); + this.btn_ledSendMsg.Name = "btn_ledSendMsg"; + this.btn_ledSendMsg.Size = new System.Drawing.Size(145, 32); + this.btn_ledSendMsg.TabIndex = 2; + this.btn_ledSendMsg.Text = "推送LED信息"; + this.btn_ledSendMsg.UseVisualStyleBackColor = false; + this.btn_ledSendMsg.Click += new System.EventHandler(this.btn_ledSendMsg_Click); + // + // txt_ledMsg + // + this.txt_ledMsg.Location = new System.Drawing.Point(23, 62); + this.txt_ledMsg.Multiline = true; + this.txt_ledMsg.Name = "txt_ledMsg"; + this.txt_ledMsg.Size = new System.Drawing.Size(356, 130); + this.txt_ledMsg.TabIndex = 1; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(20, 36); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(54, 17); + this.label8.TabIndex = 0; + this.label8.Text = "LED信息"; + // + // panel5 + // + this.panel5.Controls.Add(this.btn_dataAnalyse); + this.panel5.Controls.Add(this.btn_ledEnvironment1); + this.panel5.Controls.Add(this.label6); + this.panel5.Controls.Add(this.txt_humidity); + this.panel5.Controls.Add(this.label1); + this.panel5.Controls.Add(this.label5); + this.panel5.Controls.Add(this.txt_fire); + this.panel5.Controls.Add(this.txt_temperature); + this.panel5.Controls.Add(this.label2); + this.panel5.Controls.Add(this.label4); + this.panel5.Controls.Add(this.txt_smoke); + this.panel5.Controls.Add(this.txt_light); + this.panel5.Controls.Add(this.label3); + this.panel5.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel5.Location = new System.Drawing.Point(0, 552); + this.panel5.Name = "panel5"; + this.panel5.Size = new System.Drawing.Size(1043, 100); + this.panel5.TabIndex = 1; + // + // btn_dataAnalyse + // + this.btn_dataAnalyse.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(168)))), ((int)(((byte)(255))))); + this.btn_dataAnalyse.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_dataAnalyse.Location = new System.Drawing.Point(792, 35); + this.btn_dataAnalyse.Name = "btn_dataAnalyse"; + this.btn_dataAnalyse.Size = new System.Drawing.Size(119, 32); + this.btn_dataAnalyse.TabIndex = 23; + this.btn_dataAnalyse.Text = "数据分析"; + this.btn_dataAnalyse.UseVisualStyleBackColor = false; + this.btn_dataAnalyse.Click += new System.EventHandler(this.btn_dataAnalyse_Click); + // + // btn_ledEnvironment1 + // + this.btn_ledEnvironment1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(86)))), ((int)(((byte)(149)))), ((int)(((byte)(212))))); + this.btn_ledEnvironment1.Font = new System.Drawing.Font("微软雅黑", 12F); + this.btn_ledEnvironment1.Location = new System.Drawing.Point(910, 35); + this.btn_ledEnvironment1.Name = "btn_ledEnvironment1"; + this.btn_ledEnvironment1.Size = new System.Drawing.Size(121, 32); + this.btn_ledEnvironment1.TabIndex = 15; + this.btn_ledEnvironment1.Text = "推送天气信息"; + this.btn_ledEnvironment1.UseVisualStyleBackColor = false; + this.btn_ledEnvironment1.Click += new System.EventHandler(this.btn_ledEnvironment1_Click); + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("微软雅黑", 18F); + this.label6.Location = new System.Drawing.Point(12, 31); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(110, 31); + this.label6.TabIndex = 11; + this.label6.Text = "环境数据"; + // + // txt_humidity + // + this.txt_humidity.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_humidity.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_humidity.Location = new System.Drawing.Point(716, 36); + this.txt_humidity.Name = "txt_humidity"; + this.txt_humidity.Size = new System.Drawing.Size(70, 32); + this.txt_humidity.TabIndex = 22; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label1.Location = new System.Drawing.Point(132, 38); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(50, 25); + this.label1.TabIndex = 12; + this.label1.Text = "火焰"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label5.Location = new System.Drawing.Point(660, 39); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(50, 25); + this.label5.TabIndex = 21; + this.label5.Text = "湿度"; + // + // txt_fire + // + this.txt_fire.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_fire.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_fire.Location = new System.Drawing.Point(188, 35); + this.txt_fire.Name = "txt_fire"; + this.txt_fire.Size = new System.Drawing.Size(70, 32); + this.txt_fire.TabIndex = 13; + // + // txt_temperature + // + this.txt_temperature.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_temperature.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_temperature.Location = new System.Drawing.Point(584, 35); + this.txt_temperature.Name = "txt_temperature"; + this.txt_temperature.Size = new System.Drawing.Size(70, 32); + this.txt_temperature.TabIndex = 20; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label2.Location = new System.Drawing.Point(264, 36); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(50, 25); + this.label2.TabIndex = 14; + this.label2.Text = "烟雾"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label4.Location = new System.Drawing.Point(528, 38); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(50, 25); + this.label4.TabIndex = 19; + this.label4.Text = "温度"; + // + // txt_smoke + // + this.txt_smoke.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_smoke.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_smoke.Location = new System.Drawing.Point(320, 33); + this.txt_smoke.Name = "txt_smoke"; + this.txt_smoke.Size = new System.Drawing.Size(70, 32); + this.txt_smoke.TabIndex = 16; + // + // txt_light + // + this.txt_light.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(206)))), ((int)(((byte)(206))))); + this.txt_light.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txt_light.Location = new System.Drawing.Point(452, 32); + this.txt_light.Name = "txt_light"; + this.txt_light.Size = new System.Drawing.Size(70, 32); + this.txt_light.TabIndex = 18; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("微软雅黑", 14F); + this.label3.Location = new System.Drawing.Point(396, 35); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(50, 25); + this.label3.TabIndex = 17; + this.label3.Text = "光照"; + // + // panel3 + // + this.panel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(229)))), ((int)(((byte)(229))))); + this.panel3.Controls.Add(this.lb_return); + this.panel3.Dock = System.Windows.Forms.DockStyle.Top; + this.panel3.Location = new System.Drawing.Point(0, 0); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(1043, 39); + this.panel3.TabIndex = 0; + this.panel3.Paint += new System.Windows.Forms.PaintEventHandler(this.panel3_Paint); + // + // lb_return + // + this.lb_return.AutoSize = true; + this.lb_return.Location = new System.Drawing.Point(25, 12); + this.lb_return.Name = "lb_return"; + this.lb_return.Size = new System.Drawing.Size(83, 12); + this.lb_return.TabIndex = 0; + this.lb_return.Text = "< 返回主窗体"; + this.lb_return.Click += new System.EventHandler(this.lb_return_Click); + // + // Environment + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1043, 791); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Environment"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Environment"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Environment_FormClosed); + this.Load += new System.EventHandler(this.Environment_Load); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel2.ResumeLayout(false); + this.panel_bg.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + this.panel_form.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_lampOpen)).EndInit(); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.panel5.ResumeLayout(false); + this.panel5.PerformLayout(); + this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Label lb_return; + private System.Windows.Forms.Panel panel_bg; + private System.Windows.Forms.Panel panel5; + private System.Windows.Forms.Panel panel_form; + private System.Windows.Forms.Button btn_dataAnalyse; + private System.Windows.Forms.Button btn_ledEnvironment1; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox txt_humidity; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txt_fire; + private System.Windows.Forms.TextBox txt_temperature; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox txt_smoke; + private System.Windows.Forms.TextBox txt_light; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.PictureBox pic_lampOpen; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.TextBox txt_autoLight; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.CheckBox ch_autoLamp; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.Button btn_ledEnvironment2; + private System.Windows.Forms.CheckBox ch_autoLedFire; + private System.Windows.Forms.Button btn_ledSendMsg; + private System.Windows.Forms.TextBox txt_ledMsg; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + } +} \ No newline at end of file diff --git a/samples/p8-t5-历史图片/Environment.cs b/samples/p8-t5-历史图片/Environment.cs new file mode 100644 index 0000000..c136074 --- /dev/null +++ b/samples/p8-t5-历史图片/Environment.cs @@ -0,0 +1,279 @@ +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 DeviceCtrlLibrary; +using DeviceCtrlLibrary.Model; +using 智慧校园.SQLHelpers; +using System.Threading; + +namespace 智慧校园 +{ + public partial class Environment : Form + { + public Environment() + { + InitializeComponent(); + } + //用于各类耗时长的操作(SQL、数据采集、设备控制等) + Thread thread; + //用于异步通行 + SynchronizationContext _main; + //结果模型 + ADAM4017ResModel ResModel_4017; + ADAM4150ResModel ResModel_4150; + //设置自动控制路灯的光照值 + double environmentLight, setLight; + //按钮状态标志 + bool IsAuto_Lamp = false; + bool IsAuto_FireMsg = false; + bool IsLampOpen = false; + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void lb_return_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void Environment_Load(object sender, EventArgs e) + { + try + { + + //隐藏曲线图 + chart1.Visible = false; + thread = new Thread(new ThreadStart(Tick)); + _main = WindowsFormsSynchronizationContext.Current; + thread.Start(); + } + catch + { + } + + } + private void Tick() + { + try + { + while (true) + { + //数据采集 + ResModel_4017 = DeviceCtrlHelper.adam4017Helper.SetData(); + Thread.Sleep(500); + ResModel_4150 = DeviceCtrlHelper.adam4150Helper.SetData(); + + //UI显示数据 + + _main.Send(_ => + { + try //防止无数据出错 + { + txt_fire.Text = (ResModel_4150.fireValue ? "发生火情" : "正常"); + txt_smoke.Text = (ResModel_4150.smokeValue ? "发生烟情" : "正常"); + txt_light.Text = ResModel_4017.lightValue; + txt_temperature.Text = ResModel_4017.temperatureValue; + txt_humidity.Text = ResModel_4017.humidityValue; + } + catch { } + }, null); + + //自动路灯控制 + double.TryParse(ResModel_4017.lightValue, out environmentLight); + if (IsAuto_Lamp && environmentLight < setLight) + { + LampOnOff(1, true); + } + else if (IsAuto_Lamp && !(environmentLight < setLight)) + { + LampOnOff(1, false); + } + + //自动推送火情LED信息控制 + if (IsAuto_FireMsg) + { + if (ResModel_4150.fireValue && ResModel_4150.smokeValue) + DeviceCtrlHelper.ledHelper.SendLedString("发生严重火灾 "); + else if (ResModel_4150.fireValue) + DeviceCtrlHelper.ledHelper.SendLedString("发现火情 "); + else if (ResModel_4150.smokeValue) + DeviceCtrlHelper.ledHelper.SendLedString("发现烟情 "); + } + + //执行数据上传 + SQLBLL.EnvironmentUpData(ResModel_4150.fireValue, ResModel_4150.smokeValue, ResModel_4017.lightValue, ResModel_4017.temperatureValue, ResModel_4017.humidityValue); + + Thread.Sleep(5000); + } + } + catch + { + } + } + private void LampOnOff(int RelayNum, bool IsOpen) + { + try + { + //开启路灯 + DeviceCtrlHelper.zigBeeHelper.OnOff(RelayNum, IsOpen); + + //切换UI背景 + _main.Send(_ => + { + if (IsOpen) + { + pic_lampOpen.BackgroundImage = Properties.Resources.switch_on; + panel_bg.BackgroundImage = Properties.Resources.day_01; + } + else + { + panel_bg.BackgroundImage = Properties.Resources.day_02; + pic_lampOpen.BackgroundImage = Properties.Resources.switch_off; + } + }, null); + } + catch + { + } + } + + private void Environment_FormClosed(object sender, FormClosedEventArgs e) + { + try + { + thread.Suspend(); + thread = null; + + } + catch + { + } + + + } + + private void btn_dataAnalyse_Click(object sender, EventArgs e) + { + try + { + if (btn_dataAnalyse.Text.Equals("数据分析")) + { + //绑定图标数据 + chart1.DataSource = SQLBLL.GetEnvironmentGraphData(); + //更新图标数据 + chart1.DataBind(); + chart1.Visible = true; + btn_dataAnalyse.Text = "关闭图表"; + } + else if (btn_dataAnalyse.Text.Equals("关闭图表")) + { + chart1.Visible = false; + btn_dataAnalyse.Text = "数据分析"; + } + } + catch + { + } + + } + + private void pic_lampOpen_Click(object sender, EventArgs e) + { + //手动路灯控制 + try + { + if (!IsLampOpen) + { + LampOnOff(1, true); + + } + else + { + LampOnOff(1, false); + + } + + IsLampOpen = !IsLampOpen; + } + catch + { + } + } + + private void btn_ledEnvironment1_Click(object sender, EventArgs e) + { + try + { + //推送LED天气信息 + if (ResModel_4017 != null && ResModel_4150 != null) + DeviceCtrlHelper.ledHelper.SendLedString("当前温度:" + ResModel_4017.temperatureValue + "℃ 湿度:" + ResModel_4017.humidityValue + "%"); + } + catch + { + } + } + + private void btn_ledEnvironment2_Click(object sender, EventArgs e) + { + try + { + //推送LED天气信息 + if (ResModel_4017 != null && ResModel_4150 != null) + DeviceCtrlHelper.ledHelper.SendLedString("当前温度:" + ResModel_4017.temperatureValue + "℃ 湿度:" + ResModel_4017.humidityValue + "%"); + } + catch + { + } + } + + private void panel3_Paint(object sender, PaintEventArgs e) + { + + } + + private void txt_autoLight_TextChanged(object sender, EventArgs e) + { + try + { + //获取光照比较值 + double.TryParse(txt_autoLight.Text,out setLight); + + } + + catch + { + } + } + + private void btn_ledSendMsg_Click(object sender, EventArgs e) + { + try + { + //推送LED信息 + DeviceCtrlHelper.ledHelper.SendLedString(txt_ledMsg.Text); + } + catch + { + } + } + + private void ch_autoLamp_CheckedChanged(object sender, EventArgs e) + { + //自动控制路灯 + IsAuto_Lamp = ch_autoLamp.Checked; + } + + private void ch_autoLedFire_CheckedChanged(object sender, EventArgs e) + { + //自动推送火情 + IsAuto_FireMsg = ch_autoLedFire.Checked; + } + } +} diff --git a/samples/p8-t5-历史图片/Main.Designer.cs b/samples/p8-t5-历史图片/Main.Designer.cs new file mode 100644 index 0000000..dc4cf19 --- /dev/null +++ b/samples/p8-t5-历史图片/Main.Designer.cs @@ -0,0 +1,145 @@ +namespace 智慧校园 +{ + partial class Main + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.pic_exit = new System.Windows.Forms.PictureBox(); + this.pic_security = new System.Windows.Forms.PictureBox(); + this.pic_environment = new System.Windows.Forms.PictureBox(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_exit)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_security)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_environment)).BeginInit(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(53)))), ((int)(((byte)(147)))), ((int)(((byte)(237))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1018, 100); + this.panel1.TabIndex = 0; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(57, 23); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(197, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel2 + // + this.panel2.BackgroundImage = global::智慧校园.Properties.Resources.bg_home; + this.panel2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel2.Controls.Add(this.pic_exit); + this.panel2.Controls.Add(this.pic_security); + this.panel2.Controls.Add(this.pic_environment); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(0, 100); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(1018, 516); + this.panel2.TabIndex = 1; + this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint); + // + // pic_exit + // + this.pic_exit.BackColor = System.Drawing.Color.Transparent; + this.pic_exit.Image = global::智慧校园.Properties.Resources.icon_04; + this.pic_exit.Location = new System.Drawing.Point(660, 124); + this.pic_exit.Name = "pic_exit"; + this.pic_exit.Size = new System.Drawing.Size(180, 210); + this.pic_exit.TabIndex = 6; + this.pic_exit.TabStop = false; + this.pic_exit.Click += new System.EventHandler(this.pic_exit_Click); + // + // pic_security + // + this.pic_security.BackColor = System.Drawing.Color.Transparent; + this.pic_security.Image = global::智慧校园.Properties.Resources.icon_03; + this.pic_security.Location = new System.Drawing.Point(404, 124); + this.pic_security.Name = "pic_security"; + this.pic_security.Size = new System.Drawing.Size(180, 210); + this.pic_security.TabIndex = 5; + this.pic_security.TabStop = false; + this.pic_security.Click += new System.EventHandler(this.pic_security_Click); + // + // pic_environment + // + this.pic_environment.BackColor = System.Drawing.Color.Transparent; + this.pic_environment.Image = global::智慧校园.Properties.Resources.icon_02; + this.pic_environment.Location = new System.Drawing.Point(133, 124); + this.pic_environment.Name = "pic_environment"; + this.pic_environment.Size = new System.Drawing.Size(180, 210); + this.pic_environment.TabIndex = 4; + this.pic_environment.TabStop = false; + this.pic_environment.Click += new System.EventHandler(this.pic_environment_Click); + // + // Main + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1018, 616); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Main"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Main_Load); + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pic_exit)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_security)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_environment)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.PictureBox pic_exit; + private System.Windows.Forms.PictureBox pic_security; + private System.Windows.Forms.PictureBox pic_environment; + } +} + diff --git a/samples/p8-t5-历史图片/Main.cs b/samples/p8-t5-历史图片/Main.cs new file mode 100644 index 0000000..075f2c6 --- /dev/null +++ b/samples/p8-t5-历史图片/Main.cs @@ -0,0 +1,72 @@ +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 DeviceCtrlLibrary; +namespace 智慧校园 +{ + public partial class Main : Form + { + public Main() + { + InitializeComponent(); + } + + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void pic_environment_Click(object sender, EventArgs e) + { + try + { + new Environment().Show(); + + } + catch + { + } + } + + private void panel2_Paint(object sender, PaintEventArgs e) + { + + } + + private void Main_Load(object sender, EventArgs e) + { + try + { + //实例化工具类 + DeviceCtrlHelper.adam4017Helper.Open(AppSet.ADAM4017_COM); + DeviceCtrlHelper.adam4150Helper.Open(AppSet.ADAM4150_COM); + DeviceCtrlHelper.zigBeeHelper.Open(AppSet.ZigBee_COM); + DeviceCtrlHelper.ledHelper.OpenLedCom(AppSet.LED_COM); + } + catch { } + } + + private void pic_security_Click(object sender, EventArgs e) + { + try + { + new Security().Show(); + + } + catch + { + } + } + + private void pic_exit_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/samples/p8-t5-历史图片/Program.cs b/samples/p8-t5-历史图片/Program.cs new file mode 100644 index 0000000..2fd691b --- /dev/null +++ b/samples/p8-t5-历史图片/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 智慧校园 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Main()); + } + } +} diff --git a/samples/p8-t5-历史图片/Properties/Resources.Designer.cs b/samples/p8-t5-历史图片/Properties/Resources.Designer.cs new file mode 100644 index 0000000..0ed5c14 --- /dev/null +++ b/samples/p8-t5-历史图片/Properties/Resources.Designer.cs @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// 项目资源(平台素材库)。在"项目资源"里添加或移除,不要手动修改这个文件。 +// +//------------------------------------------------------------------------------ + +namespace 智慧校园.Properties { + + /// + /// 项目资源:Properties.Resources.资源名 + /// + internal class Resources { + + /// 标题:智慧校园 + internal static System.Drawing.Bitmap ico_title { + get { return global::Sim.Host.ProjectResources.Image("ico_title.png"); } + } + + /// 主界面背景:校园 + internal static System.Drawing.Bitmap bg_home { + get { return global::Sim.Host.ProjectResources.Image("bg_home.png"); } + } + + /// 图标:校园环境 + internal static System.Drawing.Bitmap icon_02 { + get { return global::Sim.Host.ProjectResources.Image("icon_02.png"); } + } + + /// 图标:校园安防 + internal static System.Drawing.Bitmap icon_03 { + get { return global::Sim.Host.ProjectResources.Image("icon_03.png"); } + } + + /// 图标:退出 + internal static System.Drawing.Bitmap icon_04 { + get { return global::Sim.Host.ProjectResources.Image("icon_04.png"); } + } + + /// 路灯场景:亮灯 + internal static System.Drawing.Bitmap day_01 { + get { return global::Sim.Host.ProjectResources.Image("day_01.png"); } + } + + /// 路灯场景:灭灯 + internal static System.Drawing.Bitmap day_02 { + get { return global::Sim.Host.ProjectResources.Image("day_02.png"); } + } + + /// 面板背景(窄) + internal static System.Drawing.Bitmap bg_from2 { + get { return global::Sim.Host.ProjectResources.Image("bg_from2.png"); } + } + + /// 开关:开 + internal static System.Drawing.Bitmap switch_on { + get { return global::Sim.Host.ProjectResources.Image("switch_on.png"); } + } + + /// 开关:关 + internal static System.Drawing.Bitmap switch_off { + get { return global::Sim.Host.ProjectResources.Image("switch_off.png"); } + } + + /// 监控:无画面 + internal static System.Drawing.Bitmap icon_monitor { + get { return global::Sim.Host.ProjectResources.Image("icon_monitor.png"); } + } + + /// 监控:方向盘底座 + internal static System.Drawing.Bitmap panel_video_ctrl { + get { return global::Sim.Host.ProjectResources.Image("panel_video_ctrl.png"); } + } + + /// 方向键:上 + internal static System.Drawing.Bitmap btn_arrow_up_normal { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_up_normal.png"); } + } + + /// 方向键:上(按下) + internal static System.Drawing.Bitmap btn_arrow_up_press { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_up_press.png"); } + } + + /// 方向键:下 + internal static System.Drawing.Bitmap btn_arrow_down_normal { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_down_normal.png"); } + } + + /// 方向键:下(按下) + internal static System.Drawing.Bitmap btn_arrow_down_press { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_down_press.png"); } + } + + /// 方向键:左 + internal static System.Drawing.Bitmap btn_arrow_left_normal { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_left_normal.png"); } + } + + /// 方向键:左(按下) + internal static System.Drawing.Bitmap btn_arrow_left_press { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_left_press.png"); } + } + + /// 方向键:右 + internal static System.Drawing.Bitmap btn_arrow_right_normal { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_right_normal.png"); } + } + + /// 方向键:右(按下) + internal static System.Drawing.Bitmap btn_arrow_right_press { + get { return global::Sim.Host.ProjectResources.Image("btn_arrow_right_press.png"); } + } + + /// 翻页:上一张 + internal static System.Drawing.Bitmap arrow_left_normal { + get { return global::Sim.Host.ProjectResources.Image("arrow_left_normal.png"); } + } + + /// 翻页:下一张 + internal static System.Drawing.Bitmap arrow_right_normal { + get { return global::Sim.Host.ProjectResources.Image("arrow_right_normal.png"); } + } + + /// 关闭按钮 + internal static System.Drawing.Bitmap windowstate_closed_hover { + get { return global::Sim.Host.ProjectResources.Image("windowstate_closed_hover.png"); } + } + } +} diff --git a/samples/p8-t5-历史图片/SQLHelpers/SQLBLL.cs b/samples/p8-t5-历史图片/SQLHelpers/SQLBLL.cs new file mode 100644 index 0000000..c737537 --- /dev/null +++ b/samples/p8-t5-历史图片/SQLHelpers/SQLBLL.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 智慧校园.SQLHelpers +{ + class SQLBLL + { + + public static SQLRes SecurityUpData(Image img)//把图片保存到数据库 + { + SQLRes sqlRes = new SQLRes(); + byte[] imgByte = null; + + using (MemoryStream ms = new MemoryStream())//图片转换为二进制数组 + { + img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); + imgByte = new byte[ms.Length]; + imgByte = ms.ToArray(); + } + + string sqlStr = "INSERT INTO SecurityData (EvenTime,EvenImage) VALUES (@time,@img)"; + SqlParameter[] sqlParameter = new SqlParameter[] { new SqlParameter("time", DateTime.Now.ToString()), new SqlParameter("img", imgByte) }; + + if (SQLHelper.Exec(sqlStr, sqlParameter) >= 1) + { + sqlRes.Result = true; + sqlRes.Msg = "成功!"; + } + else + { + sqlRes.Result = false; + sqlRes.Msg = "失败!"; + } + + return sqlRes; + } + + public static Dictionary GetSecurityData(DateTime startDate, DateTime endDate) + { + Dictionary ImgDictionary = new Dictionary(); + + if (string.IsNullOrWhiteSpace(startDate.Month.ToString()) && string.IsNullOrWhiteSpace(endDate.Month .ToString())) + { + return ImgDictionary; + } + //选择查询日期日期 + string sql = "SELECT * FROM SecurityData WHERE EvenTime between @time_start and @time_end"; + SqlParameter[] sqlParameter = new SqlParameter[] { new SqlParameter("time_start", startDate.Year + "/" + startDate.Month + "/" + startDate.Day), new SqlParameter("time_end", endDate.Year + "/" + endDate.Month + "/" + endDate.Day+" 23:59:59" )}; + + DataSet ds = SQLHelper.getData(sql, sqlParameter); + + for (int i = 0; i < ds.Tables[0].Rows.Count; i++) + { + ImgDictionary.Add(ds.Tables[0].Rows[i]["EvenTime"].ToString(), Image.FromStream(new MemoryStream((byte[])ds.Tables[0].Rows[i]["EvenImage"]))); + } + + return ImgDictionary; + } + + public static SQLRes EnvironmentUpData(bool fire, bool smoke, string light, string temperature, string humidity) + { + + SQLRes sqlRes = new SQLRes(); + + string sqlStr = "INSERT INTO EnvironmentData (Fire ,Smoke ,Temperature ,Humidity , Light, _Time) VALUES (@fire,@smoke,@temperature,@humidity,@light,@time)"; + SqlParameter[] sqlParameter = new SqlParameter[] { new SqlParameter("time", DateTime.Now.ToString()), new SqlParameter("fire", fire), new SqlParameter("smoke", smoke), new SqlParameter("temperature", temperature), new SqlParameter("humidity", humidity), new SqlParameter("light", light) }; + + if (SQLHelper.Exec(sqlStr, sqlParameter) >= 1) + { + sqlRes.Result = true; + sqlRes.Msg = "成功!"; + } + else + { + sqlRes.Result = false; + sqlRes.Msg = "失败!"; + } + + return sqlRes; + + } + + public static DataTable GetEnvironmentGraphData() + { + string sqlStr = "SELECT TOP 7 CONVERT(varchar(10),_Time,120) AS _Time, ROUND(Max(Temperature),2) AS MaxTemperature, ROUND(AVG(Temperature),2) AS AVGTemperature FROM EnvironmentData GROUP BY CONVERT(varchar(10),_Time,120) ORDER BY CONVERT(varchar(10),_Time,120) DESC "; + return SQLHelper.getData(sqlStr, null).Tables[0]; + } + + + } + + class SQLRes + { + public string Msg { get; set; } + public bool Result { get; set; } + } + + } + diff --git a/samples/p8-t5-历史图片/SQLHelpers/SQLHelper.cs b/samples/p8-t5-历史图片/SQLHelpers/SQLHelper.cs new file mode 100644 index 0000000..d37157e --- /dev/null +++ b/samples/p8-t5-历史图片/SQLHelpers/SQLHelper.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 智慧校园.SQLHelpers +{ + class SQLHelper + { + public static string strConn = AppSet.SqlConn; + + public static bool SaveData(string sql, DataTable dt) + { + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + SqlDataAdapter sda = new SqlDataAdapter(sql, conn); + SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(sda); + sda.Update(dt); + conn.Close(); + return true; + } + catch (Exception e) + { + string Error = e.Message; + return false; + } + } + + public static DataSet getData(string sql, params SqlParameter[] para) + { + DataSet ds = new DataSet(); + + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + SqlCommand cmd = new SqlCommand(sql, conn); + if (para != null) + { + foreach (SqlParameter item in para) + { + cmd.Parameters.Add(item); + } + } + SqlDataAdapter sda = new SqlDataAdapter(cmd); + sda.Fill(ds); + cmd.Parameters.Clear(); + conn.Close(); + } + catch(Exception e) + { + string Error = e.Message; + } + + return ds; + } + + public static DataSet getData(SqlCommand cmd) + { + DataSet ds = new DataSet(); + + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + cmd.Connection = conn; + + SqlDataAdapter sda = new SqlDataAdapter(cmd); + sda.Fill(ds); + cmd.Parameters.Clear(); + conn.Close(); + } + catch (Exception e) + { + string Error = e.Message; + } + + return ds; + } + + public static int Exec(string sql, params SqlParameter[] para) + { + try + { + SqlConnection conn = new SqlConnection(strConn); + conn.Open(); + SqlCommand cmd = new SqlCommand(sql, conn); + if (para != null) + { + foreach (SqlParameter item in para) + { + cmd.Parameters.Add(item); + } + } + int iRsult = cmd.ExecuteNonQuery(); + conn.Close(); + return iRsult; + } + catch (Exception e) + { + string Error = e.Message; + return -1; + } + } + } + } + diff --git a/samples/p8-t5-历史图片/Security.Designer.cs b/samples/p8-t5-历史图片/Security.Designer.cs new file mode 100644 index 0000000..97c6b9c --- /dev/null +++ b/samples/p8-t5-历史图片/Security.Designer.cs @@ -0,0 +1,297 @@ +namespace 智慧校园 +{ + partial class Security + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel3 = new System.Windows.Forms.Panel(); + this.lb_return = new System.Windows.Forms.Label(); + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel_bg_video = new System.Windows.Forms.Panel(); + this.btn_history = new System.Windows.Forms.Button(); + this.btn_camera = new System.Windows.Forms.Button(); + this.panel_video_ctrl = new System.Windows.Forms.Panel(); + this.pic_left = new System.Windows.Forms.PictureBox(); + this.pic_right = new System.Windows.Forms.PictureBox(); + this.pic_down = new System.Windows.Forms.PictureBox(); + this.pic_up = new System.Windows.Forms.PictureBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.lb_infrared = new System.Windows.Forms.Label(); + this.pic_video = new System.Windows.Forms.PictureBox(); + this.panel3.SuspendLayout(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel_bg_video.SuspendLayout(); + this.panel_video_ctrl.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_left)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_right)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_down)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_up)).BeginInit(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_video)).BeginInit(); + this.SuspendLayout(); + // + // panel3 + // + this.panel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(229)))), ((int)(((byte)(229))))); + this.panel3.Controls.Add(this.lb_return); + this.panel3.Dock = System.Windows.Forms.DockStyle.Top; + this.panel3.Location = new System.Drawing.Point(0, 100); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(1081, 39); + this.panel3.TabIndex = 1; + // + // lb_return + // + this.lb_return.AutoSize = true; + this.lb_return.Location = new System.Drawing.Point(25, 12); + this.lb_return.Name = "lb_return"; + this.lb_return.Size = new System.Drawing.Size(83, 12); + this.lb_return.TabIndex = 0; + this.lb_return.Text = "< 返回主窗体"; + this.lb_return.Click += new System.EventHandler(this.lb_return_Click); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(116)))), ((int)(((byte)(133))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(1081, 100); + this.panel1.TabIndex = 2; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); + // + // pictureBox1 + // + this.pictureBox1.Image = global::智慧校园.Properties.Resources.ico_title; + this.pictureBox1.Location = new System.Drawing.Point(44, 12); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(226, 54); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel_bg_video + // + this.panel_bg_video.BackColor = System.Drawing.Color.White; + this.panel_bg_video.Controls.Add(this.btn_history); + this.panel_bg_video.Controls.Add(this.btn_camera); + this.panel_bg_video.Controls.Add(this.panel_video_ctrl); + this.panel_bg_video.Controls.Add(this.panel2); + this.panel_bg_video.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel_bg_video.Location = new System.Drawing.Point(0, 139); + this.panel_bg_video.Name = "panel_bg_video"; + this.panel_bg_video.Size = new System.Drawing.Size(1081, 499); + this.panel_bg_video.TabIndex = 3; + this.panel_bg_video.Paint += new System.Windows.Forms.PaintEventHandler(this.panel_bg_video_Paint); + // + // btn_history + // + this.btn_history.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(143)))), ((int)(((byte)(213)))), ((int)(((byte)(122))))); + this.btn_history.Font = new System.Drawing.Font("微软雅黑", 14F); + this.btn_history.Location = new System.Drawing.Point(804, 410); + this.btn_history.Name = "btn_history"; + this.btn_history.Size = new System.Drawing.Size(160, 49); + this.btn_history.TabIndex = 10; + this.btn_history.Text = "查看历史图像"; + this.btn_history.UseVisualStyleBackColor = false; + this.btn_history.Click += new System.EventHandler(this.btn_history_Click); + // + // btn_camera + // + this.btn_camera.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(200)))), ((int)(((byte)(81))))); + this.btn_camera.Font = new System.Drawing.Font("微软雅黑", 16F); + this.btn_camera.Location = new System.Drawing.Point(804, 326); + this.btn_camera.Name = "btn_camera"; + this.btn_camera.Size = new System.Drawing.Size(160, 49); + this.btn_camera.TabIndex = 9; + this.btn_camera.Text = "拍照"; + this.btn_camera.UseVisualStyleBackColor = false; + this.btn_camera.Click += new System.EventHandler(this.btn_camera_Click); + // + // panel_video_ctrl + // + this.panel_video_ctrl.BackgroundImage = global::智慧校园.Properties.Resources.panel_video_ctrl; + this.panel_video_ctrl.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.panel_video_ctrl.Controls.Add(this.pic_left); + this.panel_video_ctrl.Controls.Add(this.pic_right); + this.panel_video_ctrl.Controls.Add(this.pic_down); + this.panel_video_ctrl.Controls.Add(this.pic_up); + this.panel_video_ctrl.Location = new System.Drawing.Point(741, 15); + this.panel_video_ctrl.Name = "panel_video_ctrl"; + this.panel_video_ctrl.Size = new System.Drawing.Size(328, 294); + this.panel_video_ctrl.TabIndex = 1; + // + // pic_left + // + this.pic_left.BackgroundImage = global::智慧校园.Properties.Resources.btn_arrow_left_normal; + this.pic_left.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.pic_left.Location = new System.Drawing.Point(63, 116); + this.pic_left.Name = "pic_left"; + this.pic_left.Size = new System.Drawing.Size(39, 54); + this.pic_left.TabIndex = 6; + this.pic_left.TabStop = false; + this.pic_left.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_left_MouseDown); + this.pic_left.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_left_MouseUp); + // + // pic_right + // + this.pic_right.BackgroundImage = global::智慧校园.Properties.Resources.btn_arrow_right_normal; + this.pic_right.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.pic_right.Location = new System.Drawing.Point(223, 116); + this.pic_right.Name = "pic_right"; + this.pic_right.Size = new System.Drawing.Size(39, 54); + this.pic_right.TabIndex = 5; + this.pic_right.TabStop = false; + this.pic_right.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_right_MouseDown); + this.pic_right.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_right_MouseUp); + // + // pic_down + // + this.pic_down.BackgroundImage = global::智慧校园.Properties.Resources.btn_arrow_down_normal; + this.pic_down.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.pic_down.Location = new System.Drawing.Point(143, 202); + this.pic_down.Name = "pic_down"; + this.pic_down.Size = new System.Drawing.Size(39, 54); + this.pic_down.TabIndex = 4; + this.pic_down.TabStop = false; + this.pic_down.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_down_MouseDown); + this.pic_down.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_down_MouseUp); + // + // pic_up + // + this.pic_up.BackgroundImage = global::智慧校园.Properties.Resources.btn_arrow_up_normal; + this.pic_up.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.pic_up.Location = new System.Drawing.Point(142, 20); + this.pic_up.Name = "pic_up"; + this.pic_up.Size = new System.Drawing.Size(39, 54); + this.pic_up.TabIndex = 1; + this.pic_up.TabStop = false; + this.pic_up.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_up_MouseDown); + this.pic_up.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_up_MouseUp); + // + // panel2 + // + this.panel2.BackColor = System.Drawing.Color.DimGray; + this.panel2.Controls.Add(this.label2); + this.panel2.Controls.Add(this.lb_infrared); + this.panel2.Controls.Add(this.pic_video); + this.panel2.Location = new System.Drawing.Point(69, 15); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(666, 472); + this.panel2.TabIndex = 0; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.BackColor = System.Drawing.Color.Transparent; + this.label2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label2.ForeColor = System.Drawing.Color.White; + this.label2.Location = new System.Drawing.Point(545, 91); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(46, 21); + this.label2.TabIndex = 12; + this.label2.Text = "入侵:"; + // + // lb_infrared + // + this.lb_infrared.AutoSize = true; + this.lb_infrared.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.lb_infrared.ForeColor = System.Drawing.Color.White; + this.lb_infrared.Location = new System.Drawing.Point(597, 91); + this.lb_infrared.Name = "lb_infrared"; + this.lb_infrared.Size = new System.Drawing.Size(41, 21); + this.lb_infrared.TabIndex = 11; + this.lb_infrared.Text = "N/A"; + // + // pic_video + // + this.pic_video.BackColor = System.Drawing.Color.DarkGray; + this.pic_video.BackgroundImage = global::智慧校园.Properties.Resources.icon_monitor; + this.pic_video.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + this.pic_video.Location = new System.Drawing.Point(32, 38); + this.pic_video.Name = "pic_video"; + this.pic_video.Size = new System.Drawing.Size(478, 322); + this.pic_video.TabIndex = 0; + this.pic_video.TabStop = false; + this.pic_video.Click += new System.EventHandler(this.pictureBox2_Click); + // + // Security + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1081, 638); + this.Controls.Add(this.panel_bg_video); + this.Controls.Add(this.panel3); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Security"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Security"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Security_FormClosed); + this.Load += new System.EventHandler(this.Security_Load); + this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel_bg_video.ResumeLayout(false); + this.panel_video_ctrl.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pic_left)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_right)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_down)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_up)).EndInit(); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_video)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Label lb_return; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel_bg_video; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.PictureBox pic_video; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label lb_infrared; + private System.Windows.Forms.Button btn_history; + private System.Windows.Forms.Button btn_camera; + private System.Windows.Forms.Panel panel_video_ctrl; + private System.Windows.Forms.PictureBox pic_left; + private System.Windows.Forms.PictureBox pic_right; + private System.Windows.Forms.PictureBox pic_down; + private System.Windows.Forms.PictureBox pic_up; + } +} \ No newline at end of file diff --git a/samples/p8-t5-历史图片/Security.cs b/samples/p8-t5-历史图片/Security.cs new file mode 100644 index 0000000..f3c083a --- /dev/null +++ b/samples/p8-t5-历史图片/Security.cs @@ -0,0 +1,252 @@ +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.IO; +using System.Threading; + +using DeviceCtrlLibrary; +using 智慧校园.SQLHelpers; + +namespace 智慧校园 +{ + public partial class Security : Form + { //显示图像 + Image img = null; + //入侵标识 + bool IsInfrared = false; + //图像文件夹路径 + string ImgDir = AppDomain.CurrentDomain.BaseDirectory + "Camera\\"; + //用于数据采集和SQL操作 + Thread thread; + SynchronizationContext _main; + public Security() + { + InitializeComponent(); + } + void ipCameraHelper_ImageRead(ImageReadEvenArgs e) + { + img = e.img; + pic_video.Image = e.img; + } + void tick() + { + try + { + while (true) + { + try + { + //采集入侵状态 + IsInfrared = DeviceCtrlHelper.adam4150Helper.SetData().infraredValue; + //UI显示入侵状态 + _main.Send(_ => + { + lb_infrared.Text = IsInfrared ? "发现入侵" : "正常"; + }, null); + + if (IsInfrared) + { + if (img != null) + //上传报警信息 + SQLBLL.SecurityUpData(img); + } + } + catch + { + } + + Thread.Sleep(1000); + } + } + catch + { + } + } + private void pictureBox2_Click(object sender, EventArgs e) + { + + } + + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void panel_bg_video_Paint(object sender, PaintEventArgs e) + { + + } + + private void Security_Load(object sender, EventArgs e) + { + try + { + + + //实例化摄像头控制类 + DeviceCtrlHelper.ipCameraHelper.Open(AppSet.Camera_Ip, AppSet.Camera_Uid, AppSet.Camera_Pwd); + DeviceCtrlHelper.ipCameraHelper.ImageRead += ipCameraHelper_ImageRead; + DeviceCtrlHelper.ipCameraHelper.Start(); + + thread = new Thread(new ThreadStart(tick)); + _main = WindowsFormsSynchronizationContext.Current; + thread.Start(); + + if (!Directory.Exists(ImgDir)) + //创建文件夹 + Directory.CreateDirectory(ImgDir); + } + catch + { + } + } + + private void Security_FormClosed(object sender, FormClosedEventArgs e) + { + try + { + DeviceCtrlHelper.ipCameraHelper.Stop(); + DeviceCtrlHelper.ipCameraHelper.Close(); + thread.Suspend(); + thread = null; + + } + catch + { + } + + } + + private void btn_camera_Click(object sender, EventArgs e) + { + try + { + pic_video.Image.Save(ImgDir + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".jpg"); + SQLBLL.SecurityUpData(pic_video.Image); + } + catch + { + } + + } + + private void btn_history_Click(object sender, EventArgs e) + { + try + { + new SecurityCameraData().ShowDialog(); + } + catch + { + } + + } + + private void pic_up_MouseDown(object sender, MouseEventArgs e) + { + try + { + pic_up.BackgroundImage = Properties.Resources.btn_arrow_up_press; + DeviceCtrlHelper.ipCameraHelper.PanUp(); + } + catch + { + } + } + + private void pic_up_MouseUp(object sender, MouseEventArgs e) + { + try + { + pic_up.BackgroundImage = Properties.Resources.btn_arrow_up_normal; + DeviceCtrlHelper.ipCameraHelper.PanUp(); + } + catch + { + } + } + + private void pic_down_MouseDown(object sender, MouseEventArgs e) + { + try + { + pic_down.BackgroundImage = Properties.Resources.btn_arrow_down_press; + DeviceCtrlHelper.ipCameraHelper.PanDown(); + } + catch + { + } + } + + private void pic_down_MouseUp(object sender, MouseEventArgs e) + { + try + { + pic_down.BackgroundImage = Properties.Resources.btn_arrow_down_normal; + DeviceCtrlHelper.ipCameraHelper.PanDown(); + } + catch + { + } + } + + private void pic_left_MouseDown(object sender, MouseEventArgs e) + { + try + { + pic_left.BackgroundImage = Properties.Resources.btn_arrow_left_press; + DeviceCtrlHelper.ipCameraHelper.PanLeft(); + } + catch + { + } + } + + private void pic_left_MouseUp(object sender, MouseEventArgs e) + { + try + { + pic_left.BackgroundImage = Properties.Resources.btn_arrow_left_normal; + DeviceCtrlHelper.ipCameraHelper.PanLeft(); + } + catch + { + } + } + + private void pic_right_MouseDown(object sender, MouseEventArgs e) + { + try + { + pic_right.BackgroundImage = Properties.Resources.btn_arrow_right_press; + DeviceCtrlHelper.ipCameraHelper.PanRight(); + } + catch + { + } + } + + private void pic_right_MouseUp(object sender, MouseEventArgs e) + { + try + { + pic_right.BackgroundImage = Properties.Resources.btn_arrow_right_normal; + DeviceCtrlHelper.ipCameraHelper.PanRight(); + } + catch + { + } + } + + private void lb_return_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/samples/p8-t5-历史图片/SecurityCameraData.Designer.cs b/samples/p8-t5-历史图片/SecurityCameraData.Designer.cs new file mode 100644 index 0000000..dda0f9c --- /dev/null +++ b/samples/p8-t5-历史图片/SecurityCameraData.Designer.cs @@ -0,0 +1,246 @@ +namespace 智慧校园 +{ + partial class SecurityCameraData + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.pic_close = new System.Windows.Forms.PictureBox(); + this.label1 = new System.Windows.Forms.Label(); + this.panel_toolBar = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker(); + this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker(); + this.btn_get = new System.Windows.Forms.Button(); + this.lb_noData = new System.Windows.Forms.Label(); + this.lb_time = new System.Windows.Forms.Label(); + this.pic_down = new System.Windows.Forms.PictureBox(); + this.pic_up = new System.Windows.Forms.PictureBox(); + this.pic_camera = new System.Windows.Forms.PictureBox(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_close)).BeginInit(); + this.panel_toolBar.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_down)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_up)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_camera)).BeginInit(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(116)))), ((int)(((byte)(133))))); + this.panel1.Controls.Add(this.pic_close); + this.panel1.Controls.Add(this.label1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(835, 53); + this.panel1.TabIndex = 0; + // + // pic_close + // + this.pic_close.BackgroundImage = global::智慧校园.Properties.Resources.windowstate_closed_hover; + this.pic_close.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + this.pic_close.Location = new System.Drawing.Point(789, 6); + this.pic_close.Name = "pic_close"; + this.pic_close.Size = new System.Drawing.Size(36, 42); + this.pic_close.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pic_close.TabIndex = 1; + this.pic_close.TabStop = false; + this.pic_close.Click += new System.EventHandler(this.pictureBox1_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label1.ForeColor = System.Drawing.Color.White; + this.label1.Location = new System.Drawing.Point(12, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(129, 20); + this.label1.TabIndex = 0; + this.label1.Text = "历史报警记录"; + // + // panel_toolBar + // + this.panel_toolBar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(229)))), ((int)(((byte)(229))))); + this.panel_toolBar.Controls.Add(this.label2); + this.panel_toolBar.Controls.Add(this.label3); + this.panel_toolBar.Controls.Add(this.dateTimePicker2); + this.panel_toolBar.Controls.Add(this.dateTimePicker1); + this.panel_toolBar.Controls.Add(this.btn_get); + this.panel_toolBar.Location = new System.Drawing.Point(0, 53); + this.panel_toolBar.Name = "panel_toolBar"; + this.panel_toolBar.Size = new System.Drawing.Size(835, 56); + this.panel_toolBar.TabIndex = 1; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(364, 24); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(53, 12); + this.label2.TabIndex = 19; + this.label2.Text = "结束时间"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(88, 24); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(53, 12); + this.label3.TabIndex = 18; + this.label3.Text = "开始时间"; + // + // dateTimePicker2 + // + this.dateTimePicker2.Location = new System.Drawing.Point(423, 18); + this.dateTimePicker2.Name = "dateTimePicker2"; + this.dateTimePicker2.Size = new System.Drawing.Size(200, 21); + this.dateTimePicker2.TabIndex = 17; + // + // dateTimePicker1 + // + this.dateTimePicker1.Location = new System.Drawing.Point(147, 18); + this.dateTimePicker1.Name = "dateTimePicker1"; + this.dateTimePicker1.Size = new System.Drawing.Size(200, 21); + this.dateTimePicker1.TabIndex = 16; + // + // btn_get + // + this.btn_get.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(203)))), ((int)(((byte)(81))))); + this.btn_get.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btn_get.Location = new System.Drawing.Point(660, 12); + this.btn_get.Name = "btn_get"; + this.btn_get.Size = new System.Drawing.Size(75, 32); + this.btn_get.TabIndex = 15; + this.btn_get.Text = "查询"; + this.btn_get.UseVisualStyleBackColor = false; + this.btn_get.Click += new System.EventHandler(this.btn_get_Click); + // + // lb_noData + // + this.lb_noData.AutoSize = true; + this.lb_noData.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.lb_noData.Font = new System.Drawing.Font("宋体", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.lb_noData.ForeColor = System.Drawing.Color.Red; + this.lb_noData.Location = new System.Drawing.Point(259, 320); + this.lb_noData.Name = "lb_noData"; + this.lb_noData.Size = new System.Drawing.Size(252, 64); + this.lb_noData.TabIndex = 3; + this.lb_noData.Text = "NO DATA"; + // + // lb_time + // + this.lb_time.AutoSize = true; + this.lb_time.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.lb_time.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.lb_time.ForeColor = System.Drawing.Color.Red; + this.lb_time.Location = new System.Drawing.Point(527, 539); + this.lb_time.Name = "lb_time"; + this.lb_time.Size = new System.Drawing.Size(40, 16); + this.lb_time.TabIndex = 4; + this.lb_time.Text = "TIME"; + // + // pic_down + // + this.pic_down.Image = global::智慧校园.Properties.Resources.arrow_right_normal; + this.pic_down.Location = new System.Drawing.Point(668, 138); + this.pic_down.Name = "pic_down"; + this.pic_down.Size = new System.Drawing.Size(67, 479); + this.pic_down.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.pic_down.TabIndex = 6; + this.pic_down.TabStop = false; + this.pic_down.Click += new System.EventHandler(this.pic_down_Click); + // + // pic_up + // + this.pic_up.Image = global::智慧校园.Properties.Resources.arrow_left_normal; + this.pic_up.Location = new System.Drawing.Point(49, 138); + this.pic_up.Name = "pic_up"; + this.pic_up.Size = new System.Drawing.Size(67, 479); + this.pic_up.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.pic_up.TabIndex = 5; + this.pic_up.TabStop = false; + this.pic_up.Click += new System.EventHandler(this.pic_up_Click); + // + // pic_camera + // + this.pic_camera.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.pic_camera.Location = new System.Drawing.Point(49, 138); + this.pic_camera.Name = "pic_camera"; + this.pic_camera.Size = new System.Drawing.Size(686, 479); + this.pic_camera.TabIndex = 2; + this.pic_camera.TabStop = false; + // + // SecurityCameraData + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(835, 629); + this.Controls.Add(this.pic_down); + this.Controls.Add(this.pic_up); + this.Controls.Add(this.lb_time); + this.Controls.Add(this.lb_noData); + this.Controls.Add(this.pic_camera); + this.Controls.Add(this.panel_toolBar); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "SecurityCameraData"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "SecurityCameraData"; + this.Load += new System.EventHandler(this.SecurityCameraData_Load); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_close)).EndInit(); + this.panel_toolBar.ResumeLayout(false); + this.panel_toolBar.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pic_down)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_up)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pic_camera)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pic_close; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Panel panel_toolBar; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.DateTimePicker dateTimePicker2; + private System.Windows.Forms.DateTimePicker dateTimePicker1; + private System.Windows.Forms.Button btn_get; + private System.Windows.Forms.PictureBox pic_camera; + private System.Windows.Forms.Label lb_noData; + private System.Windows.Forms.Label lb_time; + private System.Windows.Forms.PictureBox pic_up; + private System.Windows.Forms.PictureBox pic_down; + } +} \ No newline at end of file diff --git a/samples/p8-t5-历史图片/SecurityCameraData.cs b/samples/p8-t5-历史图片/SecurityCameraData.cs new file mode 100644 index 0000000..c374125 --- /dev/null +++ b/samples/p8-t5-历史图片/SecurityCameraData.cs @@ -0,0 +1,129 @@ +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 DeviceCtrlLibrary; +using 智慧校园.SQLHelpers; + +namespace 智慧校园 +{ + public partial class SecurityCameraData : Form + { + public SecurityCameraData() + { + InitializeComponent(); + } + //存放报警信息的集合 + Dictionary ImgDictionary = new Dictionary(); + //图片下标 + int index = -1; + Image img; + //KEY的列表(报警时间为KEY) + List Keys = new List(); + + private void SecurityCameraData_Load(object sender, EventArgs e) + { + try + { + //设置父容器 + pic_up.Parent = pic_camera; + pic_down.Parent = pic_camera; + //设置加载坐标 + pic_up.Location = new Point(20, 0); + pic_down.Location = new Point(560, 0); + GetData(); + } + catch + { + } + } + //更新数据 + private void GetData() + { + try + { + DateTime startdt = dateTimePicker1.Value; + DateTime enddt = dateTimePicker2.Value; + ImgDictionary = SQLBLL.GetSecurityData(startdt, enddt); + index = -1; + Keys.Clear(); + + if (ImgDictionary.Count != 0) + lb_noData.Visible = false; + else + { + lb_noData.Visible = true; + return; + } + foreach (string key in ImgDictionary.Keys) + { + Keys.Add(key); + } + + ImageChanged(); + } + catch + { + } + } + //切换图片 + private void ImageChanged(char UpOrDown = '+') + { + try + { + if (ImgDictionary.Count == 0) + return; + + if (UpOrDown == '+') + index++; + else if (UpOrDown == '-') + index--; + + if (index == ImgDictionary.Count) + index = 0; + + if (index == -1) + index = ImgDictionary.Count - 1; + + ImgDictionary.TryGetValue(Keys[index], out img); + pic_camera.Image = img; + lb_time.Text = Keys[index]; + } + catch + { + } + + } + + private void btn_get_Click(object sender, EventArgs e) + { + try + { + GetData(); + } + catch + { + } + } + + private void pictureBox1_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void pic_up_Click(object sender, EventArgs e) + { + ImageChanged('-'); + } + + private void pic_down_Click(object sender, EventArgs e) + { + ImageChanged(); + } + } +} diff --git a/samples/p8-t5-历史图片/checks.yaml b/samples/p8-t5-历史图片/checks.yaml new file mode 100644 index 0000000..1821c5a --- /dev/null +++ b/samples/p8-t5-历史图片/checks.yaml @@ -0,0 +1,55 @@ +# 评分规则:书上评价表的功能项。每项单独启动一次程序,按步骤操作,核对结果。 +# 格式说明见 server/src/grading/checks.ts +# 先拨虚拟时钟再拍照,照片的时间就是确定的(9:00:00、10:30:00 左右)。 +- title: 能查看拍下的历史照片 + steps: + - clock: '09:00:00' + - click: pic_security + - expect: { control: pic_video, image: true, within: 3s } + - click: btn_camera + - click: btn_history + - expect: { window: SecurityCameraData, desc: 点"查看历史图像"打开历史报警记录窗体 } + - expect: { control: pic_camera, image: true, desc: 显示今天拍的照片 } + - expect: { control: lb_noData, visible: false, desc: 有照片时不显示"NO DATA" } + - expect: { control: lb_time, contains: ' 9:00:0', desc: 显示照片的拍摄时间 } + +- title: 照片能根据图片按钮切换 + steps: + - clock: '09:00:00' + - click: pic_security + - expect: { control: pic_video, image: true, within: 3s } + - click: btn_camera + - clock: '10:30:00' + - click: btn_camera + - click: btn_history + - expect: { control: lb_time, contains: ' 9:00:0', desc: 先显示第一张照片 } + - click: pic_down + - expect: { control: lb_time, contains: '10:30:0', desc: 点右箭头显示下一张 } + - click: pic_down + - expect: { control: lb_time, contains: ' 9:00:0', desc: 最后一张再往后回到第一张 } + - click: pic_up + - expect: { control: lb_time, contains: '10:30:0', desc: 点左箭头显示上一张 } + +- title: 能正确查找时间段内的历史图片 + steps: + - clock: '09:00:00' + - click: pic_security + - expect: { control: pic_video, image: true, within: 3s } + - click: btn_camera + - click: btn_history + - pick: { control: dateTimePicker1, value: '2024-01-01' } + - click: btn_get + - expect: { control: lb_noData, visible: false, desc: 2024-01-01 到今天之间有照片 } + - expect: { control: lb_time, contains: ' 9:00:0' } + - pick: { control: dateTimePicker2, value: '2024-01-31' } + - click: btn_get + - expect: { control: lb_noData, visible: true, desc: 2024 年 1 月没有照片,显示"NO DATA" } + +- title: 能关闭历史报警记录窗体 + steps: + - click: pic_security + - click: btn_history + - expect: { window: SecurityCameraData } + - click: pic_close + - expect: { window: SecurityCameraData, open: false } + - expect: { window: Security, desc: 回到校园安防窗体 } diff --git a/samples/p8-t5-历史图片/database.sql b/samples/p8-t5-历史图片/database.sql new file mode 100644 index 0000000..2e5eeba --- /dev/null +++ b/samples/p8-t5-历史图片/database.sql @@ -0,0 +1,54 @@ +-- 实验的初始数据库 WisdomCampus(教材"综合实训"附带的库):环境数据表 EnvironmentData、报警图片表 SecurityData、用户表 Users。 +-- EnvironmentData 预置了 7 天的历史数据,"数据分析"的图表一打开就有内容;SecurityData 是空的,拍照或有人入侵时才有记录。 +-- 学生可以在数据库页面"恢复实验初始数据";评分时每个检查项用一份新的。 +CREATE DATABASE WisdomCampus +GO +USE WisdomCampus +GO +CREATE TABLE Users (Id int IDENTITY(1,1) PRIMARY KEY, UserName nvarchar(50) NOT NULL, Password nvarchar(50) NOT NULL) +CREATE TABLE EnvironmentData (Id int IDENTITY(1,1) PRIMARY KEY, Fire bit NOT NULL, Smoke bit NOT NULL, Temperature float NULL, Humidity float NULL, Light float NULL, _Time datetime NOT NULL) +CREATE TABLE SecurityData (Id int IDENTITY(1,1) PRIMARY KEY, EvenTime datetime NOT NULL, EvenImage image NOT NULL) +GO +INSERT INTO Users (UserName, Password) VALUES ('admin', '123') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.9, 58, 258, '2026-10-14 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.1, 53, 475, '2026-10-14 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.8, 51, 761, '2026-10-14 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 22.5, 49, 733, '2026-10-14 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 54, 528, '2026-10-14 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.1, 57, 283, '2026-10-14 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.9, 59, 261, '2026-10-15 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.6, 53, 499, '2026-10-15 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.8, 52, 764, '2026-10-15 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 23.5, 47, 778, '2026-10-15 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.8, 52, 503, '2026-10-15 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.6, 56, 218, '2026-10-15 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 13.9, 63, 258, '2026-10-16 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.6, 60, 477, '2026-10-16 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.8, 51, 741, '2026-10-16 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 20.5, 54, 796, '2026-10-16 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 55, 488, '2026-10-16 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.6, 59, 214, '2026-10-16 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 11.9, 67, 234, '2026-10-17 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.1, 63, 544, '2026-10-17 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.3, 60, 804, '2026-10-17 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.5, 54, 801, '2026-10-17 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.8, 59, 524, '2026-10-17 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.1, 58, 286, '2026-10-17 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 16.4, 59, 250, '2026-10-18 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.6, 55, 533, '2026-10-18 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.3, 50, 749, '2026-10-18 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 24, 48, 766, '2026-10-18 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 20.8, 54, 534, '2026-10-18 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.1, 53, 241, '2026-10-18 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.4, 54, 253, '2026-10-19 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.1, 50, 474, '2026-10-19 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 22.3, 48, 778, '2026-10-19 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 26, 46, 783, '2026-10-19 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 23.3, 50, 520, '2026-10-19 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 20.6, 50, 213, '2026-10-19 18:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 15.9, 62, 230, '2026-10-20 08:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 18.6, 52, 471, '2026-10-20 10:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 53, 751, '2026-10-20 12:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 21.5, 48, 747, '2026-10-20 14:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 19.3, 55, 527, '2026-10-20 16:00:00') +INSERT INTO EnvironmentData (Fire, Smoke, Temperature, Humidity, Light, _Time) VALUES (0, 0, 17.1, 57, 220, '2026-10-20 18:00:00') diff --git a/samples/p8-t5-历史图片/meta.json b/samples/p8-t5-历史图片/meta.json new file mode 100644 index 0000000..5f121a2 --- /dev/null +++ b/samples/p8-t5-历史图片/meta.json @@ -0,0 +1,4 @@ +{ + "title": "项目8 任务5 实现\"校园安防\"模块中显示历史图片的功能", + "source": "教材书 p181–185,界面和代码取自配套参考工程;图片是平台素材库里自绘的同名素材(尺寸和教材一致);每次查询前清空 Keys(书上没清空,重复查询时照片和时间对不上)" +} diff --git a/server/test/grading.test.ts b/server/test/grading.test.ts index d91a3a6..61bad62 100644 --- a/server/test/grading.test.ts +++ b/server/test/grading.test.ts @@ -35,7 +35,7 @@ async function prepare(id: string, name: string, edit?: { file: string; from: st describe('参考答案全部通过', async () => { const ids = (await Array.fromAsync(new Bun.Glob('*/checks.yaml').scan({ cwd: SAMPLES }))).map((p) => p.split('/')[0]).sort() - test('每个示例都有评分规则', () => expect(ids.length).toBe(18)) + test('每个示例都有评分规则', () => expect(ids.length).toBe(23)) for (const id of ids) { test(id, async () => { const result = await grade(await prepare(id, id), await checksOf(id), id) @@ -89,7 +89,7 @@ describe('改坏的代码', () => { const dir = await prepare(id, 'camera', { file: 'Form1.cs', from: 'DeviceCtrlHelper.ipCameraHelper.ImageRead += ipCameraHelper_ImageRead;', to: '' }) const result = await grade(dir, await checksOf(id), id) expect(result.results.map((r) => r.passed)).toEqual([true, false, true, false]) - expect(result.results[1].message).toBe('期望3 秒内 pictureBox1 显示摄像机拍到的图像,实际是空的') + expect(result.results[1].message).toBe('期望3 秒内 pictureBox1 显示摄像机拍到的图像,实际没有图片') }, 60000) test('数据库:照书上 INSERT 不写列名,温度和光照存反了', async () => { @@ -142,6 +142,27 @@ describe('改坏的代码', () => { expect(result.results[2]).toMatchObject({ passed: false, message: '期望 lstbRecored 列表里有"发现火情"的记录,实际列表是空的' }) }, 60000) + test('管理平台:照参考工程没给"自动推送火情"复选框绑定 CheckedChanged,有火情时 LED 屏不推送', async () => { + const id = 'p8-t3-环境采集与分析' + const dir = await prepare(id, 'auto-fire', { + file: 'Environment.Designer.cs', + from: ' this.ch_autoLedFire.CheckedChanged += new System.EventHandler(this.ch_autoLedFire_CheckedChanged);\n', + to: '', + }) + const result = await grade(dir, await checksOf(id), id) + const fire = result.results.find((r) => r.title === '能自动推送火情到 LED 屏')! + expect(fire).toMatchObject({ passed: false, message: '期望8 秒内实训台 LED 屏显示"发现火情"(勾选"自动推送火情"后有火焰),实际什么也没显示' }) + expect(result.results.filter((r) => !r.passed)).toHaveLength(1) + }, 60000) + + test('管理平台:开灯时换错了背景图片', async () => { + const id = 'p8-t3-环境采集与分析' + const dir = await prepare(id, 'lamp-image', { file: 'Environment.cs', from: 'panel_bg.BackgroundImage = Properties.Resources.day_01;', to: 'panel_bg.BackgroundImage = Properties.Resources.day_02;' }) + const result = await grade(dir, await checksOf(id), id) + const lamp = result.results.find((r) => r.title === '路灯能手动控制')! + expect(lamp).toMatchObject({ passed: false, message: '期望 panel_bg 背景换成亮灯的场景(day_01),实际是别的图片' }) + }, 60000) + test('报警灯接错了 DO 口', async () => { const id = 'p4-t3-报警灯' const dir = await prepare(id, 'relay', { file: 'Form1.cs', from: 'DeviceCtrlHelper.adam4150Helper.OnOff(0, IsOpen);', to: 'DeviceCtrlHelper.adam4150Helper.OnOff(1, IsOpen);' })