| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 | using Comal.Classes;using InABox.Clients;using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using Xamarin.Forms;using Xamarin.Forms.Xaml;namespace comal.timesheets{	[XamlCompilation(XamlCompilationOptions.Compile)]	public partial class SignatureSaver : ContentPage	{        public delegate void SignatureSaved();        public event SignatureSaved OnSignatureSaved;		public SignatureSaver ()		{			InitializeComponent ();		}		void Save_Clicked(object sender, EventArgs e)		{            signaturePad.Save();            if (signaturePad.ImageSource != null)            {                string base64 = ImageSourceToBase64(signaturePad.ImageSource);                byte[] data = Convert.FromBase64String(base64);                try                {                    Employee employee = new Employee { ID = GlobalVariables.EmpID };                    employee.Signature = data;                    new Client<Employee>().Save(employee, "Signature Saved from mobile");                }                catch                {                                 }                if (Application.Current.Properties.ContainsKey("SavedSignature"))                {                    Application.Current.Properties["SavedSignature"] = data;                }                else                {                    Application.Current.Properties.Add("SavedSignature", data);                }            }            OnSignatureSaved?.Invoke();            Navigation.PopAsync();        }		void Clear_Clicked(object sender, EventArgs e)		{			signaturePad.Clear();		}        void DeleteSaved_Clicked(object sender, EventArgs e)        {            try            {                Employee employee = new Employee { ID = GlobalVariables.EmpID };                employee.Signature = null;                new Client<Employee>().Save(employee, "Signature Saved from mobile");                DisplayAlert("Success", "Signature deleted for Employee", "OK");            }            catch            {            }        }        private string ImageSourceToBase64(ImageSource source)        {            StreamImageSource streamImageSource = (StreamImageSource)source;            System.Threading.CancellationToken cancellationToken = System.Threading.CancellationToken.None;            Task<Stream> task = streamImageSource.Stream(cancellationToken);            Stream stream = task.Result;            byte[] bytes = new byte[stream.Length];            stream.Read(bytes, 0, bytes.Length);            string s = Convert.ToBase64String(bytes, Base64FormattingOptions.InsertLineBreaks);            return s;        }    }}
 |