Exemplo n.º 1
0
        private Protocol prepareProtocol()
        {
            if (contextGroup.Count != contextDescription.Count)
            {
                // Both must be equally sized as they will be acessed by index
                return(null);
            }

            ProtocolHeaderData headerData = new ProtocolHeaderData();

            headerData.Title      = "Inbetriebnahme-Protokoll (intern)";
            headerData.Serial     = varDevSerial;
            headerData.Filename   = varDevFilename;
            headerData.DeviceType = varDevType;
            headerData.User       = varUser;
            headerData.Date       = varDate;

            // Creating a default (A4, portrait) page setup
            ProtocolPageSetup pageSetup = new ProtocolPageSetup();

            pageSetup.RightMargin_cm = 2.5;

            Protocol protocol = new Protocol(headerData, pageSetup);

            //
            // Add the group 'Montage'
            //
            bool headingPrinted = false;

            foreach (checklistdata item in varCheckList0)
            {
                if (headingPrinted == false)
                {
                    protocol.AddHeading1("Montage");
                    headingPrinted = true;
                }

                string context = item.context;

                string description = contextDescription[context];
                string user        = item.person;
                bool   ok          = item.ok;

                if (context.EndsWith("montage.vde"))
                {
                    protocol.AddHeading1("VDE-Prüfung");

                    var queryLib = new QueryLibraryCommon(devID);
                    protocol.AddCheckedParagraph(description, user, ok);
                    protocol.AddTable(queryLib.SelectVDETable(),
                                      TableDrawMode.Default);
                }
                else
                {
                    protocol.AddCheckedParagraph(description, user, ok);
                }
            }

            //
            // Add the group 'Grundeinstellungen'
            //
            var translations = new Dictionary <string, string>()
            {
                { "general.ipa", "IP-Adresse eingestellt" },
                { "kric.general.ipa", "IP-Adresse eingestellt" },
                { "kric.general.version", "Firmware Version" },
                { "general.params", "Geräteparameter konfiguriert" },
                { "kric.general.params", "Geräteparameter konfiguriert" },
                { "general.hellfeld", "Hellfeldmessung durchgeführt" },
                { "kric.general.hellfeld", "Hellfeldmessung durchgeführt" },
            };

            headingPrinted = false;
            foreach (checklistdata item in varCheckList1)
            {
                if (headingPrinted == false)
                {
                    protocol.AddHeading1("Grundeinstellungen");
                    headingPrinted = true;
                }

                string context = item.context;
                string value   = item.value;
                string description;

                if (!contextDescription.TryGetValue(context, out description))
                {
                    description = item.text;
                    if (description.Contains("Auckland"))
                    {
                        // This can only be the auckland / cupid version item
                        double version = double.TryParse(
                            value,
                            NumberStyles.Any,
                            CultureInfo.InvariantCulture,
                            out version) ? version : double.NaN;

                        if (!double.IsNaN(version) && version >= 6.00)
                        {
                            // This is a CUPID board
                            description = description.Replace("Auckland", "Cupid");
                        }
                    }

                    if (isKrRico && description.Contains("Eco"))
                    {
                        // KrRico board s have no ECO, taher it's called KMU
                        description = description.Replace("Eco", "KMU");
                    }
                }

                string user = item.person;
                bool   ok   = item.ok;

                // Some descriptions should be translated to be shorter.
                // .See dictionary 'translations' above.
                if (translations.ContainsKey(context))
                {
                    description = translations[context];
                }

                protocol.AddCheckedParagraph(description, value, user, ok);
                if (context == "kric.general.hellfeld")
                {
                    var    queryLib  = new QueryLibraryRefracto(devID);
                    string curveData = queryLib.SelectBrightField(false);
                    if (curveData.Length > 0)
                    {
                        protocol.AddTextParagraph("");

                        var curve = new DataPointsXYList(curveData, 1000);
                        protocol.AddChart(curve,
                                          0, 2050, 200,
                                          0, 3000, 0, "0",
                                          "10² Pixel", "");
                    }
                }
                else if (context == "general.hellfeld")
                {
                    var    queryLib  = new QueryLibraryRefracto(devID);
                    string curveData = queryLib.SelectBrightField(true);
                    if (curveData.Length > 0)
                    {
                        protocol.AddTextParagraph("");

                        var curve = new DataPointsXYList(curveData);
                        protocol.AddChart(curve,
                                          0, 2050, 200,
                                          0, 5000, 0, "0",
                                          "10² Pixel", "");
                    }
                }
            }

            //
            // Add the group 'Funktion'
            //
            headingPrinted = false;
            foreach (checklistdata item in varCheckList2)
            {
                if (headingPrinted == false)
                {
                    protocol.AddHeading1("Funktion");
                    headingPrinted = true;
                }

                string context = item.context;

                string description = contextDescription[context];
                string user        = item.person;
                bool   ok          = item.ok;

                protocol.AddCheckedParagraph(description, user, ok);
            }

            //
            // Add the group 'Justierung'
            //
            headingPrinted = false;
            foreach (checklistdata item in varCheckList3)
            {
                if (headingPrinted == false)
                {
                    protocol.AddHeading1("Justierung");
                    headingPrinted = true;
                }

                string context     = item.context;
                string description = contextDescription[context];
                string user        = item.person;
                bool   ok          = item.ok;


                if (context.EndsWith("calib.dr6000.temp"))
                {
                    if ((deviceType == CustomDeviceType.DS7500) ||
                        (deviceType == CustomDeviceType.DS7900))
                    {
                        user = "******";
                        protocol.AddCheckedParagraph(description, user, ok);
                    }
                    else
                    {
                        protocol.AddHeading2("Temperatur");
                        protocol.AddCheckedParagraph(description, user, ok);

                        var queryLib = new QueryLibraryCommon(devID);
                        protocol.AddTable(queryLib.SelectTempAdjustment(),
                                          TableDrawMode.Default);

                        var adjDate = queryLib.SelectTempAdjustDate();
                        if (adjDate == DateTime.MinValue)
                        {
                            protocol.AddTextParagraph(
                                "Datum der Justierung: nicht vorhanden");
                        }
                        else
                        {
                            protocol.AddTextParagraph(
                                $"Datum der Justierung: {adjDate}");
                        }

                        if (!isKrRico)
                        {
                            // For ECO devices also add the temp adjustment coeffs
                            protocol.AddTable(queryLib.SelectTempMeasCoeffs(),
                                              TableDrawMode.Default);
                        }
                    }
                }
                else if (context.EndsWith("calib.dr6000.meas"))
                {
                    protocol.AddHeading2("Messwert");
                    protocol.AddCheckedParagraph(description, user, ok);

                    var queryLib = new QueryLibraryRefracto(devID);
                    protocol.AddTable(queryLib.SelectMeasAdjustment(),
                                      TableDrawMode.SideBySideAuto);

                    var adjDate = queryLib.SelectMeasAdjustDate();
                    if (adjDate == DateTime.MinValue)
                    {
                        protocol.AddTextParagraph(
                            "Datum der Justierung: nicht vorhanden");
                    }
                    else
                    {
                        protocol.AddTextParagraph(
                            $"Datum der Justierung: {adjDate}");
                    }


                    if (!isKrRico)
                    {
                        // For ECO devices also add the meas adjustment coeffs
                        protocol.AddTable(queryLib.SelectMeasCoeffs(),
                                          TableDrawMode.Default);
                    }
                }
                else if (context.EndsWith("calib.dr6000.caldata"))
                {
                    protocol.AddHeading2("Justierdaten");
                    description = "Kurve geprüft";
                    protocol.AddCheckedParagraph(description, user, ok);

                    // Get the meas curve with its max. 50 values
                    var queryLib = new QueryLibraryRefracto(devID);
                    var curve    = queryLib.SelectMeasAdjustCurve();

                    // Taking this curve and creating an interpolated version
                    // of it using the known points and interpolate the missing
                    // ones in-between. This one will have 200 values.
                    var curveInterPolated = new DataPointsXYList(2000);
                    for (int i = 0; i < curve.Count; i++)
                    {
                        curveInterPolated.AppendInterpolated((int)curve.PointsX[i] / 100,
                                                             curve.PointsY[i]);
                    }

                    // TODO
                    //curveInterPolated.Extrapolate();

                    protocol.AddChart(curveInterPolated,
                                      0, 2050, 200,
                                      1.0, 1.7, 0, "0.0",
                                      "10² Pixel", "nD");
                }
                else if (context.EndsWith("calib.ds7000.pressure"))
                {
                    protocol.AddHeading2("Drucksensor");
                    protocol.AddCheckedParagraph(description, user, ok);

                    var queryLib = new QueryLibraryDensity(devID);
                    protocol.AddTable(queryLib.SelectPressureAdjustment(),
                                      TableDrawMode.Default);

                    var calDate = queryLib.SelectPressureAdjustDate();
                    if (calDate.Year > 1970)
                    {
                        protocol.AddTextParagraph(
                            $"Datum der Justierung: {calDate}");
                    }
                }
                else if (context.EndsWith("calib.p8000.meas"))
                {
                    protocol.AddHeading2("Messwert");
                    protocol.AddCheckedParagraph(description, user, ok);

                    var queryLib = new QueryLibraryPolari(devID);
                    protocol.AddTable(queryLib.SelectMeasAdjustment(),
                                      TableDrawMode.Default);

                    var calDate = queryLib.SelectMeasAdjustDate();
                    if (calDate.Year > 1970)
                    {
                        protocol.AddTextParagraph(
                            $"Datum der Justierung: {calDate}");
                    }
                }
                else
                {
                    protocol.AddCheckedParagraph(description, user, ok);
                }
            }

            //
            // Add the group 'Endtest'
            //
            headingPrinted = false;
            foreach (checklistdata item in varCheckList4)
            {
                if (headingPrinted == false)
                {
                    protocol.AddHeading1("Endtest");
                    headingPrinted = true;
                }

                string context     = item.context;
                string description = contextDescription[context];
                string user        = item.person;
                bool   ok          = item.ok;

                protocol.AddCheckedParagraph(description, user, ok);

                if (context.EndsWith("final.meas")) // TODO or only ".temp" ??
                {
                    var queryLib = new QueryLibraryCommon(devID);
                    protocol.AddTable(queryLib.SelectFinalMeas(),
                                      TableDrawMode.Default);
                }
            }

            //
            // Add the group 'Abschluss Software'
            //
            headingPrinted = false;
            foreach (checklistdata item in varCheckList5)
            {
                if (headingPrinted == false)
                {
                    protocol.AddHeading1("Abschluss Software");
                    headingPrinted = true;
                }

                string context     = item.context;
                string description = contextDescription[context];
                string user        = item.person;
                bool   ok          = item.ok;

                protocol.AddCheckedParagraph(description, user, ok);
            }

            //
            // Add the group 'Gehäuse'
            //
            headingPrinted = false;
            foreach (checklistdata item in varCheckList6)
            {
                if (headingPrinted == false)
                {
                    protocol.AddHeading1("Gehäuse");
                    headingPrinted = true;
                }

                string context     = item.context;
                string description = contextDescription[context];
                string user        = item.person;
                bool   ok          = item.ok;

                protocol.AddCheckedParagraph(description, user, ok);
            }

            //
            // Add the final area with date and space for user sign
            //
            string date = DateTime.Now.ToString("dd.MM.yyyy");

            string signText = Environment.NewLine;

            signText += Environment.NewLine;
            signText += Environment.NewLine;
            signText += Environment.NewLine;
            signText += Environment.NewLine;
            signText += Environment.NewLine;
            signText += new string('_', 60);
            signText += Environment.NewLine;
            signText += $"Hamburg, den {date}, Unterschrift {varUser}";

            protocol.AddTextParagraph(signText);

            return(protocol);
        }