private void OpenExcelFile(string srcFile, CoreEA.LoginInfo.OleDBVersion curVersion) { if (!File.Exists(srcFile)) { "FileNotFound".GetFromResourece().Show(); return; } LoginInfo_Excel info = new LoginInfo_Excel() { Database = srcFile, IsFirstRowIsColumnName = (bool)chkIsFirstRowIsColumnName.IsChecked, CurrentOleDBVersion = curVersion, }; App.MainEngineer = new CoreEA.CoreE(CoreEA.CoreE.UsedDatabaseType.Excel).X_Handler; try { App.MainEngineer.Open(info); if (App.MainEngineer.IsOpened) { App.MainEngineer.CurDatabase = info.Database; App.MainEngineer.CurPwd = info.Pwd; RibbionIDE ide = new RibbionIDE(); ide.ShowDialog(); } } catch (Exception ee) { App.ResetMainEngineer(); ee.HandleMyException(); } }
/// <summary> /// Notice: /// Because OleDB Suppor many db types . /// So the UsingOleDbType property in LoginInfo should be specifed. otherwise will use default db type -->Here is Access /// </summary> /// <param name="pInfo"></param> public override void Open(BaseLoginInfo pInfo) { //Record to base class (Vital) baseLoginInfo = pInfo; LoginInfo_Excel myInfo = pInfo as LoginInfo_Excel; LoginInfo_ForAllDbTypes allInfo = pInfo as LoginInfo_ForAllDbTypes; if ((myInfo == null) && (allInfo == null)) { throw new ArgumentException("Only Support Oledb login info and AllDBTypes Info"); } if (IsOpened) { return; } string myConnString = string.Empty; try { if (allInfo != null) { myInfo = new LoginInfo_Excel(); myInfo.Database = allInfo.Database; myInfo.Pwd = allInfo.Pwd; myInfo.Username = allInfo.Username; myInfo.CurrentOleDBVersion = allInfo.CurrentOleDBVersion; } switch (myInfo.CurrentOleDBVersion) { case OleDBVersion.Is2003: myConnString = DbConnectionString.Excel.GetOleDbConnectionString(myInfo.Database, myInfo.IsFirstRowIsColumnName); break; case OleDBVersion.Is2007: myConnString = DbConnectionString.Excel2007.GetOleDBString(myInfo.Database, myInfo.IsFirstRowIsColumnName); break; default: myConnString = DbConnectionString.Excel.GetOleDbConnectionString(myInfo.Database, myInfo.IsFirstRowIsColumnName); break; } baseConn = new OleDbConnection(myConnString); baseConn.Open(); invalidator = new InvalidatorForOledb(); CurDatabase = myInfo.Database; CurPwd = myInfo.Pwd; } catch (Exception e) { throw e; } }