Exemplo n.º 1
0
        private async void create_btn_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            Animation.DropShadowOpacity(create_btn, 0.5, TimeSpan.FromMilliseconds(0));
            // TODO: save image with filename as ApplianceID then retrieve it when load
            double watt;
            byte   pin;

            if (!double.TryParse(ec_tb.Text, out watt))
            {
                MessageBox.Show("Please enter a valid wattage.");
                return;
            }
            if (!byte.TryParse(pin_tb.Text, out pin))
            {
                MessageBox.Show("Please enter a valid pin.");
                return;
            }
            else
            {
                if (pin < 1 || pin > 2)
                {
                    MessageBox.Show("The only available pins for this device are 1 and 2.");
                    return;
                }
                else
                {
                    if (await Globals.PinExists(pin))
                    {
                        MessageBox.Show("Pin is already in use.");
                        return;
                    }
                }
            }
            await Globals.AddAppliance(devname_tb.Text, devloc_tb.Text, devtype_tb.Text, watt, pin);

            var appID = await Globals.GetLastAppliance();

            main.Add_Appliances(appID.Rows[0][0].ToString(), devname_tb.Text, devloc_tb.Text, watt.ToString(), logo);
            this.Close();
        }