Пример #1
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();
            }
        }
Пример #2
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="dbFileFullPath"></param>
            /// <param name="pwd"></param>
            /// <param name="Encrypt"></param>
            /// <param name="curOpenMode"></param>
            /// <param name="maxBufferSize">Default is 1024 </param>
            /// <param name="maxDbSize">Default is 256 ,Max is 164091
            /// But we changed to default is 4000</param>
            /// <returns></returns>
            public static string GetSSCEConnectionString(string dbFileFullPath, string pwd, bool Encrypt, OpenModeClass curOpenMode
                                                         , uint maxDbSize = 4000, uint maxBufferSize = 1024)
            {
                string result = string.Empty;

                result = string.Format("DataSource={0}", dbFileFullPath);

                if (!string.IsNullOrEmpty(pwd))
                {
                    result = string.Format("{0} ;Password={1}", result, @pwd);
                }

                result = string.Format("{0} ;Encrypt={1}", result, Encrypt);

                switch (curOpenMode.mode)
                {
                case OpenMode.ReadWrite:
                    result = string.Format("{0}; File Mode={1}", result, curOpenMode.modeDisplayName);
                    break;

                case OpenMode.ReadOnly:
                    result = string.Format("{0}; File Mode={1};Temp Path=%temp%", result, curOpenMode.modeDisplayName);
                    break;

                case OpenMode.Exclusive:
                    break;

                case OpenMode.SharedRead:
                    break;

                default:
                    result = string.Format("{0}; File Mode={1}", result, curOpenMode.modeDisplayName);
                    break;
                }

                result = string.Format("{0}; Max Database Size={1}", result, maxDbSize);

                if ((maxBufferSize != 0) && (maxBufferSize != 1024))
                {
                    result = string.Format("{0}; Max Buffer Size={1}", result, maxBufferSize);
                }
                return(result);
            }
Пример #3
0
        public sealed override void Open(BaseLoginInfo pInfo)
        {
            //Record to base class (Vital)
            baseLoginInfo = pInfo;


            LoginInfo_SSCE          myInfo  = pInfo as LoginInfo_SSCE;
            LoginInfo_ForAllDbTypes allInfo = pInfo as LoginInfo_ForAllDbTypes;

            if ((myInfo == null) && (allInfo == null))
            {
                throw new ArgumentException("Only Support SSCE login info and AllDBTypes Info");
            }

            if (IsOpened)
            {
                return;
            }

            string myConnString = string.Empty;

            try
            {
                if (allInfo != null)
                {
                    myInfo             = new LoginInfo_SSCE();
                    myInfo.DbName      = allInfo.Database;
                    myInfo.Pwd         = allInfo.Pwd;
                    myInfo.IsEncrypted = allInfo.IsEncrypt;
                }

                OpenModeClass op = new OpenModeClass();
                op.mode = myInfo.CurOpenMode;
                switch (myInfo.CurOpenMode)
                {
                case OpenMode.ReadWrite:
                    op.modeDisplayName = "Read Write";
                    break;

                case OpenMode.ReadOnly:
                    op.modeDisplayName = "Read Only";
                    break;

                case OpenMode.Exclusive:
                    op.modeDisplayName = "Exclusive";
                    break;

                case OpenMode.SharedRead:
                    op.modeDisplayName = "Shared Read";
                    break;

                default:
                    op.modeDisplayName = "Read Write";
                    break;
                }

                if (myInfo.MaxBufferSize == 0)
                {
                    myInfo.MaxBufferSize = 1024;
                }
                if (myInfo.MaxDbSize == 0)
                {
                    myInfo.MaxDbSize = 4000;
                }

                myConnString = DbConnectionString.SSCE.GetSSCEConnectionString(
                    myInfo.DbName, myInfo.Pwd, myInfo.IsEncrypted, op, myInfo.MaxDbSize, myInfo.MaxBufferSize);


                baseConn = new SqlCeConnection(myConnString);
                baseConn.Open();

                CurDatabase = myInfo.DbName;
                CurPwd      = myInfo.Pwd;

                invalidator = new InvalidatorForSqlCe();
            }
            catch (Exception e)
            {
                throw e;
            }
        }