using Accord.Statistics.Models.Regression.Linear; using Google.Protobuf.WellKnownTypes; using MySql.Data.MySqlClient; using MySqlX.XDevAPI.Relational; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Printing; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; namespace StacjaProb { public partial class fullTestReportForm : Form { private System.Windows.Forms.DataVisualization.Charting.Chart chartH; private System.Windows.Forms.DataVisualization.Charting.Chart chartP; private System.Windows.Forms.DataVisualization.Charting.Chart chartETA; private string typ_popmy_value = ""; private string sn_popmy_value = ""; private string typ_silnika_value = ""; private string sn_silnika_value = ""; private string uwagi_value = ""; private string klient_value = ""; private string zlecenie_value = ""; private string prowadzacy_value = ""; private string tst_date = ""; private int pupm_id_value = 0; private int currentPrintPage = 1; // numer aktualnie drukowanej strony private double qn_value = 0; private double qmin_value = 0; private double qmax_value = 0; private double hn_value = 0; private double hmin_value = 0; private double hmax_value = 0; private double eta_value = 0; private double moc_value = 0; private double nap_value = 0; private double prad_value = 0; private double obrot_value = 0; private double spraw_sil_value = 0; private double wsp_mocy = 0; private double czest_value = 0; private double stan_izol_zimny = 0; private double stan_izol_cieply = 0; private int xLeft; private int yTop; private int xRight; private int yButtom; private int printWidth; private int printHeight; public static int spm_test_id; private System.Drawing.Printing.PrintDocument printDocumentKartaEksploatacji = new System.Drawing.Printing.PrintDocument(); public fullTestReportForm() { InitializeComponent(); printDocumentKartaEksploatacji.PrintPage += printDocumentKartaEksploatacji_PrintPage; } // Obsługa kliknięcia przycisku Karta Eksploatacji private void buttonKartaEksploatacji_Click(object sender, EventArgs e) { using (PrintDialog dlg = new PrintDialog()) { dlg.Document = printDocumentKartaEksploatacji; if (dlg.ShowDialog() == DialogResult.OK) { using (PrintPreviewDialog preview = new PrintPreviewDialog()) { preview.Document = printDocumentKartaEksploatacji; // Ustawienie okna podglądu na zmaksymalizowane preview.WindowState = System.Windows.Forms.FormWindowState.Maximized; if (preview.ShowDialog() == DialogResult.OK) { printDocumentKartaEksploatacji.PrinterSettings = dlg.PrinterSettings; printDocumentKartaEksploatacji.Print(); } } } } } //funcja na index górny, dolny public static void DrawRichText(Graphics g, string text, Font baseFont, float x, float y) { // Kolor tekstu – domyślnie czarny Brush brush = Brushes.Black; // Czcionki: główna i mniejsze dla sub/sup float baseSize = baseFont.Size; Font subFont = new Font(baseFont.FontFamily, baseSize * 0.7f, baseFont.Style); Font supFont = new Font(baseFont.FontFamily, baseSize * 0.7f, baseFont.Style); float cursorX = x; float cursorY = y; // Podziel tekst na fragmenty z , i resztę string pattern = @"(.*?|.*?|[^<]+)"; var matches = Regex.Matches(text, pattern, RegexOptions.IgnoreCase); foreach (Match m in matches) { string part = m.Value; if (part.StartsWith("", StringComparison.OrdinalIgnoreCase)) { // Dolny indeks string inner = part.Substring(5, part.Length - 11); g.DrawString(inner, subFont, brush, cursorX, cursorY + baseSize * 0.3f); SizeF size = g.MeasureString(inner, subFont); cursorX += size.Width; } else if (part.StartsWith("", StringComparison.OrdinalIgnoreCase)) { // Górny indeks string inner = part.Substring(5, part.Length - 11); g.DrawString(inner, supFont, brush, cursorX, cursorY - baseSize * 0.4f); SizeF size = g.MeasureString(inner, supFont); cursorX += size.Width; } else { // Zwykły tekst g.DrawString(part, baseFont, brush, cursorX, cursorY); SizeF size = g.MeasureString(part, baseFont); cursorX += size.Width; } } } // Rysowanie wydruku Karty Eksploatacji private void printDocumentKartaEksploatacji_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Font myFont = new System.Drawing.Font("tahoma", 9, FontStyle.Regular); Font myFont8 = new System.Drawing.Font("tahoma", 8, FontStyle.Regular); Font myFont12 = new System.Drawing.Font("tahoma", 11, FontStyle.Regular); Font myFontBold = new System.Drawing.Font("tahoma", 9, FontStyle.Bold); Font myFontBold8 = new System.Drawing.Font("tahoma", 8, FontStyle.Bold); Font myFontBold12 = new System.Drawing.Font("tahoma", 11, FontStyle.Bold); Font myFontBoldMid = new System.Drawing.Font("tahoma", 13, FontStyle.Bold); Font myFontMala = new System.Drawing.Font("tahoma", 7, FontStyle.Regular); Font myFontMalaBold = new System.Drawing.Font("tahoma", 7, FontStyle.Bold); Font myFontMalenka = new System.Drawing.Font("tahoma", 6, FontStyle.Regular); Font myFontMalenkaBold = new System.Drawing.Font("tahoma", 6, FontStyle.Bold); Font myFontTytul = new System.Drawing.Font("arial", 16, FontStyle.Bold); Font myFontLic = new System.Drawing.Font("tahoma", 7, FontStyle.Regular); Pen myPenCzarny = new Pen(System.Drawing.Color.Black, 1); Pen myPenSzary = new Pen(System.Drawing.Color.Gray, 1); Brush czarny = new SolidBrush(System.Drawing.Color.Black); Brush szary = new SolidBrush(System.Drawing.Color.Gray); Rectangle marginBounds = e.MarginBounds; xLeft = marginBounds.Left - 50; yTop = marginBounds.Top - 50; xRight = marginBounds.Right + 50; yButtom = marginBounds.Bottom + 50; printWidth = xRight - xLeft; printHeight = yButtom - yTop; var g = e.Graphics; var pageBounds = e.MarginBounds; string cableType = ""; string cableLength = ""; string cableOznak_01 = ""; string cableOznak_02 = ""; mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { //MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM tst_aggregate_export_spm WHERE TAR_ID=(SELECT MAX(TAR_ID) FROM tst_aggregate_export_spm WHERE TAR_PUP_NAME='" + typ_popmy_value + "' and TAR_PUP_SN_NO='"+ sn_popmy_value + "' and TAR_ENG_NAME='"+ typ_silnika_value + "' and TAR_ENG_SN_NO='"+ sn_silnika_value + "' AND DATE(TAR_AUDIT_CD) = '"+ tst_date + "')", mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM tst_aggregate_export_spm WHERE TAR_TST_ID=" + spm_test_id.ToString(), mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { cableType = dataReader["TAR_CABLE_TYP"].ToString(); cableLength = dataReader["TAR_CABLE_DLUGOSC"].ToString(); cableOznak_01 = dataReader["TAR_CABLE_OZNAK_01"].ToString(); cableOznak_02 = dataReader["TAR_CABLE_OZNAK_02"].ToString(); if (!string.IsNullOrEmpty(klient_value)) klient_value = dataReader["TAR_DEPARTMENT"].ToString(); // Nowy warunek — jeśli jest wypełnione pole TAR_CABLE_MEMO, rozbij je na pola string memo = dataReader["TAR_CABLE_MEMO"]?.ToString(); if (!string.IsNullOrEmpty(memo)) { // Zamiana symbolu ^ na nową linię (jeśli w bazie zapisano w ten sposób) memo = memo.Replace('^', '\n'); // Dzielimy po nowych liniach string[] lines = memo.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'); int x = 1; foreach (string line in lines) { if (string.IsNullOrWhiteSpace(line)) continue; // Każdy wiersz: długość;oznak01;oznak02 string[] parts = line.Split(';'); //if (parts.Length > 0) MessageBox.Show(parts[0].Trim()); //cableLength = parts[0].Trim(); //if (parts.Length > 1) MessageBox.Show(parts[1].Trim());//cableOznak_01 = parts[1].Trim(); //if (parts.Length > 2) MessageBox.Show(parts[2].Trim());//cableOznak_02 = parts[2].Trim(); if (x == 1) e.Graphics.DrawString(x.ToString() + ". Lk=" + parts[0].Trim() + "m ["+ parts[1].Trim() + "] ["+ parts[2].Trim() + "]", myFontMala, czarny, xLeft + 10, (yTop + 120 + 268)); if (x == 2) e.Graphics.DrawString(x.ToString() + ". Lk=" + parts[0].Trim() + "m ["+ parts[1].Trim() + "] ["+ parts[2].Trim() + "]", myFontMala, czarny, xLeft + 10, (yTop + 120 + 280)); x++; } } } //if (!string.IsNullOrEmpty(cableLength)) cableLength = " "; //if (!string.IsNullOrEmpty(cableOznak_01)) cableOznak_01 = " "; //if (!string.IsNullOrEmpty(cableOznak_02)) cableOznak_02 = " "; dataReader.Close(); mySqlFunctions.CloseConnection(); } int px_boki = 159; int px_srodek = 568; int xLeft_L = xLeft + px_boki; int xLeft_P = xLeft + px_srodek; e.Graphics.DrawString("Data druku: " + DateTime.Now.ToString("yyyy-MM-dd"), myFontLic, szary, xRight - 120, yTop - 15); // rysuje ramkę raportu //pierwszy poziom // ================================================================================================================================== e.Graphics.DrawRectangle(myPenCzarny, xLeft, yTop, px_srodek, 40); e.Graphics.DrawRectangle(myPenCzarny, xLeft + px_srodek, yTop, px_boki, 40); //Wpisy e.Graphics.DrawString("RAMB Sp. z o.o. Dział TO", myFontTytul, szary, xLeft_L, yTop + 10); //próba e.Graphics.DrawString("Nr karty próby:", myFont, czarny, xLeft_P + 25, yTop + 7); e.Graphics.DrawString(spm_test_id.ToString(), myFontBold, czarny, xLeft_P + 45, yTop + 22); int yPos = yTop + 40; // ================================================================================================================================== //drugi poziom // ================================================================================================================================== e.Graphics.DrawRectangle(myPenCzarny, xLeft, yPos, px_boki, 80); e.Graphics.DrawRectangle(myPenCzarny, xLeft_L, yPos, px_srodek, 80); e.Graphics.DrawRectangle(myPenCzarny, xLeft_P, yPos, px_boki, 40); e.Graphics.DrawRectangle(myPenCzarny, xLeft_P, yPos + 40, px_boki, 40); //logo Image oryginal = Properties.Resources.logo_ramb; var oW = (decimal)oryginal.Width; var oH = (decimal)oryginal.Height; Bitmap logoSoftSPM = new Bitmap(oryginal, (int)oW, (int)oH); Point ulCorner = new Point(xLeft + 17, yPos + 7); e.Graphics.DrawImage(logoSoftSPM, ulCorner); e.Graphics.DrawString("KARTA EKSPLOATACJI", myFontTytul, czarny, xLeft + 250, yPos + 15); e.Graphics.DrawString("Głębinowego Agregatu Pompowego", myFontBoldMid, czarny, xLeft + 200, yPos + 40); e.Graphics.DrawString("Data: " + tst_date, myFont, czarny, xLeft + 592, yPos + 12); e.Graphics.DrawString("Oddz.: " + klient_value, myFont, czarny, xLeft + 592, yPos + 51); yPos = yPos + 80; // ================================================================================================================================== //trzeci poziom // ================================================================================================================================== e.Graphics.DrawRectangle(myPenCzarny, xLeft, yPos, px_boki, 350); e.Graphics.DrawRectangle(myPenCzarny, xLeft_L, yPos, px_srodek, 350); e.Graphics.DrawRectangle(myPenCzarny, xLeft_P, yPos, px_boki, 350); e.Graphics.DrawString("Typ agregatu", myFontBold12, czarny, xLeft + 10, yPos + 10); e.Graphics.DrawString(typ_popmy_value, myFont12, czarny, xLeft + 10, yPos + 35); e.Graphics.DrawString(typ_silnika_value, myFont12, czarny, xLeft + 10, yPos + 55); //myFont8 //myFontBold8 //myFontMalenka //myFontMalenkaBold DrawTextWithBold(e.Graphics,xLeft + 10,yPos + 85, myFont8,czarny,"Nr pompy: " + sn_popmy_value + ""); DrawTextWithBold(e.Graphics, xLeft + 10, yPos + 102, myFont8, czarny, "Nr silnika: " + sn_silnika_value + ""); DrawTextWithBold(e.Graphics, xLeft + 10, yPos + 128, myFont8, czarny, "Qmin= " + Math.Round(qmin_value / 60, 3).ToString("F2") + " m3/min"); DrawTextWithBold(e.Graphics, xLeft + 10, yPos + 145, myFont8, czarny, "Qmax= " + Math.Round(qmax_value / 60, 3).ToString("F2") + " m3/min"); DrawTextWithBold(e.Graphics, xLeft + 10, yPos + 162, myFont8, czarny, "Hmin= " + hmin_value.ToString("F2") + " m"); DrawTextWithBold(e.Graphics, xLeft + 10, yPos + 179, myFont8, czarny, "Hmax= " + hmax_value.ToString("F2") + " m"); DrawTextWithBold(e.Graphics, xLeft + 10, yPos + 198, myFont8, czarny, "In= " + prad_value.ToString("F2") + " A"); DrawTextWithBold(e.Graphics, xLeft + 10, yPos + 220, myFont8, czarny, "Typ przewodu= " + cableType + ""); DrawTextWithBold(e.Graphics, xLeft + 10, yPos + 237, myFont8, czarny, "Lkw= " + cableLength + " m"); e.Graphics.DrawString("["+cableOznak_01+ "] ["+cableOznak_02+"]", myFontMala, czarny, xLeft + 30, yPos + 252); e.Graphics.DrawString("Data przekazania", myFont, czarny, xLeft + 10, yPos + 300); e.Graphics.DrawString(".........................", myFont, czarny, xLeft + 10, yPos + 335); e.Graphics.DrawString("Podpis ....................................", myFont, czarny, xLeft_L + 10, yPos + 335); e.Graphics.DrawString("Podpis ....................", myFont, czarny, xLeft_P + 7, yPos + 335); e.Graphics.DrawString("SoftSPM " + vGlobal.softwareVersion, myFontMala, szary, xLeft, yPos + 355); //yPos = yPos + 10; // ================================================================================================================================== e.Graphics.DrawString("Parametry energetyczne", myFontBold12, czarny, xLeft_L + 100, yPos + 10); e.Graphics.DrawString("Dane eksploatacyjne", myFontBold, czarny, xLeft_P + 5, yPos + 10); yPos = yPos + 50; // ----------------------------------------------------------------------------------------------------------- // PARAMETRY USTAWIENIA TABELI // ----------------------------------------------------------------------------------------------------------- int columns = 6; int rows = 6; // Zakres poziomy tabeli (między lewą i prawą kolumną Twojego raportu) int tableLeft = xLeft_L+5; int tableRight = xLeft_P-2; int tableWidth = tableRight - tableLeft; // Wysokość każdej komórki int rowHeight = 40; // Pierwsza kolumna (Lp.) – węższa int lpWidth = 40; int otherColsWidth = (tableWidth - lpWidth) / (columns - 1); // Miejsce początkowe tabeli od góry int tableTopStart = yPos; // 👈 tu ustaw, gdzie tabela ma się zacząć (np. +50 pikseli poniżej yPos) // Całkowita wysokość tabeli int tableHeight = rows * rowHeight; double paramX_Show = 0; double paramY_Show = 0; // ----------------------------------------------------------------------------------------------------------- // RYSOWANIE TABELI // ----------------------------------------------------------------------------------------------------------- for (int r = 0; r < rows; r++) { // Pozycja pionowa wiersza int y = tableTopStart + r * rowHeight; // Przesuwany "kursor" X int x = tableLeft; for (int c = 0; c < columns; c++) { int colWidth = (c == 0) ? lpWidth : otherColsWidth; // Rysowanie komórki e.Graphics.DrawRectangle(myPenCzarny, x, y, colWidth, rowHeight); // Rysowanie tekstu (wyśrodkowany) StringFormat center = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; // Zdefiniuj własne nagłówki (musi być tyle elementów, ile kolumn) string[] headers = new string[] { "Lp.", "Q\nm3/min", "H\nm", "I\nA", "U\nV", "P\nkW" }; string cellText; // Rysowanie wiersza nagłówkowego if (r == 0) { // Nagłówki kolumn cellText = (c < headers.Length) ? headers[c] : string.Empty; e.Graphics.DrawString(cellText, myFontBold, Brushes.Black, new RectangleF(x, y, colWidth, rowHeight), center); } else { if (c == 0) { paramX_Show = r; } else if (c == 1) { if (r == 1) paramX_Show = qn_value * 0.55; else if (r == 2) paramX_Show = qn_value * 0.7; else if (r == 3) paramX_Show = qn_value; else if (r == 4) paramX_Show = qn_value * 1.22; else if (r == 5) paramX_Show = qn_value * 1.35; } else if (c == 2) { paramY_Show = GetPolynomialValue(spm_test_id, "TSD_VAL_04", "TSD_VAL_08", paramX_Show, 3); } else if (c == 3) { paramY_Show = GetPolynomialValue(spm_test_id, "TSD_VAL_04", "TSD_VAL_16", paramX_Show, 3); } else if (c == 4) { paramY_Show = GetPolynomialValue(spm_test_id, "TSD_VAL_04", "TSD_VAL_13", paramX_Show, 3); } else if (c == 5) { paramY_Show = GetPolynomialValue(spm_test_id, "TSD_VAL_04", "TSD_VAL_14", paramX_Show, 3); } // Dane //cellText = (c == 0) ? r.ToString() : $"R{r}C{c}"; if (c == 0) e.Graphics.DrawString(paramX_Show.ToString(), myFont, Brushes.Black, new RectangleF(x, y, colWidth, rowHeight), center); else if (c == 1) e.Graphics.DrawString(Math.Round(paramX_Show / 60, 3).ToString(), myFont, Brushes.Black,new RectangleF(x, y, colWidth, rowHeight), center); else e.Graphics.DrawString(Math.Round(paramY_Show,2).ToString(), myFont, Brushes.Black, new RectangleF(x, y, colWidth, rowHeight), center); } x += colWidth; } } // ----------------------------------------------------------------------------------------------------------- e.Graphics.DrawString("Nr studni: ...............", myFont, czarny, xLeft_P + 7, yPos + 5); e.Graphics.DrawString("Data uruch: ..............", myFont, czarny, xLeft_P + 7, yPos + 35); e.Graphics.DrawString("Data zatrz: ..............", myFont, czarny, xLeft_P + 7, yPos + 65); e.Graphics.DrawString("Czas pracy: ..............", myFont, czarny, xLeft_P + 7, yPos + 95); e.Graphics.DrawString("Przyczyna: ...............", myFont, czarny, xLeft_P + 7, yPos + 125); e.Graphics.DrawString("Lp= .............. m", myFont, czarny, xLeft_P + 7, yPos + 155); e.Graphics.DrawString("Hst= .............. m", myFont, czarny, xLeft_P + 7, yPos + 185); e.Graphics.DrawString("Hd= .............. m", myFont, czarny, xLeft_P + 7, yPos + 215); e.Graphics.DrawString("Q= .............. m3/min", myFont, czarny, xLeft_P + 7, yPos + 245); } private void LoadPageSize(PrintPageEventArgs param) { Rectangle marginBounds = param.MarginBounds; xLeft = marginBounds.Left - 50; yTop = marginBounds.Top - 50; xRight = marginBounds.Right + 50; yButtom = marginBounds.Bottom + 50; printWidth = xRight - xLeft; printHeight = yButtom - yTop; } double SafeParse(object val) { if (val == null) return 0; var s = val.ToString().Trim().Replace(",", "."); double result; return double.TryParse(s, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out result) ? result : 0; } private void fullTestReportForm_Load(object sender, EventArgs e) { tabControl1.TabPages[0].Text = "Dane podstawowe i nominalne"; tabControl1.TabPages[1].Text = "Pompa - dane pomiarowe"; tabControl1.TabPages[2].Text = "Silnik - dane pomiarowe"; tabControl1.TabPages[3].Text = "Podnoszenie - wykres"; tabControl1.TabPages[4].Text = "Moc - wykres"; tabControl1.TabPages[5].Text = "Sprawność agregatu - wykres"; tabControl1.TabPages[6].Text = "Komentarz / Uwagi"; // do definicji w kontekście przeprowadzonej próby textBoxHeader01.Text = "Parametry pompy zgodne z normą. Próba zakończona pomyślnie."; textBoxHeader02.Text = "Nr próby: " + spm_test_id.ToString(); labelPodnoszenie.Text = "Podnoszenie H(Q)"; labelMoc.Text = "Moc P(Q)"; labelSprawnosc.Text = "Sprawność agregatu ƞA(Q)"; //select PUP_Q_N,PUP_Q_MIN,PUP_Q_MAX,PUP_H_P,PUP_H_MIN,PUP_H_MAX,PUP_ETA_MAX from tst_tests left join seg_pumps on TST_PUP_ID=PUP_ID where TST_ID=89 mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select PUP_ID,PUP_NAME,TST_PUP_SN_NO,PUP_Q_N,PUP_Q_MIN,PUP_Q_MAX,PUP_H_P,PUP_H_MIN,PUP_H_MAX,PUP_ETA_MAX,TST_STAN_COLD,TST_STAN_WARM,TST_STATUS,TST_AUDIT_CU,TST_AUDIT_CD from tst_tests left join seg_pumps on TST_PUP_ID=PUP_ID where TST_ID=" + spm_test_id.ToString(), mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { pupm_id_value = Convert.ToInt32(dataReader["PUP_ID"].ToString()); typ_popmy_value = dataReader["PUP_NAME"].ToString(); sn_popmy_value = dataReader["TST_PUP_SN_NO"].ToString(); // RAMB - 10.10.2025 - poprawa parsowania double /* qn_value = Math.Round(Convert.ToDouble(dataReader["PUP_Q_N"].ToString()), 2); qmin_value = Math.Round(Convert.ToDouble(dataReader["PUP_Q_MIN"].ToString()), 2); qmax_value = Math.Round(Convert.ToDouble(dataReader["PUP_Q_MAX"].ToString()), 2); hn_value = Math.Round(Convert.ToDouble(dataReader["PUP_H_P"].ToString()), 2); hmin_value = Math.Round(Convert.ToDouble(dataReader["PUP_H_MIN"].ToString()), 2); hmax_value = Math.Round(Convert.ToDouble(dataReader["PUP_H_MAX"].ToString()), 2); eta_value = Math.Round(Convert.ToDouble(dataReader["PUP_ETA_MAX"].ToString()), 2); stan_izol_zimny = Math.Round(Convert.ToDouble(dataReader["TST_STAN_COLD"].ToString()), 2); stan_izol_cieply = Math.Round(Convert.ToDouble(dataReader["TST_STAN_WARM"].ToString()), 2); */ qn_value = Math.Round(SafeParse(dataReader["PUP_Q_N"]), 2); qmin_value = Math.Round(SafeParse(dataReader["PUP_Q_MIN"]), 2); qmax_value = Math.Round(SafeParse(dataReader["PUP_Q_MAX"]), 2); hn_value = Math.Round(SafeParse(dataReader["PUP_H_P"]), 2); hmin_value = Math.Round(SafeParse(dataReader["PUP_H_MIN"]), 2); hmax_value = Math.Round(SafeParse(dataReader["PUP_H_MAX"]), 2); eta_value = Math.Round(SafeParse(dataReader["PUP_ETA_MAX"]), 2); stan_izol_zimny = Math.Round(SafeParse(dataReader["TST_STAN_COLD"]), 2); stan_izol_cieply = Math.Round(SafeParse(dataReader["TST_STAN_WARM"]), 2); prowadzacy_value = dataReader["TST_AUDIT_CU"].ToString(); labelProwadzacy.Text = prowadzacy_value; //tst_date = dataReader["TST_AUDIT_CD"].ToString().Substring(0,10); DateTime auditDate = Convert.ToDateTime(dataReader["TST_AUDIT_CD"]); tst_date = auditDate.ToString("yyyy-MM-dd"); if (String.Compare(dataReader["TST_STATUS"].ToString(), "0", true) == 0) textBoxHeader01.Text = "Parametry agregatu poza zakresem stosowalności."; else if (String.Compare(dataReader["TST_STATUS"].ToString(), "2", true) == 0) textBoxHeader01.Text = "Próba została przerwana."; } dataReader.Close(); mySqlFunctions.CloseConnection(); } //select ENG_POWER,ENG_VOLTAGE,ENG_ELECTRICITY,ENG_RPM,ENG_ETA,ENG_COS_FI from tst_tests left join seg_engines on TST_ENG_ID=ENG_ID where TST_ID=89 mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select ENG_NAME,TST_ENG_SN_NO,ENG_POWER,ENG_VOLTAGE,ENG_ELECTRICITY,ENG_RPM,ENG_ETA,ENG_COS_FI from tst_tests left join seg_engines on TST_ENG_ID=ENG_ID where TST_ID=" + spm_test_id.ToString(), mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { typ_silnika_value = dataReader["ENG_NAME"].ToString(); sn_silnika_value = dataReader["TST_ENG_SN_NO"].ToString(); moc_value = Math.Round(Convert.ToDouble(dataReader["ENG_POWER"].ToString()), 2); nap_value = Math.Round(Convert.ToDouble(dataReader["ENG_VOLTAGE"].ToString()), 2); prad_value = Math.Round(Convert.ToDouble(dataReader["ENG_ELECTRICITY"].ToString()), 2); obrot_value = Math.Round(Convert.ToDouble(dataReader["ENG_RPM"].ToString()), 2); spraw_sil_value = Math.Round(Convert.ToDouble(dataReader["ENG_ETA"].ToString()), 2); wsp_mocy = Math.Round(Convert.ToDouble(dataReader["ENG_COS_FI"].ToString()), 2); } dataReader.Close(); MySql.Data.MySqlClient.MySqlCommand cmd1 = new MySql.Data.MySqlClient.MySqlCommand("select * from tst_test_notif where TNF_ON_REPORT='1' and TNF_TST_ID=" + spm_test_id.ToString(), mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader1 = cmd1.ExecuteReader(); while (dataReader1.Read()) { uwagi_value = dataReader1["TNF_DESC"].ToString(); //klient_value = dataReader1["TNF_CUSTOMER"].ToString(); zlecenie_value = dataReader1["TNF_COMMISION"].ToString(); } dataReader1.Close(); mySqlFunctions.CloseConnection(); } // pobiera informacje o Oddziale pompy mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd1 = new MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM seg_dev_resources WHERE DRS_ID=(SELECT MAX(DRS_ID) FROM seg_dev_resources,seg_pumps WHERE DRS_DEV_TYPE=10 AND DRS_DEV_ID=PUP_ID AND PUP_ID='"+ pupm_id_value + "' AND DRS_SN_NUMBER='"+ sn_popmy_value + "')", mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd1.ExecuteReader(); while (dataReader.Read()) { klient_value = dataReader["DRS_AUDIT_USR"].ToString(); } dataReader.Close(); mySqlFunctions.CloseConnection(); } czest_value = 50; int ilPomiarow = mySqlFunctions.sqlIntValue("select count(1) from tst_test_details where TSD_TST_ID=" + spm_test_id.ToString()); LoadTabPages02(spm_test_id); if (ilPomiarow>0) LoadTabPages03(spm_test_id); LoadTabPages01(spm_test_id); LoadTabPages00(spm_test_id); LoadTabPages06(spm_test_id); } private void buttonDrukujRaport_Click(object sender, EventArgs e) { // Najpierw dialog wyboru drukarki // Reset numeru strony przed każdym wydrukiem currentPrintPage = 1; printDialog.AllowSomePages = true; printDialog.ShowHelp = false; printDialog.Document = printDocument; if (printDialog.ShowDialog() == DialogResult.OK) { printDocument.PrinterSettings = printDialog.PrinterSettings; printPreviewDialog.Document = printDocument; // Ustawienie PrintPreviewDialog na maksymalny rozmiar if (printPreviewDialog != null && printPreviewDialog is Form) { Form previewForm = (Form)printPreviewDialog; previewForm.WindowState = FormWindowState.Maximized; } printPreviewDialog.ShowDialog(); } } private void PrintHeader(PrintPageEventArgs e, int num) { Font myFont = new System.Drawing.Font("tahoma", 10, FontStyle.Regular); Font myFontBold = new System.Drawing.Font("tahoma", 10, FontStyle.Bold); Font myFontMala = new System.Drawing.Font("tahoma", 8, FontStyle.Regular); Font myFontMalaBold = new System.Drawing.Font("tahoma", 8, FontStyle.Bold); Font myFontMalenka = new System.Drawing.Font("tahoma", 7, FontStyle.Regular); Font myFontMalenkaBold = new System.Drawing.Font("tahoma", 7, FontStyle.Bold); Font myFontTytul = new System.Drawing.Font("arial", 20, FontStyle.Bold); Pen myPenCzarny = new Pen(System.Drawing.Color.Black, 1); Pen myPenSzary = new Pen(System.Drawing.Color.Gray, 1); Brush czarny = new SolidBrush(System.Drawing.Color.Black); //rysuje górny kwadrat e.Graphics.DrawRectangle(myPenCzarny, xLeft, yTop, printWidth, 118); //e.Graphics.DrawString(vGlobal.softwareLicencePart001 + (char)10 + vGlobal.softwareLicencePart002 + (char)10, myFontMalaBold, czarny, xLeft + 1, yTop + 90); // tytuł na protokole e.Graphics.DrawString("RAMB Sp. z o.o." + (char)10 + "Piaski 2," + (char)10 + "97-400 Bełchatów", myFont, czarny, xLeft + 1, yTop + 5); e.Graphics.DrawString("tel.: +48 44 737 78 01" + (char)10 + "fax: +48 44 737 78 02", myFontMala, czarny, xLeft + 1, yTop + 90); //e.Graphics.DrawString("Baza Zemborzycka", myFont, czarny, xLeft + 1, yTop + 35); //e.Graphics.DrawString("ul. Zemborzycka 114a" + (char)10 + "20-445 Lublin" + (char)10 + "tel.: +48 817 443 641" + (char)10 + "fax: +48 817 443 280", myFontMala, czarny, xLeft + 1, yTop + 60); //Image logoSoftSPM = Image.FromFile(@"images\agh_logo_png.png"); Image oryginal = Properties.Resources.logo_ramb; var oW = (decimal)oryginal.Width; var oH = (decimal)oryginal.Height; Bitmap logoSoftSPM = new Bitmap(oryginal, (int)oW, (int)oH); Point ulCorner = new Point(xLeft + xLeft + 120, yTop +30); e.Graphics.DrawImage(logoSoftSPM, ulCorner); e.Graphics.DrawString("Protokół próby", myFontTytul, czarny, xLeft + 330, yTop+45); e.Graphics.DrawLine(myPenCzarny, new Point(xLeft + 580, yTop), new Point(xLeft + 580, yTop + 118)); e.Graphics.DrawLine(myPenCzarny, new Point(xLeft + 580, yTop + 59), new Point(xRight, yTop + 59)); e.Graphics.DrawString("Nr: ", myFontBold, czarny, xLeft + 585, yTop + 25); e.Graphics.DrawString(spm_test_id.ToString(), myFontBold, czarny, xLeft + 610, yTop + 25); e.Graphics.DrawString("Data: " + tst_date, myFontBold, czarny, xLeft + 585, yTop + 68); e.Graphics.DrawString("Strona: " + num.ToString(), myFontBold, czarny, xLeft + 585, yTop + 88); e.Graphics.DrawRectangle(myPenCzarny, xLeft, yTop + 120, printWidth / 2 - 1, 20); e.Graphics.DrawRectangle(myPenCzarny, xLeft + (printWidth / 2 + 2), yTop + 120, printWidth / 2 - 1, 20); e.Graphics.DrawString("Typ pompy: " + typ_popmy_value, myFont, czarny, xLeft + 1, yTop + 122); e.Graphics.DrawString("Nr pompy: " + sn_popmy_value, myFont, czarny, xLeft + 1, yTop + 143); e.Graphics.DrawRectangle(myPenCzarny, xLeft, yTop + 142, printWidth / 2 - 1, 20); e.Graphics.DrawRectangle(myPenCzarny, xLeft + (printWidth / 2 + 2), yTop + 142, printWidth / 2 - 1, 20); e.Graphics.DrawString("Typ silnika: " + typ_silnika_value, myFont, czarny, xLeft + (printWidth / 2 + 3), yTop + 122); e.Graphics.DrawString("Nr silnika: " + sn_silnika_value, myFont, czarny, xLeft + (printWidth / 2 + 3), yTop + 143); } private void PrintFooter(PrintPageEventArgs e, int num) { Font myFont = new System.Drawing.Font("tahoma", 8, FontStyle.Regular); Font myFontLic = new System.Drawing.Font("tahoma", 7, FontStyle.Regular); Pen myPenSzary = new Pen(System.Drawing.Color.Gray, 1); Brush szary = new SolidBrush(System.Drawing.Color.Gray); e.Graphics.DrawLine(myPenSzary, xLeft, yButtom, xRight, yButtom); e.Graphics.DrawString("© SoftSPM " + vGlobal.softwareVersion + " " + vGlobal.softwareLicenceFull, myFontLic, szary, xLeft, yButtom + 1); e.Graphics.DrawString("Strona: " + num + "/3", myFontLic, szary, xRight-51, yButtom + 1); e.Graphics.DrawString("Data wydruku: " + DateTime.Now.ToString("yyyy-MM-dd"), myFontLic, szary, xRight - 120, yTop-15); } // Wydruk danych nominalnych pompy i silnika - na drukarce private void PrintPumpData(PrintPageEventArgs e, int test_id) { Font myFont = new System.Drawing.Font("tahoma", 10, FontStyle.Regular); Font myFontMala = new System.Drawing.Font("tahoma", 9, FontStyle.Regular); Font myFontCur = new System.Drawing.Font("courier new", 12, FontStyle.Bold); Font myFontBold = new System.Drawing.Font("courier new", 9, FontStyle.Bold); Pen myPenCzarny = new Pen(System.Drawing.Color.Black, 1); Pen myPenSzary = new Pen(System.Drawing.Color.Gray, 1); Brush czarny = new SolidBrush(System.Drawing.Color.Black); Brush szary = new SolidBrush(System.Drawing.Color.Gray); e.Graphics.DrawRectangle(myPenCzarny, xLeft, yTop + 164, printWidth / 2 - 1, 20); e.Graphics.DrawString("Dane nominalne pompy", myFont, czarny, xLeft + 2, yTop + 165); e.Graphics.DrawRectangle(myPenCzarny, xLeft + (printWidth / 2 + 2), yTop + 164, printWidth / 2 - 1, 20); e.Graphics.DrawString("Dane nominalne silnika", myFont, czarny, xLeft + (printWidth / 2 + 4), yTop + 165); // pompa e.Graphics.DrawRectangle(myPenCzarny, xLeft, yTop + 184, printWidth / 2 - 1, 112); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + 1, yTop + 200), new Point(xLeft + (printWidth / 2 - 2), yTop + 200)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + 1, yTop + 216), new Point(xLeft + (printWidth / 2 - 2), yTop + 216)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + 1, yTop + 232), new Point(xLeft + (printWidth / 2 - 2), yTop + 232)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + 1, yTop + 248), new Point(xLeft + (printWidth / 2 - 2), yTop + 248)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + 1, yTop + 264), new Point(xLeft + (printWidth / 2 - 2), yTop + 264)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + 1, yTop + 280), new Point(xLeft + (printWidth / 2 - 2), yTop + 280)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + (printWidth / 2 - 2) / 3, yTop + 185), new Point(xLeft + (printWidth / 2 - 2) / 3, yTop + 295)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + 2 * ((printWidth / 2 - 2) / 3), yTop + 185), new Point(xLeft + 2 * ((printWidth / 2 - 2) / 3), yTop + 295)); e.Graphics.DrawString("Wydajność", myFontMala, szary, xLeft + 1, yTop + 185); e.Graphics.DrawString("Podnoszenie", myFontMala, szary, xLeft + 1, yTop + 233); e.Graphics.DrawString("Sprawność", myFontMala, szary, xLeft + 1, yTop + 281); e.Graphics.DrawString("Qn", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1, yTop + 185); e.Graphics.DrawString("[m3/min]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 60, yTop + 185); e.Graphics.DrawString("Qmin", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3)+1, yTop + 201); e.Graphics.DrawString("[m3/min]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 60, yTop + 201); e.Graphics.DrawString("Qmax", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1, yTop + 217); e.Graphics.DrawString("[m3/min]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 60, yTop + 217); e.Graphics.DrawString("Hn", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1, yTop + 233); e.Graphics.DrawString("[m]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 60, yTop + 233); e.Graphics.DrawString("Hmin", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1, yTop + 249); e.Graphics.DrawString("[m]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 60, yTop + 249); e.Graphics.DrawString("Hmax", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1, yTop + 265); e.Graphics.DrawString("[m]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 60, yTop + 265); e.Graphics.DrawString("ƞ max", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1, yTop + 281); e.Graphics.DrawString(convertDataFromSerial.ConvertToM3PerMin(qn_value).ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5, yTop + 185); e.Graphics.DrawString(convertDataFromSerial.ConvertToM3PerMin(qmin_value).ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5, yTop + 201); e.Graphics.DrawString(convertDataFromSerial.ConvertToM3PerMin(qmax_value).ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5, yTop + 217); e.Graphics.DrawString(hn_value.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5, yTop + 233); e.Graphics.DrawString(hmin_value.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5, yTop + 249); e.Graphics.DrawString(hmax_value.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5, yTop + 265); e.Graphics.DrawString(eta_value.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5, yTop + 281); // silnik e.Graphics.DrawRectangle(myPenCzarny, xLeft + (printWidth / 2 + 2), yTop + 184, printWidth / 2 - 1, 112); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + (printWidth / 2 + 3), yTop + 200), new Point(xLeft + (printWidth / 2 + 2) + (printWidth / 2 - 2), yTop + 200)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + (printWidth / 2 + 3), yTop + 216), new Point(xLeft + (printWidth / 2 + 2) + (printWidth / 2 - 2), yTop + 216)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + (printWidth / 2 + 3), yTop + 232), new Point(xLeft + (printWidth / 2 + 2) + (printWidth / 2 - 2), yTop + 232)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + (printWidth / 2 + 3), yTop + 248), new Point(xLeft + (printWidth / 2 + 2) + (printWidth / 2 - 2), yTop + 248)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + (printWidth / 2 + 3), yTop + 264), new Point(xLeft + (printWidth / 2 + 2) + (printWidth / 2 - 2), yTop + 264)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + (printWidth / 2 + 3), yTop + 280), new Point(xLeft + (printWidth / 2 + 2) + (printWidth / 2 - 2), yTop + 280)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + (printWidth / 2 + 3) + (printWidth / 2 - 2) / 3, yTop + 185), new Point(xLeft + (printWidth / 2 + 3) + (printWidth / 2 - 2) / 3, yTop + 295)); e.Graphics.DrawLine(myPenSzary, new Point(xLeft + (printWidth / 2 + 3) + 2 * ((printWidth / 2 - 2) / 3), yTop + 185), new Point(xLeft + (printWidth / 2 + 3) + 2 * ((printWidth / 2 - 2) / 3), yTop + 295)); e.Graphics.DrawString("Moc", myFontMala, szary, xLeft + (printWidth / 2 + 3), yTop + 185); e.Graphics.DrawString("Napięcie", myFontMala, szary, xLeft + (printWidth / 2 + 3), yTop + 201); e.Graphics.DrawString("Prąd", myFontMala, szary, xLeft + (printWidth / 2 + 3), yTop + 217); e.Graphics.DrawString("Obroty", myFontMala, szary, xLeft + (printWidth / 2 + 3), yTop + 233); e.Graphics.DrawString("Sprawność", myFontMala, szary, xLeft + (printWidth / 2 + 3), yTop + 249); e.Graphics.DrawString("Wsp. mocy", myFontMala, szary, xLeft + (printWidth / 2 + 3), yTop + 265); e.Graphics.DrawString("Częstotliwość", myFontMala, szary, xLeft + (printWidth / 2 + 3), yTop + 281); e.Graphics.DrawString("Pn ", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1 + (printWidth / 2 + 3), yTop + 185); e.Graphics.DrawString("[kW]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 61 + (printWidth / 2 + 3), yTop + 185); e.Graphics.DrawString("Un ", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1 + (printWidth / 2 + 3), yTop + 201); e.Graphics.DrawString("[V]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 61 + (printWidth / 2 + 3), yTop + 201); e.Graphics.DrawString("In ", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1 + (printWidth / 2 + 3), yTop + 217); e.Graphics.DrawString("[A]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 61 + (printWidth / 2 + 3), yTop + 217); e.Graphics.DrawString("n ", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1 + (printWidth / 2 + 3), yTop + 233); e.Graphics.DrawString("[1/min]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 61 + (printWidth / 2 + 3), yTop + 233); e.Graphics.DrawString("ƞ ", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1 + (printWidth / 2 + 3), yTop + 249); e.Graphics.DrawString("cos φ", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1 + (printWidth / 2 + 3), yTop + 265); e.Graphics.DrawString("f ", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 1 + (printWidth / 2 + 3), yTop + 281); e.Graphics.DrawString("[Hz]", myFontMala, szary, xLeft + ((printWidth / 2 - 2) / 3) + 61 + (printWidth / 2 + 3), yTop + 281); e.Graphics.DrawString(moc_value.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5 + (printWidth / 2 + 3), yTop + 185); e.Graphics.DrawString(nap_value.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5 + (printWidth / 2 + 3), yTop + 201); e.Graphics.DrawString(prad_value.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5 + (printWidth / 2 + 3), yTop + 217); e.Graphics.DrawString(obrot_value.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5 + (printWidth / 2 + 3), yTop + 233); e.Graphics.DrawString(spraw_sil_value.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5 + (printWidth / 2 + 3), yTop + 249); e.Graphics.DrawString(wsp_mocy.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5 + (printWidth / 2 + 3), yTop + 265); e.Graphics.DrawString(czest_value.ToString(), myFontMala, szary, xLeft + 2 * ((printWidth / 2 - 2) / 3) + 5 + (printWidth / 2 + 3), yTop + 281); e.Graphics.DrawString("Pompa", myFontCur, czarny, xLeft + printWidth / 2 -25 , yTop + 300); int il_column = 8; int auto_szer = printWidth / il_column; e.Graphics.DrawRectangle(myPenCzarny, xLeft, yTop + 320, auto_szer, 60); e.Graphics.DrawString("Lp.", myFontMala, czarny, xLeft + 20, yTop + 340); e.Graphics.DrawRectangle(myPenCzarny, xLeft + auto_szer, yTop + 320, auto_szer, 60); e.Graphics.DrawString("Wydajność", myFontMala, czarny, xLeft + auto_szer + 5, yTop + 321); e.Graphics.DrawString("Q", myFontBold, czarny, xLeft + auto_szer + 25, yTop + 340); e.Graphics.DrawString("[m3/min]", myFontMala, czarny, xLeft + auto_szer + 5, yTop + 360); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 2 * auto_szer, yTop + 320, auto_szer, 60); e.Graphics.DrawString("Ciśnienie", myFontMala, czarny, xLeft + 2 * auto_szer + 5, yTop + 321); e.Graphics.DrawString("p", myFontBold, czarny, xLeft + 2*auto_szer + 25, yTop + 340); e.Graphics.DrawString("[m]", myFontMala, czarny, xLeft + 2 * auto_szer + 20, yTop + 360); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 3 * auto_szer, yTop + 320, auto_szer, 60); e.Graphics.DrawString("Człon dyn.", myFontMala, czarny, xLeft + 3 * auto_szer + 5, yTop + 321); e.Graphics.DrawString("C2/2g", myFontBold, czarny, xLeft + 3 * auto_szer + 25, yTop + 340); e.Graphics.DrawString("[m]", myFontMala, czarny, xLeft + 3 * auto_szer + 20, yTop + 360); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 4 * auto_szer, yTop + 320, auto_szer, 60); e.Graphics.DrawString("Człon geo", myFontMala, czarny, xLeft + 4 * auto_szer + 5, yTop + 321); e.Graphics.DrawString("Z", myFontBold, czarny, xLeft + 4 * auto_szer + 25, yTop + 340); e.Graphics.DrawString("[m]", myFontMala, czarny, xLeft + 4 * auto_szer + 20, yTop + 360); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 5 * auto_szer, yTop + 320, auto_szer, 60); e.Graphics.DrawString("Podnoszenie", myFontMala, czarny, xLeft + 5 * auto_szer + 5, yTop + 321); e.Graphics.DrawString("H", myFontBold, czarny, xLeft + 5 * auto_szer + 25, yTop + 340); e.Graphics.DrawString("[m]", myFontMala, czarny, xLeft + 5 * auto_szer + 20, yTop + 360); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 6 * auto_szer, yTop + 320, auto_szer, 60); e.Graphics.DrawString("Moc oddana", myFontMala, czarny, xLeft + 6 * auto_szer + 5, yTop + 321); e.Graphics.DrawString("Pp", myFontBold, czarny, xLeft + 6 * auto_szer + 25, yTop + 340); e.Graphics.DrawString("[kW]", myFontMala, czarny, xLeft + 6 * auto_szer + 20, yTop + 360); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 7 * auto_szer, yTop + 320, auto_szer, 60); e.Graphics.DrawString("Sprawność agr.", myFontMala, czarny, xLeft + 7 * auto_szer + 1, yTop + 321); e.Graphics.DrawString("ƞA", myFontBold, czarny, xLeft + 7 * auto_szer + 25, yTop + 340); int index=0; mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select TSD_MSR_STEP,TSD_VAL_04,TSD_VAL_05,TSD_VAL_07,TSD_VAL_01,TSD_VAL_08,TSD_VAL_09,TSD_VAL_18 from tst_test_details where TSD_TST_ID=" + test_id.ToString() + " order by TSD_VAL_04", mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { e.Graphics.DrawRectangle(myPenCzarny, xLeft, yTop + 380 + (16 * index), auto_szer, 16); e.Graphics.DrawString((index+1).ToString(), myFontMala, szary, xLeft + 20, yTop + 380 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 1 * auto_szer, yTop + 380 + (16 * index), auto_szer, 16); e.Graphics.DrawString(convertDataFromSerial.ConvertToM3PerMin(dataReader["TSD_VAL_04"]).ToString(), myFontMala, szary, xLeft + 1 * auto_szer + 10, yTop + 380 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 2 * auto_szer, yTop + 380 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_05"].ToString(), myFontMala, szary, xLeft + 2 * auto_szer + 10, yTop + 380 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 3 * auto_szer, yTop + 380 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_07"].ToString(), myFontMala, szary, xLeft + 3 * auto_szer + 10, yTop + 380 + (16 * index) + 1); // AGH - ciśnienie HH e.Graphics.DrawRectangle(myPenCzarny, xLeft + 4 * auto_szer, yTop + 380 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_01"].ToString(), myFontMala, szary, xLeft + 4 * auto_szer + 10, yTop + 380 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 5 * auto_szer, yTop + 380 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_08"].ToString(), myFontMala, szary, xLeft + 5 * auto_szer + 10, yTop + 380 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 6* auto_szer, yTop + 380 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_09"].ToString(), myFontMala, szary, xLeft + 6 * auto_szer + 10, yTop + 380 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 7 * auto_szer, yTop + 380 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_18"].ToString(), myFontMala, szary, xLeft + 7 * auto_szer + 10, yTop + 380 + (16 * index) + 1); index++; } mySqlFunctions.CloseConnection(); } } private void PrintMotorData(PrintPageEventArgs e, int test_id) { Font myFont = new System.Drawing.Font("tahoma", 10, FontStyle.Regular); Font myFontMala = new System.Drawing.Font("tahoma", 9, FontStyle.Regular); Font myFontCur = new System.Drawing.Font("courier new", 12, FontStyle.Bold); Font myFontBold = new System.Drawing.Font("courier new", 9, FontStyle.Bold); Pen myPenCzarny = new Pen(System.Drawing.Color.Black, 1); Pen myPenSzary = new Pen(System.Drawing.Color.Gray, 1); Brush czarny = new SolidBrush(System.Drawing.Color.Black); Brush szary = new SolidBrush(System.Drawing.Color.Gray); e.Graphics.DrawString("Silnik", myFontCur, czarny, xLeft + printWidth / 2 - 25, yTop + 170); int il_column = 10; int auto_szer = printWidth / il_column; e.Graphics.DrawRectangle(myPenCzarny, xLeft, yTop + 190, auto_szer, 60); e.Graphics.DrawString("Lp.", myFontMala, czarny, xLeft + 20, yTop + 210); e.Graphics.DrawRectangle(myPenCzarny, xLeft + auto_szer, yTop + 190, auto_szer, 60); e.Graphics.DrawString("Napięcie", myFontMala, czarny, xLeft + auto_szer + 5, yTop + 191); e.Graphics.DrawString("U", myFontBold, czarny, xLeft + auto_szer + 27, yTop + 210); e.Graphics.DrawString("[V]", myFontMala, czarny, xLeft + auto_szer + 25, yTop + 230); e.Graphics.DrawLine(myPenCzarny, new Point(xLeft + 2 * auto_szer, yTop + 190), new Point(xLeft + 7 * auto_szer, yTop + 190)); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 2 * auto_szer, yTop + 209, auto_szer, 41); e.Graphics.DrawString("IR", myFontBold, czarny, xLeft + 2 * auto_szer + 25, yTop + 210); e.Graphics.DrawString("[A]", myFontMala, czarny, xLeft + 2 * auto_szer + 25, yTop + 230); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 3 * auto_szer, yTop + 209, auto_szer, 41); e.Graphics.DrawString("IS", myFontBold, czarny, xLeft + 3 * auto_szer + 25, yTop + 210); e.Graphics.DrawString("[A]", myFontMala, czarny, xLeft + 3 * auto_szer + 25, yTop + 230); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 4 * auto_szer, yTop + 209, auto_szer, 41); e.Graphics.DrawString("Prąd", myFontMala, czarny, xLeft + 4 * auto_szer + 5, yTop + 191); e.Graphics.DrawString("IT", myFontBold, czarny, xLeft + 4 * auto_szer + 25, yTop + 210); e.Graphics.DrawString("[A]", myFontMala, czarny, xLeft + 4 * auto_szer + 25, yTop + 230); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 5 * auto_szer, yTop + 209, auto_szer, 41); e.Graphics.DrawString("∆I", myFontBold, czarny, xLeft + 5 * auto_szer + 25, yTop + 210); e.Graphics.DrawString("[%]", myFontMala, czarny, xLeft + 5 * auto_szer + 25, yTop + 230); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 6 * auto_szer, yTop + 209, auto_szer, 41); e.Graphics.DrawString("I", myFontBold, czarny, xLeft + 6 * auto_szer + 25, yTop + 210); e.Graphics.DrawString("[A]", myFontMala, czarny, xLeft + 6 * auto_szer + 25, yTop + 230); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 7 * auto_szer, yTop + 190, auto_szer, 60); e.Graphics.DrawString("Moc pob.", myFontMala, czarny, xLeft + 7 * auto_szer + 5, yTop + 191); e.Graphics.DrawString("P", myFontBold, czarny, xLeft + 7 * auto_szer + 27, yTop + 210); e.Graphics.DrawString("[kW]", myFontMala, czarny, xLeft + 7 * auto_szer + 20, yTop + 230); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 8 * auto_szer, yTop + 190, auto_szer, 60); e.Graphics.DrawString("Współcz.", myFontMala, czarny, xLeft + 8 * auto_szer + 5, yTop + 191); e.Graphics.DrawString("mocy", myFontMala, czarny, xLeft + 8 * auto_szer + 25, yTop + 210); e.Graphics.DrawString("cos φ", myFontBold, czarny, xLeft + 8 * auto_szer + 20, yTop + 230); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 9 * auto_szer, yTop + 190, auto_szer, 60); e.Graphics.DrawString("Obroty", myFontMala, czarny, xLeft + 9 * auto_szer + 5, yTop + 191); e.Graphics.DrawString("n", myFontBold, czarny, xLeft + 9 * auto_szer + 27, yTop + 210); e.Graphics.DrawString("[1/min]", myFontMala, czarny, xLeft + 9 * auto_szer + 10, yTop + 230); int index = 0; mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select TSD_VAL_13,TSD_VAL_10,TSD_VAL_11,TSD_VAL_12,TSD_VAL_17,TSD_VAL_16,TSD_VAL_14,TSD_VAL_15,TSD_VAL_03 from tst_test_details where TSD_TST_ID=" + test_id.ToString() + " order by TSD_MSR_STEP", mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { e.Graphics.DrawRectangle(myPenCzarny, xLeft, yTop + 250 + (16 * index), auto_szer, 16); e.Graphics.DrawString((index + 1).ToString(), myFontMala, szary, xLeft + 20, yTop + 250 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 1 * auto_szer, yTop + 250 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_13"].ToString(), myFontMala, szary, xLeft + 1 * auto_szer + 10, yTop + 250 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 2 * auto_szer, yTop + 250 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_10"].ToString(), myFontMala, szary, xLeft + 2 * auto_szer + 10, yTop + 250 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 3 * auto_szer, yTop + 250 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_11"].ToString(), myFontMala, szary, xLeft + 3 * auto_szer + 10, yTop + 250 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 4 * auto_szer, yTop + 250 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_12"].ToString(), myFontMala, szary, xLeft + 4 * auto_szer + 10, yTop + 250 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 5 * auto_szer, yTop + 250 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_17"].ToString(), myFontMala, szary, xLeft + 5 * auto_szer + 10, yTop + 250 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 6 * auto_szer, yTop + 250 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_16"].ToString(), myFontMala, szary, xLeft + 6 * auto_szer + 10, yTop + 250 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 7 * auto_szer, yTop + 250 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_14"].ToString(), myFontMala, szary, xLeft + 7 * auto_szer + 10, yTop + 250 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 8 * auto_szer, yTop + 250 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_15"].ToString(), myFontMala, szary, xLeft + 8 * auto_szer + 10, yTop + 250 + (16 * index) + 1); e.Graphics.DrawRectangle(myPenCzarny, xLeft + 9 * auto_szer, yTop + 250 + (16 * index), auto_szer, 16); e.Graphics.DrawString(dataReader["TSD_VAL_03"].ToString(), myFontMala, szary, xLeft + 9 * auto_szer + 10, yTop + 250 + (16 * index) + 1); index++; } mySqlFunctions.CloseConnection(); } e.Graphics.DrawString("Prowadzący: " + prowadzacy_value, myFontMala, czarny, xLeft, yTop + 250 + (16 * index) + 20); e.Graphics.DrawString("Oddział: " + klient_value, myFontMala, czarny, xLeft, yTop + 250 + (16 * index) + 40); e.Graphics.DrawString("Zlecenie: " + zlecenie_value, myFontMala, czarny, xLeft, yTop + 250 + (16 * index) + 60); e.Graphics.DrawString("Uwagi", myFontCur, czarny, xLeft, yTop + 250 + (16 * index) + 90); e.Graphics.DrawString(uwagi_value, myFontMala, czarny, xLeft, yTop + 250 + (16 * index) + 110); } private void PrintCharts(PrintPageEventArgs e, int pump_id) { int qMax = mySqlFunctions.getQmaxforPumpID(pump_id); //int hMax = mySqlFunctions.getHmaxforPumpID(pump_id); int hMax = mySqlFunctions.getScaledMaxForPumpAndTestWithRegression(pump_id, spm_test_id); int pMax = mySqlFunctions.getPmaxforTestID(spm_test_id); // ======================================================================== // this.chartH = new System.Windows.Forms.DataVisualization.Charting.Chart(); Rectangle marginBoundsH = new Rectangle(xLeft, yTop + 180, printWidth, 280); this.chartP = new System.Windows.Forms.DataVisualization.Charting.Chart(); Rectangle marginBoundsP = new Rectangle(xLeft, yTop + 460, printWidth, 280); this.chartETA = new System.Windows.Forms.DataVisualization.Charting.Chart(); Rectangle marginBoundsETA = new Rectangle(xLeft, yTop + 740, printWidth, 280); // ======================================================================== // ((System.ComponentModel.ISupportInitialize)(this.chartH)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.chartP)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.chartETA)).BeginInit(); // ======================================================================== // //skaluje wykres w zależności od Qn pompy if (qn_value < 1.5) qMax = qMax / 4; else if (qn_value >= 1.5 && qn_value < 2) qMax = qMax / 2; setChartAreasAndScale(chartH, "H", qMax, "Q [m3/min]", hMax, "H [m]"); setSeriesBubble(chartH, "H", 1); drawCatalougeSplineForPump(chartH, pump_id, qMax); setChartAreasAndScale(chartP, "P", qMax, "Q [m3/min]", pMax, "P [kW]"); setSeriesBubble(chartP, "P", 1); setChartAreasAndScale(chartETA, "ETA", qMax, "Q [m3/min]", 1, "ƞA"); setSeriesBubble(chartETA, "ETA", 1); // ======================================================================== // int index = 1; mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select TSD_VAL_04,TSD_VAL_08,TSD_VAL_14,TSD_VAL_18 from tst_test_details where TSD_TST_ID=" + spm_test_id + " order by TSD_VAL_04", mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { double val04 = 0.0; if (double.TryParse(dataReader["TSD_VAL_04"].ToString(), out double tmpVal)) { val04 = Math.Round(tmpVal / 60.0, 3); // dzielimy przez 60 i zaokrąglamy do 3 miejsc } dataGridViewTabPages01.Rows.Add( index, val04, dataReader["TSD_VAL_08"], dataReader["TSD_VAL_14"], dataReader["TSD_VAL_18"] ); index++; //addBubblePoint(chartH, "H", Convert.ToDouble(dataReader["TSD_VAL_04"]), Convert.ToDouble(dataReader["TSD_VAL_08"])); //addBubblePoint(chartP, "P", Convert.ToDouble(dataReader["TSD_VAL_04"]), Convert.ToDouble(dataReader["TSD_VAL_14"])); //addBubblePoint(chartETA, "ETA", Convert.ToDouble(dataReader["TSD_VAL_04"]), Convert.ToDouble(dataReader["TSD_VAL_18"])); addBubblePoint(chartH, "H", val04, Convert.ToDouble(dataReader["TSD_VAL_08"])); addBubblePoint(chartP, "P", val04, Convert.ToDouble(dataReader["TSD_VAL_14"])); addBubblePoint(chartETA, "ETA", val04, Convert.ToDouble(dataReader["TSD_VAL_18"])); } dataReader.Close(); mySqlFunctions.CloseConnection(); } // ======================================================================== // setSeriesSpline(chartH, "H"); double qMax_converted = qMax / 60.0; double upperLimit = Math.Max((hMax / 60), (qMax / 60.0)); double step = Math.Max(Math.Round(upperLimit / 200.0, 6), 0.0005); //for (double q = 0; q <= qMax_converted; q += 0.1) for (double q = 0; q <= upperLimit; q += step) { double yVal = GetPolynomialValue(spm_test_id, "TSD_VAL_04", "TSD_VAL_08", q * 60.0); if (!double.IsNaN(yVal)) addSplinePointMP(chartH, "H", Math.Round(q, 3), yVal); } // ======================================================================== // setSeriesSpline(chartP, "P"); //for (double q = 0; q <= qMax_converted; q += 0.1) for (double q = 0; q <= upperLimit; q += step) { double yVal = GetPolynomialValue(spm_test_id, "TSD_VAL_04", "TSD_VAL_14", q * 60.0); if (!double.IsNaN(yVal)) addSplinePointMP(chartP, "P", Math.Round(q, 3), yVal); } // ======================================================================== // setSeriesSpline(chartETA, "ETA"); //for (double q = 0; q <= qMax_converted; q += 0.1) for (double q = 0; q <= upperLimit; q += step) { double yVal = GetPolynomialValue(spm_test_id, "TSD_VAL_04", "TSD_VAL_18", q * 60.0); if (!double.IsNaN(yVal)) addSplinePointMP(chartETA, "ETA", Math.Round(q, 3), yVal); } // ======================================================================== // chartH.Printing.PrintPaint(e.Graphics, marginBoundsH); chartP.Printing.PrintPaint(e.Graphics, marginBoundsP); chartETA.Printing.PrintPaint(e.Graphics, marginBoundsETA); ((System.ComponentModel.ISupportInitialize)(this.chartH)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.chartP)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.chartETA)).EndInit(); // ======================================================================== // } // ======================================================================== // private void setChartAreasAndScale(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, int x_scope, string x_name, int y_scope, string y_name) { // Przeliczamy zakres X z sekund na minuty (lub inne jednostki, jeśli tak interpretujesz) double x_scope_converted = Math.Round(x_scope / 60.0, 3); // dzielenie przez 60 i zaokrąglenie do 3 miejsc po przecinku chartType.ChartAreas.Clear(); chartType.ChartAreas.Add(name); // Ustawienia osi X po przeliczeniu chartType.ChartAreas[name].AxisX.Minimum = 0; chartType.ChartAreas[name].AxisX.Maximum = x_scope_converted; chartType.ChartAreas[name].AxisX.Interval = x_scope_converted / 10.0; // Ustawienia osi Y bez zmian chartType.ChartAreas[name].AxisY.Minimum = 0; chartType.ChartAreas[name].AxisY.Maximum = y_scope; chartType.ChartAreas[name].AxisY.Interval = y_scope / 5.0; // Opisy osi chartType.ChartAreas[name].AxisX.Title = x_name; chartType.ChartAreas[name].AxisY.Title = y_name; // Styl opisów chartType.ChartAreas[name].AxisX.LabelStyle.Font = new Font("Tahoma", 7); chartType.ChartAreas[name].AxisY.LabelStyle.Font = new Font("Tahoma", 7); // (opcjonalne) jeśli chcesz dodać orientację / wyrównanie tytułu: // chartType.ChartAreas[name].AxisX.TitleAlignment = StringAlignment.Far; // chartType.ChartAreas[name].AxisX.TextOrientation = System.Windows.Forms.DataVisualization.Charting.TextOrientation.Horizontal; } // ======================================================================== // private void setSeriesBubble(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, int boolSize) { chartType.Series.Clear(); chartType.Series.Add(name + "_B"); chartType.Series[name + "_B"].Color = Color.Blue; chartType.Series[name + "_B"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; chartType.Series[name + "_B"].MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle; chartType.Series[name + "_B"]["BubbleMaxSize"] = boolSize.ToString(); //chartType.Series[name + "_B"].Points.AddXY(-1, -1); } // ======================================================================== // private void setSeriesSpline(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name) { chartType.Series.Add(name + "_S"); chartType.Series[name + "_S"].Color = Color.Blue; chartType.Series[name + "_S"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; //chartType.Series[name + "_S"].Points.AddXY(-1, -1); } // ======================================================================== // private void addBubblePoint(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, double x, double y) { chartType.Series[name + "_B"].Points.AddXY(x, y); } // ======================================================================== // private void addSplinePoint(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, double x, double y) { chartType.Series[name + "_S"].Points.AddXY(x, y); } // ======================================================================== // //funkcja wykreśla krzywą katalogową dla wybranej pompy // ======================================================================== // private void drawCatalougeSplineForPump(System.Windows.Forms.DataVisualization.Charting.Chart chartType, int pump_id, int x_scope) { //Przeliczenie zakresu osi X z m3/h na m3/min double x_scope_converted = Math.Round(x_scope / 60.0, 3); //Pobranie maksymalnego przepływu z bazy (m3/h → m3/min) int q_max_h = mySqlFunctions.sqlIntValue( "SELECT MAX(PEP_X_PARAM) FROM seg_pump_eng_param WHERE PEP_PUP_ID=" + pump_id); double q_max = Math.Round(q_max_h / 60.0, 3); chartType.Series.Add("catalouge"); chartType.Series["catalouge"].Color = Color.FromArgb(255, 120, 120, 120); chartType.Series["catalouge"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; /* double upperLimit = Math.Max(q_max, x_scope_converted); for (double q = 0; q <= upperLimit; q += 0.1) { double h_val = GetPumpPolynomialValue(pump_id, q); // wyliczenie H dla Q [m3/min] if (!double.IsNaN(h_val)) chartType.Series["catalouge"].Points.AddXY(Math.Round(q, 3), h_val); } */ // 4️ Górny limit i DYNAMICZNY KROK (klucz do małych pomp) double upperLimit = Math.Max(q_max, x_scope_converted); // ~200 punktów na całą szerokość, ale nie mniej niż 0.0005 m3/min double step = Math.Max(Math.Round(upperLimit / 200.0, 6), 0.0005); for (double q = 0; q <= upperLimit; q += step) { double h_val = GetPumpPolynomialValue(pump_id, q); // Q w m3/min (bez zmian) if (!double.IsNaN(h_val)) chartType.Series["catalouge"].Points.AddXY(Math.Round(q, 4), h_val); } //Krzyż tolerancji – przeliczenie Qn z m3/h → m3/min double qn_value_min = Math.Round((qn_value / 60.0) - ((qn_value / 60.0) * 0.08), 3); double qn_value_max = Math.Round((qn_value / 60.0) + ((qn_value / 60.0) * 0.08), 3); double qn_value_mid = Math.Round(qn_value / 60.0, 3); //Obliczenie wysokości podnoszenia (Hn) z funkcji regresji double hn_value_calc = GetPumpPolynomialValue(pump_id, qn_value_mid); // Krzyż tolerancji // 🔹 linia pozioma (stałe H, zmienne Q) chartType.Series.Add("lineHorizontal"); chartType.Series["lineHorizontal"].Color = Color.Green; chartType.Series["lineHorizontal"].BorderWidth = 3; chartType.Series["lineHorizontal"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; chartType.Series["lineHorizontal"].Points.AddXY(qn_value_min, hn_value_calc); chartType.Series["lineHorizontal"].Points.AddXY(qn_value_max, hn_value_calc); // 🔹 linia pionowa (stałe Q, zmienne H) chartType.Series.Add("lineVertical"); chartType.Series["lineVertical"].Color = Color.Green; chartType.Series["lineVertical"].BorderWidth = 3; chartType.Series["lineVertical"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; chartType.Series["lineVertical"].Points.AddXY(qn_value_mid, hn_value_calc - (hn_value_calc * 0.07)); chartType.Series["lineVertical"].Points.AddXY(qn_value_mid, hn_value_calc + (hn_value_calc * 0.05)); } // ======================================================================== // PaperSize paperSize = new PaperSize("papersize", 807, 1150);//set the paper size int totalPages = 0;//this is for total number of items of the list or array private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { LoadPageSize(e); PrintHeader(e, currentPrintPage); PrintFooter(e, currentPrintPage); switch (currentPrintPage) { case 1: PrintPumpData(e, spm_test_id); e.HasMorePages = true; currentPrintPage++; break; case 2: PrintMotorData(e, spm_test_id); e.HasMorePages = true; currentPrintPage++; break; case 3: int ilPomiarow = mySqlFunctions.sqlIntValue("select count(1) from tst_test_details where TSD_TST_ID=" + spm_test_id.ToString()); if (ilPomiarow > 0) PrintCharts(e, pupm_id_value); e.HasMorePages = false; currentPrintPage = 1; // reset na koniec wydruku break; default: e.HasMorePages = false; currentPrintPage = 1; break; } } private void LoadTabPages00(int tst_id) { labelTypPompy.Text = "Typ Pompy:"; labelValTypPompy.Text = typ_popmy_value; labelNrPompy.Text = "Nr Pompy:"; labelValNrPompy.Text = sn_popmy_value; labelTypSilnika.Text = "Typ Silnika"; labelValTypSilnika.Text = typ_silnika_value; labelNrSilnika.Text = "Nr Silnika"; labelValNrSilnika.Text = sn_silnika_value; groupBox1.Text = "Dane nominalne pompy"; groupBox2.Text = "Dane nominalne silnika"; labelQn.Text = convertDataFromSerial.ConvertToM3PerMin(qn_value).ToString(); labelQmin.Text = convertDataFromSerial.ConvertToM3PerMin(qmin_value).ToString(); labelQmax.Text = convertDataFromSerial.ConvertToM3PerMin(qmax_value).ToString().ToString(); labelHn.Text = hn_value.ToString(); labelHmin.Text = hmin_value.ToString(); labelHmax.Text = hmax_value.ToString(); labelETA.Text = eta_value.ToString(); labelValMoc.Text =moc_value.ToString(); labelValNapiecie.Text =nap_value.ToString(); labelValPrad.Text =prad_value.ToString(); labelValObroty.Text =obrot_value.ToString(); labelValSprawnosc.Text =spraw_sil_value.ToString(); labelValWspMocy.Text = wsp_mocy.ToString(); labelValCzestotliwosc.Text = "50"; labelValRizZimny.Text = stan_izol_zimny.ToString(); labelValRicCieply.Text = stan_izol_cieply.ToString(); } private void LoadTabPages01(int tst_id) { //dataGridViewTabPages01 dataGridViewTabPages01.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewTabPages01.ColumnCount = 8; dataGridViewTabPages01.Columns[0].Name = "Lp."; dataGridViewTabPages01.Columns[1].Name = "Wydajność Q [m3/min]"; dataGridViewTabPages01.Columns[2].Name = "Ciśnienie p [m]"; dataGridViewTabPages01.Columns[3].Name = "Człon dyn. [m]"; dataGridViewTabPages01.Columns[4].Name = "Człon geo Z [m]"; dataGridViewTabPages01.Columns[5].Name = "Podnoszenie H [m]"; dataGridViewTabPages01.Columns[6].Name = "Moc oddana Pp [kW]"; dataGridViewTabPages01.Columns[7].Name = "Sprawność ƞA"; dataGridViewTabPages01.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGridViewTabPages01.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages01.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages01.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages01.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages01.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages01.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages01.Columns[7].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; int index=1; mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from tst_test_details where TSD_TST_ID=" + tst_id + " order by TSD_VAL_04", mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { double val04 = 0.0; if (double.TryParse(dataReader["TSD_VAL_04"].ToString(), out double tmpVal)) { val04 = Math.Round(tmpVal / 60.0, 3); // dzielimy przez 60 i zaokrąglamy do 3 miejsc } dataGridViewTabPages01.Rows.Add( index, val04, dataReader["TSD_VAL_05"], dataReader["TSD_VAL_07"], dataReader["TSD_VAL_01"], dataReader["TSD_VAL_08"], dataReader["TSD_VAL_09"], dataReader["TSD_VAL_18"] ); index++; addBubblePoint(chartTabH, "H", val04, Convert.ToDouble(dataReader["TSD_VAL_08"])); addBubblePoint(chartTabP, "P", val04, Convert.ToDouble(dataReader["TSD_VAL_14"])); addBubblePoint(chartTabETA, "ETA", val04, Convert.ToDouble(dataReader["TSD_VAL_18"])); } mySqlFunctions.CloseConnection(); } } private void LoadTabPages02(int tst_id) { //dataGridViewTabPages01 dataGridViewTabPages02.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewTabPages02.ColumnCount = 10; dataGridViewTabPages02.Columns[0].Name = "Lp."; dataGridViewTabPages02.Columns[1].Name = "Napięcie [U]"; dataGridViewTabPages02.Columns[2].Name = "IR [A]"; dataGridViewTabPages02.Columns[3].Name = "IS [A]"; dataGridViewTabPages02.Columns[4].Name = "IT [A]"; dataGridViewTabPages02.Columns[5].Name = "∆I [%]"; dataGridViewTabPages02.Columns[6].Name = "I [A]"; dataGridViewTabPages02.Columns[7].Name = "Moc pobrana [kW]"; dataGridViewTabPages02.Columns[8].Name = "cos φ"; dataGridViewTabPages02.Columns[9].Name = "Obroty"; dataGridViewTabPages02.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGridViewTabPages02.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages02.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages02.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages02.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages02.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages02.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages02.Columns[7].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages02.Columns[8].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewTabPages02.Columns[9].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; int index = 1; mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select TSD_VAL_13,TSD_VAL_10,TSD_VAL_11,TSD_VAL_12,TSD_VAL_17,TSD_VAL_16,TSD_VAL_14,TSD_VAL_15,TSD_VAL_03 from tst_test_details where TSD_TST_ID=" + tst_id + " order by TSD_MSR_STEP", mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { dataGridViewTabPages02.Rows.Add( index, dataReader["TSD_VAL_13"], dataReader["TSD_VAL_10"], dataReader["TSD_VAL_11"], dataReader["TSD_VAL_12"], dataReader["TSD_VAL_17"], dataReader["TSD_VAL_16"], dataReader["TSD_VAL_14"], dataReader["TSD_VAL_15"], dataReader["TSD_VAL_03"] ); index++; } dataReader.Close(); mySqlFunctions.CloseConnection(); } } private void LoadTabPages03(int tst_id) { //chartTabH int qMax = mySqlFunctions.getQmaxforPumpID(pupm_id_value); //int hMax = mySqlFunctions.getHmaxforPumpID(pupm_id_value); int hMax = mySqlFunctions.getScaledMaxForPumpAndTestWithRegression(pupm_id_value, tst_id); int pMax = mySqlFunctions.getPmaxforTestID(tst_id); //skaluje wykres w zależności od Qn pompy if (qn_value < 1.5) qMax = qMax / 4; else if (qn_value >= 1.5 && qn_value < 2) qMax = qMax / 2; // Po wybraniu pompy buduje skale na wykresach i przygotowuje serie. // ============================================================== // //setChartAreasAndScale4chartH(qMax, hMax); setChartAreasAndScale(chartTabH, "H", qMax, "Q [m3/min]", hMax, "H [m]"); setSeriesBubble(chartTabH, "H", 1); // ============================================================== // setChartAreasAndScale(chartTabP, "P", qMax, "Q [m3/min]", pMax, "P [kW]"); setSeriesBubble(chartTabP, "P", 1); // ============================================================== // setChartAreasAndScale(chartTabETA, "ETA", qMax, "Q [m3/min]", 1, "ƞA"); setSeriesBubble(chartTabETA, "ETA", 1); // ============================================================== // setBackgroundArea(chartTabH, "H", 30, qMax, hMax, qn_value); setBackgroundArea(chartTabP, "P", 30, qMax, pMax, qn_value); setBackgroundArea(chartTabETA, "ETA", 30, qMax, 1, qn_value); drawCatalougeSplineForPump(pupm_id_value, qMax); //tutaj // ============================================================== // setSeriesSplineMP(chartTabH, "H"); // setSeriesSpline(chartH, "H"); // qMax przeliczony z m³/h → m³/min double qMax_converted = qMax / 60.0; double upperLimit = Math.Max((hMax / 60), (qMax / 60.0)); double step = Math.Max(Math.Round(upperLimit / 200.0, 6), 0.0005); // Iteracja po przepływach w jednostkach m³/min //for (double q = 0; q <= qMax_converted; q += 0.1) for (double q = 0; q <= upperLimit; q += step) { // Wyliczamy Y (TSD_VAL_08) dla danego przepływu Q w m³/min // UWAGA: do funkcji przekazujemy q * 60, ponieważ dane w bazie są w m³/h! double yVal = GetPolynomialValue(spm_test_id, "TSD_VAL_04", "TSD_VAL_08", q * 60.0); if (!double.IsNaN(yVal)) addSplinePointMP(chartTabH, "H", Math.Round(q, 3), yVal); } // ============================================================== // setSeriesSplineMP(chartTabP, "P"); //for (double q = 0; q <= qMax_converted; q += 0.1) for (double q = 0; q <= upperLimit; q += step) { double yVal = GetPolynomialValue(spm_test_id, "TSD_VAL_04", "TSD_VAL_14", q * 60.0); if (!double.IsNaN(yVal)) addSplinePointMP(chartTabP, "P", Math.Round(q, 3), yVal); } // ============================================================== // setSeriesSplineMP(chartTabETA, "ETA"); //for (double q = 0; q <= qMax_converted; q += 0.1) for (double q = 0; q <= upperLimit; q += step) { double yVal = GetPolynomialValue(spm_test_id, "TSD_VAL_04", "TSD_VAL_18", q * 60.0); if (!double.IsNaN(yVal)) addSplinePointMP(chartTabETA, "ETA", Math.Round(q, 3), yVal); } } // ======================================================================== // private void setChartAreasAndScaleMP(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, int x_scope, string x_name, int y_scope, string y_name) { chartType.ChartAreas.Clear(); chartType.ChartAreas.Add(name); chartType.ChartAreas[name].AxisX.Minimum = 0; chartType.ChartAreas[name].AxisX.Maximum = x_scope; chartType.ChartAreas[name].AxisX.Interval = x_scope / 10; chartType.ChartAreas[name].AxisY.Minimum = 0; chartType.ChartAreas[name].AxisY.Maximum = y_scope; chartType.ChartAreas[name].AxisY.Interval = y_scope / 5; chartType.ChartAreas[name].AxisX.Title = x_name; chartType.ChartAreas[name].AxisY.Title = y_name; chartType.ChartAreas[name].AxisX.LabelStyle.Font = new Font("Tahoma", 7); chartType.ChartAreas[name].AxisY.LabelStyle.Font = new Font("Tahoma", 7); //chartH.ChartAreas["H"].AxisX.TitleAlignment = StringAlignment.Far; //chartH.ChartAreas["H"].AxisX.TextOrientation = System.Windows.Forms.DataVisualization.Charting.TextOrientation.Horizontal; } // ======================================================================== // private void setSeriesBubbleMP(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, int boolSize) { chartType.Series.Clear(); chartType.Series.Add(name + "_B"); chartType.Series[name + "_B"].Color = Color.Blue; chartType.Series[name + "_B"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; chartType.Series[name + "_B"].MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle; chartType.Series[name + "_B"]["BubbleMaxSize"] = boolSize.ToString(); //chartType.Series[name + "_B"].Points.AddXY(-1, -1); } // ======================================================================== // private void setSeriesSplineMP(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name) { chartType.Series.Add(name + "_S"); chartType.Series[name + "_S"].Color = Color.Red; chartType.Series[name + "_S"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; //chartType.Series[name + "_S"].Points.AddXY(-1, -1); } // ======================================================================== // private void addBubblePointMP(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, double x, double y) { chartType.Series[name + "_B"].Points.AddXY(x, y); } // ======================================================================== // private void addSplinePointMP(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, double x, double y) { chartType.Series[name + "_S"].Points.AddXY(x, y); } // ======================================================================== // //funkcja rysuje podkład pod wykresy // ======================================================================== // private void setBackgroundArea(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, int alfa_color, int x_scope, int y_scope, double qn) { // Przeliczamy qn oraz x_scope z sekund na minuty (zaokrąglone do 3 miejsc) double qn_converted = Math.Round(qn / 60.0, 3); double x_scope_converted = Math.Round(x_scope / 60.0, 3); // BG1 – czerwona strefa chartType.Series.Add(name + "_BG1"); chartType.Series[name + "_BG1"].Color = Color.FromArgb(alfa_color, 255, 0, 0); chartType.Series[name + "_BG1"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; chartType.Series[name + "_BG1"].Points.AddXY(0, y_scope); chartType.Series[name + "_BG1"].Points.AddXY(0.55 * qn_converted, y_scope); // BG2 – żółta strefa chartType.Series.Add(name + "_BG2"); chartType.Series[name + "_BG2"].Color = Color.FromArgb(alfa_color, 255, 255, 0); chartType.Series[name + "_BG2"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; chartType.Series[name + "_BG2"].Points.AddXY(0.55 * qn_converted, y_scope); chartType.Series[name + "_BG2"].Points.AddXY(0.7 * qn_converted, y_scope); // BG3 – zielona strefa chartType.Series.Add(name + "_BG3"); chartType.Series[name + "_BG3"].Color = Color.FromArgb(alfa_color, 0, 255, 0); chartType.Series[name + "_BG3"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; chartType.Series[name + "_BG3"].Points.AddXY(0.7 * qn_converted, y_scope); chartType.Series[name + "_BG3"].Points.AddXY(1.22 * qn_converted, y_scope); // BG4 – żółta strefa chartType.Series.Add(name + "_BG4"); chartType.Series[name + "_BG4"].Color = Color.FromArgb(alfa_color, 255, 255, 0); chartType.Series[name + "_BG4"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; chartType.Series[name + "_BG4"].Points.AddXY(1.22 * qn_converted, y_scope); chartType.Series[name + "_BG4"].Points.AddXY(1.35 * qn_converted, y_scope); // BG5 – czerwona strefa chartType.Series.Add(name + "_BG5"); chartType.Series[name + "_BG5"].Color = Color.FromArgb(alfa_color, 255, 0, 0); chartType.Series[name + "_BG5"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; chartType.Series[name + "_BG5"].Points.AddXY(1.35 * qn_converted, y_scope); chartType.Series[name + "_BG5"].Points.AddXY(x_scope_converted, y_scope); } // ======================================================================== // //funkcja wykreśla krzywą katalogową dla wybranej pompy private void drawCatalougeSplineForPump(int pump_id, int x_scope) { // 1️⃣ Przeliczenie zakresu osi X z m3/h na m3/min double x_scope_converted = Math.Round(x_scope / 60.0, 3); // 2️⃣ Pobranie maksymalnego przepływu z bazy (m3/h → m3/min) int q_max_h = mySqlFunctions.sqlIntValue( "SELECT MAX(PEP_X_PARAM) FROM seg_pump_eng_param WHERE PEP_PUP_ID=" + pump_id); double q_max = Math.Round(q_max_h / 60.0, 3); // 3️⃣ Dodanie serii dla charakterystyki katalogowej chartTabH.Series.Add("catalouge"); chartTabH.Series["catalouge"].Color = Color.FromArgb(255, 120, 120, 120); chartTabH.Series["catalouge"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; /* // 4️⃣ Generowanie punktów charakterystyki pompy do końca skali X // (nie tylko do q_max, ale aż do x_scope_converted) double upperLimit = Math.Max(q_max, x_scope_converted); for (double q = 0; q <= upperLimit; q += 0.1) { double h_val = GetPumpPolynomialValue(pump_id, q); // wyliczenie H dla Q [m3/min] if (!double.IsNaN(h_val)) chartTabH.Series["catalouge"].Points.AddXY(Math.Round(q, 3), h_val); } */ // 4️ Górny limit i DYNAMICZNY KROK (klucz do małych pomp) double upperLimit = Math.Max(q_max, x_scope_converted); // ~200 punktów na całą szerokość, ale nie mniej niż 0.0005 m3/min double step = Math.Max(Math.Round(upperLimit / 200.0, 6), 0.0005); for (double q = 0; q <= upperLimit; q += step) { double h_val = GetPumpPolynomialValue(pump_id, q); // Q w m3/min (bez zmian) if (!double.IsNaN(h_val)) chartTabH.Series["catalouge"].Points.AddXY(Math.Round(q, 4), h_val); } // 5️⃣ Krzyż tolerancji – przeliczenie Qn z m3/h → m3/min double qn_value_min = Math.Round((qn_value / 60.0) - ((qn_value / 60.0) * 0.08), 3); double qn_value_max = Math.Round((qn_value / 60.0) + ((qn_value / 60.0) * 0.08), 3); double qn_value_mid = Math.Round(qn_value / 60.0, 3); // 6️⃣ Obliczenie wysokości podnoszenia (Hn) z funkcji regresji double hn_value_calc = GetPumpPolynomialValue(pump_id, qn_value_mid); // 🔹 linia pozioma (stałe H, zmienne Q) chartTabH.Series.Add("lineHorizontal"); chartTabH.Series["lineHorizontal"].Color = Color.Green; chartTabH.Series["lineHorizontal"].BorderWidth = 3; chartTabH.Series["lineHorizontal"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; chartTabH.Series["lineHorizontal"].Points.AddXY(qn_value_min, hn_value_calc); chartTabH.Series["lineHorizontal"].Points.AddXY(qn_value_max, hn_value_calc); // 🔹 linia pionowa (stałe Q, zmienne H) chartTabH.Series.Add("lineVertical"); chartTabH.Series["lineVertical"].Color = Color.Green; chartTabH.Series["lineVertical"].BorderWidth = 3; chartTabH.Series["lineVertical"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; chartTabH.Series["lineVertical"].Points.AddXY(qn_value_mid, hn_value_calc - (hn_value_calc * 0.07)); chartTabH.Series["lineVertical"].Points.AddXY(qn_value_mid, hn_value_calc + (hn_value_calc * 0.05)); } // ======================================================================== // private string getRegresionModel(int numer_proby, string wykres, int reg_val) { string model = ""; string query = ""; List x = new List(); List y = new List(); if (string.Compare(wykres, "H", true) == 0) query = "select TSD_VAL_04 X,TSD_VAL_08 Y from tst_test_details where TSD_TST_ID=" + numer_proby + " order by TSD_MSR_STEP"; else if (string.Compare(wykres, "P", true) == 0) query = "select TSD_VAL_04 X,TSD_VAL_14 Y from tst_test_details where TSD_TST_ID=" + numer_proby + " order by TSD_MSR_STEP"; else if (string.Compare(wykres, "ETA", true) == 0) query = "select TSD_VAL_04 X,TSD_VAL_18 Y from tst_test_details where TSD_TST_ID=" + numer_proby + " order by TSD_MSR_STEP"; mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { // Ładuje listę kroków MySql.Data.MySqlClient.MySqlCommand _cmd = new MySql.Data.MySqlClient.MySqlCommand(query, mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader _dataReader = _cmd.ExecuteReader(); while (_dataReader.Read()) { x.Add(Convert.ToDouble(_dataReader["X"].ToString().Replace(".", ","))); y.Add(Convert.ToDouble(_dataReader["Y"].ToString().Replace(".", ","))); } double[] x_wsp = x.ToArray(); double[] y_wsp = y.ToArray(); model = Accord.Statistics.Models.Regression.Linear.PolynomialRegression.FromData(reg_val, x_wsp, y_wsp).ToString(); _dataReader.Close(); mySqlFunctions.CloseConnection(); } else model = ""; //model = "y(x) = -0,000828746298910538x^3 + 0,053873107664072x^2 + -1,53702600032278x^1 + 54,8583955664353x^0"; return model; } private void buttonTestExport_Click(object sender, EventArgs e) { //Stream myStream; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "plik próby (*.spm)|*.spm"; saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); saveFileDialog1.FileName = tst_date.Replace("-","") + "_tst_" + spm_test_id.ToString(); saveFileDialog1.FilterIndex = 2; saveFileDialog1.RestoreDirectory = true; try { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { using (StreamWriter writer = new StreamWriter(saveFileDialog1.OpenFile())) { writer.WriteLine("##SOFTSPMTEST##"); writer.WriteLine("#NP#" + spm_test_id.ToString()); writer.WriteLine("#DP#" + tst_date); writer.WriteLine("#UP#" + prowadzacy_value); writer.WriteLine("#TPP#" + typ_popmy_value); writer.WriteLine("#SNP#" + sn_popmy_value); writer.WriteLine("#TPE#" + typ_silnika_value); writer.WriteLine("#SNE#" + sn_silnika_value); mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from tst_tests where TST_ID=" + spm_test_id.ToString(), mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { writer.WriteLine("#TST#" + dataReader[0].ToString() + "|" + dataReader[1].ToString() + "|" + dataReader[2].ToString() + "|" + dataReader[3].ToString() + "|" + dataReader[4].ToString() + "|" + dataReader[5].ToString() + "|" + dataReader[6].ToString() + "|" + dataReader[7].ToString() + "|" + dataReader[8].ToString() + "|" + dataReader[9].ToString() + "|" + dataReader[10].ToString() + "|" + dataReader[11].ToString() + "|" + dataReader[12].ToString() + "|" ); } dataReader.Close(); MySql.Data.MySqlClient.MySqlCommand cmd1 = new MySql.Data.MySqlClient.MySqlCommand("select * from tst_test_details where TSD_TST_ID=" + spm_test_id.ToString() + " order by TSD_MSR_STEP", mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader1 = cmd1.ExecuteReader(); while (dataReader1.Read()) { writer.WriteLine("#TSD#" + dataReader1[0].ToString() + "|" + dataReader1[1].ToString() + "|" + dataReader1[2].ToString() + "|" + dataReader1[3].ToString() + "|" + dataReader1[4].ToString() + "|" + dataReader1[5].ToString() + "|" + dataReader1[6].ToString() + "|" + dataReader1[7].ToString() + "|" + dataReader1[8].ToString() + "|" + dataReader1[9].ToString() + "|" + dataReader1[10].ToString() + "|" + dataReader1[11].ToString() + "|" + dataReader1[12].ToString() + "|" + dataReader1[13].ToString() + "|" + dataReader1[14].ToString() + "|" + dataReader1[15].ToString() + "|" + dataReader1[16].ToString() + "|" + dataReader1[17].ToString() + "|" + dataReader1[18].ToString() + "|" + dataReader1[19].ToString() + "|" + dataReader1[20].ToString() + "|" + dataReader1[21].ToString() + "|" + dataReader1[22].ToString() + "|" + dataReader1[23].ToString() + "|" + dataReader1[24].ToString() + "|" ); } dataReader1.Close(); } mySqlFunctions.CloseConnection(); writer.Close(); MessageBox.Show("Próba " + spm_test_id.ToString() + " została pomyślnie wyeksportowana do pliku " + saveFileDialog1.FileName.ToString()); } } } catch { } } private void buttonClose_Click(object sender, EventArgs e) { this.Close(); } // Komentarz / Uwagi private void LoadTabPages06(int tst_id) { string isReport = ""; mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from tst_test_notif where TNF_TST_ID=" + spm_test_id.ToString(), mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { textBoxKlient.Text = dataReader["TNF_CUSTOMER"].ToString(); textBoxZlecenie.Text = dataReader["TNF_COMMISION"].ToString(); richTextBoxUwagi.Text = dataReader["TNF_DESC"].ToString(); isReport = dataReader["TNF_ON_REPORT"].ToString(); } dataReader.Close(); mySqlFunctions.CloseConnection(); if (isReport.Length > 0) checkBoxNaProtokole.Checked = true; else checkBoxNaProtokole.Checked = false; } } private void updateDataForTabPages06(int tst_id) { //update if (mySqlFunctions.sqlIntValue("select count(1) ile from tst_test_notif where TNF_TST_ID="+ tst_id.ToString()) >0) { mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("UPDATE tst_test_notif SET TNF_CUSTOMER='"+ textBoxKlient.Text + "',TNF_COMMISION='"+ textBoxZlecenie.Text + "',TNF_DESC='"+ richTextBoxUwagi.Text + "',TNF_ON_REPORT='1' WHERE TNF_TST_ID=" + tst_id.ToString(), mySqlFunctions.connection); cmd.ExecuteNonQuery(); } mySqlFunctions.CloseConnection(); } //insert else { mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("INSERT INTO tst_test_notif SET TNF_TST_ID='"+ tst_id.ToString() + "',TNF_CUSTOMER='" + textBoxKlient.Text + "',TNF_COMMISION='" + textBoxZlecenie.Text + "',TNF_DESC='" + richTextBoxUwagi.Text + "',TNF_ON_REPORT='1'", mySqlFunctions.connection); cmd.ExecuteNonQuery(); } mySqlFunctions.CloseConnection(); } uwagi_value = richTextBoxUwagi.Text; klient_value = textBoxKlient.Text; zlecenie_value = textBoxZlecenie.Text; } private void textBoxKlient_Leave(object sender, EventArgs e) { updateDataForTabPages06(spm_test_id); } private void textBoxZlecenie_Leave(object sender, EventArgs e) { updateDataForTabPages06(spm_test_id); } private void richTextBoxUwagi_Leave(object sender, EventArgs e) { updateDataForTabPages06(spm_test_id); } public static double GetPolynomialValue(int id_proby, string xField, string yField, double q, int reg_val=3) { // Wynik końcowy double result = double.NaN; // Listy danych wejściowych List x = new List(); List y = new List(); mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { // Budujemy zapytanie SQL — zabezpieczone przed SQL injection (parametryzowane) string query = $"SELECT {xField}, {yField} FROM tst_test_details WHERE TSD_TST_ID = @id ORDER BY {xField}"; MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(query, mySqlFunctions.connection); cmd.Parameters.AddWithValue("@id", id_proby); MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if (double.TryParse(reader[xField].ToString(), out double xv) && double.TryParse(reader[yField].ToString(), out double yv)) { x.Add(xv); y.Add(yv); } } reader.Close(); // Sprawdzamy, czy są dane if (x.Count > 1 && y.Count > 1) { double[] xArr = x.ToArray(); double[] yArr = y.ToArray(); // Tworzymy model regresji wielomianowej var model = Accord.Statistics.Models.Regression.Linear.PolynomialRegression.FromData(reg_val, xArr, yArr); // Liczymy wartość dla punktu q result = model.Transform(q); } mySqlFunctions.CloseConnection(); } return result; } //m3/min public static double GetPumpPolynomialValue(int pump_id, double q, int reg_val = 3) { double result = double.NaN; List x = new List(); List y = new List(); mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { try { // --- 1️⃣ Pobierz punkty pomiarowe --- string query = @" SELECT (PEP_X_PARAM / 60.0) AS PEP_X_PARAM, PEP_Y_PARAM FROM seg_pump_eng_param WHERE PEP_PUP_ID = @pump_id AND PEP_TYPE = 'H' ORDER BY PEP_X_PARAM"; using (var cmd = new MySqlCommand(query, mySqlFunctions.connection)) { cmd.Parameters.AddWithValue("@pump_id", pump_id); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { if (double.TryParse(reader["PEP_X_PARAM"].ToString(), out double xv) && double.TryParse(reader["PEP_Y_PARAM"].ToString(), out double yv)) { x.Add(xv); y.Add(yv); } } } } // --- 2️⃣ Sprawdź, czy pierwszy punkt X jest bliski 0 --- if (x.Count > 0 && x[0] > 1.0) // brak punktu przy zerze { string hmaxQuery = "SELECT PUP_H_MAX FROM seg_pumps WHERE PUP_ID = @pump_id"; using (var hmaxCmd = new MySqlCommand(hmaxQuery, mySqlFunctions.connection)) { hmaxCmd.Parameters.AddWithValue("@pump_id", pump_id); object val = hmaxCmd.ExecuteScalar(); if (val != DBNull.Value && val != null) { double hmax = Convert.ToDouble(val); // --- Dodaj punkt (0, Hmax * (1 + 2–3%)) --- Random rnd = new Random(); double margin = rnd.Next(2, 4) / 100.0; // losowo 2–3 % double adjustedHmax = hmax * (1.0 + margin); x.Insert(0, 0.0); y.Insert(0, adjustedHmax); } } } // --- 3️⃣ Oblicz regresję --- if (x.Count > 1 && y.Count > 1) { double[] xArr = x.ToArray(); double[] yArr = y.ToArray(); var model = PolynomialRegression.FromData(reg_val, xArr, yArr); double pred = model.Transform(q); if (!double.IsNaN(pred) && !double.IsInfinity(pred)) result = pred; } } catch { // Ciche przechwycenie błędów – zwróci NaN, jeśli coś pójdzie nie tak } finally { mySqlFunctions.CloseConnection(); } } return result; } public static void DrawTextWithBold(Graphics g, float x, float y, Font baseFont, Brush brush, string text) { if (g == null || baseFont == null || brush == null || string.IsNullOrEmpty(text)) return; // Przygotuj font pogrubiony na bazie podstawowego using (Font boldFont = new Font(baseFont, FontStyle.Bold)) { float currentX = x; // Regex do wykrywania fragmentów ... var parts = Regex.Split(text, "(|)"); bool isBold = false; foreach (var part in parts) { if (string.IsNullOrEmpty(part)) continue; if (part == "") { isBold = true; continue; } else if (part == "") { isBold = false; continue; } // Wybierz odpowiedni font Font fontToUse = isBold ? boldFont : baseFont; // Narysuj fragment tekstu g.DrawString(part, fontToUse, brush, currentX, y); // Zmierz szerokość fragmentu i przesuń pozycję X SizeF size = g.MeasureString(part, fontToUse); currentX += size.Width; } } } } }