Example #1
0
 public static bool TryGetPath(this FileDialog dialog, out string path)
 {
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         path = dialog.FileName;
         dialog.Dispose();
         return(true);
     }
     else
     {
         dialog.Dispose();
         path = null;
         return(false);
     }
 }
Example #2
0
            void BrowseButtonClicked(object sender, EventArgs e)
            {
                dialog = new OpenFileDialog();

                try {
                    if (!string.IsNullOrEmpty(currentFolder))
                    {
                        dialog.CurrentFolder = currentFolder;
                    }
                    if (!string.IsNullOrEmpty(title))
                    {
                        dialog.Title = title;
                    }
                    if (dialog.Run(ParentWindow))
                    {
                        FileName = dialog.FileName;
                    }

                    // Ensure the parent window has focus after the OpenFileDialog is closed.
                    IdeServices.DesktopService.FocusWindow(ParentWindow);
                } finally {
                    dialog.Dispose();
                    dialog = null;
                }
            }
            void BrowseButtonClicked(object sender, EventArgs e)
            {
                dialog = new OpenFileDialog();

                try
                {
                    if (!string.IsNullOrEmpty(currentFolder))
                    {
                        dialog.CurrentFolder = currentFolder;
                    }
                    if (!string.IsNullOrEmpty(title))
                    {
                        dialog.Title = title;
                    }
                    if (dialog.Run(ParentWindow))
                    {
                        FileName = dialog.FileName;
                    }
                }
                finally
                {
                    dialog.Dispose();
                    dialog = null;
                }
            }
Example #4
0
 protected override void Dispose(Boolean disposing)
 {
     PathBeenSelected  = null;
     PathsBeenSelected = null;
     FileDialog.Dispose();
     base.Dispose(disposing);
 }
Example #5
0
        /// <summary>
        /// Диалог открытия\сохранения файла
        /// </summary>
        /// <param name="filter">строка фильтра в формате "XML files (*.xml)|*.xml"</param>
        /// <param name="filename">имя файла, может быть null</param>
        /// <param name="isOpen">если true то открываеться диалог открытия, иначе диалог сохранения</param>
        /// <returns>возвращает полный путь к файлу, иначе null </returns>
        public static string OpenFile(string filter, string filename = null, bool isOpen = true)
        {
            string pt = null;

            if (filter == null)
            {
                filter = DefaultFilers;
            }
            System.Windows.Forms.FileDialog FileDialog = null;

            if (isOpen)
            {
                FileDialog = new System.Windows.Forms.OpenFileDialog();
            }
            else
            {
                FileDialog = new System.Windows.Forms.SaveFileDialog();
                //openFileDialog1.InitialDirectory = System.;
                if (filename != null)
                {
                    FileDialog.FileName = filename;
                }
            }

            FileDialog.Filter           = filter;
            FileDialog.FilterIndex      = 1;
            FileDialog.RestoreDirectory = true;
            if (FileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                pt = FileDialog.FileName;
            }
            FileDialog.Dispose();
            return(pt);
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting
 /// unmanaged resources.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void Dispose()
 {
     if (m_dlg != null)
     {
         m_dlg.Dispose();
     }
     m_dlg = null;
 }
Example #7
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         if (disposing)
         {
             fileDialog?.Dispose();
         }
         disposedValue = true;
     }
 }
Example #8
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FileDialog openFileDialog = (FileDialog) new OpenFileDialog();

            openFileDialog.Filter           = "CSV files (*.csv)|*.csv|Text Files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 0;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                openFileDialog.Dispose();
                return;
            }

            LoadFile(openFileDialog.FileName);
        }
Example #9
0
        void FileChooser_FileOk(object sender, CancelEventArgs e)
        {
            FileChooser.Dispose();
            if (e.Cancel)
            {
                return;
            }

            string ImportFileName = FileChooser.FileName;

            Program.logEvent("Import file name: " + ImportFileName);
            if (!File.Exists(ImportFileName))
            {
                Program.logEvent("Data file does not exist");
                Program.ShowErrorMessage(LanguageTranslation.DATA_FILE_NOT_EXIST, 4000);
                resetCurrentWorkingDirectory();
                return;
            }

            #region Import Users
            if (ImportType == ImportType.User)
            {
                try
                {
                    Program.logEvent("Importing User Data");
                    if (Path.GetExtension(ImportFileName) == ".xml")
                    {
                        Program.logEvent("XML File identified");
                        if ((Program.userMgr.ReloadFromFile(ImportFileName)))
                        {
                            Program.logEvent("XML File Verified");
                            File.Copy(ImportFileName, DestinationFileName, true);
                            Program.logEvent("XML File Copied");
                        }
                        else
                        {
                            Program.ShowErrorMessage(LanguageTranslation.DATA_FILE_HAS_ERRORS, 4000);
                            Program.logEvent("Error with file during user import");
                        }
                    }
                    else if (Path.GetExtension(ImportFileName) == ".csv")
                    {
                        Program.logEvent("CSV File identified");
                        usersList list = new usersList();
                        //read in list from .csv into List
                        StreamReader reader = new StreamReader(ImportFileName);
                        string       currentline; string[] currentlinecomponents;

                        currentline = reader.ReadLine(); //read the first line and ignore it
                        while (!reader.EndOfStream)
                        {
                            currentline = reader.ReadLine();

                            if (currentline.Trim() != "" && currentline != null)
                            {
                                currentlinecomponents = currentline.Split(',');
                                if (currentlinecomponents.Length == 5)
                                {
                                    list.AddUser(new User(currentlinecomponents[0].Trim(), currentlinecomponents[1].Trim(),
                                                          currentlinecomponents[2].Trim(), currentlinecomponents[3].Trim(),
                                                          currentlinecomponents[4].Trim()));
                                }
                                else if (currentlinecomponents.Length == 7)
                                {
                                    list.AddUser(new User(currentlinecomponents[0].Trim(), currentlinecomponents[1].Trim(),
                                                          currentlinecomponents[2].Trim(), currentlinecomponents[3].Trim(),
                                                          currentlinecomponents[4].Trim(), currentlinecomponents[5].Trim(),
                                                          currentlinecomponents[6].Trim()));
                                }
                                else if (currentlinecomponents.Length == 14)
                                {
                                    list.AddUser(new User(currentlinecomponents[0].Trim(), currentlinecomponents[1].Trim(),
                                                          currentlinecomponents[2].Trim(), currentlinecomponents[3].Trim(),
                                                          currentlinecomponents[4].Trim(), currentlinecomponents[5].Trim(),
                                                          currentlinecomponents[6].Trim(), int.Parse(currentlinecomponents[7].Trim()),
                                                          currentlinecomponents[8].Trim(), currentlinecomponents[9].Trim(),
                                                          currentlinecomponents[10].Trim(), int.Parse(currentlinecomponents[11].Trim()),
                                                          currentlinecomponents[12].Trim(), currentlinecomponents[13].Trim()));
                                }
                            }
                        }

                        Program.logEvent("CSV file read into memory");
                        //serialize list to XML file
                        list.SerializeToXmlFile("temp.xml");
                        Program.logEvent("CSV file converted to XML");
                        if ((Program.userMgr.ReloadFromFile("temp.xml")))
                        {
                            Program.logEvent("XML file Verified");
                            File.Copy("temp.xml", DestinationFileName, true);
                            Program.logEvent("XML file Copied");
                            try
                            {
                                File.Delete("temp.xml");
                                Program.logEvent("XML temp file deleted");
                            }
                            catch (Exception ex)
                            {
                                Program.logEvent("Error trying to delete temp.xml: " + ex.Message);
                            }
                        }
                        else
                        {
                            Program.ShowErrorMessage(LanguageTranslation.DATA_FILE_HAS_ERRORS, 4000);
                            Program.logEvent("Error with file during user import");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Program.ShowErrorMessage(LanguageTranslation.DATA_FILE_ERRORS_NOT_EXIST, 4000);
                    Program.logEvent("Error during user import: " + ex.Message);
                    this.Close();
                }
            }
            #endregion
            #region Import Access Codes
            else if (ImportType == ImportType.AccessCode)
            {
                try
                {
                    Program.logEvent("Importing KeyPassword Data");
                    if (Path.GetExtension(ImportFileName) == ".xml")
                    {
                        Program.logEvent("XML file identified");
                        if ((Program.passwordMgr.ReloadFromFile(ImportFileName)))
                        {
                            Program.logEvent("XML file verified");
                            File.Copy(ImportFileName, DestinationFileName, true);
                            Program.logEvent("XML file copied");
                        }
                        else
                        {
                            Program.ShowErrorMessage(LanguageTranslation.DATA_FILE_HAS_ERRORS, 4000);
                            Program.logEvent("Error with file during department import");
                        }
                    }
                    else if (Path.GetExtension(ImportFileName) == ".csv")
                    {
                        Program.logEvent("CSV file identified");
                        KeyPassWordList list = new KeyPassWordList();
                        //read in list from .csv into List
                        StreamReader reader = new StreamReader(ImportFileName);
                        string       currentline; string[] currentlinecomponents;

                        currentline = reader.ReadLine(); //read the first line and ignore it
                        while (!reader.EndOfStream)
                        {
                            currentline = reader.ReadLine();
                            if ((currentline.Trim() != "") && (currentline != null))
                            {
                                currentlinecomponents = currentline.Split(',');
                                if (currentlinecomponents.Length == 2)
                                {
                                    list.AddKeyPassword(new KeyPassword(currentlinecomponents[0].Trim(),
                                                                        currentlinecomponents[1].Trim()));
                                }
                                else if (currentlinecomponents.Length == 5)
                                {
                                    list.AddKeyPassword(new KeyPassword(currentlinecomponents[0].Trim(),
                                                                        currentlinecomponents[1].Trim(), currentlinecomponents[2].Trim(), currentlinecomponents[3].Trim(),
                                                                        currentlinecomponents[4].Trim()));
                                }
                                else if (currentlinecomponents.Length == 9)
                                {
                                    list.AddKeyPassword(new KeyPassword(currentlinecomponents[0].Trim(),
                                                                        currentlinecomponents[1].Trim(), currentlinecomponents[2].Trim(),
                                                                        currentlinecomponents[3].Trim(), currentlinecomponents[4].Trim(),
                                                                        currentlinecomponents[5].Trim(), int.Parse(currentlinecomponents[6].Trim()),
                                                                        currentlinecomponents[7].Trim(), currentlinecomponents[9].Trim()));
                                }
                            }
                        }
                        Program.logEvent("CSV file read into memory");
                        //serialize list to XML file
                        list.SerializeToXmlFile("temp.xml");
                        Program.logEvent("CSV file converted to XML");
                        if ((Program.passwordMgr.ReloadFromFile("temp.xml")))
                        {
                            Program.logEvent("XML file verified");
                            File.Copy("temp.xml", DestinationFileName, true);
                            Program.logEvent("XML file copied");
                            try
                            {
                                File.Delete("temp.xml");
                                Program.logEvent("XML temp file deleted");
                            }
                            catch (Exception ex)
                            {
                                Program.logEvent("Error trying to delete temp.xml: " + ex.Message);
                            }
                        }
                        else
                        {
                            Program.ShowErrorMessage(LanguageTranslation.DATA_FILE_HAS_ERRORS, 4000);
                            Program.logEvent("Error with file during department import");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Program.ShowErrorMessage(LanguageTranslation.DATA_FILE_ERRORS_NOT_EXIST, 4000);
                    Program.logEvent("Error during department import: " + ex.Message);
                    this.Close();
                }
            }
            #endregion
            button_cancel.Visible = false;
            SetLabelText(label, LanguageTranslation.IMPORT_COMPLETE);
            resetCurrentWorkingDirectory();
        }