using System; using System.Collections.Generic; using System.Linq; using System.Text; using CY.IDAL; using System.Data.SqlClient; using System.Data; using CY.Model; using System.Transactions; namespace CY.SQLDAL { //软件销售记录 public class Soft_SellRecordDAL : ISoft_SellRecordDAL { private Database _dataBase = null; public Soft_SellRecordDAL() { _dataBase = new Database(); } public Soft_SellRecordDAL(Database dataBase) { _dataBase = dataBase; } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.Soft_SellRecord trueModel = model as Model.Soft_SellRecord; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@ClientId", trueModel.ClientId) , new SqlParameter("@ClientName", trueModel.ClientName) , new SqlParameter("@AccountManagerId", trueModel.AccountManagerId) , new SqlParameter("@BusinessManagerId", trueModel.BusinessManagerId) , new SqlParameter("@SoftId", trueModel.SoftId) , new SqlParameter("@SoftName", trueModel.SoftName) , new SqlParameter("@SoftQuantity", trueModel.SoftQuantity) , new SqlParameter("@SoftUnitprice", trueModel.SoftUnitprice) , new SqlParameter("@OrderMoney", trueModel.OrderMoney) , new SqlParameter("@OrderReceiveMoney", trueModel.OrderReceiveMoney) , new SqlParameter("@OrderStatus", trueModel.OrderStatus) , new SqlParameter("@OrderNum", trueModel.OrderNum) , new SqlParameter("@CreatTime", trueModel.CreatTime) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Operator", trueModel.Operator) , new SqlParameter("@VisitStatus", trueModel.VisitStatus) , new SqlParameter("@VisitSoftScore", trueModel.VisitSoftScore) , new SqlParameter("@VisitSoftServers", trueModel.VisitSoftServers) , new SqlParameter("@VisitReason", trueModel.VisitReason) , new SqlParameter("@VisitProposal", trueModel.VisitProposal) , new SqlParameter("@VisitPeople", trueModel.VisitPeople) , new SqlParameter("@VisitTime", trueModel.VisitTime) , new SqlParameter("@DegreeImportanId", trueModel.DegreeImportanId) , new SqlParameter("@Mobile", trueModel.Mobile) , new SqlParameter("@QQ", trueModel.QQ) , new SqlParameter("@OrderRemark", trueModel.OrderRemark) }; try { _dataBase.Query("sp_Soft_SellRecord_Insert", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.Soft_SellRecord trueModel = model as Model.Soft_SellRecord; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid", trueModel.Keyid) , new SqlParameter("@ClientId", trueModel.ClientId) , new SqlParameter("@ClientName", trueModel.ClientName) , new SqlParameter("@AccountManagerId", trueModel.AccountManagerId) , new SqlParameter("@BusinessManagerId", trueModel.BusinessManagerId) , new SqlParameter("@SoftId", trueModel.SoftId) , new SqlParameter("@SoftName", trueModel.SoftName) , new SqlParameter("@SoftQuantity", trueModel.SoftQuantity) , new SqlParameter("@SoftUnitprice", trueModel.SoftUnitprice) , new SqlParameter("@OrderMoney", trueModel.OrderMoney) , new SqlParameter("@OrderReceiveMoney", trueModel.OrderReceiveMoney) , new SqlParameter("@OrderStatus", trueModel.OrderStatus) , new SqlParameter("@OrderNum", trueModel.OrderNum) , new SqlParameter("@CreatTime", trueModel.CreatTime) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Operator", trueModel.Operator) , new SqlParameter("@VisitStatus", trueModel.VisitStatus) , new SqlParameter("@VisitSoftScore", trueModel.VisitSoftScore) , new SqlParameter("@VisitSoftServers", trueModel.VisitSoftServers) , new SqlParameter("@VisitReason", trueModel.VisitReason) , new SqlParameter("@VisitProposal", trueModel.VisitProposal) , new SqlParameter("@VisitPeople", trueModel.VisitPeople) , new SqlParameter("@VisitTime", trueModel.VisitTime) , new SqlParameter("@DegreeImportanId", trueModel.DegreeImportanId) , new SqlParameter("@Mobile", trueModel.Mobile) , new SqlParameter("@QQ", trueModel.QQ) , new SqlParameter("@OrderRemark", trueModel.OrderRemark) }; try { _dataBase.Query("sp_Soft_SellRecord_Update", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.Soft_SellRecord trueModel = model as Model.Soft_SellRecord; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_Soft_SellRecord_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 分页查询 /// /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination) { throw new NotImplementedException(); } /// /// 单个查询 /// /// /// public IEnumerable SelectAllModel(Infrastructure.Query.Query query) { throw new NotImplementedException(); } /// /// 根据编号获得信息 /// /// 编号 /// public Soft_SellRecord GetModelByKeyid(int? Keyid) { try { if (Keyid == null || Keyid < 0) return null;//错误数据返会空 IList result = _dataBase.SelectModel(" a.*,b.Name AS AccountManagerName,c.Name AS BusinessManagerName,d.Name AS DegreeImportanName ", " dbo.Soft_SellRecord AS a LEFT JOIN dbo.OA_Staff AS b ON a.AccountManagerId = b.Keyid LEFT JOIN dbo.OA_Staff AS c ON a.BusinessManagerId = c.Keyid LEFT JOIN dbo.Sys_Dictionary AS d ON a.DegreeImportanId = d.Keyid ", string.Format(" a.Keyid='{0}' ", Keyid)) as IList;//执行查询 return (null == result || result.Count == 0) ? null : result[0];//返回结果 } catch (Exception ex) { throw ex; } } /// /// 分页查询 /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, int? _ClientId, string _ClientName, int? _AccountManagerId, int? _BusinessManagerId, int? _SoftId, string _SoftName, int? _SoftQuantity, int? _SoftUnitprice, int? _OrderMoney, int? _OrderReceiveMoney, int? _OrderStatus, string _OrderNum, DateTime? _BeginCreatTime, DateTime? _EndCreatTime, DateTime? _BeginLastUpdateTime, DateTime? _EndLastUpdateTime, string _Operator, int? _VisitStatus, string _VisitSoftScore, string _VisitSoftServers, string _VisitReason, string _VisitProposal, string _VisitPeople, DateTime? _BeginVisitTime, DateTime? _EndVisitTime, int? _DegreeImportanId, string _Mobile, string _QQ,int? _MoneyStatus) { try { string condition = " 1=1 "; if (_ClientId.HasValue) condition += " and ClientId = '" + _ClientId + "' "; if (!string.IsNullOrEmpty(_ClientName)) condition += " and ClientName like '%" + _ClientName + "%' "; if (_AccountManagerId.HasValue) condition += " and AccountManagerId = '" + _AccountManagerId + "' "; if (_BusinessManagerId.HasValue) condition += " and BusinessManagerId = '" + _BusinessManagerId + "' "; if (_SoftId.HasValue) condition += " and SoftId = '" + _SoftId + "' "; if (!string.IsNullOrEmpty(_SoftName)) condition += " and SoftName = '" + _SoftName + "' "; if (_SoftQuantity.HasValue) condition += " and SoftQuantity = '" + _SoftQuantity + "' "; if (_SoftUnitprice.HasValue) condition += " and SoftUnitprice = '" + _SoftUnitprice + "' "; if (_OrderMoney.HasValue) condition += " and OrderMoney = '" + _OrderMoney + "' "; if (_OrderReceiveMoney.HasValue) condition += " and OrderReceiveMoney = '" + _OrderReceiveMoney + "' "; if (_OrderStatus.HasValue) condition += " and OrderStatus = '" + _OrderStatus + "' "; if (!string.IsNullOrEmpty(_OrderNum)) condition += " and OrderNum like '%" + _OrderNum + "%' "; if (_BeginCreatTime.HasValue) condition += string.Format(" and CAST(CreatTime AS DATE) >='{0}' ", _BeginCreatTime); if (_EndCreatTime.HasValue) condition += string.Format(" and CAST(CreatTime AS DATE) <='{0}' ", _EndCreatTime); if (_BeginLastUpdateTime.HasValue) condition += string.Format(" and CAST(LastUpdateTime AS DATE) >='{0}' ", _BeginLastUpdateTime); if (_EndLastUpdateTime.HasValue) condition += string.Format(" and CAST(LastUpdateTime AS DATE) <='{0}' ", _EndLastUpdateTime); if (!string.IsNullOrEmpty(_Operator)) condition += " and Operator = '" + _Operator + "' "; if (_VisitStatus.HasValue) condition += " and VisitStatus = '" + _VisitStatus + "' "; if (!string.IsNullOrEmpty(_VisitSoftScore)) condition += " and VisitSoftScore = '" + _VisitSoftScore + "' "; if (!string.IsNullOrEmpty(_VisitSoftServers)) condition += " and VisitSoftServers = '" + _VisitSoftServers + "' "; if (!string.IsNullOrEmpty(_VisitReason)) condition += " and VisitReason = '" + _VisitReason + "' "; if (!string.IsNullOrEmpty(_VisitProposal)) condition += " and VisitProposal = '" + _VisitProposal + "' "; if (!string.IsNullOrEmpty(_VisitPeople)) condition += " and VisitPeople = '" + _VisitPeople + "' "; if (_BeginVisitTime.HasValue) condition += string.Format(" and CAST(VisitTime AS DATE) >='{0}' ", _BeginVisitTime); if (_EndVisitTime.HasValue) condition += string.Format(" and CAST(VisitTime AS DATE) <='{0}' ", _EndVisitTime); if (_DegreeImportanId.HasValue) condition += " and DegreeImportanId = '" + _DegreeImportanId + "' "; if (!string.IsNullOrEmpty(_Mobile)) condition += " and Mobile = '" + _Mobile + "' "; if (!string.IsNullOrEmpty(_QQ)) condition += " and QQ = '" + _QQ + "' "; if (_MoneyStatus.HasValue) { switch (_MoneyStatus) { case 1: condition += " and OrderReceiveMoney >= OrderMoney "; break; case 2: condition += " and OrderReceiveMoney = '0' "; break; case 3: condition += " and OrderReceiveMoney < OrderMoney and OrderReceiveMoney > 0 "; break; default: break; } } return _dataBase.SelectModelPage(pagination, " * ", " Soft_SellRecord ", " Keyid desc", " Keyid desc ", condition); } catch (Exception ex) { throw ex; } } /// /// 统计金额 /// /// /// public Model.Soft_SellRecord OrderAllMoney(Infrastructure.Query.Pagination pagination, int? _ClientId, string _ClientName, int? _AccountManagerId, int? _BusinessManagerId, int? _SoftId, string _SoftName, int? _SoftQuantity, int? _SoftUnitprice, int? _OrderMoney, int? _OrderReceiveMoney, int? _OrderStatus, string _OrderNum, DateTime? _BeginCreatTime, DateTime? _EndCreatTime, DateTime? _BeginLastUpdateTime, DateTime? _EndLastUpdateTime, string _Operator, int? _VisitStatus, string _VisitSoftScore, string _VisitSoftServers, string _VisitReason, string _VisitProposal, string _VisitPeople, DateTime? _BeginVisitTime, DateTime? _EndVisitTime, int? _DegreeImportanId, string _Mobile, string _QQ, int? _MoneyStatus) { try { string condition = " 1=1 "; if (_ClientId.HasValue) condition += " and ClientId = '" + _ClientId + "' "; if (!string.IsNullOrEmpty(_ClientName)) condition += " and ClientName like '%" + _ClientName + "%' "; if (_AccountManagerId.HasValue) condition += " and AccountManagerId = '" + _AccountManagerId + "' "; if (_BusinessManagerId.HasValue) condition += " and BusinessManagerId = '" + _BusinessManagerId + "' "; if (_SoftId.HasValue) condition += " and SoftId = '" + _SoftId + "' "; if (!string.IsNullOrEmpty(_SoftName)) condition += " and SoftName = '" + _SoftName + "' "; if (_SoftQuantity.HasValue) condition += " and SoftQuantity = '" + _SoftQuantity + "' "; if (_SoftUnitprice.HasValue) condition += " and SoftUnitprice = '" + _SoftUnitprice + "' "; if (_OrderMoney.HasValue) condition += " and OrderMoney = '" + _OrderMoney + "' "; if (_OrderReceiveMoney.HasValue) condition += " and OrderReceiveMoney = '" + _OrderReceiveMoney + "' "; if (_OrderStatus.HasValue) condition += " and OrderStatus = '" + _OrderStatus + "' "; if (!string.IsNullOrEmpty(_OrderNum)) condition += " and OrderNum like '%" + _OrderNum + "%' "; if (_BeginCreatTime.HasValue) condition += string.Format(" and CAST(CreatTime AS DATE) >='{0}' ", _BeginCreatTime); if (_EndCreatTime.HasValue) condition += string.Format(" and CAST(CreatTime AS DATE) <='{0}' ", _EndCreatTime); if (_BeginLastUpdateTime.HasValue) condition += string.Format(" and CAST(LastUpdateTime AS DATE) >='{0}' ", _BeginLastUpdateTime); if (_EndLastUpdateTime.HasValue) condition += string.Format(" and CAST(LastUpdateTime AS DATE) <='{0}' ", _EndLastUpdateTime); if (!string.IsNullOrEmpty(_Operator)) condition += " and Operator = '" + _Operator + "' "; if (_VisitStatus.HasValue) condition += " and VisitStatus = '" + _VisitStatus + "' "; if (!string.IsNullOrEmpty(_VisitSoftScore)) condition += " and VisitSoftScore = '" + _VisitSoftScore + "' "; if (!string.IsNullOrEmpty(_VisitSoftServers)) condition += " and VisitSoftServers = '" + _VisitSoftServers + "' "; if (!string.IsNullOrEmpty(_VisitReason)) condition += " and VisitReason = '" + _VisitReason + "' "; if (!string.IsNullOrEmpty(_VisitProposal)) condition += " and VisitProposal = '" + _VisitProposal + "' "; if (!string.IsNullOrEmpty(_VisitPeople)) condition += " and VisitPeople = '" + _VisitPeople + "' "; if (_BeginVisitTime.HasValue) condition += string.Format(" and CAST(VisitTime AS DATE) >='{0}' ", _BeginVisitTime); if (_EndVisitTime.HasValue) condition += string.Format(" and CAST(VisitTime AS DATE) <='{0}' ", _EndVisitTime); if (_DegreeImportanId.HasValue) condition += " and DegreeImportanId = '" + _DegreeImportanId + "' "; if (!string.IsNullOrEmpty(_Mobile)) condition += " and Mobile = '" + _Mobile + "' "; if (!string.IsNullOrEmpty(_QQ)) condition += " and QQ = '" + _QQ + "' "; if (_MoneyStatus.HasValue) { switch (_MoneyStatus) { case 1: condition += " and OrderReceiveMoney >= OrderMoney "; break; case 2: condition += " and OrderReceiveMoney = '0' "; break; case 3: condition += " and OrderReceiveMoney < OrderMoney and OrderReceiveMoney > 0 "; break; default: break; } } List m_Soft_SellRecordList = _dataBase.SelectModel(" SUM(OrderMoney) AS AllMoney,SUM(OrderReceiveMoney) AS AllRecive, SUM(CASE WHEN OrderMoney>OrderReceiveMoney THEN (OrderMoney-OrderReceiveMoney) ELSE 0 END) AS AllBalance ", " Soft_SellRecord ", condition) as List; if (m_Soft_SellRecordList.Count > 0) { return m_Soft_SellRecordList[0]; } else { Soft_SellRecord m_Soft_SellRecord = new Soft_SellRecord(); m_Soft_SellRecord.AllMoney = 0; return m_Soft_SellRecord; } } catch (Exception ex) { throw ex; } } /// /// 获取订单号 /// /// public string LoadOrderNum() { string res = ""; List m_Soft_SellRecordList = _dataBase.SelectModel(" * ", " Soft_SellRecord ", " 1=1 and OrderNum like '" + DateTime.Now.ToString("yyyyMMdd") + "%' order by Keyid DESC") as List; if (m_Soft_SellRecordList != null && m_Soft_SellRecordList.Count > 0) { res = DateTime.Now.ToString("yyyyMMdd") + (int.Parse(m_Soft_SellRecordList[0].OrderNum.Substring(8, 3)) + 1).ToString("000"); } else { res = DateTime.Now.ToString("yyyyMMdd") + "001"; } return res; } } }