コード例 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            Model.Sys_User m = new Model.Sys_User();
            m.CreateTime = DateTime.Now;
            m.Password   = "******";
            m.Status     = true;
            m.UpdateTime = DateTime.Now;
            m.UserName   = "******" + DateTime.Now.Ticks.ToString();
            m.UserRole   = "testrole";

            Model.ECom_Work work = new Model.ECom_Work();
            work.Address        = "zxc";
            work.City           = "zxc";
            work.Province       = "zxc";
            work.Classification = "sdfds";
            work.Contents       = "zxc";
            work.CreateTime     = DateTime.Now;
            work.District       = "zxc";
            work.ExpirationDate = DateTime.Now;
            work.HTMLUrl        = "zxc";
            work.Status         = true;
            work.Title          = "zxc";
            work.TitleColor     = "zxc";
            work.UpdateTime     = DateTime.Now;
            work.Province       = "sdf";
            work.UserName       = "******";
            work.WorkID         = Guid.NewGuid().ToString();
            work.WorkType       = "放活";

            Model.ECom_Work work1 = new Model.ECom_Work();
            work1.Address        = "zxc";
            work1.City           = "zxc";
            work1.Classification = "sdfds";
            work1.Contents       = "zxc";
            work1.CreateTime     = DateTime.Now;
            work1.District       = "zxc";
            work1.ExpirationDate = DateTime.Now;
            work1.HTMLUrl        = "zxc";
            work1.Status         = true;
            work1.Title          = "zxc";
            work1.TitleColor     = "zxc";
            work1.UpdateTime     = DateTime.Now;
            work1.UserName       = "******";
            work1.Province       = "sdf";
            work1.WorkID         = Guid.NewGuid().ToString();
            work1.WorkType       = "放活";
            m.Works = new List <Model.ECom_Work>()
            {
                work, work1
            };

            IRepository <Model.Sys_User> r = RepositoryFactory <Model.Sys_User> .CreateRepository("Model.Sys_User");

            if (r.Add(m))
            {
                MessageBox.Show("添加成功");
            }
        }
コード例 #2
0
        private void button27_Click_1(object sender, EventArgs e)
        {
            Model.Test_Table m1 = new Model.Test_Table();
            m1.key1 = "k001";
            m1.key2 = "k002";
            m1.memo = "测试下";

            Model.Test_Table m2 = new Model.Test_Table();
            m2.key1 = "k0011";
            m2.key2 = "k0022";
            m2.memo = "测试下2";

            Model.Sys_User m3 = new Model.Sys_User();
            m3.CreateTime = DateTime.Now;
            m3.Password   = "******";
            m3.Status     = true;
            m3.UpdateTime = DateTime.Now;
            m3.UserName   = "******" + DateTime.Now.Ticks.ToString();
            m3.UserRole   = "testrole";

            Model.ECom_Work work = new Model.ECom_Work();
            work.Address        = "zxc";
            work.City           = "zxc";
            work.Province       = "zxc";
            work.Classification = "sdfds";
            work.Contents       = "zxc";
            work.CreateTime     = DateTime.Now;
            work.District       = "zxc";
            work.ExpirationDate = DateTime.Now;
            work.HTMLUrl        = "zxc";
            work.Status         = true;
            work.Title          = "zxc";
            work.TitleColor     = "zxc";
            work.UpdateTime     = DateTime.Now;
            work.Province       = "sdf";
            work.UserName       = "******";
            work.WorkID         = Guid.NewGuid().ToString();
            work.WorkType       = "放活";

            Model.ECom_Work work1 = new Model.ECom_Work();
            work1.Address        = "zxc";
            work1.City           = "zxc";
            work1.Classification = "sdfds";
            work1.Contents       = "zxc";
            work1.CreateTime     = DateTime.Now;
            work1.District       = "zxc";
            work1.ExpirationDate = DateTime.Now;
            work1.HTMLUrl        = "zxc";
            work1.Status         = true;
            work1.Title          = "zxc";
            work1.TitleColor     = "zxc";
            work1.UpdateTime     = DateTime.Now;
            work1.UserName       = "******";
            work1.Province       = "sdf";
            work1.WorkID         = Guid.NewGuid().ToString();
            work1.WorkType       = "放活";
            m3.Works             = new List <Model.ECom_Work>()
            {
                work, work1
            };

            List <EntityBase> list = new List <EntityBase>();

            list.Add(m1);
            list.Add(m2);
            list.Add(m3);
            if (RepositoryBase <EntityBase> .BatchSave(list))
            {
                MessageBox.Show("保存成功");
            }
        }
コード例 #3
0
        private void btnTransaction_Click(object sender, EventArgs e)
        {
            Model.Test_Table m1 = new Model.Test_Table();
            m1.key1 = "k0011";
            m1.key2 = "k0021";
            m1.memo = "测试下";

            Model.Test_Table m2 = new Model.Test_Table();
            m2.key1 = "k00111";
            m2.key2 = "k00221";
            m2.memo = "测试下2";

            Model.Sys_User m3 = new Model.Sys_User();
            m3.CreateTime = DateTime.Now;
            m3.Password   = "******";
            m3.Status     = true;
            m3.UpdateTime = DateTime.Now;
            m3.UserName   = "******";// +DateTime.Now.Ticks.ToString();
            m3.UserRole   = "testrole111";

            Model.ECom_Work work = new Model.ECom_Work();
            work.Address        = "zxc";
            work.City           = "zxc";
            work.Province       = "zxc";
            work.Classification = "sdfds";
            work.Contents       = "zxc";
            work.CreateTime     = DateTime.Now;
            work.District       = "zxc";
            work.ExpirationDate = DateTime.Now;
            work.HTMLUrl        = "zxc";
            work.Status         = true;
            work.Title          = "zxc";
            work.TitleColor     = "zxc";
            work.UpdateTime     = DateTime.Now;
            work.Province       = "sdf";
            work.UserName       = "******";
            work.WorkID         = Guid.NewGuid().ToString();
            work.WorkType       = "放活";

            Model.ECom_Work work1 = new Model.ECom_Work();
            work1.Address        = "zxc";
            work1.City           = "zxc";
            work1.Classification = "sdfds";
            work1.Contents       = "zxc";
            work1.CreateTime     = DateTime.Now;
            work1.District       = "zxc";
            work1.ExpirationDate = DateTime.Now;
            work1.HTMLUrl        = "zxc";
            work1.Status         = true;
            work1.Title          = "zxc";
            work1.TitleColor     = "zxc";
            work1.UpdateTime     = DateTime.Now;
            work1.UserName       = "******";
            work1.Province       = "sdf";
            work1.WorkID         = Guid.NewGuid().ToString();
            work1.WorkType       = "放活";
            m3.Works             = new List <Model.ECom_Work>()
            {
                work, work1
            };

            DBTransaction tran = new DBTransaction();

            tran.TransactionOpen();

            IRepository <Model.Test_Table> r = RepositoryFactory <Model.Test_Table> .CreateRepository(tran);

            IRepository <Model.Sys_User> r1 = RepositoryFactory <Model.Sys_User> .CreateRepository(tran);

            try
            {
                r.AddOrUpdate(m1);
                r.AddOrUpdate(m2);
                r1.AddOrUpdate(m3);
                Model.Sys_User mu = new Model.Sys_User();
                mu.UserRole = "rrole";
                r1.UpdateByCondition(mu, new ConditionItem("UserName", "testtest", SearchType.Accurate));
                r1.DeleteByCondition(new ConditionItem("UserName", "test", SearchType.RightFuzzy));
                tran.TransactionCommit();
                MessageBox.Show("处理成功");
            }
            catch
            {
                tran.TransactionRollback();
                MessageBox.Show("处理失败");
            }
        }