Beispiel #1
0
        static async Task <object> LoadCodeLookupDictRows(AsyncExprCtx ae, IList args)
        {
            var conn = (IDbConn)await OPs.ConstValueOf(ae, args[0]);

            var table = Convert.ToString(await OPs.ConstValueOf(ae, args[1])).Replace(' ', '_').Replace(',', '_');
            var query = $"SELECT {nameof(LookupEntry.Code)}, {nameof(LookupEntry.Description)}, {nameof(LookupEntry.ReplacedWith_Code)} FROM {table}";
            var cmd   = new SqlCommandData()
            {
                Kind = CommandKind.Query, SqlText = query, ConvertMultiResultsToLists = false
            };
            var rows = (IIndexedDict[])await conn.ExecCmd(cmd, ae.Cancellation);

            var dict = new Dictionary <string, LookupEntry>(rows.Length);

            foreach (var r in rows)
            {
                var entry = new LookupEntry()
                {
                    Code              = r.ValuesList[0].ToString(),
                    Description       = Convert.ToString(r.ValuesList[1]),
                    ReplacedWith_Code = Convert.ToString(r.ValuesList[2]),
                };
                dict.Add(entry.Code, entry);
            }
            // incapsulate into tuple to mask IList interface
            return(Tuple.Create(dict));
        }
Beispiel #2
0
        public static async Task <object> _ReportRow(AsyncExprCtx ae, IList args)
        {
            // get/calculate values
            var lstVals = (IList)await OPs.VectorValueOf(ae, args[3]);

            int n    = lstVals.Count;
            var vals = new object[n];

            for (int i = n - 1; i >= 0; i--)
            {
                try { vals[i] = await OPs.ConstValueOf(ae, lstVals[i]); }
                catch (TaskCanceledException) { throw; }
            }
Beispiel #3
0
        public static async Task <object> WRptGetXmlWriter(AsyncExprCtx ae, IList args)
        {
            var outputFiles = (IWriteFiles)await OPs.ConstValueOf(ae, args[0]);

            var parts = new string[args.Count - 1];

            for (int i = args.Count - 1; i >= 1; i--)
            {
                parts[i - 1] = Convert.ToString(await OPs.ConstValueOf(ae, args[i]));
            }
            var stream = await outputFiles.CreateFile(Path.Combine(parts), ae.Cancellation);

            var writer = new XmlTextWriter(stream, Encoding.UTF8);

            return(writer);
        }
Beispiel #4
0
        public static async Task <object> _ReportSheet(AsyncExprCtx ae, IList args)
        {
            using (var wr = (XmlWriter)await OPs.ConstValueOf(ae, args[0]))
            {
                var xmls = (IEnumerable <Xlsx.XmlItem>) await OPs.ConstValueOf(ae, args[1]);

                wr.WriteStartDocument();
                object result = string.Empty;

                foreach (var xml in xmls)
                {
                    xml.WriteStartElementAndAttrs(wr);

                    var xmlSheetData = new Xlsx.XmlItem();
                    {   // write xml before "sheetData"
                        bool stop = false;
                        xml.Traverse(x =>
                        {
                            if (stop)
                            {
                                return;
                            }
                            if (x.Name != "sheetData")
                            {
                                if (x.Name == "dimension")
                                {
                                    return;
                                }
                                x.WritePart(wr);
                                return;
                            }
                            x.WriteStartElementAndAttrs(wr);
                            xmlSheetData = x;
                            stop         = true;
                        });
                    }
                    if (xmlSheetData.IsEmpty)
                    {
                        continue; // no sheet data
                    }
                    // write sheet data (rows)
                    for (int i = 2; i < args.Count; i++)
                    {
                        result = await OPs.ConstValueOf(ae, args[i]);

                        //Console.WriteLine(res); // debug
                    }

                    {   // write xml after "sheetData"
                        bool skip = true;
                        xml.Traverse(x =>
                        {
                            if (!skip)
                            {
                                x.WritePart(wr); return;
                            }
                            else if (x.Name == "sheetData")
                            {
                                skip = false;
                                wr.WriteEndElement();
                            }
                        });
                    }
                    wr.WriteEndElement();
                }
                wr.WriteEndDocument();
                return(result);
            }
        }