static string GenerateApplicationErrorScript(Options options) { GenericSqlCommand command = new GenericSqlCommand("ConnectionString"); DataTable table = command.ExecuteQueryForDataTable(" SELECT * FROM tb_Application_Error WHERE ApplicationId IN ( SELECT Id FROM tb_Application WHERE ApplicationName = '" + options.ApplicationName + "' ) ORDER BY ParentId, OrderId "); return(SqlScriptHelper.GenerateDateTableScript("", "tb_Application_Error", table)); }
static string GenerateApplicationMenuScopeScript(Options options) { GenericSqlCommand command = new GenericSqlCommand("ConnectionString"); DataTable table = command.ExecuteQueryForDataTable(" SELECT * FROM tb_Application_Menu_Scope WHERE EntityId IN ( SELECT Id FROM tb_Application_Menu WHERE ApplicationId IN ( SELECT Id FROM tb_Application WHERE ApplicationName = '" + options.ApplicationName + "' ) ) ORDER BY EntityId, AuthorizationObjectType "); return(SqlScriptHelper.GenerateDateTableScript("", "tb_Application_Menu_Scope", table)); }
static string GenerateApplicationScript(Options options) { GenericSqlCommand command = new GenericSqlCommand("ConnectionString"); DataTable table = command.ExecuteQueryForDataTable(" SELECT * FROM tb_Application WHERE ApplicationName = '" + options.ApplicationName + "' "); return(SqlScriptHelper.GenerateDateTableScript("", "tb_Application", table)); }
/// <summary> /// 取得数据库名称 /// </summary> /// <param name="tableName">数据表</param> /// <returns>数据库名称</returns> public DataColumnSchemaCollection GetColumns(string databaseName, string ownerName, string tableName) { DataColumnSchemaCollection list = new DataColumnSchemaCollection(); GenericSqlCommand command = new GenericSqlCommand(connectionString, "OracleClient"); string commandText = string.Format(@" select column_id, column_name, data_type, data_length, data_precision, data_scale, nullable, data_default from user_tab_columns where table_name = '{0}' order by column_id", tableName); var table = command.ExecuteQueryForDataTable(commandText); foreach (DataRow row in table.Rows) { DataColumnSchema item = new DataColumnSchema(); item.Name = row["column_name"].ToString().ToLower(); item.Type = SetDataType(row["data_type"].ToString()); item.Nullable = (row["nullable"].ToString() == "N") ? false : true; switch (item.Type) { case DbType.String: item.Length = (row["data_length"] == DBNull.Value) ? 0 : Convert.ToInt32(row["data_length"].ToString()); break; case DbType.Decimal: // item.Precision = (dr["Precision"] == DBNull.Value) ? (byte)0 : (byte)dr["Precision"]; // item.Scale = (dr["Scale"] == DBNull.Value) ? 0 : (int)dr["Scale"]; break; default: break; } list.Add(item); } return(list); }
/// <summary>查询数据库中表的外键字段信息</summary> /// <param name="databaseName">数据库</param> /// <param name="ownerName">所有者</param> /// <param name="tableName">表名</param> /// <returns>外键字段信息集合</returns> public DataColumnSchemaCollection GetForeignKeyColumns(string databaseName, string ownerName, string tableName) { DataColumnSchemaCollection list = new DataColumnSchemaCollection(); GenericSqlCommand command = new GenericSqlCommand(connectionString, "SQLite"); string commandText = string.Format("SHOW FULL FIELDS FROM {1} FROM {0} WHERE `Key`='MUL'", databaseName, tableName); var table = command.ExecuteQueryForDataTable(commandText); foreach (DataRow row in table.Rows) { DataColumnSchema item = new DataColumnSchema(); item.Name = row["Field"].ToString(); list.Add(item); } return(list); }
/// <summary></summary> public override string ParseHtml() { try { string widgetRuntimeId = StringHelper.ToGuid(); VelocityContext context = new VelocityContext(); context.Put("widgetRuntimeId", widgetRuntimeId); context.Put("height", (this.Height == 0 ? "height:auto;" : "height:" + this.Height + "px;")); context.Put("width", (this.Width == 0 ? "width:auto;" : "width:" + this.Width + "px;")); // 设置最大行数 int maxRowCount; int.TryParse(this.options["maxRowCount"], out maxRowCount); if (maxRowCount < 1) { maxRowCount = 1; } if (maxRowCount > 100) { maxRowCount = 100; } string tableName = this.options["tableName"].ToString(); string tableColumns = this.options["tableColumns"].ToString(); string url = this.options["url"].ToString(); if (string.IsNullOrEmpty(tableName)) { context.Put("widgetHtml", "请配置相关数据"); } else { var connection = KernelConfigurationView.Instance.ConnectionPlugin; string commandText = null; if (connection.Provider == "MySql") { commandText = " SELECT " + tableColumns + " FROM " + this.options["tableName"] + " ORDER BY " + this.options["orderBy"] + " LIMIT " + maxRowCount; } else { commandText = " SELECT TOP " + maxRowCount + " " + tableColumns + " FROM " + this.options["tableName"] + " ORDER BY " + this.options["orderBy"]; } GenericSqlCommand command = new GenericSqlCommand(connection.ConnectionString, connection.Provider); DataTable table = command.ExecuteQueryForDataTable(StringHelper.ToSafeSQL(commandText)); StringBuilder outString = new StringBuilder(); outString.Append("<div style=\"padding:0 10px 10px 10px;\" >"); for (int i = 0; i < table.Rows.Count; i++) { outString.Append("<div style=\"padding:10px 0 0 0 ;\" ><a href=\"" + string.Format(url, table.Rows[i][0].ToString()) + "\" target=\"_blank\" >" + HttpUtility.HtmlEncode(table.Rows[i][1].ToString()) + "</a></div>"); } outString.Append("</div>"); context.Put("widgetHtml", outString.ToString()); } return(VelocityManager.Instance.Merge(context, "themes/" + WebConfigurationView.Instance.ThemeName + "/widgets/general.vm")); } catch (Exception ex) { return(ex.Message); } }
public string Generate() { StringBuilder outString = new StringBuilder(); // 执行依赖任务 if (!string.IsNullOrEmpty(task.Depends)) { string[] depends = task.Depends.Split(','); foreach (string depend in depends) { // 任务不能自身依赖 避免发生循环引用 if (depend == task.Name) { continue; } DataDumpTask dependTask = DataDumpConfiguration.Instance.Tasks[depend]; // 重写依赖任务的参数选项和输出数据库类型 dependTask.Options = task.Options; dependTask.OutputDbType = task.OutputDbType; IDataDumpProvider dependProvider = (IDataDumpProvider)KernelContext.CreateObject(dependTask.DataDumpProvider); dependProvider.Init(dependTask); outString.AppendLine(dependProvider.Generate()); } } // 执行任务 string comment, result; foreach (TaskStatement statement in task.Statements) { comment = null; result = null; if (!string.IsNullOrEmpty(statement.Description)) { string[] descriptionLines = statement.Description.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string descriptionLine in descriptionLines) { if (!string.IsNullOrEmpty(descriptionLine.Trim())) { comment += "-- " + descriptionLine.Trim() + Environment.NewLine; } } } GenericSqlCommand command = new GenericSqlCommand(task.DataSourceName); string sql = statement.Sql; foreach (KeyValuePair <string, string> option in options) { sql = sql.Replace("$" + option.Key + "$", option.Value); } DataTable table = command.ExecuteQueryForDataTable(sql); if (table.Rows.Count == 0) { continue; } result = SqlScriptHelper.GenerateDateTableScript(task.OutputDbType, statement.DestTable, table); outString.Append(comment); outString.AppendLine(result); } return(outString.ToString()); }