Esempio n. 1
0
        private void DoSelect()
        {
            SSCEObjects curObject = myHistoryGrid.SelectedItem as SSCEObjects;

            if (curObject != null)
            {
                if (AfterSelectedValue != null)
                {
                    AfterSelectedValue(curObject.DbFileFullPath);
                }
                Close();
            }
        }
Esempio n. 2
0
        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();
            }
        }