using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace StacjaProb { public partial class PumpStockChFromCatalogForm : Form { public PumpStockChFromCatalogForm() { InitializeComponent(); } // Ładuje stan pomp private void LoadCurrentPumpLists(string pumpName = null) { dataGridViewPumpLists.Rows.Clear(); dataGridViewPumpLists.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewPumpLists.ColumnCount = 7; dataGridViewPumpLists.Columns[0].Name = "id"; dataGridViewPumpLists.Columns[1].Name = "Typ pompy"; dataGridViewPumpLists.Columns[2].Name = "Qn [m3/h]"; dataGridViewPumpLists.Columns[3].Name = "Hn [m]"; dataGridViewPumpLists.Columns[4].Name = "Producent"; dataGridViewPumpLists.Columns[5].Name = "Eta"; dataGridViewPumpLists.Columns[6].Name = "Hmax"; dataGridViewPumpLists.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGridViewPumpLists.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewPumpLists.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewPumpLists.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewPumpLists.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewPumpLists.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewPumpLists.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from seg_pumps left join seg_manufacturers on MCF_ID=PUP_MCF_ID where LENGTH(PUP_NAME)>0 and PUP_Q_N>0 and PUP_H_MAX>0 and PUP_NAME like '%"+ pumpName + "%' order by PUP_NAME,PUP_Q_N", mySqlFunctions.connection); MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { dataGridViewPumpLists.Rows.Add( dataReader["PUP_ID"], dataReader["PUP_NAME"], dataReader["PUP_Q_N"], dataReader["PUP_H_P"], dataReader["MCF_NAME"], dataReader["PUP_ETA_MAX"], dataReader["PUP_H_MAX"] ); } dataGridViewPumpLists.Columns[6].Visible = false; } private void PumpStockChFromCatalogForm_Load(object sender, EventArgs e) { buttonWybierz.Enabled = false; mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { LoadCurrentPumpLists(); mySqlFunctions.CloseConnection(); } } private void dataGridViewPumpLists_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { int pumpID = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(this.dataGridViewPumpLists.CurrentRow.Cells[0].Value.ToString().Replace(".", ",")))); int q_nom = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(this.dataGridViewPumpLists.CurrentRow.Cells[2].Value.ToString().Replace(".", ",")))); int q_max = Convert.ToInt32(Math.Ceiling(1.6 * q_nom)); int h_max = Convert.ToInt32(1.6 * Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(this.dataGridViewPumpLists.CurrentRow.Cells[6].Value.ToString().Replace(".", ","))))); setChartAreasAndScale(chartH, "H", q_max, "Q [m3/h]", h_max, "H [m]"); setBackgroundArea(chartH, "H", 25, q_max, h_max, q_nom); setChartAreasAndScale(chartETA, "ETA", q_max, "Q [m3/h]", 1, "ƞ"); setBackgroundArea(chartETA, "ETA", 25, q_max, 1, q_nom); drawCatalougeSplineForPump(pumpID, q_max); buttonWybierz.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void setChartAreasAndScale(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); } private void setBackgroundArea(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, int alfa_color, int x_scope, int y_scope, double qn) { chartType.Series.Clear(); 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, y_scope); 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, y_scope); chartType.Series[name + "_BG2"].Points.AddXY(0.7 * qn, y_scope); 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, y_scope); chartType.Series[name + "_BG3"].Points.AddXY(1.22 * qn, y_scope); 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, y_scope); chartType.Series[name + "_BG4"].Points.AddXY(1.35 * qn, y_scope); 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, y_scope); chartType.Series[name + "_BG5"].Points.AddXY(x_scope, y_scope); } private void drawCatalougeSplineForPump(int pump_id, int q_max) { chartH.Series.Add("catalouge"); chartH.Series["catalouge"].Color = Color.FromArgb(255, 187, 0, 0); chartH.Series["catalouge"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chartETA.Series.Add("catalouge"); chartETA.Series["catalouge"].Color = Color.FromArgb(255, 187, 0, 0); chartETA.Series["catalouge"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; string x3modelH = mySqlFunctions.getPolyRegresionModel(pump_id, 3); string x3modelEta = mySqlFunctions.getPolyRegresionModel_ETA(pump_id, 3); for (int i = 0; i <= q_max; i++) { chartH.Series["catalouge"].Points.AddXY(i, convertDataFromSerial.setYparamFor3(x3modelH, i)); chartETA.Series["catalouge"].Points.AddXY(i, convertDataFromSerial.setYparamFor3(x3modelEta, i)); } } private void buttonWybierz_Click(object sender, EventArgs e) { PumpStockEditForm.newPumpID = Convert.ToInt32(this.dataGridViewPumpLists.CurrentRow.Cells[0].Value.ToString()); PumpStockEditForm.newPumpName = this.dataGridViewPumpLists.CurrentRow.Cells[1].Value.ToString(); this.Close(); } private void textBoxSearchPump_TextChanged(object sender, EventArgs e) { mySqlFunctions.initConnection(); if (mySqlFunctions.OpenConnection()) { LoadCurrentPumpLists(textBoxSearchPump.Text); mySqlFunctions.CloseConnection(); } } private void buttonClose_Click(object sender, EventArgs e) { this.Close(); } } }