Exemplo n.º 1
0
        private void MonitorPage_Load(object sender, EventArgs e)
        {
            this.BedValue.Text = "BED " + (bed.BedNumber + 1).ToString();
            this.Text          = bed.WardRef.Name + "- " + this.Text;
            //initialize arrays
            int nMonitors = bed.Monitors.Length;

            frames         = new GroupBox[nMonitors];
            dropdowns      = new ComboBox[nMonitors];
            values         = new Label[nMonitors];
            minLabels      = new Label[nMonitors];
            maxLabels      = new Label[nMonitors];
            minSelectors   = new NumericUpDown[nMonitors];
            maxSelectors   = new NumericUpDown[nMonitors];
            silenceButtons = new Button[nMonitors];
            // for each monitor
            for (int monitor = 0; monitor < nMonitors; monitor++)
            {
                // create design elements
                frames[monitor]         = new GroupBox();
                dropdowns[monitor]      = new ComboBox();
                values[monitor]         = new Label();
                minLabels[monitor]      = new Label();
                maxLabels[monitor]      = new Label();
                minSelectors[monitor]   = new NumericUpDown();
                maxSelectors[monitor]   = new NumericUpDown();
                silenceButtons[monitor] = new Button();
                // hide and disable silence buttons
                silenceButtons[monitor].Enabled = false;
                silenceButtons[monitor].Visible = false;
                // add controls to their containers
                MonitorPageFlowPanel.Controls.Add(frames[monitor]);
                frames[monitor].Controls.Add(dropdowns[monitor]);
                frames[monitor].Controls.Add(values[monitor]);
                frames[monitor].Controls.Add(minLabels[monitor]);
                frames[monitor].Controls.Add(maxLabels[monitor]);
                frames[monitor].Controls.Add(minSelectors[monitor]);
                frames[monitor].Controls.Add(maxSelectors[monitor]);
                frames[monitor].Controls.Add(silenceButtons[monitor]);
                // set names
                dropdowns[monitor].Name      = "Dropdown_" + monitor.ToString();
                minSelectors[monitor].Name   = "MinSel_" + monitor.ToString();
                maxSelectors[monitor].Name   = "MaxSel_" + monitor.ToString();
                silenceButtons[monitor].Name = "SilBut_" + monitor.ToString();
                // set static text
                values[monitor].Text         = "###";
                minLabels[monitor].Text      = "Alarms: Min";
                maxLabels[monitor].Text      = "Max";
                silenceButtons[monitor].Text = "Silence Alarm";
                // add options to dropdowns
                dropdowns[monitor].Items.AddRange(bed.GetPossibleMonitors());
                // set positions
                dropdowns[monitor].Location      = new System.Drawing.Point(70, 11);
                values[monitor].Location         = new System.Drawing.Point(5, 35);
                minLabels[monitor].Location      = new System.Drawing.Point(10, 100);
                maxLabels[monitor].Location      = new System.Drawing.Point(128, 100);
                minSelectors[monitor].Location   = new System.Drawing.Point(80, 98);
                maxSelectors[monitor].Location   = new System.Drawing.Point(156, 98);
                silenceButtons[monitor].Location = new System.Drawing.Point(170, 50);
                // set sizes
                frames[monitor].Size       = new System.Drawing.Size(250, 130);
                minLabels[monitor].Size    = new System.Drawing.Size(50, 13);
                maxLabels[monitor].Size    = new System.Drawing.Size(30, 13);
                values[monitor].Size       = new System.Drawing.Size(150, 55);
                values[monitor].AutoSize   = false;
                minSelectors[monitor].Size = new System.Drawing.Size(50, 20);
                maxSelectors[monitor].Size = new System.Drawing.Size(50, 20);
                // set fonts
                values[monitor].Font = new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                // set colours
                frames[monitor].BackColor = System.Drawing.Color.PowderBlue;
                // add events
                dropdowns[monitor].SelectedIndexChanged += new EventHandler(ChangeMonitor);
                minSelectors[monitor].ValueChanged      += new EventHandler(MonitorMinChanged);
                maxSelectors[monitor].ValueChanged      += new EventHandler(MonitorMaxChanged);
                silenceButtons[monitor].Click           += new EventHandler(SilenceAlarm);

                // set initial values
                if (!(bed.Monitors[monitor] is null))
                {
                    dropdowns[monitor].Text = bed.Monitors[monitor].Name;
                    SetValuesForMonitors(monitor);
                }

                // enable/disable register/deregister buttons
                string          staffid = SqlQueryExecutor.GetColumnValuesAsString("Staff", 0, "First_Name=\'" + LoginBackEnd.user + "\'")[0];
                DataSet         data    = SqlQueryExecutor.SelectAllFromTable("Staff_To_Notify_About_Beds", "(Ward_Id=" + bed.WardRef.Id + ") AND (Bay_Number=" + bed.BayID + ") AND (Bed_Number=" + bed.BedNumber + ") AND (Staff_Id=\'" + staffid + "\')");
                DataTableReader reader  = data.CreateDataReader();
                if (reader.Read())
                {
                    DeregisterButton.Enabled = true;
                    RegisterButton.Enabled   = false;
                }
                else
                {
                    DeregisterButton.Enabled = false;
                    RegisterButton.Enabled   = true;
                }
            }
        }