添加项目文件。

This commit is contained in:
jl
2023-01-13 15:30:20 +08:00
parent 40ed216831
commit bf208bde56
834 changed files with 470902 additions and 0 deletions

190
Epost.DAL/ControlDAL.cs Normal file
View File

@ -0,0 +1,190 @@
using Epost.Common;
using Epost.Model;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
namespace Epost.DAL
{
public class ControlDAL
{
//DataBaseOpration.OprationSqlDAL db = DB_DLL.GetInstance();//【sql】
DataBaseOpration.OprationSqlDAL db = DB_DLL.GetInstance();//【mysql】
XmlHelper xml = new XmlHelper();
string path = System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["ControlXML"]);
string nodename = "EpostController";
#region
public bool CreateControl(ControlModel model)
{
XElement xe = XElement.Load(path);
IEnumerable<XAttribute> elements = from ele in xe.Elements("EpostController").Attributes().OrderByDescending(e => (string)e.Value)
select ele;
int maxNum = 0;
if (elements.Any())
{
maxNum = Convert.ToInt32(elements.First().Value == null ? 0 : Convert.ToInt32(elements.First().Value));
}
XElement controlXE = new XElement(nodename, new XAttribute("name", maxNum + 1),
new XElement("ControlName", model.ControlName),
new XElement("ControlIP", model.ControlIP)
// new XElement("ControlBus", model.ControlBus)
);
xe.Add(controlXE);
xe.Save(path);
return true;
}
#endregion
#region
public bool UpdateControl(ControlModel Model)
{
XElement xe = XElement.Load(path);
IEnumerable<XElement> elements = from ele in xe.Elements(nodename).Where(p => p.Attribute("name").Value.Equals(Model.ControlID))
select ele;
foreach (var ele in elements)
{
if (ele.FirstAttribute.Value == Model.ControlID)
{
ele.Element("ControlIP").SetValue(Model.ControlIP);
ele.Element("ControlName").SetValue(Model.ControlName);
// ele.Element("ControlBus").SetValue(Model.ControlBus);
xe.Save(path);
break;
}
}
return true;
}
#endregion
#region
public bool DeleteControl(ControlModel Model)
{
XElement xe = XElement.Load(path);
IEnumerable<XElement> elements = from ele in xe.Elements(nodename).Where(p => p.Attribute("name").Value.Equals(Model.ControlID))
select ele;
foreach (var ele in elements)
{
if (ele.FirstAttribute.Value == Model.ControlID)
{
ele.Remove();
xe.Save(path);
break;
}
}
return true;
}
#endregion
#region
public List<ControlModel> ControlList()
{
XElement xe = XElement.Load(path);
IEnumerable<XElement> elements = from ele in xe.Elements(nodename)
select ele;
List<ControlModel> list = new List<ControlModel>();
foreach (var ele in elements)
{
ControlModel model = new ControlModel();
model.ControlName = ele.Element("ControlName").Value;
// model.ControlBus = ele.Element("ControlBus").Value;
model.ControlIP = ele.Element("ControlIP").Value;
model.ControlID = ele.FirstAttribute.Value;
list.Add(model);
}
return list;
}
#endregion
#region ControlID查询相关信息
public ControlModel GetControlByControlID(string ControlID)
{
XElement xe = XElement.Load(path);
IEnumerable<XElement> elements = from ele in xe.Elements(nodename).Where(p => p.Attribute("name").Value.Equals(ControlID))
select ele;
ControlModel model = new ControlModel();
foreach (var ele in elements)
{
if (ele.FirstAttribute.Value == ControlID)
{
model.ControlName = ele.Element("ControlName").Value;
// model.ControlBus = ele.Element("ControlBus").Value;
model.ControlIP = ele.Element("ControlIP").Value;
break;
}
}
return model;
}
#endregion
#region
public bool OpenSql()
{
string sql = "select count(*) from Addressstorage";
DataTable dt = db.GetsqlForDT(sql);
if (dt.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
#endregion
#region
public DataTable Xgate()
{
string sql = "select ID,ControlIP from Controller";
DataTable dt = db.GetsqlForDT(sql);
return dt;
}
#endregion
#region id
public int Xgateid(string gateip)
{
string sql = "select ID from Controller where ControlIP='{0}'";
sql = string.Format(sql, gateip);
DataTable dt = db.GetsqlForDT(sql);
int gateid = Convert.ToInt32(dt.Rows[0]["ID"]);
return gateid;
}
#endregion
#region
public DataTable Xgate_Address(int gateid)
{
//string sql = "select distinct cast(address as int) as address,bkaddress,type,addresstype,state,block,area,way,shelfid,layer,SUBSTRING ( location,1,4) as Area_area from Addressstorage where ControlID={0} order by address";//【sql】
string sql = "select distinct convert(address,signed) as address,bkaddress,type,addresstype,state,block,area,way,shelfid,layer,location as Area_area from Addressstorage where ControlID={0} group by address order by address";//【sql】
sql = string.Format(sql, gateid);
DataTable dt = db.GetsqlForDT(sql);
return dt;
}
#endregion
}
}