Ejemplo n.º 1
0
        /// <summary>
        /// Form Validation then create the store
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BTN_Create_Click(object sender, EventArgs e)
        {
            string storeName = TB_StoreName.Text + Utilities.NEW_FILE_TYPE;

            Directory.CreateDirectory(Utilities.DEFAULT_SAVE_PATH);

            // If store name is invalid
            if (storeName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                MessageBox.Show(Utilities.MSG_INVALID_CHARS,
                                Utilities.ERROR_INVALID_CHARS,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            // else if file already exists
            else if (File.Exists(Path.Combine(Utilities.DEFAULT_SAVE_PATH, storeName)))
            {
                MessageBox.Show(Utilities.MSG_FILE_EXISTS,
                                Utilities.ERROR_FILE_EXISTS,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            // All good!
            else
            {
                string saveFile = Path.Combine(Utilities.DEFAULT_SAVE_PATH, storeName);
                var    file     = File.Create(saveFile);
                file.Close();

                MessageBox.Show(Utilities.MSG_FILE_CREATED,
                                Utilities.SUCCESS_TITLE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                Utilities.STORE_FILE = saveFile;
                Utilities.STORE_NAME = TB_StoreName.Text;

                // Set parent form
                StoreForm storeForm = new StoreForm
                {
                    MdiParent = _workshop
                };
                storeForm.Show();
            }
        }
        // Opens a previously generated store
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Title            = "Browse Store Files",
                DefaultExt       = Utilities.NEW_FILE_TYPE,
                CheckFileExists  = true,
                CheckPathExists  = true,
                InitialDirectory = Utilities.DEFAULT_SAVE_PATH,
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Utilities.STORE_NAME = Path.GetFileNameWithoutExtension(openFileDialog.FileName);
                Utilities.STORE_FILE = openFileDialog.FileName;

                StoreForm storeForm = new StoreForm();
                storeForm.MdiParent = this;
                storeForm.Show();
            }
        }