Exemplo n.º 1
0
        private async void OpenPage()
        {
            KooshDarooDatabase odb = new KooshDarooDatabase();
            var oLoginItemS        = odb.GetItemsAsync();

            if (oLoginItemS.Result.Count > 0)
            {
                MemberService memberservices = new MemberService();
                //var member = await memberservices.GetMemberByPhoneNoAsync(oLoginItemS.Result[0].PhoneNo);
                var member = Task.Run(() => memberservices.GetMemberByPhoneNoAsync(oLoginItemS.Result[0].PhoneNo));
                if (member.Result.Count == 0)
                //if (member.Count == 0)
                {
                    oLoginItemS.Result.ForEach(f => odb.DeleteItemAsync(f));
                    App.Current.MainPage = new SignUpPage();
                }
                else
                {
                    App.Current.MainPage = new MainPageTabbed();
                }
            }
            else
            {
                App.Current.MainPage = new SignUpPage();
            }
            //MainPage = new NavigationPage(new SignUpPage());
        }
        private async void SignUpButton_Clicked(object sender, EventArgs e)
        {
            MemberService memberservices = new MemberService();
            //var xo = await memberservices.GetMemberAsync();
            var member = await memberservices.GetMemberByPhoneNoAsync(phoneNo.Text);

            if (member.Count == 0)
            {
                Member _member = new Member {
                    PhoneNo = phoneNo.Text, isInactive = false
                };
                var result = memberservices.PostMemberAsync(_member);
            }
            KooshDarooDatabase odb       = new KooshDarooDatabase();
            tblMember          newmember = new tblMember {
                PhoneNo = phoneNo.Text
            };
            int r = await odb.SaveItemAsync(newmember);

            odb = new KooshDarooDatabase();
            var oLoginItemS = odb.GetItemsAsync();
            var o           = oLoginItemS.Result.Count;

            App.Current.MainPage = new MainPageTabbed();
            //this.Content = (new MainPage()).Content;
        }
Exemplo n.º 3
0
        public async Task <bool> CanPrescribeAsync()
        {
            KooshDarooDatabase odb = new KooshDarooDatabase();
            var oLoginItemS        = odb.GetItemsAsync();

            if (oLoginItemS.Result.Count == 0)
            {
                return(false);
            }
            else
            {
                //var result = await restClient.GetAsyncByFieldNameFirst("Prescribe","PhoneNo", oLoginItemS.Result[0].PhoneNo);
                //return (DateTime.Now.ToOADate()-result.DateOf.ToOADate() > 0.5);
                return((DateTime.Now.ToOADate() - oLoginItemS.Result[0].LastPrescribeDate.ToOADate()) >= 0.5);
            }
        }
        private async void OnSendTapped(object sender, EventArgs args)
        {
            double x = 0.0;
            double y = 0.0;

            try
            {
                var location = await Geolocation.GetLastKnownLocationAsync();

                if (location != null)
                {
                    x = location.Latitude;
                    y = location.Longitude;
                }
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                await DisplayAlert("Faild", fnsEx.Message, "OK");
            }
            catch (PermissionException pEx)
            {
                await DisplayAlert("Faild", pEx.Message, "OK");
            }
            catch (Exception ex)
            {
                await DisplayAlert("Faild", ex.Message, "OK");
            }


            if (x == 0 & y == 0)
            {
                return;
            }
            //await DisplayAlert("Sent", "To Server", "OK");
            PrescribeService Prescribeservice = new PrescribeService();

            if (Prescribeservice.CanPrescribeAsync().Result || true)
            {
                if (prescribeimage.Source == null)
                {
                    DisplayAlert("توجه", "ابتدا باید از نسخه عکس بگیرید", "OK");
                    return;
                }
                KooshDarooDatabase odb = new KooshDarooDatabase();
                var       oLoginItemS  = odb.GetItemsAsync();
                var       oLoginItem   = oLoginItemS.Result[0];
                Prescribe Prescribe    = new Prescribe
                {
                    isCancelled  = false,
                    Prescription = ReadFully((StreamImageSource)prescribeimage.Source),
                    X            = x,
                    Y            = y,
                    PhoneNo      = oLoginItem.PhoneNo
                };
                var result = await Prescribeservice.PostPrescribeAsync(Prescribe);

                if (result.id == 0)
                {
                    DisplayAlert("خطا", "امکان ارسال نسخه وجود ندارد و یادر 12 ساعت گذشته نسخه ارسال کرده اید و تا 12 ساعت امکان ثبت نسخه جدید ندارید.", "OK");
                }
                else
                {
                    prescribeimage.Source = null;
                    DisplayAlert("توجه", "نسخه ارسال شد. لطفاً تا رسیدن پاسخ از داروخانه ها صبرکنید.", "OK");
                    _prescribeId = result.id;

                    if (hubConnection.State == HubConnectionState.Disconnected)
                    {
                        StartConnectionToHub();
                    }

                    await hubConnection.SendAsync("SendPrescribeToPharmacy", Prescribe.X, Prescribe.Y, result.DateOf, result.id);

                    //await hubConnection.SendAsync("Send", "Testing the hub...");
                }
                //if (result == 0)
                //    DisplayAlert("خطا", "امکان ارسال نسخه وجود ندارد.", "OK");
                //else if (result == -1)
                //    DisplayAlert("خطا", "در 12 ساعت گذشته نسخه ارسال کرده اید و تا 12 ساعت امکان ثبت نسخه جدید ندارید.", "OK");
                //else
                //{
                //    prescribeimage.Source = null;
                //    DisplayAlert("توجه", "نسخه ارسال شد. لطفاً تا رسیدن پاسخ از داروخانه ها صبرکنید.", "OK");

                //    StartConnectionToHub();

                //    //await hubConnection.SendAsync("SendPrescribeToPharmacy", Prescribe.PhoneNo, Prescribe.DateOf);
                //    //await hubConnection.SendAsync("Send", "Testing the hub...");

                //}
            }
        }
Exemplo n.º 5
0
        private async void OnSendTapped(object sender, EventArgs args)
        {
            double x = 0.0;
            double y = 0.0;

            try
            {
                var location = await Geolocation.GetLastKnownLocationAsync();

                if (location != null)
                {
                    x = location.Latitude;
                    y = location.Longitude;
                }
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                await DisplayAlert("Faild", fnsEx.Message, "OK");
            }
            catch (PermissionException pEx)
            {
                await DisplayAlert("Faild", pEx.Message, "OK");
            }
            catch (Exception ex)
            {
                await DisplayAlert("Faild", ex.Message, "OK");
            }


            //await DisplayAlert("Sent", "To Server", "OK");
            PrescribesService prescribesservice = new PrescribesService();
            {
                if (prescribeimage.Source == null)
                {
                    DisplayAlert("توجه", "ابتدا باید از نسخه عکس بگیرید", "OK");
                    return;
                }
                KooshDarooDatabase odb = new KooshDarooDatabase();
                var        oLoginItemS = odb.GetItemsAsync();
                var        oLoginItem  = oLoginItemS.Result[0];
                Prescribes prescribes  = new Prescribes {
                    DateOf = DateTime.Now.ToOADate(), isCancelled = false, Prescribe = ReadFully((StreamImageSource)prescribeimage.Source), X = x, Y = y, PhoneNo = oLoginItem.PhoneNo
                };
                var result = await prescribesservice.PostPrescribesAsync(prescribes);

                if (result.id != 0)
                {
                    prescribeimage.Source = null;
                    DisplayAlert("توجه", "نسخه ارسال شد. لطفاً تا رسیدن پاسخ از داروخانه ها صبرکنید.", "OK");

                    StartConnectionToHub();

                    await hubConnection.SendAsync("SendPrescribeToPharmacy", prescribes.PhoneNo, prescribes.DateOf);

                    //await hubConnection.SendAsync("Send", "Testing the hub...");
                }
                else
                {
                    DisplayAlert("خطا", "امکان ارسال نسخه وجود ندارد ویا در 12 ساعت گذشته نسخه ارسال کرده اید و تا 12 ساعت امکان ثبت نسخه جدید ندارید.", "OK");
                }
            }
        }