private void OpenSqliteFile(string srcFile) { if (!File.Exists(srcFile)) { "FileNotFound".GetFromResourece().Show(); return; } try { App.MainEngineer = new CoreEA.CoreE(CoreEA.CoreE.UsedDatabaseType.Sqlite).X_Handler; string dbName = srcFile; App.MainEngineer.Open (new CoreEA.LoginInfo.LoginInfo_Sqlite() { DbFile = dbName, Pwd = txtPwd.Password, IsReadOnly = (bool)chkIsReadOnly.IsChecked, IsUnicode = (bool)chkIsUnicode.IsChecked, } ); if (App.MainEngineer.IsOpened) { RibbionIDE ide = new RibbionIDE(); ide.WindowState = WindowState.Maximized; ide.BringIntoView(); ide.ShowDialog(); } } catch (Exception ee) { App.ResetMainEngineer(); ee.HandleMyException(); } }
private void butOpen_Click(object sender, RoutedEventArgs e) { switch (currentDBConnectionType) { case ConnectionType.File: if (txtDbLocation.Text.IsEmpty()) { "TitleInputDbFile".GetFromResourece().Show(); return; } break; case ConnectionType.Memory: if (txtDBName.Text.IsEmpty()) { "TitleInputDbFile".GetFromResourece().Show(); return; } break; } try { App.MainEngineer = new CoreEA.CoreE(CoreEA.CoreE.UsedDatabaseType.Effiproz).X_Handler; string dbName = string.Empty; switch (currentDBConnectionType) { case ConnectionType.File: string rootPath = System.IO.Path.GetDirectoryName(txtDbLocation.Text); dbName = rootPath + "\\" + System.IO.Path.GetFileNameWithoutExtension(txtDbLocation.Text); break; case ConnectionType.Memory: dbName = txtDBName.Text; break; default: throw new Exception("invalid mode"); } App.MainEngineer.Open (new CoreEA.LoginInfo.LoginInfo_Effiproz() { InitialCatalog = dbName, Username = txtUserName.Text, Password = txtPwd.Password, DBConnectionType = currentDBConnectionType, IsReadOnly = (bool)chkIsReadonly.IsChecked, IsAutoShutdown = (bool)chkIsAutoShutdown.IsChecked, IsAutoCommit = (bool)chkIsAutoCommit.IsChecked, } ); if (App.MainEngineer.IsOpened) { RibbionIDE ide = new RibbionIDE(); try { ide.WindowState = WindowState.Maximized; ide.BringIntoView(); ide.ShowDialog(); } catch (InvalidOperationException ee) { Debug.WriteLine(ee.Message); ee.Message.Show(); } catch (Exception ee) { ee.Message.Show(); } } else { App.ResetMainEngineer(); } } catch (Exception ee) { MessageBox.Show(ee.Message); App.ResetMainEngineer(); return; } }
private void butOpen_Click(object sender, RoutedEventArgs e) { string dbName = txtDbPath.Text; string dbPwd = txtPwd.Password; if (string.IsNullOrEmpty(dbName)) { "Please input database name".Notify(); return; } if (Utility.DetectNetworkDriver.IsPathOnNetworkDrive(dbName)) { "SQLCE do not support open from network".Notify(); return; } OpenModeClass CurOpenMode = null; if (cmbOpenMode.SelectedItem == null) { CurOpenMode = cmbOpenMode.Items[0] as OpenModeClass; } else { CurOpenMode = cmbOpenMode.SelectedItem as OpenModeClass; } uint maxDbSize = (uint)txtMaxDBSize.Value; //If open db ok ,and get tables info ok , then do //otherwise do nothing try { App.MainEngineer = new CoreEA.CoreE(CoreEA.CoreE.UsedDatabaseType.SqlCE35).X_Handler; App.MainEngineer.Open(new LoginInfo_SSCE() { DbName = dbName, Pwd = txtPwd.Password, CurOpenMode = CurOpenMode.mode, MaxDbSize = maxDbSize }); } catch (SqlCeInvalidDatabaseFormatException sqe) { Debug.WriteLine("*****************" + sqe.Message); #region if (wf.DialogResult.Yes == wf.MessageBox.Show("Your database format is old version ,do you want to upgrade it ,so this software can modify it?", "Warning", wf.MessageBoxButtons.YesNo, wf.MessageBoxIcon.Question, wf.MessageBoxDefaultButton.Button1)) { try { if (Properties.Settings.Default.AutoBackupOldVersionFileBeforeUpgrade) { if (!Directory.Exists(Config.AutoBackupFolder)) { Directory.CreateDirectory(Config.AutoBackupFolder); } File.Copy(dbName, Config.AutoBackupFolder + Path.GetFileName(dbName), true); } } catch (Exception ee) { #if DEBUG throw ee; #else ee.Message.Show(); #endif } SqlCeEngine d = new SqlCeEngine(CoreEA.ConnSTR.DbConnectionString.SSCE.GetSSCEConnectionString( dbName, dbPwd, (bool)chkIsEncrypted.IsChecked, CurOpenMode)); try { d.Upgrade(); "Upgrade Successful".Notify(); } catch (Exception dee) { dee.Message.Notify(); App.ResetMainEngineer(); return; } goto ReOpen; } else { App.ResetMainEngineer(); return; } #endregion } catch (Exception eee) { eee.Message.Notify(); } ReOpen: if (App.MainEngineer.IsOpened) { App.MainEngineer.CurDatabase = dbName; App.MainEngineer.CurPwd = txtPwd.Password; //this.Hide(); txtDbPath.Text = string.Empty; txtPwd.Password = string.Empty; Properties.Settings.Default.LastestOpenedDb = dbName; Properties.Settings.Default.LastestOpenedDbPwd = dbPwd; Properties.Settings.Default.Save(); #region Save to Opened History Info SSCEObjects ssceItem = new SSCEObjects(); ssceItem.DbFileFullPath = dbName; if (!SerializeClass.DatabaseHistoryInfo.SSCEHistory.IsContainSubValue(ssceItem.DbFileFullPath)) { HistoryObject oldObject = SerializeClass.DatabaseHistoryInfo; ssceItem.LatestVisitTime = DateTime.Now; oldObject.SSCEHistory.Add(ssceItem); SerializeClass.DatabaseHistoryInfo = oldObject; } #endregion RefreshLastOpenedDbsStatus(); RibbionIDE ide = new RibbionIDE(); ide.WindowState = WindowState.Maximized; ide.BringIntoView(); ide.ShowDialog(); } else { App.ResetMainEngineer(); } }