예제 #1
0
        //method to get all the data from sql server
        private async Task getDataFromServer()
        {
            //Dismiss Keybaord
            InputMethodManager imm = (InputMethodManager)Activity.GetSystemService(Context.InputMethodService);

            //get location if android >= 5.1
            if (Values.GEO)
            {
                var androindVersion = Android.OS.Build.VERSION.SdkInt;
                if (androindVersion >= BuildVersionCodes.LollipopMr1)
                {
                    using (var rs = new XMLRS("Select CMP_INTEGER from Datos_Empresa where Codigo='LOC_TIME'", Values.gDatos))
                    {
                        await rs.OpenAsync();

                        if (rs.RecordCount != 0)
                        {
                            Values.LocTime = rs["CMP_INTEGER"].ToInt();
                        }
                    }
                    var request = new GeolocationRequest(GeolocationAccuracy.High, TimeSpan.FromSeconds(30));
                    var ini     = await Geolocation.GetLastKnownLocationAsync();

                    Location location = null;
                    //try
                    //{
                    //    location = await Geolocation.GetLocationAsync(request);
                    //}
                    //catch (Exception ex)
                    //{
                    //    Console.WriteLine(ex.Message);
                    //}
                    if (location != null)
                    {
                        var _locData = new DataLocation()
                        {
                            Accuracy = location.Accuracy, Course = location.Course, Altitude = location.Altitude, Latitude = location.Latitude, Longitude = location.Longitude, Speed = location.Speed, Timestamp = location.Timestamp
                        };
                        await _locData.ToDB();
                    }
                    Activity.StartService(new Intent(Activity, typeof(LocatorService)));
                    LocatorService.Active = true;
                }
            }
            imm.HideSoftInputFromWindow(orderNumberET.WindowToken, 0);
            int _progress = 0;

            if (Values.gOrderNumber != 0)
            {
                Values.iFt.pushInfo("Getting Label Data");
                //data from labels for checkng
                using (var _rs = new XMLRS(string.Format("select numero,partnumber,qty,cajas,rack,Modulo from etiquetas where Numero_orden={0} and Tipo='PEQ'", Values.gOrderNumber), Values.gDatos))
                {
                    await _rs.OpenAsync();

                    Values.sFt.socksProgress.Indeterminate = false;
                    Values.sFt.socksProgress.Max           = _rs.RecordCount / 5;
                    Values.sFt.socksProgress.Progress      = 0;
                    foreach (var r in _rs.Rows)
                    {
                        await Values.SQLidb.db.InsertAsync(new Labels { Serial = r["numero"].ToString(), Partnumber = r["partnumber"].ToString(), qty = r["qty"].ToInt(), boxes = r["cajas"].ToInt(), rack = r["rack"].ToString(), mod = r["Modulo"].ToString() });

                        _progress++;
                        if (_progress % 5 == 0)
                        {
                            Values.sFt.socksProgress.Progress++;
                        }
                    }
                    Values.sFt.socksProgress.Indeterminate = true;
                    //Values.sFt.CheckQtyTotal= _rs.Rows.Count;
                    //Values.sFt.UpdateInfo();
                }
                Values.iFt.pushInfo("Done");
            }

            Values.iFt.pushInfo("Getting RacksBlocks table");
            //data from RacksBlocks table
            using (var _rs = new XMLRS(string.Format("select Block,Rack from RacksBlocks where service='{0}' and dbo.CheckFlag(flags,'OBS')=0", Values.gService), Values.gDatos))
            {
                await _rs.OpenAsync();

                Values.sFt.socksProgress.Indeterminate = false;
                Values.sFt.socksProgress.Max           = _rs.RecordCount / 5;
                Values.sFt.socksProgress.Progress      = 0;
                foreach (var r in _rs.Rows)
                {
                    await Values.SQLidb.db.InsertAsync(new RacksBlocks { Block = r["Block"].ToString(), Rack = r["Rack"].ToString() });

                    _progress++;
                    if (_progress % 5 == 0)
                    {
                        Values.sFt.socksProgress.Progress++;
                    }
                }
            }
            Values.sFt.socksProgress.Indeterminate = true;
            Values.iFt.pushInfo("Done");
            Values.iFt.pushInfo("Getting PartnumberRacks table");
            //data from RacksBlocks table
            // [dvalles] 20220601: Added isnull for avioiding later error when accessing that column (it makes the app to crash when it results null)
            string _prquery = $"Select p.Rack,Partnumber,MinBoxes,MaxBoxes,p.flags,alternate=isnull(dbo.fObtenerValor(ExtraData,'ALTREAD'),'') from PartnumbersRacks p inner join RacksBlocks r on r.Rack=p.Rack where p.service='{Values.gService}' " +
#if DEBUG
                              $"and r.Block='{Values.gBlock}' " +
#endif
                              $"and dbo.CheckFlag(r.flags,'OBS')=0";

            using (var _rs = new XMLRS(_prquery, Values.gDatos))
            {
                await _rs.OpenAsync();

                Values.sFt.socksProgress.Indeterminate = false;
                Values.sFt.socksProgress.Max           = _rs.RecordCount / 5;
                Values.sFt.socksProgress.Progress      = 0;
                foreach (var r in _rs.Rows)
                {
                    await Values.SQLidb.db.InsertAsync(new PartnumbersRacks { Rack = r["Rack"].ToString(), Partnumber = r["Partnumber"].ToString(), MinBoxes = r["MinBoxes"].ToInt(), MaxBoxes = r["MaxBoxes"].ToInt(), alternate = r["alternate"].ToString() });

                    _progress++;
                    if (_progress % 5 == 0)
                    {
                        Values.sFt.socksProgress.Progress++;
                    }
                }
            }
            Values.sFt.socksProgress.Indeterminate = true;
            Values.iFt.pushInfo("Done loading database data");
            Values.elIntent = new Intent(Activity, typeof(DataTransferManager));
            Activity.StartService(Values.elIntent);
            DataTransferManager.Active = true;
            ((MainScreen)Activity).changeOrderToEnterDataFragments();
        }