using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Common;
|
using Model;
|
using Model.WcsModel;
|
|
namespace BLL.DAL
|
{
|
public class DAL_IpPlcInfo
|
{
|
#region WCSIP
|
|
/// <summary>
|
/// 获取WCSIP信息
|
/// </summary>
|
/// <param name="json"></param>
|
/// <param name="pageInfo"></param>
|
/// <returns></returns>
|
public IList<WCSIP> GetList(AjaxGetIpList json, ref PageInfo pageInfo)
|
{
|
try
|
{
|
StringBuilder strSql = new StringBuilder();
|
List<SqlParam> para = new List<SqlParam>();
|
|
// 0 未下发 1 已下发 2 ? 3已完成
|
strSql.Append("select Id,IP, Type,WareHouseNo,Text,IsDel,CreateTime,CreateUser from WCSIP where IsDel = '0'");
|
|
|
if (!string.IsNullOrWhiteSpace(json.Ip))
|
{
|
strSql.Append(" and IP like '%" + json.Ip + "%' ");
|
}
|
if (!string.IsNullOrWhiteSpace(json.Type))
|
{
|
strSql.Append(" and Type = '" + json.Type + "' ");
|
}
|
|
SqlParam[] param = null;
|
if (para != null)
|
{
|
param = para.ToArray();
|
}
|
|
DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "Id", "asc", ref pageInfo);
|
return ModelConvertHelper<WCSIP>.DataTableToModel(dt);
|
}
|
catch(Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取WCSIP单条信息
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public WCSIP GetOneIp(string id)
|
{
|
try
|
{
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append($"select Id,IP, Type,WareHouseNo,Text,IsDel,CreateTime,CreateUser from WCSIP where Id = {id} ");
|
|
var dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
|
return ModelConvertHelper<WCSIP>.ReaderToModel(dt);
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取设备类型
|
/// </summary>
|
/// <param name="type"></param>
|
/// <returns></returns>
|
public string GetDicTypeHtml(string type = "")
|
{
|
try
|
{
|
StringBuilder sb = new StringBuilder();
|
string resMenuTemplate = "<option value='{0}' {1}>{2}</option>";
|
sb.AppendFormat(resMenuTemplate, "", "", "选择");
|
|
var list = new List<DicOption>();
|
list.Add(new DicOption()
|
{
|
Val="0",
|
Text = "跺机"
|
});
|
list.Add(new DicOption()
|
{
|
Val = "1",
|
Text = "托盘输送线"
|
});
|
list.Add(new DicOption()
|
{
|
Val = "2",
|
Text = "件箱输送线"
|
});
|
|
foreach (var row in list)
|
{
|
sb.AppendFormat(resMenuTemplate, row.Val, row.Val == type ? "selected='selected'" :
|
string.Empty, row.Text);
|
}
|
|
return sb.ToString();
|
}
|
catch
|
{
|
return "";
|
}
|
}
|
/// <summary>
|
/// 添加IP信息
|
/// </summary>
|
/// <param name="models"></param>
|
/// <returns></returns>
|
public bool IpAdd(AjasWCSIP models)
|
{
|
bool result = false;
|
try
|
{
|
StringBuilder sqlString = new StringBuilder();
|
// 验证任务是否已存在
|
//sqlString.Append($"select count(Id) from WCSIP where PalletNo = '{models.PalletNo}';");
|
//DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sqlString);
|
//if (dt.Rows[0][0].ToString() != "0")
|
//{
|
// throw new Exception("托盘号:" + models.PalletNo + ";已存在!");
|
//}
|
|
// 新增任务
|
sqlString.Clear();
|
var str = $"insert into WCSIP (IP ,Type ,WareHouseNo ,Text ,IsDel ,CreateTime ,CreateUser) VALUES('{models.IP}','{models.Type}','{models.WareHouseNo}','{models.Text}','0',GETDATE(),'{models.CreateUser}' ); ";
|
|
sqlString.Append(str);
|
|
var num = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
|
|
if (num == 1) result = true;
|
|
return result;
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
/// <summary>
|
/// 修改IP信息
|
/// </summary>
|
/// <param name="models"></param>
|
/// <returns></returns>
|
public bool IpUpdate(AjasWCSIP models)
|
{
|
bool result = false;
|
try
|
{
|
StringBuilder sqlString = new StringBuilder();
|
// 验证任务是否已存在
|
//sqlString.Append($"select count(Id) from WCSIP where PalletNo = '{models.PalletNo}';");
|
//DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sqlString);
|
//if (dt.Rows[0][0].ToString() != "0")
|
//{
|
// throw new Exception("托盘号:" + models.PalletNo + ";已存在!");
|
//}
|
|
// 新增任务
|
sqlString.Clear();
|
var str = $"update WCSIP set IP = '{models.IP}',Type = '{models.Type}',WareHouseNo = '{models.WareHouseNo}', Text = '{models.Text}' where Id = {models.Id} ; ";
|
|
sqlString.Append(str);
|
|
var num = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
|
|
if (num == 1) result = true;
|
|
return result;
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
/// <summary>
|
/// 删除IP信息
|
/// </summary>
|
/// <param name="Id"></param>
|
/// <returns></returns>
|
public bool IpDel(string[] Id)
|
{
|
bool result = false;
|
try
|
{
|
int dt = DataFactory.SqlDataBase().IsExist("WCSIP", "Id", Id);
|
if (dt >= Id.Length)
|
{
|
int i = 0;
|
while (i < Id.Length)
|
{
|
|
StringBuilder sql = new StringBuilder();
|
// 验证任务是否已存在
|
sql.Append($"select count(Id) from WCSPlcInfo where PlcIP = {Id[i]};");
|
DataTable dt2 = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
|
if (dt2.Rows[0][0].ToString() != "0")
|
{
|
throw new Exception($"当前IP下存有工位设备信息,请先移除!");
|
}
|
// 获取当前IP信息
|
sql.Clear();
|
sql.Append($"select * from WCSIP where Id = '{Id[i]}';");
|
DataTable monitorDt = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
|
if (monitorDt != null && monitorDt.Rows.Count > 0)
|
{
|
if (monitorDt.Rows[0]["IsDel"].ToString() == "1")
|
{
|
i++;
|
continue;
|
}
|
sql.Clear();
|
// 修改任务状态
|
sql.Append($"update WCSIP set IsDel = '1' where Id = {Id[i]} ;");
|
int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
|
if (_ret >= 1) result = true;
|
}
|
i++;
|
}
|
|
}
|
return result;
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
#endregion
|
|
|
#region WCSPlcInfo
|
|
/// <summary>
|
/// 获取WCSPlcInfo信息
|
/// </summary>
|
/// <param name="json"></param>
|
/// <param name="pageInfo"></param>
|
/// <returns></returns>
|
public IList<WCSPlcInfo> GetPlcInfoList(AjaxGetIpList json, ref PageInfo pageInfo)
|
{
|
try
|
{
|
StringBuilder strSql = new StringBuilder();
|
List<SqlParam> para = new List<SqlParam>();
|
|
// 0 未下发 1 已下发 2 ? 3已完成
|
strSql.Append("select Id ,PlcIP ,LedIP ,DbNumber ,Level ,StationNum ,PlcPos ,WcsPos ,PosType ,Text ,IsDel ,CreateTime ,CreateUser from WCSPlcInfo where IsDel = '0' ");
|
|
if (!string.IsNullOrWhiteSpace(json.Ip))
|
{
|
strSql.Append(" and PlcIP = '" + json.Ip + "' ");
|
}
|
|
SqlParam[] param = null;
|
if (para != null)
|
{
|
param = para.ToArray();
|
}
|
|
DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "Id", "asc", ref pageInfo);
|
return ModelConvertHelper<WCSPlcInfo>.DataTableToModel(dt);
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取 WCSPlcInfo 单条信息
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public WCSPlcInfo GetOnePlc(string id)
|
{
|
try
|
{
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append($"select * from WCSPlcInfo where Id = {id} ");
|
|
var dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
|
return ModelConvertHelper<WCSPlcInfo>.ReaderToModel(dt);
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取设备级别
|
/// </summary>
|
/// <param name="type"></param>
|
/// <returns></returns>
|
public string GetDicLevelHtml(string type = "")
|
{
|
try
|
{
|
StringBuilder sb = new StringBuilder();
|
string resMenuTemplate = "<option value='{0}' {1}>{2}</option>";
|
sb.AppendFormat(resMenuTemplate, "", "", "选择");
|
|
var list = new List<DicOption>();
|
list.Add(new DicOption()
|
{
|
Val = "1",
|
Text = "DB区域级别"
|
});
|
list.Add(new DicOption()
|
{
|
Val = "2",
|
Text = "工位级别"
|
});
|
|
foreach (var row in list)
|
{
|
sb.AppendFormat(resMenuTemplate, row.Val, row.Val == type ? "selected='selected'" :
|
string.Empty, row.Text);
|
}
|
|
return sb.ToString();
|
}
|
catch
|
{
|
return "";
|
}
|
}
|
/// <summary>
|
/// 获取设备级别
|
/// </summary>
|
/// <param name="code"></param>
|
/// <returns></returns>
|
public string GetDicPlcIpHtml(string code = "")
|
{
|
try
|
{
|
StringBuilder sb = new StringBuilder();
|
string resMenuTemplate = "<option value='{0}' {1}>{2}</option>";
|
sb.AppendFormat(resMenuTemplate, "", "", "选择");
|
|
StringBuilder sql = new StringBuilder();
|
sql.Append("select * from WCSIP where IsDel = 0;");
|
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
|
|
foreach (DataRow row in dt.Rows)
|
{
|
sb.AppendFormat(resMenuTemplate, row["Id"].ToString(), row["Id"].ToString() == code ? "selected='selected'" :
|
string.Empty, row["Text"].ToString());
|
}
|
|
return sb.ToString();
|
}
|
catch
|
{
|
return "";
|
}
|
}
|
|
/// <summary>
|
/// 添加PlcInfo信息
|
/// </summary>
|
/// <param name="models"></param>
|
/// <returns></returns>
|
public bool PlcAdd(AjasWCSPlcInfo models)
|
{
|
bool result = false;
|
try
|
{
|
StringBuilder sqlString = new StringBuilder();
|
// 验证任务是否已存在
|
//sqlString.Append($"select count(Id) from WCSIP where PalletNo = '{models.PalletNo}';");
|
//DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sqlString);
|
//if (dt.Rows[0][0].ToString() != "0")
|
//{
|
// throw new Exception("托盘号:" + models.PalletNo + ";已存在!");
|
//}
|
|
// 新增任务
|
sqlString.Clear();
|
var str = $"insert into WCSPlcInfo (PlcIP ,LedIP ,DbNumber ,Level,StationNum ,PlcPos ,WcsPos ,PosType ,Text ,IsDel ,CreateTime,CreateUser) VALUES('{models.PlcIP}','{models.LedIP}','{models.DbNumber}','{models.Level}','{models.StationNum}','{models.PlcPos}','{models.WcsPos}','{models.PosType}','{models.Text}','0',GETDATE(),'{models.CreateUser}' ); ";
|
|
sqlString.Append(str);
|
|
var num = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
|
|
if (num == 1) result = true;
|
|
return result;
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 修改IP信息
|
/// </summary>
|
/// <param name="models"></param>
|
/// <returns></returns>
|
public bool PlcUpdate(AjasWCSPlcInfo models)
|
{
|
bool result = false;
|
try
|
{
|
StringBuilder sqlString = new StringBuilder();
|
// 验证任务是否已存在
|
//sqlString.Append($"select count(Id) from WCSIP where PalletNo = '{models.PalletNo}';");
|
//DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sqlString);
|
//if (dt.Rows[0][0].ToString() != "0")
|
//{
|
// throw new Exception("托盘号:" + models.PalletNo + ";已存在!");
|
//}
|
|
// 新增任务
|
sqlString.Clear();
|
var str = $"update WCSPlcInfo set PlcIP = '{models.PlcIP}',LedIP = '{models.LedIP}',DbNumber ='{models.DbNumber}',Level = '{models.Level}',StationNum = '{models.StationNum}',PlcPos = '{models.PlcPos}',WcsPos = '{models.WcsPos}',PosType = '{models.PosType}',Text = '{models.Text}' where Id = {models.Id} ; ";
|
|
sqlString.Append(str);
|
|
var num = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
|
|
if (num == 1) result = true;
|
|
return result;
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 删除IP信息
|
/// </summary>
|
/// <param name="Id"></param>
|
/// <returns></returns>
|
public bool PlcDel(string[] Id)
|
{
|
bool result = false;
|
try
|
{
|
int dt = DataFactory.SqlDataBase().IsExist("WCSPlcInfo", "Id", Id);
|
if (dt >= Id.Length)
|
{
|
int i = 0;
|
while (i < Id.Length)
|
{
|
|
StringBuilder sql = new StringBuilder();
|
// 验证任务是否已存在
|
sql.Append($"select count(Id) from WCSPlcPos where PlcInfoId = {Id[i]};");
|
DataTable dt2 = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
|
if (dt2.Rows[0][0].ToString() != "0")
|
{
|
throw new Exception($"当前IP下存有流程字信息,请先移除!");
|
}
|
// 获取当前IP信息
|
sql.Clear();
|
sql.Append($"select * from WCSPlcInfo where Id = '{Id[i]}';");
|
DataTable monitorDt = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
|
if (monitorDt != null && monitorDt.Rows.Count > 0)
|
{
|
if (monitorDt.Rows[0]["IsDel"].ToString() == "1")
|
{
|
i++;
|
continue;
|
}
|
sql.Clear();
|
// 修改任务状态
|
sql.Append($"update WCSPlcInfo set IsDel = '1' where Id = {Id[i]} ;");
|
int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
|
if (_ret >= 1) result = true;
|
}
|
i++;
|
}
|
|
}
|
return result;
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
|
#endregion
|
|
|
}
|
|
public class DicOption
|
{
|
public string Val { get; set; }
|
|
public string Text { get; set; }
|
}
|
|
}
|