Exemple #1
0
        public static Participation ToDataObject(this IParticipation self)
        {
            Participation outputData = new Participation
            {
                CostPrice1Day = self.CostPrice1Day,
                CostPrice20Day = self.CostPrice20Day,
                MainForceInflows = self.MainForceInflows,
                SuperLargeInflows = self.SuperLargeInflows,
                Time = self.Time,
                Value = self.Value,
            };

            return outputData;
        }
Exemple #2
0
        public void TestParticipationReadAndWrite()
        {
            Participation insertData = new Participation()
            {
                Time = new DateTime(2016, 1, 11),
                CostPrice1Day = 16.37,
                CostPrice20Day = 17.62,
                MainForceInflows = -18890.18,
                SuperLargeInflows = -13224.41,
                Value = 37.97
            };

            string fileName = "Participation.sdf";
            string fullPath = Path.Combine(directory, fileName);

            // Add
            using (IRepositoryContext context = ContextFactory.Create(ContextType.Participation, fullPath))
            {
                var repository = new Repository<Participation>(context);
                repository.Add(insertData);
                repository.UnitOfWork.Commit();
            }

            // Read
            Participation readData;
            using (IRepositoryContext context = ContextFactory.Create(ContextType.Participation, fullPath))
            {
                var repository = new Repository<Participation>(context);
                readData = repository.Get(insertData.Time);
            }
            Assert.IsNotNull(readData);
            Assert.AreEqual(insertData.Time, readData.Time);
        }
        public IEnumerable<IParticipation> GetAll()
        {
            List<Participation> result = new List<Participation>();
            string sql = string.Format("SELECT * FROM {0}", tableName);

            using (SqlCeConnection conn = new SqlCeConnection(ConnectionString))
            {
                conn.Open();

                using (SqlCeCommand cmd = new SqlCeCommand(sql, conn))
                {
                    SqlCeDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Participation dbo = new Participation
                        {
                            CostPrice1Day = Double.Parse(reader[colCostPrice1Day].ToString().Trim()),
                            CostPrice20Day = Double.Parse(reader[colCostPrice20Day].ToString().Trim()),
                            MainForceInflows = Double.Parse(reader[colMainForceInflows].ToString().Trim()),
                            SuperLargeInflows = Double.Parse(reader[colSuperLargeInflows].ToString().Trim()),
                            Time = DateTime.Parse(reader[colTime].ToString().Trim()),
                            Value = Double.Parse(reader[colValue].ToString().Trim())
                        };
                        result.Add(dbo);
                    }
                    reader.Close();
                }

                conn.Close();
            }
            return result;
        }
        public IParticipation Get(string keyCode)
        {
            Participation result = null;
            string sql = string.Format("SELECT * FROM {0} WHERE {1}='{2}'", tableName, colTime, keyCode);

            using (SqlCeConnection conn = new SqlCeConnection(ConnectionString))
            {
                conn.Open();

                using (SqlCeCommand cmd = new SqlCeCommand(sql, conn))
                {
                    SqlCeDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Participation dbo = new Participation
                        {
                            CostPrice1Day = Double.Parse(reader[colCostPrice1Day].ToString().Trim()),
                            CostPrice20Day = Double.Parse(reader[colCostPrice20Day].ToString().Trim()),
                            MainForceInflows = Double.Parse(reader[colMainForceInflows].ToString().Trim()),
                            SuperLargeInflows = Double.Parse(reader[colSuperLargeInflows].ToString().Trim()),
                            Time = DateTime.Parse(reader[colTime].ToString().Trim()),
                            Value = Double.Parse(reader[colValue].ToString().Trim())
                        };
                        result = dbo;
                    }
                    reader.Close();
                }

                conn.Close();
            }
            return result;
        }