using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using IoTIntegrationPlatform.Common; using IoTIntegrationPlatform.Interface; using IoTIntegrationPlatform.Model.common; using IoTIntegrationPlatform.Model.Model; using SqlSugar; namespace IoTIntegrationPlatform.Services { public class SystemService : ISystemService { private ISqlSugarClient db { get; } public SystemService(ISqlSugarClient _db) { db = _db; } #region 类句柄操作 private IntPtr handle; private bool disposed = false; //关闭句柄 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Interoperability", "CA1401:PInvokesShouldNotBeVisible"), System.Runtime.InteropServices.DllImport("Kernel32")] public extern static Boolean CloseHandle(IntPtr handle); /// /// 释放对象资源 /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// 释放对象资源 /// /// protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (handle != IntPtr.Zero) { CloseHandle(handle); handle = IntPtr.Zero; } } disposed = true; } ~SystemService() { Dispose(false); } #endregion #region 客户信息 /// /// 获取客户信息 /// /// /// /// /// /// public CustomerInfo GetCustomerInfo(int customerId, string name, string code,string account) { CustomerInfo model = new CustomerInfo(); try { model = db.Queryable() .Where(it => it.IsValid == true) .WhereIF(customerId > 0, it => it.CustomerId == customerId) .WhereIF(!string.IsNullOrEmpty(name), it => it.ContactName.Equals(name)) .WhereIF(!string.IsNullOrEmpty(code), it => it.CustomerCode.Equals(code)) .WhereIF(!string.IsNullOrEmpty(account), it => it.CustomerAccount.Equals(account)) .First(); } catch (Exception ex) { Logging.Error(ex, ex.Message); } return model; } /// /// 获取客户列表 /// /// /// /// public List GetCustomerList(BaseParm parm, ref int page) { List list = new List(); try { list = db.Queryable() .Where(it => it.IsValid == true) .WhereIF(!string.IsNullOrEmpty(parm.Name), it => it.ContactName.Equals(parm.Name)) .WhereIF(!string.IsNullOrEmpty(parm.Code), it => it.CustomerCode == parm.Code) .ToPageList(parm.PageIndex, parm.PageSize, ref page); } catch (Exception ex) { Logging.Error(ex, ex.Message); } return list; } /// /// 添加客户信息 /// /// /// public bool AddCustomer(CustomerInfo model) { bool result = false; try { model.CreateTime = DateTime.Now; model.UpdateTime = DateTime.Now; model.IsValid = true; int row = db.Insertable(model).ExecuteCommand(); if (row > 0) { result = true; } } catch (Exception ex) { Logging.Error(ex, "添加客户"); } return result; } /// /// 编辑客户 /// /// /// public bool UpdatedCustomer(CustomerInfo model) { bool result = false; try { var row = db.Updateable(model).IgnoreColumns(it => new { it.CustomerId, it.CreateTime, it.IsValid }) .Where(it => it.CustomerId == model.CustomerId) .ExecuteCommand(); if (row > 0) { result = true; } } catch (Exception ex) { Logging.Error(ex, ex.Message); } return result; } /// /// 修改客户密码 /// /// /// public bool UpdateCustomerPassWord(CustomerInfo model) { bool result = false; try { model.UpdateTime = DateTime.Now; int row = db.Updateable() .SetColumns(it => new CustomerInfo { UpdateTime = DateTime.Now, CustomerPassword = model.CustomerPassword, SecretKey = model.SecretKey }) .Where(it => it.CustomerId == model.CustomerId) .ExecuteCommand(); if (row > 0) { result = true; } } catch (Exception ex) { Logging.Error(ex, ex.Message); } return result; } /// /// 删除客户 /// /// /// public bool DeleteCustomer(BaseParm parm) { bool result = false; try { int row = db.Updateable() .SetColumns(it => new CustomerInfo { UpdateTime = DateTime.Now, IsValid = false }) .Where(it => it.CustomerId == parm.Id) .ExecuteCommand(); if (row > 0) { result = true; } } catch (Exception ex) { Logging.Error(ex, ex.Message); } return result; } #endregion } }