public override void CreateDatabase(DatabaseConfig config)
        {
            SqliteDatabaseConfig sqliteConfig = config as SqliteDatabaseConfig;
            FileInfo             sqliteFile   = new FileInfo(sqliteConfig.DataSource);

            if (File.Exists(sqliteConfig.DataSource))
            {
                throw new Exception("指定的数据库已经存在");
            }
            connectionString = string.Format("Data Source={0};Cache=Shared;",
                                             sqliteConfig.DataSource);
            string securityTableSql             = @"create table if not exists Security
                                        (
                                            SecurityID integer not null primary key AUTOINCREMENT,
                                            SecurityCode varchar(10) not null,
                                            SecurityAbbr varchar(128) not null,
                                            CompanyCode varchar(128) not null,
                                            CompanyAbbr varchar(128) not null,
                                            ListingDate DateTime not null,
                                            ExchangeMarket varchar(10) not null
                                        )";
            string SecurityTaskTableSql         = @"create table if not exists SecurityTask(
                                            TaskID integer not null primary key AUTOINCREMENT,
                                            SecurityCode varchar(10) not null,
                                            ExchangeMarket varchar(10) not null,
                                            BeginDate DateTime not null,
                                            EndDate DateTime not null,
                                            IsFinished int not null
                                        )";
            string SecurityDayQuotationTableSql = @"create table if not exists SecurityDayQuotation
                                            (
                                                id integer not null primary key AUTOINCREMENT,
                                                SecurityCode varchar(10) not null,
                                                TxDate DateTime not null,
                                                ClosePrice float not null,
                                                HighPrice float not null,
                                                LowPrice float not null,
                                                OpenPrice float not null,
                                                LastClosePrice float not null,
                                                PriceChange float not null,
                                                Change float not null,
                                                TurnOver float not null,
                                                VolumeTurnOver float not null,
                                                PriceTurnOver float not null,
                                                MarketValue float not null,
                                                NegoValue float not null
                                            )";

            ExecuteNoQuery(securityTableSql);
            ExecuteNoQuery(SecurityTaskTableSql);
            ExecuteNoQuery(SecurityDayQuotationTableSql);
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            string databaseType = comboDatabaseType.Text;
            DatabaseConfigFactory   configFactory   = new DatabaseConfigFactory();
            DatabaseConfig          config          = configFactory.Create(databaseType);
            SecurityDatabaseService databaseService = new SecurityDatabaseService();

            if (databaseType == "mssql")
            {
                MSSqlDatabaseConfig tempConfig = (MSSqlDatabaseConfig)config;
                tempConfig.DataSource     = txtMSSqlIP.Text.Trim();
                tempConfig.InitialCatelog = txtMSSqlDatabaseName.Text.Trim();
                tempConfig.UserID         = txtMSSqlUserID.Text.Trim();
                tempConfig.Password       = txtMSSqlPwd.Text.Trim();
                tempConfig.DatabasePath   = txtMSSqlDatabasePath.Text.Trim();
                try
                {
                    databaseService.CreateDatabase(tempConfig);
                }
                catch (Exception ex)
                {
                    customError.ShowError(ex.Message);
                }
            }
            else
            {
                SqliteDatabaseConfig tempConfig = (SqliteDatabaseConfig)config;
                tempConfig.DataSource = txtSqliteDatabaseName.Text.Trim();
                try
                {
                    databaseService.CreateDatabase(tempConfig);
                }
                catch (Exception ex)
                {
                    customError.ShowError(ex.Message);
                }
            }
        }
Exemple #3
0
 public void CreateDataBase()
 {
     try
     {
         SecurityDatabaseService service     = new SecurityDatabaseService();
         MSSqlDatabaseConfig     mssqlConfig = new MSSqlDatabaseConfig();
         mssqlConfig.DataSource     = "172_17_0_13";
         mssqlConfig.InitialCatelog = "testSecurity";
         mssqlConfig.UserID         = "sa";
         mssqlConfig.Password       = "******";
         mssqlConfig.DatabasePath   = "C:\\renkf\\database";
         service.CreateDatabase(mssqlConfig);
         Assert.IsTrue(1 == 1, "MSSQL数据库创建成功");
         SqliteDatabaseConfig sqliteConfig = new SqliteDatabaseConfig();
         sqliteConfig.DataSource = "C:\\renkf\\database\\text.db";
         service.CreateDatabase(sqliteConfig);
         Assert.IsTrue(1 == 1, "Sqlite数据库创建成功");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(1 == 0, ex.Message);
     }
 }
        public void AddRemoveUpdateAssetTest()
        {
            // First, create a simple asset type.  We'll do colors!
            SqliteDatabaseConfig databaseConfig = new SqliteDatabaseConfig
            {
                DatabaseLocation = this.db1Location
            };
            Guid databaseId = databaseConfig.DatabaseId;

            DatabaseApi uut = new DatabaseApi(new List <IDatabaseConfig> {
                databaseConfig
            });

            int typeId = this.AddColorAttributeType(uut, databaseId);

            Assert.Greater(typeId, 0);

            int redId = this.AddRedAsset(uut, databaseId, typeId);

            this.VerifyRedAsset(uut.GetAsset(databaseId, redId));

            int greenId = this.AddGreenAsset(uut, databaseId, typeId);

            this.VerifyGreenAsset(uut.GetAsset(databaseId, greenId));
            // Ensure red wasn't modified
            this.VerifyRedAsset(uut.GetAsset(databaseId, redId));

            int blueId = this.AddBlueAsset(uut, databaseId, typeId);

            this.VerifyBlueAsset(uut.GetAsset(databaseId, blueId));
            // Ensure red and green weren't modified.
            this.VerifyRedAsset(uut.GetAsset(databaseId, redId));
            this.VerifyGreenAsset(uut.GetAsset(databaseId, greenId));

            // Add a duplicate color, blue 2.
            int blue2Id = this.AddBlueAsset(uut, databaseId, typeId);

            this.VerifyBlueAsset(uut.GetAsset(databaseId, blue2Id));
            // Ensure existing assets weren't modified.
            this.VerifyRedAsset(uut.GetAsset(databaseId, redId));
            this.VerifyGreenAsset(uut.GetAsset(databaseId, greenId));
            this.VerifyBlueAsset(uut.GetAsset(databaseId, blueId));

            // Remove duplicate blue ID
            uut.DeleteAsset(databaseId, typeId, blue2Id);
            Assert.Throws <ArgumentException>(() => uut.GetAsset(databaseId, blue2Id));    // <- Should not exist.
            // Ensure existing assets weren't modified.
            this.VerifyRedAsset(uut.GetAsset(databaseId, redId));
            this.VerifyGreenAsset(uut.GetAsset(databaseId, greenId));
            this.VerifyBlueAsset(uut.GetAsset(databaseId, blueId));

            // Edit red to make it slightly less red.
            {
                Asset redAsset = uut.GetAsset(databaseId, redId);
                AssetNameAttribute nameAttr = redAsset.CloneAttributeAsType <AssetNameAttribute>(nameKey);
                nameAttr.Value = "New Red!";
                redAsset.SetAttribute(nameKey, nameAttr);

                IntegerAttribute redAttr = redAsset.CloneAttributeAsType <IntegerAttribute>(redKey);
                redAttr.Value = 254;
                redAsset.SetAttribute(redKey, redAttr);

                IntegerAttribute greenAttr = redAsset.CloneAttributeAsType <IntegerAttribute>(greenKey);
                greenAttr.Value = 1;
                redAsset.SetAttribute(greenKey, greenAttr);

                IntegerAttribute blueAttr = redAsset.CloneAttributeAsType <IntegerAttribute>(blueKey);
                blueAttr.Value = 5;
                redAsset.SetAttribute(blueKey, blueAttr);

                uut.UpdateAsset(redId, redAsset);
                this.VerifyAsset(
                    uut.GetAsset(databaseId, redId),
                    nameAttr.Value,
                    redAttr.Value,
                    greenAttr.Value,
                    blueAttr.Value
                    );
            }

            AssetListInfo assetList = uut.GetAssetsOfType(databaseId, typeId);

            Assert.AreEqual(3, assetList.AssetList.Count);
            Assert.AreEqual(typeId, assetList.AssetTypeId);
            Assert.AreEqual(colorTypeName, assetList.AssetTypeName);
            Assert.AreEqual(databaseId, assetList.DatabaseId);
        }