Esempio n. 1
0
        public void AddPositionDetail(PositionDetail model)
        {
            PositionDetails.Add(model);

            string sql = "INSERT INTO PositionDetail (Id,DateForPosition,DateForActual,Item,Ticket,BuySize,BuyPrice,SaleSize,SalePrice,YesterdaySettlementPrice,TodaySettlementPrice,Profit,SH,TradeCode,SettlementType,AccountId) "
                         + "VALUES(@Id,@DateForPosition,@DateForActual,@Item,@Ticket,@BuySize,@BuyPrice,@SaleSize,@SalePrice,@YesterdaySettlementPrice,@TodaySettlementPrice,@Profit,@SH,@TradeCode,@SettlementType,@AccountId)";
            SQLiteCommand cmd = new SQLiteCommand(sql);

            cmd.Parameters.AddWithValue("@AccountId", model.AccountId.ToString());
            cmd.Parameters.AddWithValue("@BuyPrice", model.BuyPrice);
            cmd.Parameters.AddWithValue("@BuySize", model.BuySize);
            cmd.Parameters.AddWithValue("@DateForActual", model.DateForActual);
            cmd.Parameters.AddWithValue("@DateForPosition", model.DateForPosition);
            cmd.Parameters.AddWithValue("@Id", model.Id.ToString());
            cmd.Parameters.AddWithValue("@Item", model.Item);
            cmd.Parameters.AddWithValue("@Profit", model.Profit);
            cmd.Parameters.AddWithValue("@SalePrice", model.SalePrice);
            cmd.Parameters.AddWithValue("@SaleSize", model.SaleSize);
            cmd.Parameters.AddWithValue("@SettlementType", model.SettlementType);
            cmd.Parameters.AddWithValue("@SH", model.SH);
            cmd.Parameters.AddWithValue("@Ticket", model.Ticket);
            cmd.Parameters.AddWithValue("@TodaySettlementPrice", model.TodaySettlementPrice);
            cmd.Parameters.AddWithValue("@TradeCode", model.TradeCode);
            cmd.Parameters.AddWithValue("@YesterdaySettlementPrice", model.YesterdaySettlementPrice);
            cmds.Add(cmd);
        }
Esempio n. 2
0
        public List <PositionDetail> GetPositionDetails()
        {
            List <PositionDetail> result = new List <PositionDetail>();
            SQLiteConnection      conn   = null;

            try
            {
                conn = new SQLiteConnection(connectionStr);
                conn.Open();
                string           sql    = string.Format("SELECT * FROM PositionDetail");
                SQLiteCommand    cmd    = new SQLiteCommand(sql, conn);
                SQLiteDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    PositionDetail model = new PositionDetail();
                    model.Id = Guid.Parse(reader.GetString(0));
                    model.DateForPosition          = reader.GetDateTime(1);
                    model.DateForActual            = reader.GetDateTime(2);
                    model.Item                     = reader.GetString(3);
                    model.Ticket                   = reader.GetString(4);
                    model.BuySize                  = reader.GetInt32(5);
                    model.BuyPrice                 = reader.GetDecimal(6);
                    model.SaleSize                 = reader.GetInt32(7);
                    model.SalePrice                = reader.GetDecimal(8);
                    model.YesterdaySettlementPrice = reader.GetDecimal(9);
                    model.TodaySettlementPrice     = reader.GetDecimal(10);
                    model.Profit                   = reader.GetDecimal(11);
                    model.SH             = reader.GetString(12);
                    model.TradeCode      = reader.GetString(13);
                    model.SettlementType = (SettlementType)reader.GetInt32(14);
                    model.AccountId      = Guid.Parse(reader.GetString(15));
                    result.Add(model);
                }
                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(result);
        }