Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using MobileClient.Models;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Collections.Specialized;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Runtime.Serialization.Json;
- using Xamarin.Forms;
- using System.IO;
- using System.Runtime.Serialization;
- namespace MobileClient
- {
- public partial class MainPage : ContentPage
- {
- private CatClient catClient;
- public MainPage()
- {
- InitializeComponent();
- catClient = new CatClient();
- BindingContext = catClient;
- AllEmails.ItemsSource = catClient.emailList;
- AllTimes.ItemsSource = catClient.timeList;
- catClient.timeList.Add(new TimeItem() { Time = "02:00" });
- catClient.emailList.Add(new EmailItem() { Email = "AAA" });
- SendCommand("servo_auto ", "0");
- SendCommand("settings_status", "");
- }
- private void SendCommand(string command, string value)
- {
- try
- {
- catClient.WriteMessage(command + value);
- }
- catch (Exception ex)
- {
- DisplayAlert("Error", "Connection Error", "Continue");
- }
- }
- private void AddEmail_Clicked(object sender, EventArgs e)
- {
- if (EmailText.Text.Contains('@') && EmailText.Text.Contains('.') && EmailText.Text != null)
- {
- SendCommand("add_mail ", EmailText.Text);
- DisplayAlert("Success", "Email Added!", "Continue");
- }
- else
- {
- DisplayAlert("Error", "Invalid Email Address", "Continue");
- }
- }
- private void DelEmail_Clicked(object sender, EventArgs e)
- {
- if (EmailText.Text.Contains("@") && EmailText.Text.Contains(".") && EmailText.Text != null)
- {
- SendCommand("del_mail ", EmailText.Text);
- DisplayAlert("Success", "Email Deleted!", "Continue");
- }
- else
- {
- DisplayAlert("Error", "Invalid Email Address", "Continue");
- }
- }
- private void AddTime_Clicked(object sender, EventArgs e)
- {
- int selectedTime = SelectTime.SelectedIndex;
- SendCommand("add_time ", selectedTime.ToString());
- DisplayAlert("Success", "Time '" + (string)SelectTime.SelectedItem + "' Added!", "Continue");
- }
- private void DelTime_Clicked(object sender, EventArgs e)
- {
- int selectedTime = SelectTime.SelectedIndex;
- SendCommand("del_time ", selectedTime.ToString());
- DisplayAlert("Success", "Time '" + (string)SelectTime.SelectedItem + "' Deleted!", "Continue");
- }
- private void SetTime_Clicked(object sender, EventArgs e)
- {
- int selectedAmount = SelectAmount.SelectedIndex + 1;
- SendCommand("servo_time ", selectedAmount.ToString());
- DisplayAlert("Success", "Amount '" + (string)SelectAmount.SelectedItem + "' Set!", "Continue");
- }
- private void Switch_Toggled(object sender, ToggledEventArgs e)
- {
- Switch sw = (Switch)sender;
- if (sw.IsToggled == true)
- {
- SendCommand("servo_auto ", "1");
- }
- else
- {
- SendCommand("servo_auto ", "0");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement