Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MXML 3.55 KB | None | 0 0
  1. using MobileClient.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Collections.Specialized;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Runtime.Serialization.Json;
  10. using Xamarin.Forms;
  11. using System.IO;
  12. using System.Runtime.Serialization;
  13.  
  14. namespace MobileClient
  15. {
  16.     public partial class MainPage : ContentPage
  17.     {
  18.         private CatClient catClient;
  19.  
  20.         public MainPage()
  21.         {
  22.             InitializeComponent();
  23.             catClient = new CatClient();
  24.  
  25.             BindingContext = catClient;
  26.             AllEmails.ItemsSource = catClient.emailList;
  27.             AllTimes.ItemsSource = catClient.timeList;
  28.  
  29.             catClient.timeList.Add(new TimeItem() { Time = "02:00" });
  30.             catClient.emailList.Add(new EmailItem() { Email = "AAA" });
  31.  
  32.             SendCommand("servo_auto ", "0");
  33.             SendCommand("settings_status", "");
  34.         }
  35.  
  36.         private void SendCommand(string command, string value)
  37.         {
  38.             try
  39.             {
  40.                 catClient.WriteMessage(command + value);
  41.             }
  42.             catch (Exception ex)
  43.             {
  44.                 DisplayAlert("Error", "Connection Error", "Continue");
  45.             }
  46.         }
  47.  
  48.         private void AddEmail_Clicked(object sender, EventArgs e)
  49.         {
  50.             if (EmailText.Text.Contains('@') && EmailText.Text.Contains('.') && EmailText.Text != null)
  51.            {
  52.                SendCommand("add_mail ", EmailText.Text);
  53.                 DisplayAlert("Success", "Email Added!", "Continue");
  54.             }
  55.             else
  56.             {
  57.                 DisplayAlert("Error", "Invalid Email Address", "Continue");
  58.             }
  59.         }
  60.  
  61.         private void DelEmail_Clicked(object sender, EventArgs e)
  62.         {
  63.             if (EmailText.Text.Contains("@") && EmailText.Text.Contains(".") && EmailText.Text != null)
  64.            {
  65.                SendCommand("del_mail ", EmailText.Text);
  66.                 DisplayAlert("Success", "Email Deleted!", "Continue");
  67.             }
  68.             else
  69.             {
  70.                 DisplayAlert("Error", "Invalid Email Address", "Continue");
  71.             }
  72.         }
  73.  
  74.         private void AddTime_Clicked(object sender, EventArgs e)
  75.         {
  76.             int selectedTime = SelectTime.SelectedIndex;
  77.  
  78.             SendCommand("add_time ", selectedTime.ToString());
  79.  
  80.             DisplayAlert("Success", "Time '" + (string)SelectTime.SelectedItem + "' Added!", "Continue");
  81.         }
  82.  
  83.         private void DelTime_Clicked(object sender, EventArgs e)
  84.         {
  85.             int selectedTime = SelectTime.SelectedIndex;
  86.  
  87.             SendCommand("del_time ", selectedTime.ToString());
  88.  
  89.             DisplayAlert("Success", "Time '" + (string)SelectTime.SelectedItem + "' Deleted!", "Continue");
  90.         }
  91.  
  92.         private void SetTime_Clicked(object sender, EventArgs e)
  93.         {
  94.             int selectedAmount = SelectAmount.SelectedIndex + 1;
  95.  
  96.             SendCommand("servo_time ", selectedAmount.ToString());
  97.  
  98.             DisplayAlert("Success", "Amount '" + (string)SelectAmount.SelectedItem + "' Set!", "Continue");
  99.         }
  100.  
  101.         private void Switch_Toggled(object sender, ToggledEventArgs e)
  102.         {
  103.             Switch sw = (Switch)sender;
  104.             if (sw.IsToggled == true)
  105.             {
  106.                 SendCommand("servo_auto ", "1");
  107.             }
  108.             else
  109.             {
  110.                 SendCommand("servo_auto ", "0");
  111.             }
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement