Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <stock> stocks = new List <stock>();

            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                if (item.Cells["changed"].Value == null)
                {
                    continue;
                }
                string changed = item.Cells["changed"].Value.ToString();
                if (changed != "1")
                {
                    continue;
                }
                var temp = item.DataBoundItem as stock;
                if (temp == null)
                {
                    continue;
                }
                if (temp.id == 0)
                {
                    if (!string.IsNullOrEmpty(temp.code) && !string.IsNullOrEmpty(temp.name))
                    {
                        var result = stockDb.stockInfos.SingleOrDefault(t => t.code == temp.code || t.name == temp.code);
                        temp.area = result.area;
                        stockDb.stock.Add(temp);
                    }
                }
                else
                {
                    var Obj = stockDb.stock.Find(temp.id);
                    Obj.count         = temp.count;
                    Obj.name          = temp.name;
                    Obj.code          = temp.code;
                    Obj.type          = temp.type;
                    Obj.salePrice     = temp.salePrice;
                    Obj.buyPrice      = temp.buyPrice;
                    Obj.buyDate       = temp.buyDate;
                    Obj.planEarnMoney = temp.planEarnMoney;
                    Obj.lowBuyPrice   = temp.lowBuyPrice;
                    stocks.Add(Obj);
                }
            }
            stockDb.SaveChanges();
            BindGridView();
            toolStripStatusLabel1.Text = "操作成功!";
        }
Example #2
0
 private void button3_Click(object sender, EventArgs e)
 {
     using (StockInfoEntities stockDb = new StockInfoEntities())
     {
         //同步昨日净值
         foreach (DataGridViewRow item in dataGridView1.Rows)
         {
             var stock     = (stock)item.DataBoundItem;
             var stockInfo = stockDb.stock.Find(stock.id);
             stockInfo.PrevEarnMoney = Convert.ToDecimal(item.Cells["earnMoney"].Value);
         }
         stockDb.SaveChanges();
     }
     MessageBox.Show("操作成功!");
 }
Example #3
0
        private async Task BindGridViewAsync()
        {
            using (StockInfoEntities stockDb = new StockInfoEntities())
            {
                var Data = stockDb.stock.Where(t => t.type == "持有").ToList();
                MyStock = (from item in Data
                           select new stockExtend()
                {
                    id = item.id,
                    code = item.code,
                    buyPrice = item.buyPrice,
                    area = item.area,
                    count = item.count,
                    curPrice = 0,
                    name = item.name,
                    salePrice = item.salePrice,
                    type = item.type,
                    planEarnMoney = item.planEarnMoney,
                    PrevEarnMoney = item.PrevEarnMoney,
                    isShort = item.isShort
                }
                           ).ToList();
                stockBindingSource.DataSource = Data;


                foreach (var item in MyStock)
                {
                    var dict = await RequestHelper.GetStockMAInfoAsync(item.area.ToUpper() + item.code);

                    var tempStockInfo = stockDb.stock.Find(item.id);
                    tempStockInfo.MAInfos = "MA4:" + dict["MA4"].ToString() + ";";
                    item.DictMaInfos      = dict;
                    stockDb.SaveChanges();
                }
            }
        }