Пример #1
0
        public async void DrawerSelected(string obj)
        {
            switch (obj)
            {
            case "Patient_Search":
                await NavigationService.NavigateAsync("NavigationPage/PatientSearchPage");

                break;

            case "Patient":
            {
                try
                {
                    if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                    {
                        ui = new LoadingViewPopup();
                        await navigation.PushPopupAsync(ui);


                        await MasterSync.Sync_mstr_patient_info(this);


                        await navigation.PopPopupAsync();


                        await PageDialog.DisplayAlertAsync("Alert!!", AppResources.ResourceManager.GetString("msg7", AppResources.Culture), "OK");

                        CurrentProgress = 0f;
                    }
                    else
                    {
                        await PageDialog.DisplayAlertAsync("Alert!!", AppResources.ResourceManager.GetString("msg10", AppResources.Culture), "OK");
                    }
                }
                catch (Exception)
                {
                }
            }
            break;

            case "Master":
            {
                IsPageEnabled = true;
                if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                {
                    isMstrNotificationAvailable = true;
                    ui = new LoadingViewPopup();
                    await navigation.PushPopupAsync(ui);



                    await MasterSync.SyncMaster(this);

                    int    atime = Convert.ToInt32(Library.KEY_USER_adjusttime);
                    string tm    = DateTime.Now.AddMinutes(-atime).ToString("dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

                    Library.last_mastersynctime = tm;

                    MessagingCenter.Send <App, string>((App)Xamarin.Forms.Application.Current, "MasterSync", "Master");
                    await PageDialog.DisplayAlertAsync("Alert!!", AppResources.ResourceManager.GetString("msg0", AppResources.Culture), "OK");

                    await navigation.PopPopupAsync();

                    isMstrNotificationAvailable = false;
                    CurrentProgress             = 0f;
                }
                else
                {
                    await PageDialog.DisplayAlertAsync("Alert!!", AppResources.ResourceManager.GetString("msg10", AppResources.Culture), "OK");
                }
                IsPageEnabled = false;
            }
            break;

            case "Menu":
            {
                IsPageEnabled = true;
                if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                {
                    isMenuNotificationAvailable = true;
                    ui = new LoadingViewPopup();
                    await navigation.PushPopupAsync(ui);



                    await MasterSync.SyncMenuMaster(this);

                    //await MasterSync.Sync_mstr_menu_master();
                    //await MasterSync.Sync_mstr_menu_item();

                    int    atime = Convert.ToInt32(Library.KEY_USER_adjusttime);
                    string tm    = DateTime.Now.AddMinutes(-atime).ToString("dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

                    Library.last_mealssynctime = tm;

                    await PageDialog.DisplayAlertAsync("Alert!!", AppResources.ResourceManager.GetString("msg8", AppResources.Culture), "OK");

                    await navigation.PopPopupAsync();

                    isMenuNotificationAvailable = false;
                    CurrentProgress             = 0f;
                }
                else
                {
                    await PageDialog.DisplayAlertAsync("Alert!!", AppResources.ResourceManager.GetString("msg10", AppResources.Culture), "OK");
                }
                IsPageEnabled = false;
            }
            break;

            case "Order":
                await NavigationService.NavigateAsync("NavigationPage/DailyOrderDetailPage", new NavigationParameters { { "Create", "Create" } });

                break;

            case "Feed":
            {
                if (Library.KEY_USER_feedback_link.Contains("http"))
                {
                    await NavigationService.NavigateAsync("NavigationPage/FeedBackPage");
                }
                else
                {
                    await PageDialog.DisplayAlertAsync("Alert!!", AppResources.ResourceManager.GetString("flna", AppResources.Culture), "OK");
                }
            }
            break;

            case "Offline":
                try
                {
                    if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                    {
                        if (OrderCount == 0)
                        {
                            await PageDialog.DisplayAlertAsync("No Data", AppResources.ResourceManager.GetString("syncofforder", AppResources.Culture), "OK");

                            return;
                        }
                        else
                        {
                            var ui = new LoadingViewPopup();
                            await navigation.PushPopupAsync(ui);

                            await ConfirmOrderSync.SyncNow(_orderlocalRepo, _mealtimeRepo, PageDialog);

                            OfflineOrderCount();


                            await navigation.PopPopupAsync();



                            if (OrderCount == 0)
                            {
                                await PageDialog.DisplayAlertAsync("Alert!!", AppResources.ResourceManager.GetString("msg1", AppResources.Culture), "OK");
                            }

                            MessagingCenter.Send <App, string>((App)Xamarin.Forms.Application.Current, "offlineOrderSync", "offlineOrder");
                        }
                    }
                    else
                    {
                        await PageDialog.DisplayAlertAsync("Error!!", AppResources.ResourceManager.GetString("serv", AppResources.Culture), "OK");
                    }
                }
                catch (Exception ex)
                {
                }

                break;

            case "LogOut":
            {
                var response = await PageDialog.DisplayAlertAsync(AppResources.ResourceManager.GetString("txtlogText", AppResources.Culture), AppResources.ResourceManager.GetString("logsure", AppResources.Culture), AppResources.ResourceManager.GetString("contentyes", AppResources.Culture), AppResources.ResourceManager.GetString("contentno", AppResources.Culture));

                if (response)
                {
                    //Library.KEY_USER_LANGUAGE = "English";
                    SessionManager.Instance.EndTrackSession();
                    await NavigationService.NavigateAsync("app:///LoginPage");
                }
            }
            break;
            }
            IsPageEnabled = false;
        }
        public async void DrawerSelected(string obj)
        {
            switch (obj)
            {
            case "Patient_Search":
                await NavigationService.NavigateAsync("NavigationPage/PatientSearchPage");

                break;

            case "Patient":
            {
                try
                {
                    if (CrossConnectivity.Current.IsConnected == true)
                    {
                        var ui = new LoadingViewPopup();
                        await navigation.PushPopupAsync(ui);

                        await Task.Run(async() =>
                            {
                                await MasterSync.Sync_mstr_patient_info(ui);
                            });


                        await navigation.PopPopupAsync();

                        await PageDialog.DisplayAlertAsync("Alert!!", "Patient data synced successfully.", "OK");
                    }
                    else
                    {
                        await PageDialog.DisplayAlertAsync("Alert!!", "Server is not accessible, please check internet connection.", "OK");
                    }
                }
                catch (Exception)
                {
                }
            }
            break;

            case "Master":
            {
                IsPageEnabled = true;
                if (CrossConnectivity.Current.IsConnected)
                {
                    isMstrNotificationAvailable = true;
                    var ui = new LoadingViewPopup();
                    ui.logDeatils = new List <LogDetail>();

                    await navigation.PushPopupAsync(ui);



                    await MasterSync.SyncMaster(ui);

                    int    atime = Convert.ToInt32(Library.KEY_USER_adjusttime);
                    string tm    = DateTime.Now.AddMinutes(-atime).ToString("dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

                    Library.last_mastersynctime = tm;

                    MessagingCenter.Send <App, string>((App)Xamarin.Forms.Application.Current, "MasterSync", "Master");

                    //string msg = string.Empty;

                    //for (int i = 0; i < ui.logDeatils.Count; i++)
                    //{
                    //    if (i == 0)
                    //    {
                    //        msg = $" <b> {ui.logDeatils[0].Name}</b> - Total Records: {ui.logDeatils[0].totalRecord} Success: {ui.logDeatils[0].SuccessCount} \n";
                    //    }
                    //    else
                    //        msg += $" {ui.logDeatils[i].Name} - Total Records: {ui.logDeatils[i].totalRecord} Success: {ui.logDeatils[i].SuccessCount} \n";
                    //}


                    string msg = string.Empty;

                    for (int i = 0; i < ui.logDeatils.Count; i++)
                    {
                        if (ui.logDeatils[i].Name.Length > 13)
                        {
                            msg += $"{ui.logDeatils[i].Name.Substring(0, 11) + ".."}\tTotal Records:. {ui.logDeatils[i].totalRecord}\tSuccess Count:. {ui.logDeatils[i].SuccessCount}\n";
                        }
                        else
                        {
                            for (int j = 0; j < 13 - ui.logDeatils[i].Name.Length; j++)
                            {
                                ui.logDeatils[i].Name += " ";
                            }

                            msg += $"{ui.logDeatils[i].Name}\tTotal Records:. {ui.logDeatils[i].totalRecord}\tSuccess Count:. {ui.logDeatils[i].SuccessCount}\n";
                        }
                    }

                    await PageDialog.DisplayAlertAsync("Sync Status!!", msg, "OK");

                    await navigation.PopPopupAsync();

                    isMstrNotificationAvailable = false;
                }
                else
                {
                    await PageDialog.DisplayAlertAsync("Alert!!", "Server is not accessible, please check internet connection.", "OK");
                }
                IsPageEnabled = false;
            }
            break;

            case "Menu":
            {
                IsPageEnabled = true;
                if (CrossConnectivity.Current.IsConnected)
                {
                    isMenuNotificationAvailable = true;
                    var ui = new LoadingViewPopup();
                    ui.logDeatils = new List <LogDetail>();
                    await navigation.PushPopupAsync(ui);



                    await MasterSync.SyncMenuMaster(ui);

                    int    atime = Convert.ToInt32(Library.KEY_USER_adjusttime);
                    string tm    = DateTime.Now.AddMinutes(-atime).ToString("dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

                    Library.last_mealssynctime = tm;

                    string msg = string.Empty;

                    for (int i = 0; i < ui.logDeatils.Count; i++)
                    {
                        msg += $"{ui.logDeatils[i].Name}\tTotal Records:. {ui.logDeatils[i].totalRecord}\tSuccess Count:. {ui.logDeatils[i].SuccessCount}\n";
                    }

                    await PageDialog.DisplayAlertAsync("Sync Status!!", msg, "OK");

                    await navigation.PopPopupAsync();

                    isMenuNotificationAvailable = false;
                }
                else
                {
                    await PageDialog.DisplayAlertAsync("Alert!!", "Server is not accessible, please check internet connection.", "OK");
                }
                IsPageEnabled = false;
            }
            break;

            case "Order":
                await NavigationService.NavigateAsync("NavigationPage/DailyOrderDetailPage", new NavigationParameters { { "Create", "Create" } });

                break;

            case "OrderStatus":
                await NavigationService.NavigateAsync("NavigationPage/MealOrderStatusPage");

                break;

            case "Feed":
            {
                if (Library.KEY_USER_feedback_link.Contains("http"))
                {
                    await NavigationService.NavigateAsync("NavigationPage/FeedBackPage");
                }
                else
                {
                    await PageDialog.DisplayAlertAsync("Alert!!", "Feedback link not available", "OK");
                }
            }
            break;

            case "Offline":
                try
                {
                    if (CrossConnectivity.Current.IsConnected)
                    {
                        if (OrderCount == 0)
                        {
                            await PageDialog.DisplayAlertAsync("No Data", "There is no offline order to be sync.", "OK");

                            return;
                        }
                        else
                        {
                            var ui = new LoadingViewPopup();
                            await navigation.PushPopupAsync(ui);

                            await ConfirmOrderSync.SyncNow(_orderlocalRepo, _mealtimeRepo, PageDialog);

                            OfflineOrderCount();


                            await navigation.PopPopupAsync();



                            if (OrderCount == 0)
                            {
                                await PageDialog.DisplayAlertAsync("Alert!!", "Meal Orders Have been synced successfully", "OK");
                            }

                            MessagingCenter.Send <App, string>((App)Xamarin.Forms.Application.Current, "offlineOrderSync", "offlineOrder");
                        }
                    }
                    else
                    {
                        await PageDialog.DisplayAlertAsync("Error!!", "Please check your internet connection.", "OK");
                    }
                }
                catch (Exception)
                {
                }

                break;

            case "LogOut":
            {
                var response = await PageDialog.DisplayAlertAsync("Log Out", "Are you sure you want to logout?", "Yes", "No");

                if (response)
                {
                    if (CrossConnectivity.Current.IsConnected)
                    {
                        using (var httpClient = new System.Net.Http.HttpClient())
                        {
                            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Library.URL + "/updatelogfalse/" + Library.KEY_USER_ID);

                            await httpClient.SendAsync(request);
                        }
                        Library.KEY_USER_ID = string.Empty;
                    }
                    SessionManager.Instance.EndTrackSession();
                    await NavigationService.NavigateAsync("app:///LoginPage");
                }
            }
            break;
            }
            IsPageEnabled = false;
        }