Exemplo n.º 1
0
        /// <summary>
        /// Parse a recipe item from the current row.
        /// </summary>
        /// <param name="cursor">The database cursor, pointing to a valid query result row.</param>
        /// <returns>The parsed recipe item.</returns>
        private RecipeItem ParseRecipeItem(ICursor iter)
        {
            RecipeItem res     = new RecipeItem();
            Flavor     resFlav = new Flavor();

            res.Flavor     = resFlav;
            res.ID         = iter.GetInt(0);
            res.Percentage = iter.GetFloat(1);
            resFlav.ID     = iter.GetInt(2);
            resFlav.Name   = iter.GetString(3);
            resFlav.PG     = (iter.GetInt(4) > 0);
            resFlav.RecommendedPercentage = iter.GetFloat(5);

            return(res);
        }
Exemplo n.º 2
0
        public List <Item> get_itens(Context context)
        {
            DBAdapter   db     = new DBAdapter(context);
            List <Item> list   = new List <Item>();
            ICursor     cursor = db.search("item", new string[] { "*" }, null, null, null, null, "registration_date ASC");

            cursor = db.search("item", new string[] { "*" }, "_tripid = ?", new string[] { id.ToString() }, null, null, "registration_date ASC");

            if (cursor == null)
            {
                return(null);
            }

            cursor.MoveToFirst();

            do
            {
                Item i = new Item();

                i.id                = cursor.GetLong(0);
                i.trip_id           = cursor.GetLong(1);
                i.category_id       = cursor.GetLong(2);
                i.value             = cursor.GetFloat(3);
                i.details           = cursor.GetString(4);
                i.registration_date = DateTime.Parse(cursor.GetString(5));
                i.lastedit_date     = DateTime.Parse(cursor.GetString(6));

                list.Add(i);
            } while (cursor.MoveToNext());

            return(list);
        }
Exemplo n.º 3
0
        public static List <Trip> get_all(Context context)
        {
            DBAdapter   db   = new DBAdapter(context);
            List <Trip> list = new List <Trip>();
            //TODO
            ICursor cursor = db.search("trip", new string[] { "*" }, null, null, null, null, null);

            if (cursor == null)
            {
                return(null);
            }

            cursor.MoveToFirst();

            do
            {
                Trip t = new Trip();

                t.id                = cursor.GetLong(0);
                t.reward            = cursor.GetFloat(1);
                t.home              = cursor.GetString(1);
                t.destiny           = cursor.GetString(3);
                t.toll_value        = cursor.GetFloat(4);
                t.fuell_value       = cursor.GetFloat(5);
                t.freight           = cursor.GetString(6);
                t.registration_date = DateTime.Parse(cursor.GetString(7));
                t.lastedit_date     = DateTime.Parse(cursor.GetString(8));
                string tmp = cursor.GetString(9);
                if (tmp == "" || tmp == null)
                {
                    t.complete_date = null;
                }
                else
                {
                    t.complete_date = DateTime.Parse(tmp);
                }

                list.Add(t);
            } while (cursor.MoveToNext());

            return(list);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parse a flavor from the current row.
        /// </summary>
        /// <param name="cursor">The database cursor, pointing to a valid query result row.</param>
        /// <returns>The parsed flavor.</returns>
        private Flavor ParseFlavor(ICursor cursor)
        {
            Flavor res = new Flavor();

            res.ID   = cursor.GetInt(0);
            res.Name = cursor.GetString(1);
            res.PG   = (cursor.GetInt(2) > 0);
            res.RecommendedPercentage = cursor.GetFloat(3);

            return(res);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Parse a recipe from the current row.
        /// </summary>
        /// <param name="iter">The database cursor pointing to a row of a query.</param>
        /// <returns>The parsed recipe.</returns>
        private Recipe ParseRecipe(ICursor iter)
        {
            Recipe   res    = new Recipe();
            Nicotine resNic = new Nicotine();

            res.Nicotine         = resNic;
            res.ID               = iter.GetInt(0);
            res.Name             = iter.GetString(1);
            res.VG               = (byte)iter.GetInt(2);
            res.BatchSize        = iter.GetInt(3);
            res.TargetNicotine   = iter.GetFloat(4);
            resNic.ID            = iter.GetInt(5);
            resNic.Name          = iter.GetString(6);
            resNic.VG            = (byte)iter.GetInt(7);
            resNic.Concentration = iter.GetInt(8);

            return(res);
        }
Exemplo n.º 6
0
 public override float GetFloat(int column)
 {
     return(_queueCursor.GetFloat(column));
 }
Exemplo n.º 7
0
        /**
         * Update the properties for a file by it's cursor.
         * This method should be called in an interval and on reinitialization.
         */
        public void UpdateFileProperties(ICursor cursor, DownloadFileImplementation downloadFile)
        {
            downloadFile.TotalBytesWritten  = cursor.GetFloat(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnBytesDownloadedSoFar));
            downloadFile.TotalBytesExpected = cursor.GetFloat(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnTotalSizeBytes));

            switch ((DownloadStatus)cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnStatus)))
            {
            case DownloadStatus.Successful:
                downloadFile.DestinationPathName = cursor.GetString(cursor.GetColumnIndex("local_uri"));
                downloadFile.StatusDetails       = default(string);
                downloadFile.Status = DownloadFileStatus.COMPLETED;
                RemoveFile(downloadFile);
                break;

            case DownloadStatus.Failed:
                downloadFile.Status = DownloadFileStatus.FAILED;
                RemoveFile(downloadFile);

                var reasonFailed = cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnReason));
                if (reasonFailed < 600)
                {
                    downloadFile.StatusDetails = "Error.HttpCode: " + reasonFailed;
                }
                else
                {
                    switch ((DownloadError)reasonFailed)
                    {
                    case DownloadError.CannotResume:
                        downloadFile.StatusDetails = "Error.CannotResume";
                        break;

                    case DownloadError.DeviceNotFound:
                        downloadFile.StatusDetails = "Error.DeviceNotFound";
                        break;

                    case DownloadError.FileAlreadyExists:
                        downloadFile.StatusDetails = "Error.FileAlreadyExists";
                        break;

                    case DownloadError.FileError:
                        downloadFile.StatusDetails = "Error.FileError";
                        break;

                    case DownloadError.HttpDataError:
                        downloadFile.StatusDetails = "Error.HttpDataError";
                        break;

                    case DownloadError.InsufficientSpace:
                        downloadFile.StatusDetails = "Error.InsufficientSpace";
                        break;

                    case DownloadError.TooManyRedirects:
                        downloadFile.StatusDetails = "Error.TooManyRedirects";
                        break;

                    case DownloadError.UnhandledHttpCode:
                        downloadFile.StatusDetails = "Error.UnhandledHttpCode";
                        break;

                    case DownloadError.Unknown:
                        downloadFile.StatusDetails = "Error.Unknown";
                        break;

                    default:
                        downloadFile.StatusDetails = "Error.Unregistered: " + reasonFailed;
                        break;
                    }
                }
                break;

            case DownloadStatus.Paused:
                downloadFile.Status = DownloadFileStatus.PAUSED;

                var reasonPaused = cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnReason));
                switch ((DownloadPausedReason)reasonPaused)
                {
                case DownloadPausedReason.QueuedForWifi:
                    downloadFile.StatusDetails = "Paused.QueuedForWifi";
                    break;

                case DownloadPausedReason.WaitingToRetry:
                    downloadFile.StatusDetails = "Paused.WaitingToRetry";
                    break;

                case DownloadPausedReason.WaitingForNetwork:
                    downloadFile.StatusDetails = "Paused.WaitingForNetwork";
                    break;

                case DownloadPausedReason.Unknown:
                    downloadFile.StatusDetails = "Paused.Unknown";
                    break;

                default:
                    downloadFile.StatusDetails = "Paused.Unregistered: " + reasonPaused;
                    break;
                }
                break;

            case DownloadStatus.Pending:
                downloadFile.StatusDetails = default(string);
                downloadFile.Status        = DownloadFileStatus.PENDING;
                break;

            case DownloadStatus.Running:
                downloadFile.StatusDetails = default(string);
                downloadFile.Status        = DownloadFileStatus.RUNNING;
                break;
            }
        }
Exemplo n.º 8
0
        /**
         * Update the properties for a file by it's cursor.
         * This method should be called in an interval and on reinitialization.
         */
        public void UpdateFileProperties(ICursor cursor, DownloadFileImplementation downloadFile)
        {
            downloadFile.TotalBytesWritten  = cursor.GetFloat(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnBytesDownloadedSoFar));
            downloadFile.TotalBytesExpected = cursor.GetFloat(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnTotalSizeBytes));
            string reason = cursor.GetString(cursor.GetColumnIndex("reason"));

            switch ((DownloadStatus)cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnStatus)))
            {
            case DownloadStatus.Successful:
                string title    = cursor.GetString(cursor.GetColumnIndex("title"));
                string pathFile = cursor.GetString(cursor.GetColumnIndex("local_uri"));
                string type     = cursor.GetString(cursor.GetColumnIndex("media_type"));
                string path     = pathFile.Replace("file://", "");
                downloadFile.DestinationPathName = path;
                downloadFile.MimeType            = type;
                downloadFile.StatusDetails       = default(string);
                downloadFile.Status = DownloadFileStatus.COMPLETED;
                IDictionary <string, string> dict = new Dictionary <string, string>();
                dict.Add(DownloadFile_NotifyKey, path);
                dict.Add("type", type);
                RemoveFile(downloadFile);
                //CrossLocalNotifications_Droid.Current.PushNotify(
                //    downloadFile.NameFile,
                //     "Tải tập tin thành công",
                //    new Action<NotificationResult>(result => {
                //        if (result != null && result.Action == NotificationAction.Clicked)
                //        {
                //            IDocumentViewer documentViewer = DependencyService.Get<IDocumentViewer>();
                //            documentViewer.OpenFileDownloaded(path, type);
                //        }
                //    }),
                //    dict);
                break;

            case DownloadStatus.Failed:
                var reasonFailed = cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnReason));
                if (reasonFailed < 600)
                {
                    downloadFile.StatusDetails = "Error.HttpCode: " + reasonFailed;
                }
                else
                {
                    switch ((DownloadError)reasonFailed)
                    {
                    case DownloadError.CannotResume:
                        downloadFile.StatusDetails = "Error.CannotResume";
                        break;

                    case DownloadError.DeviceNotFound:
                        downloadFile.StatusDetails = "Error.DeviceNotFound";
                        break;

                    case DownloadError.FileAlreadyExists:
                        downloadFile.StatusDetails = "Error.FileAlreadyExists";
                        break;

                    case DownloadError.FileError:
                        downloadFile.StatusDetails = "Error.FileError";
                        break;

                    case DownloadError.HttpDataError:
                        downloadFile.StatusDetails = "Error.HttpDataError";
                        break;

                    case DownloadError.InsufficientSpace:
                        downloadFile.StatusDetails = "Error.InsufficientSpace";
                        break;

                    case DownloadError.TooManyRedirects:
                        downloadFile.StatusDetails = "Error.TooManyRedirects";
                        break;

                    case DownloadError.UnhandledHttpCode:
                        downloadFile.StatusDetails = "Error.UnhandledHttpCode";
                        break;

                    case DownloadError.Unknown:
                        downloadFile.StatusDetails = "Error.Unknown";
                        break;

                    default:
                        downloadFile.StatusDetails = "Error.Unregistered: " + reasonFailed;
                        break;
                    }
                }
                downloadFile.Status = DownloadFileStatus.FAILED;
                RemoveFile(downloadFile);
                //CrossLocalNotifications_Droid.Current.PushNotify(downloadFile.NameFile, "Tải tập tin không thành công", null);
                break;

            case DownloadStatus.Paused:
                var reasonPaused = cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnReason));
                switch ((DownloadPausedReason)reasonPaused)
                {
                case DownloadPausedReason.QueuedForWifi:
                    downloadFile.StatusDetails = "Paused.QueuedForWifi";
                    break;

                case DownloadPausedReason.WaitingToRetry:
                    downloadFile.StatusDetails = "Paused.WaitingToRetry";
                    break;

                case DownloadPausedReason.WaitingForNetwork:
                    downloadFile.StatusDetails = "Paused.WaitingForNetwork";
                    break;

                case DownloadPausedReason.Unknown:
                    downloadFile.StatusDetails = "Paused.Unknown";
                    break;

                default:
                    downloadFile.StatusDetails = "Paused.Unregistered: " + reasonPaused;
                    break;
                }
                downloadFile.Status = DownloadFileStatus.PAUSED;
                break;

            case DownloadStatus.Pending:
                downloadFile.StatusDetails = default(string);
                downloadFile.Status        = DownloadFileStatus.PENDING;
                break;

            case DownloadStatus.Running:
                downloadFile.StatusDetails = default(string);
                downloadFile.Status        = DownloadFileStatus.RUNNING;
                break;
            }
        }