Пример #1
0
 public void AddFolders(string username, IEnumerable <MailFolder> folders)
 {
     foreach (MailFolder f in folders)
     {
         MFolder folder = new MFolder();
         folder.Username   = username;
         folder.FolderId   = f.id;
         folder.FolderName = f.name;
         db.Save(folder);
     }
 }
Пример #2
0
 private void AddSchemaChange(Models.SchemaChange changeScript)
 {
     if (changeScript.Status == Models.SchemaChange.Status_Success)
     {
         _database.Save(changeScript);
     }
 }
Пример #3
0
        public JsonResult Delete(IList<Route> data)
        {
            bool success = false;
            string message = "Delete method failed";

            if (data != null)
            {
                using (var db = new PetaPoco.Database("MissNancy"))
                {
                    foreach (var item in data)
                    {
                        item.EditDate = DateTime.Now;
                        item.Active = false;
                        db.Save("tblRoutes", "RouteKey", item);
                    }

                    success = true;
                    message = "Route(s) deleted successfully";
                }
            }

            return Json(new
            {
                success,
                message
            });
        }
Пример #4
0
        public JsonResult Create(List<Bus> data)
        {
            bool success = false;
            string message = "Create method failed";

            if (data != null)
            {
                using (var db = new PetaPoco.Database("MissNancy"))
                {
                    foreach (var item in data)
                    {
                        item.CreateDate = DateTime.Now;
                        item.EditDate = DateTime.Now;
                        db.Save("tblBuses", "BusKey", item);
                    }

                    success = true;
                    message = "Jesus Saves and so did this method";
                }
            }

            return Json(new
            {
                data,
                success,
                message
            });
        }
Пример #5
0
 public static void UpdateUser(Models.User u)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         db.Save(u);
     }
 }
Пример #6
0
 public static void UpdateUser(Models.User u)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         db.Save(u);
     }
 }
 private void simpleButton1_Click(object sender, EventArgs e)
 {
     foreach (var a in allCustomers)
     {
         db.Save("customers", "custumer_id", a);
     }
 }
Пример #8
0
 public static bool UpdateForum(Models.Forums forum)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         forum.UpdateTime = DateTime.Now;
         db.Save(forum);
         return(true);
     }
 }
Пример #9
0
        /// <summary>
        /// 创建值集
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public ValueSet.Entity.ValueSet CreateValueSet(string name, string description, string userName, string badge)
        {
            string msg = string.Empty;
            var    v   = new ValueSet.Entity.ValueSet()
            {
                Text        = name,
                Description = description,
                Creator     = badge,
                CreateTime  = DateTime.Now,
                CreatorID   = userName,
                IsDelete    = false,
                IsEnabled   = true
            };

            var duptest = db.Fetch <ValueSet.Entity.ValueSet>(" where Text=@0 ", name).Where(o => o.IsDelete == false).ToList();

            if (duptest.Count > 0)
            {
                throw new InfoException("同名的值集已经存在!");
            }

            try
            {
                db.Save(v);
            }
            catch (Exception ex)
            {
                throw new InfoException("创建失败。" + ex.Message + "!");
            }
            return(v);
        }
Пример #10
0
 public void AddYeZhu(List <YeZhu> yz)
 {
     if (Config.Conn.State == System.Data.ConnectionState.Closed)
     {
         Config.Conn.Open();
     }
     DB.BeginTransaction();
     foreach (YeZhu y in yz)
     {
         DB.Save(y);
     }
     DB.CompleteTransaction();
 }
Пример #11
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            db.BeginTransaction();

            foreach (customers c in bindingSource)
            {
                if (modRows.ContainsKey(c.id.ToString()))
                {
                    db.Save("customers", "id", c);
                }
            }

            db.CompleteTransaction();
        }
Пример #12
0
        /// <summary>
        /// 插入标签
        /// </summary>
        /// <param name="targTitle"></param>
        /// <param name="fid"></param>
        public static void AddTarg(string targTitle, int fid)
        {
            using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
            {
                Models.Targs tag = db.SingleOrDefault<Models.Targs>("WHERE tag_title=@0", targTitle);
                if (tag == null)
                {
                    tag = new Models.Targs();
                    tag.Forums = fid;
                    tag.Title = targTitle;
                    db.Save(tag);
                }

                Models.TargsRelation tagr = new Models.TargsRelation();
                tagr.TagID = tag.TagID;
                tagr.ForumsId = fid;
                db.Insert(tagr);
            }
        }
Пример #13
0
        /// <summary>
        /// 插入标签
        /// </summary>
        /// <param name="targTitle"></param>
        /// <param name="fid"></param>
        public static void AddTarg(string targTitle, int fid)
        {
            using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
            {
                Models.Targs tag = db.SingleOrDefault <Models.Targs>("WHERE tag_title=@0", targTitle);
                if (tag == null)
                {
                    tag        = new Models.Targs();
                    tag.Forums = fid;
                    tag.Title  = targTitle;
                    db.Save(tag);
                }

                Models.TargsRelation tagr = new Models.TargsRelation();
                tagr.TagID    = tag.TagID;
                tagr.ForumsId = fid;
                db.Insert(tagr);
            }
        }
Пример #14
0
        /// <summary>
        /// 创建值集
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public void CreateValueSet(string name, string description, string inputUser)
        {
            string msg = string.Empty;
            var    v   = new ValueSet();

            v.Name        = name;
            v.Description = description;
            v.InputUser   = inputUser;
            v.InputTime   = DateTime.Now;
            v.IsDelete    = false;
            v.IsEnabled   = true;

            var duptest = _db.Fetch <ValueSet>(" where Name =@0", name);

            if (duptest.Count > 0)
            {
                throw new Exception("同名的值集已经存在!");
            }
            _db.Save(v);
        }
Пример #15
0
        public JsonResult Update(Classes data)
        {
            bool success = false;
            string message = "no record found";
            if (data != null && data.ClassKey > 0)
            {
                using (var db = new PetaPoco.Database("MissNancy"))
                {
                    var rec = db.SingleOrDefault<Classes>("WHERE ClassKey = @0", data.ClassKey);
                    rec.ClassDisplay = data.ClassDisplay;
                    db.Save("tblClasses", "ClassKey", rec);
                    success = true;
                    message = "Update method called successfully";
                }
            }

            return Json(new
            {
                data,
                success,
                message
            });
        }
Пример #16
0
 public static bool UpdateForum(Models.Forums forum)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         forum.UpdateTime = DateTime.Now;
         db.Save(forum);
         return true;
     }
 }
Пример #17
0
        public JsonResult Update(IList<Neighborhood> data)
        {
            bool success = false;
            string message = "no record found";
            if (data != null)
            {
                using (var db = new PetaPoco.Database("MissNancy"))
                {
                    foreach (var item in data)
                    {
                        var rec = db.SingleOrDefault<Neighborhood>("WHERE NeighborhoodKey = @0", item.NeighborhoodKey);

                        rec = item;
                        rec.EditDate = DateTime.Now;
                        db.Save("tblNeighborhoods", "NeighborhoodKey", rec);
                    }

                    success = true;
                    message = "Jesus Saves and so did this method";
                }
            }

            return Json(new
            {
                data,
                success,
                message
            });
        }
Пример #18
0
        public SettingsProvider(string scope)
        {
            _currentSettings   = new Hashtable();
            _scopelessSettings = new Hashtable();

            string p = System.IO.Path.Combine(new string[] { System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GAPP" });

            if (!Directory.Exists(p))
            {
                Directory.CreateDirectory(p);
            }
            string fn = System.IO.Path.Combine(p, "settings.db3");

            //create backup first
            List <string> availableBackups = new List <string>();

            if (File.Exists(fn))
            {
                File.Copy(fn, string.Format("{0}.{1}.bak", fn, DateTime.Now.ToString("yyyyMMddHHmmss")));

                //keep maximum of X backups
                availableBackups = Directory.GetFiles(p, "settings.db3.*.bak").OrderBy(x => x).ToList();
                while (availableBackups.Count > 20)
                {
                    File.Delete(availableBackups[0]);
                    availableBackups.RemoveAt(0);
                }
            }

            bool dbOK;
            bool backupUsed = false;

            do
            {
                try
                {
                    _database = new PetaPoco.Database(string.Format("data source=file:{0}", fn), Community.CsharpSqlite.SQLiteClient.SqliteClientFactory.Instance);
                    dbOK      = _database.ExecuteScalar <string>("PRAGMA integrity_check") == "ok";
                    //if (availableBackups.Count > 2) dbOK = false; //test
                }
                catch
                {
                    dbOK = false;
                }
                if (!dbOK)
                {
                    backupUsed = true;
                    try
                    {
                        _database.Dispose();
                    }
                    catch
                    {
                    }
                    _database = null;

                    //delete settings and move to latest
                    File.Delete(fn);
                    if (availableBackups.Count > 0)
                    {
                        File.Move(availableBackups[availableBackups.Count - 1], fn);
                        availableBackups.RemoveAt(availableBackups.Count - 1);
                    }
                }
            } while (!dbOK);

            if (backupUsed)
            {
                System.Windows.Forms.MessageBox.Show("The settings file was corrupt and a backup file is restored.", "Settings");
            }

            if (!TableExists("Settings"))
            {
                _database.Execute("create table 'Settings' (Name text, Value text)");
                _database.Execute("insert into Settings (Name, Value) values ('Scope', 'default')");
            }

            if (!TableExists("SettingsScope"))
            {
                _database.Execute("create table 'SettingsScope' (ID integer primary key autoincrement, Name text)");
            }

            if (string.IsNullOrEmpty(scope))
            {
                scope = _database.ExecuteScalar <string>("select Value from Settings where Name=@0", "Scope");
                if (string.IsNullOrEmpty(scope))
                {
                    scope = "default";
                }
            }

            _scope = _database.FirstOrDefault <SettingsScope>("where Name=@0", scope);
            if (_scope == null)
            {
                _scope      = new SettingsScope();
                _scope.Name = scope;
                _database.Save(_scope);
            }

            if (!TableExists(string.Format("Settings_{0}", _scope.ID)))
            {
                _database.Execute(string.Format("create table 'Settings_{0}' (Name text, Value text)", _scope.ID));
            }

            var settings = _database.Fetch <Setting>(string.Format("select * from Settings_{0}", _scope.ID));

            foreach (var s in settings)
            {
                _currentSettings.Add(s.Name, s.Value);
            }
            var scopelesssettings = _database.Fetch <Setting>("select * from Settings");

            foreach (var s in scopelesssettings)
            {
                _scopelessSettings.Add(s.Name, s.Value);
            }
        }
Пример #19
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            var db = new PetaPoco.Database("MissNancy");
            var myClass = db.SingleOrDefault<Classes>("SELECT * FROM tblClasses WHERE ClassKey = @0", id);

            try
            {
                UpdateModel(myClass, collection.ToValueProvider());
                db.Save("tblClasses", "ClassKey", myClass);

                return RedirectToAction("Index");
            }
            catch (Exception e)
            {
                return View(myClass);
            }
        }