private void btnClearHistory_Click(object sender, RoutedEventArgs e)
 {
     myHistory = new HistoryViewModel();
     try { 
         myHistory.clearHistory();
         messageBox("History has been cleared");
         this.Frame.Navigate(typeof(HistoryPage));
     }
     catch (Exception ex)
     {
         messageBox("error " + ex.Message);
     }
     
 }
Exemple #2
0
 public ObservableCollection <HistoryViewModel> getHistory()
 {
     history = new ObservableCollection <HistoryViewModel>();
     using (var db = new SQLite.SQLiteConnection(app.DBPath))
     {
         var query = db.Table <History>();
         foreach (var _history in query)
         {
             var histories = new HistoryViewModel()
             {
                 ID              = _history.ID,
                 USED_UNITS      = _history.used_watts,
                 REMAINING_UNITS = _history.remaining_watts,
                 DATE            = _history.date
             };
             history.Add(histories);
         }
     }
     return(history);
 }
        public ObservableCollection<HistoryViewModel> getHistory()
        {
            history = new ObservableCollection<HistoryViewModel>();
            using (var db = new SQLite.SQLiteConnection(app.DBPath))
            {
                var query = db.Table<History>();
                foreach(var _history in query)
                {
                    var histories = new HistoryViewModel()
                    {
                        ID = _history.ID,
                        USED_UNITS = _history.used_watts,
                        REMAINING_UNITS = _history.remaining_watts,
                        DATE = _history.date
                    };
                    history.Add(histories);
                }
            }
            return history;

        }
        private void Commandhandler(IUICommand cmd)
        {
            HistoryViewModel myHistory = null;
            var lable = cmd.Label;
            myHistory = new HistoryViewModel();
            switch (lable)
            {
                case "Yes":

                     try 
                     { 
                        string username = txtUserName.Text;
                        user = new UserViewModel();
                        if (user.verify(username) != null)
                        {
                            user.removeUser(username);

                            this.Frame.Navigate(typeof(MainPage1));
                        }
                       else if(user.verify(username) == null)
                        { 
                            lblDeleted.Text = "Username not found";
                        }
        
                }
                catch
                {

                    //messageBox("Error!!! cannot find user");
                }
                txtUserName.Text = "";
                    break;
                case "No":
                    break;

            }
        }
        private void Commandhandler(IUICommand cmd)
        {
            var lable = cmd.Label;
            myHistory = new HistoryViewModel();
            switch(lable)
            {
                case "Yes":
                    
                    try { 
                        myHistory.clearHistory();
                        //messageBox("History has been cleared");
                        this.Frame.Navigate(typeof(HistoryPage));
                    }
                    catch (Exception ex)
                    {
                        //messageBox("error " + ex.Message);
                    }
                    break;
                case "No":
                    break;

            }
        }
 private void linkDropHistory_Click(object sender, RoutedEventArgs e)
 {
     HistoryViewModel history = new HistoryViewModel();
     history.dropHistory();
     messageBox("success");
 }
        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 Commandhandler(IUICommand cmd)
        {
            HistoryViewModel myHistory = null;
            var lable = cmd.Label;
            myHistory = new HistoryViewModel();
            switch (lable)
            {
                case "Yes":

                    try
                    {
                        this.Frame.Navigate(typeof(MainPage1));
                    }
                    catch (Exception ex)
                    {
                        //messageBox("error " + ex.Message);
                    }
                    break;
                case "No":
                    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);
            }

        }