/// <summary>uu /// Vorbereiten der Daten zum Druck /// </summary> /// <param name="_devSerial"></param> private bool prepareData(string _devSerial, string _devFileName) { varDevSerial = _devSerial; varDevFilename = _devFileName; string prefixKrRico = ""; if (isKrRico) { prefixKrRico = "kric."; } SqlConnection dbconn = new SqlConnection(db.ConnectionString); dbconn.Open(); string sql = "SELECT id," + db.TAB_DEVICE_USERID + " FROM " + db.TAB_DEVICE + " " + "WHERE " + db.TAB_DEVICE_SERIAL + "='" + varDevSerial + "'" + "AND " + db.TAB_DEVICE_FILENAME + "='" + varDevFilename + "'"; DbDataReader dr = db.QueryDataReader(new SqlCommand(sql, dbconn)); if (dr == null) { return(false); } if (!dr.Read()) { dr.Close(); dbconn.Close(); return(false); } devID = (int)dr["id"]; int uid = (int)dr[db.TAB_DEVICE_USERID]; dr.Close(); sql = "select " + db.TAB_USER_NACHNAME + "," + db.TAB_USER_VORNAME + " from " + db.TAB_USER + " " + "where id=" + uid; dr = db.QueryDataReader(new SqlCommand(sql, dbconn)); if (dr == null) { dbconn.Close(); return(false); } if (!dr.Read()) { dr.Close(); dbconn.Close(); return(false); } varUser = (string)dr[db.TAB_USER_NACHNAME] + ", " + (string)dr[db.TAB_USER_VORNAME]; dr.Close(); sql = "select * from " + db.TAB_PARAMS + " " + "where id=" + devID; dr = db.QueryDataReader(new SqlCommand(sql, dbconn)); if (dr == null) { dbconn.Close(); return(false); } if (!dr.Read()) { dr.Close(); dbconn.Close(); return(false); } devBits = (int)dr[db.TAB_PARAMS_TYP]; devType = (devBits & 0x7F000000) >> 24; deviceType = DeviceBits.Type(devBits); dr.Close(); if (deviceType == CustomDeviceType.DR6000) { QueryLibraryRefracto queryLibRefracto = new QueryLibraryRefracto(devID); queryLibRefracto = new QueryLibraryRefracto(devID); TargetTable type; refractoAdjustment = queryLibRefracto .SelectLatestMeasAdjustment(out refractoAdjustmentDate, out type); } varDevType = DeviceBits.DeviceName(devBits); if (varDevType.Length == 0) { varDevType = DeviceBits.GroupNameShort(devBits); } varDate = DateTime.Now.ToShortDateString(); //---Gruppe "1" Checklistedatenliste vorbereiten--- int groupIdGeneral = Array.FindIndex(groupName, item => item.EndsWith("general")); addCheckListData(groupIdGeneral, devID, dbconn, prefixKrRico + "general.ipa", db.TAB_PARAMS, db.TAB_PARAMS_IPA, typeof(string)); //addCheckListData(1, devID, dbconn, prefixKrRico + "general.serial", db.TAB_DEVICE, db.TAB_DEVICE_SERIAL, typeof(string)); //addCheckListData(1, devID, dbconn, prefixKrRico + "general.typ", varDevType); addCheckListData(groupIdGeneral, devID, dbconn, prefixKrRico + "general.version", db.TAB_PARAMS, db.TAB_PARAMS_VERSION_AUCKLAND, typeof(string), ".auckland", "Firmware Version Auckland", db.TAB_PARAMS, db.TAB_PARAMS_VERSION_ECO, typeof(string), ".eco", "Firmware Version Eco"); addCheckListData(groupIdGeneral, devID, dbconn, prefixKrRico + "general.date", db.TAB_PARAMS, db.TAB_PARAMS_TIMESYNC, typeof(DateTime)); if (devType == 2) { addCheckListData(groupIdGeneral, devID, dbconn, prefixKrRico + "general.measurement.range", db.TAB_PARAMS, db.TAB_PARAMS_MEAS_RANGE_MIN, db.TAB_PARAMS_MEAS_RANGE_MAX, typeof(double)); } //---für alle anderen Gruppen außer "1" Checklistedatenliste vorbereiten--- foreach (KeyValuePair <string, string> pair in contextDescription) { if (contextGroup.ContainsKey(pair.Key)) { if (contextGroup[pair.Key] != 1) { //if (pair.Key != prefixKrRico + "general.typ" && pair.Key != prefixKrRico + "general.serial") //{ // ==> mit Ulf nach Vereinfachung suchen checklistdata cld = new checklistdata(pair.Key, contextGroup[pair.Key], pair.Value, false, ""); varCheckList.Add(pair.Key, cld); //} } } } //---Checklistedaten aus DB lesen--- sql = "select * from " + db.TAB_TREE + " where id=" + devID; dr = db.QueryDataReader(new SqlCommand(sql, dbconn)); if (dr == null) { dbconn.Close(); return(false); } while (dr.Read()) { string ctx = (string)dr[db.TAB_TREE_CONTEXT]; if (isKrRico && !ctx.StartsWith(prefixKrRico)) { ctx = prefixKrRico + ctx; } string person; int sta = db.GetTreeStatus(devID, ctx, dbconn, out person); if (!varCheckList.ContainsKey(ctx)) { string txt = ""; int grp = -1; if (contextDescription.ContainsKey(ctx)) { txt = contextDescription[ctx]; } if (contextGroup.ContainsKey(ctx)) { grp = contextGroup[ctx]; } varCheckList.Add(ctx, new checklistdata(ctx, grp, txt, sta == 2, person)); } else { varCheckList[ctx].ok = (sta == 2); varCheckList[ctx].person = person; } } dr.Close(); //---weitere parameter aus DB auslesen--- if (varCheckList.ContainsKey("finalize.params")) { checklistdata d = varCheckList["finalize.params"]; if (d.ok) { sql = "select " + db.TAB_CONFIG_TIMESTAMP + " from " + db.TAB_CONFIG + " " + "where (id=" + devID + ")and(" + db.TAB_CONFIG_TYP + "=" + (int)db.ConfigType.DeviceParametersBinary + ")"; dr = db.QueryDataReader(new SqlCommand(sql, dbconn)); if (dr != null) { if (dr.Read()) { d.value = ((DateTime)dr[db.TAB_CONFIG_TIMESTAMP]).ToString(); } dr.Close(); } } } if (varCheckList.ContainsKey(prefixKrRico + "finalize.db")) { checklistdata d = varCheckList[prefixKrRico + "finalize.db"]; if (d.ok) { sql = "select " + db.TAB_CONFIG_TIMESTAMP + " from " + db.TAB_CONFIG + " " + "where (id=" + devID + ")and(" + db.TAB_CONFIG_TYP + "=" + (int)db.ConfigType.DeviceDatabaseBinary + ")"; dr = db.QueryDataReader(new SqlCommand(sql, dbconn)); if (dr != null) { if (dr.Read()) { d.value = ((DateTime)dr[db.TAB_CONFIG_TIMESTAMP]).ToString(); } dr.Close(); } } } //---prepare group 0 data--- foreach (KeyValuePair <string, checklistdata> pair in varCheckList) { if (pair.Value.group == 0) { varCheckList0.Add(new checklistdata(pair.Value)); } } //---prepare group 1 data--- foreach (KeyValuePair <string, checklistdata> pair in varCheckList) { if (pair.Value.group == 1) { if (pair.Key != "general.version") { varCheckList1.Add(new checklistdata(pair.Value)); } } } //---prepare group 2 data--- foreach (KeyValuePair <string, checklistdata> pair in varCheckList) { if (pair.Value.group == 2) { varCheckList2.Add(new checklistdata(pair.Value)); } } //---prepare group 3 data--- foreach (KeyValuePair <string, checklistdata> pair in varCheckList) { if (pair.Value.group == 3) { varCheckList3.Add(new checklistdata(pair.Value)); } } //---prepare group 4 data--- foreach (KeyValuePair <string, checklistdata> pair in varCheckList) { if (pair.Value.group == 4) { varCheckList4.Add(new checklistdata(pair.Value)); } } //---prepare group 5 data--- foreach (KeyValuePair <string, checklistdata> pair in varCheckList) { if (pair.Value.group == 5) { varCheckList5.Add(new checklistdata(pair.Value)); } } //---prepare group 6 data--- foreach (KeyValuePair <string, checklistdata> pair in varCheckList) { if (pair.Value.group == 6) { varCheckList6.Add(new checklistdata(pair.Value)); } } dbconn.Close(); return(true); }
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); }