public FixtureSettings(LightingFixtureSettings settings, Window parent)
            : base(settings.name, settings.name.IsNotEmpty(), parent)
        {
            fixtureName = settings.name;

            var t = new SettingsTextBox("Name");

            t.textBox.text              = fixtureName.IsNotEmpty() ? fixtureName : "Enter name";
            t.textBox.TextChangedEvent += (sender, args) => {
                if (args.text.IsEmpty())
                {
                    args.keepText = false;
                }
                else if (Devices.Lighting.GadgetNameExists(args.text))
                {
                    MessageBox.Show("Heater name already exists");
                    args.keepText = false;
                }
            };
            AddSetting(t);

            var c = new SettingsComboBox("Outlet");

            if (fixtureName.IsNotEmpty())
            {
                var ic = settings.channel;
                c.combo.comboList.Add(string.Format("Current: {0}.p{1}", ic.Group, ic.Individual));
                c.combo.activeIndex = 0;
            }
            c.combo.nonActiveMessage = "Select outlet";
            c.combo.comboList.AddRange(Driver.Power.GetAllAvaiableChannels());
            AddSetting(c);

            var s = new SettingsSelectorSwitch("Temp Lockout");

            if (fixtureName.IsNotEmpty())
            {
                s.selectorSwitch.currentSelected = settings.highTempLockout ? 0 : 1;
            }
            AddSetting(s);

            bool isDimming = settings.dimmingChannel.IsNotEmpty();

            s = new SettingsSelectorSwitch("Dimming Fixture", "Yes", "No");
            s.selectorSwitch.currentSelected = isDimming ? 0 : 1;
            showOptional = isDimming;
            s.selectorSwitch.SelectorChangedEvent += (sender, args) => {
                if (args.currentSelectedIndex == 0)
                {
                    showOptional = true;
                }
                else
                {
                    showOptional = false;
                }
            };
            AddSetting(s);

            c = new SettingsComboBox("Dimming Channel");
            if (fixtureName.IsNotEmpty() && isDimming)
            {
                var ic = settings.dimmingChannel;
                c.combo.comboList.Add(string.Format("Current: {0}.q{1}", ic.Group, ic.Individual));
                c.combo.activeIndex = 0;
            }
            c.combo.nonActiveMessage = "Select outlet";
            c.combo.comboList.AddRange(Driver.AnalogOutput.GetAllAvaiableChannels());
            AddOptionalSetting(c);

            DrawSettings();
        }
        public WaterGroupSettings(WaterLevelGroupSettings settings, Window parent)
            : base(settings.name + " Water", settings.name.IsNotEmpty(), parent)
        {
            groupName = settings.name;

            var t = new SettingsTextBox("Name");

            t.textBox.text              = groupName.IsNotEmpty() ? groupName : "Enter name";
            t.textBox.TextChangedEvent += (sender, args) => {
                if (args.text.IsEmpty())
                {
                    args.keepText = false;
                }

                if (WaterLevel.WaterLevelGroupNameExists(args.text))
                {
                    MessageBox.Show("Water level group name already exists");
                    args.keepText = false;
                }
            };
            AddSetting(t);

            var b = new SettingsBlank("blank1");

            AddSetting(b);

            var s = new SettingsSelectorSwitch("Enable High Alarm");

            s.selectorSwitch.currentSelected = 1;
            if (groupName.IsNotEmpty())
            {
                s.selectorSwitch.currentSelected = settings.enableHighAnalogAlarm ? 0 : 1;
            }
            AddSetting(s);

            t = new SettingsTextBox("High Alarm");
            t.textBox.text = groupName.IsNotEmpty() ?
                             settings.highAnalogAlarmSetpoint.ToString() :
                             "0";
            t.textBox.TextChangedEvent += (sender, args) => {
                try {
                    float highAlarmStpnt = Convert.ToSingle(args.text);

                    if (highAlarmStpnt < 0f)
                    {
                        MessageBox.Show("High alarm setpoint can't be negative");
                        args.keepText = false;
                        return;
                    }
                } catch {
                    MessageBox.Show("Improper high alarm setpoint format");
                    args.keepText = false;
                }
            };
            AddSetting(t);

            s = new SettingsSelectorSwitch("Enable Low Alarm");
            s.selectorSwitch.currentSelected = 1;
            if (groupName.IsNotEmpty())
            {
                s.selectorSwitch.currentSelected = settings.enableLowAnalogAlarm ? 0 : 1;
            }
            AddSetting(s);

            t = new SettingsTextBox("Low Alarm");
            t.textBox.text = groupName.IsNotEmpty() ?
                             settings.lowAnalogAlarmSetpoint.ToString() :
                             "0";
            t.textBox.TextChangedEvent += (sender, args) => {
                try {
                    float lowAlarmStpnt = Convert.ToSingle(args.text);

                    if (lowAlarmStpnt < 0f)
                    {
                        MessageBox.Show("Low alarm setpoint can't be negative");
                        args.keepText = false;
                        return;
                    }
                } catch {
                    MessageBox.Show("Improper low alarm setpoint format");
                    args.keepText = false;
                }
            };
            AddSetting(t);

            DrawSettings();
        }
예제 #3
0
        public AtoSettings(AutoTopOffGroupSettings settings, Window parent)
            : base(settings.name + " Auto Top Off", settings.name.IsNotEmpty(), parent)
        {
            groupName = settings.name;

            var t = new SettingsTextBox("Name");

            t.textBox.text              = groupName.IsNotEmpty() ? groupName : "Enter name";
            t.textBox.TextChangedEvent += (sender, args) => {
                if (args.text.IsEmpty())
                {
                    args.keepText = false;
                }
                else if (!AutoTopOff.AtoGroupNameOk(args.text))
                {
                    MessageBox.Show("ATO group name already exists");
                    args.keepText = false;
                }
            };
            AddSetting(t);

            var s = new SettingsSelectorSwitch("Enable");

            if (groupName.IsNotEmpty())
            {
                s.selectorSwitch.currentSelected = settings.enable ? 0 : 1;
            }
            AddSetting(s);

            var c = new SettingsComboBox("Water Group");

            c.combo.nonActiveMessage = "Select Water Level Group";
            var availableGroups = WaterLevel.GetAllWaterLevelGroupNames();

            c.combo.comboList.AddRange(availableGroups);
            if (groupName.IsNotEmpty())
            {
                var index = Array.IndexOf(availableGroups, settings.waterLevelGroupName);
                c.combo.activeIndex = index;
            }
            AddSetting(c);

            t = new SettingsTextBox("Request Bit Name");
            t.textBox.text              = groupName.IsNotEmpty() ? settings.requestBitName : "Enter name";
            t.textBox.TextChangedEvent += (sender, args) => {
                if (args.text.IsEmpty())
                {
                    args.keepText = false;
                }
            };
            AddSetting(t);

            s = new SettingsSelectorSwitch("Use Analog");
            if (groupName.IsNotEmpty())
            {
                s.selectorSwitch.currentSelected = settings.useAnalogSensors ? 0 : 1;
            }
            AddSetting(s);

            t = new SettingsTextBox("Analog Off");
            t.textBox.text              = groupName.IsNotEmpty() ? settings.analogOffSetpoint.ToString() : "0";
            t.textBox.TextChangedEvent += (sender, args) => {
                try {
                    float offStpnt = Convert.ToSingle(args.text);

                    if (offStpnt < 0f)
                    {
                        MessageBox.Show("Analog on setpoint can't be negative");
                        args.keepText = false;
                        return;
                    }
                } catch {
                    MessageBox.Show("Improper analog off setpoint format");
                    args.keepText = false;
                }
            };
            AddSetting(t);

            t = new SettingsTextBox("Analog On");
            t.textBox.text              = groupName.IsNotEmpty() ? settings.analogOnSetpoint.ToString() : "0";
            t.textBox.TextChangedEvent += (sender, args) => {
                try {
                    float onStpnt = Convert.ToSingle(args.text);

                    if (onStpnt < 0f)
                    {
                        MessageBox.Show("Analog on setpoint can't be negative");
                        args.keepText = false;
                        return;
                    }
                } catch {
                    MessageBox.Show("Improper analog on setpoint format");
                    args.keepText = false;
                }
            };
            AddSetting(t);

            s = new SettingsSelectorSwitch("Use Float Switch");
            if (groupName.IsNotEmpty())
            {
                s.selectorSwitch.currentSelected = settings.useFloatSwitches ? 0 : 1;
            }
            AddSetting(s);

            t = new SettingsTextBox("Max Runtime");
            t.textBox.text = groupName.IsNotEmpty() ?
                             string.Format("{0} mins", settings.maximumRuntime) :
                             "1 min";
            t.textBox.TextChangedEvent += (sender, args) => {
                if (args.text.IsEmpty())
                {
                    args.keepText = false;
                }

                var time = ParseTime(args.text);
                if (time >= 0)
                {
                    args.text = string.Format("{0} mins", time);
                }
                else
                {
                    MessageBox.Show("Improper format");
                    args.keepText = false;
                }
            };
            AddSetting(t);

            t = new SettingsTextBox("Cooldown");
            t.textBox.text = groupName.IsNotEmpty() ?
                             string.Format("{0} mins", settings.minimumCooldown) :
                             "10 min";
            t.textBox.TextChangedEvent += (sender, args) => {
                if (args.text.IsEmpty())
                {
                    args.keepText = false;
                }

                var time = ParseTime(args.text);
                if (time >= 0)
                {
                    args.text = string.Format("{0} mins", time);
                }
                else
                {
                    MessageBox.Show("Improper format");
                    args.keepText = false;
                }
            };
            AddSetting(t);

            DrawSettings();
        }