Exemple #1
0
        /// <summary>
        /// Получить список номеров выбранных элементов в списке на форме.
        /// </summary>
        /// <returns></returns>
        private List <int> GetCheckedItemsNumbers()
        {
            var checkedItems = new List <int>();

            foreach (var treeNode in exportingObjectsTree.AllNodes)
            {
                var node = treeNode.Tag as Node;
                if (node != null && node.CheckState == CheckState.Checked &&
                    node.Tag is ITreeViewItem item)
                {
                    if (item != null && item.IsMainObject)
                    {
                        List <ITreeViewItem> objects = TechObjectsExporter
                                                       .GetInstance().Objects.ToList();
                        int objGlobalNum = objects.IndexOf(item) + 1;
                        if (objGlobalNum > 0)
                        {
                            checkedItems.Add(objGlobalNum);
                        }
                    }
                }
            }

            bool isEmpty = checkedItems.Count == 0;

            if (isEmpty)
            {
                throw new Exception("Выберите хотя бы 1 объект для экспорта");
            }

            return(checkedItems);
        }
Exemple #2
0
        /// <summary>
        /// Кнопка "Экспортировать".
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exportButton_Click(object sender, EventArgs e)
        {
            var sfd = new SaveFileDialog();

            sfd.Filter     = saveFileDialogFilter;
            sfd.DefaultExt = luaExtension;

            try
            {
                var checkedItems = GetCheckedItemsNumbers();

                DialogResult saveResult = sfd.ShowDialog();
                if (saveResult == DialogResult.Cancel)
                {
                    return;
                }
                string fileName = sfd.FileName;

                TechObjectsExporter.GetInstance()
                .Export(fileName, checkedItems);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Предупреждение",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Close();
        }
 /// <summary>
 /// Singleton
 /// </summary>
 /// <returns></returns>
 public static TechObjectsExporter GetInstance()
 {
     if (techObjectsExporter == null)
     {
         techObjectsExporter = new TechObjectsExporter();
     }
     return(techObjectsExporter);
 }
Exemple #4
0
        /// <summary>
        /// Событие при загрузке формы.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExportObjectsForm_Load(object sender, EventArgs e)
        {
            exportingObjectsTree.BeginUpdate();
            exportingObjectsTree.Model = null;
            exportingObjectsTree.Refresh();
            var treeModel = new TreeModel();
            var root      = new Node(TechObjectsExporter.GetInstance().ProjectName);

            treeModel.Nodes.Add(root);

            ITreeViewItem[] objects = TechObjectsExporter.GetInstance()
                                      .RootItems;
            LoadObjectsForExport(objects, root);

            exportingObjectsTree.Model = treeModel;
            exportingObjectsTree.EndUpdate();
        }