Exemple #1
0
        private string AddDataToMyDb()
        {
            using (var db = new SQLite.SQLiteConnection(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "bancoteste.db3")))
            {
                foreach (var item in ResultCategory)
                {
                    Categoria itemCategory = new Categoria
                    {
                        Id   = item.Id,
                        Name = item.Name
                    };
                    db.InsertOrReplace(itemCategory);
                }
                //int i = 0;
                foreach (var item in ResultPromotion)
                {
                    List <Policies> ListPolicies  = new List <Policies>();
                    Promotion       itemPromotion = new Promotion
                    {
                        //Id = null,
                        Name       = item.Name,
                        CategoryId = item.Category_id
                    };
                    foreach (var subItem in item.Policies)
                    {
                        Policies itemPolicies = new Policies
                        {
                            //Id = null,
                            Min      = subItem.Min,
                            Discount = subItem.Discount
                        };
                        db.InsertOrReplace(itemPolicies);
                        ListPolicies.Add(itemPolicies);
                    }
                    db.InsertOrReplace(itemPromotion);
                    itemPromotion.PoliciesId = ListPolicies;
                    WriteOperations.UpdateWithChildren(db, itemPromotion);
                    //db.
                }

                foreach (var item in ResultProduct)
                {
                    Product itemProduct = new Product
                    {
                        //Id = null,
                        Name        = item.Name,
                        Photo       = ConvertPngToJpeg(item.Photo),
                        Price       = item.Price,
                        Description = item.Description,
                        CategoryId  = item.Category_id
                    };
                    db.InsertOrReplace(itemProduct);
                }
            }
            return("terminou");
        }
        // ***** NewsItemTable methods

        static public bool updateDBWithJSON(string jsonString)
        {
            //Console.WriteLine("jsonString: " + jsonString);
            itemList = JsonConvert.DeserializeObject <List <NewsItem> >(jsonString);
            //categorisedItemList = JsonConvert.DeserializeObject<List<NewsItem>>(jsonString);
            //categorisedItemList.AddRange(itemList);
            db.RunInTransaction(() =>
            {
                foreach (var item in itemList)
                {
                    db.InsertOrReplace(item);
                }
            });
            return(true);
        }
Exemple #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Informacje newInfo = new Informacje()
            {
                Id         = 1,
                Wlasciciel = Owner.Text,
                Adres      = Address.Text,
                Telefon    = PhoneNumber.Text,
                Fax        = Fax.Text,
                Kasjerzy   = Cashiers.Text,
                Myjnia     = Wash_Stuff.Text,
                Monitoring = Monitoring_Stuff.Text,
                ObslugaLPG = LPG_Stuff.Text
            };

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
            {
                conn.CreateTable <Informacje>();
                conn.InsertOrReplace(newInfo);
            }

            MessageBox.Show("Zaktualizowano.");
            MainWindow mainWindow = new MainWindow(_loggedInAccount);

            this.Close();
            mainWindow.Show();
        }
            public Task <bool> UpdateAsync(IActiveLock activeLock, CancellationToken cancellationToken)
            {
                var entry = ToEntry(activeLock);

                _connection.InsertOrReplace(entry);
                return(Task.FromResult(true));
            }
        /// <inheritdoc />
        protected override Task <EntityTag> UpdateDeadETagAsync(IEntry entry, CancellationToken cancellationToken)
        {
            var etag = new EntityTag(false);
            var key  = GetETagProperty.PropertyName;
            var prop = new PropertyEntry()
            {
                Id       = CreateId(key, entry),
                Language = null,
                Path     = entry.Path.ToString(),
                XmlName  = key.ToString(),
                Value    = etag.ToXml().ToString(SaveOptions.OmitDuplicateNamespaces),
            };

            _connection.InsertOrReplace(prop);
            return(Task.FromResult(etag));
        }
        public async Task UpdateAsync(DateTime dateTime)
        {
            using (var dbConnection = new SQLiteConnection(_dbUnitAndroidPrinterApp))
            {
                TypeWorkDB[] typesWork = await GetTypesWorkAsync();
                PrinterEntryDB[] printerEntrys = await GetAllPrinterEntryAsync(dateTime.ToString("yyyy-MM-dd"));
                AccountDB[] accounts = await GetAllAccountAsync();

                dbConnection.RunInTransaction(() =>
                {
                    foreach (var item in printerEntrys)
                        dbConnection.InsertOrReplace(item);
                    foreach (var item in accounts)
                        dbConnection.InsertOrReplace(item);
                    foreach (var item in typesWork)
                        dbConnection.InsertOrReplace(item);
                    dbConnection.InsertOrReplace(new LastModifyDateDB() { id = 0, LastModifyDate = dateTime });
                });
            }
        }
 private static void InsertFood(SQLiteConnection db)
 {
     db.InsertOrReplace(new GameObject()
     {
         GameObjectId = (int)GameObjectEnum.Apple,
         ObjectName = "Apple",
         Description = "Healthy apple",
         HealthEffect = 5,
         HungerEffect = 5,
         HygeneEffect = 0,
         DisciplineEffect = 0,
         MoodEffect = 5,
         EnergyEffect = 3,
     });
     db.InsertOrReplace(new GameObject()
     {
         GameObjectId = (int)GameObjectEnum.Burger,
         ObjectName = "Burger",
         Description = "Lotsofcaloriesburger, with cheese and stuff!",
         HealthEffect = -5,
         HungerEffect = 10,
         HygeneEffect = -2,
         DisciplineEffect = -10,
         MoodEffect = 5,
         EnergyEffect = 6,
     });
     db.InsertOrReplace(new GameObject()
     {
         GameObjectId = (int)GameObjectEnum.Watter,
         ObjectName = "Watter",
         Description = "A refreshing glass of watter",
         HealthEffect = 1,
         HungerEffect = 2,
         HygeneEffect = 0,
         DisciplineEffect = 0,
         MoodEffect = 3,
         EnergyEffect = 10,
     });
 }
Exemple #8
0
        private void CreateUserButton_Click(object sender, RoutedEventArgs e)
        {
            using (var connection = new SQLiteConnection(new Net.Platform.WinRT.SQLitePlatformWinRT(), path))
            {
                if (!TableExists <User>(connection))
                {
                    connection.CreateTable <User>(Net.Interop.CreateFlags.AutoIncPK);
                }

                connection.InsertOrReplace(new User()
                {
                    Name = this.NameTextBox.Text
                }, typeof(User));
                this.Users = new ObservableCollection <User>(connection.Table <User>().Select(i => i));
            }
        }
 public static async Task CreateDatabase()
 {
     // Create a new connection
     using (var db = new SQLiteConnection(DbPath))
     {
         // Activate Tracing
         db.Trace = true;
         // Create the table if it does not exist
         var c = db.CreateTable<Data>();
         Data data = new Data();
         data.DataID = 0;
         data.DataName = "Taxi";
         data.DataPrice = "5";
         StorageFile file = await StorageFile.GetFileFromPathAsync(Path.Combine(Package.Current.InstalledLocation.Path, @"Assets\Pictures\11th_Doctor.png"));
         var i = db.InsertOrReplace(data);
     }
 }
        private void UpdateData(object sender, RoutedEventArgs e)
        {
            Cennik updatedPrices = new Cennik();

            updatedPrices.Benzyna_E95      = double.Parse(E95.Text);
            updatedPrices.Benzyna_E98      = double.Parse(E98.Text);
            updatedPrices.Olej_napedowy_ON = double.Parse(ON.Text);
            updatedPrices.LPG = double.Parse(LPG.Text);
            updatedPrices.Mycie_standardowe = double.Parse(mstand.Text);
            updatedPrices.Mycie_z_woskiem   = double.Parse(mwosk.Text);

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
            {
                conn.CreateTable <Cennik>();
                conn.InsertOrReplace(updatedPrices);
            }

            MainWindow mainwindow = new MainWindow(_loggedInAccount);

            this.Close();
            mainwindow.Show();
        }
 private static void InsertObjects(SQLiteConnection db)
 {
     db.InsertOrReplace(new GameObject()
     {
         GameObjectId = (int)GameObjectEnum.Soap,
         ObjectName = "Soap",
         Description = "Take the soap and clean your pet",
         HealthEffect = 0,
         HungerEffect = 0,
         HygeneEffect = 15,
         DisciplineEffect = 0,
         MoodEffect = 0,
         EnergyEffect = 0,
     });
     db.InsertOrReplace(new GameObject()
     {
         GameObjectId = (int)GameObjectEnum.Book,
         ObjectName = "Book",
         Description = "Contains good education",
         HealthEffect = 0,
         HungerEffect = -15,
         HygeneEffect = -2,
         DisciplineEffect = 25,
         MoodEffect = -25,
         EnergyEffect = -10,
     });
     db.InsertOrReplace(new GameObject()
     {
         GameObjectId = (int)GameObjectEnum.Light,
         ObjectName = "Day and night",
         Description = "Put your pet to sleep or wake him up",
         HealthEffect = 5,
         HungerEffect = -5,
         HygeneEffect = 0,
         DisciplineEffect = 0,
         MoodEffect = -10,
         EnergyEffect = 5,
     });
     db.InsertOrReplace(new GameObject()
     {
         GameObjectId = (int)GameObjectEnum.Ball,
         ObjectName = "Play Ball!!",
         Description = "Play a little rugby!",
         HealthEffect = 2,
         HungerEffect = -15,
         HygeneEffect = 0,
         DisciplineEffect = -15,
         MoodEffect = 15,
         EnergyEffect = -25,
     });
     db.InsertOrReplace(new GameObject()
     {
         GameObjectId = (int)GameObjectEnum.Medkit,
         ObjectName = "Healing object",
         Description = "heal your pet",
         HealthEffect = 25,
         HungerEffect = -10,
         HygeneEffect = -10,
         DisciplineEffect = 0,
         MoodEffect = 10,
         EnergyEffect = 0,
     });
 }
        private void insertToDatabase(Book theBook)
        {
            var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            _pathToDatabase = Path.Combine(documents, _databaseName);

            using (var db = new SQLite.SQLiteConnection(_pathToDatabase ))
            {
                db.InsertOrReplace (theBook);
            }
            Console.Out.WriteLine ("Book " + newBook.getTitle () + " inserted into database.");

            // ui alert to let the user know
            var alert = UIAlertController.Create("Book Added!", "Hit the back button to see the book in your Book List.", UIAlertControllerStyle.Alert);

            // add buttons
            alert.AddAction(UIAlertAction.Create("Okay", UIAlertActionStyle.Default, null));

            // actually show the thing
            PresentViewController(alert, true, null);
        }
        private void Redeem4_Click(object sender, RoutedEventArgs e)
        {
            if (_loggedInAccount.Points > int.Parse(mycie_z_woskiem_nagrody_label.Content.ToString()))
            {
                Coupon newCoupon = new Coupon()
                {
                    Name  = "Mycie Woskiem",
                    Owner = _loggedInAccount.Email
                };
                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
                {
                    conn.CreateTable <Coupon>();
                    conn.Insert(newCoupon);
                }

                _loggedInAccount.Points = _loggedInAccount.Points - int.Parse(mycie_z_woskiem_nagrody_label.Content.ToString());

                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
                {
                    conn.CreateTable <Konto>();
                    conn.InsertOrReplace(_loggedInAccount);
                }

                using (SQLiteConnection conn3 = new SQLiteConnection(App.databasePath))
                {
                    conn3.CreateTable <ProgramLojalnościowy>();
                    prog_prices = (conn3.Table <ProgramLojalnościowy>().FirstOrDefault());

                    benzyna_e95label.Content                = prog_prices.benzyna_E95;
                    benzyna_e98label.Content                = prog_prices.benzyna_E98;
                    olej_napedowylabel.Content              = prog_prices.olej_nepedowy;
                    lpglabel.Content                        = prog_prices.lpg;
                    benzyna_on_nagrody_label.Content        = prog_prices.benzyna_on_nagrody;
                    lpg_nagrody_label.Content               = prog_prices.lpg_ngrody;
                    mycie_z_woskiemlabel.Content            = prog_prices.mycie_z_woskiem;
                    mycie_standardowelabel.Content          = prog_prices.mycie_standardowe;
                    mycie_standardowe_nagrody_label.Content = prog_prices.mycie_standardowe_nagrody;
                    mycie_z_woskiem_nagrody_label.Content   = prog_prices.mycie_z_woskiem_nagrody;
                }

                if (_loggedInAccount.Email != null)
                {
                    Konto AccountToUpdate = new Konto();

                    using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(App.databasePath))
                    {
                        AccountToUpdate = connection.Table <Konto>().FirstOrDefault(a => a.Email == _loggedInAccount.Email);
                    }
                    saldo.Content = AccountToUpdate.Points;

                    List <Coupon> coupons = new List <Coupon>();

                    using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(App.databasePath))
                    {
                        coupons = connection.Table <Coupon>().Where(n => n.Owner == _loggedInAccount.Email).ToList();
                    }
                    if (coupons != null)
                    {
                        this.CouponList.ItemsSource = coupons;
                        CouponList.SelectedItem     = coupons[0];
                    }
                }
            }
        }
        internal void CreateCatalogDatabaseAndInsertEntries(string dbFilename, Uri registryUrl, string registryCacheDirectory) {
            Directory.CreateDirectory(Path.GetDirectoryName(dbFilename));

            using (var db = new SQLiteConnection(dbFilename)) {
                // prevent errors from occurring when table doesn't exist
                db.RunInTransaction(() => {
                    db.CreateCatalogTableIfNotExists();
                    db.InsertOrReplace(new DbVersion() {
                        Id = _databaseSchemaVersion
                    });
                    db.InsertOrReplace(new RegistryFileMapping() {
                        RegistryUrl = registryUrl.ToString(),
                        DbFileLocation = registryCacheDirectory
                    });
                });
            }
        }
        internal void ParseResultsAndAddToDatabase(TextReader reader, string dbFilename, string registryUrl) {
            Directory.CreateDirectory(Path.GetDirectoryName(dbFilename));

            using (var db = new SQLiteConnection(dbFilename)) {
                db.RunInTransaction(() => {
                    db.CreateRegistryTableIfNotExists();

                    using (var jsonReader = new JsonTextReader(reader)) {
                        while (jsonReader.Read()) {
                            if (JsonToken.PropertyName != jsonReader.TokenType) {
                                continue;
                            }

                            if ((string)jsonReader.Value == "_updated") {
                                jsonReader.Read();
                                db.InsertOrReplace(new RegistryInfo() {
                                    RegistryUrl = registryUrl,
                                    Revision = (long)jsonReader.Value,
                                    UpdatedOn = DateTime.Now
                                });
                                continue;

                            }

                            var builder = new NodeModuleBuilder();
                            JToken token = null;

#if DEV14_OR_LATER
                            try {
#endif
                                token = JToken.ReadFrom(jsonReader);
#if DEV14_OR_LATER
                            } catch (JsonReaderException) {
                                // Reached end of file, so continue.
                                break;
                            }
#endif

                            var module = token.FirstOrDefault();
                            while (module != null) {
                                try {
                                    builder.Name = (string)module["name"];
                                    if (string.IsNullOrEmpty(builder.Name)) {
                                        continue;
                                    }

                                    builder.AppendToDescription((string)module["description"] ?? string.Empty);

                                    var time = module["time"];
                                    if (time != null) {
                                        builder.AppendToDate((string)time["modified"]);
                                    }

                                    var distTags = module["dist-tags"];
                                    if (distTags != null) {
                                        var latestVersion = distTags
                                            .OfType<JProperty>()
                                            .Where(v => (string)v.Name == "latest")
                                            .Select(v => (string)v.Value)
                                            .FirstOrDefault();

                                        if (!string.IsNullOrEmpty(latestVersion)) {
                                            try {
                                                builder.LatestVersion = SemverVersion.Parse(latestVersion);
                                            } catch (SemverVersionFormatException) {
                                                OnOutputLogged(String.Format(Resources.InvalidPackageSemVersion, latestVersion, builder.Name));
                                            }
                                        }
                                    }

                                    var versions = module["versions"];
                                    if (versions != null) {
                                        builder.AvailableVersions = GetVersions(versions);
                                    }

                                    AddKeywords(builder, module["keywords"]);

                                    AddAuthor(builder, module["author"]);

                                    AddHomepage(builder, module["homepage"]);

                                    var package = builder.Build();

                                    InsertCatalogEntry(db, package);
                                } catch (InvalidOperationException) {
                                    // Occurs if a JValue appears where we expect JProperty
                                } catch (ArgumentException) {
                                    OnOutputLogged(string.Format(Resources.ParsingError, builder.Name));
                                    if (!string.IsNullOrEmpty(builder.Name)) {
                                        var package = builder.Build();
                                        InsertCatalogEntry(db, package);
                                    }
                                }

                                builder.Reset();
#if DEV14_OR_LATER
                                try {
#endif
                                    token = JToken.ReadFrom(jsonReader);
#if DEV14_OR_LATER
                                } catch (JsonReaderException) {
                                    // Reached end of file, so continue.
                                    break;
                                }
#endif
                                module = token.FirstOrDefault();
                            }
                        }
                    }

                    // FTS doesn't support INSERT OR REPLACE. This is the most efficient way to bypass that limitation.
                    db.Execute("DELETE FROM CatalogEntry WHERE docid NOT IN (SELECT MAX(docid) FROM CatalogEntry GROUP BY Name)");
                });
            }
        }
Exemple #16
0
        /// <summary>
        /// Updates the resource.
        /// </summary>
        /// <param name="resourceFire">Resource fire.</param>
        /// <param name="resourceEarth">Resource earth.</param>
        /// <param name="resourceWater">Resource water.</param>
        /// <param name="resourceAir">Resource air.</param>
        /// <param name="resourceMagic">Resource magic.</param>
        /// <param name="resourceGold">Resource gold.</param>
        /// <param name="id">Identifier for the account.</param>
        public void UpdateResource(int resourceFire, int resourceEarth, int resourceWater, int resourceAir, int resourceMagic, int resourceGold, int id)
        {
            SQLiteConnection con = new SQLiteConnection(ServerConstants.DB_PATH);

               TableResource tr = new TableResource();
               tr.Id = id;
               tr.Fire = resourceFire;
               tr.Earth = resourceEarth;
               tr.Water = resourceWater;
               tr.Air = resourceAir;
               tr.Magic = resourceMagic;
               tr.Gold = resourceGold;

               con.InsertOrReplace(tr);
        }
Exemple #17
0
        /// <summary>
        /// Updates the unit.
        /// </summary>
        /// <param name="unitEntity">Unit entity.</param>
        /// <param name="id">Identifier for the account.</param>
        public void UpdateUnit(Entity unitEntity, int id)
        {
            SQLiteConnection con = new SQLiteConnection(ServerConstants.DB_PATH);

               TableUnit tu = new TableUnit();
               tu.Id = id;
               tu.PositionX = unitEntity.Position.X;
               tu.PositionY = unitEntity.Position.Y;

               con.InsertOrReplace(tu);
        }
        internal void ParseResultsAndAddToDatabase(TextReader reader,
                                                   string dbFilename,
                                                   string registryUrl) {

            Directory.CreateDirectory(Path.GetDirectoryName(dbFilename));

            using (var db = new SQLiteConnection(dbFilename)) {
                db.RunInTransaction(() => {
                    db.CreateRegistryTableIfNotExists();

                    using (var jsonReader = new JsonTextReader(reader)) {
                        /*
                        The schema seems to have changed over time.

                        The first format we need to handle is an object literal. It
                        starts with an "_updated" property, with a value of the
                        timestamp it was retrived, and then a property for each
                        package, with a name of the package name, and a value which
                        is on object literal representing the package info. An example
                        downloaded may start:

{
"_updated": 1413573404788,
"unlink-empty-files": {
  "name": "unlink-empty-files",
  "description": "given a directory, unlink (remove) all files with a length of 0",
  "dist-tags": { "latest": "1.0.1" },
  "maintainers": [
    {
      "name": "kesla",
etc.

                        The other format is an array literal, where each element is an
                        object literal for a package, similar to the value of the
                        properties above, for example:

[
{"name":"008-somepackage","description":"Test Package","dist-tags":{"latest":"1.1.1"}..
,
{"name":"01-simple","description":"That is the first app in order to study the ..."
,
etc.

                        In this second format, there is no "_updated" property with a
                        timestamp, and the 'Date' timestamp from the HTTP request for
                        the data is used instead.

                        The NPM code that handles the payload seems to be written in
                        a way to handle both formats
                        See https://github.com/npm/npm/blob/2.x-release/lib/cache/update-index.js#L87
                        */
                        jsonReader.Read();
                        switch (jsonReader.TokenType) {
                            case JsonToken.StartObject:
                                ReadPackagesFromObject(db, jsonReader, registryUrl);
                                break;
                            case JsonToken.StartArray:
                                // The array format doesn't contain the "_update" field,
                                // so create a rough timestamp. Use the time from 30 mins
                                // ago (to set it before the download request started),
                                // converted to a JavaScript value (milliseconds since
                                // start of 1970)
                                var timestamp = DateTime.UtcNow
                                    .Subtract(new DateTime(1970, 1, 1, 0, 30, 0, DateTimeKind.Utc))
                                    .TotalMilliseconds;
                                ReadPackagesFromArray(db, jsonReader);
                                db.InsertOrReplace(new RegistryInfo() {
                                    RegistryUrl = registryUrl,
                                    Revision = (long)timestamp,
                                    UpdatedOn = DateTime.Now
                                });
                                break;
                            default:
                                throw new JsonException("Unexpected JSON token at start of NPM catalog data");
                        }
                    }

                    // FTS doesn't support INSERT OR REPLACE. This is the most efficient way to bypass that limitation.
                    db.Execute("DELETE FROM CatalogEntry WHERE docid NOT IN (SELECT MAX(docid) FROM CatalogEntry GROUP BY Name)");
                });
            }
        }
Exemple #19
0
        /// <summary>
        /// Updates the building.
        /// </summary>
        /// <param name="buildingEntity">Building entity.</param>
        /// <param name="id">Identifier for the account.</param>
        public void UpdateBuilding(Entity buildingEntity, int id)
        {
            SQLiteConnection con = new SQLiteConnection(ServerConstants.DB_PATH);

               TableBuilding tb = new TableBuilding();
               tb.Id = id;
               tb.PositionX = buildingEntity.Position.X;
               tb.PositionY = buildingEntity.Position.Y;

               con.InsertOrReplace(tb);
        }
        private void ReadPackagesFromObject(SQLiteConnection db,
                                            JsonTextReader jsonReader,
                                            string registryUrl) {
            var builder = new NodeModuleBuilder();
            while (jsonReader.Read()) {
                if (jsonReader.TokenType == JsonToken.EndObject) {
                    // Reached the end of the object literal containing the data.
                    // This should be the normal exit point.
                    return;
                }

                // Every property should be either the "_updated" value, or a package
                if (jsonReader.TokenType != JsonToken.PropertyName) {
                    throw new JsonException("Unexpected JSON token in NPM catalog data");
                }
                string propertyName = (string)jsonReader.Value;

                // If it's "_updated", update the revision info.
                if (propertyName.Equals("_updated", StringComparison.Ordinal)) {
                    jsonReader.Read();
                    db.InsertOrReplace(new RegistryInfo() {
                        RegistryUrl = registryUrl,
                        Revision = (long)jsonReader.Value,
                        UpdatedOn = DateTime.Now
                    });
                    continue;
                }

                // Else the property should be an object literal representing the package
                jsonReader.Read();
                if (jsonReader.TokenType == JsonToken.StartObject) {
                    IPackage package = ReadPackage(jsonReader, builder);
                    if (package != null) {
                        InsertCatalogEntry(db, package);
                    }
                } else {
                    throw new JsonException("Unexpected JSON token reading a package from the NPM catalog data");
                }
            }
            throw new JsonException("Unexpected end of stream reading the NPM catalog data object");
        }
Exemple #21
0
        private void SaveInvoice(object sender, RoutedEventArgs e)
        {
            Invoices newInvoice = new Invoices()
            {
                email        = selectedEmail,
                CouponUsed   = SelectedCoupon.Name,
                Nazwa_firmy  = this.FirmaTxtBox.Text,
                Imie         = this.ImieTxtBox.Text,
                Nazwisko     = this.NazwiskoTxtBox.Text,
                Ulica        = this.UlicaTxtBox.Text,
                Numer        = this.NumberTxtBox.Text,
                Miasto       = this.MiastoTxtBox.Text,
                Kod_pocztowy = this.KodTxtBox.Text,
                BenzynaE95   = double.Parse(this.Be95txtBox.Text),
                BenzynaE98   = double.Parse(this.Be98txtBox.Text),
                OlejNapowy   = double.Parse(this.OlejtxtBox.Text),
                LPG          = double.Parse(this.LPGTxtBox.Text),
                TotalPrice   = totalPrice,
            };

            if (SelectedCoupon != null)
            {
                if (SelectedCoupon.Name == "BE/ON")
                {
                    double        e95, e98, on;
                    List <double> numbers = new List <double>();
                    Dictionary <string, double> values = new Dictionary <string, double>();

                    using (SQLiteConnection conn2 = new SQLiteConnection(App.databasePath))
                    {
                        conn2.CreateTable <Cennik>();
                        prices = (conn2.Table <Cennik>().FirstOrDefault());

                        e95 = prices.Benzyna_E95;
                        e98 = prices.Benzyna_E98;
                        on  = prices.Olej_napedowy_ON;
                    }

                    if (int.Parse(Be95txtBox.Text) < 1)
                    {
                        e95 = 0;
                    }

                    if (int.Parse(Be98txtBox.Text) < 1)
                    {
                        e98 = 0;
                    }

                    if (int.Parse(OlejtxtBox.Text) < 1)
                    {
                        on = 0;
                    }

                    values.Add("e95", e95);
                    values.Add("e98", e98);
                    values.Add("on", on);

                    values.OrderBy(key => key.Value);
                    var meh = values.ToList();
                    if (meh[0].Key == "e95")
                    {
                        newInvoice.TotalPrice -= be95;
                        if (newInvoice.TotalPrice < 0)
                        {
                            newInvoice.TotalPrice = 0;
                        }


                        string command = $"delete from Coupon where id in ( select id FROM Coupon where name='BE/ON' AND Owner='{couponOwner}' Limit 1 )";
                        using (SQLiteConnection connection = new SQLiteConnection(App.databasePath))
                        {
                            SQLiteCommand cm = new SQLiteCommand(connection);
                            cm.CommandText = command;
                            cm.ExecuteNonQuery();
                        }
                    }
                    else if (meh[0].Key == "e98")
                    {
                        if (newInvoice.TotalPrice < 0)
                        {
                            newInvoice.TotalPrice = 0;
                        }


                        string command = $"delete from Coupon where id in ( select id FROM Coupon where name='BE/ON' AND  Owner='{couponOwner}'  Limit 1 )";
                        using (SQLiteConnection connection = new SQLiteConnection(App.databasePath))
                        {
                            SQLiteCommand cm = new SQLiteCommand(connection);
                            cm.CommandText = command;
                            cm.ExecuteNonQuery();
                        }
                    }
                    else if (meh[0].Key == "on")
                    {
                        newInvoice.TotalPrice -= on;
                        if (newInvoice.TotalPrice < 0)
                        {
                            newInvoice.TotalPrice = 0;
                        }

                        string command = $"delete from Coupon where id in ( select id FROM Coupon where name='BE/ON' AND  Owner='{couponOwner}'  Limit 1 )";
                        using (SQLiteConnection connection = new SQLiteConnection(App.databasePath))
                        {
                            SQLiteCommand cm = new SQLiteCommand(connection);
                            cm.CommandText = command;
                            cm.ExecuteNonQuery();
                        }
                    }
                }
                else if (SelectedCoupon.Name == "LPG")
                {
                    if (int.Parse(LPGTxtBox.Text) > 0)
                    {
                        newInvoice.TotalPrice -= lpg;
                        if (newInvoice.TotalPrice < 0)
                        {
                            newInvoice.TotalPrice = 0;
                        }

                        string command = $"delete from Coupon where id in ( select id FROM Coupon where name='LPG' AND  Owner='{couponOwner}'  Limit 1 )";
                        using (SQLiteConnection connection = new SQLiteConnection(App.databasePath))
                        {
                            SQLiteCommand cm = new SQLiteCommand(connection);
                            cm.CommandText = command;
                            cm.ExecuteNonQuery();
                        }
                    }
                }
            }

            if (newInvoice.TotalPrice != 0)
            {
                newInvoice.TotalPrice = Math.Truncate(newInvoice.TotalPrice * 100) / 100;
            }

            using (SQLiteConnection conn = new SQLiteConnection(App.databasePath))
            {
                conn.CreateTable <Invoices>();
                conn.Insert(newInvoice);
            }

            Data ube95, ube98, uon, ulpg;

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
            {
                ube95 = conn.Table <Data>().Where(f => f.FuelName == "be95").FirstOrDefault();
                ube98 = conn.Table <Data>().Where(f => f.FuelName == "be98").FirstOrDefault();
                uon   = conn.Table <Data>().Where(f => f.FuelName == "ON").FirstOrDefault();
                ulpg  = conn.Table <Data>().Where(f => f.FuelName == "LPG").FirstOrDefault();
            }

            ube95.Litres = ube95.Litres - int.Parse(Be95txtBox.Text);
            ube98.Litres = ube98.Litres - int.Parse(Be98txtBox.Text);
            uon.Litres   = uon.Litres - int.Parse(OlejtxtBox.Text);
            ulpg.Litres  = ulpg.Litres - int.Parse(LPGTxtBox.Text);


            string command5 = $"update  Data set litres= {ube95.Litres} where fuelname='be95'";
            string command6 = $"update  Data set litres= {ube98.Litres} where fuelname='be98'";
            string command7 = $"update  Data set litres= {uon.Litres} where fuelname='ON'";
            string command8 = $"update  Data set litres= {ulpg.Litres} where fuelname='LPG'";

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
            {
                SQLiteCommand cm = new SQLiteCommand(conn);
                cm.CommandText = command5;
                cm.ExecuteNonQuery();
            }
            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
            {
                SQLiteCommand cm = new SQLiteCommand(conn);
                cm.CommandText = command6;
                cm.ExecuteNonQuery();
            }
            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
            {
                SQLiteCommand cm = new SQLiteCommand(conn);
                cm.CommandText = command7;
                cm.ExecuteNonQuery();
            }
            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
            {
                SQLiteCommand cm = new SQLiteCommand(conn);
                cm.CommandText = command8;
                cm.ExecuteNonQuery();
            }

            this.FirmaTxtBox.Text          = "";
            this.ImieTxtBox.Text           = "";
            this.NazwiskoTxtBox.Text       = "";
            this.UlicaTxtBox.Text          = "";
            this.NumberTxtBox.Text         = "";
            this.MiastoTxtBox.Text         = "";
            this.KodTxtBox.Text            = "";
            this.Be95txtBox.Text           = "";
            this.Be98txtBox.Text           = "";
            this.OlejtxtBox.Text           = "";
            this.LPGTxtBox.Text            = "";
            CustomersComboBox.SelectedItem = customerList[0];
            // calculate points
            double be95_point, be98_point, on_point, lpg_point;

            using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(App.databasePath))
            {
                be95_point = connection.Table <ProgramLojalnościowy>().Select(s => s.benzyna_E95).FirstOrDefault();
                be98_point = connection.Table <ProgramLojalnościowy>().Select(s => s.benzyna_E98).FirstOrDefault();
                on_point   = connection.Table <ProgramLojalnościowy>().Select(s => s.olej_nepedowy).FirstOrDefault();
                lpg_point  = connection.Table <ProgramLojalnościowy>().Select(s => s.lpg).FirstOrDefault();
            }


            // update points
            Konto AccountToUpdate = new Konto();

            using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(App.databasePath))
            {
                AccountToUpdate = connection.Table <Konto>().FirstOrDefault(a => a.Email == selectedEmail);
            }

            AccountToUpdate.Points += ((int)be95_point) * (int)newInvoice.BenzynaE95 + (((int)be98_point) * (int)newInvoice.BenzynaE98)
                                      + (((int)on_point) * (int)newInvoice.OlejNapowy) + (((int)lpg_point) * (int)newInvoice.LPG);


            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
            {
                conn.CreateTable <Konto>();
                conn.InsertOrReplace(AccountToUpdate);
            }


            MessageBox.Show("Faktura dodana.");
            MainWindow mainwindow = new MainWindow(_loggedInAccount);

            mainwindow.Show();
            this.Close();
        }
        private void SaveInvoice(object sender, RoutedEventArgs e)
        {
            Invoices newInvoice = new Invoices()
            {
                email        = selectedEmail,
                CouponUsed   = SelectedCoupon.Name,
                Nazwa_firmy  = this.FirmaTxtBox.Text,
                Imie         = this.ImieTxtBox.Text,
                Nazwisko     = this.NazwiskoTxtBox.Text,
                Ulica        = this.UlicaTxtBox.Text,
                Numer        = this.NumberTxtBox.Text,
                Miasto       = this.MiastoTxtBox.Text,
                Kod_pocztowy = this.KodTxtBox.Text,
                Standardowe  = double.Parse(this.StandardowetxtBox.Text),
                Zwoskiem     = double.Parse(this.woskiemTxtBx.Text),
                TotalPrice   = totalPrice,
            };

            if (SelectedCoupon != null)
            {
                if (SelectedCoupon.Name == "Mycie Standardowe")
                {
                    if (int.Parse(StandardowetxtBox.Text) > 0)
                    {
                        newInvoice.TotalPrice -= mycie_stand;
                        if (newInvoice.TotalPrice < 0)
                        {
                            newInvoice.TotalPrice = 0;
                        }

                        string command = $"delete from Coupon where id in ( select id FROM Coupon where name='Mycie Standardowe' AND  Owner='{couponOwner}'  Limit 1 )";
                        using (SQLiteConnection connection = new SQLiteConnection(App.databasePath))
                        {
                            SQLiteCommand cm = new SQLiteCommand(connection);
                            cm.CommandText = command;
                            cm.ExecuteNonQuery();
                        }
                    }
                }
                else
                {
                    if (int.Parse(woskiemTxtBx.Text) > 0)
                    {
                        newInvoice.TotalPrice -= mycie_wosk;
                        if (newInvoice.TotalPrice < 0)
                        {
                            newInvoice.TotalPrice = 0;
                        }

                        string command = $"delete from Coupon where id in ( select id FROM Coupon where name='Mycie Woskiem' AND  Owner='{couponOwner}'  Limit 1 )";
                        using (SQLiteConnection connection = new SQLiteConnection(App.databasePath))
                        {
                            SQLiteCommand cm = new SQLiteCommand(connection);
                            cm.CommandText = command;
                            cm.ExecuteNonQuery();
                        }
                    }
                }
            }

            if (newInvoice.TotalPrice != 0)
            {
                newInvoice.TotalPrice = Math.Truncate(newInvoice.TotalPrice * 100) / 100;
            }

            using (SQLiteConnection conn = new SQLiteConnection(App.databasePath))
            {
                conn.CreateTable <Invoices>();
                conn.Insert(newInvoice);
            }

            this.FirmaTxtBox.Text          = "";
            this.ImieTxtBox.Text           = "";
            this.NazwiskoTxtBox.Text       = "";
            this.UlicaTxtBox.Text          = "";
            this.NumberTxtBox.Text         = "";
            this.MiastoTxtBox.Text         = "";
            this.KodTxtBox.Text            = "";
            this.StandardowetxtBox.Text    = "";
            this.woskiemTxtBx.Text         = "";
            CustomersComboBox.SelectedItem = customerList[0];

            double standard_point, woskiem_point;

            using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(App.databasePath))
            {
                standard_point = connection.Table <ProgramLojalnościowy>().Select(s => s.mycie_standardowe).FirstOrDefault();
                woskiem_point  = connection.Table <ProgramLojalnościowy>().Select(s => s.mycie_z_woskiem).FirstOrDefault();
            }

            Konto AccountToUpdate = new Konto();

            using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(App.databasePath))
            {
                AccountToUpdate = connection.Table <Konto>().FirstOrDefault(a => a.Email == selectedEmail);
            }

            AccountToUpdate.Points += ((int)standard_point * (int)newInvoice.Standardowe) + ((int)woskiem_point * (int)newInvoice.Zwoskiem);

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath))
            {
                conn.CreateTable <Konto>();
                conn.InsertOrReplace(AccountToUpdate);
            }

            MessageBox.Show("Faktura dodana.");
            MainWindow mainwindow = new MainWindow(_loggedInAccount);

            mainwindow.Show();
            this.Close();
        }
        private static void InsertStages(SQLiteConnection db)
        {
            db.InsertOrReplace(new Stage()
            {
                StageId = (int)StageEnum.Egg,
                AgeFrom = 0,
                AgeTo = 1,
                HealthInterval = 14,
                HealthCoeff = 3,
                HungerInterval = 3,
                HungerCoeff = 2,
                HygeneInterval = 2,
                HygeneCoeff = 1,
                DisciplineInterval = 3,
                DisciplineCoeff = 2,
                MoodInterval = 1,
                MoodCoeff = 2,
                EnergyInterval = 2,
                EnergyCoeff = 1
            });

            db.InsertOrReplace(new Stage()
            {
                StageId = (int)StageEnum.Baby,
                AgeFrom = 1,
                AgeTo = 6,
                HealthInterval = 14,
                HealthCoeff = 1,
                HungerInterval = 10,
                HungerCoeff = 2,
                HygeneInterval = 10,
                HygeneCoeff = 3,
                DisciplineInterval = 0,
                DisciplineCoeff = 0,
                MoodInterval = 10,
                MoodCoeff = 2,
                EnergyInterval = 10,
                EnergyCoeff = 3
            });
            db.InsertOrReplace(new Stage()
            {
                StageId = (int)StageEnum.Child,
                AgeFrom = 6,
                AgeTo = 11,
                HealthInterval = 10,
                HealthCoeff = 3,
                HungerInterval = 14,
                HungerCoeff = 2,
                HygeneInterval = 10,
                HygeneCoeff = 3,
                DisciplineInterval = 10,
                DisciplineCoeff = 4,
                MoodInterval = 10,
                MoodCoeff = 4,
                EnergyInterval = 10,
                EnergyCoeff = 3
            });
            db.InsertOrReplace(new Stage()
            {
                StageId = (int)StageEnum.Teen,
                AgeFrom = 11,
                AgeTo = 21,
                HealthInterval = 10,
                HealthCoeff = 4,
                HungerInterval = 10,
                HungerCoeff = 3,
                HygeneInterval = 14,
                HygeneCoeff = 3,
                DisciplineInterval = 14,
                DisciplineCoeff = 3,
                MoodInterval = 14,
                MoodCoeff = 3,
                EnergyInterval = 14,
                EnergyCoeff = 2
            });
            db.InsertOrReplace(new Stage()
            {
                StageId = (int)StageEnum.Adult,
                AgeFrom = 21,
                AgeTo = 50,
                HealthInterval = 14,
                HealthCoeff = 4,
                HungerInterval = 14,
                HungerCoeff = 4,
                HygeneInterval = 14,
                HygeneCoeff = 2,
                DisciplineInterval = 14,
                DisciplineCoeff = 1,
                MoodInterval = 14,
                MoodCoeff = 3,
                EnergyInterval = 14,
                EnergyCoeff = 3
            });
            db.InsertOrReplace(new Stage()
            {
                StageId = (int)StageEnum.Senior,
                AgeFrom = 50,
                AgeTo = 999,
                HealthInterval = 10,
                HealthCoeff = 2,
                HungerInterval = 14,
                HungerCoeff = 2,
                HygeneInterval = 10,
                HygeneCoeff = 3,
                DisciplineInterval = 14,
                DisciplineCoeff = 2,
                MoodInterval = 14,
                MoodCoeff = 3,
                EnergyInterval = 10,
                EnergyCoeff = 3
            });
        }
        private static void InsertText(SQLiteConnection db)
        {
            db.DeleteAll<SayText>();
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 1,
                From = 0,
                To = 25,
                Parametter = (int)ParameterEnum.Health,
                Text = "I'm feeling\n very \nvery sick! :("
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 2,
                From = 25,
                To = 50,
                Parametter = (int)ParameterEnum.Health,
                Text = "Please take\n me to doctor!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 3,
                From = 50,
                To = 75,
                Parametter = (int)ParameterEnum.Health,
                Text = "An apple\n or watter\n would be nice!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 4,
                From = 75,
                To = 100,
                Parametter = (int)ParameterEnum.Health,
                Text = "I've feel\n very healthy!\n :) Thank you!"
            });

            db.InsertOrReplace(new SayText()
            {
                SayTextId = 5,
                From = 0,
                To = 25,
                Parametter = (int)ParameterEnum.Hunger,
                Text = "I could\n eat a horse!\n PLEASE FEED ME!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 6,
                From = 25,
                To = 50,
                Parametter = (int)ParameterEnum.Hunger,
                Text = "I want\n a burger!!\n NOW!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 7,
                From = 50,
                To = 75,
                Parametter = (int)ParameterEnum.Hunger,
                Text = "I would\n like\n something\n to eat, Please! ;)"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 8,
                From = 75,
                To = 100,
                Parametter = (int)ParameterEnum.Hunger,
                Text = "Thank you\n for feeding me,\n I Love YOU! :)"
            });

            db.InsertOrReplace(new SayText()
            {
                SayTextId = 9,
                From = 0,
                To = 25,
                Parametter = (int)ParameterEnum.Discipline,
                Text = "A. B..\n bebe\n boom \nbaam!!!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 10,
                From = 25,
                To = 50,
                Parametter = (int)ParameterEnum.Discipline,
                Text = "Read me a\n story, PLEASE!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 11,
                From = 50,
                To = 75,
                Parametter = (int)ParameterEnum.Discipline,
                Text = "I'm smart! :)"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 12,
                From = 75,
                To = 100,
                Parametter = (int)ParameterEnum.Discipline,
                Text = "In future\n I will be\n a rocket scientist!"
            });

            db.InsertOrReplace(new SayText()
            {
                SayTextId = 13,
                From = 0,
                To = 25,
                Parametter = (int)ParameterEnum.Energy,
                Text = "No..\n more..\n energy..\n"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 14,
                From = 25,
                To = 50,
                Parametter = (int)ParameterEnum.Energy,
                Text = "Sleep,\n I feel\n so sleepy!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 15,
                From = 50,
                To = 75,
                Parametter = (int)ParameterEnum.Energy,
                Text = "Let's play,\n let's do\n something!!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 16,
                From = 75,
                To = 100,
                Parametter = (int)ParameterEnum.Energy,
                Text = "WOOHOO!!!\n PARTY!!\n - I'm\n full of energy!"
            });

            db.InsertOrReplace(new SayText()
            {
                SayTextId = 17,
                From = 0,
                To = 25,
                Parametter = (int)ParameterEnum.Hygene,
                Text = "Ogh,\n whats that smell?\n Oh, it's me.\n CLEAN ME!!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 18,
                From = 25,
                To = 50,
                Parametter = (int)ParameterEnum.Hygene,
                Text = "I need a bath..."
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 19,
                From = 50,
                To = 75,
                Parametter = (int)ParameterEnum.Hygene,
                Text = "Hygene\n is very important,\n and I know it!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 20,
                From = 75,
                To = 100,
                Parametter = (int)ParameterEnum.Hygene,
                Text = "I feel\n clean like a unicorn!\n ^^"
            });

            db.InsertOrReplace(new SayText()
            {
                SayTextId = 21,
                From = 0,
                To = 25,
                Parametter = (int)ParameterEnum.Mood,
                Text = "I feel so lonely...\n I have nobody.. ;("
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 22,
                From = 25,
                To = 50,
                Parametter = (int)ParameterEnum.Mood,
                Text = "Wanna be fiends?\n Let's play!"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 23,
                From = 50,
                To = 75,
                Parametter = (int)ParameterEnum.Mood,
                Text = "This is fun!!\n I feel good! :D"
            });
            db.InsertOrReplace(new SayText()
            {
                SayTextId = 24,
                From = 75,
                To = 100,
                Parametter = (int)ParameterEnum.Mood,
                Text = "Today is a\n great day! Sun is shining\n ..and me to!"
            });
        }
Exemple #25
0
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();



            var selectedtab = "Economics, Business & Acc";

            View.BackgroundColor = UIColor.FromRGB(13, 13, 13);


            //creates BhasvicTitle
            var titleLabel = new UILabel(new CGRect(10, 20, View.Bounds.Width - 10, 30));

            titleLabel.Text      = "BHASVIC";
            titleLabel.Font      = UIFont.BoldSystemFontOfSize(20);
            titleLabel.TextColor = UIColor.LightTextColor;
            View.AddSubview(titleLabel);

            var homeButton = UIButton.FromType(UIButtonType.System);

            homeButton.Frame = new CGRect(100, 20, View.Bounds.Width - 10, 30);
            homeButton.SetTitle("HOME", UIControlState.Normal);
            View.AddSubview(homeButton);



            HttpClient client = new HttpClient();

            string startDate = DateTime.Now.AddDays(-100).ToString("yyyy-MM-dd");
            string endDate   = DateTime.Now.ToString("yyyy-MM-dd");


            Console.WriteLine(startDate);
            Console.WriteLine(endDate);
            string uriString = "https://www.bhasvic.ac.uk/umbraco/api/BHANewsPostservice/getPosts?start=" + startDate + "&end=" + endDate + "&student=true&public=false";



            Uri    uri        = new Uri(uriString);
            string jsonString = await client.GetStringAsync(uri);

            //var filename = Path.Combine(documents, "account.json");
            //ile.WriteAllText(filename, jsonString);

            //Console.WriteLine(jsonString);
            itemList = JsonConvert.DeserializeObject <List <NewsItem> >(jsonString);



            categorisedItemList = JsonConvert.DeserializeObject <List <NewsItem> >(jsonString);
            //categorisedItemList.AddRange(itemList);
            var documents       = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var _pathToDatabase = Path.Combine(documents, "db_sqlite-net.db");



            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string libraryPath   = Path.Combine(documentsPath, "../Library/");
            var    path          = Path.Combine(libraryPath, "MyDatabase.db3");

            Console.WriteLine(path);

            var db = new SQLite.SQLiteConnection(path);

            db.CreateTable <NewsItem>();



            db.RunInTransaction(() =>
            {
                foreach (var item in itemList)
                {
                    db.InsertOrReplace(item);
                }
            });
            //todo, create a new table after select period of time and omit old data



            var query = db.Table <NewsItem>().Where(v => v.Category.Equals("General"));

            foreach (var category in query)
            {
                Console.WriteLine("Category: " + category.Name);
            }

            //	var query = db.Query<NewsItem>("select * from NewsItem where Category = 'General'");
            //	Console.WriteLine(query.ToString());



            Console.WriteLine(categorisedItemList.ElementAt(0).Category);



            UITableView _table;

            _table = new UITableView
            {
                Frame           = new CGRect(-10, 60, View.Bounds.Width, (categorisedItemList.Count * 45)),
                BackgroundColor = UIColor.FromRGB(24, 24, 24)                   //	Source = new TableSource(itemList, NavigationController)
            };


            _table.WeakDataSource = this;
            _table.WeakDelegate   = this;
            View.AddSubview(_table);
        }
Exemple #26
0
 //------------------------------------------------------------------------//
 //used to replace an existing row
 public bool update_data(ShopItem data)
 {
     try
     {
         var db = new SQLiteConnection(m_db_path);
         //returns the number of rows affected
         if ( 0 == db.InsertOrReplace(data) )
         {
             return false;
         }
         return true;
     }
     catch (SQLiteException ex)
     {
         Console.WriteLine("exception handled while replacing data:{0}", ex.Message);
         return false;
     }
 }