using Commom.Utility;
|
using Common;
|
using Model;
|
using Model.WcsModel;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Text;
|
|
namespace BLL.DAL
|
{
|
public class DAL_PlcPos
|
{
|
/// <summary>
|
/// 根据ID获取流程字信息
|
/// </summary>
|
/// <returns></returns>
|
public WCSPlcPos GetPlcPos(string Id)
|
{
|
try
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
strSql.Append($"select * from WCSPlcPos where IsDel = 0 and Id = '{Id}' order by createTime;");
|
|
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
|
var model = ModelConvertHelper<WCSPlcPos>.ReaderToModel(dt);
|
return model;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
/// <summary>
|
/// 获取工位对应的流程字数据集合
|
/// </summary>
|
/// <param name="Json">查询条件</param>
|
/// <param name="pageInfo">分页信息</param>
|
/// <returns></returns>
|
public IList<WCSPlcPos> GetPlcPosList(AjaxPlcPosList Json, ref PageInfo pageInfo)
|
{
|
try
|
{
|
IList<WCSPlcPos> list = new List<WCSPlcPos>();
|
StringBuilder sqlString = new StringBuilder();
|
List<SqlParam> para = new List<SqlParam>();
|
|
sqlString.Append("select tb1.Id,tb1.PlcInfoId,tb1.StationNum,tb1.PlcPos, ");
|
sqlString.Append("tb1.PosType,tb1.LedIP,tb1.Name,tb1.CreateUser,tb2.RealName as CreateUserName,tb1.CreateTime ");
|
sqlString.Append("from WCSPlcPos as tb1 left join UserInfo as tb2 on tb1.CreateUser = tb2.ID ");
|
sqlString.Append("where tb1.IsDel = 0 ");
|
if (!string.IsNullOrWhiteSpace(Json.StationNum))
|
{
|
sqlString.Append($"and tb1.StationNum like '%{Json.StationNum}%' ");
|
}
|
|
if (!string.IsNullOrWhiteSpace(Json.PlcPos))
|
{
|
sqlString.Append($"and tb1.PlcPos like '%{Json.PlcPos}%' ");
|
}
|
|
DataTable dt = DataFactory.SqlDataBase().GetPageList(sqlString.ToString(), null, "CreateTime", "DESC", ref pageInfo);
|
|
list = ModelConvertHelper<WCSPlcPos>.DataTableToModel(dt);
|
|
return list;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
/// <summary>
|
/// 删除工位对应的流程字信息
|
/// </summary>
|
/// <param name="ID">ID集合</param>
|
/// <returns></returns>
|
public bool DeletePlcPos(string[] ID)
|
{
|
bool result = false;
|
try
|
{
|
int dt = DataFactory.SqlDataBase().IsExist("WCSPlcPos", "ID", ID);
|
if (dt >= ID.Length)
|
{
|
int i = 0;
|
while (i < ID.Length)
|
{
|
StringBuilder sql = new StringBuilder();
|
sql.Append("update WCSPlcPos set IsDel=1 where Id='" + ID[i] + "'");
|
int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
|
if (_ret >= ID.Length) result = true;
|
i++;
|
}
|
|
}
|
return result;
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
|
/// <summary>
|
/// 新增编辑流程字信息
|
/// </summary>
|
/// <param name="model">流程字信息</param>
|
/// <returns>true:保存成功 false:保存失败</returns>
|
public bool AddPlcPos(AjaxPlcPos model)
|
{
|
bool bl = false;
|
try
|
{
|
int rowCount = 0;
|
Hashtable ht = new Hashtable();
|
if (model.Operation == "Add")
|
{
|
string[] StationNumlist = model.StationNum.Split('-');
|
// add
|
ht["PlcInfoId"] = model.PlcInfoId;
|
ht["StationNum"] = StationNumlist[0].AddQuotes();
|
ht["PlcPos"] = model.PlcPos.AddQuotes();
|
ht["PosType"] = model.PosType.AddQuotes();
|
ht["LedIP"] = model.LedIP.AddQuotes();
|
ht["Name"] = model.Name.AddQuotes();
|
ht["CreateUser"] = model.CreateUser;
|
|
rowCount = DataFactory.SqlDataBase().InsertByHashtableNullParam("WCSPlcPos", ht);
|
}
|
else
|
{
|
// Edit
|
string[] StationNumlist = model.StationNum.Split('-');
|
ht["PlcInfoId"] = model.PlcInfoId;
|
ht["StationNum"] = StationNumlist[0].AddQuotes();
|
ht["PlcPos"] = model.PlcPos.AddQuotes();
|
ht["PosType"] = model.PosType.AddQuotes();
|
ht["LedIP"] = model.LedIP.AddQuotes();
|
ht["Name"] = model.Name.AddQuotes();
|
|
rowCount = DataFactory.SqlDataBase().UpdateByHashtable("WCSPlcPos", "id", model.Id.ToString(), ht);
|
}
|
|
if (rowCount == 1)
|
{
|
bl = true;
|
}
|
}
|
catch (Exception)
|
{
|
bl = false;
|
}
|
|
return bl;
|
}
|
|
|
/// <summary>
|
/// 获取工位下拉框
|
/// </summary>
|
/// <param name="PlcInfoId">工位ID</param>
|
/// <returns></returns>
|
public string GetPlcPosHtml(string PlcInfoId = "")
|
{
|
try
|
{
|
StringBuilder sb = new StringBuilder();
|
string resMenuTemplate = "<option value='{0}' {1}>{2}</option>";
|
sb.AppendFormat(resMenuTemplate, "", "", "选择");
|
|
StringBuilder sqlString = new StringBuilder();
|
sqlString.Append("select * from WCSPlcInfo where IsDel = 0 and Level ='2';");
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sqlString);
|
|
foreach (DataRow row in dt.Rows)
|
{
|
sb.AppendFormat(resMenuTemplate, row["Id"].ToString(), row["Id"].ToString() == PlcInfoId ? "selected='selected'" :
|
string.Empty, row["StationNum"].ToString()+"-"+ row["Text"].ToString());
|
}
|
|
return sb.ToString();
|
}
|
catch
|
{
|
return "";
|
}
|
}
|
|
|
/// <summary>
|
/// 验证是否存在重复项
|
/// </summary>
|
/// <param name="sqlWhere">查询条件</param>
|
/// <returns></returns>
|
public bool IsExist(string sqlWhere)
|
{
|
return DataFactory.SqlDataBase().IsExist("WCSPlcPos", sqlWhere);
|
}
|
}
|
}
|