private async void loadData()
        {
            //SQLiteAsyncConnection conn1 = new SQLiteAsyncConnection(System.IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, "Appointment.db"), true);

            
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection(System.IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, "Appointment.db"), true);
            conn.DropTableAsync<SampleAppointment>();

            await conn.CreateTableAsync<SampleAppointment>();

            DateTime temp = DateTime.Now;

            DateTime start = DateTime.Parse("06/08/2013 6:00 PM");
            DateTime end = DateTime.Parse("06/09/2013 6:00 PM");

            SampleAppointment appointment1 = new SampleAppointment
            {
                Subject = "MACF - App Camp",
                AdditionalInfo = "BRTN 291, RSVP Reguired",
                StartDate = start,
                EndDate = end
            };

            conn.InsertAsync(appointment1);

            SampleAppointment appointment2 = new SampleAppointment
            {
                StartDate = DateTime.Now.AddMinutes(30),
                EndDate = DateTime.Now.AddHours(1),
                Subject = "Appointment 376",
                AdditionalInfo = "Info 3"
            };

            conn.InsertAsync(appointment2);

            start = DateTime.Parse("06/05/2013 5:00 PM");
            end = DateTime.Parse("06/05/2013 6:00 PM");
            SampleAppointment appointment3 = new SampleAppointment
            {
                StartDate = DateTime.Now.AddHours(2),
                EndDate = DateTime.Now.AddHours(3),
                Subject = "Appointment uhy4",
                AdditionalInfo = "Info 4"
            };

            conn.InsertAsync(appointment3);

            SampleAppointment appointment4 = new SampleAppointment
            {
                Subject = "Malaysian Night",
                AdditionalInfo = "STEW Common, Members Only",
                StartDate = start,
                EndDate = end
            };

            conn.InsertAsync(appointment4);

            //this.OnDataLoaded();
        }
        public async Task <bool> SaveToDBAsync(FreeDiscItemDownload freeDiscDownloader)
        {
            if (freeDiscDownloader == null)
            {
                #if DEBUG
                Debug.Write("SaveToDBAsync: freeDiscDownloader == null");
                #endif
                return(false);
            }
            #if DEBUG
            Debug.Write("SaveToDB: ID" + freeDiscDownloader.DBID + " Title: " + freeDiscDownloader?.Title + " Status: " + freeDiscDownloader?.ItemStatus.ToString());
            #endif
            try
            {
                var conn = new SQLite.SQLiteAsyncConnection(App.AppSetting.DBDownloadPath);
                await conn.CreateTableAsync <FreeDiscItemDownload>();

                await conn.InsertAsync(freeDiscDownloader);
            }
            catch (Exception e)
            {
                #if DEBUG
                Debug.Write("SaveToDB: Save error !");
                #endif
                return(false);
            }
            #if DEBUG
            Debug.Write("SaveToDB: Result ID" + freeDiscDownloader?.DBID ?? "NULL");
            #endif
            return(true);
        }
        private static async Task SetValueAsyncInternal(string name, string value, SQLiteAsyncConnection conn)
        {
            // if we don't have a connection, assume the system one...
            if(conn == null)
			    conn = StreetFooRuntime.GetSystemDatabase();

			// load an existing value...
			var setting = await conn.Table<SettingItem>().Where(v => v.Name == name).FirstOrDefaultAsync();
			if (setting != null)
			{
				// change and update...
				setting.Value = value;
				await conn.UpdateAsync(setting);
			}
			else
			{
				setting = new SettingItem()
				{
					Name = name,
					Value = value
				};

				// save...
				await conn.InsertAsync(setting);
			}
        }
Example #4
0
		public async Task<int> AddVisit(Visit visit) {
			SQLiteAsyncConnection conn = new SQLiteAsyncConnection(this.dbPath);
			if (visit.ID > 0) {
				return await conn.UpdateAsync(visit);
			}
			return await conn.InsertAsync(visit);
		}
        private async void btnOK_Click(object sender, RoutedEventArgs e)
        {
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, "people.db"), true);

            Person person = new Person
            {
                DoctorName = watermarkTextBox.Text,
                Date = datepick.ValueString,
                Time = timepick.ValueString
             };

            await conn.InsertAsync(person);

            //My_Medi.ViewModels.MainViewModel veiw = new ViewModels.MainViewModel();

            //veiw.LoadData();
            DataContext = App.ViewModel;
            App.ViewModel.Items.Clear();
            App.ViewModel.LoadData();            
            

            NavigationService.GoBack();
            
            


        }
        public async Task WriteMessage(string messageString)
        {
            var message = new Message {MessageString = messageString};

            var connection = new SQLiteAsyncConnection(_databasePath);

            await connection.InsertAsync(message);
        }
Example #7
0
 private async void Button_Click_2(object sender, RoutedEventArgs e)
 {
     SQLiteAsyncConnection conn = new SQLiteAsyncConnection(ApplicationData.Current.LocalFolder.Path + "\\people.db");
     Person person = new Person
     {
         Name = "张三",
         Work = "程序员"
     };
     await conn.InsertAsync(person);
     Person person2 = new Person
     {
         Name = "李四",
         Work = "设计师"
     };
     await conn.InsertAsync(person2);
     MessageBox.Show("插入数据成功");
 }
 public async static Task InsertOrganization(Organization organization)
 {
     SQLiteAsyncConnection sqlConnection = new SQLiteAsyncConnection(DbHelper.DB_PATH);
     var collectionItem = await sqlConnection.Table<Organization>().Where(x => x.Id == organization.Id).FirstOrDefaultAsync();
     if (collectionItem == null)
     {
         await sqlConnection.InsertAsync(organization);
     }
 }
        public async Task AddOrUpdateCounterAsync(Counter counter)
        {
            var connection = new SQLiteAsyncConnection(_dbPath);
            if (counter.Id == 0)
                await connection.InsertAsync(counter);
            else
                await connection.InsertOrReplaceAsync(counter);

            OnCountersChanged();
        }
Example #10
0
        public static async void insertProduct(Product product)
        {
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection(PRODUCTS_TABLE);

            await conn.CreateTableAsync<Product>();

            await conn.InsertAsync(product);


        }
        // Favourites

        public static async Task<int> addFavouriteStop(OCDirection direction)
        {
            int result = 0;
            String path = ApplicationData.Current.LocalFolder.Path + "/OCTranspo.sqlite";
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection(path);
            await conn.InsertAsync(direction).ContinueWith((t) =>
           {
               result = t.Result;
           });
            return result;
        }
Example #12
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection("institutionFinder.db");
            await conn.InsertAsync(newColleges);

            // Add to the user list
            college.Add(newColleges);

            // Refresh user list
            searchColleges.ItemsSource = null;
            searchColleges.ItemsSource = college;
        }
Example #13
0
 /// <summary>
 /// Initialise the Database connection and creates tables/default values if not existant.
 /// </summary>
 private async void ConnectionInit()
 {
     //Connection init
     var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
     Database = new SQLite.SQLiteAsyncConnection(dbPath);
     //Create tables if not exists
     await Database.CreateTablesAsync(new Account().GetType(), new DatabaseRoute().GetType(), new DatabasePOI().GetType());
     await Database.ExecuteAsync("create table if not exists \"RouteBinds\"(\"RouteID\" integer,\"WaypointID\" integer);", new object[] { });
     //Set default Admin Admin password
     var result = await Database.ExecuteScalarAsync<String>("Select Gebruikersnaam From Account WHERE Gebruikersnaam = ? AND Password = ?", new object[] { "Admin", "Admin" });
     if(result == null)
         await Database.InsertAsync(new Account("Admin", "Admin"));
 }
 private async void Button_Click_2(object sender, RoutedEventArgs e)
 {
     var path = ApplicationData.Current.LocalFolder.Path + @"\Users.db";
     var db = new SQLiteAsyncConnection(path);
     var data = new User
     {
         name=txt_name.Text,
         email=txt_email.Text
     
     };
     int i = await db.InsertAsync(data);
    
 }
 private static async void createSettingsTable()
 {
     String path = ApplicationData.Current.LocalFolder.Path + "/OCTranspo.sqlite";
     SQLiteAsyncConnection conn = new SQLiteAsyncConnection(path);
     var count = await conn.ExecuteScalarAsync<int>("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='OCSettings'");
     if (count == 0)
     {
         await conn.CreateTableAsync<OCSettings>();
         OCSettings settings = OCSettings.newOCSettings(500);
         settings.id = 1;
         await conn.InsertAsync(settings);
     }
 }
Example #16
0
 private async Task<string> insertUpdateData(Person data, string path)
 {
     try
     {
         var db = new SQLiteAsyncConnection(path);
         if (await db.InsertAsync(data) != 0)
             await db.UpdateAsync(data);
         return "Single data file inserted or updated";
     }
     catch (SQLiteException ex)
     {
         return ex.Message;
     }
 }
        public async Task IncrementCounterAsync(Counter counter)
        {
            var connection = new SQLiteAsyncConnection(_dbPath);

            counter.Value++;
            await AddOrUpdateCounterAsync(counter);
            var history = new CounterIncrementHistory
            {
                CounterId = counter.Id,
                IncrementDateTimeUtc = DateTime.UtcNow
            };

            await connection.InsertAsync(history);
        }
Example #18
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {

            // Add row to the User Table
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection("institutionFinder.db");
            await conn.InsertAsync(newUser);

            // Add to the user list
            users.Add(newUser);

            // Refresh user list
            searchViewList.ItemsSource = null;
            searchViewList.ItemsSource = users;
           
        }
        private async void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            string idNo = txtIdNumber.Text;
            string name,surname,idNumber,contacts, address, email, password, province;
                name = txtName.Text;
                surname = txtSurname.Text;
                idNumber = txtIdNumber.Text;
                contacts = txtContacts.Text;
                address = txtAddress.Text;
                province = txtProvince.Text;
                email = txtEmail.Text;
                password = txtPassword.Text;



                if (name == "" && surname == "" && idNumber == "" && contacts == "" && address == "" && province == "" && email == "" && password == "")
                {
                    messageBox("make sure all field are filled with correct values");
                }
                else
                {
                    Enroll newUser = new Enroll()
                    {

                        name = txtName.Text,
                        surname = txtSurname.Text,
                        idNumber = txtIdNumber.Text,
                        contacts = txtContacts.Text,
                        address = txtAddress.Text,
                        province = txtProvince.Text,
                        email = txtEmail.Text,
                        password = txtPassword.Text
                    };
                    SQLiteAsyncConnection conn = new SQLiteAsyncConnection("Registers.db");
                    await conn.InsertAsync(newUser);
                    if (model.getUser(idNo) == null)
                    {
                        messageBox("You are not registered");
                    }
                    else
                    {
                        messageBox("You are successfully registered");
                    }
                }
            


        }
Example #20
0
 public async static Task InsertMenu(Menu menu)
 {
     SQLiteAsyncConnection sqlConnection = new SQLiteAsyncConnection(DbHelper.DB_PATH);
     var collectionItem = await sqlConnection.Table<Menu>().Where(x => x.MenuId == menu.MenuId && x.CounterId == menu.CounterId).FirstOrDefaultAsync();
     if (collectionItem != null)
     {
         if (collectionItem.Version < menu.Version)
         {
             await sqlConnection.UpdateAsync(menu);
         }
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("Menu Inserted: "+await sqlConnection.InsertAsync(menu));
     }
 }
Example #21
0
 public async static Task InsertCounter(Counter counter)
 {
     SQLiteAsyncConnection sqlConnection = new SQLiteAsyncConnection(DbHelper.DB_PATH);
     var collectionItem = await sqlConnection.Table<Counter>().Where(x => x.Id == counter.Id).FirstOrDefaultAsync();
     if (collectionItem != null)
     {
         if (collectionItem.MenuVersion != counter.MenuVersion)
         {
             await sqlConnection.UpdateAsync(counter);
         }
     }
     else
     {
         await sqlConnection.InsertAsync(counter);
     }
     await CounterSubscribed();
 }
Example #22
0
        public async Task<string> InsertUpdateDataAsync (UserVideo data)
        {
            try
            {
                var db = new SQLiteAsyncConnection (_path);

                if (await db.InsertAsync (data) != 0)
                    await db.UpdateAsync (data);
                
                return "Single data file inserted or updated";
            }
            catch (SQLiteException ex)
            {
                Log.Error (TAG, ex.Message);
                return string.Empty;
            }
        }
Example #23
0
        public async Task<GeoLocationItem> InsertAsync(GeoLocationItem item) 
        {

            var asyncConnect = new SQLiteAsyncConnection(DB_PATH);

            int insertedId  = await asyncConnect.InsertAsync(item);

            item.Id = insertedId;

            return item;
            
            /*using (var dbConn = new SQLite.SQLiteConnection(DB_PATH))
            {
                int insertedId = dbConn.Insert(item);
                item.Id = insertedId;
                return item;
            }*/
        }
Example #24
0
        private async void AddUserAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            // Create a random user
            College newUser = new College()
            {
                // the Id will be set by SQlite
                Name = string.Format("College X (created at {0})", DateTime.Now),
                
            };

            // Add row to the User Table
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection("institutionFinder.db");
            await conn.InsertAsync(newUser);

            // Add to the user list
            users.Add(newUser);

            // Refresh user list
            UserLists.ItemsSource = null;
            UserLists.ItemsSource = users;
        }
 protected void InitializeDatabase()
 {
     var dbName = "people";
     var conn = new SQLiteAsyncConnection (dbName);
     conn.CreateTableAsync<Person> ().ContinueWith ((task) =>
     {
         foreach (var i in Enumerable.Range (0,1000)) {
             var p = new Person ("Bob");
             conn.InsertAsync (p).ContinueWith ((task2) =>
             {
                 var id = p.Id;
                 this.InvokeOnMainThread (delegate {
                     this.recordCount.Text = id.ToString ();
                     this.recordCount.SetNeedsDisplay ();
                 }
                 );
             }
             );
         }
     }
     );
 }
Example #26
0
 public Task <int> CreateStationAsync(Entities.Station Station)
 {
     return(Database.InsertAsync(Station));
 }
        //private bool TableExists<T>(SQLiteConnection connection)
        //{
        //    const string cmdText = "SELECT name FROM sqlite_master WHERE type='table' AND name=?";
        //    var cmd = connection.CreateCommand(cmdText, typeof(T).Name);
        //    return cmd.ExecuteScalar<string>() != null;
        //}

        public async Task AddBankAccountFundsTransferAsync(BankAccountFundsTransfer fundsTransfer)
        {
            var inserted = await connection.InsertAsync(fundsTransfer);
        }
Example #28
0
 public Task Add(TracklistItem track)
 {
     var connection = new SQLiteAsyncConnection(DbPath);
     return connection.InsertAsync(track);
 }
Example #29
0
        async Task PickAlbumsFromDir()
        {
            var now = DateTime.Now;
            var albumFolders = await KnownFolders.MusicLibrary.GetFoldersAsync(Windows.Storage.Search.CommonFolderQuery.GroupByArtist);
            foreach (var albumFolder in albumFolders)
            {
                Debug.WriteLine(albumFolder.Name);
                var files = from b in await albumFolder.GetFilesAsync()
                            where !b.Path.EndsWith(".jpg")
                            select b;
                var propDict = (from b in files
                                select new { b.Properties.GetMusicPropertiesAsync().AsTask().Result,
                                             Value = b }
                                ).ToDictionary(b => b.Result, b => b.Value);
                var musicProperties = from b in propDict.Keys
                                      orderby b.TrackNumber
                                      group b by b.Album;
                var albumPool = new List<Album>() { };

                foreach (var tracks in musicProperties)
                {
                    var props = tracks.ToList();
                    var paths = (from b in props
                                 select propDict[b].Path).ToList();
                    var yearDesc = 10000 - props[0].Year;
                    var albumID = $"{props[0].Artist} {yearDesc} {props[0].Album}";

                    var db1 = new SQLiteAsyncConnection("PlaneAudioU.db");
                    var album = await db1
                                      .Table<Album>()
                                      .Where(a => a.AlbumID == albumID)
                                      .FirstOrDefaultAsync();
                    var albumNew = new Album()
                    {
                        AlbumID = albumID,
                        Title = props[0].Album,
                        Artist = props[0].Artist,
                        Titles = props.Select(a => a.Title).ToList(),
                        TrackPaths = paths,
                        Length = props.Count(),
                        Added = now
                    };

                    var db2 = new SQLiteAsyncConnection("PlaneAudioU.db");
                    if (album == null)
                    {

                        await db2.InsertAsync(albumNew);
                    }
                    else
                    {
                        await db2.UpdateAsync(albumNew);
                    }

                    albumPool.Add(albumNew);
                }

                Debug.WriteLine("album pool. " + albumPool.Count.ToString());
                if (albumPool.Count() > 0)
                {
                    var albumToShow = (from a in albumPool
                                       where !shownAlbums.Contains(a.AlbumID)
                                       select a).ToList();
                    if (albumToShow.Count() > 0)
                    {
                        var artistRect = GetArtistRect(albumToShow[0].Artist);
                        albumPanel.Items.Add(artistRect);
                        foreach (var album in albumToShow.OrderBy(a => a.AlbumID))
                        {
                            var button = await album.GetButton();
                            button.Click += AlbumButton_Clicked;
                            albumPanel.Items.Add(button);
                            shownAlbums.Add(album.AlbumID);
                        }
                    }
                }

            }

            Debug.WriteLine("Saving to db.");
            var db3 = new SQLiteAsyncConnection("PlaneAudioU.db");
            foreach (var oldAlbum in await db3.Table<Album>().Where(a => now > a.Added).ToListAsync())
            {
                var db4 = new SQLiteAsyncConnection("PlaneAudioU.db");
                await db4.DeleteAsync(oldAlbum);
            }

        }
Example #30
0
 public Task <int> CreateEmergencyAsync(Entities.Emergency Emergency)
 {
     return(Database.InsertAsync(Emergency));
 }
Example #31
0
        /// <summary>
        /// Adds a cached image to the database.
        /// </summary>
        /// <param name="image">
        /// The cached image to add.
        /// </param>
        /// <returns>
        /// The true if the addition of the cached image is added; otherwise, false.
        /// </returns>
        internal static async Task<int> AddImageAsync(CachedImage image)
        {
            try
            {
                SQLiteAsyncConnection connection = new SQLiteAsyncConnection(ConnectionString);

                return await connection.InsertAsync(image);
            }
            catch
            {
                return 0;
            }
        }
Example #32
0
 public Task Add(MusicLibraryViewModel.TrackItem track)
 {
     var connection = new SQLiteAsyncConnection(_dbPath);
     return connection.InsertAsync(track);
 }
        public async Task InitDatabase(string name)
        {
            //
            // Check if the database is already exist
            //
            bool dbexist = await CheckDbAsync(name);

            //
            // Open the database, creating the database if it not already exist
            //
            Dbconnection = new SQLiteAsyncConnection(name);

            //
            // If the database is new create tables
            //
            if (!dbexist)
            {
                await Dbconnection.CreateTableAsync<File>();
                await Dbconnection.CreateTableAsync<Directory>();
                await Dbconnection.CreateTableAsync<Album>();
                await Dbconnection.CreateTableAsync<Artist>();
                await Dbconnection.CreateTableAsync<Genre>();
                await Dbconnection.CreateTableAsync<CurrentPlaylist>();
                await Dbconnection.CreateTableAsync<PlaylistFile>();
                await Dbconnection.CreateTableAsync<Playlist>();
                await Dbconnection.CreateTableAsync<AudioOutput>();

                AudioOutput newAudioOutput = new AudioOutput()
                {
                    Name = "Windows Phone Audio Output",
                    Enabled = true
                };

                await Dbconnection.InsertAsync(newAudioOutput);

                await Dbconnection.CreateTableAsync<Option>();

                Option newOption = new Option()
                {
                    Name = "repeat",
                    ValueBool = false
                };
                await Dbconnection.InsertAsync(newOption);

                newOption = new Option()
                {
                    Name = "random",
                    ValueBool = false
                };
                await Dbconnection.InsertAsync(newOption);

                newOption = new Option()
                {
                    Name = "consume",
                    ValueBool = false
                };
                await Dbconnection.InsertAsync(newOption);

                newOption = new Option()
                {
                    Name = "single",
                    ValueBool = false
                };
                await Dbconnection.InsertAsync(newOption);

                /*
                newOption = new Option()
                {
                    Name = "state",
                    ValueString = "stop"
                };
                await Dbconnection.InsertAsync(newOption);
                */
            }

            //
            // Check if empty start Directory exist
            //
            Directory startDirectory = await GetDirectory(string.Empty, 0);

            //
            // If not, create a empty start directory
            //
            // This is so MPD uri's should work in a easy way
            //
            if (startDirectory == null)
            {

                //
                // Create empty start parent Directory
                //
                startDirectory = new Directory()
                {
                    Name = string.Empty,
                    Path = string.Empty,
                    RelativePath = string.Empty,
                    ParentDirectoryId = 0,
                    FolderRelativeId = string.Empty
                };

                //
                // Add start Directory to Directories
                //
                await Dbconnection.InsertAsync(startDirectory);
            }
        }
Example #34
0
 public Task Add(MusicLibraryViewModel.ArtistItem artist)
 {
     var connection = new SQLiteAsyncConnection(_dbPath);
     return connection.InsertAsync(artist);
 }
Example #35
0
 public Task <int> CreateProductAsync(Product product)
 {
     return(_database.InsertAsync(product));
 }
Example #36
0
        private void updateExternalDBStruct_v2(DBVersion dbVersion)
        {
            dbVersion.Loaction = LocationEnum.External;
            dbVersion.Version  = 2;
            mDatabase.InsertOrReplaceAsync(dbVersion);

            // 执行数据库升级脚本
            //mDatabase.CreateTableAsync<View.BuBuGao.Word>().Wait();

            //mDatabase.InsertAsync(new View.BuBuGao.Word() { Content = "天空" });
            mDatabase.CreateTableAsync <View.BuBuGao.Word>().Wait();
            mDatabase.CreateTableAsync <View.BuBuGao.Question>().Wait();

            View.BuBuGao.Question a1 = new View.BuBuGao.Question();
            a1.Name  = "天空";
            a1.Words = new List <View.BuBuGao.Word>();
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "天空"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "空气"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "气体"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "体力"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "力度"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "度过"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "过去"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "去年"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "年轻"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "轻松"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "松树"
            });
            a1.Words.Add(new View.BuBuGao.Word()
            {
                Content = "树木"
            });

            View.BuBuGao.Question a2 = new View.BuBuGao.Question();
            a2.Name  = "大人";
            a2.Words = new List <View.BuBuGao.Word>();
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "大人"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "人生"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "生命"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "命运"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "运货"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "货物"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "物品"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "品尝"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "尝试"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "试验"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "验证"
            });
            a2.Words.Add(new View.BuBuGao.Word()
            {
                Content = "证明"
            });

            View.BuBuGao.Question a3 = new View.BuBuGao.Question();
            a3.Name  = "红豆";
            a3.Words = new List <View.BuBuGao.Word>();
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "红豆"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "豆沙"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "沙子"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "子女"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "女巫"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "巫师"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "师父"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "父亲节"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "节约"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "约见"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "见面"
            });
            a3.Words.Add(new View.BuBuGao.Word()
            {
                Content = "面粉"
            });

            View.BuBuGao.Question a4 = new View.BuBuGao.Question();
            a4.Name  = "太黑";
            a4.Words = new List <View.BuBuGao.Word>();
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "太黑"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "黑白"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "白饭"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "饭菜"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "菜园"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "园丁"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "丁香花"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "花生"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "生气"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "气球"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "球体"
            });
            a4.Words.Add(new View.BuBuGao.Word()
            {
                Content = "体检"
            });

            View.BuBuGao.Question a5 = new View.BuBuGao.Question();
            a5.Name  = "上面";
            a5.Words = new List <View.BuBuGao.Word>();

            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "上面"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "面条"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "条件"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "件数"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "数学"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "学习"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "习惯"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "惯性"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "性格"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "格子"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "子孙"
            });
            a5.Words.Add(new View.BuBuGao.Word()
            {
                Content = "孙悟空"
            });

            mDatabase.InsertAsync(a1);
            mDatabase.InsertAsync(a2);
            mDatabase.InsertAsync(a3);
            mDatabase.InsertAsync(a4);
            mDatabase.InsertAsync(a5).Wait();

            InsertWordList(a1);
            InsertWordList(a2);
            InsertWordList(a3);
            InsertWordList(a4);
            InsertWordList(a5);
        }
Example #37
0
        /// <summary>
        /// Creates the world account if needed and sets it.
        /// </summary>
        public async Task EnsureWorldAccountExistsAsync()
        {
            //World account matches the current world, ignore.
            if (SEconomyPlugin.WorldAccount != null && SEconomyPlugin.WorldAccount.WorldID == Terraria.Main.worldID)
            {
                return;
            }

            if (Terraria.Main.worldID > 0)
            {
                int bankAccountK = 0;
                DatabaseObjects.BankAccount worldAccount = await(from i in AsyncConnection.Table <DatabaseObjects.BankAccount>()
                                                                 where (i.Flags & DatabaseObjects.BankAccountFlags.SystemAccount) == DatabaseObjects.BankAccountFlags.SystemAccount &&
                                                                 (i.Flags & DatabaseObjects.BankAccountFlags.PluginAccount) == 0 &&
                                                                 i.WorldID == Terraria.Main.worldID
                                                                 select i).FirstOrDefaultAsync();

                if (worldAccount == null)
                {
                    //world account does not exist for this world ID, create one
                    worldAccount = new DatabaseObjects.BankAccount();
                    worldAccount.UserAccountName = "SYSTEM";
                    worldAccount.WorldID         = Terraria.Main.worldID;
                    worldAccount.Description     = "World account for world " + Terraria.Main.worldName;
                    //This account is always enabled, locked to the world it's in and a system account (ie. can run into deficit) but not a plugin account
                    worldAccount.Flags = DatabaseObjects.BankAccountFlags.Enabled | DatabaseObjects.BankAccountFlags.LockedToWorld | DatabaseObjects.BankAccountFlags.SystemAccount;

                    bankAccountK = await AsyncConnection.InsertAsync(worldAccount);

                    worldAccount.BankAccountK = bankAccountK;
                }

                if (worldAccount != null && worldAccount.BankAccountK > 0)
                {
                    //Is this account listed as enabled?
                    bool accountEnabled = (worldAccount.Flags & DatabaseObjects.BankAccountFlags.Enabled) == DatabaseObjects.BankAccountFlags.Enabled;

                    if (!accountEnabled)
                    {
                        TShockAPI.Log.ConsoleError("The world account for world " + Terraria.Main.worldName + " is disabled.  Currency will not work for this game.");
                    }
                    else
                    {
                        SEconomyPlugin.WorldAccount = new Economy.BankAccount(worldAccount);
                    }
                }
                else
                {
                    Log.ConsoleError("There was an error loading the bank account for this world.  Currency will not work for this game.");
                }



                /*
                 * See how much easier this shit is?
                 *
                 *
                 * return AsyncConnection.Table<DatabaseObjects.BankAccount>().Where(i => (i.Flags & DatabaseObjects.BankAccountFlags.SystemAccount) == DatabaseObjects.BankAccountFlags.SystemAccount
                 *      && (i.Flags & DatabaseObjects.BankAccountFlags.PluginAccount) == 0
                 *      && i.WorldID == Terraria.Main.worldID).FirstOrDefaultAsync().ContinueWith((worldAccountResult) => {
                 *
                 *  if (worldAccountResult.Result == null) {
                 *      //world account does not exist for this world ID, create one
                 *      DatabaseObjects.BankAccount worldAccount = new DatabaseObjects.BankAccount();
                 *      worldAccount.UserAccountName = "SYSTEM";
                 *      worldAccount.WorldID = Terraria.Main.worldID;
                 *      worldAccount.Description = "World account for world " + Terraria.Main.worldName;
                 *
                 *      //This account is always enabled, locked to the world it's in and a system account (ie. can run into deficit) but not a plugin account
                 *      worldAccount.Flags = DatabaseObjects.BankAccountFlags.Enabled | DatabaseObjects.BankAccountFlags.LockedToWorld | DatabaseObjects.BankAccountFlags.SystemAccount;
                 *
                 *      AsyncConnection.InsertAsync(worldAccount).ContinueWith((newPrimaryKey) => {
                 *          int bankAccountK = newPrimaryKey.Result;
                 *
                 *          if (bankAccountK > 0) {
                 *
                 *              //Retrieve the new world account from the database
                 *              AsyncConnection.Table<DatabaseObjects.BankAccount>().Where(i => i.BankAccountK == bankAccountK).FirstOrDefaultAsync().ContinueWith((newWorldAccountResult) => {
                 *                  if (newWorldAccountResult.Result != null) {
                 *
                 *                      //override world account inserter with the new one.
                 *                      worldAccount = newWorldAccountResult.Result;
                 *
                 *                      //Is this account listed as enabled?
                 *                      bool accountEnabled = (worldAccount.Flags & DatabaseObjects.BankAccountFlags.Enabled) == DatabaseObjects.BankAccountFlags.Enabled;
                 *
                 *                      if (!accountEnabled) {
                 *                          TShockAPI.Log.ConsoleError("The world account for world " + Terraria.Main.worldName + " is disabled.  Currency will not work for this game.");
                 *                      }
                 *
                 *                      //Push it back to the main instance.
                 *                      SEconomyPlugin.WorldAccount = new Economy.BankAccount(worldAccount);
                 *                  }
                 *              });
                 *
                 *          } else {
                 *              Log.ConsoleError(string.Format("SEconomy: error: create world account for {0} failed.", Terraria.Main.worldName));
                 *          }
                 *      });
                 *
                 *  } else {
                 *      DatabaseObjects.BankAccount worldAccount = worldAccountResult.Result;
                 *
                 *      //Is this account listed as enabled?
                 *      bool accountEnabled = (worldAccount.Flags & DatabaseObjects.BankAccountFlags.Enabled) == DatabaseObjects.BankAccountFlags.Enabled;
                 *
                 *      if (!accountEnabled) {
                 *          TShockAPI.Log.ConsoleError("The world account for world " + Terraria.Main.worldName + " is disabled.  Currency will not work for this game.");
                 *      }
                 *
                 *      //Assign the world account to the running world.
                 *      SEconomyPlugin.WorldAccount = new Economy.BankAccount(worldAccount);
                 *  }
                 * });
                 *
                 * } else {
                 * return Task.Factory.StartNew(() => {
                 *  TShockAPI.Log.ConsoleError("SEconomy: EnsureBankAccountExists called but no world has been loaded yet.");
                 * });
                 */
            }
        }
Example #38
0
 public async Task Insert <T>(T item) where T : BaseModel, new()
 {
     await connection.InsertAsync(item);
 }
Example #39
0
 public Task <int> CreateUserInfoAsync(Entities.UserInfo userInfo)
 {
     return(Database.InsertAsync(userInfo));
 }