Ejemplo n.º 1
0
        private void BrowseFileButton_OnClick(object sender, RoutedEventArgs e)
        {
            using (var openFileDialog = new Forms.OpenFileDialog())
            {
                Forms.DialogResult result = openFileDialog.ShowDialog();

                if (result == Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(openFileDialog.FileName))
                {
                    AddAppOrFolder(openFileDialog.FileName);
                }
            }

            HideFileFolderSelection();
        }
Ejemplo n.º 2
0
 private void Import()
 {
     if (ImportButtonContent == startImportStr)
     {
         DoProgress(delegate
         {
             var dataSet = LoadDataFromExcel();
             FillData(dataSet);
         }, "正在导入...");
     }
     else
     {
         using (var dialog = new System.Windows.Forms.OpenFileDialog()
         {
             DefaultExt = "xls"
         }) {
             if (dialog.ShowDialog() == DialogResult.OK && dialog.FileName != null)
             {
                 ExcelPath = dialog.FileName;
             }
         }
     }
 }
Ejemplo n.º 3
0
 public static string SystemFileName()
 {
     string result;
     using (var openFileDialog = new System.Windows.Forms.OpenFileDialog())
     {
         openFileDialog.Filter = "All File (*.*)|*.*";
         openFileDialog.InitialDirectory = "C:\\krc\\bin\\";
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             result = openFileDialog.FileName;
             return result;
         }
     }
     result = string.Empty;
     return result;
 }
Ejemplo n.º 4
0
        private void ImportDatabaseXmlClickExecute(RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog
            {
                Filter = "Xml file|*.xml",
                Title = "Import Xml-file as a Database.",
                RestoreDirectory = true
            };

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
               // try
                //{
                    using (Stream fileStream = File.Open(openFileDialog.FileName, FileMode.Open))
                    {
                        using (XmlReader reader = XmlReader.Create(fileStream))
                        {
                            switch (openFileDialog.SafeFileName)
                            {
                                case "devices.xml":
                                    var value1 = DeserializeXmlToObject(reader, typeof(ObservableCollection<Device>));
                                    break;
                                case "categories.xml":
                                    var value2 = DeserializeXmlToObject(reader, typeof(ObservableCollection<Category>));
                                    ImportCategories((ObservableCollection<Category>)value2);
                                    break;
                                case "productTypes.xml":
                                    var value3 = DeserializeXmlToObject(reader, typeof(ObservableCollection<ProductType>));
                                    ImportProductTypes((ObservableCollection<ProductType>)value3);
                                    break;
                                case "suppliers.xml":
                                    var value4 = DeserializeXmlToObject(reader, typeof(ObservableCollection<Supplier>));
                                    break;
                                case "cableTypes.xml":
                                    var value5 = DeserializeXmlToObject(reader, typeof (ObservableCollection<CableType>));
                                    break;
                                case "sockets.xml":
                                    var value6 = DeserializeXmlToObject(reader, typeof(ObservableCollection<Socket>));
                                    break;
                                case "signalTypes.xml":
                                    var value7 = DeserializeXmlToObject(reader, typeof(ObservableCollection<SignalType>));
                                    break;
                            }
                        }
                    }
               // }
/*                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message, "Error",
                        MessageBoxButton.OK, MessageBoxImage.Error);
                }*/
            }
        }