コード例 #1
0
ファイル: ResourceTool.cs プロジェクト: NALSS/epiinfo-82474
        void WriteResourcesToDatabase(GlobalizationDataSet ds, IDbDriver db)
        {
            AppendToLog("Please wait...");

            List<TableColumn> columns = new List<TableColumn>();

            columns.Add(new TableColumn("AssemblyName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ManifestResourceName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ResourceName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ResourceValue", GenericDbColumnType.StringLong, false));
            columns.Add(new TableColumn("ResourceType", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ResourceVersion", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("SourceCultureName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("SourceValue", GenericDbColumnType.StringLong, 255, false));

            //columns.Add(new TableColumn("CreationDate", GenericDbColumnType.String, 255, false));

            DbDriverInfo dbInfo = new DbDriverInfo();
            dbInfo.DBName = "CulturalResources";
            dbInfo.DBCnnStringBuilder = new System.Data.OleDb.OleDbConnectionStringBuilder();
            dbInfo.DBCnnStringBuilder.ConnectionString = db.ConnectionString;
            dbFactory.CreatePhysicalDatabase(dbInfo);
            //            db.CreateDatabase("CulturalResources");

            string tableName = ds.CulturalResources.TableName;

            db.CreateTable(tableName, columns);

            StringBuilder sb = new StringBuilder();
            sb.Append("insert into ");
            sb.Append(tableName);
            sb.Append(" (");
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append(columns[x].Name);
                if (x < columns.Count - 1)
                {
                    sb.Append(", ");
                }
            }
            sb.Append(") values ");
            sb.Append(" (");
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append("@");
                sb.Append(columns[x].Name);
                if (x < columns.Count - 1)
                {
                    sb.Append(", ");
                }
            }
            sb.Append(")");
            Query insertQuery = db.CreateQuery(sb.ToString());
            for (int x = 0; x < columns.Count; x++)
            {
                insertQuery.Parameters.Add(new QueryParameter("@" + columns[x].Name, DbType.String, columns[x].Name, columns[x].Name));
            }

            sb.Remove(0, sb.Length);

            sb.Append("update [").Append(tableName);
            sb.Append(StringLiterals.RIGHT_SQUARE_BRACKET).Append(StringLiterals.SPACE);
            sb.Append("set").Append(StringLiterals.SPACE);
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append(StringLiterals.LEFT_SQUARE_BRACKET);
                sb.Append(columns[x].Name);
                sb.Append(StringLiterals.RIGHT_SQUARE_BRACKET);
                sb.Append(StringLiterals.EQUAL);
                sb.Append("@NewValue").Append(StringLiterals.SPACE);
                sb.Append(", ");
            }
            sb.Append("where ");
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append(columns[x].Name).Append(StringLiterals.SPACE);
                sb.Append(StringLiterals.EQUAL);
                sb.Append("@OldValue");
                if (columns.Count > 1)
                {
                    sb.Append(" and");
                }
            }
            Query updateQuery = db.CreateQuery(sb.ToString());
            for (int x = 0; x < columns.Count; x++)
            {
                updateQuery.Parameters.Add(new QueryParameter("@NewValue", DbType.String, columns[x].Name, columns[x].Name));
                updateQuery.Parameters.Add(new QueryParameter("@OldValue", DbType.String, columns[x].Name, columns[x].Name));
                updateQuery.Parameters[1].SourceVersion = DataRowVersion.Original;
            }

            db.Update(ds.Tables[0], tableName, insertQuery, null);
        }
コード例 #2
0
        void WriteResourcesToDatabase(GlobalizationDataSet ds, IDbDriver db)
        {
            AppendToLog("Please wait...");

            List <TableColumn> columns = new List <TableColumn>();

            columns.Add(new TableColumn("AssemblyName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ManifestResourceName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ResourceName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ResourceValue", GenericDbColumnType.StringLong, false));
            columns.Add(new TableColumn("ResourceType", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ResourceVersion", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("SourceCultureName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("SourceValue", GenericDbColumnType.StringLong, 255, false));

            //columns.Add(new TableColumn("CreationDate", GenericDbColumnType.String, 255, false));

            DbDriverInfo dbInfo = new DbDriverInfo();

            dbInfo.DBName             = "CulturalResources";
            dbInfo.DBCnnStringBuilder = new System.Data.OleDb.OleDbConnectionStringBuilder();
            dbInfo.DBCnnStringBuilder.ConnectionString = db.ConnectionString;
            dbFactory.CreatePhysicalDatabase(dbInfo);
//            db.CreateDatabase("CulturalResources");

            string tableName = ds.CulturalResources.TableName;

            db.CreateTable(tableName, columns);

            StringBuilder sb = new StringBuilder();

            sb.Append("insert into ");
            sb.Append(tableName);
            sb.Append(" (");
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append(columns[x].Name);
                if (x < columns.Count - 1)
                {
                    sb.Append(", ");
                }
            }
            sb.Append(") values ");
            sb.Append(" (");
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append("@");
                sb.Append(columns[x].Name);
                if (x < columns.Count - 1)
                {
                    sb.Append(", ");
                }
            }
            sb.Append(")");
            Query insertQuery = db.CreateQuery(sb.ToString());

            for (int x = 0; x < columns.Count; x++)
            {
                insertQuery.Parameters.Add(new QueryParameter("@" + columns[x].Name, DbType.String, columns[x].Name, columns[x].Name));
            }

            sb.Remove(0, sb.Length);

            sb.Append("update [").Append(tableName);
            sb.Append(StringLiterals.RIGHT_SQUARE_BRACKET).Append(StringLiterals.SPACE);
            sb.Append("set").Append(StringLiterals.SPACE);
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append(StringLiterals.LEFT_SQUARE_BRACKET);
                sb.Append(columns[x].Name);
                sb.Append(StringLiterals.RIGHT_SQUARE_BRACKET);
                sb.Append(StringLiterals.EQUAL);
                sb.Append("@NewValue").Append(StringLiterals.SPACE);
                sb.Append(", ");
            }
            sb.Append("where ");
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append(columns[x].Name).Append(StringLiterals.SPACE);
                sb.Append(StringLiterals.EQUAL);
                sb.Append("@OldValue");
                if (columns.Count > 1)
                {
                    sb.Append(" and");
                }
            }
            Query updateQuery = db.CreateQuery(sb.ToString());

            for (int x = 0; x < columns.Count; x++)
            {
                updateQuery.Parameters.Add(new QueryParameter("@NewValue", DbType.String, columns[x].Name, columns[x].Name));
                updateQuery.Parameters.Add(new QueryParameter("@OldValue", DbType.String, columns[x].Name, columns[x].Name));
                updateQuery.Parameters[1].SourceVersion = DataRowVersion.Original;
            }


            db.Update(ds.Tables[0], tableName, insertQuery, null);
        }