Exemple #1
0
        private void compactDatbaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string message = "Compacting the database will discard the unused space occupied by it."
                             + "\nAny open window associated with the currently opened financial year " +
                             "will be closed prior to compacting it. OK?";

            System.Media.SystemSounds.Question.Play();
            DialogResult result = MessageBox.Show(message, "Confirm Action", MessageBoxButtons.OKCancel,
                                                  MessageBoxIcon.Question);

            if (result == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            FinancialYear financialYear = Global.CurrentFinancialYear;

            GlobalMethods.closeCurrentlyOpenYear();

            bool returnValue = GlobalMethods.ShrinkDatabase(financialYear.FilePath);

            if (returnValue)
            {
                System.Media.SystemSounds.Asterisk.Play();
                message        = "The database was successfully compacted !!";
                Cursor.Current = Cursors.Default;
                MessageBox.Show(message, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            Global.CurrentFinancialYear = financialYear;
            this.Text = Global.AssemblyTitle + " (Financial Year: " +
                        Global.CurrentFinancialYear.ToString() + ")";
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            FinancialYear sourceYear = (FinancialYear)availableDatabasesListBox.SelectedItem;

            FinancialYear currentYear = Global.CurrentFinancialYear;

            if (currentYear != null && currentYear.Equals(sourceYear))
            {
                if (!GlobalMethods.closeCurrentlyOpenYear())
                {
                    return;
                }
            }

            Cursor.Current = Cursors.WaitCursor;

            if (!restoreDatabase(sourceYear.FilePath))
            {
                return;
            }

            System.Media.SystemSounds.Asterisk.Play();
            Cursor.Current = Cursors.Default;
            MessageBox.Show("The database was successfully restored !!", "Success",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);

            if (currentYear != null)
            {
                Global.CurrentFinancialYear = currentYear;
                this.MdiParent.Text         = Global.AssemblyTitle + " (Financial Year: " +
                                              Global.CurrentFinancialYear.ToString() + ")";
            }

            this.Close();
        }
Exemple #3
0
        private void MDIForm_Load(object sender, EventArgs e)
        {
            this.WindowState = Properties.Settings.Default.LastMDIWindowState;
            if (Properties.Settings.Default.LastMDIWindowState == FormWindowState.Normal)
            {
                Size lastSize = Properties.Settings.Default.LastMDIFormSize;
                if (!lastSize.IsEmpty)
                {
                    this.Size = Properties.Settings.Default.LastMDIFormSize;
                }
            }

            string filePath = Properties.Settings.Default.LastlyOpenedFYPath;

            if (!string.IsNullOrWhiteSpace(filePath))
            {
                if (File.Exists(filePath))
                {
                    FileInfo fileInfo = new FileInfo(filePath);
                    if (fileInfo.Directory.Parent.FullName.Equals(Properties.Settings.Default.DatabasePath))
                    {
                        FinancialYear financialYear = GlobalMethods.getFinancialYear(filePath);
                        if (financialYear != null)
                        {
                            Global.CurrentFinancialYear = financialYear;
                            this.Text = Global.AssemblyTitle + " (Financial Year: " +
                                        financialYear.ToString() + ")";
                        }
                    }
                }
            }
        }
        private bool backupDatabase(FinancialYear financialYear)
        {
            string sourcePath      = financialYear.FilePath;
            string destinationPath = backupLocationField.Text;

            destinationPath = destinationPath + "\\" + Global.AssemblyTitle + "-Backup-" +
                              DateTime.Today.ToString("dd-MMM-yyyy");

            if (!createBackupFolder(destinationPath))
            {
                return(false);
            }

            return(copyDatabaseFile(financialYear.FilePath, destinationPath));
        }
Exemple #5
0
        private List <FinancialYear> getPreviousFinancialYears(int startYear)
        {
            FinancialYear        fy    = new FinancialYear(startYear, DateTime.Today, string.Empty);
            List <FinancialYear> years = new List <FinancialYear>(financialYears.Count);

            foreach (FinancialYear year in financialYears)
            {
                if (year.CompareTo(fy) < 0)
                {
                    years.Add(year);
                }
            }

            return(years);
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            FinancialYear financialYear = Global.CurrentFinancialYear;

            if (financialYear == null)
            {
                SystemSounds.Exclamation.Play();
                string message = "No Financial year to back up." +
                                 "\nPlease open a financial year and then backup its database.";
                MessageBox.Show(message, "No Opened Financial Year", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                return;
            }

            if (!GlobalMethods.closeCurrentlyOpenYear())
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            bool success = backupDatabase(financialYear);

            if (success)
            {
                SystemSounds.Asterisk.Play();
                Cursor.Current = Cursors.Default;
                MessageBox.Show("The database was successfully backed up !!", "Success",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            //open the financial year irrespective of the result

            Global.CurrentFinancialYear = financialYear;
            this.MdiParent.Text         = Global.AssemblyTitle + " (Financial Year: " +
                                          Global.CurrentFinancialYear.ToString() + ")";

            Properties.Settings.Default.LastBackupLocation = backupLocationField.Text;
            try
            {
                Properties.Settings.Default.Save();
            }
            catch (Exception ex) { ErrorLogger.LogError(ex); }

            Cursor.Current = Cursors.Default;
            this.Close();
        }
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            FinancialYear fy = obj as FinancialYear;

            if (fy == null)
            {
                return(false);
            }

            return(this.StartYear == fy.StartYear);
        }
Exemple #8
0
        private bool deleteFinancialYear(FinancialYear year)
        {
            try
            {
                File.Delete(year.FilePath);
            }
            catch (Exception ex)
            {
                string message = "An error occurred in deleting the database file for the financial year " +
                                 year.ToString() + "\nThe error text is as follows:\n" + Global.getExceptionText(ex);
                SystemSounds.Hand.Play();
                Cursor.Current = Cursors.Default;
                MessageBox.Show(message, "Error Occurred", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                ErrorLogger.LogError(ex);
                return(false);
            }

            return(true);
        }
Exemple #9
0
        private void okButton_Click(object sender, EventArgs e)
        {
            FinancialYear selectedYear = (FinancialYear)financialYearsListBox.SelectedItem;

            string message = "Are you sure that you want to delete the financial year " +
                             selectedYear.ToString() + "?";

            SystemSounds.Question.Play();

            DialogResult result = MessageBox.Show(message, "Confirm Deletion", MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Question);

            if (result == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            if (Global.CurrentFinancialYear != null && Global.CurrentFinancialYear.StartYear ==
                selectedYear.StartYear)
            {
                if (!GlobalMethods.closeCurrentlyOpenYear())
                {
                    return;
                }
            }

            if (!deleteFinancialYear(selectedYear))
            {
                return;
            }

            financialYearsListBox.Items.Remove(selectedYear);
            SystemSounds.Asterisk.Play();
            MessageBox.Show("The financial year " + selectedYear.ToString() + " was successfully deleted.",
                            "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #10
0
 private static int CompareFinancialYears(FinancialYear a, FinancialYear b)
 {
     return(a.CompareTo(b));
 }
Exemple #11
0
 public int CompareTo(FinancialYear fy)
 {
     return(this.StartYear - fy.StartYear);
 }
Exemple #12
0
        private bool isExists(int startYear)
        {
            FinancialYear fy = new FinancialYear(startYear, DateTime.Today, string.Empty);

            return(financialYears.Contains(fy));
        }
Exemple #13
0
        private void okButton_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            if (!this.ValidateChildren(ValidationConstraints.Enabled))
            {
                Cursor.Current = Cursors.Default;
                return;
            }

            int      startYear = (int)startYearField.Value;
            DateTime booksStartDate;

            if (transferDataFromAnotherYearButton.Enabled && transferDataFromAnotherYearButton.Checked)
            {
                booksStartDate = new DateTime(startYear, 4, 1);
            }
            else
            {
                booksStartDate = booksStartDatePicker.Value.Date;
            }

            if (!createRootFolderIfNotExists())
            {
                return;
            }

            if (!CreateDatabase(startYear, booksStartDate))
            {
                return;
            }

            if (transferDataFromAnotherYearButton.Enabled && transferDataFromAnotherYearButton.Checked)
            {
                string        targetDatabasePath = getDatabaseNameWithPath(startYear);
                FinancialYear sourceYear         = (FinancialYear)financialYearCombo.SelectedItem;
                bool          result             = InterDatabaseDataTransfer.TransferData(sourceYear.FilePath, targetDatabasePath);
                if (!result)
                {
                    deleteDatabaseFile(targetDatabasePath);
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }

            string message = "The financial year " + startYear + "-" + (startYear + 1) +
                             " was successfully created.";

            SystemSounds.Asterisk.Play();
            Cursor.Current = Cursors.Default;
            MessageBox.Show(message, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

            if (Global.CurrentFinancialYear == null)
            {
                Global.CurrentFinancialYear = new FinancialYear(startYear, booksStartDate,
                                                                getDatabaseNameWithPath(startYear));
                this.MdiParent.Text = Global.AssemblyTitle + " (Financial Year: " + startYear + "-"
                                      + (startYear + 1) + ")";
            }

            this.Close();
        }