Пример #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            using (var db = new  Repository.SqliteDbContext())
            {
                Models.Accounts Root = new Models.Accounts();

                Root.AccountName  = "成本科目清单";
                Root.AccountLevel = 0;
                Root.Level        = 0;
                Root.Name         = "根节点";
                Root.Order        = 0;

                Root.Child = new List <Models.Tree>();
                Models.ExpenseAccounts ea = new Models.ExpenseAccounts();
                ea.Name          = "费用1";
                ea.PricingComent = "输入收费说明";
                ea.Level         = 1;
                ea.Order         = 0;
                Root.Child.Add(ea);

                ea.Child = new List <Models.Tree>();
                Models.Accounts ac = new Models.Accounts();
                ac.Name        = "费用1-科目1";
                ac.AccountName = "科目";
                ac.Level       = 2;
                ac.Order       = 0;
                ea.Child.Add(ac);

                var _account = db.Set <Models.Accounts>();
                _account.Add(Root);

                db.SaveChanges();
            }
        }
Пример #2
0
        //保存数据
        public void ChangeGridData( )
        {
            var ds   = (DataSet)((BindingSource)(dataGridView1.DataSource)).DataSource;
            var bdt  = ds.Tables["BaseType"];
            var idt  = ds.Tables["ItemType"];
            var idts = ds.Relations[0];

            /**
             *  删除              修改              新增
             * 1.删除子表       1.修改子表       1.新增主表
             * 2.删除主表       2.修改主表       2.新增子表
             */
            using (var db = new Repository.SqliteDbContext())
            {
                onDataDelete(db, bdt, idt);
                onDataModify(db, bdt, idt);
                onDataAdd(db, bdt, idt, idts);
                db.SaveChanges();
            }
            ds.AcceptChanges();
            initGridView();
        }