コード例 #1
0
 public static DataSet ExecuteDataset(DatabaseEnum databaseName, CommandType commandType, string commandText, params SqlParameter[] parames)
 {
     return(ExecuteDataset(ConnectionStringFactory.CreateConnectionString(databaseName), commandType, commandText, parames));
 }
コード例 #2
0
        /// <summary>
        /// Monta a string de conexão a partir de um XML externo com os dados de login e servidor(BD),
        /// também define a base/catálogo inicial
        /// </summary>
        public void MountConnection(String xmlLocation, DatabaseEnum database)
        {
            String databaseName = GetDatabaseName(database);

            MountConnection(xmlLocation, databaseName);
        }
コード例 #3
0
 public static DataTable ExecuteTable(DatabaseEnum database, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
 {
     return(ExecuteTable(ConnectionStringFactory.CreateConnectionString(database), cmdType, cmdText, commandParameters));
 }
コード例 #4
0
 public static string CreateConnectionString(DatabaseEnum databaseEnum)
 {
     return(CreateConnectionString(databaseEnum.ToString()));
 }
コード例 #5
0
        public override void Execute(object parameter)
        {
            try
            {
                DatabaseConfigModel dbConfig = NetworkingViewModel.DatabaseConfigModel;

                DatabaseEnum databaseEnum = DataBaseSoft.TransDatabaseSoft(dbConfig.DatabaseSoft, dbConfig.IsAdvancedSetting);

                IDatabaseHelper db = DatabaseHelper.Open(databaseEnum, dbConfig.ConnectionString);
                ;

                string sql = null;
                if (dbConfig.DatabaseSoft == DatabaseSoft.SQLServer)
                {
                    sql = "select name from sys.databases";
                }
                else if (dbConfig.DatabaseSoft == DatabaseSoft.MySql)
                {
                    sql = " SHOW DATABASES ";
                }
                else if (dbConfig.DatabaseSoft == DatabaseSoft.PostgreSQL)
                {
                    sql = "SELECT datname FROM pg_database";
                }
                if (sql == null)
                {
                    return;
                }

                DataTable table = db.ExecuteQuery(sql);

                if (table == null)
                {
                    return;
                }

                var list = new ObservableCollection <string>();

                EnumerableRowCollection <string> en = null;
                if (table.Columns.Contains("datname"))
                {
                    en = table.AsEnumerable().Select(r => r["datname"].ToString());
                }
                else if (table.Columns.Contains("name"))
                {
                    en = table.AsEnumerable().Select(r => r["name"].ToString());
                }
                else
                {
                    en = table.AsEnumerable().Select(r => r["Database"].ToString());
                }

                foreach (string str in en)
                {
                    if (string.IsNullOrEmpty(str))
                    {
                        continue;
                    }

                    list.Add(str);
                }

                NetworkingViewModel.DatabaseList = list;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #6
0
        public override void Execute(object parameter)
        {
            DatabaseConfigModel dbConfig = NetworkingViewModel.DatabaseConfigModel;
            DataCallBackModel   dcModel  = NetworkingViewModel.DataCallBackModel;

            DatabaseEnum databaseEnum = DataBaseSoft.TransDatabaseSoft(dbConfig.DatabaseSoft, dbConfig.IsAdvancedSetting);

            IDatabaseHelper db = DatabaseHelper.Open(databaseEnum, dbConfig.ConnectionString);

            ;

            string tableName = string.Empty;

            if (dcModel.CallbackType == "表")
            {
                tableName = dcModel.TargetTableName;
            }
            else if (dcModel.CallbackType == "存储过程")
            {
                tableName = dcModel.TargetProcName;
            }

            if (string.IsNullOrEmpty(tableName))
            {
                return;
            }

            string sql = string.Empty;

            if (dbConfig.DatabaseSoft == DatabaseSoft.SQLServer)
            {
                sql =
                    string.Format(
                        "SELECT A.NAME,B.NAME AS TYPE,A.LENGTH,A.ISNULLABLE FROM SYSCOLUMNS A,SYSTYPES B,SYSOBJECTS D WHERE A.XTYPE=B.XUSERTYPE AND A.ID=D.ID AND A.ID =OBJECT_ID('{0}')",
                        tableName);
            }
            else if (dbConfig.DatabaseSoft == DatabaseSoft.Oracle)
            {
                if (dcModel.CallbackType == "表")
                {
                    sql =
                        string.Format(
                            "SELECT A.COLUMN_NAME AS NAME,A.DATA_TYPE AS TYPE,A.DATA_LENGTH AS LENGTH,A.NULLABLE AS ISNULLABLE FROM USER_TAB_COLS A WHERE UPPER(A.TABLE_NAME) = '{0}'",
                            tableName.ToUpper());
                }
                else
                {
                    sql =
                        string.Format(
                            "SELECT A.ARGUMENT_NAME AS NAME,A.DATA_TYPE AS TYPE,NVL(A.DATA_LENGTH,0) AS LENGTH, 0 AS ISNULLABLE FROM USER_ARGUMENTS A WHERE UPPER(A.OBJECT_NAME)='{0}' ORDER BY SEQUENCE",
                            tableName.ToUpper());
                }
            }
            else if (dbConfig.DatabaseSoft == DatabaseSoft.PostgreSQL)
            {
                sql =
                    string.Format(
                        "select a.column_name as Name, a.udt_name as TYPE,a.character_maximum_length as LENGTH, a.is_nullable as ISNULLABLE from information_schema.columns a where table_schema='public' and table_name='{0}'",
                        tableName);
            }
            else
            {
                if (dcModel.CallbackType == "表")
                {
                    sql =
                        string.Format(
                            "SELECT A.COLUMN_NAME AS NAME, A.DATA_TYPE TYPE,A.COLUMN_TYPE AS LENGTH,A.IS_NULLABLE AS ISNULLABLE FROM INFORMATION_SCHEMA.COLUMNS A WHERE A.TABLE_SCHEMA = '{0}' AND A.TABLE_NAME = '{1}'",
                            dbConfig.Database, tableName);
                }
                else
                {
                    sql =
                        string.Format(
                            "SELECT DB, TYPE, SPECIFIC_NAME, PARAM_LIST, RETURNS FROM MYSQL.PROC A WHERE UPPER(A.SPECIFIC_NAME) = '{0}'",
                            tableName.ToUpper());
                }
            }

            DataTable table = db.ExecuteQuery(sql);

            dcModel.CallbackTabelMap.Clear();

            if (!(dbConfig.DatabaseSoft == DatabaseSoft.MySql && dcModel.CallbackType == "存储过程"))
            {
                var regex = new Regex(@"^\d*$");

                foreach (DataRow row in table.AsEnumerable())
                {
                    string name = row["NAME"].ToString();

                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }

                    int    size   = -1;
                    string length = row["LENGTH"].ToString();

                    Match match = regex.Match(length);

                    if (match.Success && !string.IsNullOrEmpty(match.Value))
                    {
                        size = Convert.ToInt32(match.Value);
                    }

                    var tfmm = new TableFieldMapModel();

                    tfmm.LocalField  = row["NAME"].ToString();
                    tfmm.Type        = row["TYPE"].ToString();
                    tfmm.TargetField = "";
                    tfmm.Size        = size;

                    dcModel.CallbackTabelMap.Add(tfmm);
                }
            }
            else
            {
                DataRow dataRow = table.AsEnumerable().FirstOrDefault();

                if (dataRow != null)
                {
                    var parambytes = dataRow["PARAM_LIST"] as byte[];

                    var ue = new ASCIIEncoding();

                    string paramList = ue.GetString(parambytes);

                    if (!string.IsNullOrEmpty(paramList))
                    {
                        string[] paraml = paramList.Split(new string[1] {
                            ","
                        }, StringSplitOptions.RemoveEmptyEntries);

                        foreach (string param in paraml)
                        {
                            string value = param.Trim();
                            if (value.StartsWith("OUT"))
                            {
                                continue;
                            }

                            string[] values = value.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                            string   name   = string.Empty;
                            string   type   = string.Empty;

                            if (value.StartsWith("IN"))
                            {
                                name = values[1];
                                type = values[2];
                            }
                            else
                            {
                                name = values[0];
                                type = values[1];
                            }

                            var tfmm = new TableFieldMapModel();

                            tfmm.LocalField  = name;
                            tfmm.Type        = type;
                            tfmm.TargetField = "";
                            tfmm.Size        = 0;

                            dcModel.CallbackTabelMap.Add(tfmm);
                        }
                    }
                }
            }

            //NetworkingViewModel.TargetFieldList = list;
        }
コード例 #7
0
        public override void Execute(object parameter)
        {
            DatabaseConfigModel dbConfig     = NetworkingViewModel.DatabaseConfigModel;
            DatabaseEnum        databaseEnum = DataBaseSoft.TransDatabaseSoft(dbConfig.DatabaseSoft, dbConfig.IsAdvancedSetting);
            IDatabaseHelper     db           = DatabaseHelper.Open(databaseEnum, dbConfig.ConnectionString);

            if (string.IsNullOrEmpty(dbConfig.User) || string.IsNullOrEmpty(dbConfig.Password))
            {
                return;
            }
            string sql = null;

            string tableName = NetworkingViewModel.PatientMapModel.PatientTableName;

            if (string.IsNullOrEmpty(tableName))
            {
                return;
            }
            if (dbConfig.DatabaseSoft == DatabaseSoft.SQLServer)
            {
                sql =
                    string.Format(
                        "select a.name as ColumnName,b.name as type,a.length,a.isnullable from syscolumns a,systypes b,sysobjects d where a.xtype=b.xusertype and a.id=d.id and a.id =object_id('{0}')",
                        tableName);
            }
            else if (dbConfig.DatabaseSoft == DatabaseSoft.Oracle)
            {
                sql =
                    string.Format(
                        "SELECT A.TABLE_NAME   as TableName,A.COLUMN_NAME  as ColumnName,A.DATA_TYPE    as type,A.DATA_LENGTH  as length  FROM USER_TAB_COLS A  where A.TABLE_NAME  = '{0}'",
                        tableName.ToUpper());
            }
            else if (dbConfig.DatabaseSoft == DatabaseSoft.PostgreSQL)
            {
                sql =
                    string.Format(
                        "select a.column_name as ColumnName, a.udt_name as type,a.character_maximum_length as length, a.is_nullable as isnullable from information_schema.columns a where table_name='{0}'",
                        tableName);
            }
            else
            {
                sql =
                    string.Format(
                        "Select A.COLUMN_NAME as ColumnName, A.DATA_TYPE TYPE,A.COLUMN_TYPE as LENGTH,A.IS_NULLABLE as ISNULLABLE FROM INFORMATION_SCHEMA.COLUMNS A Where A.table_schema = '{0}' AND A.table_name = '{1}'",
                        dbConfig.Database, tableName);
            }

            DataTable table = db.ExecuteQuery(sql);

            var list = new ObservableCollection <string>();

            foreach (DataRow row in table.AsEnumerable())
            {
                string name = row["ColumnName"].ToString();

                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }

                list.Add(string.Format("[{0}]", name));
            }

            NetworkingViewModel.TargetFieldList = list;
        }