private void btnRemove_Click(object sender, RoutedEventArgs e)
 {
     applianceModel = new ApplianceViewModel();
     string applianceName = txtAppliance.Text;
     try
     {
         applianceModel.deleteEachAppliance(applianceName);
     }
     catch(Exception ex)
     {
         
     }
     
 }
 public ObservableCollection<ApplianceViewModel> getAllAppliances()
 {
     appliances = new ObservableCollection<ApplianceViewModel>();
     using (var db = new SQLite.SQLiteConnection(app.DBPath))
     {
         var query = db.Table<Appliance>();
         
             foreach(var _appliance in query)
             {
                 var appliance = new ApplianceViewModel()
                 {
                     ID = _appliance.ID,
                     APPLIANCE_NAME = _appliance.applianceName,
                     WATTS = _appliance.WATTS,
                     NUMBER_OF_ITEMS = _appliance.numberOfAppliances
                 };
                 appliances.Add(appliance);
             }
     }
     return appliances;
 }
Exemplo n.º 3
0
        public ObservableCollection <ApplianceViewModel> getAllAppliances()
        {
            appliances = new ObservableCollection <ApplianceViewModel>();
            using (var db = new SQLite.SQLiteConnection(app.DBPath))
            {
                var query = db.Table <Appliance>();

                foreach (var _appliance in query)
                {
                    var appliance = new ApplianceViewModel()
                    {
                        ID              = _appliance.ID,
                        APPLIANCE_NAME  = _appliance.applianceName,
                        WATTS           = _appliance.WATTS,
                        NUMBER_OF_ITEMS = _appliance.numberOfAppliances
                    };
                    appliances.Add(appliance);
                }
            }
            return(appliances);
        }
        private void btnAddAppliance_Click(object sender, RoutedEventArgs e)
        {

            try 
            { 
                applianceViewModel = new ApplianceViewModel(); 
                string name = txtApplianceName.Text;
                string strwatts = txtWatts.Text;
                string strnumber = txtNumberOfItems.Text;
                int watts = Convert.ToInt32(txtWatts.Text);
                int number = Convert.ToInt32(txtNumberOfItems.Text);
            if (!(name.Equals("")))
            {
                applianceViewModel.addAppliance(name, watts, number);
                messageBox("Appliance Has been Saved");
                this.Frame.Navigate(typeof(UnitsPage1));
            }
            else {
               messageBox("Error!!!! Please enter the name of the appliance");
            }
            }
            catch { messageBox("Error!!!! You have to enter the watts and the total number of appliance of that type"); }
        }
Exemplo n.º 5
0
 private void linkRemoveAppliances_Click(object sender, RoutedEventArgs e)
 {
     appliance = new ApplianceViewModel();
     appliance.deleteAllAppliances();
     messageBox("All Appliances Removed");
 }
Exemplo n.º 6
0
        private void DropAppliancesCommandhandler(IUICommand cmd)
        {
            HistoryViewModel myHistory = null;
            var lable = cmd.Label;
            myHistory = new HistoryViewModel();
            switch (lable)
            {
                case "Yes":

                    try
                    {
                        appliance = new ApplianceViewModel();
                        appliance.deleteAllAppliances();
                        //this.Frame.Navigate(typeof(MainPage));
                    }
                    catch (Exception ex)
                    {
                        //messageBox("error " + ex.Message);
                    }
                    break;
                case "Calcel":
                    break;
                

            }
        }
        private void btnCalculate_Click(object sender, RoutedEventArgs e)
        {
            meterView = new MeterViewModel();
            history = new HistoryViewModel();
            DateTime date = DateTime.Today;
            int day = date.Day;
            int month = date.Month;
            int year = date.Year;
            string myDate = day +"//"+ month +"//"+ year;

            applianceViewModel = new ApplianceViewModel();
            CURRENT_UNITS = Convert.ToDouble(txtCurrentUnits.Text);
            double total_units = 0;
            string appliance1 = txtAppliance1Hours.Text;
            string appliance2 = txtAppliance2Hours.Text;
            string appliance3 = txtAppliance3Hours.Text;
            string appliance4 = txtAppliance4Hours.Text;
            string appliance5 = txtAppliance5Hours.Text;
            try { 
            double first_appliance_hours = Convert.ToDouble(appliance1);
            double second_appliance_hours = Convert.ToDouble(appliance2);
            double third_appliance_hours = Convert.ToDouble(appliance3);
            double fourth_appliance_hours = Convert.ToDouble(appliance4);
            double fifth_appliance_hours = Convert.ToDouble(appliance5);

            double total_appliance_hours = first_appliance_hours + second_appliance_hours + third_appliance_hours + fourth_appliance_hours + fifth_appliance_hours;
            Kilo_Watts = (total_watts * total_appliance_hours) * tota_number;

            total_units = Kilo_Watts / 1000;
            REMAINING_UNITS += CURRENT_UNITS - total_units;
            string checkDate = date.ToString("D");
            history.saveHistory(tota_number, total_units, REMAINING_UNITS, checkDate);
            lblRemainingUnits.Text = "You have " + REMAINING_UNITS + " Units Remaining";
            meterView.updateMeterBoxUnits(total_units);
            txtCurrentUnits.Text = ""+REMAINING_UNITS;
            messageBox("Total consumed Units for selected appliances is : " + total_units + " units");
            }
            catch (Exception ex){
                messageBox("Please check your text fields or "+ex.Message);
            }

        }