示例#1
0
        private void DeleteData(DateTime date)
        {
            try
            {
                mainWindow.ProgressInfoVisible(3);
                using (StatementContext statement = new StatementContext())
                {
                    mainWindow.SetProgressText("(1/3)正在删除数据...");
                    statement.Delete(date, _Session.SelectedAccountId, typeof(ClosedTradeDetail), typeof(CommoditySummarization), typeof(FundStatus), typeof(PositionDetail), typeof(Position), typeof(Remittance), typeof(Stock), typeof(TradeDetail), typeof(Trade));
                    mainWindow.AddProgressValue(1);

                    mainWindow.SetProgressText("(2/3)正在校准权益...");
                    var stocks     = statement.Stocks.Where(m => m.AccountId == _Session.SelectedAccountId).OrderBy(m => m.Date);
                    var fundStatus = statement.FundStatus.Where(m => m.AccountId == _Session.SelectedAccountId).OrderBy(m => m.Date);
                    if (stocks.Count() > 0 && fundStatus.Count() > 0)
                    {
                        var lastStock      = stocks.ToList().LastOrDefault();
                        var lastFundStatus = fundStatus.ToList().LastOrDefault();
                        var diff           = lastFundStatus.CustomerRights - lastStock.Close;
                        if (diff != 0)
                        {
                            foreach (var stc in stocks)
                            {
                                stc.Open  += diff;
                                stc.High  += diff;
                                stc.Low   += diff;
                                stc.Close += diff;
                            }
                            mainWindow.AddProgressValue(1);
                            statement.UpdateStocks(stocks);
                        }
                    }

                    mainWindow.SetProgressText("(3/3)正在保存数据...");
                    statement.SaveChanged();
                    mainWindow.AddProgressValue(1);

                    MessageBox.Show(string.Concat("账号【", statement.Accounts.FirstOrDefault(m => m.Id == _Session.SelectedAccountId).AccountNumber, "】 ", date.ToString("yyyy年MM月dd日"), " 以及之后的数据已全部删除。"));
                }
                mainWindow.InitializeUserControlsThreadStart();
            }
            catch (Exception ex)
            {
                OverStatusAndProgressBar();
                MessageBoxSync(ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                mainWindow.ProgressInfoHidden();
            }
        }