Example #1
0
        /// <summary>
        /// 导出.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormExport subForm = new FormExport();

            subForm.MdiParent = this;
            subForm.Show();
        }
Example #2
0
        /// <summary>
        /// Write all the data to a csv file.
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="FormExport"></param>
        public static void WriteFile(string FilePath, FormExport FormExport)
        {
            try
            {
                ModelList ModelList = new ModelList();
                string    HeaderCsv = null;

                if (FilePath == "")
                {
                    if (MessageBox.Show("Please choose a file!", "ERROR") == DialogResult.OK)
                    {
                        using (OpenFileDialog openFileDialog = new OpenFileDialog())
                        {
                            openFileDialog.Filter           = "csv files (*.csv)|*.csv";
                            openFileDialog.RestoreDirectory = true;

                            if (openFileDialog.ShowDialog() == DialogResult.OK)
                            {
                                FilePath = openFileDialog.FileName;
                                FormExport.label_FichierExporte.Text = "FileName: " + System.IO.Path.GetFileName(FilePath);
                            }
                        }
                    }
                }

                using (var StreamReader = new StreamReader(FilePath, Encoding.Default))
                {
                    HeaderCsv = StreamReader.ReadLine();
                    StreamReader.Close();
                }

                using (var FileStream = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    FileStream.SetLength(0);
                    using (var StreamWriter = new StreamWriter(FileStream, Encoding.Default))
                    {
                        FormExport.progressBar.Maximum = ModelList.Articles.Count + 1;
                        FormExport.progressBar.Value   = 1;

                        StreamWriter.WriteLine(HeaderCsv);
                        foreach (var Article in ModelList.Articles)
                        {
                            StreamWriter.WriteLine(Article.Description + ";" + Article.RefArticle + ";" + Article.Marque.MarqueName
                                                   + ";" + FamilleController.FindFamillesByRefFamille(Article.SousFamille.RefFamille).FamilleName + ";" + Article.SousFamille.SousFamilleName + ";" + Article.PrixHT);
                            FormExport.progressBar.Value++;
                        }
                    }
                }

                string Message = ModelList.Articles.Count + " articles have been added!";

                MessageBox.Show(" Export success!\n" + Message, System.IO.Path.GetFileName(FilePath));
            }
            catch
            {
                MessageBox.Show("Please close the selected file!");
            }
        }
Example #3
0
 public static void ExportCesium3DTiles(string unparsed)
 {
     using (AssemblyResolver.Use())
     {
         try
         {
             var view = Session.GetActiveViewport();
             var hasSelectElements = SelectionSetManager.NumSelected() > 0;
             var appConfig         = AppConfigManager.Load();
             var dialog            = new FormExport(view, appConfig, hasSelectElements, Titles.CESIUM_3D_TILES);
             dialog.ShowDialog();
         }
         catch (Exception ex)
         {
             Log(ex.ToString());
         }
     }
 }
Example #4
0
        public override int ExecuteCommand(string name, params string[] parameters)
        {
            var mainWindow = Autodesk.Navisworks.Api.Application.Gui.MainWindow;

            try
            {
                switch (name)
                {
#if !EXPRESS
                case @"ButtonExportToSvfzip":
                {
                    var appConfig = AppConfigManager.Load();
                    var dialog    = new FormExport(appConfig, TITLE_SVF);
                    dialog.ShowDialog(mainWindow);
                    break;
                }
#endif
                case @"ButtonExportToGltf":
                {
                    var appConfig = AppConfigManager.Load();
                    var dialog    = new FormExport(appConfig, TITLE_GLTF);
                    dialog.ShowDialog(mainWindow);
                    break;
                }

                case @"ButtonExportToCesium3DTiles":
                {
                    var appConfig = AppConfigManager.Load();
                    var dialog    = new FormExport(appConfig, TITLE_3DTILES);
                    dialog.ShowDialog(mainWindow);
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(mainWindow, ex.ToString(), @"Exception", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }

            return(0);
        }
Example #5
0
        public static void ExportSvfzip(string unparsed)
        {
#if EXPRESS
            Log(@"Unsupported function: 'Export Svfzip'");
#else
            using (AssemblyResolver.Use())
            {
                try
                {
                    var view = Session.GetActiveViewport();
                    var hasSelectElements = SelectionSetManager.NumSelected() > 0;
                    var appConfig         = AppConfigManager.Load();
                    var dialog            = new FormExport(view, appConfig, hasSelectElements, Titles.SVFZIP);
                    dialog.ShowDialog();
                }
                catch (Exception ex)
                {
                    Log(ex.ToString());
                }
            }
#endif
        }
Example #6
0
        private void exportStringToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormExport f2 = new FormExport();

            f2.Show(); // Shows Form2
        }
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            var uiapp = commandData.Application;
            var uidoc = uiapp.ActiveUIDocument;
            var doc   = uidoc.Document;

            var view = doc.ActiveView as View3D;

            if (null == view)
            {
                ShowMessageBox(Strings.MessageOpen3DViewFirst);
                return(Result.Succeeded);
            }

            Dictionary <int, bool> elementIds;

            var elementSelected = uidoc.Selection.GetElementIds();

            if (elementSelected != null && elementSelected.Count > 0)
            {
                elementIds = new Dictionary <int, bool>(elementSelected.Count);
                foreach (var elementId in elementSelected)
                {
                    if (elementId == ElementId.InvalidElementId)
                    {
                        continue;
                    }
                    elementIds.Add(elementId.IntegerValue, true);
                }
            }
            else
            {
                elementIds = null;
            }

            try
            {
#if R2014
                uidoc.Selection.Elements?.Clear();
#else
                uidoc.Selection.SetElementIds(new List <ElementId>());
#endif
                Application.DoEvents();

                var appConfig = AppConfigManager.Load();
                var dialog    = new FormExport(uidoc, view, appConfig, elementIds, TITLE);
                dialog.ShowDialog();
            }
            finally
            {
#if R2014
                if (elementSelected != null && elementSelected.Count > 0)
                {
                    foreach (var elementId in elementSelected)
                    {
                        var element = doc.GetElement(elementId);
                        uidoc.Selection.Elements?.Add(element);
                    }
                }
#else
                uidoc.Selection.SetElementIds(elementSelected);
#endif
            }

            return(Result.Succeeded);
        }
Example #8
0
        /*
         * private void ExportDBF(Action<IEnumerable<FileInfo>> callBack)
         * {
         *  var filesToDownload = GetSelectedFiles();
         *  var disc = DiscoverRepository.GetInstance();
         *  var rep = DiscoverRepository.CurrentRepository;
         *  var convert = new DBConvert(folderBrowserDialog1.SelectedPath);
         *  var download = disc.DownloadCache(rep.Name, DiscoveredRepositoryCache.Files, filesToDownload);
         *  var localFiles = disc.CopyCacheTo(download, folderBrowserDialog1.SelectedPath);
         *  convert.ConvertDBC2DBF(localFiles.ToArray());
         *  foreach (var lf in localFiles)
         *      lf.Delete();
         *  callBack?.Invoke( localFiles.Select(f => new FileInfo(f.FullName.ToLower().TrimEnd('c') + "f"))?.ToArray());
         *  //return convert;
         * }
         *
         * private void ExportLocalDBF(Action<IEnumerable<FileInfo>> callBack)
         * {
         *  var filesToDownload = GetSelectedFiles();
         *  var disc = DiscoverRepository.GetInstance();
         *  var rep = DiscoverRepository.CurrentRepository;
         *  var wk = Path.Combine(@"c:\temp\sus", rep.Name);
         *  if (!Directory.Exists(wk))
         *      Directory.CreateDirectory(wk);
         *  var convert = new DBConvert(wk);
         *  var download = disc.DownloadCache(rep.Name, DiscoveredRepositoryCache.Files, filesToDownload);
         *  var localFiles = disc.CopyCacheTo(download, wk);
         *  convert.ConvertDBC2DBF(localFiles.ToArray());
         *  foreach (var lf in localFiles)
         *      lf.Delete();
         *  callBack?.Invoke(localFiles.Select(f => new FileInfo(f.FullName.ToLower().TrimEnd('c') + "f"))?.ToArray());
         *  //return convert;
         * }*/

        private void btnExport_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = @"C:\";
            var selected = GetSelectedFiles("dbc");

            if ((selected?.Count() ?? 0) == 0)
            {
                MessageBox.Show("Selecione ao menos um arquivo compatível (.dbc)!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            var files = GetSelectedFiles().Where(f => f.Name.ToLower().EndsWith("dbc"));

            if (files?.Count() != selected?.Count())
            {
                MessageBox.Show("Apenas arquivos no formato DBC podem ser exportados para outros formatos\r\nOutras extensões serão ignoradas no processo",
                                "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            string type = "";

            FormExport.OpenDialog((format) => {
                type = format;
            });
            if (string.IsNullOrEmpty(type))
            {
                return;
            }
            if (folderBrowserDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var workingFolder   = DBConvert.GetWorkingDirectory();
            var filesToDownload = GetSelectedFiles();
            var disc            = DiscoverRepository.GetInstance();
            var rep             = DiscoverRepository.CurrentRepository;

            type = Regex.Match(type, @"\w+", RegexOptions.IgnoreCase).Value.ToUpper();

            IEnumerable <FileInfo> dbfs = null;

            Action callbackExport = () =>
            {
                disc.ExportFiles2DBF(filesToDownload, (d) => dbfs = d, workingFolder);
            };
            var  tableManager = new DBFReader(workingFolder, DBVersion.Default);
            bool tdbf         = false;

            switch (type)
            {
            case "DBF":
                tdbf            = true;
                callbackExport += () => {
                    tdbf = true;
                };
                break;

            case "XML":
                callbackExport += () =>
                {
                    if (dbfs?.Any() != true)
                    {
                        return;
                    }
                    foreach (var dbf in dbfs)
                    {
                        tableManager.ToXML(dbf.Name);
                    }
                };
                break;

            case "CSV":
                callbackExport += () =>
                {
                    if (dbfs?.Any() != true)
                    {
                        return;
                    }
                    foreach (var dbf in dbfs)
                    {
                        tableManager.ToCSV(dbf.Name);
                    }
                };
                break;

            case "JSON":
                callbackExport += () =>
                {
                    if (dbfs?.Any() != true)
                    {
                        return;
                    }
                    foreach (var dbf in dbfs)
                    {
                        tableManager.ToJSON(dbf.Name);
                    }
                };
                break;
            }
            if (!tdbf)
            {
                callbackExport += () =>
                {
                    if (dbfs?.Any() != true)
                    {
                        return;
                    }
                    foreach (var dbf in dbfs)
                    {
                        dbf.Delete();
                    }
                };
            }
            else
            {
                callbackExport += () =>
                {
                    if (dbfs?.Any() != true)
                    {
                        return;
                    }
                    foreach (var dbf in dbfs)
                    {
                        dbf.MoveTo(Path.Combine(folderBrowserDialog1.SelectedPath, dbf.Name));
                    }
                };
            }
            callbackExport += () =>
            {
                tableManager.Dispose();
                //MessageBox.Show("Arquivos exportados com sucesso", "Conversão", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Process.Start("explorer", folderBrowserDialog1.SelectedPath);
            };


            FormProgress.Run(callbackExport, (ex) =>
            {
                if (ex != null)
                {
                    MessageBox.Show("Ocorreu a sequinte excessão:\r\n" + ex, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            });
        }
        /*
         * public static string ExportToCsv<T>(string fileName, IList<T> listModel) where T : class, new()
         * {
         *  string results = "";
         *  try
         *  {
         *      StringBuilder sb = new StringBuilder();
         *      //通过反射 显示要显示的列
         *      BindingFlags bf = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;//反射标识
         *      Type objType = typeof(T);
         *      PropertyInfo[] propInfoArr = objType.GetProperties(bf);
         *      string header = string.Empty;
         *      List<string> listPropertys = new List<string>();
         *      foreach (PropertyInfo info in propInfoArr)
         *      {
         *          if (string.Compare(info.Name.ToUpper(), "ID") != 0) //不考虑自增长的id或者自动生成的guid等
         *          {
         *              if (!listPropertys.Contains(info.Name))
         *              {
         *                  listPropertys.Add(info.Name);
         *              }
         *              header += info.Name + ";";
         *          }
         *      }
         *      //这里是要生成的表头
         *      header = "Description" + ";" + "Ref" + ";" + "Marque" + ";" + "Famille" + ";" + "Sous-Famille" + ";" + "Prix H.T.";
         *      sb.AppendLine(header.Trim(';')); //csv头
         *
         *      foreach (T model in listModel)
         *      {
         *          string strModel = string.Empty;
         *          foreach (string strProp in listPropertys)
         *          {
         *              foreach (PropertyInfo propInfo in propInfoArr)
         *              {
         *                  if (string.Compare(propInfo.Name.ToUpper(), strProp.ToUpper()) == 0)
         *                  {
         *                      PropertyInfo modelProperty = model.GetType().GetProperty(propInfo.Name);
         *                      if (modelProperty != null)
         *                      {
         *                          object objResult = modelProperty.GetValue(model, null);
         *                          string result = ((objResult == null) ? string.Empty : objResult).ToString().Trim();
         *                          if (result.IndexOf(';') != -1)
         *                          {
         *                              result = "\"" + result.Replace("\"", "\"\"") + "\""; //特殊字符处理
         *                          }
         *                          if (!string.IsNullOrEmpty(result))
         *                          {
         *                              Type valueType = modelProperty.PropertyType;
         *                              if (valueType.Equals(typeof(Nullable<decimal>)))
         *                              {
         *                                  result = decimal.Parse(result).ToString("#.#");
         *                              }
         *                              else if (valueType.Equals(typeof(decimal)))
         *                              {
         *                                  result = decimal.Parse(result).ToString("#.#");
         *                              }
         *                              else if (valueType.Equals(typeof(Nullable<double>)))
         *                              {
         *                                  result = double.Parse(result).ToString("#.#");
         *                              }
         *                              else if (valueType.Equals(typeof(double)))
         *                              {
         *                                  result = double.Parse(result).ToString("#.#");
         *                              }
         *                              else if (valueType.Equals(typeof(Nullable<float>)))
         *                              {
         *                                  result = float.Parse(result).ToString("#.#");
         *                              }
         *                              else if (valueType.Equals(typeof(float)))
         *                              {
         *                                  result = float.Parse(result).ToString("#.#");
         *                              }
         *                          }
         *                          strModel += result + ";";
         *                      }
         *                      else
         *                      {
         *                          strModel += ";";
         *                      }
         *                      break;
         *                  }
         *              }
         *          }
         *          strModel = strModel.Substring(0, strModel.Length - 1);
         *          sb.AppendLine(strModel);
         *      }
         *      string content = sb.ToString();
         *
         *      results = content;
         *
         *  }
         *  catch
         *  {
         *
         *  }
         *  return results;
         *
         * }
         */


        /*
         * public static string ExportToCsv(string FilePath, FormExport Form_Export, BacchusModel BacchusModel)
         * {
         *  string FileName = System.IO.Path.GetFileNameWithoutExtension(FilePath);
         *  string Path = System.IO.Path.GetDirectoryName(FilePath);
         *
         *  var NbLines = (int)BacchusModel.GetArticles().LongCount();
         *
         *  Form_Export.ToolStripProgressBar.Maximum = NbLines;
         *  Form_Export.ToolStripProgressBar.Value = 0;
         *
         *  StreamWriter writer = null;
         *
         *  //StreamReader.ReadLine();
         *
         *  writer = new StreamWriter(FilePath);
         *  StringBuilder sb = new StringBuilder();
         *  string header = string.Empty;
         *  //这里是要生成的表头
         *  header = "Description" + ";" + "Ref" + ";" + "Marque" + ";" + "Famille" + ";" + "Sous-Famille" + ";" + "Prix H.T.";
         *  sb.AppendLine(header.Trim(';')); //csv头
         *
         *  List<Article> Articles = BacchusModel.GetArticles();
         *  Articles[i]
         *  for (int i = 0; i < NbLines; i++)
         *  {
         *      for (int j = 0; j < 6; j++)
         *      {
         *
         *
         *
         *          Marque Marque = BacchusModel.SearchMarque(Nom_Marque);
         *
         *          String ValueArticle =
         *          var Description = Values[0].Trim();
         *          var Ref_Article = Values[1].Trim();
         *          var Nom_Marque = Values[2].Trim();
         *          var Nom_Famille = Values[3].Trim();
         *          var Nom_SousFamille = Values[4].Trim();
         *          var PrixHT = float.Parse(Values[5].Trim());
         *      }
         *
         *  }
         *
         *
         *
         *
         *
         *
         *
         *
         *
         *  int AddedProducts = 0;
         *  int ExistingProducts = 0;
         *
         *  using (var StreamReader = new StreamReader(FilePath, Encoding.Default))
         *  {
         *      //var NbLines = File.ReadAllLines(FilePath).Length;
         *      var NbLines = (int)BacchusModel.GetArticles().LongCount();
         *
         *      Form_Export.ToolStripProgressBar.Maximum = NbLines;
         *      Form_Export.ToolStripProgressBar.Value = 0;
         *
         *
         *      string Line;
         *      while (writer.WriteLine()) == null)
         *      {
         *
         *          var Values = Line.Split(';');
         *
         *          var Description = Values[0].Trim();
         *          var Ref_Article = Values[1].Trim();
         *          var Nom_Marque = Values[2].Trim();
         *          var Nom_Famille = Values[3].Trim();
         *          var Nom_SousFamille = Values[4].Trim();
         *          var PrixHT = float.Parse(Values[5].Trim());
         *
         *          if (BacchusModel.SearchArticle(Ref_Article) != null)
         *          {
         *              ExistingProducts += 1;
         *              continue;
         *          }
         *          else
         *          {
         *              AddedProducts += 1;
         *          }
         *
         *          Marque Marque = BacchusModel.SearchMarque(Nom_Marque);
         *          if (Marque == null)
         *          {
         *              Marque = new Marque(0, Nom_Marque);
         *              BacchusModel.Marques.Add(Marque);
         *              MarqueDAO MarqueDao = new MarqueDAO();
         *              int countmarque = MarqueDao.Insert(Marque);
         *
         *          }
         *
         *          Famille Famille = BacchusModel.SearchFamille(Nom_Famille);
         *          if (Famille == null)
         *          {
         *              Famille = new Famille(0, Nom_Famille);
         *              BacchusModel.Familles.Add(Famille);
         *              FamilleDAO FamilleDao = new FamilleDAO();
         *              int countfamille = FamilleDao.Insert(Famille);
         *          }
         *
         *          SousFamille SousFamille = BacchusModel.SearchSousFamille(Nom_SousFamille);
         *          if (SousFamille == null)
         *          {
         *              SousFamille = new SousFamille(0, Famille, Nom_SousFamille);
         *              BacchusModel.SousFamilles.Add(SousFamille);
         *              SousFamilleDAO SousFamilleDao = new SousFamilleDAO();
         *              SousFamilleDao.Insert(SousFamille);
         *          }
         *
         *          Article Article = new Article(Ref_Article, Description, SousFamille, Marque, PrixHT, 1);
         *          BacchusModel.Articles.Add(Article);
         *          ArticleDAO ArticleDao = new ArticleDAO();
         *          ArticleDao.Insert(Article);
         *
         *          Form_Export.ToolStripProgressBar.Value++;
         *      }
         *      StreamWriter.Close();
         *  }
         *
         *  string Message = "Résultat: \n" +
         *                   "Nombre d'articles ajoutés " + AddedProducts + "\n" +
         *                   "Nombre d'articles anomalies " + ExistingProducts;
         *  return Message;
         *
         * }
         */



        public static string ExportToCsv(string FilePath, FormExport Form_Export, BacchusModel BacchusModel)
        {
            return(null);
        }
Example #10
0
 public static void RunExport()
 {
     FormExport formExport = new FormExport();
     formExport.ShowDialog();
 }