Exemplo n.º 1
0
 private void byOfficeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (ActiveMdiChild.GetType() == typeof(FRM_EquipmentEditing))
     {
         // get the active mdi child and determine if it is an equipment form
         FRM_EquipmentEditing tempForm = (FRM_EquipmentEditing)ActiveMdiChild;
     }
 }
Exemplo n.º 2
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fileCounter++;
            FRM_EquipmentEditing frm = new FRM_EquipmentEditing();

            frm.MdiParent = this;
            frm.Show();
            openFileName = frm.Filepath;
        }
Exemplo n.º 3
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "SQL Server Database Files|*.mdf";
            open.Title  = "Open Inventory File";

            if (open.ShowDialog() == DialogResult.OK) // if the user pressed OK on the form then read the file
            {
                FRM_EquipmentEditing frm = new FRM_EquipmentEditing(open.FileName);
                frm.MdiParent = this;
                frm.Show();
                openFileName = open.FileName;
            }
        }
Exemplo n.º 4
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                // get active MDI Form and determine if it is an EquipmentView Form
                if (ActiveMdiChild.GetType() == typeof(FRM_EquipmentEditing))
                {
                    // get the active mdi child and determine if it is an equipment form
                    FRM_EquipmentEditing tempForm = (FRM_EquipmentEditing)ActiveMdiChild;

                    if (tempForm.PageEquip.getResultCount() == 0)
                    {
                        MessageBox.Show("Database table has no entries!", "Saving Failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    SaveFileDialog save = new SaveFileDialog();
                    save.Filter   = "SQL Server Database Files|*.mdf";
                    save.Title    = "Save Inventory File";
                    save.FileName = "Equipment_Record";

                    DialogResult result = save.ShowDialog();

                    if (result == DialogResult.OK && tempForm.IsNewDB == true)
                    {
                        try
                        {
                            if (File.Exists(save.FileName)) // overwrite the existing file
                            {
                                File.Delete(save.FileName);
                                string str = Path.GetFileNameWithoutExtension(save.FileName);
                                str += "_log.ldf";
                                string str2 = Path.GetDirectoryName(save.FileName);
                                File.Delete(str2 + @"\\" + str); // delete the ldf file
                            }
                            tempForm.Db.Dispose(true);
                            File.Move(tempForm.Db.fileName, save.FileName);

                            tempForm.IsNewDB  = false;
                            tempForm.Filepath = save.FileName; // load the saved Database and bind it to the DGV

                            tempForm.initalizeDataGrid(tempForm.getDGV());
                            tempForm.PageEquip.ReCount();
                            tempForm.PageEquip.loadPage();
                            tempForm.PageMnf.ReCount();
                            tempForm.PageMnf.loadPage();
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show(err.Message);
                        }
                    }
                    else if (result == DialogResult.OK && tempForm.IsNewDB == false)
                    {
                        try
                        {
                            if (File.Exists(save.FileName)) // overwrite if the file is exisiting
                            {
                                File.Delete(save.FileName);
                                string str = Path.GetFileNameWithoutExtension(save.FileName);
                                str += "_log.ldf";
                                string str2 = Path.GetDirectoryName(save.FileName);
                                File.Delete(str2 + @"\\" + str);            // delete the ldf file
                            }
                            File.Copy(tempForm.Db.fileName, save.FileName); // copy DB to the new DIR
                            tempForm.Db.Dispose(true);

                            tempForm.IsNewDB  = false;
                            tempForm.Filepath = save.FileName; // load the saved Database and bind it to the DGV
                            tempForm.initalizeDataGrid(tempForm.getDGV());
                            tempForm.PageEquip.ReCount();
                            tempForm.PageEquip.loadPage();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Failed to Save file, are you trying to overwrite a locked DB?", "Saving Failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
            catch (Exception)
            { }
        }