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_Led { /// /// 根据ID获取Led信息 /// /// public WCSLed GetLed(string Id) { try { StringBuilder strSql = new StringBuilder(); strSql.Append($"select * from WCSLed where IsDel = 0 and Id = '{Id}' order by createTime;"); IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql); var model = ModelConvertHelper.ReaderToModel(dt); return model; } catch { throw new NotImplementedException(); } } /// /// 获取所有Led设置 /// /// 查询条件 /// 分页信息 /// public IList GetLedList(AjaxLedList Json, ref PageInfo pageInfo) { try { IList list = new List(); StringBuilder sqlString = new StringBuilder(); List para = new List(); sqlString.Append("select tb1.Id,tb1.Ip,tb1.Name, "); sqlString.Append("tb1.CreateUser,tb2.RealName as CreateUserName,tb1.CreateTime "); sqlString.Append("from WCSLed as tb1 left join UserInfo as tb2 on tb1.CreateUser = tb2.ID "); sqlString.Append("where tb1.IsDel = 0 "); if (!string.IsNullOrWhiteSpace(Json.Ip)) { sqlString.Append($"and tb1.Ip like '%{Json.Ip}%' "); } if (!string.IsNullOrWhiteSpace(Json.Name)) { sqlString.Append($"and tb1.Name like '%{Json.Name}%' "); } DataTable dt = DataFactory.SqlDataBase().GetPageList(sqlString.ToString(), null, "CreateTime", "DESC", ref pageInfo); list = ModelConvertHelper.DataTableToModel(dt); return list; } catch { throw new NotImplementedException(); } } /// /// 删除LedIp /// /// ID集合 /// public bool DeleteLed(string[] ID) { bool result = false; try { int dt = DataFactory.SqlDataBase().IsExist("WCSLed", "ID", ID); if (dt >= ID.Length) { int i = 0; while (i < ID.Length) { StringBuilder sql = new StringBuilder(); sql.Append("update WCSLed 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; } } /// /// 新增编辑LEd地址信息 /// /// Led地址名称数据集 /// true:保存成功 false:保存失败 public bool AddLed(AjaxLeds model) { bool bl = false; try { int rowCount = 0; Hashtable ht = new Hashtable(); if (model.Operation == "Add") { // add ht["Ip"] = model.Ip.AddQuotes(); ht["Name"] = model.Name.AddQuotes(); ht["CreateUser"] = model.CreateUser; rowCount = DataFactory.SqlDataBase().InsertByHashtableNullParam("WCSLed", ht); } else { // Edit ht["Ip"] = model.Ip.AddQuotes(); ht["Name"] = model.Name.AddQuotes(); rowCount = DataFactory.SqlDataBase().UpdateByHashtable("WCSLed", "id", model.Id.ToString(), ht); } if (rowCount == 1) { bl = true; } } catch (Exception) { bl = false; } return bl; } /// /// 验证是否存在重复项 /// /// 查询条件 /// public bool IsExist(string sqlWhere) { return DataFactory.SqlDataBase().IsExist("WCSLed", sqlWhere); } } }