Exemplo n.º 1
0
        private void SaveFuzzyDatabase()
        {
            try
            {
                // Record to database
                Cursor oldCursor = Cursor;
                Cursor = Cursors.WaitCursor;
                frmProgressBar frm = new frmProgressBar();
                frm.LblName.Text = "Saving...";
                frm.Show();
                frm.Refresh();

                fdbBll = new FdbBLL();

                fdbBll.DropFuzzyDatabase(fdbEntity);
                if (!fdbBll.SaveFuzzyDatabase(fdbEntity))//Why fdbEntity doesn't null? Because it was created in  OpenFuzzyDatabase or CreateFuzzyDatabase
                {
                    siStatus.Caption = "Cannnot save the Database!";
                    timer.Start();
                }
                else
                {
                    siStatus.Caption = "The Database has been saved!";
                    timer.Start();
                }

                frm.Close();
                Cursor = oldCursor;
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR:\n" + ex.Message);
            }
        }
Exemplo n.º 2
0
        private void SaveFuzzyDatabaseAs()
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.DefaultExt = "tbb";                                                                   // Default extension
                sfd.Filter = "Fuzzy Database File (*.tbb)|*.tbb|All files (*.*)|*.*";              // add extension to dialog
                sfd.AddExtension = true;                                                                // enable adding extension
                sfd.RestoreDirectory = true;                                                           // Automatic restore path for another time
                sfd.Title = "Save as...";
                sfd.InitialDirectory = FdbBLL.GetRootPath(AppDomain.CurrentDomain.BaseDirectory.ToString());
                sfd.SupportMultiDottedExtensions = true;

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    siStatus.Caption = "Saving Database...";

                    //NewFuzzyDatabaseEntity(sfd.FileName);
                    Clone(sfd.FileName);
                    this.path = sfd.FileName;

                    Cursor oldCursor = Cursor;
                    Cursor = Cursors.WaitCursor;

                    frmProgressBar frm = new frmProgressBar();
                    frm.LblName.Text = "Saving...";
                    frm.Show();
                    frm.Refresh();
                    //if (!fdbBll.SaveFuzzyDatabaseAs(fdbEntity))//Why doesn't fdbEntity null? Because it was created in  OpenFuzzyDatabase or CreateFuzzyDatabase
                    //{
                    //    siStatus.Caption = "Cannnot save the database!";
                    //    timer.Start();
                    //}
                    //else
                    //{
                    //    siStatus.Caption = "The database has been saved!";
                    //    timer.Start();
                    //}

                    frm.Close();
                    Cursor = oldCursor;
                    ShowTreeList();
                    ShowTreeListNode();
                    //Some enable control
                }

                sfd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        private void OpenFuzzyDatabase()
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.DefaultExt = "tbb";
                ofd.CheckFileExists = true;
                ofd.Filter = "Fuzzy Database File (*.tbb) | *.tbb";
                ofd.AddExtension = true;
                ofd.Multiselect = false;
                ofd.RestoreDirectory = true;
                ofd.Title = "Open Fuzzy Database...";

                String tmp = ReadPath();// Read the path
                if (tmp != "" && Directory.Exists(tmp))
                    ofd.InitialDirectory = tmp;
                else
                    ofd.InitialDirectory = FdbBLL.GetRootPath(AppDomain.CurrentDomain.BaseDirectory.ToString());

                ofd.SupportMultiDottedExtensions = true;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    siStatus.Caption = "Opening fuzzy database...";

                    NewFuzzyDatabaseEntity(ofd.FileName);
                    this.path = ofd.FileName;
                    WritePath(this.path.Substring(0, this.path.LastIndexOf("\\")));//Save the last path

                    threadBLL = new ThreadBLL(DBValues.connString);
                    threadBLL.WorkerThread = new Thread(new ThreadStart(threadBLL.StartWorker));
                    threadBLL.WorkerThread.Name = "Database Client Worker Thread";
                    threadBLL.WorkerThread.Start();
                    Cursor oldCursor = Cursor;
                    Cursor = Cursors.WaitCursor;
                    frmProgressBar frm = new frmProgressBar();
                    frm.Show();
                    frm.Refresh();
                    Boolean success = threadBLL.Connecting();
                    success = success && fdbBll.OpenFuzzyDatabase(fdbEntity);
                    frm.Close();
                    Cursor = oldCursor;

                    if (!success)
                    {
                        threadBLL.Dispose();
                        throw new Exception("ERROR:\n Can not connect to fuzzy database!");
                    }
                    else
                    {
                        ShowTreeList();
                        ShowTreeListNode();
                        ActiveDatabase(true);
                        iOpenExistingDatabase.Enabled = false;
                        iNewDatabase.Enabled = false;
                        threadBLL.Dispose();
                    }
                }

                ofd.Dispose();
            }
            catch (Exception ex)
            {
                DialogResult result = MessageBox.Show("You haven't installed SQLite yet, do you want to install SQLite right now?", "SQLite"
                   + fdbEntity.FdbName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    Process.Start("SQLite-1.0.66.0-setup.exe");
                }
            }
        }