示例#1
0
        public IDBase CreateInitialDbClass(DBkind dbkind, DbOptKind optkind, DBConnectInfo info)
        {
            switch (optkind)
            {
            case DbOptKind.Oledb:
                oledbOptDbase = new OleDBase(dbkind, info);
                break;

#if UseOracle
            case DbOptKind.OracleClient:
                oralclientOptDbase = new OracleDbase(info);
                break;
#endif
            default:
                break;
            }
            IDBase result = null;
            if (optkind == DbOptKind.Oledb)
            {
                result = oledbOptDbase;
            }
#if UseOracle
            else
            {
                result = oralclientOptDbase;
            }
#endif
            return(result);
        }
示例#2
0
 public bool Open(string dbpath, ref string msg)
 {
     try
     {
         DBaseFactory  factory = new DBaseFactory();
         DBConnectInfo info    = new DBConnectInfo()
         {
             DataSource = dbpath
         };
         ODMDB = factory.CreateInitialDbClass(DBkind.Access2013, DbOptKind.Oledb, info);
         if (ODMDB.ConnectionState == ConnectionState.Closed)
         {
             ODMDB.DbConnection.Open();
         }
         DatabaseFilePath = dbpath;
         Name             = Path.GetFileNameWithoutExtension(dbpath);
         msg = "successful";
         return(true);
     }
     catch (Exception ex)
     {
         msg = ex.Message;
         return(false);
     }
 }
		EditDatabaseConnectDialog(DBConnectInfo dbConnectInfo)
		{
			InitializeComponent();
			type.ItemsSource = Enum.GetValues(typeof(DBConnectInfo.DBType)).Cast<DBConnectInfo.DBType>().Where(item => item != DBConnectInfo.DBType.None).ToList();
			ConnectionName = dbConnectInfo.Name;
			DBType = dbConnectInfo.Type;
			ConnStr = dbConnectInfo.ConnectionString;
		}
示例#4
0
 EditDatabaseConnectDialog(DBConnectInfo dbConnectInfo)
 {
     InitializeComponent();
     type.ItemsSource = Enum.GetValues(typeof(DBConnectInfo.DBType)).Cast <DBConnectInfo.DBType>().Where(item => item != DBConnectInfo.DBType.None).ToList();
     ConnectionName   = dbConnectInfo.Name;
     DBType           = dbConnectInfo.Type;
     ConnStr          = dbConnectInfo.ConnectionString;
 }
示例#5
0
        public static DBConnectInfo Run(Window parent, DBConnectInfo dbConnectInfo)
        {
            var dialog = new EditDatabaseConnectDialog(dbConnectInfo)
            {
                Owner = parent
            };

            return(dialog.ShowDialog() ? dialog.GetResult() : null);
        }
示例#6
0
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            var list = value as IEnumerable <EditDatabaseConnectDialog.DBParam>;
            var type = list.Select(dbParam => dbParam.DBType).FirstOrDefault();
            var builder = new DBConnectInfo {
                Type = type
            }.GetBuilder();
            var props = builder.GetType().GetProperties().ToDictionary(prop => prop.Name);

            list.Where(dbParam => !dbParam.IsDefault).ForEach(dbParam => props[dbParam.Name].SetValue(builder, System.Convert.ChangeType(dbParam.Value, props[dbParam.Name].PropertyType)));
            return(new object[] { type, builder.ToString() });
        }
示例#7
0
 public OleDBase(DBkind dbkind, DBConnectInfo info)
 {
     mDBkind = dbkind;
     if (dbkind == DBkind.Access2003 || dbkind == DBkind.Access2007 || dbkind == DBkind.Access2013)
     {
         mConnectString = string.Format("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = {0};Persist Security Info=False; ", info.DataSource);
         //    mConnectString = string.Format("Provider = Microsoft.ACE.OleDB.15.0; Data Source = {0};Persist Security Info=False; ", info.DataSource);
     }
     else if (dbkind == DBkind.Oracle)
     {
         mConnectString = "Provider=msdaora; data source =  " + info.DataSource + "; user id = " + info.UserName + "; PassWord = "******"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + info.DataSource + "; Extended Properties=Excel 8.0";
     }
     else if (dbkind == DBkind.Sqlserver)
     {
         mConnectString = "Provider=SQLOLEDB;Data Source=" + info.DataSource + ";Initial Catalog= " + info.DatabaseName + ";UserId=" +
                          info.UserName + ";Password="******";";
     }
     OpenConnection(mConnectString);
 }
示例#8
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if ((values[0] == null) || (values[1] == null) || (!(values[0] is DBConnectInfo.DBType)) || ((DBConnectInfo.DBType)values[0] == DBConnectInfo.DBType.None) || (!(values[1] is string)))
            {
                return(DependencyProperty.UnsetValue);
            }

            var dbType  = (DBConnectInfo.DBType)values[0];
            var connStr = values[1] as string;

            try
            {
                var builder = new DBConnectInfo {
                    Type = dbType, ConnectionString = connStr
                }.GetBuilder();
                var defaults = new DBConnectInfo {
                    Type = dbType
                }.GetBuilder();
                var baseProps = new HashSet <string>(typeof(DbConnectionStringBuilder).GetProperties().Select(prop => prop.Name));
                var props     = builder.GetType().GetProperties().Where(prop => !baseProps.Contains(prop.Name)).Where(prop => prop.CanWrite).Where(prop => prop.GetIndexParameters().Length == 0).ToList();
                return(props.Select(prop => new EditDatabaseConnectDialog.DBParam(dbType, prop, builder, defaults)).OrderBy(dbParam => dbParam.IsDefault).ToList());
            }
            catch { return(DependencyProperty.UnsetValue); }
        }
 public SqlServerDatabase(DBConnectInfo info)
 {
     connectionString = "Provider=System.Data.SqlClient;Data Source=" + info.DataSource + ";Initial Catalog= " + info.DatabaseName + ";User Id=" +
                        info.UserName + ";Password="******";";
 }
		public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
		{
			var list = value as IEnumerable<EditDatabaseConnectDialog.DBParam>;
			var type = list.Select(dbParam => dbParam.DBType).FirstOrDefault();
			var builder = new DBConnectInfo { Type = type }.GetBuilder();
			var props = builder.GetType().GetProperties().ToDictionary(prop => prop.Name);
			list.Where(dbParam => !dbParam.IsDefault).ForEach(dbParam => props[dbParam.Name].SetValue(builder, System.Convert.ChangeType(dbParam.Value, props[dbParam.Name].PropertyType)));
			return new object[] { type, builder.ToString() };
		}
		public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
		{
			if ((values[0] == null) || (values[1] == null) || (!(values[0] is DBConnectInfo.DBType)) || ((DBConnectInfo.DBType)values[0] == DBConnectInfo.DBType.None) || (!(values[1] is string)))
				return DependencyProperty.UnsetValue;

			var dbType = (DBConnectInfo.DBType)values[0];
			var connStr = values[1] as string;

			try
			{
				var builder = new DBConnectInfo { Type = dbType, ConnectionString = connStr }.GetBuilder();
				var defaults = new DBConnectInfo { Type = dbType }.GetBuilder();
				var baseProps = new HashSet<string>(typeof(DbConnectionStringBuilder).GetProperties().Select(prop => prop.Name));
				var props = builder.GetType().GetProperties().Where(prop => !baseProps.Contains(prop.Name)).Where(prop => prop.CanWrite).Where(prop => prop.GetIndexParameters().Length == 0).ToList();
				return props.Select(prop => new EditDatabaseConnectDialog.DBParam(dbType, prop, builder, defaults)).OrderBy(dbParam => dbParam.IsDefault).ToList();
			}
			catch { return DependencyProperty.UnsetValue; }
		}
		public static DBConnectInfo Run(Window parent, DBConnectInfo dbConnectInfo)
		{
			var dialog = new EditDatabaseConnectDialog(dbConnectInfo) { Owner = parent };
			return dialog.ShowDialog() ? dialog.GetResult() : null;
		}
			public DBParam(DBConnectInfo.DBType dbType, PropertyInfo prop, DbConnectionStringBuilder values, DbConnectionStringBuilder defaults)
			{
				DBType = dbType;
				Name = prop.Name;
				try { Original = prop.GetValue(values); } catch { }
				try { Default = prop.GetValue(defaults); } catch { }
				Value = Original;
				Type = prop.PropertyType;
			}