Beispiel #1
0
        public bool DBInsert(ResultDataClass datas)
        {
            string connectionStr = DatabasePath;

            try
            {
                using (var db = new LiteDatabase(connectionStr))
                {
                    // Get customer collection
                    var notes = db.GetCollection <ResultDataClass>(Schema);

                    notes.EnsureIndex(x => x.DATASTAMP);
                    notes.EnsureIndex(x => x.STAMP);

                    // Insert (Id will be auto-incremented)
                    datas.ID = Guid.Empty;
                    BsonValue bv = notes.Insert(datas);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return(false);
        }
Beispiel #2
0
        public bool DBDelete(ResultDataClass datas)
        {
            string connectionStr = DatabasePath;

            try
            {
                using (var db = new LiteDatabase(connectionStr))
                {
                    // Get customer collection
                    var notes = db.GetCollection <ResultDataClass>(Schema);

                    notes.Delete(datas.ID);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return(false);
        }
Beispiel #3
0
        public bool DBUpdate(ResultDataClass datas)
        {
            var    lf            = Application.StartupPath;
            string connectionStr = DatabasePath;

            using (var db = new LiteDatabase(connectionStr))
            {
                var notes = db.GetCollection <ResultDataClass>(Schema);
                notes.EnsureIndex(x => x.DATASTAMP);
                notes.EnsureIndex(x => x.STAMP);
                notes.Update(datas);

                /*
                 * foreach (var imagePath in datas.SongFiles)
                 * {
                 *  FileStream stream = new FileStream($@"{imagePath.FilesName}", FileMode.Open, FileAccess.ReadWrite);
                 *  db.FileStorage.Upload(imagePath.FilesID, $@"{imagePath.FilesName}", stream);
                 *  stream.Close();
                 * }
                 */
                return(true);
            }
        }
Beispiel #4
0
        public ResultDataClass GetFirst(string key)
        {
            var list = new ResultDataClass();

            using (var db = new LiteDatabase(DatabasePath))
            {
                var col = db.GetCollection <ResultDataClass>(Schema);
                if (string.IsNullOrEmpty(key))
                {
                    foreach (ResultDataClass _id in col.FindAll())
                    {
                        list = _id;
                    }
                }
                else
                {
                    foreach (ResultDataClass _id in col.Find(x => x.MEASNAME == key))
                    {
                        list = _id;
                    }
                }
            }
            return(list);
        }