Esempio n. 1
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            _application.mqttHelper.SubscribeMQTT("RESPON_BARCODE_TRIAL_INJECTION_" + GlobalVar.MacAddress);
            MessagingCenter.Subscribe <MqttHelper, string>(this, MessagingCenterKeys.RESPON_BARCODE_TRIAL_INJECTION, (sender, args) =>
            {
                if (args != null)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (args.Contains("ERROR"))
                        {
                            DisplayAlert("Warning", "Barcode yang terscan salah silahkan ulangi kembali.", "OK");
                        }
                        else if (args.Contains("ALREADY"))
                        {
                            DisplayAlert("Information", "Sudah di input ", "OK");
                        }
                        else
                        {
                            CounterInjection cinj = new CounterInjection();
                            cinj.BarcodeID        = args;

                            List <CounterInjection> x = new List <CounterInjection>();
                            sfListView.ItemsSource    = x;

                            _listCounterInjections.Add(cinj);
                            sfListView.ItemsSource = _listCounterInjections;
                            labeltotal.Text        = string.Format("Total = {0}", Convert.ToString(_listCounterInjections.Count()));
                            Vibration.Vibrate();
                        }
                    });
                }
            });
        }
Esempio n. 2
0
        private async void Process(string result)
        {
            if (AppSettings.IsMqttConnected && !string.IsNullOrEmpty(result))
            {
                if (result.Length > 11 && result.Length <= 50)
                {
                    string pubmsg = string.Format("{0},{1},{2},{3}", result, GlobalVar.PlantID, GlobalVar.Username, "RESPON_BARCODE_TRIAL_INJECTION_" + GlobalVar.MacAddress);

                    if (!SwitchMqttOrWebAPI.IsToggled)
                    {
                        _application.mqttHelper.PublishMQTT(pubmsg, "SCAN_BARCODE_TRIAL_INJECTION");
                        _application.mqttHelper.SubscribeMQTT("RESPON_BARCODE_TRIAL_INJECTION_" + GlobalVar.MacAddress);
                    }
                    else
                    {
                        try
                        {
                            WebClient wc = new WebClient();
                            wc.Proxy = null;

                            pubmsg = string.Format("{0}@$@{1}@$@{2}", result, GlobalVar.PlantID, GlobalVar.Username);

                            string link = "http://192.168.77.174/WebAPITest/api/values/" + pubmsg;

                            string downloadedstring = wc.DownloadString(link);
                            if (downloadedstring.Contains("ERROR"))
                            {
                                await DisplayAlert("Warning", "Barcode yang terscan salah silahkan ulangi kembali.", "OK");
                            }
                            else if (downloadedstring.Contains("ALREADY"))
                            {
                                await DisplayAlert("Information", "Sudah di input ", "OK");
                            }
                            else
                            {
                                CounterInjection cinj = new CounterInjection();
                                cinj.BarcodeID = downloadedstring;

                                List <CounterInjection> x = new List <CounterInjection>();
                                sfListView.ItemsSource = x;

                                _listCounterInjections.Add(cinj);
                                sfListView.ItemsSource = _listCounterInjections;
                                labeltotal.Text        = string.Format("Total = {0}", Convert.ToString(_listCounterInjections.Count()));
                                Vibration.Vibrate();
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else if (result.Length > 50)
                {
                    if (result.Contains("Z1") && result.Contains("Z2") && result.Contains("Z3") && result.Contains("Z4") && result.Contains("Z5") && result.Contains("Z6") && result.Contains("Z7"))
                    {
                        int    index1          = result.IndexOf("Z5");
                        int    index2          = result.IndexOf("|", index1);
                        string customerbarcode = result.Substring(index1 + 2, index2 - index1 - 2);
                        string pubmsg          = string.Format("{0},{1},{2},{3}", customerbarcode, GlobalVar.PlantID, GlobalVar.Username, "RESPON_BARCODE_TRIAL_INJECTION_" + GlobalVar.MacAddress);

                        if (!SwitchMqttOrWebAPI.IsToggled)
                        {
                            _application.mqttHelper.PublishMQTT(pubmsg, "SCAN_BARCODE_TRIAL_INJECTION");
                            _application.mqttHelper.SubscribeMQTT("RESPON_BARCODE_TRIAL_INJECTION_" + GlobalVar.MacAddress);
                        }
                        else
                        {
                            try
                            {
                                WebClient wc = new WebClient();
                                wc.Proxy = null;

                                pubmsg = string.Format("{0}@$@{1}@$@{2}", customerbarcode, GlobalVar.PlantID, GlobalVar.Username);

                                string link = "http://192.168.77.174/WebAPITest/api/values/" + pubmsg;

                                string downloadedstring = wc.DownloadString(link);
                                if (downloadedstring.Contains("ERROR"))
                                {
                                    await DisplayAlert("Warning", "Barcode yang terscan salah silahkan ulangi kembali.", "OK");
                                }
                                else if (downloadedstring.Contains("ALREADY"))
                                {
                                    await DisplayAlert("Information", "Sudah di input ", "OK");
                                }
                                else
                                {
                                    CounterInjection cinj = new CounterInjection();
                                    cinj.BarcodeID = downloadedstring;

                                    List <CounterInjection> x = new List <CounterInjection>();
                                    sfListView.ItemsSource = x;

                                    _listCounterInjections.Add(cinj);
                                    sfListView.ItemsSource = _listCounterInjections;
                                    labeltotal.Text        = string.Format("Total = {0}", Convert.ToString(_listCounterInjections.Count()));
                                    Vibration.Vibrate();
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
                else
                {
                    await DisplayAlert("Warning", "Barcode yang terscan salah silahkan ulangi kembali.", "OK");
                }
            }
        }