无线照明系统开发过程说明(三)
为配合软件安装、管理和操作方便。软件系统适用性和通用性是必须的。将常规一些设置进行书面化保存,方便修改。所以在系统中建立两个XML类型文件。
第一个是ShuJuKLJ.xml,记录登录数据库服务器的用户名,密码等,更为重要在此设计要访问的计算机串口,这个串口随着不的计算机串口不同,可以设置。另外还记录日常的开灯时间和关灯时间并设置系统强制运行状态,防止白天被人为开灯能够强制进行关灯操作,设置此状态目的还考虑可能是检修灯时的处理状态。其内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<ShuJuKCS>
<FuWuQMC>wangli</FuWuQMC>
<ShuJuKMC>ZhaoMing</ShuJuKMC>
<YongHuID>sa</YongHuID>
<YongHuKL>sa</YongHuKL>
<CommPort>COM1</CommPort>
<OpenLedTime>17:30</OpenLedTime>
<CloseLedTime>06:30</CloseLedTime>
<RunState>0</RunState>
</ShuJuKCS>
另一个是ledPoint.xml 文件,主要是记录灯的名称(或地址)对应在显示器上的坐标,因为每一个灯的位置是可调的,所以对应的坐标是无法固定的,也是为以后适用灯塔或移动灯塔的方便操作。原来设计LEDNAME=灯的名称,后来在实际中感觉,这样不是很方便,遂改为对应灯的地址。
<?xml version="1.0" encoding="utf-8" ?>
<root>
<Led LedName="1" Xpoint="137" Ypoint="121" />
<Led LedName="2" Xpoint="334" Ypoint="120" />
<Led LedName="3" Xpoint="230" Ypoint="120" />
<Led LedName="4" Xpoint="139" Ypoint="274" />
<Led LedName="5" Xpoint="227" Ypoint="272" />
<Led LedName="6" Xpoint="322" Ypoint="274" />
<Led LedName="7" Xpoint="123" Ypoint="441" />
<Led LedName="8" Xpoint="228" Ypoint="441" />
<Led LedName="9" Xpoint="324" Ypoint="440" />
<Led LedName="10" Xpoint="186" Ypoint="618" />
<Led LedName="11" Xpoint="308" Ypoint="616" />
<Led LedName="12" Xpoint="498" Ypoint="119" />
<Led LedName="13" Xpoint="605" Ypoint="117" />
<Led LedName="14" Xpoint="499" Ypoint="274" />
<Led LedName="15" Xpoint="601" Ypoint="272" />
<Led LedName="16" Xpoint="487" Ypoint="436" />
<Led LedName="17" Xpoint="597" Ypoint="436" />
<Led LedName="18" Xpoint="492" Ypoint="622" />
<Led LedName="19" Xpoint="608" Ypoint="621" />
<Led LedName="20" Xpoint="405" Ypoint="751" />
<Led LedName="21" Xpoint="621" Ypoint="763" />
<Led LedName="22" Xpoint="791" Ypoint="114" />
<Led LedName="23" Xpoint="924" Ypoint="190" />
<Led LedName="24" Xpoint="828" Ypoint="295" />
<Led LedName="25" Xpoint="784" Ypoint="477" />
<Led LedName="26" Xpoint="989" Ypoint="479" />
<Led LedName="27" Xpoint="784" Ypoint="620" />
<Led LedName="28" Xpoint="1000" Ypoint="626" />
<Led LedName="29" Xpoint="779" Ypoint="775" />
<Led LedName="30" Xpoint="1015" Ypoint="762" />
<Led LedName="31" Xpoint="877" Ypoint="864" />
<Led LedName="32" Xpoint="843" Ypoint="34" />
<Led LedName="33" Xpoint="552" Ypoint="36" />
<Led LedName="34" Xpoint="229" Ypoint="36" />
</root>
上述两个文件读取方法,第一个是获取系统配置信息的方法。
''' <summary>
''' 建立数据库的连接
''' </summary>
''' <returns>Boolean</returns>
''' <remarks></remarks>
Public Shared Function JianLiSJK() As Boolean
Dim strFuWuQMC As String
Dim strShuJuKMC As String
Dim strYongHuID As String
Dim strYongHuKL As String
Dim strcn As String
' Dim LuJing As System.IO.Path
'返回系统连接
XiTongLJ = IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location)
JianLiSJK = False
Dim dsLianJieCS As New DataSet("ShuJuKLJCS")
If DuQuXML(XiTongLJ & "\ShuJuKLJ.xml", dsLianJieCS) = False Then
Exit Function
End If
'/从XML文件中读取数据库连接参数到Dataset中
If dsLianJieCS.Tables(0).Rows.Count > 0 Then
With dsLianJieCS.Tables(0).Rows(0)
strFuWuQMC = .Item("FuWuQMC").ToString
strShuJuKMC = .Item("ShuJuKMC").ToString
strYongHuID = .Item("YongHuID").ToString
strYongHuKL = .Item("YongHuKL").ToString
XTComm = .Item("CommPort").ToString
XTOpenime = .Item("OpenLedTime").ToString
XTCloseTime = .Item("CloseLedTime").ToString
XTSelect = .Item("RunState").ToString
End With
strcn = "Data Source=" & strFuWuQMC & _
";Initial Catalog=" & strShuJuKMC & _
";USER ID=" & strYongHuID & _
";password=" & strYongHuKL & ";"
Else
strcn = 数据库连接字串_CUI
End If
If ShuJuKFW.ChuangJianLJ(strcn) = True Then
JianLiSJK = True
Else
JianLiSJK = False
End If
End Function
其中 XiTongLJ = IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location)
是利用反射的方法来获取系统运行的目录。
第二,获得每一个灯坐标信息的方法
Public Function FindXml(ByVal pLedName As String) As IEnumerable(Of Mpoint)
'加载指定的xml文件
Dim xdoc As XDocument = XDocument.Load(XmlFile)
'查询指定姓名的元素
Dim name As String = pLedName
Dim pLed As IEnumerable(Of Mpoint)
'没有输入姓名时,显示整个XML文档的元素
If name = "" Then
pLed = From p In xdoc.Root.Elements("Led") _
Select New Mpoint With { _
.LeDName = p.Attribute("LedName").Value, _
.X_Point = p.Attribute("Xpoint").Value, _
.Y_Point = p.Attribute("Ypoint").Value}
Else
pLed = From p In xdoc.Root.Elements("Led") _
Where p.Attribute("LedName").Value = name _
Select New Mpoint With { _
.LeDName = p.Attribute("LedName").Value, _
.X_Point = p.Attribute("Xpoint").Value, _
.Y_Point = p.Attribute("Ypoint").Value}
End If
Return pLed
End Function
以上是在系统初始化时,在加载的内容和方法。