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 Integrity_IntegrityCardDAL : IIntegrity_IntegrityCardDAL { private Database _dataBase = null; public Integrity_IntegrityCardDAL() { _dataBase = new Database(); } public Integrity_IntegrityCardDAL(Database database) { _dataBase = database; } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.Integrity_IntegrityCard trueModel = model as Model.Integrity_IntegrityCard; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@RuleId",trueModel.RuleId), new SqlParameter("@MemberId",trueModel.MemberId), new SqlParameter("@UserType",trueModel.UserType), new SqlParameter("@Credit",trueModel.Credit), new SqlParameter("@CreditLevel",trueModel.CreditLevel), new SqlParameter("@LevelIcon",trueModel.LevelIcon), new SqlParameter("@GoodEvaluation",trueModel.GoodEvaluation), new SqlParameter("@MediumEvaluation",trueModel.MediumEvaluation), new SqlParameter("@BadEvaluation",trueModel.BadEvaluation), new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime), new SqlParameter("@Operator",trueModel.Operator), new SqlParameter("@Remark",trueModel.Remark) }; try { _dataBase.Query("sp_Integrity_IntegrityCard_Insert", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.Integrity_IntegrityCard trueModel = model as Model.Integrity_IntegrityCard; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid), new SqlParameter("@RuleId",trueModel.RuleId), new SqlParameter("@MemberId",trueModel.MemberId), new SqlParameter("@UserType",trueModel.UserType), new SqlParameter("@Credit",trueModel.Credit), new SqlParameter("@CreditLevel",trueModel.CreditLevel), new SqlParameter("@LevelIcon",trueModel.LevelIcon), new SqlParameter("@GoodEvaluation",trueModel.GoodEvaluation), new SqlParameter("@MediumEvaluation",trueModel.MediumEvaluation), new SqlParameter("@BadEvaluation",trueModel.BadEvaluation), new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime), new SqlParameter("@Operator",trueModel.Operator), new SqlParameter("@Remark",trueModel.Remark) }; try { _dataBase.Query("sp_Integrity_IntegrityCard_Update", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.Integrity_IntegrityCard trueModel = model as Model.Integrity_IntegrityCard; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_Integrity_IntegrityCard_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 分页查询 /// /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination) { return _dataBase.SelectModel(" * ", "Integrity_IntegrityCard"); } /// /// 根据会员编号以及类型获取诚信名片 /// /// 会员编号 /// 类型 /// public Integrity_IntegrityCard SelectModelPage(Guid MemberId) { Integrity_IntegrityCard model = new Integrity_IntegrityCard(); return model; } /// /// 单个查询 /// /// /// public IEnumerable SelectAllModel(Infrastructure.Query.Query query) { throw new NotImplementedException(); } /// /// 根据会员编号以及类型获取诚信名片 /// /// 会员编号 /// 类型 /// public Integrity_IntegrityCard SelectListByMemberIdAndRuleType(Guid MemberId, bool RuleType) { Integrity_IntegrityCard model = new Integrity_IntegrityCard(); if (MemberId == null) return null;//错误数据返会空 IList result = _dataBase.SelectModel("*", " Integrity_IntegrityCard a left join Integrity_CreditLevelRule b on a.RuleId = b.RuleId ", " MemberId ='" + MemberId + "' and b.RuleType ='" + RuleType + "'") as IList;//执行查询 if (result != null && result.Count > 0) model = result[0]; return model; } /// /// 根据会员编号以及类型获取诚信名片图片 /// /// 会员编号 /// 类型 /// public string GetLevelImgByMemberIdAndRuleType(Guid MemberId, bool RuleType) { Integrity_IntegrityCard model = new Integrity_IntegrityCard(); if (MemberId == null) return null;//错误数据返会空 IList result = _dataBase.SelectModel("*", " Integrity_IntegrityCard a left join Integrity_CreditLevelRule b on a.RuleId = b.RuleId ", " MemberId ='" + MemberId + "' and b.RuleType ='" + RuleType + "'") as IList;//执行查询 if (result != null && result.Count > 0) model = result[0]; else return ""; return "" + model.CreditLevel + ""; } /// /// 根据编号诚信名片 /// /// 会员编号 /// public Integrity_IntegrityCard SelectModelByKeyid(int? Keyid) { Integrity_IntegrityCard model = new Integrity_IntegrityCard(); if (Keyid == null) return null;//错误数据返会空 IList result = _dataBase.SelectModel("*", " Integrity_IntegrityCard ", " Keyid ='" + Keyid + "'") as IList;//执行查询 if (result != null && result.Count > 0) model = result[0]; return model; } /// /// 给诚信名片增加诚信 /// /// /// /// /// /// public bool GetNowCardByKeyidAndCredit(int? Keyid, int? Credit, string reason, string Operator) { try { bool IsSuccess = false; Integrity_IntegrityCard m_Integrity_IntegrityCard = SelectModelByKeyid(Keyid); if (m_Integrity_IntegrityCard != null) { Integrity_CreditGrowRecordDAL dal_Integrity_CreditGrowRecordDAL = new Integrity_CreditGrowRecordDAL(_dataBase); Integrity_CreditLevelRuleDAL dal_Integrity_CreditLevelRuleDAL = new Integrity_CreditLevelRuleDAL(_dataBase); Integrity_CreditLevelRule m_Integrity_CreditLevelRuleOld = dal_Integrity_CreditLevelRuleDAL.SelectModelByRuleId(m_Integrity_IntegrityCard.RuleId); Integrity_CreditLevelRule m_Integrity_CreditLevelRule = dal_Integrity_CreditLevelRuleDAL.SelectModelByCredit(Credit, m_Integrity_CreditLevelRuleOld.RuleType); if (m_Integrity_CreditLevelRule != null) { Integrity_CreditGrowRecord m_Integrity_CreditGrowRecord = new Integrity_CreditGrowRecord(); m_Integrity_CreditGrowRecord.Fraction = Credit - m_Integrity_IntegrityCard.Credit; m_Integrity_CreditGrowRecord.IntegrityCardId = m_Integrity_IntegrityCard.Keyid; m_Integrity_CreditGrowRecord.LastUpdateTime = DateTime.Now; m_Integrity_CreditGrowRecord.Operator = Operator; m_Integrity_CreditGrowRecord.Reason = reason; m_Integrity_CreditGrowRecord.Remark = ""; m_Integrity_IntegrityCard.Credit = Credit; m_Integrity_IntegrityCard.CreditLevel = m_Integrity_CreditLevelRule.LevelName; m_Integrity_IntegrityCard.LevelIcon = m_Integrity_CreditLevelRule.LevelIcon; m_Integrity_IntegrityCard.RuleId = m_Integrity_CreditLevelRule.RuleId; using (TransactionScope t_TransactionScope = new TransactionScope()) { IsSuccess = dal_Integrity_CreditGrowRecordDAL.InserModel(m_Integrity_CreditGrowRecord); if (IsSuccess) { IsSuccess = UpdateModel(m_Integrity_IntegrityCard); if (IsSuccess) { t_TransactionScope.Complete(); } } } } } return IsSuccess; } catch (Exception ex) { throw ex; } } /// /// 厂商评价并结束评价 /// /// /// /// /// /// /// public bool FirmEndOrderEva(Integrity_EvaluationRecords m_Integrity_EvaluationRecords, Integrity_IntegrityCard m_Integrity_IntegrityCard_Buyer, Integrity_CreditGrowRecord m_Integrity_CreditGrowRecord_Buyer) { try { Integrity_EvaluationRecordsDAL dal_Integrity_EvaluationRecordsDAL = new Integrity_EvaluationRecordsDAL(_dataBase); Integrity_IntegrityCardDAL dal_Integrity_IntegrityCardDAL = new Integrity_IntegrityCardDAL(_dataBase); Integrity_CreditGrowRecordDAL dal_Integrity_CreditGrowRecordDAL = new Integrity_CreditGrowRecordDAL(_dataBase); bool result = false; using (TransactionScope t_TransactionScope = new TransactionScope()) { if (m_Integrity_EvaluationRecords.Keyid > 0) { result = dal_Integrity_EvaluationRecordsDAL.UpdateModel(m_Integrity_EvaluationRecords); } else { result = dal_Integrity_EvaluationRecordsDAL.InserModel(m_Integrity_EvaluationRecords); } if (result) { if (m_Integrity_IntegrityCard_Buyer != null) { result = dal_Integrity_IntegrityCardDAL.UpdateModel(m_Integrity_IntegrityCard_Buyer); } if (result) { if (m_Integrity_CreditGrowRecord_Buyer != null) { result = dal_Integrity_CreditGrowRecordDAL.InserModel(m_Integrity_CreditGrowRecord_Buyer); } if (result) { t_TransactionScope.Complete(); } } } } return result; } catch (Exception ex) { throw ex; } } } }