コード例 #1
0
ファイル: MainForm.cs プロジェクト: aldarcose/AISReports
        private void InitTreeView()
        {
            ReportSchema schema = null;
            var          lf     = new LoadingForm
            {
                WaitForThis = new System.Threading.Tasks.Task(() =>
                {
                    schema = ReportManager.Instance.LoadDbReportSchema();
                })
            };

            lf.ShowDialog();
            if (schema == null)
            {
                return;
            }

            ReportSchema.Instance = schema;
            foreach (var folder in schema.Folders)
            {
                TreeNode treeNode = new TreeNode(folder.Name, 0, 0);
                treeView1.Nodes.Add(treeNode);
                PopulateTreeView(folder, treeNode);
            }

            foreach (var report in schema.Reports)
            {
                TreeNode treeNode = new TreeNode(report.Name, 1, 1);
                treeNode.Tag = report;
                treeView1.Nodes.Add(treeNode);
            }
        }
コード例 #2
0
        public ReportSchema LoadDbReportSchema()
        {
            // Схема отчетов
            ReportSchema schema = new ReportSchema();
            // Загрузка отчетов
            var dbReports = LoadDbReports();

            Dictionary <int, Folder> folders = new Dictionary <int, Folder>();
            Folder             tempFolder;
            Func <int, Folder> GetFolder = id =>
            {
                if (!folders.TryGetValue(id, out tempFolder))
                {
                    return(null);
                }
                return(tempFolder);
            };

            foreach (var dbReport in dbReports)
            {
                if (dbReport.Fields[3] == DBNull.Value)
                {
                    continue;
                }

                object paramsData = dbReport.Fields[4];
                string entryName  = (string)dbReport.Fields[3];
                int    id         = (int)dbReport.Fields[0];
                int    parent_id  = (int)dbReport.Fields[1];
                int    level      = (int)dbReport.Fields[2];

                string paramsText = GetStringParameters(paramsData);
                if (!string.IsNullOrEmpty(paramsText))
                {
                    // Пропуск пустых отчетов
                    if (paramsText.Equals("NULL") || paramsText.Equals(Environment.NewLine))
                    {
                        continue;
                    }

                    bool isDesignedReport             = false;
                    var  report                       = new Report(id, entryName);
                    List <ReportParameter> parameters = ParseParameters(paramsText, ref isDesignedReport);
                    if (parameters == null)
                    {
                        continue;
                    }

                    report.IsDesigned = isDesignedReport;
                    report.Parameters.AddRange(parameters);

                    if (level == 1)
                    {
                        schema.Reports.Add(report);
                    }
                    else
                    {
                        GetFolder(parent_id).Reports.Add(report);
                    }
                }
                else
                {
                    Folder folder = new Folder(entryName, level);
                    if (level != 1)
                    {
                        GetFolder(parent_id).Folders.Add(folder);
                    }

                    folders[id] = folder;
                }
            }

            // Корневые папки
            foreach (Folder fldr in folders.Values)
            {
                if (fldr.Level != 1)
                {
                    continue;
                }
                schema.Folders.Add(fldr);
            }
            return(schema);
        }