namespace aplic_bin_v4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics zona_desen; System.Drawing.SolidBrush pens_rosie; System.Drawing.Font font_nina; int i, x0, y0, w, contor = 0, faza = 0; const int nri = 5; string[] numei = new string[] { "Incarcare acumulator electric", "Start", "Seringa detectata", "Senzor lichid", "Golire-completa"}; const int nractionari = 4; string[] numeout = new string[] { "Blocare seringa", "Injectare", "Ventil umplere seringa", "Alarma"}; bool[] leduri = new bool[nractionari]; private void Form1_Load(object sender, EventArgs e) { x0 = 300; y0 = 30; w = 15; for (i = nractionari - 1; i <= 0; i--) { leduri[i] = false; } this.checkBox1.Checked = false; this.checkBox1.Text = "0"; this.checkBox2.Checked = false; this.checkBox2.Text = "0"; this.checkBox3.Checked = false; this.checkBox3.Text = "0"; this.checkBox4.Checked = false; this.checkBox4.Text = "0"; this.checkBox5.Checked = false; this.checkBox5.Text = "0"; } private void Form1_Paint(object sender, PaintEventArgs e) { zona_desen = this.CreateGraphics(); pens_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red); font_nina = new System.Drawing.Font("Nina", 10); i = 0; int y = 45; for (i = 0; i < nri; i++) { zona_desen.DrawString(numei[i], font_nina, pens_rosie, 70, y); y += 37; } } private void timer1_Tick(object sender, EventArgs e) { afis_bin_bin_vw(zona_desen, x0, y0, w, nractionari, leduri, numeout); // Asteptare conditii de pornire if (faza == 0) { this.label1.Text = "Pentru utilizarea injectomatului - apasati Alimentare!"; if (this.checkBox2.Checked && !this.checkBox1.Checked) leduri[3] = true; if (this.checkBox1.Checked) { this.checkBox1.Text = "1"; this.label1.Text = "Pentru a incepe alimentarea - apasati Start!"; if (this.checkBox2.Checked) { this.checkBox2.Text = "1"; leduri[3] = false; this.label1.Text = "Astept detectarea seringii."; if (this.checkBox3.Checked) { this.checkBox3.Text = "1"; leduri[0] = false; this.label1.Text = "Seringa detectata."; faza = 1; // Se asteapta umplerea prin activarea contorului contor = 20; } } } } if(faza==1) // faza de umplere { this.label1.Text = "Se umple seringa"; leduri[0] = true; // Blocare seringa leduri[2] = true; // Pornire ventil umplere seringa if ((contor == 0) && (faza == 1)) { leduri[0] = false; // Delocare seringa leduri[2] = false; // Oprire ventil umplere seringa this.label1.Text = "Seringa cu solutie detectata. Injectarea poate incepe"; faza = 2; } } if (faza == 2) { this.label1.Text = "Astept senzor lichid"; if (this.checkBox4.Checked) { leduri[2] = true; // Pornire ventil umplere seringa this.label1.Text = "Injectare"; leduri[1] = true;// Injectare leduri[2] = false;// Deblocare seringa contor = 25; faza = 3; // injectare } } if (faza == 3) { if ((contor == 0)) { this.label1.Text = "Astept golire completa"; if (contor == 0) { faza = 4; contor = 15; } } } if (faza == 4) { if (this.checkBox5.Checked) { this.label1.Text = "Injectare terminata"; if (contor == 0) { leduri[0] = false; leduri[1] = false; leduri[2] = false; leduri[3] = false; this.checkBox1.Checked = false; this.checkBox1.Text = "0"; this.checkBox2.Checked = false; this.checkBox2.Text = "0"; this.checkBox3.Checked = false; this.checkBox3.Text = "0"; this.checkBox4.Checked = false; this.checkBox4.Text = "0"; this.checkBox5.Checked = false; this.checkBox5.Text = "0"; faza = 0;// se reia ciclul } } } if (contor > 0) contor--; this.label2.Text = contor.ToString(); this.label3.Text = "Faza: " + faza.ToString(); } private void afis_bin_bin_vw(Graphics desen, int px0, int py0, int bit_w, int nr_biti, bool[] vector_binar, string[] nume_biti) { System.Drawing.Pen creion; System.Drawing.SolidBrush pens_verde; System.Drawing.SolidBrush pens_rosie; System.Drawing.SolidBrush pens_gri; System.Drawing.Font font_nina; creion = new System.Drawing.Pen(System.Drawing.Color.Gray, 2); pens_verde = new System.Drawing.SolidBrush(System.Drawing.Color.Lime); pens_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red); pens_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray); font_nina = new System.Drawing.Font("Nina", 10); int x = px0 + bit_w; int y = py0 + bit_w; int i; for (i = nr_biti - 1; i >= 0; i--) { desen.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2); desen.DrawString(nume_biti[i].ToString(), font_nina, pens_rosie, x + 2 * bit_w, y); if (vector_binar[i]) desen.FillEllipse(pens_verde, x, y, bit_w, bit_w); else desen.FillEllipse(pens_gri, x, y, bit_w, bit_w); y += 2 * bit_w; } } } }