예제 #1
0
파일: Template1.cs 프로젝트: ej-z/DMS
        public string CielingResults3(DocInputs inputs)
        {
            var None            = inputs.Attributes["None"];
            var Loosefill       = inputs.Attributes["Loosefill"];
            var InsulationBatts = inputs.Attributes["InsulationBatts"];

            if (None.FinalValue == "True")
            {
                return("No asbestos insulation was detected in the ceiling space.");
            }
            else if (Loosefill.FinalValue == "True" && InsulationBatts.FinalValue == "True")
            {
                return("Insulation batts, Loose fill insulation are distributed throughout the ceiling space.");
            }
            else if (Loosefill.FinalValue == "True")
            {
                return("Loose fill insulation is distributed throughout the ceiling space.");
            }
            else if (InsulationBatts.FinalValue == "True")
            {
                return("Insulation batts is distributed throughout the ceiling space.");
            }

            return(string.Empty);
        }
예제 #2
0
파일: Template1.cs 프로젝트: ej-z/DMS
        public string CielingResults1(DocInputs inputs)
        {
            var None            = inputs.Attributes["None"];
            var Loosefill       = inputs.Attributes["Loosefill"];
            var InsulationBatts = inputs.Attributes["InsulationBatts"];

            if (None.FinalValue == "True")
            {
                return("absence of insulation batts/loose fill insulation");
            }
            else if (Loosefill.FinalValue == "True" && InsulationBatts.FinalValue == "True")
            {
                return("presence of loose fill insulation, insulation batts");
            }
            else if (Loosefill.FinalValue == "True")
            {
                return("presence of loose fill insulation");
            }
            else if (InsulationBatts.FinalValue == "True")
            {
                return("presence of insulation batts");
            }

            return(string.Empty);
        }
예제 #3
0
파일: Repeater.cs 프로젝트: ej-z/DMS
        public int CloneInput()
        {
            var input = new DocInputs();

            foreach (var inputInfo in InputData)
            {
                input.AddInput(inputInfo.Name, inputInfo.Type, inputInfo.Properties);
            }
            RepeaterData.Add(input);
            return(LastPosition);
        }
예제 #4
0
파일: Template1.cs 프로젝트: ej-z/DMS
        public string CielingResults2(DocInputs inputs)
        {
            var LFAI            = inputs.Attributes["LFAIfound"];
            var Loosefill       = inputs.Attributes["Loosefill"];
            var InsulationBatts = inputs.Attributes["InsulationBatts"];

            if (LFAI.Value == "Yes")
            {
                return("Yes,");
            }
            else
            {
                return("No");
            }
        }
예제 #5
0
파일: Template1.cs 프로젝트: ej-z/DMS
        public string SampleResults2(DocInputs inputs)
        {
            var repeater = inputs.Repeaters["Sample"];

            for (var i = 0; i < repeater.Count; i++)
            {
                var res = repeater.GetAttribute(i, "Result").FinalValue;
                if (string.IsNullOrEmpty(res) || res.ToLower() != "no asbestos detected")
                {
                    return(string.Empty);
                }
            }

            return("No asbestos was detected within any of the samples collected");
        }
예제 #6
0
파일: Template1.cs 프로젝트: ej-z/DMS
        public string SampleResults1(DocInputs inputs)
        {
            var repeater = inputs.Repeaters["Sample"];
            var c        = repeater.Count > 1 ? "were" : "was";
            var d        = new Dictionary <string, int>();
            int x        = 0;

            for (var i = 0; i < repeater.Count; i++)
            {
                var desc = repeater.GetAttribute(i, "SampleDescription").FinalValue;
                if (desc != null)
                {
                    if (d.ContainsKey(desc))
                    {
                        d[desc]++;
                    }
                    else
                    {
                        d.Add(desc, 1);
                        x++;
                    }
                }
            }

            StringBuilder sb = new StringBuilder();

            bool first = true;

            foreach (var v in d)
            {
                sb.Append(NumberToWords(v.Value, first) + " (" + v.Value + ") " + v.Key);
                if (x == 2)
                {
                    sb.Append(" and ");
                }
                if (x > 2)
                {
                    sb.Append(", ");
                }

                first = false;
            }
            sb.Append(" " + c);

            return(sb.ToString());
        }
예제 #7
0
파일: DocManp.cs 프로젝트: ej-z/DMS
        public DocInputs ReadDoc(string srcfilename)
        {
            DocInputs inputs = new DocInputs();

            using (var document = WordprocessingDocument.Open(srcfilename, false))
            {
                var main = document.MainDocumentPart;
                var doc  = main.Document;
                var body = doc.Body;

                foreach (TableRow row in body.Descendants <Table>().Last().Descendants <TableRow>())
                {
                    var cells = row.Descendants <TableCell>().ToArray();
                    inputs.AddInput(cells[0].InnerText, cells[1].InnerText, cells[2].InnerText);
                }
            }
            return(inputs);
        }
예제 #8
0
        public static Attribute Create(string type, string properties, Dictionary <string, Attribute> attributes = null, DocInputs inputs = null)
        {
            var propertiesMap = properties.Split('|')
                                .ToDictionary(x => x.Split(':')[0], x => x.Split(':').Length > 1 ? x.Split(':')[1] : string.Empty);
            Attribute attribute;

            switch (type)
            {
            case "Text":
            case "TextArea":
                attribute = new TextAttribute(type);
                break;

            case "Enum":
                attribute = new EnumAttribute(type);
                break;

            case "Bit":
                attribute = new BitAttribute(type);
                break;

            case "Label":
                attribute = new LabelAttribute(type);
                break;

            case "Image":
                attribute = new ImageAttribute(type);
                break;

            case "File":
                attribute = new FileAttribute(type);
                break;

            case "Complex":
                var attr = new ComplexAttribute(type);
                attr.SetProperties(propertiesMap, attributes);
                attribute = attr;
                break;

            case "Unique":
                attribute = new UniqueAttribute(type, inputs);
                break;

            default:
                attribute = new Attribute("");
                break;
            }
            attribute.SetProperties(propertiesMap);
            return(attribute);
        }
예제 #9
0
파일: DocInputs.cs 프로젝트: ej-z/DMS
 public UniqueAttribute(string type, DocInputs inputs) : base(type)
 {
     this.inputs = inputs;
 }
예제 #10
0
파일: DocManp.cs 프로젝트: ej-z/DMS
        public void CreateDoc(DocInputs inputs, string srcfilename, string tarfilename)
        {
            using (var mainDoc = WordprocessingDocument.Open(srcfilename, false))
                using (var resultDoc = WordprocessingDocument.Create(tarfilename, DocumentFormat.OpenXml.WordprocessingDocumentType.Document))
                {
                    foreach (var part in mainDoc.Parts)
                    {
                        resultDoc.AddPart(part.OpenXmlPart, part.RelationshipId);
                    }

                    var   main           = resultDoc.MainDocumentPart;
                    var   doc            = main.Document;
                    var   body           = doc.Body;
                    Regex attributeRegex = new Regex(attributeRegexExpr);
                    Regex bitRegex       = new Regex(bitRegexExpr);
                    Regex repeaterRegex  = new Regex(repeaterRegexExpr);
                    Regex photoRegex     = new Regex(photoExpr);
                    foreach (Text text in body.Descendants <Text>())
                    {
                        MatchCollection mc1 = attributeRegex.Matches(text.Text);
                        foreach (Match m in mc1)
                        {
                            var name = m.Groups[1].Value;
                            text.Text = text.Text.Replace(name.ToAttributeString(), inputs.Attributes[name].FinalValue);
                        }
                    }

                    foreach (Table t in body.Descendants <Table>().Where(tbl => bitRegex.IsMatch(tbl.InnerText)))
                    {
                        MatchCollection mc1    = bitRegex.Matches(t.InnerText);
                        List <string>   Groups = (from Match m in mc1 select m.Groups[1].Value).ToList();

                        var availableBitAttributes =
                            inputs.Attributes.Values.Where(x => x.Type == "Bit" && x.FinalValue == "True")
                            .Select(x => (BitAttribute)x)
                            .Where(x => Groups.Contains(x.Group))
                            .GroupBy(x => x.Group)
                            .ToDictionary(x => x.Key, x => x.ToList());

                        var maxGroupCount = availableBitAttributes.Values.OrderByDescending(x => x.Count).First().Count;
                        var row           = t.Descendants <TableRow>().First(tbl => bitRegex.IsMatch(tbl.InnerText));
                        for (int i = 0; i < maxGroupCount - 1; i++)
                        {
                            var newRow = new TableRow();
                            foreach (TableCell c in row.Descendants <TableCell>())
                            {
                                newRow.Append(c.CloneNode(true));
                            }
                            t.Append(newRow.CloneNode(true));
                        }

                        for (int i = 0; i < maxGroupCount; i++)
                        {
                            var r = t.Descendants <TableRow>().Skip(i).First(tbl => bitRegex.IsMatch(tbl.InnerText));
                            foreach (Text text in r.Descendants <Text>())
                            {
                                MatchCollection mc2 = bitRegex.Matches(text.Text);
                                foreach (Match m in mc2)
                                {
                                    var group = m.Groups[1].Value;
                                    if (availableBitAttributes.ContainsKey(group) && i < availableBitAttributes[group].Count)
                                    {
                                        text.Text = text.Text.Replace(group.ToGroupString(), availableBitAttributes[group][i].Label);
                                    }
                                    else
                                    {
                                        text.Text = string.Empty;
                                    }
                                }
                            }
                        }
                    }


                    foreach (Table t in body.Descendants <Table>().Where(tbl => repeaterRegex.IsMatch(tbl.InnerText)))
                    {
                        var repeaterName = repeaterRegex.Match(t.InnerText).Groups[1].Value;
                        var repeater     = inputs.Repeaters[repeaterName];
                        var row          = t.Descendants <TableRow>().First(tbl => repeaterRegex.IsMatch(tbl.InnerText));
                        for (int i = 0; i < repeater.Count - 1; i++)
                        {
                            var newRow = new TableRow();
                            foreach (TableCell c in row.Descendants <TableCell>())
                            {
                                newRow.Append(c.CloneNode(true));
                            }
                            t.Append(newRow.CloneNode(true));
                        }

                        var ph = 1;
                        for (int i = 0; i < repeater.Count; i++)
                        {
                            var r = t.Descendants <TableRow>().Skip(i).First(tbl => repeaterRegex.IsMatch(tbl.InnerText));
                            foreach (Text text in r.Descendants <Text>())
                            {
                                MatchCollection mc1 = repeaterRegex.Matches(text.Text);
                                foreach (Match m in mc1)
                                {
                                    var name  = m.Groups[2].Value;
                                    var value = string.Empty;
                                    if (name == "Photono" && !string.IsNullOrEmpty(repeater.GetAttribute(i, "Photo").FinalValue))
                                    {
                                        value = (ph++).ToString();
                                    }
                                    else if (name != "Photono")
                                    {
                                        value = repeater.GetAttribute(i, name).FinalValue;
                                    }
                                    text.Text = text.Text.Replace(name.ToRepeaterString(m.Groups[1].Value), value);
                                }
                            }
                        }
                    }

                    foreach (Text text in body.Descendants <Text>())
                    {
                        MatchCollection mc1 = photoRegex.Matches(text.Text);
                        foreach (Match m in mc1)
                        {
                            text.Text = string.Empty;
                            {
                                var       repeater = inputs.Repeaters["Sample"];
                                Paragraph para     = text.Ancestors <Paragraph>().FirstOrDefault();
                                if (para == null)
                                {
                                    break;
                                }
                                var ph = 1;
                                for (int i = 0; i < repeater.Count; i++)
                                {
                                    ImagePart imagePart = main.AddImagePart(ImagePartType.Jpeg);
                                    var       location  = repeater.GetAttribute(i, "Photo").FinalValue;
                                    if (!string.IsNullOrEmpty(location))
                                    {
                                        using (FileStream stream = new FileStream(location, FileMode.Open))
                                        {
                                            imagePart.FeedData(stream);
                                        }
                                        AddImageToBody(para, main.GetIdOfPart(imagePart), location);
                                        Run run = para.AppendChild(new Run());
                                        run.AppendChild(new Text("\r\nPhotograph " + (ph++) + ". " + repeater.GetAttribute(i, "PhotoDescription").FinalValue + "\r\n\r\n"));
                                    }
                                }
                            }
                        }
                    }

                    var configTable = body.Descendants <Table>().Last();
                    configTable.Remove();
                    var lastBreak = doc.Descendants <Break>().Last();
                    lastBreak.Remove();
                }
        }