//protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) //{ // base.OnActivityResult(requestCode, resultCode, data); // if (resultCode == Result.Ok && requestCode == 0) // { // string Result = data.GetStringExtra("Result"); // if (Result == "OK") // { // if (CallingPkg == null) // { // var intent = new Intent(this, typeof(MainScreen)); // StartActivityForResult(intent, 1); // } else // { // MainActivity.LaunchPackage(CallingPkg, this); // } // } // else // { // Finish(); // } // } // else // { // Finish(); // } //} public async static Task LaunchPackage(string packageName, Context context) { try { Intent intent = packageName == "com.espack.logon" ? new Intent(context, typeof(MainScreen)) : context.PackageManager.GetLaunchIntentForPackage(packageName); //((Activity)context).RunOnUiThread(async () => //{ //check if package exists if (intent == null) { var pd = ProgressDialog.Show(context, "", "Downloading...", false, false); pd.SetProgressStyle(ProgressDialogStyle.Spinner); try { await UpdatePackage.DoUpdatePackage(packageName, context); intent = context.PackageManager.GetLaunchIntentForPackage(packageName); } catch (Exception ex) { Toast.MakeText(context, ex.Message, ToastLength.Long); pd.Dismiss(); return; } pd.Dismiss(); } //check if package is updated if (UpdatePackage.CheckPackageIsOutdated(packageName, Values.LogonDetails.Version, context)) { bool dialogResult = await AlertDialogHelper.ShowAsync(context, "New version found", "Do you want to update your current program?", "Yes", "No"); if (dialogResult) { var pd = ProgressDialog.Show(context, "", "Downloading...", false, false); pd.SetProgressStyle(ProgressDialogStyle.Spinner); try { await UpdatePackage.DoUpdatePackage(packageName, context); return; //intent = context.PackageManager.GetLaunchIntentForPackage(packageName); } catch (Exception ex) { var builder = new Android.Support.V7.App.AlertDialog.Builder(context); builder.SetTitle("ERROR"); builder.SetIcon(Android.Resource.Drawable.IcDialogAlert); builder.SetMessage(ex.Message); builder.SetNeutralButton("OK", delegate { }); } pd.Dismiss(); } } intent.PutExtra("USR", LogonDetails.User); intent.PutExtra("PWD", LogonDetails.Password); intent.PutExtra("SRV", "db01.local"); intent.PutExtra("VERSION", LogonDetails.Version); intent.PutExtra("FULLNAME", LogonDetails.FullName); context.StartActivity(intent); //}); } catch (Exception ex) { Toast.MakeText(context, ex.Message, ToastLength.Long); } }
private async Task DoThings() { if (cUser.Text == "" || cPassword.Text == "") { cMsgText.Text = "Please input correct User and Password"; } else { this.RunOnUiThread(() => { cUser.Enabled = false; cPassword.Enabled = false; }); gDatos.DataBase = "SISTEMAS"; gDatos.Server = LogonDetails.ConnectionServer; gDatos.User = "******"; gDatos.Password = "******"; bool error = false; try { await gDatos.ConnectAsync(); //RunOnUiThread(async () => { }); } catch (Exception ex) { var builder = new Android.Support.V7.App.AlertDialog.Builder(this); builder.SetTitle("ERROR"); builder.SetIcon(Android.Resource.Drawable.IcDialogAlert); builder.SetMessage("Error: " + ex.Message); builder.SetNeutralButton("OK", delegate { Intent intent = new Intent(); intent.PutExtra("Result", "ERROR"); SetResult(Result.Ok, intent); Finish(); }); RunOnUiThread(() => { builder.Create().Show(); }); error = true; } if (!error) { RSFrame _RS; _RS = (RSFrame)CObjectFactory.CreateObject("RS", typeofCaller, "select date=getdate()", gDatos); await _RS.OpenAsync(); gDatos.Close(); SPFrame LogonSP; LogonSP = (SPFrame)CObjectFactory.CreateObject("SP", typeofCaller, gDatos, "pLogonUser"); LogonSP.AddParameterValue("User", cUser.Text); LogonSP.AddParameterValue("Password", cPassword.Text); LogonSP.AddParameterValue("Origin", packageName.ToUpper()); LogonSP.AddParameterValue("FullName", ""); string _version = "123456"; string _packageName = "123456789"; LogonSP.AddParameterValue("Version", _version); LogonSP.AddParameterValue("PackageName", _packageName); try { await LogonSP.ExecuteAsync(); if (LogonSP.LastMsg.Substring(0, 2) != "OK") { throw new Exception(LogonSP.LastMsg); } else { Toast.MakeText(this, "Logon OK!", ToastLength.Short).Show(); LogonDetails.User = LogonSP.ReturnValues()["@User"].ToString(); LogonDetails.Password = LogonSP.ReturnValues()["@Password"].ToString(); LogonDetails.FullName = LogonSP.ReturnValues()["@FullName"].ToString(); _version = LogonSP.ReturnValues()["@Version"].ToString(); var _versionArray = _version.Split('.'); _version = string.Format("{0}.{1}", _versionArray[0], _versionArray[1]); var versionArray = version.Split('.'); version = string.Format("{0}.{1}", versionArray[0], versionArray[1]); _packageName = LogonSP.ReturnValues()["@PackageName"].ToString(); #if DEBUG if (true) //if(_version != version) #else if (_version != version) #endif { bool dialogResult = await AlertDialogHelper.ShowAsync(this, "New version found", "Do you want to update your current program?", "Yes", "No"); if (dialogResult) { try { Window.SetFlags(Android.Views.WindowManagerFlags.NotTouchable, Android.Views.WindowManagerFlags.NotTouchable); progressBarHolder.Visibility = ViewStates.Visible; await UpdatePackageURL(_packageName); //pd.Dismiss(); progressBarHolder.Visibility = ViewStates.Gone; Window.ClearFlags(WindowManagerFlags.NotTouchable); } catch (Exception ex) { Window.ClearFlags(WindowManagerFlags.NotTouchable); cMsgText.Text = string.Format("Error updating app, {0}: {1}", ex.Message, ex.InnerException.Message); Window.ClearFlags(WindowManagerFlags.NotTouchable); } } } Intent intent = new Intent(); intent.PutExtra("Result", "OK"); SetResult(Result.Ok, intent); Finish(); } } catch (Exception ex) { cMsgText.Text = string.Format("{0}: {1}", ex.Message, ex.InnerException.Message); cUser.Text = ""; cPassword.Text = ""; #if DEBUG cUser.Text = "restelles"; cPassword.Text = "1312"; #endif cUser.RequestFocus(); } } this.RunOnUiThread(() => { cUser.Enabled = true; cPassword.Enabled = true; }); } }
protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (resultCode == Result.Ok && requestCode == 0) { string Result = data.GetStringExtra("Result"); if (Result == "OK") { Values.gDatos.DataBase = "LOGISTICA"; Values.gDatos.Server = "net.espackeuro.com"; Values.gDatos.User = LogonDetails.User; Values.gDatos.Password = LogonDetails.Password; string _mainScreenMode = "NEW"; //create sqlite database Values.SQLidb = new SQLiteDatabase("DELIVERIES"); if (Values.SQLidb.Exists) //check if database exists { //Values.SQLidb.CreateDatabase(); //link the file to the sqlite database await Values.CreateDatabase(); //create tables if not exist Settings _settings = await Values.SQLidb.db.Table <Settings>().FirstOrDefaultAsync(); //get settings of persistent data if (_settings != null && _settings.User == Values.gDatos.User && _settings.Password == Values.gDatos.Password) //if not empty and user and password matches the logon ones { //var _lastXfec = from r in Values.SQLidb.db.Table<ScannedData>().ToListAsync().Result orderby r.xfec descending select xfec; try { var _lastRecord = await Values.SQLidb.db.QueryAsync <ScannedData>("Select * from ScannedData order by idreg desc limit 1"); //ScannedData _lastRecord = await Values.SQLidb.db.Table<ScannedData>().FirstOrDefaultAsync(); //get the last record time added, nullable datetime type if (_lastRecord.Count != 0 && (DateTime.Now - _lastRecord[0].xfec).Minutes < 60) //if time less than one hour { bool _a1, _a2 = false; _a1 = await AlertDialogHelper.ShowAsync(this, "Warning", "There are incomplete session data in the device, do you want to continue last session or erase and start a new one?", "ERASE", "CONTINUE SESSION"); if (_a1) //ERASE { _a2 = await AlertDialogHelper.ShowAsync(this, "Warning", "This will erase all pending content present in the device, are you sure?", "ERASE", "CONTINUE SESSION"); } if (!_a1 || !_a2) { Values.gSession = _settings.Session; Values._block = _settings.Block; Values.gOrderNumber = _settings.Order; Values.gService = _settings.Service; _mainScreenMode = "CONTINUE"; } else { await Values.EmptyDatabase(); await Values.CreateDatabase(); } } else { await Values.EmptyDatabase(); await Values.CreateDatabase(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { await Values.EmptyDatabase(); await Values.CreateDatabase(); } } else { await Values.CreateDatabase(); } // var intent = new Intent(this, typeof(MainScreen)); intent.PutExtra("MainScreenMode", _mainScreenMode); StartActivityForResult(intent, 1); //SetContentView(Resource.Layout.mainLayout); } else { Finish(); } } else { Finish(); } }
public async Task Add(string reading) { if (Context == null) { throw new Exception("Context not set"); } Processing = true; cData _data; //QRCODE if (reading.Length > 2 && reading.Substring(0, 2) == "@@" && reading.Substring(reading.Length - 2, 2) == "##") //QRCODE { var _readingFields = reading.Split('|'); if (Values.WorkMode == WorkModes.READING) { //"QRCODE|R GRAZ|07/02/2017|724008707|VCE15|303639641|KLT3215|U00045|L538|1000|W700530S300|STRAP 3-80X4.6 PLA||" reading = string.Format("%{0}%{1}%{2}", _readingFields[11], _readingFields[4], _readingFields[12]); } else { reading = _readingFields[5]; } } // CHECKING if ((reading.IsNumeric() && reading.Length == 9) || (reading.Substring(0, 1) == "S" && reading.Substring(1, 9).IsNumeric())) //checking { if (reading.Substring(0, 1) == "S" && reading.Substring(1, 9).IsNumeric()) { reading = reading.Substring(1, 9); } if (Values.WorkMode == WorkModes.READING) { cSounds.Error(Context); await AlertDialogHelper.ShowAsync(Context, "ERROR", "Current mode is READING, cannot process this data.", "OK", ""); Processing = false; return; } //check if serial is in list if (_dataList.OfType <dataChecking>().FirstOrDefault(r => r.Serial == reading) != null) { cSounds.Error(Context); Values.iFt.SetMessage(string.Format("Error: Serial {0} already checked.", reading)); Processing = false; return; } _data = new dataChecking() { Context = Context, Rack = Values.CurrentRack, Data = reading, Serial = reading }; if (await _data.doCheckings()) { _dataList.Add(_data); position++; //Values.sFt.CheckQtyReceived++; } _data.PushInfo(); Processing = false; return; } else // READING if (reading.Substring(0, 1) == "%") //reading { if (Values.WorkMode == WorkModes.CHECKING) { cSounds.Error(Context); await AlertDialogHelper.ShowAsync(Context, "ERROR", "Current mode is CHECKING, cannot process this data.", "OK", ""); Processing = false; return; } var _split = reading.Split('%'); string _pn = _split[1]; string _lr = _split[2]; string _ls = _split.Length == 4 ? _split[3] : ""; dataReading _r; bool newReading = false; //SAME READING QTY+1 if (position > -1 && Current() is dataReading) { _r = (dataReading)Current(); if (_r.Partnumber == _pn && _r.LabelRack == _lr && _r.LabelService == _ls) { _r.Qty++; await _r.doCheckings(); Current().UpdateCurrent(); Processing = false; return; } else { newReading = true; } } else { newReading = true; } if (newReading) { //NEW READING //get previous reading in the rack with the same data var itemToRemove = _dataList.SingleOrDefault(r => r is dataReading && ((dataReading)r).Partnumber == _pn && ((dataReading)r).LabelRack == _lr && ((dataReading)r).LabelService == _ls && (((dataReading)r).Status == dataStatus.READ || ((dataReading)r).Status == dataStatus.WARNING)); //var _query = from r in _dataList // where r is dataReading && ((dataReading)r).Partnumber == _pn && ((dataReading)r).LabelRack == _lr && ((dataReading)r).LabelService == _ls && (((dataReading)r).Status == dataStatus.READ || ((dataReading)r).Status == dataStatus.WARNING) // select r; //foreach (var d in _query) //_dataList.Remove(d); if (itemToRemove != null) { _dataList.Remove(itemToRemove); position--; } //_dataList.OfType<dataReading>().Select(r) => r.Partnumber=_pn && r.) _data = new dataReading() { Context = Context, Rack = Values.CurrentRack, Data = reading, Partnumber = _split[1], LabelRack = _split[2], LabelService = _split.Length == 4 ? _split[3] : "", Qty = 1 }; if (await _data.doCheckings()) { _dataList.Add(_data); position++; //Values.sFt.ReadQtyReceived++; } _data.PushInfo(); Processing = false; return; } } else //CLOSE CODE if (reading == Values.gCloseCode) { //set alert for executing the task bool dialogResult = await AlertDialogHelper.ShowAsync(Context, "Confirm Close Session", "This will close current session. Are you sure?", "Close Session", "Cancel"); if (!dialogResult) { ((Activity)Context).RunOnUiThread(() => { Toast.MakeText(Context, "Cancelled!", ToastLength.Short).Show(); }); Processing = false; return; } _data = new dataCloseSession() { Context = Context, Data = reading }; if (await _data.doCheckings()) { _dataList.Add(_data); //after close code we insert all reading from previous rack Values.dFt.SetMessage("Waiting for the pending data to be transmitted"); foreach (var r in _dataList.Where(r => r.Status == dataStatus.READ || r.Status == dataStatus.WARNING)) { await r.ToDB(); } Values.sFt.UpdateInfo(); //await Values.iFt.pushInfo("Waiting for the pending data to be transmitted"); while (true) { //SpinWait.SpinUntil(() => Values.SQLidb.pendingData && (monitor.State == NetworkState.ConnectedData || monitor.State == NetworkState.ConnectedWifi)); await Task.Delay(1000); if (Values.SQLidb.db.Table <ScannedData>().Where(r => r.Transmitted == false).CountAsync().Result == 0)//(Values.sFt.ReadQtyReceived == Values.sFt.ReadQtyTransmitted && Values.sFt.CheckQtyReceived == Values.sFt.CheckQtyTransmitted) { break; } } await Values.EmptyDatabase(); //clear info, debug and status fragments Values.iFt.Clear(); Values.dFt.Clear(); Values.sFt.Clear(); Values.hFt.Clear(); Values.gDatos.User = ""; Values.gDatos.Password = ""; Values.gSession = ""; Values.gService = ""; Values.gOrderNumber = 0; Values.gBlock = ""; _dataList.Clear(); position = -1; Values.SetCurrentRack(""); //change to enter order fragment var intent = new Intent(Context, typeof(MainActivity)); ((MainScreen)Context).StartActivityForResult(intent, 1); //Context.Dispose(); Processing = false; return; } } else //NEW READING QTY if (reading.IsNumeric()) { if (position > -1 && Current() is dataReading) { dataReading _r = (dataReading)Current(); _r.Qty = reading.ToInt(); await _r.doCheckings(); } else { cSounds.Error(Context); Processing = false; return; } cSounds.Scan(Context); Current().UpdateCurrent(); Processing = false; return; } else //NEW RACK CODE { if (reading == Values.CurrentRack) { ((Activity)Context).RunOnUiThread(() => { Toast.MakeText(Context, "Scanned Rack is the current one.", ToastLength.Short).Show(); cSounds.Error(Context); }); Processing = false; return; } _data = new dataChangeRack() { Context = Context, Data = reading }; if (await _data.doCheckings()) { //after new rack code we insert all reading from previous rack if (_dataList.Count != 0) { Values.dFt.SetMessage(string.Format("Transmitting Rack {0}", Values.CurrentRack)); foreach (var r in _dataList.Where(r => r.Status == dataStatus.READ || r.Status == dataStatus.WARNING)) { await r.ToDB(); } } _dataList.Add(_data); Values.sFt.UpdateInfo(); position++; //try //{ // await Values.dtm.Transfer(); //} //catch (Exception ex) //{ // await Values.dFt.pushInfo(ex.Message); //} } _data.PushInfo(); Processing = false; return; } }
public async Task AddData(string text, Context context) { if (Status == ReadingStatusEnum.FINISHED) { Status = ReadingStatusEnum.TROLL; } //ticket var ticketPattern = @"(.*)(?:\ +|%)(\d\d\d\d)(?:\ +|%)(.*)"; var ticketMatch = Regex.Match(text, ticketPattern); if (ticketMatch.Success) //ticket { if (Status != ReadingStatusEnum.TICKET) { throw new Exception($"Wrong data, expecting {Status.ToString()}"); } var ticketVINNr = ticketMatch.Groups[1].ToString().Replace("%", ""); var ticketSequenceNumber = ticketMatch.Groups[2].ToString().Replace("%", ""); var ticketPartnumberSeqLabel = ticketMatch.Groups[3].ToString().Replace("%", "").Replace(" ", ""); //check if already read if (await SQLidb.db.Table <Tickets>().FirstOrDefaultAsync(o => o.SequenceNumber == ticketSequenceNumber && o.TicketVIN == ticketVINNr && o.TicketPartnumber == ticketPartnumberSeqLabel) != null) { throw new Exception($"This Ticket has already been read today in a different session."); } if (await SQLidb.db.Table <ScannedData>().Where(o => o.VINNr == ticketVINNr && o.SequenceNumber == ticketSequenceNumber && o.PartnumberSeqLabel == ticketPartnumberSeqLabel).CountAsync() != 0) { throw new Exception($"Wrong ticket, already scanned."); } if (ticketSequenceNumber == "0001" && tFt.Trolley.UsedGaps != 0) { bool dialogResult = await AlertDialogHelper.ShowAsync(context, "New sequence number start", "This sequence means the end of the previous day and the start of a new group of sequence numbers. Are you sure?", "Yes", "No"); if (!dialogResult) { throw new Exception($"Cancelled the new sequence number group."); } } var _usedGaps = tFt.Trolley.UsedGaps; if (ticketSequenceNumber != "0001" && _usedGaps != 0) { var _prevSeqNum = tFt.Trolley[_usedGaps].SequenceNumber; if (Convert.ToInt32(ticketSequenceNumber) != (Convert.ToInt32(_prevSeqNum) + 1)) { throw new Exception($"Wrong ticket, Sequence Numbers should be consecutive or 0001."); } } CurrentData.VINNr = ticketVINNr; CurrentData.SequenceNumber = ticketSequenceNumber; CurrentData.PartnumberSeqLabel = ticketPartnumberSeqLabel; iFt.InfoSeqNr.Text = $"SeqNr: { CurrentData.SequenceNumber}"; iFt.InfoVIN.Text = $"VIN: { CurrentData.VINNr}"; iFt.InfoPartnumber.Text = $"Partnumber: { CurrentData.PartnumberSeqLabel}"; return; } //trolley var trollPattern = "(T..)-(..)"; var trollMatch = Regex.Match(text, trollPattern); if (trollMatch.Success) //troll { if (Status != ReadingStatusEnum.TROLL) { throw new Exception($"Wrong data, expecting {Status.ToString()}"); } var _previousGap = Convert.ToInt32(CurrentGap?.Substring(1, 2) ?? "0"); var _curGap = trollMatch.Groups[2].ToString(); if ((tFt.Trolley.Gaps[$"g{_curGap}"].Status != GapStatus.ERASED) && Convert.ToInt32(_curGap) != _previousGap + 1) { throw new Exception($"Wrong gap, please follow order, next gap expected is {_previousGap + 1}"); } CurrentGap = $"g{_curGap}"; if (CurrentTrolley == null) { CurrentTrolley = trollMatch.Groups[1].ToString(); hFt.t3.Text = $"Trolley: {CurrentTrolley}"; hFt.t4.Text = $"Gap: {CurrentGap}"; } else if (CurrentTrolley != trollMatch.Groups[1].ToString()) { throw new Exception($"Wrong trolley, expecting {CurrentTrolley}"); } CurrentGap = $"g{trollMatch.Groups[2].ToString()}"; if (await SQLidb.db.Table <ScannedData>().Where(o => o.TrollLocation == text).CountAsync() != 0) { //if (Values.DataReadingList.OfType<ScannedData>().Where(o => o.TrollLocation==text).Count() != 0) throw new Exception($"Wrong trolley, already scanned."); } CurrentData.TrollLocation = text; iFt.Clear(); iFt.InfoTrolley.Text = $"Trolley: {text}"; tFt.SetStatus(CurrentGap, GapStatus.FILLING); return; } //if (text==) //QTY //{ // if (Status != ReadingStatusEnum.QTY) // throw new Exception($"Wrong data, expecting {Status.ToString()}"); // CurrentData.Qty = text.ToInt(); // iFt.InfoQTY.Text = "Qty: "+ text; // return; //} //partnumber if (Status == ReadingStatusEnum.PARTNUMBER) { if (text == "icugoxaco9") { CurrentData.Qty = 0; CurrentData.PartnumberLabel = "NO-STOCK"; //iFt.InfoPartnumber.Text = $"Partnumber: {partnumber}✓"; iFt.InfoBatch.Text = $"Batch: --"; iFt.InfoQTY.Text = "Qty: NO STOCK"; return; } var labelPattern = @"(.*)(?:\r\n|\r|\n)(.*)(?:\r\n|\r|)"; var match = Regex.Match(text, labelPattern, RegexOptions.Singleline); if (!match.Success) { throw new Exception($"'{text}' wrong data, expecting {Status.ToString()}"); } var partnumber = match.Groups[1].ToString(); var batch = match.Groups[2].ToString(); if (!partnumber.Contains(CurrentData.PartnumberSeqLabel)) { throw new Exception($"Wrong partnumber, does not match ticket."); } CurrentData.PartnumberLabel = partnumber; CurrentData.Batch = batch; CurrentData.Qty = 1; iFt.InfoPartnumber.Text = $"Partnumber: {partnumber}✓"; iFt.InfoBatch.Text = $"Batch: {batch}"; iFt.InfoQTY.Text = "Qty: OK"; return; } throw new Exception($"'{text}' wrong data, expecting {Status.ToString()}"); }