Ejemplo n.º 1
0
        public void TestSave_Update()
        {
            using (new TransactionScope())
                using (var dao = new TrendDbContext())
                {
                    var beforeCount = dao.Set <MarkSixSpecifiedLocationPurchase>().Count();
                    var service     = new MarkSixPurchaseService();
                    var addDto      = new MarkSixSpecifiedLocationPurchase
                    {
                        Times        = "2017001",
                        Odds         = 40,
                        Location     = 7,
                        PurchaseList = "12:50;36:100"
                    };
                    service.SaveSpecifiedLocation(addDto);
                    var afterCount = dao.Set <MarkSixSpecifiedLocationPurchase>().Count();
                    Assert.IsTrue(beforeCount + 1 == afterCount);
                    var purchase = dao.Set <MarkSixSpecifiedLocationPurchase>().OrderByDescending(m => m.Id).FirstOrDefault();
                    Assert.IsNotNull(purchase);
                    Assert.IsTrue(purchase.Times == addDto.Times);

                    addDto.Id       = purchase.Id;
                    addDto.Location = 6;
                    service.SaveSpecifiedLocation(addDto);
                    purchase = dao.Set <MarkSixSpecifiedLocationPurchase>().AsNoTracking().FirstOrDefault(m => m.Id == purchase.Id);
                    Assert.IsTrue(purchase.Location == addDto.Location);
                }
        }
Ejemplo n.º 2
0
        private void btnPurchase_Click(object sender, EventArgs e)
        {
            var frm = new frmMarkSixSpecifiedLocationPurchase();

            byte location = 1;

            if (!byte.TryParse(cboNumberLocation.Text, out location) || location < 1 || location > 7)
            {
                MessageBox.Show("请选择1-7的号码位置!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboNumberLocation.Focus();
                return;
            }
            var times = cboTimes.Text;

            if (string.IsNullOrWhiteSpace(times))
            {
                MessageBox.Show("期次不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboTimes.Focus();
                return;
            }

            var numbers = new byte[] { 3, 6, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 88, 99 }.ToList();
            var purchasesString = string.Join(";", numbers.Select(a => a.ToString() + ":"));

            var purchase = new MarkSixSpecifiedLocationPurchase {
                Times = times, Location = location, PurchaseList = purchasesString
            };

            frm.MarkSixSpecifiedLocationPurchase = purchase;
            frm.Text = string.Format("第{0}期第{0}位 号码清单", times, location);
            try
            {
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    frmMdi.tsslInfo.Text      = "保存购买成功!";
                    frmMdi.tsslInfo.BackColor = Color.Green;
                    var frmPurchaseRecord = FormHelper.OpenForm <frmMarkSixSpecifiedLocationPurchaseRecord>(frmMdi);
                }
                else
                {
                    frmMdi.tsslInfo.Text      = "取消购买";
                    frmMdi.tsslInfo.BackColor = Color.Yellow;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("生成购买时,发生错误:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                frmMdi.tsslInfo.Text      = "购买失败";
                frmMdi.tsslInfo.BackColor = Color.Red;
                return;
            }
        }
 public void SaveSpecifiedLocation(MarkSixSpecifiedLocationPurchase dto)
 {
     if (string.IsNullOrWhiteSpace(dto.Times))
     {
         throw new Exception("错误,期次不能为空");
     }
     if (string.IsNullOrWhiteSpace(dto.PurchaseList))
     {
         throw new Exception("错误,购买清单不能为空");
     }
     if (dto.Location > 7 || dto.Location < 1)
     {
         throw new Exception("错误,购买的指定位置必须为1-7!");
     }
     if (dto.Odds <= 0)
     {
         throw new Exception("错误,赔率不能小于等于0!");
     }
     using (var dao = new TrendDbContext())
     {
         if (dto.Id > 0)
         {
             var purchase = dao.Set <MarkSixSpecifiedLocationPurchase>().FirstOrDefault(m => m.Id == dto.Id);
             if (purchase == null)
             {
                 throw new Exception(string.Format("错误,购买记录不存在!(Id:{0})", dto.Id));
             }
             purchase.Times          = dto.Times;
             purchase.PurchaseList   = dto.PurchaseList;
             purchase.Odds           = dto.Odds;
             purchase.Location       = dto.Location;
             purchase.PurchaseAmount = dto.PurchaseAmount;
             purchase.OnModified     = DateTime.Now;
         }
         else
         {
             dto.OnCreated = dto.OnModified = DateTime.Now;
             dao.Set <MarkSixSpecifiedLocationPurchase>().Add(dto);
         }
         dao.SaveChanges();
     }
 }