예제 #1
0
파일: Program.cs 프로젝트: cash2one/Z
        /// <summary>
        /// HowTO: 5. Transaction,  支持两个不同数据库连接之间的事务
        /// </summary>
        static void HowTO_5()
        {
            Console.WriteLine("HowTO: 5. Transaction,  支持两个不同数据库连接之间的事务");

            TestAbstractDA    da1 = new TestAbstractDA();
            TestAbstractTable da2 = new TestAbstractTable();

            try
            {
                using (TransScope scope = new TransScope(da1, da2))
                {
                    da1.DeleteAll();
                    da2.DeleteAll();

                    int id1 = da1.Insert("1", "1");
                    int id2 = da2.Insert("2", "2");
                    da1.Insert("3", "3");
                    da2.Insert("4", "4");

                    Console.WriteLine("da1:");
                    foreach (TestUser u in da1.SelectAll())
                    {
                        Console.WriteLine("\tID={0},UserName={1},UserPass={2}", u.ID, u.UserName, u.UserPass);
                    }

                    Console.WriteLine("da2:");
                    foreach (TestUser u in da2.SelectAll())
                    {
                        Console.WriteLine("\tID={0},UserName={1},UserPass={2}", u.ID, u.UserName, u.UserPass);
                    }

                    da1.Update(id1, "修改", "修改");
                    da2.Update(id2, "修改", "修改");

                    Console.WriteLine("da1修改后:");
                    foreach (TestUser u in da1.SelectAll())
                    {
                        Console.WriteLine("\tID={0},UserName={1},UserPass={2}", u.ID, u.UserName, u.UserPass);
                    }

                    Console.WriteLine("da1修改后:");
                    foreach (TestUser u in da2.SelectAll())
                    {
                        Console.WriteLine("\tID={0},UserName={1},UserPass={2}", u.ID, u.UserName, u.UserPass);
                    }


                    scope.Commit();
                }
            }
            catch (DatabaseException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("SQL:" + ex.SQL);
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: xqgzh/Z
        /// <summary>
        /// HowTO: 1. �������ݿ����(��AbstractDA����)
        /// </summary>
        static void HowTO_1()
        {
            Console.WriteLine("HowTO: 1. ��AbstractDA���������ݿ����");
            TestAbstractDA da = new TestAbstractDA();

            da.DeleteAll();

            int UserID = da.Insert("����1", "����1");

            TestUser u = da.SelectUserByUserId(UserID);

            Console.WriteLine("����T_TEST:  ID={0},UserName={1}, UserPass={2}", u.ID, u.UserName, u.UserPass);

            da.Update(u.ID, "�޸�֮����û���", "�޸�֮����û���");

            u = da.SelectUserByUserId(UserID);

            Console.WriteLine("����T_TEST:  ID={0},UserName={1}, UserPass={2}", u.ID, u.UserName, u.UserPass);
        }
예제 #3
0
파일: Program.cs 프로젝트: cash2one/Z
        /// <summary>
        /// HowTO: 1. 基本数据库操作(从AbstractDA派生)
        /// </summary>
        static void HowTO_1()
        {
            Console.WriteLine("HowTO: 1. 从AbstractDA派生的数据库操作");
            TestAbstractDA da = new TestAbstractDA();

            da.DeleteAll();

            int UserID = da.Insert("测试1", "测试1");

            TestUser u = da.SelectUserByUserId(UserID);

            Console.WriteLine("插入T_TEST:  ID={0},UserName={1}, UserPass={2}", u.ID, u.UserName, u.UserPass);

            da.Update(u.ID, "修改之后的用户名", "修改之后的用户名");

            u = da.SelectUserByUserId(UserID);

            Console.WriteLine("更新T_TEST:  ID={0},UserName={1}, UserPass={2}", u.ID, u.UserName, u.UserPass);
        }
예제 #4
0
파일: Program.cs 프로젝트: xqgzh/Z
        /// <summary>
        /// HowTO: 5. Transaction,  ֧��������ͬ���ݿ�����֮�������
        /// </summary>
        static void HowTO_5()
        {
            Console.WriteLine("HowTO: 5. Transaction,  ֧��������ͬ���ݿ�����֮�������");

            TestAbstractDA da1 = new TestAbstractDA();
            TestAbstractTable da2 = new TestAbstractTable();

            try
            {

                using (TransScope scope = new TransScope(da1, da2))
                {
                    da1.DeleteAll();
                    da2.DeleteAll();

                    int id1 = da1.Insert("1", "1");
                    int id2 = da2.Insert("2", "2");
                    da1.Insert("3", "3");
                    da2.Insert("4", "4");

                    Console.WriteLine("da1:");
                    foreach (TestUser u in da1.SelectAll())
                    {
                        Console.WriteLine("\tID={0},UserName={1},UserPass={2}", u.ID, u.UserName, u.UserPass);
                    }

                    Console.WriteLine("da2:");
                    foreach (TestUser u in da2.SelectAll())
                    {
                        Console.WriteLine("\tID={0},UserName={1},UserPass={2}", u.ID, u.UserName, u.UserPass);
                    }

                    da1.Update(id1, "�޸�", "�޸�");
                    da2.Update(id2, "�޸�", "�޸�");

                    Console.WriteLine("da1�޸ĺ�:");
                    foreach (TestUser u in da1.SelectAll())
                    {
                        Console.WriteLine("\tID={0},UserName={1},UserPass={2}", u.ID, u.UserName, u.UserPass);
                    }

                    Console.WriteLine("da1�޸ĺ�:");
                    foreach (TestUser u in da2.SelectAll())
                    {
                        Console.WriteLine("\tID={0},UserName={1},UserPass={2}", u.ID, u.UserName, u.UserPass);
                    }

                    scope.Commit();
                }
            }
            catch (DatabaseException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("SQL:" + ex.SQL);
            }
        }