/// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMdiChildActivate(EventArgs e)
        {
            this.columnsToolStripMenuItem.DropDownItems.Clear();

            if (this.ActiveMdiChild is ViewBooksForm)
            {
                ViewBooksForm form = this.ActiveMdiChild as ViewBooksForm;
                form.FillViewMenu(this.columnsToolStripMenuItem);
                this.SetPrintingMenu(true);
                if (form.Grid.SelectedIds.Count < 1)
                {
                    this.SetLibraryOperations(false, false, false);
                    this.SetWishListOperations(false, false);
                }
            }
            else if (this.ActiveMdiChild is AddBookForm)
            {
                this.SetPrintingMenu(true);
                this.SetLibraryOperations(false, false, false);
                this.SetWishListOperations(false, false);
            }
            else
            {
                this.SetPrintingMenu(false);
                this.SetLibraryOperations(false, false, false);
                this.SetWishListOperations(false, false);
            }

            this.columnsToolStripMenuItem.Enabled = this.columnsToolStripMenuItem.DropDownItems.Count > 0 ? true : false;
        }
 /// <summary>
 /// called when the form's Show() method is called
 /// </summary>
 /// <param name="e"></param>
 protected override void OnShown(EventArgs e)
 {
     base.OnShown(e);
     //if there is a default db, open it, if not, open the view database form
     if (_config.AppSettings.Settings[Constants.Settings.DEFAULT_DB].Value == "")
     {
         this.OpenViewDatabaseForm();
     }
     else
     {
         FileInfo db = new FileInfo(_config.AppSettings.Settings[Constants.Settings.DEFAULT_DB].Value);
         if (db.Exists)
         {
             this.CurrentDatabase = db;
             ViewBooksForm form = new ViewBooksForm(Constants.LibraryMode.LIBRARY);
             form.MdiParent = this;
             form.Show();
         }
         else
         {
             _config.AppSettings.Settings[Constants.Settings.DEFAULT_DB].Value = "";
             _config.Save(System.Configuration.ConfigurationSaveMode.Modified);
             this.OpenViewDatabaseForm();
         }
     }
 }
        private void viewWishlistToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ViewBooksForm form = new ViewBooksForm(Constants.LibraryMode.WISHLIST);

            form.MdiParent = this;
            form.Show();
        }
        void ViewLibraryToolStripMenuItemClick(object sender, EventArgs e)
        {
            ViewBooksForm form = new ViewBooksForm(Constants.LibraryMode.LIBRARY);

            form.MdiParent = this;
            form.Show();
        }
        /// <summary>
        /// Called when the "open" button is clicked on this form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpen_Click(object sender, EventArgs e)
        {
            FileInfo currentDB = this.getSelectedDatabase();
            if (currentDB == null)
                return;

            MainForm parent = this.MdiParent as MainForm;


            BaseInfoDAO dao = new BaseInfoDAO(currentDB.FullName);
            BaseInfo baseInfo = dao.GetBaseInfo();
            if (!baseInfo.Password.Equals(""))
            {
                PasswordPrompt prompt = new PasswordPrompt(baseInfo.Password);
                if (prompt.ShowDialog() != DialogResult.OK)
                    return;
            }   

            MainForm form = (MainForm)this.MdiParent;
            form.CurrentDatabase = currentDB;
            this.Close();

            foreach (Form f in parent.MdiChildren)
                f.Close();

            ViewBooksForm booksForm = new ViewBooksForm(Constants.LibraryMode.LIBRARY);
            booksForm.MdiParent = form;
            booksForm.Show();

        }
        private void viewLoanedBooksToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ViewBooksForm form = new ViewBooksForm(Constants.LibraryMode.LOANEDBOOKS);

            form.MdiParent = this;
            form.Show();
        }
        private void loanBookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.ActiveMdiChild is ViewBooksForm)
            {
                ViewBooksForm form = this.ActiveMdiChild as ViewBooksForm;

                if (form.LibraryMode == Constants.LibraryMode.LIBRARY)
                {
                    foreach (Book b in form.Grid.SelectedBooks)
                    {
                        LoanBookForm lForm = new LoanBookForm(b.Id, b.ShortTitle, this);
                    }
                }
            }
        }
        /// <summary>
        /// Called when the "open" button is clicked on this form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpen_Click(object sender, EventArgs e)
        {
            FileInfo currentDB = this.getSelectedDatabase();

            if (currentDB == null)
            {
                return;
            }

            MainForm parent = this.MdiParent as MainForm;


            BaseInfoDAO dao      = new BaseInfoDAO(currentDB.FullName);
            BaseInfo    baseInfo = dao.GetBaseInfo();

            if (!baseInfo.Password.Equals(""))
            {
                PasswordPrompt prompt = new PasswordPrompt(baseInfo.Password);
                if (prompt.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }

            MainForm form = (MainForm)this.MdiParent;

            form.CurrentDatabase = currentDB;
            this.Close();

            foreach (Form f in parent.MdiChildren)
            {
                f.Close();
            }

            ViewBooksForm booksForm = new ViewBooksForm(Constants.LibraryMode.LIBRARY);

            booksForm.MdiParent = form;
            booksForm.Show();
        }
        /// <summary>
        /// called when OK button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            int errors = 0;
            //check and make sure everything is filled out
            errors += UIUtils.ValidationHelper(this.txtOwner.Text.Length == 0,this.errorProvider1,this.txtOwner,ErrorMessages.Common.REQUIRED_FIELD);
            errors += UIUtils.ValidationHelper(this.txtLibrary.Text.Length == 0,this.errorProvider1,this.txtLibrary,ErrorMessages.Common.REQUIRED_FIELD);
            errors += UIUtils.ValidationHelper(this.chkProtected.Checked == true && this.txtPassword.Text.Length == 0,this.errorProvider1,this.txtPassword,ErrorMessages.NewDBForm.PASSWORD);

            if (errors > 0)
                return;

            //copy the empty database and rename it
            FileInfo emptyDB = new FileInfo("emdata");

            if(!emptyDB.Exists)
            {
                MessageBox.Show(emptyDB.FullName);
                MessageBox.Show(ErrorMessages.NewDBForm.EMPTY_DB_MISSING,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                this.Close();
                return;
            }
            

            string newFileName = this.txtLibrary.Text.Replace(" ","_") + ".plb";
            //check to make sure we're not writing over anything
            FileInfo newFile = new FileInfo(newFileName);

            if (newFile.Exists)
            {
                MessageBox.Show(ErrorMessages.NewDBForm.DB_ALREADY_EXISTS, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                newFile = emptyDB.CopyTo(newFileName);
            }
            catch (Exception e1)
            {
                ExceptionHandler.HandleException(e1);
                this.Close();
                return;
            }
            
            
            if (!newFile.Exists)
            {
                MessageBox.Show(ErrorMessages.NewDBForm.DB_NOT_CREATED, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //if we reached here, we have a database, now initialize it
            BaseInfoDAO dao = new BaseInfoDAO(newFileName);
            bool success = dao.InitializeDatabase(this.txtOwner.Text, this.txtLibrary.Text, this.txtPassword.Text);
           
            if (!success)
            {
                MessageBox.Show(ErrorMessages.NewDBForm.DB_NOT_CREATED, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                newFile.Delete();
            }
            else
            {
                if (DialogResult.Yes == MessageBox.Show(Messages.NewDBForm.DB_CREATED, "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    MainForm form = (MainForm)this.MdiParent;
                    form.CurrentDatabase = newFile;

                    //check and see if there is a ViewDB window open, if so, close it
                    Form[] children = form.MdiChildren;
                    foreach (Form f in children)
                    {
                        if (f is ViewDatabasesForm)
                            f.Close();
                    }

                    ViewBooksForm f2 = new ViewBooksForm(Constants.LibraryMode.LIBRARY);
                    f2.MdiParent = this.MdiParent;
                    f2.Show();
                }
                else
                {
                    //check for a view database window, and refresh it
                    MainForm form = (MainForm)this.MdiParent;
                    Form[] children = form.MdiChildren;
                    foreach (Form f in children)
                    {
                        if (f is ViewDatabasesForm)
                            f.Refresh();
                    }
                }
            }
            this.Close();

           
        }
Esempio n. 10
0
 /// <summary>
 /// called when the form's Show() method is called
 /// </summary>
 /// <param name="e"></param>
 protected override void OnShown(EventArgs e)
 {
     base.OnShown(e);
     //if there is a default db, open it, if not, open the view database form
     if (_config.AppSettings.Settings[Constants.Settings.DEFAULT_DB].Value == "")
     {
         this.OpenViewDatabaseForm();
     }
     else
     {                
     	FileInfo db = new FileInfo(_config.AppSettings.Settings[Constants.Settings.DEFAULT_DB].Value);
         if (db.Exists)
         {
             this.CurrentDatabase = db;
             ViewBooksForm form = new ViewBooksForm(Constants.LibraryMode.LIBRARY);
             form.MdiParent = this;
             form.Show();
         }
         else
         {
         	_config.AppSettings.Settings[Constants.Settings.DEFAULT_DB].Value = "";
         	_config.Save(System.Configuration.ConfigurationSaveMode.Modified);
             this.OpenViewDatabaseForm();
         }
     }
 }
Esempio n. 11
0
 void ViewLibraryToolStripMenuItemClick(object sender, EventArgs e)
 {
     ViewBooksForm form = new ViewBooksForm(Constants.LibraryMode.LIBRARY);
     form.MdiParent = this;
     form.Show();	
 }
Esempio n. 12
0
 private void viewWishlistToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     ViewBooksForm form = new ViewBooksForm(Constants.LibraryMode.WISHLIST);
     form.MdiParent = this;
     form.Show();
 }
Esempio n. 13
0
 private void viewLoanedBooksToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     ViewBooksForm form = new ViewBooksForm(Constants.LibraryMode.LOANEDBOOKS);
     form.MdiParent = this;
     form.Show();
 }
Esempio n. 14
0
        /// <summary>
        /// Erm...well...it saves.
        /// </summary>
        private void save()
        {
            if (!this.isRequiredFieldsFilled())
            {
                return;
            }

            MainForm parent = (MainForm)this.MdiParent;
            BookDAO  dao    = new BookDAO(parent.CurrentDatabase.FullName);

            if (_addMode == Constants.AddBookMode.EDIT)
            {
                if (dao.Updatebook(_book))
                {
                    this.setInfoLabel("Success");
                }
                else
                {
                    this.setInfoLabel("Failed");
                }
                return;
            }

            if (dao.ExistsInLibrary(_book))
            {
                if (this.chkAutoAdd.Checked == true)
                {
                    this.errorProvider1.SetError(this.txtLookup, ErrorMessages.Common.BOOK_EXISTS_IN_LIBRARY);
                }
                else
                {
                    this.errorProvider1.SetError(this.txtShortTitle, ErrorMessages.Common.BOOK_EXISTS_IN_LIBRARY);
                }

                this.setInfoLabel("Failed");
                this.btnClear.Focus();
                return;
            }
            else
            {
                this.errorProvider1.SetError(this.txtShortTitle, "");
                this.errorProvider1.SetError(this.txtLookup, "");
            }

            if (dao.InsertIntoLibrary(_book))
            {
                this.setInfoLabel("Success");
                this.clear();
                this.errorProvider1.SetError(this.txtShortTitle, "");
                this.errorProvider1.SetError(this.txtLookup, "");
                foreach (Form f in this.MdiParent.MdiChildren)
                {
                    if (f is ViewBooksForm)
                    {
                        ViewBooksForm frm = (ViewBooksForm)f;
                        frm.Refresh();
                    }
                }
            }
            else
            {
                this.setInfoLabel("Failed");
            }
        }
Esempio n. 15
0
 /// <summary>
 /// Called when right click -> view loan history is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void viewLoanHistoryToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (string id in this.SelectedIds)
     {
         ViewBooksForm form = new ViewBooksForm(Constants.LibraryMode.LOANHISTORY, id);
         form.MdiParent = this.ParentForm.MdiParent;
         form.Show();
     }
 }
Esempio n. 16
0
        /// <summary>
        /// called when OK button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            int errors = 0;

            //check and make sure everything is filled out
            errors += UIUtils.ValidationHelper(this.txtOwner.Text.Length == 0, this.errorProvider1, this.txtOwner, ErrorMessages.Common.REQUIRED_FIELD);
            errors += UIUtils.ValidationHelper(this.txtLibrary.Text.Length == 0, this.errorProvider1, this.txtLibrary, ErrorMessages.Common.REQUIRED_FIELD);
            errors += UIUtils.ValidationHelper(this.chkProtected.Checked == true && this.txtPassword.Text.Length == 0, this.errorProvider1, this.txtPassword, ErrorMessages.NewDBForm.PASSWORD);

            if (errors > 0)
            {
                return;
            }

            //copy the empty database and rename it
            FileInfo emptyDB = new FileInfo("emdata");

            if (!emptyDB.Exists)
            {
                MessageBox.Show(emptyDB.FullName);
                MessageBox.Show(ErrorMessages.NewDBForm.EMPTY_DB_MISSING, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                return;
            }


            string newFileName = this.txtLibrary.Text.Replace(" ", "_") + ".plb";
            //check to make sure we're not writing over anything
            FileInfo newFile = new FileInfo(newFileName);

            if (newFile.Exists)
            {
                MessageBox.Show(ErrorMessages.NewDBForm.DB_ALREADY_EXISTS, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                newFile = emptyDB.CopyTo(newFileName);
            }
            catch (Exception e1)
            {
                ExceptionHandler.HandleException(e1);
                this.Close();
                return;
            }


            if (!newFile.Exists)
            {
                MessageBox.Show(ErrorMessages.NewDBForm.DB_NOT_CREATED, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //if we reached here, we have a database, now initialize it
            BaseInfoDAO dao     = new BaseInfoDAO(newFileName);
            bool        success = dao.InitializeDatabase(this.txtOwner.Text, this.txtLibrary.Text, this.txtPassword.Text);

            if (!success)
            {
                MessageBox.Show(ErrorMessages.NewDBForm.DB_NOT_CREATED, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                newFile.Delete();
            }
            else
            {
                if (DialogResult.Yes == MessageBox.Show(Messages.NewDBForm.DB_CREATED, "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    MainForm form = (MainForm)this.MdiParent;
                    form.CurrentDatabase = newFile;

                    //check and see if there is a ViewDB window open, if so, close it
                    Form[] children = form.MdiChildren;
                    foreach (Form f in children)
                    {
                        if (f is ViewDatabasesForm)
                        {
                            f.Close();
                        }
                    }

                    ViewBooksForm f2 = new ViewBooksForm(Constants.LibraryMode.LIBRARY);
                    f2.MdiParent = this.MdiParent;
                    f2.Show();
                }
                else
                {
                    //check for a view database window, and refresh it
                    MainForm form     = (MainForm)this.MdiParent;
                    Form[]   children = form.MdiChildren;
                    foreach (Form f in children)
                    {
                        if (f is ViewDatabasesForm)
                        {
                            f.Refresh();
                        }
                    }
                }
            }
            this.Close();
        }