Files
Desktop_BLVStudio/BLV_Studio/EnergySavingAttribute.vb
2026-01-16 19:20:06 +08:00

754 lines
33 KiB
VB.net
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Imports System.IO
Imports System.Net
Imports System.Text
Imports Newtonsoft.Json
Public Class EnergySavingAttribute
Public G_ReportingScenario As ReportingScenario
Public G_loopNameAddr As Dictionary(Of String, String)
Public G_roomtypeid As Integer
Public G_Hotelid As Integer
Public G_Uploaduser As String
Public G_roomtypename As String
Public G_DateStr As Dictionary(Of String, List(Of (String String)))
Public IsLoadServer As Integer = 0
Public g_Oldloopinfo As String = ""
Public DbConnString As String = "Server=blv-cloud-db.mysql.rds.aliyuncs.com;Port=3307;Database=blv_rcu_db;Uid=blv_rcu;Pwd=fnadiaJDIJ7546;charset=utf8;"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PowerGridInit()
RatioGridInit()
LoadPowerInit()
End Sub
'给页面加载数据
Sub New(nReportingScenario As ReportingScenario, roomtypeid As Integer, hotelid As Integer, uploaduser As String, datestr As String, roomtypename As String)
' 此调用是设计器所必需的。
InitializeComponent()
G_roomtypeid = roomtypeid
G_roomtypename = roomtypename
G_Hotelid = hotelid
G_Uploaduser = uploaduser
G_loopNameAddr = New Dictionary(Of String, String)
G_ReportingScenario = nReportingScenario
Dim li As List(Of MDevNodeMessage) = nReportingScenario.getDateDisposeRuning(True)
For Each item In li
If G_loopNameAddr.ContainsKey(item.ModalAddress) Then
Continue For
Else
G_loopNameAddr.Add(item.ModalAddress, item.Name)
End If
Next
G_DateStr = New Dictionary(Of String, List(Of (String String)))
Dim tnli As List(Of (String String))
Dim strbuf As String() = datestr.Split(vbLf)
Dim cstrbutf As String()
For Each item In strbuf
cstrbutf = item.Trim().Split(",")
If G_DateStr.ContainsKey(cstrbutf(2)) Then
tnli = G_DateStr(cstrbutf(2))
tnli.Add((cstrbutf(3), cstrbutf(4)))
Else
tnli = New List(Of (String String))
tnli.Add((cstrbutf(3), cstrbutf(4)))
G_DateStr.Add(cstrbutf(2), tnli)
End If
Next
Console.WriteLine(G_DateStr.Count)
' 在 InitializeComponent() 调用之后添加任何初始化。
End Sub
Public Sub PowerGridInit()
PowerInit.NewFile()
PowerInit.DisplayRowNumber = True
PowerInit.Cols = 9
PowerInit.Rows = 1
PowerInit.ExtendLastCol = True
PowerInit.Cell(0, 0).Text = "ID"
PowerInit.Cell(0, 1).Text = "启用"
PowerInit.Cell(0, 2).Text = "酒店编号"
PowerInit.Cell(0, 3).Text = "房型"
PowerInit.Cell(0, 4).Text = "本地回路名称"
PowerInit.Cell(0, 5).Text = "回路地址"
PowerInit.Cell(0, 6).Text = "功率"
PowerInit.Cell(0, 7).Text = "节能比例(%"
PowerInit.Cell(0, 8).Text = "备注"
PowerInit.Column(0).Width = 40
PowerInit.Column(1).Width = 20
PowerInit.Column(2).Width = 60
PowerInit.Column(3).Width = 200
PowerInit.Column(4).Width = 100
PowerInit.Column(5).Width = 80
PowerInit.Column(6).Width = 50
PowerInit.Column(7).Width = 80
PowerInit.Column(1).CellType = FlexCell.CellTypeEnum.CheckBox
PowerInit.Column(7).CellType = FlexCell.CellTypeEnum.ComboBox
PowerInit.Column(0).Alignment = FlexCell.AlignmentEnum.CenterCenter
PowerInit.Column(1).Alignment = FlexCell.AlignmentEnum.CenterCenter
PowerInit.Column(2).Alignment = FlexCell.AlignmentEnum.CenterCenter
PowerInit.Column(3).Alignment = FlexCell.AlignmentEnum.CenterCenter
PowerInit.Column(4).Alignment = FlexCell.AlignmentEnum.CenterCenter
PowerInit.Column(5).Alignment = FlexCell.AlignmentEnum.CenterCenter
PowerInit.Column(6).Alignment = FlexCell.AlignmentEnum.CenterCenter
PowerInit.Column(7).Alignment = FlexCell.AlignmentEnum.CenterCenter
PowerInit.Column(8).Alignment = FlexCell.AlignmentEnum.CenterCenter
'设置1到4列不可编辑
For i As Integer = 2 To 5
PowerInit.Column(i).Locked = True
Next
End Sub
'加载PowerInit表
Public Sub LoadPowerInit()
If IsNothing(G_loopNameAddr) OrElse G_loopNameAddr.Count = 0 Then Return
Dim dic As Dictionary(Of String, Dictionary(Of String, String)) = GetholteloopVAl(G_Hotelid, G_roomtypeid)
Dim ncdic As Dictionary(Of String, String)
Dim li As List(Of (String String))
Dim Gcstr As String
Dim Ginttype As Integer = -1
For i As Integer = 0 To G_loopNameAddr.Keys.Count - 1
Gcstr = G_loopNameAddr.Keys(i).Substring(0, 3)
Integer.TryParse(Gcstr, Ginttype)
Select Case Ginttype
Case 24, 1 'pwm调光 、继电器
li = G_DateStr(2.ToString)
PowerInit.AddItem("")
PowerInit.Cell(PowerInit.Rows - 1, 2).Text = G_Hotelid
PowerInit.Cell(PowerInit.Rows - 1, 3).Text = G_roomtypename
PowerInit.Cell(PowerInit.Rows - 1, 4).Text = G_loopNameAddr.Values(i)
PowerInit.Cell(PowerInit.Rows - 1, 5).Text = G_loopNameAddr.Keys(i)
PowerInit.Cell(PowerInit.Rows - 1, 6).Text = "0"
If li.Count > 0 Then
PowerInit.Cell(PowerInit.Rows - 1, 7).Text = li(0).Item1
Else
PowerInit.Cell(PowerInit.Rows - 1, 7).Text = "0"
End If
If Not IsNothing(dic) AndAlso dic.ContainsKey(G_loopNameAddr.Keys(i)) Then
ncdic = dic(G_loopNameAddr.Keys(i))
PowerInit.Cell(PowerInit.Rows - 1, 1).Text = ncdic.Item("push_state")
PowerInit.Cell(PowerInit.Rows - 1, 6).Text = ncdic.Item("power")
PowerInit.Cell(PowerInit.Rows - 1, 8).Text = ncdic.Item("remark")
End If
Case 52 '色温
li = G_DateStr(2.ToString)
PowerInit.AddItem("")
PowerInit.Cell(PowerInit.Rows - 1, 2).Text = G_Hotelid
PowerInit.Cell(PowerInit.Rows - 1, 3).Text = G_roomtypename
PowerInit.Cell(PowerInit.Rows - 1, 4).Text = G_loopNameAddr.Values(i)
PowerInit.Cell(PowerInit.Rows - 1, 5).Text = G_loopNameAddr.Keys(i)
PowerInit.Cell(PowerInit.Rows - 1, 6).Text = "0"
If li.Count > 0 Then
PowerInit.Cell(PowerInit.Rows - 1, 7).Text = li(0).Item1
Else
PowerInit.Cell(PowerInit.Rows - 1, 7).Text = "0"
End If
If Not IsNothing(dic) AndAlso dic.ContainsKey(G_loopNameAddr.Keys(i)) Then
ncdic = dic(G_loopNameAddr.Keys(i))
'PowerInit.Cell(PowerInit.Rows - 1, 3).Text = ncdic.Item("name")
PowerInit.Cell(PowerInit.Rows - 1, 1).Text = ncdic.Item("push_state")
PowerInit.Cell(PowerInit.Rows - 1, 6).Text = ncdic.Item("power")
PowerInit.Cell(PowerInit.Rows - 1, 8).Text = ncdic.Item("remark")
End If
Case 50 'pwm调光
li = G_DateStr(2.ToString)
PowerInit.AddItem("")
PowerInit.Cell(PowerInit.Rows - 1, 2).Text = G_Hotelid
PowerInit.Cell(PowerInit.Rows - 1, 3).Text = G_roomtypename
PowerInit.Cell(PowerInit.Rows - 1, 4).Text = G_loopNameAddr.Values(i)
PowerInit.Cell(PowerInit.Rows - 1, 5).Text = G_loopNameAddr.Keys(i)
PowerInit.Cell(PowerInit.Rows - 1, 6).Text = "0"
If li.Count > 0 Then
PowerInit.Cell(PowerInit.Rows - 1, 7).Text = li(0).Item1
Else
PowerInit.Cell(PowerInit.Rows - 1, 7).Text = "0"
End If
If Not IsNothing(dic) AndAlso dic.ContainsKey(G_loopNameAddr.Keys(i)) Then
ncdic = dic(G_loopNameAddr.Keys(i))
'PowerInit.Cell(PowerInit.Rows - 1, 3).Text = ncdic.Item("name")
PowerInit.Cell(PowerInit.Rows - 1, 1).Text = ncdic.Item("push_state")
PowerInit.Cell(PowerInit.Rows - 1, 6).Text = ncdic("power")
PowerInit.Cell(PowerInit.Rows - 1, 8).Text = ncdic("remark")
End If
Case 7 '温控
li = G_DateStr(3.ToString)
RatioInit.AddItem("")
RatioInit.Cell(RatioInit.Rows - 1, 2).Text = G_Hotelid
RatioInit.Cell(RatioInit.Rows - 1, 3).Text = G_roomtypename
RatioInit.Cell(RatioInit.Rows - 1, 4).Text = G_loopNameAddr.Values(i)
RatioInit.Cell(RatioInit.Rows - 1, 5).Text = G_loopNameAddr.Keys(i)
If li.Count > 0 Then
'取回路地址第4到6位转成int类型
Dim Ginttype2 As Integer = Integer.Parse(G_loopNameAddr.Keys(i).Substring(3, 3))
'使用linq查询li中Item2为Ginttype2的项 取其Item1
Dim Gstr As String = (From x In li Where x.Item1 = Ginttype2 Select x.Item2).FirstOrDefault
RatioInit.Cell(RatioInit.Rows - 1, 9).Text = Gstr
Else
RatioInit.Cell(RatioInit.Rows - 1, 9).Text = "0"
End If
If Not IsNothing(dic) AndAlso dic.ContainsKey(G_loopNameAddr.Keys(i)) Then
ncdic = dic(G_loopNameAddr.Keys(i))
'RatioInit.Cell(0, 1).Text = "酒店编号"
'RatioInit.Cell(0, 2).Text = "房型"
'RatioInit.Cell(0, 3).Text = "空调名称"
'RatioInit.Cell(0, 4).Text = "空调回路"
'RatioInit.Cell(0, 5).Text = "空调类型"
'RatioInit.Cell(0, 6).Text = "厂牌"
'RatioInit.Cell(0, 7).Text = "型号"
'RatioInit.Cell(0, 8).Text = "空调节能温差"
'RatioInit.Cell(0, 9).Text = "房间高度"
'RatioInit.Cell(0, 10).Text = "房间面积"
'RatioInit.Cell(0, 11).Text = "热损失系数"
'RatioInit.Cell(0, 12).Text = "备注"
RatioInit.Cell(RatioInit.Rows - 1, 1).Text = ncdic.Item("push_state")
RatioInit.Cell(RatioInit.Rows - 1, 6).Text = ncdic("air_type")
RatioInit.Cell(RatioInit.Rows - 1, 7).Text = ncdic("air_brand")
RatioInit.Cell(RatioInit.Rows - 1, 8).Text = ncdic("air_model")
RatioInit.Cell(RatioInit.Rows - 1, 10).Text = ncdic("height")
RatioInit.Cell(RatioInit.Rows - 1, 11).Text = ncdic("area")
RatioInit.Cell(RatioInit.Rows - 1, 12).Text = ncdic("heat_loss")
RatioInit.Cell(RatioInit.Rows - 1, 13).Text = ncdic("remark")
End If
End Select
Next
End Sub
Public Function GetholteloopVAl(hotelID As String roomtypeid As String) As Dictionary(Of String, Dictionary(Of String, String))
If String.IsNullOrEmpty(hotelID) AndAlso String.IsNullOrEmpty(roomtypeid) Then Return Nothing
Dim dic As Dictionary(Of String, Dictionary(Of String, String)) = New Dictionary(Of String, Dictionary(Of String, String))
Dim dt As DataTable
Dim indexDci As Dictionary(Of String, String)
Using db As New DbExecutor(DbExecutor.DbTypeEnum.Mysql, DbConnString)
db.Open()
dt = db.ExecuteDataTable(db.CmdHelper.DbSearchAll("blv_rcu_db", "tbl_room_type_circuit_powers", $"`hotel_rcu_code`='{hotelID}' and `room_type_code`='{roomtypeid}'"))
db.Close()
End Using
If IsNothing(dt) OrElse dt.Rows.Count = 0 Then Return Nothing
For Each row As DataRow In dt.Rows
If dic.ContainsKey(row("address")) Then
indexDci = dic(row("address"))
indexDci("push_state") = row("push_state")
indexDci("type") = row("type")
indexDci("name") = row("name")
indexDci("power") = row("power")
indexDci("rate") = row("rate")
indexDci("temperature") = row("temperature")
If Not IsDBNull(row("air_type")) Then
indexDci("air_type") = row("air_type")
End If
If Not IsDBNull(row("air_brand")) Then
indexDci("air_brand") = row("air_brand")
End If
If Not IsDBNull(row("air_model")) Then
indexDci("air_model") = row("air_model")
End If
indexDci("height") = row("height")
indexDci("area") = row("area")
indexDci("heat_loss") = row("heat_loss")
indexDci("remark") = row("remark")
Else
indexDci = New Dictionary(Of String, String)
indexDci.Add("type", row("type"))
indexDci.Add("push_state", row("push_state"))
indexDci.Add("name", row("name"))
indexDci.Add("power", row("power"))
indexDci.Add("rate", row("rate"))
indexDci.Add("temperature", row("temperature"))
If Not IsDBNull(row("air_type")) Then
indexDci.Add("air_type", row("air_type"))
End If
If Not IsDBNull(row("air_brand")) Then
indexDci.Add("air_brand", row("air_brand"))
End If
If Not IsDBNull(row("air_model")) Then
indexDci.Add("air_model", row("air_model"))
End If
indexDci.Add("height", row("height"))
indexDci.Add("area", row("area"))
indexDci.Add("heat_loss", row("heat_loss"))
indexDci.Add("remark", row("remark"))
dic.Add(row("address"), indexDci)
End If
Next
Return dic
End Function
Public Sub RatioGridInit()
RatioInit.NewFile()
RatioInit.DisplayRowNumber = True
RatioInit.Cols = 14
RatioInit.Rows = 1
RatioInit.ExtendLastCol = True
RatioInit.Cell(0, 0).Text = "ID"
'酒店编号 房间号 空调回路 空调类型 厂牌 型号 空调节能温差 备注
RatioInit.Cell(0, 1).Text = "启用"
RatioInit.Cell(0, 2).Text = "酒店编号"
RatioInit.Cell(0, 3).Text = "房型"
RatioInit.Cell(0, 4).Text = "空调名称"
RatioInit.Cell(0, 5).Text = "空调回路"
RatioInit.Cell(0, 6).Text = "空调类型"
RatioInit.Cell(0, 7).Text = "厂牌"
RatioInit.Cell(0, 8).Text = "型号"
RatioInit.Cell(0, 9).Text = "空调节能温差"
RatioInit.Cell(0, 10).Text = "房间高度"
RatioInit.Cell(0, 11).Text = "房间面积"
RatioInit.Cell(0, 12).Text = "热损失系数"
RatioInit.Cell(0, 13).Text = "备注"
RatioInit.Column(0).Width = 40
RatioInit.Column(1).Width = 20
RatioInit.Column(2).Width = 60
RatioInit.Column(3).Width = 200
RatioInit.Column(4).Width = 100
RatioInit.Column(5).Width = 80
RatioInit.Column(6).Width = 50
RatioInit.Column(7).Width = 100
RatioInit.Column(8).Width = 80
RatioInit.Column(9).Width = 80
RatioInit.Column(10).Width = 80
RatioInit.Column(11).Width = 80
RatioInit.Column(12).Width = 80
RatioInit.Column(1).CellType = FlexCell.CellTypeEnum.CheckBox
RatioInit.Column(9).CellType = FlexCell.CellTypeEnum.ComboBox
RatioInit.Column(0).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(1).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(2).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(3).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(4).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(5).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(6).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(7).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(8).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(9).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(10).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(11).Alignment = FlexCell.AlignmentEnum.CenterCenter
RatioInit.Column(12).Alignment = FlexCell.AlignmentEnum.CenterCenter
'设置 1到2 列为只读
For i As Integer = 2 To 3
RatioInit.Column(i).Locked = True
Next
End Sub
'Private Function ToolStripButton1_Click(sender As Object, e As EventArgs) As List(Of Dictionary(Of String, Object))
Private Function GetRatioInitLi() As List(Of Dictionary(Of String, Object))
'判断PowerInit 是否为空
If RatioInit.Rows = 1 Then
'MsgBox("请先添加完整的温控数据!")
Return Nothing
End If
''遍历PowerInit
Dim li As New List(Of Dictionary(Of String, Object))
Dim dic As Dictionary(Of String, Object)
Dim fnumber As Double = 0
For i As Integer = 1 To RatioInit.Rows - 1
'遍历每一列
dic = New Dictionary(Of String, Object)
dic.Add("type", 1)
dic.Add("is_carbon", 0)
If RatioInit.Cell(i, 1).Text.Equals("1") Then
dic.Add("push_state", 1)
Else
dic.Add("push_state", 0)
End If
For j As Integer = 4 To RatioInit.Cols - 1
'判断是否为空
Dim str As String = RatioInit.Cell(i, j).Text
If String.IsNullOrEmpty(RatioInit.Cell(i, j).Text) AndAlso j <> RatioInit.Cols - 1 AndAlso j <> 4 Then
MsgBox($"温控 第{i}行 {j}列数据缺失请补全数据再进行上传!")
Return Nothing
End If
'RatioInit.Cell(0, 1).Text = "酒店编号"
'RatioInit.Cell(0, 2).Text = "房型"
'RatioInit.Cell(0, 3).Text = "空调名称"
'RatioInit.Cell(0, 4).Text = "空调回路"
'RatioInit.Cell(0, 5).Text = "空调类型"
'RatioInit.Cell(0, 6).Text = "厂牌"
'RatioInit.Cell(0, 7).Text = "型号"
'RatioInit.Cell(0, 8).Text = "空调节能温差"
'RatioInit.Cell(0, 9).Text = "备注"
'判断各列
Select Case j
Case 3
dic.Add("room_type_code", G_roomtypeid)
Case 4
dic.Add("name", RatioInit.Cell(i, j).Text.Trim)
Case 5
dic.Add("address", RatioInit.Cell(i, j).Text.Trim)
Case 6
dic.Add("air_type", RatioInit.Cell(i, j).Text.Trim)
Case 7
dic.Add("air_brand", RatioInit.Cell(i, j).Text.Trim)
Case 8
dic.Add("air_model", RatioInit.Cell(i, j).Text.Trim)
Case 9
If Not Double.TryParse(RatioInit.Cell(i, j).Text.Trim, fnumber) Then
MsgBox($"温控第{i}行{j}列,【空调节能温差】 数据异常!")
Return Nothing
Else
If fnumber >= 15 Or fnumber < 0 Then
MsgBox($"温控第{i}行{j}列,【功率】 数据异常!数值范围为 1到15")
Return Nothing
End If
End If
dic.Add("temperature", fnumber)
Case 10
If Not Double.TryParse(RatioInit.Cell(i, j).Text.Trim, fnumber) Then
MsgBox($"温控第{i}行{j}列,【房间高度】 数据异常!")
Return Nothing
End If
dic.Add("height", fnumber)
Case 11
If Not Double.TryParse(RatioInit.Cell(i, j).Text.Trim, fnumber) Then
MsgBox($"温控第{i}行,【房间面积】 数据异常!")
Return Nothing
End If
dic.Add("area", fnumber)
Case 12
If Not Double.TryParse(RatioInit.Cell(i, j).Text.Trim, fnumber) Then
MsgBox($"温控第{i}行{j}列,【热损失系数】 数据异常!")
Return Nothing
End If
dic.Add("heat_loss", fnumber)
Case 13
dic.Add("remark", RatioInit.Cell(i, j).Text.Trim)
End Select
Next
li.Add(dic)
Next
'Dim params As String = JsonConvert.SerializeObject(li)
'API_AllocationBarCode(G_Hotelid li)
Return li
End Function
Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click
'判断PowerInit 是否为空
If PowerInit.Rows = 1 Then
MsgBox("请先添加数据")
Return
End If
''遍历PowerInit
Dim li As New List(Of Dictionary(Of String, Object))
Dim dic As Dictionary(Of String, Object)
Dim fnumber As Double = 0
For i As Integer = 1 To PowerInit.Rows - 1
'遍历每一列
dic = New Dictionary(Of String, Object)
dic.Add("type", 0)
dic.Add("is_carbon", 0)
If PowerInit.Cell(i, 1).Text.Equals("1") Then
dic.Add("push_state", 1)
Else
dic.Add("push_state", 0)
End If
For j As Integer = 4 To PowerInit.Cols - 1
'判断是否为空
Dim str As String = PowerInit.Cell(i, j).Text
If String.IsNullOrEmpty(PowerInit.Cell(i, j).Text) AndAlso j <> PowerInit.Cols - 1 AndAlso j <> 4 Then
MsgBox($"第{i}行{j}列数据缺失请补全数据再进行上传!")
Return
End If
'判断各列
Select Case j
Case 3
dic.Add("room_type_code", G_roomtypeid)
Case 4
dic.Add("name", PowerInit.Cell(i, j).Text.Trim)
Case 5
dic.Add("address", PowerInit.Cell(i, j).Text.Trim)
Case 6
If Not Double.TryParse(PowerInit.Cell(i, j).Text.Trim, fnumber) Then
MsgBox($"第{i}行{j}列,【功率】 数据异常!")
Return
Else
If fnumber >= 10000 Or fnumber < 0 Then
MsgBox($"第{i}行{j}列,【功率】 数据异常!数值范围为 1到10000")
Return
End If
End If
dic.Add("power", fnumber)
Case 7
If Not Double.TryParse(PowerInit.Cell(i, j).Text.Trim, fnumber) Then
MsgBox($"第{i}行{j}列,【节能比例(%)】 数据异常!")
Return
Else
If fnumber > 100 Or fnumber < 0 Then
MsgBox($"第{i}行{j}列,【节能比例(%)】 数据异常!数值范围为 1到100")
Return
End If
End If
dic.Add("rate", fnumber)
Case 8
dic.Add("remark", PowerInit.Cell(i, j).Text.Trim)
End Select
Next
li.Add(dic)
Next
Dim strInputMsg As String = InputBox("请输入密码", "密码确认")
If strInputMsg <> "123456" Then Return
Dim Tli As List(Of Dictionary(Of String, Object)) = GetRatioInitLi()
If IsNothing(Tli) Then
'MsgBox("上传失败")
Return
Else
'将tli 添加到li中
li.AddRange(Tli)
End If
'插入数据到数据库
Deletetbl_room_type_circuit_powers(G_Hotelid, G_roomtypeid li)
GenerateTransactionInsertionStatements(G_Hotelid, G_roomtypeid li)
If API_AllocationBarCode(G_Hotelid, G_roomtypeid li) Then
MsgBox("上传成功")
Else
MsgBox("上传失败")
End If
End Sub
'插入数据到数据库
Public Function Deletetbl_room_type_circuit_powers(hotelID As String roomtypeid As String, insertClunm As List(Of Dictionary(Of String, Object))) As Boolean
If IsNothing(insertClunm) AndAlso insertClunm.Count = 0 Then Return False
Dim dt As DataTable
Using db As New DbExecutor(DbExecutor.DbTypeEnum.Mysql, DbConnString)
db.Open()
dt = db.ExecuteDataTable(db.CmdHelper.DeleteRows("tbl_room_type_circuit_powers", $"`hotel_rcu_code`='{hotelID}' and `room_type_code`='{roomtypeid}'"))
db.Close()
End Using
Return True
End Function
'生成事务插入语句
Public Function GenerateTransactionInsertionStatements(hotelID As String roomtypeid As String, insertClunm As List(Of Dictionary(Of String, Object))) As Boolean
If IsNothing(insertClunm) AndAlso insertClunm.Count = 0 Then Return False
'遍历insertClunm
Dim colNames As New StringBuilder
Dim db As New DbExecutor(DbExecutor.DbTypeEnum.Mysql, DbConnString)
Dim str As String = String.Empty
For Each dic As Dictionary(Of String, Object) In insertClunm
dic.Add("hotel_rcu_code", hotelID)
dic.Add("room_type_code", roomtypeid)
str = db.CmdHelper.Insert2("tbl_room_type_circuit_powers", dic)
colNames.Append(str & vbCrLf)
Next
Return Add_room_type_circuit_powers(colNames.ToString)
End Function
Public Function Add_room_type_circuit_powers(insertClunm As String) As Boolean
If String.IsNullOrEmpty(insertClunm) Then Return False
Dim dt As DataTable
Using db As New DbExecutor(DbExecutor.DbTypeEnum.Mysql, DbConnString)
db.Open()
Try
db.BeginTransaction()
dt = db.ExecuteDataTable(insertClunm)
db.CommitTransaction()
Catch ex As Exception
db.RollbackTransaction()
db.Close()
Return False
End Try
db.Close()
End Using
Return True
End Function
Public Shared Function API_AllocationBarCode(hotelID As String roomtypeid As String params As List(Of Dictionary(Of String, Object))) As Boolean
Dim jsonString As String = String.Empty
Dim dic As New Dictionary(Of String Object
'获取秒级时间戳
Dim timeStamp As String = (DateTime.Now - New DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds.ToString("0")
Dim md5key As String = GetStringMd5("BLV@blv-oa.com")
Dim filepath As String = $"hotel_code={hotelID}&time={timeStamp}&key={md5key.ToLower}"
Dim md5 As String = GetStringMd5(filepath)
dic.Add("hotel_code", hotelID)
dic.Add("room_type_code", roomtypeid)
dic.Add("time", timeStamp)
dic.Add("sign", md5.ToLower)
dic.Add("params", params)
Dim jsonDatastr As String = JsonConvert.SerializeObject(dic)
Try
jsonString = HttpMothod.PostData2("https://f-xcx.blv-oa.com/rcu/v1/circuit/power", jsonDatastr)
Catch ex As Exception
MsgBox($"网络API调用错误请联系管理员。")
Return Nothing
End Try
'Console.WriteLine(jsonString)
If jsonString = Nothing Then
Return False
End If
Dim login As Dictionary(Of String String)
Try
login = JsonConvert.DeserializeObject(Of Dictionary(Of String String))(jsonString)
If Not IsNothing(login) AndAlso login.ContainsKey("code") Then
If login.Item("code").Equals("200") Then
Return True
Else
Return False
End If
Return False
Else
Return False
End If
Catch ex As Exception
'MsgBox($"Json数据转换错误请联系管理员。详情 Json data to AllocationAPI error")
Return False
End Try
End Function
Public Shared Function PostData(ByVal url As String, ByVal data As String) As String
ServicePointManager.Expect100Continue = False
Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
'//Post请求方式
request.Method = "POST"
'内容类型
request.ContentType = "application/x-www-form-urlencoded"
'将URL编码后的字符串转化为字节
Dim encoding As New UTF8Encoding()
Dim bys As Byte() = encoding.GetBytes(data)
'设置请求的 ContentLength
request.ContentLength = bys.Length
'获得请 求流
Dim newStream As Stream = request.GetRequestStream()
newStream.Write(bys, 0, bys.Length)
newStream.Close()
'获得响应流
Dim sr As StreamReader = New StreamReader(request.GetResponse().GetResponseStream)
Return sr.ReadToEnd
End Function
Private Sub PowerInit_CellChange(Sender As Object, e As FlexCell.Grid.CellChangeEventArgs) Handles PowerInit.CellChange
If e.Row = 0 Then Return
If e.Col = 6 Or e.Col = 7 Then
Dim fnumber As Double
If Double.TryParse(PowerInit.Cell(e.Row, e.Col).Text.Trim, fnumber) Then
If (fnumber > 100 Or fnumber < 0) AndAlso e.Col = 7 Then
MsgBox($"第{PowerInit.Cell(e.Row, 0).Text}行,【节能比例(%)】 数据异常!数值范围为 1到100")
Return
End If
Else
MsgBox($"第{PowerInit.Cell(e.Row, 0).Text} 行 【公路】或节能比例 数据格式不正确,请输入数字!")
Return
End If
End If
End Sub
Private Sub PowerInit_ComboDropDown(Sender As Object, e As FlexCell.Grid.ComboDropDownEventArgs) Handles PowerInit.ComboDropDown
If e.Row = 0 Then Return
If e.Col = 7 Then
PowerInit.ComboBox(e.Col).Items.Clear()
'设置选项为 1到100
For i As Integer = 1 To 100
PowerInit.ComboBox(e.Col).Items.Add(i.ToString())
Next
End If
End Sub
Private Sub RatioInit_CellChange(Sender As Object, e As FlexCell.Grid.CellChangeEventArgs) Handles RatioInit.CellChange
If e.Row = 0 Then Return
If e.Col = 9 Then
Dim fnumber As Double
If Double.TryParse(RatioInit.Cell(e.Row, e.Col).Text.Trim, fnumber) Then
If fnumber >= 1 And fnumber <= 15 Then
Else
MsgBox($"第{RatioInit.Cell(e.Row, 0).Text}行,【空调节能温差】 数据异常,【空调节能温差】数值范围为 1到15")
End If
Else
MsgBox($"第{RatioInit.Cell(e.Row, 0).Text}行,【空调节能温差】 数据异常!")
Return
End If
End If
End Sub
Private Sub RatioInit_ComboDropDown(Sender As Object, e As FlexCell.Grid.ComboDropDownEventArgs) Handles RatioInit.ComboDropDown
If e.Row = 0 Then Return
If e.Col = 9 Then
RatioInit.ComboBox(e.Col).Items.Clear()
'设置选项为 1到100
For i As Integer = 1 To 15
RatioInit.ComboBox(e.Col).Items.Add(i.ToString())
Next
End If
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
'当勾选时CheckBox1时将PowerInit表和RatioInit表中各行启用列设置为1
If CheckBox1.Checked Then
For i As Integer = 1 To PowerInit.Rows - 1
PowerInit.Cell(i, 1).Text = "1"
Next
For i As Integer = 1 To RatioInit.Rows - 1
RatioInit.Cell(i, 1).Text = "1"
Next
Else
'当取消勾选时CheckBox1时将PowerInit表和RatioInit表中各行启用列设置为0
For i As Integer = 1 To PowerInit.Rows - 1
PowerInit.Cell(i, 1).Text = "0"
Next
For i As Integer = 1 To RatioInit.Rows - 1
RatioInit.Cell(i, 1).Text = "0"
Next
End If
End Sub
End Class