SVN-Revision: r828
This commit is contained in:
wyf
2025-07-02 05:41:40 +00:00
parent 0dff9915bf
commit 14adbc8e1a
19 changed files with 2008 additions and 0 deletions
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Root Type="DevExpress.CodeRush.Foundation.CodePlaces.Options.FavoritesListContainer">
<Options Language="Neutral">
<Groups />
</Options>
</Root>
+25
View File
@@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31410.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LadfDataApp", "LadfDataApp\LadfDataApp.csproj", "{AA75C812-16A4-498C-BF4D-F1C2CB8E0015}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AA75C812-16A4-498C-BF4D-F1C2CB8E0015}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA75C812-16A4-498C-BF4D-F1C2CB8E0015}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA75C812-16A4-498C-BF4D-F1C2CB8E0015}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA75C812-16A4-498C-BF4D-F1C2CB8E0015}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CD3FE4D7-213D-4D71-A405-8B7222DBA8C2}
EndGlobalSection
EndGlobal
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="loginName" value="lserptest"/>
<add key="server" value="120.199.12.54,14331"/>
<add key="database" value="LADFERP"/>
<add key="intervalTime" value="60"/>
</appSettings>
</configuration>
+234
View File
@@ -0,0 +1,234 @@
namespace LadfDataApp
{
partial class FrmMain
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.loginInfoPanel = new System.Windows.Forms.Panel();
this.timeUnitLab = new System.Windows.Forms.Label();
this.timeIntervalLab = new System.Windows.Forms.Label();
this.timeIntervalBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.projectComboBox = new System.Windows.Forms.ComboBox();
this.dataBaseLab = new System.Windows.Forms.Label();
this.dataBaseBox = new System.Windows.Forms.TextBox();
this.serverLab = new System.Windows.Forms.Label();
this.serverBox = new System.Windows.Forms.TextBox();
this.startBtn = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.loginPasswordBox = new System.Windows.Forms.TextBox();
this.loginNameLab = new System.Windows.Forms.Label();
this.loginNameBox = new System.Windows.Forms.TextBox();
this.panel2 = new System.Windows.Forms.Panel();
this.tipsTextBox = new System.Windows.Forms.TextBox();
this.loginInfoPanel.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// loginInfoPanel
//
this.loginInfoPanel.BackColor = System.Drawing.SystemColors.Control;
this.loginInfoPanel.Controls.Add(this.timeUnitLab);
this.loginInfoPanel.Controls.Add(this.timeIntervalLab);
this.loginInfoPanel.Controls.Add(this.timeIntervalBox);
this.loginInfoPanel.Controls.Add(this.label2);
this.loginInfoPanel.Controls.Add(this.projectComboBox);
this.loginInfoPanel.Controls.Add(this.dataBaseLab);
this.loginInfoPanel.Controls.Add(this.dataBaseBox);
this.loginInfoPanel.Controls.Add(this.serverLab);
this.loginInfoPanel.Controls.Add(this.serverBox);
this.loginInfoPanel.Controls.Add(this.startBtn);
this.loginInfoPanel.Controls.Add(this.label1);
this.loginInfoPanel.Controls.Add(this.loginPasswordBox);
this.loginInfoPanel.Controls.Add(this.loginNameLab);
this.loginInfoPanel.Controls.Add(this.loginNameBox);
this.loginInfoPanel.Dock = System.Windows.Forms.DockStyle.Top;
this.loginInfoPanel.Location = new System.Drawing.Point(0, 0);
this.loginInfoPanel.Name = "loginInfoPanel";
this.loginInfoPanel.Size = new System.Drawing.Size(603, 164);
this.loginInfoPanel.TabIndex = 0;
//
// timeUnitLab
//
this.timeUnitLab.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.timeUnitLab.Location = new System.Drawing.Point(243, 127);
this.timeUnitLab.Name = "timeUnitLab";
this.timeUnitLab.Size = new System.Drawing.Size(45, 25);
this.timeUnitLab.TabIndex = 13;
this.timeUnitLab.Text = "分钟";
this.timeUnitLab.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// timeIntervalLab
//
this.timeIntervalLab.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.timeIntervalLab.Location = new System.Drawing.Point(12, 127);
this.timeIntervalLab.Name = "timeIntervalLab";
this.timeIntervalLab.Size = new System.Drawing.Size(70, 25);
this.timeIntervalLab.TabIndex = 12;
this.timeIntervalLab.Text = "间 隔:";
this.timeIntervalLab.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// timeIntervalBox
//
this.timeIntervalBox.Location = new System.Drawing.Point(88, 127);
this.timeIntervalBox.Name = "timeIntervalBox";
this.timeIntervalBox.Size = new System.Drawing.Size(149, 21);
this.timeIntervalBox.TabIndex = 11;
//
// label2
//
this.label2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(12, 89);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(70, 25);
this.label2.TabIndex = 10;
this.label2.Text = "项 目:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// projectComboBox
//
this.projectComboBox.FormattingEnabled = true;
this.projectComboBox.Location = new System.Drawing.Point(88, 91);
this.projectComboBox.Name = "projectComboBox";
this.projectComboBox.Size = new System.Drawing.Size(200, 20);
this.projectComboBox.TabIndex = 9;
//
// dataBaseLab
//
this.dataBaseLab.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.dataBaseLab.Location = new System.Drawing.Point(308, 54);
this.dataBaseLab.Name = "dataBaseLab";
this.dataBaseLab.Size = new System.Drawing.Size(70, 25);
this.dataBaseLab.TabIndex = 8;
this.dataBaseLab.Text = "数据库:";
this.dataBaseLab.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// dataBaseBox
//
this.dataBaseBox.Location = new System.Drawing.Point(384, 54);
this.dataBaseBox.Name = "dataBaseBox";
this.dataBaseBox.Size = new System.Drawing.Size(200, 21);
this.dataBaseBox.TabIndex = 7;
//
// serverLab
//
this.serverLab.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.serverLab.Location = new System.Drawing.Point(12, 54);
this.serverLab.Name = "serverLab";
this.serverLab.Size = new System.Drawing.Size(70, 25);
this.serverLab.TabIndex = 6;
this.serverLab.Text = "服务器:";
this.serverLab.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// serverBox
//
this.serverBox.Location = new System.Drawing.Point(88, 54);
this.serverBox.Name = "serverBox";
this.serverBox.Size = new System.Drawing.Size(200, 21);
this.serverBox.TabIndex = 5;
//
// startBtn
//
this.startBtn.Location = new System.Drawing.Point(482, 127);
this.startBtn.Name = "startBtn";
this.startBtn.Size = new System.Drawing.Size(102, 31);
this.startBtn.TabIndex = 4;
this.startBtn.Text = "开始同步";
this.startBtn.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(308, 18);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(70, 25);
this.label1.TabIndex = 3;
this.label1.Text = "密 码:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// loginPasswordBox
//
this.loginPasswordBox.Location = new System.Drawing.Point(384, 18);
this.loginPasswordBox.Name = "loginPasswordBox";
this.loginPasswordBox.PasswordChar = '●';
this.loginPasswordBox.Size = new System.Drawing.Size(200, 21);
this.loginPasswordBox.TabIndex = 2;
//
// loginNameLab
//
this.loginNameLab.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.loginNameLab.Location = new System.Drawing.Point(12, 18);
this.loginNameLab.Name = "loginNameLab";
this.loginNameLab.Size = new System.Drawing.Size(70, 25);
this.loginNameLab.TabIndex = 1;
this.loginNameLab.Text = "用户名:";
this.loginNameLab.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// loginNameBox
//
this.loginNameBox.Location = new System.Drawing.Point(88, 18);
this.loginNameBox.Name = "loginNameBox";
this.loginNameBox.Size = new System.Drawing.Size(200, 21);
this.loginNameBox.TabIndex = 0;
//
// panel2
//
this.panel2.Controls.Add(this.tipsTextBox);
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(0, 164);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(603, 364);
this.panel2.TabIndex = 1;
//
// tipsTextBox
//
this.tipsTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.tipsTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.tipsTextBox.Location = new System.Drawing.Point(0, 0);
this.tipsTextBox.Multiline = true;
this.tipsTextBox.Name = "tipsTextBox";
this.tipsTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.tipsTextBox.Size = new System.Drawing.Size(603, 364);
this.tipsTextBox.TabIndex = 0;
//
// FrmMain
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(603, 528);
this.Controls.Add(this.panel2);
this.Controls.Add(this.loginInfoPanel);
this.Name = "FrmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "朗速科技物联网同步平台";
this.loginInfoPanel.ResumeLayout(false);
this.loginInfoPanel.PerformLayout();
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
this.ResumeLayout(false);
@@ -0,0 +1,652 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace LadfDataApp
{
public partial class FrmMain : Form
{
private string sid = string.Empty;//认证码
private System.Timers.Timer timer = new System.Timers.Timer();//指定间隔循环
private int timeInterval = 0;
public FrmMain()
{
InitializeComponent();
this.Load += OnFrmMainLoad;
this.startBtn.Click += OnStartBtnClick;
this.loginNameBox.TextChanged += OnTextChanged;
this.loginPasswordBox.TextChanged += OnTextChanged;
}
private void OnFrmMainLoad(object sender, EventArgs e)
{
this.loginNameBox.Text = ConfigurationManager.AppSettings["loginName"];
this.serverBox.Text = ConfigurationManager.AppSettings["server"];
this.dataBaseBox.Text = ConfigurationManager.AppSettings["database"];
this.timeIntervalBox.Text = ConfigurationManager.AppSettings["intervalTime"];
if (this.loginNameBox.Text.Equals("lserptest"))
{
this.loginPasswordBox.Text = "lserpAdmin";
}
}
private void OnTextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.loginNameBox.Text) && !string.IsNullOrEmpty(this.loginPasswordBox.Text))
{
if (Login())
{
InitComboBox();
UpdateMsg($"用户登录成功\r\n");
}
else
{
//UpdateMsg($"用户登录失败\r\n");
}
}
}
/// <summary>
/// 加载项目下拉框数据源
/// </summary>
private void InitComboBox()
{
try
{
this.projectComboBox.Items.Clear();
string url = "https://api.123321yun.com/api/user/queryProjectList";
HttpUtil.setting("application/x-www-form-urlencoded", null, null);
Dictionary<string, string> pmsDic = new Dictionary<string, string>();
pmsDic.Add("isAll", "true");
pmsDic.Add("pageNum", "1");
pmsDic.Add("pageSize", "10");
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("__sid", sid);
HttpWebResponse webResponse = HttpUtil.Post(url, "", pmsDic, headerDic, HttpUtil.Method.POST);
string result = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(result))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(result);
string code = resultJObject["code"] + "";
if (code.Equals("200"))
{
JArray projectArray = (JArray)resultJObject["data"];
foreach (JObject projectJObject in projectArray)
{
try
{
string projectName = projectJObject["name"] + "";
this.projectComboBox.Items.Add(projectName);
}
catch (Exception)
{
}
}
}
}
}
catch (Exception)
{
}
}
private void OnStartBtnClick(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.loginNameBox.Text) || string.IsNullOrEmpty(this.loginPasswordBox.Text))
{
MessageBox.Show("用户名或密码不能为空", "提示");
return;
}
if (string.IsNullOrEmpty(this.serverBox.Text) || string.IsNullOrEmpty(this.dataBaseBox.Text))
{
MessageBox.Show("服务器或数据库不能为空", "提示");
return;
}
if (string.IsNullOrEmpty(this.projectComboBox.SelectedItem + ""))
{
MessageBox.Show("未选择项目", "提示");
return;
}
if (!int.TryParse(this.timeIntervalBox.Text, out timeInterval) && timeInterval <= 0)
{
MessageBox.Show("间隔时间必须大于0", "提示");
return;
}
timer.Elapsed += OnTimerElapsed;
timer.Interval = 100;
timer.Start();
}
/// <summary>
/// 获取数据事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
this.Invoke(new Action(() =>
{
this.startBtn.Enabled = false;
this.loginNameBox.Enabled = false;
this.loginPasswordBox.Enabled = false;
this.serverBox.Enabled = false;
this.dataBaseBox.Enabled = false;
this.timeIntervalBox.Enabled = false;
this.projectComboBox.Enabled = false;
}));
if (timer.Interval == 100)
{
timer.Interval = timeInterval * 60 * 1000;
}
ClearMsg();
QueryProjectList();
UpdateMsg("同步完成,所有数据已成功写入\r\n");
string nextTime = DateTime.Now.AddMinutes(timeInterval).ToString("yyyy-MM-dd HH:mm:ss");
UpdateMsg($"下次同步时间:{nextTime}\r\n");
}
catch (Exception)
{
}
finally
{
this.Invoke(new Action(() =>
{
this.loginNameBox.Enabled = true;
this.loginPasswordBox.Enabled = true;
this.startBtn.Enabled = true;
this.serverBox.Enabled = true;
this.dataBaseBox.Enabled = true;
this.timeIntervalBox.Enabled = true;
this.projectComboBox.Enabled = true;
}));
}
}
/// <summary>
/// 登录
/// </summary>
/// <returns></returns>
private bool Login()
{
bool isLogin = false;
try
{
string url = "https://api.123321yun.com/api/user/login";
HttpUtil.setting("application/x-www-form-urlencoded", null, null);
Dictionary<string, string> pmsDic = new Dictionary<string, string>();
pmsDic.Add("username", this.loginNameBox.Text);
pmsDic.Add("password", this.loginPasswordBox.Text);
HttpWebResponse webResponse = HttpUtil.Post(url, "", pmsDic, null, HttpUtil.Method.POST);
string result = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(result))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(result);
string code = resultJObject["code"] + "";
if (code.Equals("200"))
{
sid = resultJObject["data"] + "";
isLogin = true;
}
}
}
catch (Exception)
{
}
return isLogin;
}
/// <summary>
/// 查询项目列表
/// </summary>
private void QueryProjectList()
{
try
{
string url = "https://api.123321yun.com/api/user/queryProjectList";
HttpUtil.setting("application/x-www-form-urlencoded", null, null);
Dictionary<string, string> pmsDic = new Dictionary<string, string>();
pmsDic.Add("isAll", "true");
pmsDic.Add("pageNum", "1");
pmsDic.Add("pageSize", "10");
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("__sid", sid);
HttpWebResponse webResponse = HttpUtil.Post(url, "", pmsDic, headerDic, HttpUtil.Method.POST);
string result = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(result))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(result);
string code = resultJObject["code"] + "";
if (code.Equals("200"))
{
string selectProjectName = "";
this.Invoke(new Action(() =>
{
selectProjectName = projectComboBox.SelectedItem + "";
}));
JArray projectArray = (JArray)resultJObject["data"];
bool isConnection = CreateConnection();
if (isConnection)
{
foreach (JObject projectJObject in projectArray)
{
try
{
if (projectJObject.ContainsKey("name") && (projectJObject["name"] + "").Equals(selectProjectName))
{
try
{
UpdateMsg($"正在读取项目:{projectJObject["name"]}\r\n");
ProjectModel projectModel = new ProjectModel();
projectModel.projectId = projectJObject["id"] + "";
projectModel.name = projectJObject["name"] + "";
projectModel.delFlag = projectJObject["delFlag"] + "";
projectModel.province = projectJObject["province"] + "";
projectModel.city = projectJObject["city"] + "";
projectModel.county = projectJObject["county"] + "";
projectModel.address = projectJObject["address"] + "";
projectModel.propertyOwner = projectJObject["propertyOwner"] + "";
projectModel.constructionTime = projectJObject["constructionTime"] + "";
projectModel.acreage = projectJObject["acreage"] + "";
projectModel.typeId = projectJObject["typeId"] + "";
projectModel.state = projectJObject["state"] + "";
projectModel.enableTime = projectJObject["enableTime"] + "";
projectModel.energyConsumption = projectJObject["energyConsumption"] + "";
projectModel.imgUrl = projectJObject["imgUrl"] + "";
projectModel.remarks = projectJObject["remarks"] + "";
projectModel.contractor = projectJObject["contractor"] + "";
projectModel.propertyMgmt = projectJObject["propertyMgmt"] + "";
projectModel.projectTypeId = projectJObject["projectType"]["id"] + "";
projectModel.projectTypeName = projectJObject["projectType"]["name"] + "";
StringBuilder projectSqlStrBuilder = new StringBuilder();
StringBuilder projectInsertKeys = new StringBuilder();
StringBuilder projectInsertValues = new StringBuilder();
PropertyInfo[] devicePmsPropertyInfos = projectModel.GetType().GetProperties();
foreach (System.Reflection.PropertyInfo projectPropertyInfo in devicePmsPropertyInfos)
{
projectInsertKeys.Append($"{projectPropertyInfo.Name},");
projectInsertValues.Append($"'{(projectPropertyInfo.GetValue(projectModel, null) + "").Replace("'", "''")}',");
}
projectSqlStrBuilder.Append($"delete from LadfProjectTab where projectid = '{projectModel.projectId}';\r\n" +
$"insert into LadfProjectTab ({projectInsertKeys.ToString().TrimEnd(',')}) values ({projectInsertValues.ToString().TrimEnd(',')});\r\n");
if (!string.IsNullOrEmpty(projectSqlStrBuilder.ToString()))
{
SqlHelper.ExecuteNonQuery(projectSqlStrBuilder.ToString());
}
QueryDeviceByProject(projectModel);
UpdateMsg($"项目:{projectJObject["name"]}数据写入完成\r\n");
}
catch (Exception ex)
{
UpdateMsg($"项目:{projectJObject["name"]}数据写入失败,原因:{ex.Message}\r\n");
}
}
}
catch (Exception)
{
}
}
}
else
{
UpdateMsg($"读取项目失败,服务器连接失败\r\n");
}
}
else if (code.Equals("4012"))
{
UpdateMsg($"登录失败\r\n");
Login();
QueryProjectList();
}
}
}
catch (Exception)
{
}
}
/// <summary>
/// 查询项目的设备列表
/// </summary>
private void QueryDeviceByProject(ProjectModel projectModel)
{
StringBuilder projectSqlStrBuilder = new StringBuilder();
UpdateMsg($"正在读取项目:{projectModel.name}的设备\r\n");
try
{
string url = "https://api.123321yun.com/api/device/queryDeviceByProject";
HttpUtil.setting("application/x-www-form-urlencoded", null, null);
Dictionary<string, string> pmsDic = new Dictionary<string, string>();
pmsDic.Add("projId", projectModel.projectId);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("__sid", sid);
HttpWebResponse webResponse = HttpUtil.Post(url, "", pmsDic, headerDic, HttpUtil.Method.POST);
string result = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(result))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(result);
string code = resultJObject["code"] + "";
if (code.Equals("200"))
{
JArray deviceArray = (JArray)resultJObject["data"];
foreach (JObject deviceJObject in deviceArray)
{
try
{
UpdateMsg($"正在读取设备:{deviceJObject["name"]}\r\n");
DeviceModel deviceModel = new DeviceModel();
deviceModel.deviceId = deviceJObject["id"] + "";
deviceModel.brand = deviceJObject["brand"] + "";
deviceModel.model = deviceJObject["model"] + "";
deviceModel.typeId = deviceJObject["typeId"] + "";
deviceModel.projectId = deviceJObject["projectId"] + "";
deviceModel.power = deviceJObject["power"] + "";
deviceModel.regionId = deviceJObject["regionId"] + "";
deviceModel.produceTime = deviceJObject["produceTime"] + "";
deviceModel.deviceTypeId = deviceJObject["deviceType"]["id"] + "";
deviceModel.deviceTypeName = deviceJObject["deviceType"]["name"] + "";
deviceModel.name = deviceJObject["name"] + "";
StringBuilder deviceInsertKeys = new StringBuilder();
StringBuilder deviceInsertValues = new StringBuilder();
PropertyInfo[] devicePropertyInfos = deviceModel.GetType().GetProperties();
foreach (System.Reflection.PropertyInfo devicePropertyInfo in devicePropertyInfos)
{
deviceInsertKeys.Append($"{devicePropertyInfo.Name},");
deviceInsertValues.Append($"'{(devicePropertyInfo.GetValue(deviceModel, null) + "").Replace("'", "''")}',");
}
projectSqlStrBuilder.Append($"delete from LadfDeviceTab where projectid = '{deviceModel.projectId}' and deviceId = '{deviceModel.deviceId}';\r\n" +
$"delete from LadfDeviceParamTab where projectid = '{deviceModel.projectId}' and deviceId = '{deviceModel.deviceId}';\r\n" +
$"delete from LadfDeviceParamStatusTab where projectid = '{deviceModel.projectId}' and deviceId = '{deviceModel.deviceId}';\r\n" +
$"delete from LadfDeviceParamStatusHistoryTab where projectid = '{deviceModel.projectId}' and deviceId = '{deviceModel.deviceId}' and datetime >= {GetNowTime0Stamp()} and datetime <= {GetNowTime24Stamp()};\r\n");
projectSqlStrBuilder.Append($"insert into LadfDeviceTab ({deviceInsertKeys.ToString().TrimEnd(',')}) values ({deviceInsertValues.ToString().TrimEnd(',')});\r\n");
if (!string.IsNullOrEmpty(projectSqlStrBuilder.ToString()))
{
SqlHelper.ExecuteNonQuery(projectSqlStrBuilder.ToString());
}
QueryDeviceParamStatus(deviceModel);
QueryDeviceParamStatusHistory(deviceModel);
}
catch (Exception ex)
{
UpdateMsg($"读取设备{deviceJObject["name"]}失败,原因:{ex.Message}\r\n");
}
}
}
else if (code.Equals("4012"))
{
UpdateMsg($"登录失败\r\n");
Login();
QueryDeviceByProject(projectModel);
}
}
}
catch (Exception ex)
{
if (ex.Message.Contains("未将对象引用设置到"))
{
UpdateMsg($"读取项目:{projectModel.name}的设备失败,原因:未查询到数据\r\n");
}
else
{
UpdateMsg($"读取项目:{projectModel.name}的设备失败,原因:{ex.Message}\r\n");
}
}
}
/// <summary>
/// 查询单个设备的属性
/// </summary>
private void QueryDeviceParamStatus(DeviceModel deviceModel)
{
StringBuilder projectSqlStrBuilder = new StringBuilder();
UpdateMsg($"正在读取设备:{deviceModel.name}{deviceModel.deviceTypeName}的属性数据\r\n");
try
{
string url = "https://api.123321yun.com/api/device/queryDeviceParamStatus";
HttpUtil.setting("application/x-www-form-urlencoded", null, null);
Dictionary<string, string> pmsDic = new Dictionary<string, string>();
pmsDic.Add("id", deviceModel.deviceId);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("__sid", sid);
HttpWebResponse webResponse = HttpUtil.Post(url, "", pmsDic, headerDic, HttpUtil.Method.POST);
string result = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(result))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(result);
string code = resultJObject["code"] + "";
if (code.Equals("200"))
{
JObject deviceParamJObject = (JObject)resultJObject["data"];
DeviceParamModel deviceParamModel = new DeviceParamModel();
deviceParamModel.deviceTypeId = deviceParamJObject["deviceType"]["id"] + "";
deviceParamModel.deviceTypeName = deviceParamJObject["deviceType"]["name"] + "";
deviceParamModel.deviceId = deviceParamJObject["deviceId"] + "";
deviceParamModel.deviceName = deviceParamJObject["deviceName"] + "";
deviceParamModel.workload = deviceParamJObject["workload"] + "";
deviceParamModel.elec = deviceParamJObject["elec"] + "";
deviceParamModel.errorParamNum = deviceParamJObject["errorParamNum"] + "";
deviceParamModel.warnParamNum = deviceParamJObject["warnParamNum"] + "";
deviceParamModel.errorTimeSum = deviceParamJObject["errorTimeSum"] + "";
deviceParamModel.runTimeSum = deviceParamJObject["runTimeSum"] + "";
deviceParamModel.warnEventSum = deviceParamJObject["warnEventSum"] + "";
deviceParamModel.errorEventSum = deviceParamJObject["errorEventSum"] + "";
deviceParamModel.projectId = deviceParamJObject["projectId"] + "";
deviceParamModel.status = deviceParamJObject["status"] + "";
deviceParamModel.timestamp = deviceParamJObject["timestamp"] + "";
StringBuilder deviceParamInsertKeys = new StringBuilder();
StringBuilder deviceParamInsertValues = new StringBuilder();
PropertyInfo[] deviceParamPropertyInfos = deviceParamModel.GetType().GetProperties();
foreach (System.Reflection.PropertyInfo deviceParamPropertyInfo in deviceParamPropertyInfos)
{
deviceParamInsertKeys.Append($"{deviceParamPropertyInfo.Name},");
deviceParamInsertValues.Append($"'{(deviceParamPropertyInfo.GetValue(deviceParamModel, null) + "").Replace("'", "''")}',");
}
projectSqlStrBuilder.Append($"insert into LadfDeviceParamTab ({deviceParamInsertKeys.ToString().TrimEnd(',')}) values ({deviceParamInsertValues.ToString().TrimEnd(',')});\r\n");
JArray devicePmsArray = (JArray)deviceParamJObject["jsonParams"];
foreach (JObject devicePmsJObject in devicePmsArray)
{
try
{
DeviceParamStatusModel devicePmsModel = new DeviceParamStatusModel();
devicePmsModel.projectId = deviceModel.projectId;
devicePmsModel.deviceId = deviceModel.deviceId;
devicePmsModel.qs = devicePmsJObject["qs"] + "";
devicePmsModel.realValue = devicePmsJObject["realValue"] + "";
devicePmsModel.flag = devicePmsJObject["flag"] + "";
devicePmsModel.id = devicePmsJObject["id"] + "";
devicePmsModel.paramName = devicePmsJObject["paramName"] + "";
devicePmsModel.value = devicePmsJObject["value"] + "";
devicePmsModel.unitName = devicePmsJObject["unitName"] + "";
devicePmsModel.dataType = devicePmsJObject["dataType"] + "";
StringBuilder devicePmsInsertKeys = new StringBuilder();
StringBuilder devicePmsInsertValues = new StringBuilder();
PropertyInfo[] devicePmsPropertyInfos = devicePmsModel.GetType().GetProperties();
foreach (System.Reflection.PropertyInfo devicePmsPropertyInfo in devicePmsPropertyInfos)
{
devicePmsInsertKeys.Append($"{devicePmsPropertyInfo.Name},");
devicePmsInsertValues.Append($"'{(devicePmsPropertyInfo.GetValue(devicePmsModel, null) + "").Replace("'", "''")}',");
}
projectSqlStrBuilder.Append($"insert into LadfDeviceParamStatusTab ({devicePmsInsertKeys.ToString().TrimEnd(',')}) values ({devicePmsInsertValues.ToString().TrimEnd(',')});\r\n");
}
catch (Exception)
{
}
}
if (!string.IsNullOrEmpty(projectSqlStrBuilder.ToString()))
{
SqlHelper.ExecuteNonQuery(projectSqlStrBuilder.ToString());
}
}
else if (code.Equals("4012"))
{
UpdateMsg($"登录失败\r\n");
Login();
QueryDeviceParamStatus(deviceModel);
}
UpdateMsg($"读取设备:{deviceModel.name}{deviceModel.deviceTypeName}的属性成功\r\n");
}
}
catch (Exception ex)
{
if (ex.Message.Contains("未将对象引用设置到"))
{
UpdateMsg($"读取设备:{deviceModel.name}{deviceModel.deviceTypeName}的属性成功,但未查询到数据\r\n");
}
else
{
UpdateMsg($"读取设备:{deviceModel.name}{deviceModel.deviceTypeName}的属性数据失败,原因:{ex.Message}\r\n");
}
}
}
/// <summary>
/// 查询历史数据
/// </summary>
private void QueryDeviceParamStatusHistory(DeviceModel deviceModel)
{
StringBuilder projectSqlStrBuilder = new StringBuilder();
UpdateMsg($"正在读取设备:{deviceModel.name}{deviceModel.deviceTypeName}的属性历史数据\r\n");
try
{
string url = "https://api.123321yun.com/api/device/queryDeviceParamHistoryData";
HttpUtil.setting("application/x-www-form-urlencoded", null, null);
Dictionary<string, string> pmsDic = new Dictionary<string, string>();
pmsDic.Add("deviceId", deviceModel.deviceId);
pmsDic.Add("start", GetNowTime0Stamp());
pmsDic.Add("end", GetNowTime24Stamp());
pmsDic.Add("type", "1");
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("__sid", sid);
HttpWebResponse webResponse = HttpUtil.Post(url, "", pmsDic, headerDic, HttpUtil.Method.POST);
string result = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(result))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(result);
string code = resultJObject["code"] + "";
if (code.Equals("200"))
{
JArray deviceParamHistoryJArray = (JArray)resultJObject["data"];
foreach (JObject deviceParamHistoryJObject in deviceParamHistoryJArray)
{
int datetime;
if (!int.TryParse(deviceParamHistoryJObject["datetime"] + "", out datetime))
{
Console.WriteLine("时间转换失败");
}
IEnumerable<JProperty> properties = deviceParamHistoryJObject.Properties();
foreach (JProperty item in properties)
{
string flag = item.Name.ToString().Replace("'", "''");
string value = item.Value.ToString().Replace("'", "''");
projectSqlStrBuilder.Append($"insert into LadfDeviceParamStatusHistoryTab (projectId,deviceId,flag,value,datetime) values ('{deviceModel.projectId}','{deviceModel.deviceId}','{flag}','{value}',{datetime});\r\n");
}
}
if (!string.IsNullOrEmpty(projectSqlStrBuilder.ToString()))
{
SqlHelper.ExecuteNonQuery(projectSqlStrBuilder.ToString());
}
}
else if (code.Equals("4012"))
{
UpdateMsg($"登录失败\r\n");
Login();
QueryDeviceParamStatusHistory(deviceModel);
}
UpdateMsg($"读取设备:{deviceModel.name}{deviceModel.deviceTypeName}的属性历史数据成功\r\n");
}
}
catch (Exception ex)
{
if (ex.Message.Contains("未将对象引用设置到"))
{
UpdateMsg($"读取设备:{deviceModel.name}{deviceModel.deviceTypeName}的属性历史数据失败,原因:未查询到数据\r\n");
}
else
{
UpdateMsg($"读取设备:{deviceModel.name}{deviceModel.deviceTypeName}的属性历史数据失败,原因:{ex.Message}\r\n");
}
}
}
/// <summary>
/// 连接数据库
/// </summary>
/// <returns></returns>
private bool CreateConnection()
{
string connStr = GetConnection();
if (SqlHelper._connection != null)
{
try
{
SqlHelper._connection.Close();
SqlHelper._connection.Dispose();
}
catch (Exception)
{
}
SqlHelper._connection = null;
}
try
{
SqlHelper._connection = new SqlConnection(connStr);
SqlHelper._connection.Open();
return true;
}
catch (Exception)
{
// LogHelper.Instance.WriteLog(ex.Message);
}
return false;
}
private void CloseConnection()
{
if (SqlHelper._connection != null)
{
try
{
SqlHelper._connection.Close();
SqlHelper._connection.Dispose();
}
catch (Exception)
{
}
SqlHelper._connection = null;
}
}
/// <summary>
/// 获取连接服务器的字符串
/// </summary>
/// <returns></returns>
public string GetConnection()
{
return string.Format("Server={0};Database={1};Persist Security Info=True;User ID={2};Password={3};Connection Timeout=5;MultipleActiveResultSets=true", this.serverBox.Text, this.dataBaseBox.Text, "lserpAdmin", "lserp110");
}
/// <summary>
/// 获取当天零点的时间戳
/// </summary>
/// <returns></returns>
public string GetNowTime0Stamp()
{
int year = DateTime.Now.Year;
int month = DateTime.Now.Month;
int day = DateTime.Now.Day;
DateTime dateTime = new DateTime(year, month, day, 0, 0, 0, 0);
TimeSpan tspan = dateTime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(tspan.TotalSeconds).ToString();
}
/// <summary>
/// 获取当天24点的时间戳
/// </summary>
/// <returns></returns>
public string GetNowTime24Stamp()
{
int year = DateTime.Now.Year;
int month = DateTime.Now.Month;
int day = DateTime.Now.Day;
DateTime dateTime = new DateTime(year, month, day, 23, 59, 59, 999);
TimeSpan tspan = dateTime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Con
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
namespace LadfDataApp
{
public static class HttpUtil
{
public static CookieContainer cookie = new CookieContainer(); // 用于记录访问网页时cookie数据
public static CookieCollection cookieCollection;
private static string ContentType = string.Empty;// "application/x-www-form-urlencoded";
private static string Accept = string.Empty;//"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
private static string UserAgent = string.Empty;//"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14";
public enum Method
{
POST = 0,
GET = 1
}
public static void setting(string contentType, string accept, string userAgent)
{
ContentType = contentType;
Accept = accept;
UserAgent = userAgent;
}
/// <summary>
/// post数据到指定的网址,获取cookie数据,和返回页
/// </summary>
public static HttpWebResponse Post(string url, string postData, Dictionary<string, string> pmsDic, Dictionary<string, string> headerDic, Method method)
{
return Post(url, postData, pmsDic, headerDic, method, out cookieCollection);
}
/// <summary>
/// post数据到指定的网址,获取cookie数据,和返回页
/// </summary>
public static HttpWebResponse Post(string url, string postData, Dictionary<string, string> pmsDic, Dictionary<string, string> headerDic, Method method, out CookieCollection cookieCollection)
{
HttpWebResponse httpWebResponse = null;
try
{
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookie;
httpWebRequest.ContentType = ContentType;
//httpWebRequest.Referer = url;
httpWebRequest.Accept = Accept;
httpWebRequest.UserAgent = UserAgent;
httpWebRequest.Method = method == Method.POST ? "POST" : "GET";
byte[] byteRequest = null;
if (headerDic != null)
{
foreach (var item in headerDic)
{
httpWebRequest.Headers.Add(item.Key, item.Value);
}
}
if (!string.IsNullOrEmpty(postData))
{
byteRequest = Encoding.Default.GetBytes(postData);
httpWebRequest.ContentLength = byteRequest.Length;
}
else
{
StringBuilder builder = new StringBuilder();
int i = 0;
foreach (var item in pmsDic)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
byteRequest = Encoding.UTF8.GetBytes(builder.ToString());
httpWebRequest.ContentLength = byteRequest.Length;
}
Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
cookieCollection = cookie.GetCookies(new Uri(url));
return httpWebResponse;
}
catch (Exception)
{
cookieCollection = null;
return httpWebResponse;
}
}
public static HttpWebResponse Post(string url, string postData, Dictionary<string, string> dic, Method method, out CookieCollection cookieCollection, out string result)
{
result = "";
HttpWebResponse httpWebResponse = null;
try
{
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookie;
httpWebRequest.ContentType = ContentType;
//httpWebRequest.Referer = url;
httpWebRequest.Accept = Accept;
httpWebRequest.UserAgent = UserAgent;
httpWebRequest.Method = method == Method.POST ? "POST" : "GET";
byte[] byteRequest = null;
if (!string.IsNullOrEmpty(postData))
{
byteRequest = Encoding.Default.GetBytes(postData);
httpWebRequest.ContentLength = byteRequest.Length;
}
else
{
StringBuilder builder = new StringBuilder();
int i = 0;
if (dic != null)
{
foreach (var item in dic)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AA75C812-16A4-498C-BF4D-F1C2CB8E0015}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>LadfDataApp</RootNamespace>
<AssemblyName>LadfDataApp</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.1.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\引用DLL\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Model\DeviceModel.cs" />
<Compile Include="Model\DeviceParamModel.cs" />
<Compile Include="Model\DeviceParamStatusModel.cs" />
<Compile Include="FrmMain.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmMain.Designer.cs">
<DependentUpon>FrmMain.cs</DependentUpon>
</Compile>
<Compile Include="HttpUtil.cs" />
<Compile Include="Program.cs" />
<Compile Include="Model\ProjectModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlUtil.cs" />
<EmbeddedResource Include="FrmMain.resx">
<DependentUpon>FrmMain.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="App.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.T
Binary file not shown.
@@ -0,0 +1,9 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("LadfDataApp")]
[assembly: Asse
@@ -0,0 +1,40 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace LadfDataApp.Properties
{
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager Resour
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1 @@
//-------------------------------------------------------------------
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
@@ -0,0 +1,566 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
namespace LadfDataApp
{
public static class SqlHelper
{
/// <summary>
/// 数据连接
/// </summary>
public static SqlConnection _connection;
/// <summary>
/// 请求超时时间
/// </summary>
public static int CommandTimeout;
#region ExecuteAdapter
/// <summary>
/// <para>说明:获取适配器</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>SqlDataAdapter.</returns>
public static SqlDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlDataAdapter adapter;
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
adapter = new SqlDataAdapter(cmd);
}
catch
{
throw;
}
return adapter;
}
/// <summary>
/// <para>说明:获取适配器</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <returns>SqlDataAdapter.</returns>
public static SqlDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText)
{
SqlDataAdapter adapter;
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
adapter = new SqlDataAdapter(cmd);
}
catch
{
throw;
}
return adapter;
}
#endregion
#region ExecuteDataTable
/// <summary>
/// <para>说明:执行sql返回DataTable</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdText">The command text.</param>
/// <returns>DataTable.</returns>
public static DataTable ExecuteDataTable(string cmdText)
{
return ExecuteDataSet(cmdText).Tables[0];
}
/// <summary>
/// <para>说明:执行sql返回DataTable</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdText">The command text.</param>
/// <returns>DataTable.</returns>
public static DataTable ExecuteDataTable(string cmdText, params SqlParameter[] commandParameters)
{
return ExecuteDataSet(CommandType.Text, cmdText, "temp", commandParameters).Tables[0];
}
/// <summary>
/// <para>说明:执行sql返回指定字段值</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-15 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Object.</returns>
public static object ExecuteObject(string fieldName, string cmdText)
{
object result = null;
try
{
result = ExecuteDataSet(cmdText).Tables[0].Rows[0][fieldName];
}
catch (Exception)
{
}
return result;
}
/// <summary>
/// <para>说明:执行sql返回指定字段值</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>System.Object.</returns>
public static object ExecuteObject(string fieldName, string cmdText, params SqlParameter[] commandParameters)
{
object result = null;
try
{
result = ExecuteDataSet(CommandType.Text, cmdText, "temp", commandParameters).Tables[0].Rows[0][fieldName];
}
catch (Exception)
{
}
return result;
}
/// <summary>
/// <para>说明:执行sql返回指定字段值</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-15 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Object.</returns>
public static string ExecuteString(string fieldName, string cmdText)
{
object obj = ExecuteObject(fieldName, cmdText);
return obj == null ? "" : obj.ToString();
}
/// <summary>
/// <para>说明:执行sql返回指定字段值</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>System.String.</returns>
public static string ExecuteString(string fieldName, string cmdText, params SqlParameter[] commandParameters)
{
object obj = ExecuteObject(fieldName, cmdText, commandParameters);
return obj == null ? "" : obj.ToString();
}
#endregion
#region ExecuteDataSet
/// <summary>
/// <para>说明:查询结果集</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="tabName">Name of the tab.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>DataSet.</returns>
public static DataSet ExecuteDataSet(int cmdType, string cmdText, string tabName, params SqlParameter[] commandParameters)
{
CommandType _cmdType = CommandType.Text;
switch (cmdType)
{
case 4:
_cmdType = CommandType.StoredProcedure;
break;
case 512:
_cmdType = CommandType.TableDirect;
break;
}
return ExecuteDataSet(_cmdType, cmdText, tabName, commandParameters);
}
/// <summary>
/// <para>说明:查询结果集</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">语句类型存储过程或者sql语句</param>
/// <param name="cmdText">执行内容</param>
/// <param name="tabName">表名</param>
/// <param name="commandParameters">参数</param>
/// <returns>DataSet.</returns>
public static DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string tabName, params SqlParameter[] commandParameters)
{
DataSet set2;
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, tabName);
//adapter.FillSchema(dataSet, SchemaType.Mapped, tabName);
set2 = dataSet;
}
catch (Exception e)
{
if (e.Message.StartsWith("在从服务器接收结果时发生传输级错误") ||
e.Message.StartsWith("在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误") ||
e.Message.StartsWith("在向服务器发送请求时发生传输级错误"))
{
throw new Exception("无法连接服务器,请检查网络连接.");
}
else
{
throw;
}
}
finally
{
cmd.Dispose();
}
return set2;
}
/// <summary>
/// <para>说明:查询结果集</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">语句类型存储过程或者sql语句</param>
/// <param name="cmdText">执行内容</param>
/// <param name="tabName">表名</param>
/// <returns>DataSet.</returns>
public static DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string tabName)
{
return ExecuteDataSet(cmdType, cmdText, tabName, null);
}
/// <summary>
/// <para>说明:查询结果集</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdText">执行内容</param>
/// <returns>DataSet.</returns>
public static DataSet ExecuteDataSet(string cmdText)
{
return ExecuteDataSet(CommandType.Text, cmdText, "temp");
}
/// <summary>
/// <para>说明:查询结果集</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="procedureName">Name of the procedure.</param>
/// <param name="tabName">表名</param>
/// <param name="parameterNames">The parameter names.</param>
/// <param name="parameterValues">The parameter values.</param>
/// <returns>DataSet.</returns>
public static DataSet ExecuteDataSet(string procedureName, string tabName, string[] parameterNames, object[] parameterValues)
{
DataSet set2;
try
{
SqlCommand cmd = new SqlCommand(procedureName, _connection);
cmd.CommandType = CommandType.StoredProcedure;
if (parameterNames != null && parameterValues != null)
{
for (int i = 0; i < parameterNames.Length && i < parameterValues.Length; i++)
{
cmd.Parameters.AddWithValue(parameterNames[i], parameterValues[i]);
}
}
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, tabName);
set2 = dataSet;
}
catch
{
throw;
}
return set2;
}
#endregion
#region ExecuteNonQuery
/// <summary>
/// <para>说明:执行sql语句或者存储过程</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>System.Int32.</returns>
public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
int num = 0;
try
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
num = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
catch (Exception e)
{
if (e.Message.StartsWith("在从服务器接收结果时发生传输级错误") ||
e.Message.StartsWith("在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误") ||
e.Message.StartsWith("在向服务器发送请求时发生传输级错误"))
{
throw new Exception("无法连接服务器,请检查网络连接.");
}
else
{
throw;
}
}
finally
{
cmd.Dispose();
}
return num;
}
/// <summary>
/// <para>说明:执行sql语句或者存储过程</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Int32.</returns>
public static int ExecuteNonQuery(CommandType cmdType, string cmdText)
{
return ExecuteNonQuery(CommandType.Text, cmdText, null);
}
/// <summary>
/// <para>说明:执行sql语句或者存储过程</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Int32.</returns>
public static int ExecuteNonQuery(string cmdText)
{
return ExecuteNonQuery(CommandType.Text, cmdText);
}
#endregion
#region ExecuteReader
/// <summary>
/// <para>说明:执行sql语句或者存储过程并返回结果集(只读、只进)</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>SqlDataReader.</returns>
public static SqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlDataReader reader2;
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
SqlDataReader reader = cmd.ExecuteReader();
cmd.Parameters.Clear();
reader2 = reader;
}
catch
{
throw;
}
return reader2;
}
#endregion
#region ExecuteScalar
/// <summary>
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="Connectionection">The connectionection.</param>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>System.Object.</returns>
public static object ExecuteScalar(SqlConnection Connectionection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, Connectionection, null, cmdType, cmdText, commandParameters);
object obj2 = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return obj2;
}
/// <summary>
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>System.Object.</returns>
public static object ExecuteScalar(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
object obj2 = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return obj2;
}
}
/// <summary>
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Object.</returns>
public static object ExecuteScalar(CommandType cmdType, string cmdText)
{
SqlCommand cmd = new SqlCommand();
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
object obj2 = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return obj2;
}
}
/// <summary>
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-21 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Object.</returns>
public static object ExecuteScalar(string cmdText)
{
SqlCommand cmd = new SqlCommand();
{
PrepareCommand(cmd, _connection, null, CommandType.Text, cmdText, null);
object obj2 = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return obj2;
}
}
#endregion
#region PrepareCommand
/// <summary>
/// <para>说明: sql参数处理</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmd">The command.</param>
/// <param name="Connection">The connection.</param>
/// <param name="trans">The trans.</param>