Esempio 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);
                }
        }
Esempio n. 2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (MarkSixSpecifiedLocationPurchase == null)
            {
                return;
            }
            var purchaseNumbers = MarkSixSpecifiedLocationPurchase.Purchases;

            //OnShowDialogEvent(null);
            if (purchaseNumbers != null && purchaseNumbers.Count > 0)
            {
                var totalAmount            = 0;
                var numberAmountListString = string.Empty;
                foreach (var number in purchaseNumbers.Keys)
                {
                    //购买金额文本框
                    var tb  = _textBoxs[number];
                    var str = tb.Text;
                    if (string.IsNullOrWhiteSpace(str))
                    {
                        continue;
                    }
                    var amount = 0;
                    if (!int.TryParse(tb.Text, out amount))
                    {
                        MessageBox.Show("请选择1-7的号码位置!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        tb.Focus();
                        return;
                    }
                    numberAmountListString += string.Format("{0}:{1};", number, amount);
                    totalAmount            += amount;
                }
                if (MarkSixSpecifiedLocationPurchase == null)
                {
                    throw new Exception("对象:MarkSixSpecifiedLocationPurchase为空!");
                }
                if (string.IsNullOrWhiteSpace(numberAmountListString))
                {
                    MessageBox.Show("购买清单为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                var oddsString = tbOdds.Text;

                var odds = 0;
                if (!int.TryParse(oddsString, out odds) || odds < 1)
                {
                    MessageBox.Show("赔率必须为大于0的整数!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                MarkSixSpecifiedLocationPurchase.PurchaseAmount = totalAmount;
                MarkSixSpecifiedLocationPurchase.PurchaseList   = numberAmountListString;
                MarkSixSpecifiedLocationPurchase.Odds           = odds;

                var purchaseService = new MarkSixPurchaseService();
                purchaseService.SaveSpecifiedLocation(MarkSixSpecifiedLocationPurchase);

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Esempio n. 3
0
        private void PurchaseDelete(string id)
        {
            if (MessageBox.Show($"你确定删除第{id}条记录吗?", "确认删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
            {
                return;
            }
            var service = new MarkSixPurchaseService();

            try
            {
                var recordId = long.Parse(id);
                service.RemoveSpecifiedLocation(recordId);
                Search();
                frmMdi.tsslInfo.Text      = "删除成功!";
                frmMdi.tsslInfo.BackColor = Color.Yellow;
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("删除Id:{0}的购买记录失败!{1}", id, ex.Message), "删除失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                frmMdi.tsslInfo.Text      = "删除失败!";
                frmMdi.tsslInfo.BackColor = Color.Red;
            }
        }
Esempio n. 4
0
 private void tsbExport_Click(object sender, EventArgs e)
 {
     using (var saveFileDialog = new SaveFileDialog())
     {
         saveFileDialog.Filter           = "Execl 2007files(*.xlsx)|*.xlsx";
         saveFileDialog.FilterIndex      = 0;
         saveFileDialog.RestoreDirectory = true; //保存对话框是否记忆上次打开的目录
                                                 //saveFileDialog.CreatePrompt = true;
         saveFileDialog.Title    = "导出Excel文件到";
         saveFileDialog.FileName = "MarksixPurchaseRecord.xlsx";
         if (saveFileDialog.ShowDialog() == DialogResult.OK)
         {
             var fileName = saveFileDialog.FileName;
             var table    = Search();
             if (table != null)
             {
                 var service = new MarkSixPurchaseService();
                 service.Export(table, fileName);
                 frmMdi.tsslInfo.Text      = "导出成功!";
                 frmMdi.tsslInfo.BackColor = Color.Yellow;
             }
         }
     }
 }
Esempio n. 5
0
        private void PurchaseUpdate(string id)
        {
            var service = new MarkSixPurchaseService();

            try
            {
                var recordId = long.Parse(id);

                var frm      = new frmMarkSixSpecifiedLocationPurchase();
                var purchase = service.GetSpecifiedLocationPurchaseById(recordId);
                if (purchase == null)
                {
                    throw new Exception(string.Format("错误,购买记录不存在!(Id:{0})", id));
                }
                frm.MarkSixSpecifiedLocationPurchase = purchase;
                frm.Text = string.Format("编辑 第{0}期第{0}位 购买记录", purchase.Times, purchase.Location);

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    Search();
                    frmMdi.tsslInfo.Text      = "修改成功!";
                    frmMdi.tsslInfo.BackColor = Color.Yellow;
                }
                else
                {
                    frmMdi.tsslInfo.Text      = "取消修改";
                    frmMdi.tsslInfo.BackColor = Color.Yellow;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("修改Id:{0}的购买记录失败!{1}", id, ex.Message), "修改失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                frmMdi.tsslInfo.Text      = "修改失败!";
                frmMdi.tsslInfo.BackColor = Color.Red;
            }
        }
Esempio n. 6
0
        private DataTable Search()
        {
            //每页数量
            var pageSize = 0;

            int.TryParse(tlscombo.Text, out pageSize);
            //页码开始数
            var pageIndex = 1;

            int.TryParse(bdnPositionItem.Text, out pageIndex);
            //开始位置
            var startIndex = pageSize * (pageIndex - 1);

            if (startIndex < 0)
            {
                startIndex = 0;
            }

            var searchDto = new MarkSixSpecifiedLocationPurchaseSearchDto {
                StartIndex = startIndex, PageSize = pageSize
            };

            if (tbStartDateTime.Text.Trim().Length > 0)
            {
                var      strDate = tbStartDateTime.Text.Trim();
                DateTime dt;
                if (DateTime.TryParse(strDate, out dt))
                {
                    searchDto.StartDateTime = dt;
                }
            }
            if (tbEndDateTime.Text.Trim().Length > 0)
            {
                var      strDate = tbEndDateTime.Text.Trim();
                DateTime dt;
                if (DateTime.TryParse(strDate, out dt))
                {
                    searchDto.EndDateTime = dt;
                }
            }
            var selectedLocation = cboLocation.SelectedItem as ComboBoxItem <int>;

            if (selectedLocation != null)
            {
                searchDto.Location = selectedLocation.Value;
            }

            searchDto.Times = tbTimes.Text;
            var service = new MarkSixPurchaseService();

            try
            {
                var rows = service.SearchSpecifiedLocation(searchDto);
                if (rows.Count == 0)
                {
                    MessageBox.Show(
                        "没有找到符合条件的数据!",
                        "失败",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                    frmMdi.tsslInfo.Text      = "查询内容为空!";
                    frmMdi.tsslInfo.BackColor = Color.Yellow;
                    //重新绑定数据
                    var sourceTable = dgvMarksixPurchaseRecordList.DataSource as DataTable;
                    if (sourceTable != null)
                    {
                        sourceTable.Rows.Clear();
                        dgvMarksixPurchaseRecordList.DataSource = sourceTable;
                    }
                    return(null);
                }
                frmMdi.tsslInfo.Text      = "查询完成!";
                frmMdi.tsslInfo.BackColor = frmMdi.BackColor;
                var table = rows.ConvertDataTable(properties =>
                {
                    var rowVersionProperty = properties.FirstOrDefault(p => p.Name == nameof(MarkSixSpecifiedLocationPurchase.RowVersion));
                    if (rowVersionProperty != null)
                    {
                        properties.Remove(rowVersionProperty);
                    }
                    var purchasesProperty = properties.FirstOrDefault(p => p.Name == nameof(MarkSixSpecifiedLocationPurchase.Purchases));
                    if (purchasesProperty != null)
                    {
                        properties.Remove(purchasesProperty);
                    }
                    var idProperty = properties.FirstOrDefault(p => p.Name == nameof(MarkSixSpecifiedLocationPurchase.Id));
                    if (idProperty != null)
                    {
                        properties.Remove(idProperty);
                    }
                    //Id列移动到首位
                    properties.Insert(0, idProperty);
                });
                dgvMarksixPurchaseRecordList.DataSource = table;

                var pageCount = searchDto.PageCount;
                bdnCountItem.Text = pageCount.ToString();

                if (pageIndex <= 1)
                {
                    bdnMoveFirstItem.Enabled    = false;
                    bdnMovePreviousItem.Enabled = false;
                }
                else
                {
                    bdnMoveFirstItem.Enabled    = true;
                    bdnMovePreviousItem.Enabled = true;
                }

                if (pageIndex == pageCount)
                {
                    bdnMoveNextItem.Enabled = false;
                    bdnMoveLastItem.Enabled = false;
                }
                else
                {
                    bdnMoveNextItem.Enabled = true;
                    bdnMoveLastItem.Enabled = true;
                }
                return(table);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "查询发生错误," + ex.Message,
                    "错误",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
                frmMdi.tsslInfo.Text      = "查询失败!";
                frmMdi.tsslInfo.BackColor = Color.Yellow;
                return(null);
            }
        }