Beispiel #1
0
 /// <summary>
 /// Gets the external connection string.
 /// </summary>
 /// <param name="dataSourceName">Name of the data source.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="databaseType">Type of the database.</param>
 /// <returns></returns>
 public string GetExternalConnectionString(out string tableName, out DataBaseTypeEnum databaseType)
 {
     // TODO: Implement this method
     tableName    = null;
     databaseType = default(DataBaseTypeEnum);
     throw new NotImplementedException();
 }
Beispiel #2
0
        /// <summary>
        /// Gets the external connection string to retrieve data for analysis.  Not to je confused with the
        /// metadata Connection string which is used to connect to the Ewav database
        /// </summary>
        /// <param name="dataSourceName">Name of the data source.</param>
        /// <returns></returns>
        public string GetExternalConnectionString(string dataSourceName)
        {
            //string queryString =
            //    string.Format("SELECT *  FROM {0} WHERE DatasourceName =  '{1}'", this.MetaDataViewName, dataSourceName);
            string queryString = string.Format("Call usp_read_external_connec_str ('{0}', '{1}') ", this.MetaDataViewName, dataSourceName);

            MySqlConnection conn = new MySqlConnection(this.MetaDataConnectionString);

            // Create the Command and Parameter objects.
            MySqlCommand command = new MySqlCommand(queryString, conn);

            // create a new data adapter based on the specified query.
            MySqlDataAdapter da = new MySqlDataAdapter();

            //set the SelectCommand of the adapter
            da.SelectCommand = command;
            // create a new DataTable
            DataTable dtGet = new DataTable();

            //fill the DataTable
            da.Fill(dtGet);

            //string extConnectionString =
            //    string.Format("Data Source={0};Initial Catalog={1};Persist Security Info={2};User ID={3};Password={4}", dtGet.Rows[0]["DatasourceServerName"].ToString(), dtGet.Rows[0]["InitialCatalog"], dtGet.Rows[0]["PersistSecurityInfo"], dtGet.Rows[0]["DatabaseUserID"], dtGet.Rows[0]["Password"]);                  //     shorterd01"

            string extConnectionString = " ";

            string datasourceType = dtGet.Rows[0]["DatabaseType"].ToString();

            DataBaseTypeEnum dataBaseTypeEnum = (DataBaseTypeEnum)Enum.Parse(typeof(DataBaseTypeEnum), datasourceType);

            extConnectionString = Utilities.CreateConnectionString(dataBaseTypeEnum, new DataRow[] { dtGet.Rows[0] });

            return(extConnectionString);
        }
Beispiel #3
0
 /// <summary>
 /// 获取数据库连接字符串
 /// </summary>
 /// <param name="dbName"></param>
 /// <param name="dataBaseTypeEnum">数据库类型枚举</param>
 /// <returns></returns>
 public static string GetDbConnectionString(string dbName = "default", DataBaseTypeEnum dataBaseTypeEnum = DataBaseTypeEnum.Write)
 {
     try
     {
         string   configFilePath = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/connectionStrings.config";
         XElement root           = XElement.Load(configFilePath);
         XElement dbNode         = null;
         if (dbName == "default")
         {
             dbNode = root.Elements().Where(e => e.Attribute("default").Value == "true").FirstOrDefault();
         }
         else
         {
             dbNode = root.Elements().Where(e => e.Attribute("name").Value.ToLower() == dbName.ToLower()).FirstOrDefault();
         }
         if (dbNode == null)
         {
             throw new Exception("未找到名称为:{0}的数据库配置节点");
         }
         if (dataBaseTypeEnum == DataBaseTypeEnum.Write)
         {
             return(dbNode.Element("Write").Attribute("connectionString").Value);
         }
         else
         {
             return(dbNode.Element("Read").Attribute("connectionString").Value);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("数据库配置文件配置错误", ex);
     }
 }
        /// <summary>
        /// Creates the connection string.
        /// </summary>
        /// <param name="externalDataBaseType">Type of the external data base.</param>
        /// <param name="dr">The dr.</param>
        /// <returns></returns>
        public static string xcreateConnectionString(DataBaseTypeEnum externalDataBaseType, DataRow[] dr)
        {
            string extConnectionString;

            switch (externalDataBaseType)
            {
            case DataBaseTypeEnum.MySQL:

                extConnectionString =
                    string.Format("Server={0};Database={1};User Id={2};Pwd={3}", dr[0]["DatasourceServerName"].ToString(), dr[0]["InitialCatalog"], dr[0]["DatabaseUserID"], dr[0]["Password"]);                      //     shorterd01"

                break;

            case DataBaseTypeEnum.PostgreSQL:

                extConnectionString = "";

                break;

            case DataBaseTypeEnum.SQLServer:

                extConnectionString =
                    string.Format("Data Source={0};Initial Catalog={1};Persist Security Info={2};User ID={3};Password={4}", dr[0]["DatasourceServerName"].ToString(), dr[0]["InitialCatalog"], dr[0]["PersistSecurityInfo"], dr[0]["UserID"], dr[0]["Password"]);                      //     shorterd01"

                break;

            default:
                extConnectionString = "";

                break;
            }

            return(extConnectionString);
        }
Beispiel #5
0
        public static DataBaseTypeEnum GetDbType(string providerName)
        {
            DataBaseTypeEnum dbType = DataBaseTypeEnum.SqlServer;

            if (string.IsNullOrEmpty(providerName))
            {
                throw new Exception("连接字符串未定义 ProviderName");
            }
            else if (providerName == "System.Data.SqlClient")
            {
                dbType = DataBaseTypeEnum.SqlServer;
            }
            else if (providerName == "Oracle.DataAccess.Client")
            {
                dbType = DataBaseTypeEnum.Oracle;
            }
            else if (providerName == "System.Data.OracleClient")
            {
                dbType = DataBaseTypeEnum.Oracle;
            }
            else if (providerName == "MySql.Data.MySqlClient")
            {
                dbType = DataBaseTypeEnum.MySql;
            }
            else if (providerName == "System.Data.OleDb")
            {
                dbType = DataBaseTypeEnum.Aceess;
            }
            else
            {
                throw new Exception("连接字符串未识别 ProviderName");
            }
            return(dbType);
        }
 public DbContextFactory(DataBaseTypeEnum dbType, DB dbName, bool isRead = true, bool isDBMS = false)
 {
     DbType = dbType;
     DbName = dbName;
     IsRead = isRead;
     IsDBMS = isDBMS;
 }
Beispiel #7
0
        private string GetTimeData(string variable, DataBaseTypeEnum dbType)
        {
            variable = DateTime.Parse(variable).ToString("yyyy-MM-dd HH:mm:ss");
            switch (dbType)
            {
            case DataBaseTypeEnum.SQLServer:
                variable = "Convert(datetime,'" + variable + "',120)";
                break;

            case DataBaseTypeEnum.Oracle:
                variable = "to_date('" + variable + "','yyyy-mm-dd hh24:mi:ss')";
                break;

            case DataBaseTypeEnum.Access:

                break;

            case DataBaseTypeEnum.SQLite:

                break;

            case DataBaseTypeEnum.MySql:
                variable = "date_format('" + variable + "', '%Y-%m-%d %H:%i:%S')";
                break;
            }
            return(variable);
        }
Beispiel #8
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dataBaseType"></param>
        public ServerAdapter(DataBaseTypeEnum dataBaseType)
        {
            var config = new SqliteDataAccess().GetConfigModels();

            if (config == null || !config.Any())
            {
                return;
            }
            if (dataBaseType == DataBaseTypeEnum.NotDesignated)
            {
                return;
            }
            ServerList = new List <BaseServer>();

            if ((dataBaseType & DataBaseTypeEnum.SqlServer) == DataBaseTypeEnum.SqlServer)
            {
                var tempConfigList = config.Where(f => f.DbType == DataBaseTypeEnum.SqlServer && f.IsEnable == IsEnableEnum.Enable).ToList();
                if (tempConfigList != null && tempConfigList.Count > 0)
                {
                    foreach (var tempConfig in tempConfigList)
                    {
                        if (!string.IsNullOrEmpty(tempConfig?.LinkConnectionString))
                        {
                            ServerList.Add(new BaseServer(tempConfig.LinkConnectionString, new SqlServerDataAccess(), DataBaseTypeEnum.SqlServer));
                        }
                    }
                }
            }
            if ((dataBaseType & DataBaseTypeEnum.MySql) == DataBaseTypeEnum.MySql)
            {
                var tempConfigList = config.Where(f => f.DbType == DataBaseTypeEnum.MySql && f.IsEnable == IsEnableEnum.Enable).ToList();
                if (tempConfigList != null && tempConfigList.Count > 0)
                {
                    foreach (var tempConfig in tempConfigList)
                    {
                        if (!string.IsNullOrEmpty(tempConfig?.LinkConnectionString))
                        {
                            ServerList.Add(new BaseServer(tempConfig.LinkConnectionString, new MySqlDataAccess(), DataBaseTypeEnum.MySql));
                        }
                    }
                }
            }
            if ((dataBaseType & DataBaseTypeEnum.Oracle) == DataBaseTypeEnum.Oracle)
            {
                var tempConfigList = config.Where(f => f.DbType == DataBaseTypeEnum.Oracle && f.IsEnable == IsEnableEnum.Enable).ToList();
                if (tempConfigList != null && tempConfigList.Count > 0)
                {
                    foreach (var tempConfig in tempConfigList)
                    {
                        if (!string.IsNullOrEmpty(tempConfig?.LinkConnectionString))
                        {
                            ServerList.Add(new BaseServer(tempConfig.LinkConnectionString, new OracleDataAccess(), DataBaseTypeEnum.Oracle));
                        }
                    }
                }
            }
        }
Beispiel #9
0
        public static IDbConnection GetConnection(string dbName, DataBaseTypeEnum dataBaseType)
        {
            DbName = dbName;
            var factory = DbProviderFactories.GetFactory(ProviderName);

            var dbConnection = factory.CreateConnection();

            dbConnection.ConnectionString = ConnectionString;
            return(dbConnection);
        }
 /// <summary>
 /// 有参构造函数
 /// </summary>
 /// <param name="connectionString">数据库连接字符串</param>
 /// <param name="dataBaseType">数据库类型</param>
 public DataAccess(string connectionString, DataBaseTypeEnum dataBaseType)
 {
     if (string.IsNullOrEmpty(connectionString))
     {
         _logger.LogError("创建数据库连接失败,错误信息:数据库连接字符串为空");
         throw new ArgumentNullException("Connection String is null or empty");
     }
     _connectionString = connectionString;
     _dataBaseType     = dataBaseType;
 }
Beispiel #11
0
 /// <summary>
 /// 初始化连接池
 /// </summary>
 private void InitPools(DataBaseTypeEnum type, int maxLength)
 {
     if (_connections == null)
     {
         _connections = new Connection[maxLength];
     }
     for (int i = 0; i < MaxLength; i++)
     {
         var conn = new Connection(DataBaseType);
         _connections.SetValue(conn, i);
     }
 }
Beispiel #12
0
        /// <summary>
        /// 获取视图信息
        /// </summary>
        /// <param name="dataBaseName"></param>
        /// <param name="tableName"></param>
        /// <param name="dbType"></param>
        /// <returns></returns>
        public static View GetViewInfo(string dataBaseName, string tableName, DataBaseTypeEnum dbType)
        {
            var serverAdapter = new ServerAdapter(dbType);

            if (serverAdapter.ServerList == null || !serverAdapter.ServerList.Any())
            {
                return(null);
            }
            var baseServer = serverAdapter.ServerList.First();

            return(baseServer.DbBaseTableAccess.GetViewInfo(baseServer.ConnectionString, dataBaseName, tableName));
        }
Beispiel #13
0
        public DbContext(string connectionSeting)
        {
            _connectionSeting = connectionSeting;
            Connection        = new SqlConnection(_connectionSeting);

            if (Connection == null)
            {
                throw new Exception("Connection为null");
            }

            DatabaseType = GetDataBaseType.GetDbType("System.Data.SqlClient");

            InitConnection();
        }
Beispiel #14
0
        private void ExportInsert()
        {
            string sqlmsg = "";
            string rstmsg = "";
            string sql    = textEditorControl.ActiveTextAreaControl.TextArea.SelectionManager.SelectedText.Trim();

            if (sql == "")
            {
                sql = textEditorControl.Text.Trim();
            }
            if (sql == "")
            {
                return;
            }
            sql = GetSqlZC(sql);
            sql = sql.Replace("\r\n", " ");

            ListItem item = DBToolStripComboBox.SelectedItem as ListItem;

            int DbLinkID = int.Parse(item.ID.ToString());

            if (DbLinkID == 0)
            {
                MessageBox.Show("请选择数据库");
            }
            IDbLink    ldal   = new DbLink();
            DbLinkInfo dlinfo = ldal.DbLinkGetInfo(DbLinkID);
            DataSet    ds     = dal.Run(dlinfo, sql, out sqlmsg, out rstmsg);

            if (ds != null && ds.Tables != null && ds.Tables[0].Rows.Count > 0)
            {
                DataBaseTypeEnum dbtype       = DataBaseTypeEnum.SQLServer;
                string           TargetDbType = toolStripComboBox_TargetDbType.Text;

                if (TargetDbType == "SQLServer")
                {
                    dbtype = DataBaseTypeEnum.SQLServer;
                }
                else if (TargetDbType == "Oracle")
                {
                    dbtype = DataBaseTypeEnum.Oracle;
                }
                else if (TargetDbType == "MySql")
                {
                    dbtype = DataBaseTypeEnum.MySql;
                }
                string strSql = GetInserSql(ds.Tables[0], dbtype, out rstmsg);
                Clipboard.SetDataObject(strSql);
            }
        }
Beispiel #15
0
 /// <summary>
 /// 单例模式
 /// </summary>
 /// <param name="type"></param>
 /// <param name="maxLength"></param>
 /// <returns></returns>
 public ConnectionPools CreateInstance(DataBaseTypeEnum type, int maxLength)
 {
     if (_pools == null)
     {
         lock (_lockObj)
         {
             if (_pools == null)
             {
                 return(new ConnectionPools(type, maxLength));
             }
         }
     }
     return(_pools);
 }
Beispiel #16
0
        /// <summary>
        /// Gets the external connection string to retrieve data for analysis.  Not to je confused with the
        /// metadata Connection string which is used to connect to the Ewav database
        /// </summary>
        /// <param name="dataSourceName">Name of the data source.</param>
        /// <returns></returns>
        public string GetExternalConnectionString(string dataSourceName)
        {
            SqlDatabase ewavDB = new SqlDatabase(this.MetaDataConnectionString);

            DataTable dtExternal = ewavDB.ExecuteDataSet("usp_read_external_connec_str", this.MetaDataViewName, dataSourceName).Tables[0];

            DataBaseTypeEnum dataBaseTypeEnum = ((DataBaseTypeEnum)Enum.Parse(typeof(DataBaseTypeEnum),
                                                                              dtExternal.Rows[0]["DatabaseType"].ToString()));

            string extConnectionString = " ";

            extConnectionString = Utilities.CreateConnectionString(dataBaseTypeEnum, new DataRow[] { dtExternal.Rows[0] });

            return(extConnectionString);
        }
Beispiel #17
0
        public DbContext(string connectionSeting, ITransaction tran, bool isWrite = true)
        {
            _connectionSeting = connectionSeting;
            Connection        = new SqlConnection(_connectionSeting.ToString());

            if (Connection == null)
            {
                throw new Exception("Connection为null");
            }

            DatabaseType = GetDataBaseType.GetDbType("System.Data.SqlClient");

            transaction = tran;
            InitConnection();
        }
Beispiel #18
0
        // todo
        public static IDbConnection GetConnection(DataBaseTypeEnum providerType)
        {
            IDbConnection iDbConnection;

            switch (providerType)
            {
            case DataBaseTypeEnum.SqlServer:
                iDbConnection = new SqlConnection();
                break;

            default:
                return(null);
            }

            return(iDbConnection);
        }
Beispiel #19
0
        /// <summary>
        /// Gets the factory.
        /// </summary>
        /// <param name="dataBaseTypeEnum">The data base type enum.</param>
        /// <returns></returns>
        public static IDaoFactory GetFactory(DataBaseTypeEnum dataBaseTypeEnum)
        {
            switch (dataBaseTypeEnum)
            {
            case DataBaseTypeEnum.MySQL:
                return(new MySqlDaoFactory());

            case DataBaseTypeEnum.SQLServer:
                return(new SqlServerDaoFactory());

            case DataBaseTypeEnum.PostgreSQL:
                return(new PostgreSQLDaoFactory());

            // default:
            default:
                throw new ApplicationException(string.Format("Database type {0} is not supported ", dataBaseTypeEnum.ToString()));
            }
        }
        /// <summary>
        /// Columnses as list.
        /// </summary>
        /// <returns></returns>
        public List <EwavColumn> GetColumnsForDatasource(string dataSourceName, string userName, DataTable dt)
        {
            // select the right one
            DataRow[] dr = dt.Select(string.Format("DatasourceName = '{0}' ", dataSourceName));
            // convert type to enum
            DataBaseTypeEnum externalDataBaseType =
                (DataBaseTypeEnum)Enum.Parse(typeof(DataBaseTypeEnum), dr[0]["DataBaseType"].ToString());

            string externalDataConnectionString = Ewav.DAL.Utilities.CreateConnectionString(externalDataBaseType, dr);

            // Get the right factory
            string externalDataViewName = dr[0]["DatabaseObject"].ToString();

            DAL.Interfaces.IDaoFactory externalDaoFactory =
                DaoFatories.GetFactory(externalDataBaseType, externalDataConnectionString, externalDataViewName);

            // Get the columns
            DataTable dtColumns = externalDaoFactory.RawDataDao.GetColumnsForDatasource(dr);

            // create list of EwavColumn
            List <EwavColumn> ewavColumns = new List <EwavColumn>();

            try
            {
                foreach (DataColumn col in dtColumns.Columns)
                {
                    EwavColumn ec = new EwavColumn
                    {
                        Index = ewavColumns.Count,
                        Name  = col.ColumnName,
                        SqlDataTypeAsString = Ewav.BAL.Common.GetDBType(col.DataType)
                    };

                    ewavColumns.Add(ec);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error with data columns == " + ex.Message + ex.StackTrace);
            }

            return(ewavColumns);
        }
Beispiel #21
0
        private DbConnection CreateConnection(DataBaseTypeEnum type)
        {
            DbConnection conn = null;

            switch (type)
            {
            case DataBaseTypeEnum.SqlService:
                //conn = new SqlConnection();
                break;

            case DataBaseTypeEnum.MyService:
                conn = new MySqlConnection();
                break;

            default:
                break;
            }
            return(conn);
        }
        public static DataBaseTypeEnum GetDataBaseType(int id)
        {
            DataBaseTypeEnum fc = DataBaseTypeEnum.None;

            switch (id)
            {
            case (int)DataBaseTypeEnum.None:
                fc = DataBaseTypeEnum.None;
                break;

            case (int)DataBaseTypeEnum.SQLServer:
                fc = DataBaseTypeEnum.SQLServer;
                break;

            case (int)DataBaseTypeEnum.Oracle:
                fc = DataBaseTypeEnum.Oracle;
                break;

            case (int)DataBaseTypeEnum.Access:
                fc = DataBaseTypeEnum.Access;
                break;

            case (int)DataBaseTypeEnum.SQLite:
                fc = DataBaseTypeEnum.SQLite;
                break;

            case (int)DataBaseTypeEnum.MySql:
                fc = DataBaseTypeEnum.MySql;
                break;
                //case (int)DataBaseTypeEnum.PDM:
                //    fc = DataBaseTypeEnum.PDM;
                //    break;
                //case (int)DataBaseTypeEnum.MongoDB:
                //    fc = DataBaseTypeEnum.MongoDB;
                //    break;
                //case (int)DataBaseTypeEnum.Redis:
                //    fc = DataBaseTypeEnum.Redis;
                //    break;
            }
            return(fc);
        }
Beispiel #23
0
        /// <summary>
        /// Handles the Loaded event of the AddEditDataSources control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
        void AddEditDataSources_Loaded(object sender, RoutedEventArgs e)
        {
            DataBaseTypeEnum dbenum = DataBaseTypeEnum.MySQL;

            cmbDBType.ItemsSource = System.Enum.GetValues(dbenum.GetType());

            if (SelectedDatasourceDto != null)
            {
                adminVM = new AdminDatasourceViewModel();
                adminVM.ReadAssociatedUsers(this.SelectedDatasourceDto.DatasourceId, this.SelectedDatasourceDto.OrganizationId);
                adminVM.ReadAssociatedUsersCompletedEvent -= new EventHandler <SimpleMvvmToolkit.NotificationEventArgs <Exception> >(adminVM_ReadAssociatedUsersCompletedEvent);
                adminVM.ReadAssociatedUsersCompletedEvent += new EventHandler <SimpleMvvmToolkit.NotificationEventArgs <Exception> >(adminVM_ReadAssociatedUsersCompletedEvent);
                PopulatePage();
            }
            else
            {
                //SelectedDatasourceDto = new DatasourceDto();
                adminVM = new AdminDatasourceViewModel();
                ReadAllUsers();
            }
        }
Beispiel #24
0
        /// <summary>
        /// Handles the Click event of the btnStep1Next control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void btnStep1Next_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            DataBaseTypeEnum dbTypeSelected = (DataBaseTypeEnum)(Enum.Parse(typeof(DataBaseTypeEnum), cmbDBType.SelectedItem.ToString(), true));

            if (ApplicationViewModel.Instance.IsEpiWebIntegrationEnabled &&
                dbTypeSelected == DataBaseTypeEnum.SQLServer &&
                (bool)chkEpiForm.IsChecked)//Only if integration is enabled. && for SQLServer
            {
                localDto.IsEpiInfoForm = true;
                EWEDatasourceDto EWEDsDTO = new EWEDatasourceDto();
                EWEDsDTO.DatabaseName = localDto.Connection.DatabaseName;

                adminVM.ReadEWEDatasourceFormId(EWEDsDTO);
                adminVM.ReadEweFormIdCompletedEvent -= new EventHandler <SimpleMvvmToolkit.NotificationEventArgs <Exception> >(adminVM_ReadEweFormIdCompletedEvent);
                adminVM.ReadEweFormIdCompletedEvent += new EventHandler <SimpleMvvmToolkit.NotificationEventArgs <Exception> >(adminVM_ReadEweFormIdCompletedEvent);
            }
            else
            {
                localDto.IsEpiInfoForm = false;
                NavigateToStep2();
            }
        }
        /// <summary>
        /// Gets the external connection string.
        /// </summary>
        /// <param name="dataSourceName">Name of the data source.</param>
        /// <returns></returns>
        public string GetExternalConnectionString(string dataSourceName)
        {
            DataTable     dtGet;
            PostgreSQLDB  ewavDB  = new PostgreSQLDB(this.MetaDataConnectionString);
            NpgsqlCommand Command = new NpgsqlCommand();

            Command.CommandType = CommandType.StoredProcedure;
            Command.CommandText = "read_external_connec_str";

            NpgsqlParameter parameter = new NpgsqlParameter("dsname", NpgsqlTypes.NpgsqlDbType.Varchar);

            parameter.Value     = dataSourceName;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("dbobject", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = this.MetaDataViewName;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);
            try
            {
                dtGet = ewavDB.ExecuteDataSet(Command).Tables[0];
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            DataBaseTypeEnum dataBaseTypeEnum = ((DataBaseTypeEnum)Enum.Parse(typeof(DataBaseTypeEnum),
                                                                              dtGet.Rows[0]["DatabaseType"].ToString()));

            string extConnectionString = " ";

            extConnectionString = Utilities.CreateConnectionString(dataBaseTypeEnum, new DataRow[] { dtGet.Rows[0] });

            return(extConnectionString);
        }
Beispiel #26
0
        private void cmbDBType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.SelectedDatasourceDto != null && this.SelectedDatasourceDto.Connection != null)
            {
                tbPort.Text = this.SelectedDatasourceDto.Connection.PortNumber.ToString();
            }
            else
            {
                DataBaseTypeEnum dbTypeSelected = (DataBaseTypeEnum)(Enum.Parse(typeof(DataBaseTypeEnum), cmbDBType.SelectedItem.ToString(), true));

                switch (dbTypeSelected)
                {
                case DataBaseTypeEnum.MySQL:
                    tbPort.Text           = DatabaseDefaultPorts.MySQL;
                    chkEpiForm.Visibility = System.Windows.Visibility.Collapsed;
                    break;

                case DataBaseTypeEnum.PostgreSQL:
                    tbPort.Text           = DatabaseDefaultPorts.PostgreSQL;
                    chkEpiForm.Visibility = System.Windows.Visibility.Collapsed;
                    break;

                case DataBaseTypeEnum.SQLServer:
                    tbPort.Text = DatabaseDefaultPorts.SQLServer;
                    if (ApplicationViewModel.Instance.IsEpiWebIntegrationEnabled)
                    {
                        chkEpiForm.Visibility = System.Windows.Visibility.Visible;
                    }

                    break;

                default:
                    chkEpiForm.Visibility = System.Windows.Visibility.Collapsed;
                    break;
                }
            }
        }
Beispiel #27
0
 public Connection(DataBaseTypeEnum type)
 {
     IsUsed       = false;
     DbConnection = CreateConnection(type);
 }
Beispiel #28
0
        private string GetInserSql(DataTable dt, DataBaseTypeEnum dbType, out string rstmsg)
        {
            TableInfo tInfo = new TableInfo();

            rstmsg = "";
            string        sql     = "";
            List <string> listSql = new List <string>();
            string        field   = "";

            foreach (DataColumn col in dt.Columns)
            {
                field += field == "" ? col.ColumnName : "," + col.ColumnName;
            }

            string[] fieldItem = field.Split(',');
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr     = dt.Rows[i];
                string  fvalue = "";
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    string valueTypeName = dt.Columns[j].DataType.FullName.Replace("System.", "");
                    if (j == 0)
                    {
                        if (valueTypeName.ToLower() == "string")
                        {
                            fvalue = "'" + dr[j].ToString().Trim() + "'";
                        }
                        else if (valueTypeName.ToLower() == "datetime")
                        {
                            if (dr[j].ToString() == "" || dr[j].ToString().ToLower() == "null")
                            {
                                fvalue = "NULL";
                            }
                            else
                            {
                                fvalue = "'" + dr[j].ToString().Trim() + "'";
                            }
                        }
                        else
                        {
                            if (dr[j].ToString() == "" || dr[j].ToString().ToLower() == "null")
                            {
                                fvalue = "NULL";
                            }
                            else
                            {
                                fvalue = dr[j].ToString();
                            }
                        }
                    }
                    else
                    {
                        if (valueTypeName.ToLower() == "string")
                        {
                            fvalue = fvalue + ",'" + dr[j].ToString().Trim() + "'";
                        }
                        else if (valueTypeName.ToLower().IndexOf("datetime") >= 0)
                        {
                            if (dr[j].ToString() == "" || dr[j].ToString().ToLower() == "null")
                            {
                                fvalue = fvalue + ",NULL";
                            }
                            else
                            {
                                fvalue = fvalue + "," + GetTimeData(dr[j].ToString().Trim(), dbType);
                            }
                        }
                        else
                        {
                            if (dr[j].ToString() == "" || dr[j].ToString().ToLower() == "null")
                            {
                                fvalue = fvalue + ",NULL";
                            }
                            else
                            {
                                fvalue = fvalue + "," + dr[j].ToString();
                            }
                        }
                    }
                }
                sql = "insert into '' (" + field + ")" + " values(" + fvalue + ")";
                listSql.Add(sql);
            }

            StringBuilder insertSql = new StringBuilder();

            foreach (var item in listSql)
            {
                insertSql.Append(item + ";\r\n");
            }

            return(insertSql.ToString());
        }
        public static System.Data.Common.DbConnection GetDbConnection(Model.CodeMaker.DbLinkInfo info)
        {
            System.Data.Common.DbConnection conn = null;
            try
            {
                DataBaseTypeEnum fc           = DataBaseType.GetDataBaseType(info.DbType);
                string           characterSet = ConfigurationManager.AppSettings["CharacterSet"] == null ? "" : ConfigurationManager.AppSettings["CharacterSet"];
                switch (fc)
                {
                case DataBaseTypeEnum.SQLServer:
                    conn = new System.Data.SqlClient.SqlConnection();
                    string port = "";
                    if (!string.IsNullOrEmpty(info.Port))
                    {
                        port = "," + info.Port;
                    }
                    conn.ConnectionString = "Data Source=" + info.DataSource + port + ";Initial Catalog=" + info.DbName + ";User ID=" + info.UserName + ";Password="******"(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST =" + info.DataSource + ")(PORT =" + info.Port + "))) (CONNECT_DATA = (SERVICE_NAME =" + info.DbName + ")))";
                    conn.ConnectionString = "Data Source=" + dataSource + ";User ID=" + info.UserName + ";Password="******"";
                    break;

                case DataBaseTypeEnum.Access:
                    conn = new System.Data.OleDb.OleDbConnection();
                    string AccessDataSource = info.DataSource;
                    if (AccessDataSource.IndexOf("CodeMaker.mdb") > 0)
                    {
                        AccessDataSource = DBConfig.GetConString("AccessCodeMaker");
                    }
                    conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AccessDataSource;
                    break;

                case DataBaseTypeEnum.SQLite:
                    conn = new System.Data.SQLite.SQLiteConnection();
                    string connstring = @"Data Source=" + info.DataSource + ";Version=3;";
                    if (info.PassWord.Trim() != "")
                    {
                        connstring = connstring + "Password="******"";
                    //if (!string.IsNullOrEmpty(characterSet))
                    //    charset = ";Charset=" + characterSet;

                    conn = new MySql.Data.MySqlClient.MySqlConnection();
                    conn.ConnectionString = "server=" + info.DataSource + ";database=" + info.DbName + ";port=" + info.Port + ";user id=" + info.UserName + ";password="******";Allow Zero Datetime=true" + charset;
                    //conn.ConnectionString = "Data Source=" + info.DataSource + ";port=" + info.Port+";Initial Catalog=" + info.DbName + ";User ID=" + info.UserName + ";Password="******"server=" + info.DataSource + ";database=" + info.DbName + ";port=" + info.Port + ";user id=" + info.UserName + ";password="******";Allow Zero Datetime=true";
                    //    break;
                }
                return(conn);
            }
            catch (Exception ex)
            {
                //rstmsg = "操作失败。" + ex.Message;
            }

            return(conn);
        }
Beispiel #30
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="dbContext"></param>
 public Repository(string dbName, DataBaseTypeEnum dataBaseType)
 {
     _dbContext = new DbContext(dbName, dataBaseType);
 }