public void DeleteRecord(LotteryPeriod period) { string sql = string.Format(@"DELETE {0} WHERE {1}=@{1}", LotteryRecord.TABLENAME, LotteryRecord.PERIODID); base.ExecuteNonQuery(sql, new SqlParameter(LotteryRecord.PERIODID, period.PeriodId)); }
public void InsertPeriod(LotteryPeriod period) { string sql = string.Format(@"INSERT INTO {0} ({1}) VALUES (@{1}) SELECT SCOPE_IDENTITY()", LotteryPeriod.TABLENAME, LotteryPeriod.COMPANYID); object id = base.ExecuteScalar(sql, new SqlParameter(LotteryPeriod.COMPANYID, period.Company.CompanyId)); period.PeriodId = Convert.ToInt32(id); }
public void AddLotteryResult(int companyId, IEnumerable<LotteryRecord> records) { var company = TodayLotteryCompany.Instance.GetTodayCompany().Find(it => it.CompanyId == companyId); var lenSupport = DaNumLen.GetSupportNumLengthByType(company.CompanyType); foreach (var support in lenSupport) { var numLenCount = records.Where(it => it.Value.Length == support.NumLen.Length).Count(); if (numLenCount != support.Count) throw new BusinessException("Please confirm the accuracy of the numbers!"); } bool isNewData = true; var period = DaLotteryResult.GetPeriod(company, DateTime.Today); if (isNewData = (period == null)) { period = new LotteryPeriod { Company = company }; DaLotteryResult.InsertPeriod(period); } records = records.ForEach(it => { it.PeriodId = period.PeriodId; return it; }); DaLotteryResult.ExecuteWithTransaction(() => { if (!isNewData) DaLotteryResult.DeleteRecord(period); DaLotteryResult.InsertRecord(records); }); }