123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- 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);
- /// <summary>
- /// 释放对象资源
- /// </summary>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- /// <summary>
- /// 释放对象资源
- /// </summary>
- /// <param name="disposing"></param>
- 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 客户信息
- /// <summary>
- /// 获取客户信息
- /// </summary>
- /// <param name="customerId"></param>
- /// <param name="name"></param>
- /// <param name="code"></param>
- /// <param name="account"></param>
- /// <returns></returns>
- public CustomerInfo GetCustomerInfo(int customerId, string name, string code,string account)
- {
- CustomerInfo model = new CustomerInfo();
- try
- {
- model = db.Queryable<CustomerInfo>()
- .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;
- }
- /// <summary>
- /// 获取客户列表
- /// </summary>
- /// <param name="parm"></param>
- /// <param name="page"></param>
- /// <returns></returns>
- public List<CustomerInfo> GetCustomerList(BaseParm parm, ref int page)
- {
- List<CustomerInfo> list = new List<CustomerInfo>();
- try
- {
- list = db.Queryable<CustomerInfo>()
- .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;
- }
- /// <summary>
- /// 添加客户信息
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 编辑客户
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 修改客户密码
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool UpdateCustomerPassWord(CustomerInfo model)
- {
- bool result = false;
- try
- {
- model.UpdateTime = DateTime.Now;
- int row = db.Updateable<CustomerInfo>()
- .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;
- }
- /// <summary>
- /// 删除客户
- /// </summary>
- /// <param name="parm"></param>
- /// <returns></returns>
- public bool DeleteCustomer(BaseParm parm)
- {
- bool result = false;
- try
- {
- int row = db.Updateable<CustomerInfo>()
- .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
- }
- }
|