示例#1
0
 public void UseDb(string dbkey)
 {
     if (_oleDbDic != null && _oleDbDic.ContainsKey(dbkey) == true)
     {
         _oleDb = _oleDbDic[dbkey];
     }
 }
        public void EntityUpdateTest()
        {
            AbstractDatabase     fakeDb     = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            TestEntityRepository repository = new TestEntityRepository(fakeDb);
            TestEntity           entity     = new TestEntity()
            {
                Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8
            };

            String expectedSql = "UPDATE TestTable SET TestColumn1=@PN_IDX_0,TestColumn2=@PN_IDX_1,TestColumn3=@PN_IDX_2,TestColumn4=@PN_IDX_3,TestColumn5=@PN_IDX_4,TestColumn6=@PN_IDX_5,TestColumn7=@PN_IDX_6,TestColumn8=@PN_IDX_7";

            DataParameter[] expectedParameter = new DataParameter[8]
            {
                DataParameter.InternalCreate(fakeDb, "TestColumn1", "0", entity.Test1),
                DataParameter.InternalCreate(fakeDb, "TestColumn2", "1", entity.Test2),
                DataParameter.InternalCreate(fakeDb, "TestColumn3", "2", entity.Test3),
                DataParameter.InternalCreate(fakeDb, "TestColumn4", "3", entity.Test4),
                DataParameter.InternalCreate(fakeDb, "TestColumn5", "4", DataType.Int32, entity.Test5),
                DataParameter.InternalCreate(fakeDb, "TestColumn6", "5", DataType.Double, entity.Test6),
                DataParameter.InternalCreate(fakeDb, "TestColumn7", "6", DataType.DateTime, entity.Test7),
                DataParameter.InternalCreate(fakeDb, "TestColumn8", "7", DataType.Int16, entity.Test8)
            };

            UpdateCommand cmd       = fakeDb.CreateUpdateCommand(repository.TableName).Set(entity);
            String        actualSql = cmd.GetCommandText().Trim();

            DataParameter[] actualParameter = cmd.GetAllParameters();

            Assert.AreEqual(expectedSql, actualSql);

            for (Int32 i = 0; i < actualParameter.Length; i++)
            {
                Assert.AreEqual(expectedParameter[i], actualParameter[i]);
            }
        }
 public TaisyakuTaisyouhyouTyuuki(AbstractDatabase db, string tableName = TABLE_NAME)
     : base(db, tableName)
 {
     base.AddColumn("nenndo", ColumnType.TypeInt, "");               // 年度
     base.AddColumn("juuyou_henkou", ColumnType.TypeString, "");     // 重要な会計方針の変更
     base.AddColumn("juuyou_kouhatsu", ColumnType.TypeString, "");   // 重要な後発事象
 }
        /// <summary>
        /// Obtém o último objeto de uma lista de objetos vinda do banco de dados.
        /// </summary>
        /// <typeparam name="TDto">Tipo de objeto que deseja retornar na lista</typeparam>
        /// <param name="commandSql">Parametros necessários para realizar a consulta no banco de dados</param>
        /// <returns>Retorna um objeto preenchido com as informações do banco de dados</returns>
        protected TDto LastOrDefault <TDto>(CommandSql commandSql) where TDto : class, new()
        {
            AbstractDatabase database = DatabaseFactory.CreateDatabase(commandSql.EnumDatabaseType, commandSql.StringConnection);

            using (IDbConnection connection = database.CreateOpenConnection())
            {
                using (IDbCommand command = database.CreateCommand(commandSql.CommandText, connection))
                {
                    //Adiciona os parametros no command
                    if (commandSql.Parametros != null)
                    {
                        commandSql.Parametros.ForEach(x => command.Parameters.Add(x));
                    }

                    //Define configurações do command
                    command.CommandType    = commandSql.CommandType;
                    command.CommandTimeout = commandSql.CommandTimeout;
                    command.CommandText    = commandSql.CommandText;


                    //Converte o datareader em List

                    TDto entity = ObjectMapper.FillCollection <TDto>(command.ExecuteReader()).LastOrDefault();

                    return(entity);
                }
            }
        }
示例#5
0
        public static List <T> ToList <T>(DataTable table, AbstractDatabase Db, IUnityContainer container, ICacheManager cache, string pluginName, string unityname)
        {
            Type     type    = typeof(T);
            List <T> objects = new List <T>();
            T        obj     = FactoryModel.GetObject <T>(Db, container, cache, pluginName, unityname);

            if (table != null && table.Rows.Count > 0)
            {
                while (objects.Count < table.Rows.Count)
                {
                    objects.Add((T)((ICloneable)obj).Clone());
                }

                foreach (PropertyInfo property in type.GetProperties())
                {
                    if (table.Columns.IndexOf(property.Name) >= 0)
                    {
                        for (int index = 0; index < table.Rows.Count; index++)
                        {
                            object val = table.Rows[index][property.Name];
                            if (val == System.DBNull.Value)
                            {
                                val = null;
                            }
                            property.SetValue((object)objects[index], val, null);
                        }
                    }
                }
            }
            return(objects);
        }
示例#6
0
 public void UseDb()
 {
     if (_oleDbDic != null && _oleDbDic.ContainsKey("default") == true)
     {
         _oleDb = _oleDbDic["default"];
     }
 }
示例#7
0
 public MTTaiyouNennsuu(AbstractDatabase db)
     : base(db, TABLE_NAME)
 {
     base.AddColumn("seiri_bangou", ColumnType.TypeInt, "");               // 整理番号
     base.AddColumn("shisan_meisyou", ColumnType.TypeString, "");          // 資産名称
     base.AddColumn("taiyou_nennsuu", ColumnType.TypeInt, "");             // 耐用年数
 }
        public static object GetObject(Type type, AbstractDatabase Db, IUnityContainer _container, ICacheManager _cache, string _pluginName, string unityname)
        {
            //if (Db == null)
            //{
            //    EFWCoreLib.CoreFrame.DbProvider.AbstractDatabase Rdb = EFWCoreLib.CoreFrame.DbProvider.FactoryDatabase.GetDatabase();
            //    //SysLoginRight currLoginUser = (SysLoginRight)EFWCoreLib.CoreFrame.Init.AppGlobal.cache.GetData("RoleUser");
            //    //Rdb.WorkId = currLoginUser.WorkId;
            //    Db = Rdb;
            //    _container = EFWCoreLib.CoreFrame.Init.AppGlobal.container;
            //}

            //读unity配置文件把类注入到接口得到对象实例
            IUnityContainer container = _container;

            Object t = null;

            if (unityname == null)
            {
                t = container.Resolve(type);
            }
            else
            {
                t = container.Resolve(type, unityname);
            }

            IbindDb ibind = (IbindDb)t;

            ibind.BindDb(Db, container, _cache, _pluginName);

            //给对象加上代理
            t = PolicyInjection.Wrap(t.GetType(), t);

            return(t);
        }
        static void Main(string[] args)
        {
            AbstractDatabase objDAL = FactoryBD.StringConexao();



            List <ProdutosVenda> produtos = new List <ProdutosVenda>()
            {
                new ProdutosVenda(1, 1, 1000)
            };


            double valor = 0;

            produtos.ForEach(x => valor += x.PrecoUnitario);

            Venda venda = new Venda(valor, FormaPagamento.Dinheiro, new ClienteJuridico {
                Codigo = 20, Nome = "Ernane", Email = "ernane1", Nascimento = DateTime.Now, CNPJ = "123"
            }, produtos);

            venda.Descontar();


            IVenda vendas = FactoryEntity.Venda();

            vendas.RegistrarVenda(venda);
        }
示例#10
0
        public MTKamoku(AbstractDatabase db)
            : base(db, TABLE_NAME)
        {
            base.AddColumn("kamoku", ColumnType.TypeString, "");             // 科目
            base.AddColumn("kamoku_yomi", ColumnType.TypeString, "");        // 科目よみ
            base.AddColumn("hojo_kamoku_ari", ColumnType.TypeBool, "");      // 補助科目あり
            base.AddColumn("daikubun_id", ColumnType.TypeInt, "");           // 大区分ID
            base.AddColumn("seiri_bangou", ColumnType.TypeInt, "");          // 整理番号
            base.AddColumn("zenki_kurikoshi", ColumnType.TypeInt, "");       // 前期繰越
            base.AddColumn("zenzenki_kurikoshi", ColumnType.TypeInt, "");    // 前前期繰越
            base.AddColumn("taisyaku_kubun", ColumnType.TypeString, "");     // 貸借区分
            base.AddColumn("shiyou_kubun", ColumnType.TypeBool, "");         // 使用区分
            base.AddColumn("hurikae_taisyou", ColumnType.TypeString, "");    // 振替対象
            base.AddColumn("yosan", ColumnType.TypeInt, "");                 // 予算
            base.AddColumn("zennnendo_yosan", ColumnType.TypeInt, "");       // 前年度予算
            base.AddColumn("seiretsu_jun", ColumnType.TypeInt, "");          // 整列順
            base.AddColumn("kamoku_code", ColumnType.TypeString, "");        // 科目コード
            base.AddColumn("daikubun_code", ColumnType.TypeString, "");      // 大区分コード
            base.AddColumn("seiretu_code", ColumnType.TypeString, "");       // 整列コード
            base.AddColumn("hosei_yosan", ColumnType.TypeInt, "");           // 補正予算
            base.AddColumn("daitai_kamoku_code", ColumnType.TypeString, ""); // 代替科目コード
            base.AddColumn("daitai_kamoku_bangou", ColumnType.TypeInt, "");  // 代替科目番号

            kamokuCode2RowCache = new Dictionary <string, Row>();
            firstCharList       = new SortedList <char, int>();
        }
        public void CreateNullableConditionTest()
        {
            AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;

            SelectCommand       baseCommand      = fakeDb.CreateSelectCommand("");
            SqlConditionBuilder conditionBuilder = baseCommand.ConditionBuilder;

            AbstractSqlCondition baseCondition = conditionBuilder.Equal("TestColumn2", 1);

            AbstractSqlCondition expectedCondition = baseCondition & null;
            AbstractSqlCondition actualCondition   = baseCondition;

            Assert.AreEqual(expectedCondition, actualCondition);

            AbstractSqlCondition expectedCondition2 = null & baseCondition;
            AbstractSqlCondition actualCondition2   = baseCondition;

            Assert.AreEqual(expectedCondition2, actualCondition2);

            AbstractSqlCondition expectedCondition3 = baseCondition | null;
            AbstractSqlCondition actualCondition3   = baseCondition;

            Assert.AreEqual(expectedCondition3, actualCondition3);

            AbstractSqlCondition expectedCondition4 = null | baseCondition;
            AbstractSqlCondition actualCondition4   = baseCondition;

            Assert.AreEqual(expectedCondition4, actualCondition4);
        }
        public void LinqCreateNotLikeConditionTest()
        {
            AbstractDatabase fakeDb          = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            SelectCommand    expectedCommand = fakeDb.CreateSelectCommand("");
            SelectCommand    actualCommand   = fakeDb.CreateSelectCommand("");

            SqlConditionBuilder expectedConditionBuilder = expectedCommand.ConditionBuilder;

            SqlBasicParameterCondition expectedCondition = expectedConditionBuilder.NotLike("TestColumn1", "test1");
            SqlBasicParameterCondition actualCondition   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test1.NotLike("test1")) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition, actualCondition);

            SqlBasicParameterCondition expectedCondition2 = expectedConditionBuilder.NotLikeAll("TestColumn1", "test2");
            SqlBasicParameterCondition actualCondition2   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test1.NotLikeAll("test2")) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition2, actualCondition2);

            SqlBasicParameterCondition expectedCondition3 = expectedConditionBuilder.NotLikeStartWith("TestColumn1", "test3");
            SqlBasicParameterCondition actualCondition3   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test1.NotLikeStartWith("test3")) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition3, actualCondition3);

            SqlBasicParameterCondition expectedCondition4 = expectedConditionBuilder.NotLikeEndWith("TestColumn1", "test4");
            SqlBasicParameterCondition actualCondition4   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test1.NotLikeEndWith("test4")) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition4, actualCondition4);
        }
 public TaisyakuTaisyouhyouTyuuki4(AbstractDatabase db, string tableName = TABLE_NAME)
     : base(db, tableName)
 {
     base.AddColumn("tyuuki_id", ColumnType.TypeInt, "");            // 貸借対照注記ID
     base.AddColumn("kaikei_kubun", ColumnType.TypeInt, "");         // 会計区分
     base.AddColumn("naiyou", ColumnType.TypeString, "");            // 内容
 }
示例#14
0
        private List <(string tableName, string conString, DatabaseType dbType)> GetTargetTables
            (string absTableName, ReadWriteType opType, string absDbName, object obj = null)
        {
            //获取抽象数据库
            AbstractDatabase db = null;

            if (absDbName.IsNullOrEmpty())
            {
                db = _absDb.Single();
            }
            else
            {
                db = _absDb.Where(x => x.AbsDbName == absDbName).Single();
            }
            if (db == null)
            {
                throw new Exception("请配置抽象数据库");
            }

            //获取抽象数据表
            var absTable = db.Tables.Where(x => x.AbsTableName == absDbName).Single();

            //获取物理表
            List <(string physicTableName, string dataSourceName)> physicTables = null;

            //读操作获取全部表
            if (opType == ReadWriteType.Read)
            {
                physicTables = absTable.PhysicTables;
            }
            else
            {
                //找特定表
                if (!obj.IsNullOrEmpty())
                {
                    var theTable = absTable.FindTable(obj);
                    physicTables = absTable.PhysicTables.Where(x => x.physicTableName == theTable).ToList();
                }
                //所有表
                else
                {
                    physicTables = absTable.PhysicTables;
                }
            }

            //获取数据源
            var dataSources = _dataSource
                              .Where(x => physicTables.Select(y => y.dataSourceName).Contains(x.DataSourceName))
                              .Select(x => new { x.DataSourceName, x.DbType, RandomHelper.Next(x.Dbs.Where(y => y.opType.HasFlag(opType)).ToList()).conString })
                              .ToList();

            var q = from a in physicTables
                    join b in dataSources on a.dataSourceName equals b.DataSourceName
                    select(a.physicTableName, b.conString, b.DbType);

            var resList = q.ToList();

            return(resList);
        }
示例#15
0
        public MTSetting(AbstractDatabase db)
            : base(db, TABLE_NAME)
        {
            base.AddColumn("key", ColumnType.TypeString, "");              // キー
            base.AddColumn("value", ColumnType.TypeString, "");            // 値

            key2row_ = new Dictionary <string, Row>();
        }
示例#16
0
 public TaisyakuTaisyouhyouKyakutyuu(AbstractDatabase db, string tableName = TABLE_NAME)
     : base(db, tableName)
 {
     base.AddColumn("tyuuki_id", ColumnType.TypeInt, "");                            // 貸借対照注記ID
     base.AddColumn("kaikei_kubun", ColumnType.TypeInt, "");                         // 経理区分
     base.AddColumn("genka_baikyaku_ruikei", ColumnType.TypeAmount, "");             // 減価償却累計額
     base.AddColumn("tyousyuu_hunou_kin", ColumnType.TypeAmount, "");                // 徴収不能金
 }
示例#17
0
 public TaisyakuTaisyouhyouTyuuki1(AbstractDatabase db, string tableName = TABLE_NAME)
     : base(db, tableName)
 {
     base.AddColumn("tyuuki_id", ColumnType.TypeInt, "");            // 貸借対照注記ID
     base.AddColumn("seiri_bangou", ColumnType.TypeInt, "");         // 整理番号
     base.AddColumn("koumoku_mei", ColumnType.TypeString, "");       // 項目名
     base.AddColumn("naiyou", ColumnType.TypeString, "");            // 内容
 }
示例#18
0
 public ZenkiKurikoshiHojoKamoku(AbstractDatabase db, string tableName = TABLE_NAME)
     : base(db, tableName)
 {
     base.AddColumn("keiri_kubun", ColumnType.TypeInt, "");                                // 経理区分
     base.AddColumn("nenndo", ColumnType.TypeDate, "");                                    // 年度
     base.AddColumn("hojo_id", ColumnType.TypeInt, "");                                    // 補助科目ID
     base.AddColumn("zenki_kurikoshi_gaku", ColumnType.TypeAmount, "");                    // 前期繰越額
     base.AddColumn("taisyaku_kubun", ColumnType.TypeString, "");                          // 貸借区分
 }
示例#19
0
        public MTTekiyou(AbstractDatabase db)
            : base(db, TABLE_NAME)
        {
            base.AddColumn("tekiyou_code", ColumnType.TypeInt, "");                 // 摘要コード
            base.AddColumn("tekiyou_mei", ColumnType.TypeString, "");               // 摘要名
            base.AddColumn("tekiyou_yomi", ColumnType.TypeString, "");              // 摘要読み

            firstCharList = new SortedList <char, int>();
        }
 public TaisyakuTaisyouhyouTyuuki3(AbstractDatabase db, string tableName = TABLE_NAME)
     : base(db, tableName)
 {
     base.AddColumn("tyuuki_id", ColumnType.TypeInt, "");            // 貸借対照注記ID
     base.AddColumn("kaikei_kubun", ColumnType.TypeInt, "");         // 会計区分
     base.AddColumn("kamoku_id", ColumnType.TypeInt, "");            // 勘定科目ID
     base.AddColumn("tekiyou", ColumnType.TypeString, "");           // 摘要
     base.AddColumn("amount", ColumnType.TypeAmount, "");            // 金額
 }
 public ZenkiKurikoshiKamokuKubun(AbstractDatabase db, string tableName = TABLE_NAME)
     : base(db, tableName)
 {
     base.AddColumn("kaikei_kubun_id", ColumnType.TypeInt, "");                            // 会計区分
     base.AddColumn("nenndo", ColumnType.TypeInt, "");                                     // 年度
     base.AddColumn("kamoku_kubun_id", ColumnType.TypeInt, "");                            // 科目区分ID
     base.AddColumn("zenki_kurikoshi_gaku", ColumnType.TypeAmount, "");                    // 前期繰越額
     base.AddColumn("taisyaku_kubun_id", ColumnType.TypeInt, "");                          // 貸借区分ID  !!使用しない. 表示時にmt_kanjou_kamokuからデータを取り出すように変更(貸借区分は変更される可能性があるため)
 }
示例#22
0
        public Tyuuki8(AbstractDatabase db, string tableName = TABLE_NAME)
            : base(db, tableName)
        {
            base.AddColumn("tyuuki_id", ColumnType.TypeInt, "");         //注記ID
            base.AddColumn("tanpo_kubun_id", ColumnType.TypeInt, "");    // 担保区分
            base.AddColumn("kamoku_kubun_id", ColumnType.TypeInt, "");   // 科目区分
            base.AddColumn("amount", ColumnType.TypeAmount, "");         // 金額

            base.AddIndex("create index " + tableName + "_index on " + tableName + "(tyuuki_id)");
        }
        public void LinqCreateNotInConditionTest()
        {
            AbstractDatabase fakeDb          = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            SelectCommand    expectedCommand = fakeDb.CreateSelectCommand("");
            SelectCommand    actualCommand   = fakeDb.CreateSelectCommand("");

            SqlConditionBuilder expectedConditionBuilder = expectedCommand.ConditionBuilder;

            SqlInsideParametersCondition expectedCondition = expectedConditionBuilder.NotInThese("TestColumn1", "1");
            SqlInsideParametersCondition actualCondition   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test1.NotInThese("1")) as SqlInsideParametersCondition;

            Assert.AreEqual(expectedCondition, actualCondition);

            SqlInsideParametersCondition expectedCondition2 = expectedConditionBuilder.NotInThese("TestColumn1", "1", "2", "3", "4", "5");
            SqlInsideParametersCondition actualCondition2   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test1.NotInThese("1", "2", "3", "4", "5")) as SqlInsideParametersCondition;

            Assert.AreEqual(expectedCondition2, actualCondition2);

            SqlInsideParametersCondition expectedCondition3 = expectedConditionBuilder.NotInThese("TestColumn2", 1, 2, 3, 4, 5);
            SqlInsideParametersCondition actualCondition3   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2.NotInThese(1, 2, 3, 4, 5)) as SqlInsideParametersCondition;

            Assert.AreEqual(expectedCondition3, actualCondition3);

            SqlInsideParametersCondition expectedCondition4 = expectedConditionBuilder.NotInThese("TestColumn5", 1, 2, 3, 4, 5);
            SqlInsideParametersCondition actualCondition4   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test5.NotInThese(1, 2, 3, 4, 5)) as SqlInsideParametersCondition;

            Assert.AreEqual(expectedCondition4, actualCondition4);

            TestEntityRepository repository = new TestEntityRepository(fakeDb);
            TestEntity           entity     = new TestEntity()
            {
                Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8
            };

            SqlInsideCommandCondition expectedCondition5 = expectedConditionBuilder.NotIn("TestColumn4", repository.TableName, s =>
            {
                s.Query("TestColumn4")
                .Paged(10, 2)
                .Where <TestEntity>(c => c.Test1 == "test" && c.Test2 != 222 && c.Test4 < DateTime.Now)
                .OrderBy <TestEntity>(c => c.Test3, SqlOrderType.Desc);
            });

            Action <SelectCommand> createAnotherSelect = s =>
            {
                s.Query("TestColumn4")
                .Paged(10, 2)
                .Where <TestEntity>(sc => sc.Test1 == "test" && sc.Test2 != 222 && sc.Test4 < DateTime.Now)
                .OrderBy <TestEntity>(sc => sc.Test3, SqlOrderType.Desc);
            };

            SqlInsideCommandCondition actualCondition5 = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test4.NotIn <TestEntity>(createAnotherSelect)) as SqlInsideCommandCondition;

            Assert.AreEqual(expectedCondition5, actualCondition5);
        }
示例#24
0
        public Tyuuki10(AbstractDatabase db, string tableName = TABLE_NAME)
            : base(db, tableName)
        {
            base.AddColumn("tyuuki_id", ColumnType.TypeInt, "");                   //注記ID
            base.AddColumn("kamoku_kubun_id", ColumnType.TypeInt, "");             // 科目区分
            base.AddColumn("saiken_gaku", ColumnType.TypeAmount, "");              // 債権額
            base.AddColumn("tyousyuuhunoukin_zandaka", ColumnType.TypeAmount, ""); // 徴収不能金残高
            base.AddColumn("toukimatsu_zandaka", ColumnType.TypeAmount, "");       // 当期末残高

            base.AddIndex("create index " + tableName + "_index on " + tableName + "(tyuuki_id)");
        }
示例#25
0
        public Tyuuki11(AbstractDatabase db, string tableName = TABLE_NAME)
            : base(db, tableName)
        {
            base.AddColumn("tyuuki_id", ColumnType.TypeInt, "");        //注記ID
            base.AddColumn("caption", ColumnType.TypeString, "");       // キャプション
            base.AddColumn("tyoubo_kagaku", ColumnType.TypeAmount, ""); // 帳簿価額
            base.AddColumn("jika", ColumnType.TypeAmount, "");          // 時価
            base.AddColumn("hyouka_soneki", ColumnType.TypeAmount, ""); // 評価損益

            base.AddIndex("create index " + tableName + "_index on " + tableName + "(tyuuki_id)");
        }
示例#26
0
        public YosanHojokamoku(AbstractDatabase db, string tableName = TABLE_NAME)
            : base(db, tableName)
        {
            base.AddColumn("yosan_kubun", ColumnType.TypeInt, "");   // 予算区分
            base.AddColumn("keiri_kubun", ColumnType.TypeInt, "");   // 経理区分
            base.AddColumn("nenndo", ColumnType.TypeInt, "");        // 年度
            base.AddColumn("hojo_id", ColumnType.TypeInt, "");       // 補助科目ID
            base.AddColumn("yosan", ColumnType.TypeAmount, "");      // 予算額
            base.AddColumn("hosei_kaisuu", ColumnType.TypeInt, "");  // 補正回数

            base.AddIndex("create index " + tableName + "_index on " + tableName + "(nenndo, keiri_kubun, yosan_kubun, hosei_kaisuu)");
        }
        public void LinqCreateBasicConditionTest()
        {
            AbstractDatabase fakeDb          = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            SelectCommand    expectedCommand = fakeDb.CreateSelectCommand("");
            SelectCommand    actualCommand   = fakeDb.CreateSelectCommand("");

            SqlConditionBuilder expectedConditionBuilder = expectedCommand.ConditionBuilder;

            SqlBasicParameterCondition expectedCondition = expectedConditionBuilder.Equal("TestColumn2", 123);
            SqlBasicParameterCondition actualCondition   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2 == 123) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition, actualCondition);

            SqlBasicParameterCondition expectedCondition2 = expectedConditionBuilder.NotEqual("TestColumn2", 123);
            SqlBasicParameterCondition actualCondition2   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2 != 123) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition2, actualCondition2);

            SqlBasicParameterCondition expectedCondition3 = expectedConditionBuilder.GreaterThan("TestColumn2", 123);
            SqlBasicParameterCondition actualCondition3   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2 > 123) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition3, actualCondition3);

            SqlBasicParameterCondition expectedCondition4 = expectedConditionBuilder.LessThan("TestColumn2", 123);
            SqlBasicParameterCondition actualCondition4   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2 < 123) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition4, actualCondition4);

            SqlBasicParameterCondition expectedCondition5 = expectedConditionBuilder.GreaterThanOrEqual("TestColumn2", 123);
            SqlBasicParameterCondition actualCondition5   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2 >= 123) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition5, actualCondition5);

            SqlBasicParameterCondition expectedCondition6 = expectedConditionBuilder.LessThanOrEqual("TestColumn2", 123);
            SqlBasicParameterCondition actualCondition6   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2 <= 123) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition6, actualCondition6);

            SqlBasicParameterCondition expectedCondition7 = expectedConditionBuilder.IsNotNull("TestColumn1");
            SqlBasicParameterCondition actualCondition7   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test1 != null) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition7, actualCondition7);

            SqlBasicParameterCondition expectedCondition8 = expectedConditionBuilder.IsNull("TestColumn3");
            SqlBasicParameterCondition actualCondition8   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test3 == null) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition8, actualCondition8);

            SqlBasicParameterCondition expectedCondition10 = expectedConditionBuilder.EqualColumn("TestColumn2", "TestColumn3");
            SqlBasicParameterCondition actualCondition10   = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2 == c.Test3) as SqlBasicParameterCondition;

            Assert.AreEqual(expectedCondition10, actualCondition10);
        }
示例#28
0
        /// <summary>
        /// 初始化新的Sql语句抽象类
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="rootSource">创建时的根来源</param>
        /// <param name="tableName">表格名称</param>
        /// <exception cref="ArgumentNullException">数据库不能为空</exception>
        protected AbstractSqlCommand(AbstractDatabase database, AbstractSqlCommand rootSource, String tableName)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }

            this._database       = database;
            this._rootSource     = rootSource;
            this._tableName      = tableName;
            this._parameters     = new List <DataParameter>();
            this._parameterIndex = 0;
        }
        private static string Sql2005FormatSql(string strsql, PageInfo pageInfo, AbstractDatabase oleDb)
        {
            if (pageInfo.KeyName == null || pageInfo.KeyName == "")
            {
                throw new Exception("分页KeyName属性不能为空,如:pageInfo.KeyName==\"Id\" 或 pageInfo.KeyName==\"Id|Desc\"");
            }

            int    starRecordNum = pageInfo.startNum;
            int    endRecordNum  = pageInfo.endNum;
            int    index         = strsql.ToLower().LastIndexOf("order by");
            string _strsql       = null;

            if (index != -1)
            {
                _strsql = strsql.Remove(index);
            }
            else
            {
                _strsql = strsql;
            }


            string sql_totalRecord = "select TOP 1 count(*) from (" + _strsql + ") A";
            Object obj             = oleDb.GetDataResult(sql_totalRecord);

            pageInfo.totalRecord = Convert.ToInt32(obj == DBNull.Value ? 0 : obj);

            string _sql = _strsql;

            string[] orderbys = pageInfo.KeyName.Split(new char[] { '|' });
            string   orderbyname, orderby;

            if (orderbys.Length != 2)
            {
                orderbyname = orderbys[0];
                orderby     = "desc";
            }
            else
            {
                orderbyname = orderbys[0];
                orderby     = orderbys[1];
            }

            strsql = @"select * from
                        (
                        select row_number() over(order by {3} {4}) as rownum,t.* from ({0}) t
                        ) as a where rownum between {1} and {2}";

            strsql = String.Format(strsql, _sql, starRecordNum, endRecordNum, orderbyname, orderby);
            return(strsql);
        }
        /// <summary>
        /// 获取数据库连接
        /// </summary>
        /// <param name="db">数据库</param>
        /// <returns>数据库连接</returns>
        internal static DatabaseConnectionWrapper GetConnection(AbstractDatabase db)
		{
            SystemTransaction currentTransaction = SystemTransaction.Current;

			if (currentTransaction == null)
			{
				return null;
			}

            Dictionary<SystemTransaction, Dictionary<String, DatabaseConnectionWrapper>> obj;

            Monitor.Enter(obj = TransactionConnections);
			Dictionary<String, DatabaseConnectionWrapper> connectionList;

			try
			{
                if (!TransactionConnections.TryGetValue(currentTransaction, out connectionList))
				{
					connectionList = new Dictionary<String, DatabaseConnectionWrapper>();
                    TransactionConnections.Add(currentTransaction, connectionList);

					currentTransaction.TransactionCompleted += new TransactionCompletedEventHandler(TransactionScopeConnections.OnTransactionCompleted);
				}
			}
			finally
			{
                Monitor.Exit(obj);
			}

			Dictionary<String, DatabaseConnectionWrapper> obj2;

			Monitor.Enter(obj2 = connectionList);
			DatabaseConnectionWrapper connection;

			try
			{
                if (!connectionList.TryGetValue(db.ConnectionString, out connection))
				{
                    connection = db.InternalGetConnection();
                    connectionList.Add(db.ConnectionString, connection);
				}

                connection.AddRef();
			}
			finally
			{
				Monitor.Exit(obj2);
			}

            return connection;
        }
示例#31
0
 public MTHoujinDantai(AbstractDatabase db)
     : base(db, TABLE_NAME)
 {
     base.AddColumn("dantai_meisyou", ColumnType.TypeString, "");            // 団体名称
     base.AddColumn("yuubin_bangou", ColumnType.TypeString, "");             // 郵便番号
     base.AddColumn("todouhuken", ColumnType.TypeString, "");                // 都道府県
     base.AddColumn("si_ku_gun", ColumnType.TypeString, "");                 // 市区群
     base.AddColumn("tyou_son_iki", ColumnType.TypeString, "");              // 町村域
     base.AddColumn("tatemono_mei", ColumnType.TypeString, "");              // 建物名
     base.AddColumn("denwa_bangou", ColumnType.TypeString, "");              // 電話番号
     base.AddColumn("fax_bangou", ColumnType.TypeString, "");                // FAX番号
     base.AddColumn("daihyousya_shimei", ColumnType.TypeString, "");         // 代表者氏名
     base.AddColumn("barcode", ColumnType.TypeString, "");                   // バーコード
 }
示例#32
0
        private static string Db2FormatSql(string strsql, PageInfo pageInfo, AbstractDatabase oleDb)
        {
            
            if (pageInfo.KeyName == null || pageInfo.KeyName == "")
                throw new Exception("分页KeyName属性不能为空,如:pageInfo.KeyName==\"Id\" 或 pageInfo.KeyName==\"Id|Desc\"");

            int starRecordNum = pageInfo.startNum;
            int endRecordNum = pageInfo.endNum;
            //int index = strsql.ToLower().LastIndexOf("order by");
            //string _strsql = null;
            //if (index != -1)
            //    _strsql = strsql.Remove(index);
            //else
            //    _strsql = strsql;

            string _strsql = strsql;


            string sql_totalRecord = "select count(*) from (" + _strsql + ") A";
            Object obj = oleDb.GetDataResult(sql_totalRecord);
            pageInfo.totalRecord = Convert.ToInt32(obj == DBNull.Value ? 0 : obj);

            string _sql = _strsql;
            string[] orderbys = pageInfo.KeyName.Split(new char[] { '|' });
            string orderbyname, orderby;
            if (orderbys.Length != 2)
            {
                orderbyname = orderbys[0];
                orderby = "desc";
            }
            else
            {
                orderbyname = orderbys[0];
                orderby = orderbys[1];
            }

            strsql = @"select * from (
                                select rownumber() over(order by {3} {4}) as rowid,  t.* from ({0}) t
                            )as a where a.rowid >= {1} AND  a.rowid < {2}";

            strsql = String.Format(strsql, _sql, starRecordNum, endRecordNum, orderbyname, orderby);
            return strsql;
        }
示例#33
0
 /// <summary>
 /// 格式化SQL语句
 /// </summary>
 /// <param name="strsql"></param>
 /// <param name="pageInfo"></param>
 /// <param name="oleDb"></param>
 /// <returns></returns>
 public static string FormatSql(string strsql, PageInfo pageInfo, AbstractDatabase oleDb)
 {
     switch (oleDb.DbType)
     {
         case DatabaseType.IbmDb2:
            return Db2FormatSql(strsql, pageInfo, oleDb);
         case DatabaseType.MsAccess:
            return MsAccessFormatSql(strsql, pageInfo, oleDb);
         case DatabaseType.MySQL:
            return MySQLFormatSql(strsql, pageInfo, oleDb);
         case DatabaseType.Oracle:
            return OracleFormatSql(strsql, pageInfo, oleDb);
         case DatabaseType.SqlServer2000:
            return Sql2000FormatSql(strsql, pageInfo, oleDb);
         case DatabaseType.SqlServer2005:
            return Sql2005FormatSql(strsql, pageInfo, oleDb);
     }
     return null;
 }
示例#34
0
        /// <summary>
        /// 初始化Sql语句参数类
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="columnName">字段名</param>
        /// <param name="parameterIndex">参数索引</param>
        /// <param name="value">赋值内容</param>
        private SqlParameter(AbstractDatabase database, String columnName, Int32 parameterIndex, Object value)
        {
            this._parameter = new BaseSqlParameter();
            this._parameter.SourceColumn = columnName;
            this._parameter.ParameterName = database.InternalGetParameterName("PN_IDX_" + parameterIndex.ToString());

            if (value == null)
            {
                this._parameter.Value = DBNull.Value;
            }
            else if (value is DateTime)
            {
                DateTime dt = (DateTime)value;
                this._parameter.Value = dt.ToString("yyyy-MM-dd HH:mm:ss");
            }
            else
            {
                this._parameter.Value = value;
            }

            this._isUseParameter = true;
        }
示例#35
0
 /// <summary>
 /// 初始化SQL语句创建类
 /// </summary>
 /// <param name="database">数据库</param>
 internal SqlCommandBuilder(AbstractDatabase database)
 {
     this._stringBuilder = new StringBuilder();
     this._database = database;
 }
示例#36
0
        /// <summary>
        /// 创建新的Sql语句参数类
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="columnName">字段名</param>
        /// <param name="parameterIndex">参数索引</param>
        /// <param name="dataType">字段类型</param>
        /// <param name="value">赋值内容</param>
        /// <returns>Sql语句参数类</returns>
        internal static DataParameter InternalCreate(AbstractDatabase database, String columnName, String parameterIndex, DataType dataType, Object value)
        {
            DataParameter param = new DataParameter(database, columnName, parameterIndex, value);
            param._parameter.DbType = DataParameter.GetDbType(dataType);

            return param;
        }
示例#37
0
        public static void AppStart()
        {
            lock (locker)
            {
                if (_isCalled == false)
                {
                    try
                    {
                        WriterLog("--------------------------------");
                        WriterLog("应用开始启动!");

                        string  ClientType=System.Configuration.ConfigurationManager.AppSettings["ClientType"];
                        if (ClientType == "Web")
                        {
                            appType = AppType.Web;
                            
                        }
                        else if (ClientType == "Winform")
                        {
                            appType = AppType.Winform;
                            AppRootPath = System.Windows.Forms.Application.StartupPath + "\\";
                        }
                        else if (ClientType == "WCF")
                        {
                            appType = AppType.WCF;
                            AppRootPath = System.Windows.Forms.Application.StartupPath + "\\";
                        }
                        else if (ClientType == "WCFClient")
                        {
                            appType = AppType.WCFClient;
                            AppRootPath = System.Windows.Forms.Application.StartupPath + "\\";
                        }


                        IsSaas = System.Configuration.ConfigurationManager.AppSettings["IsSaas"] == "true" ? true : false;

                        container = ZhyContainer.CreateUnity();
                        cache = ZhyContainer.CreateCache();
                        database = FactoryDatabase.GetDatabase();
                        taskList = new List<TimingTask>();
                        codeList = new List<FunClass>();
                        missingDll = new List<string>();

                        AppPluginManage.LoadAllPlugin();

                        //初始化Web定制任务
                        MultiTask.Init(container, taskList);//任务                       
                        //是否开启Web控制器请求权限认证

                        //扩展Global,网站程序启动、停止可自定义代码
                        GlobalExtend.StartInit();
                        //初始化委托代码
                        BaseDelegateCode.Init(container, codeList);//执行函数

                        _isCalled = true;
                       

                        IsRun = true;

                        if (missingDll.Count > 0)
                        {
                            string msg = "缺失的程序集:";
                            WriterLog(msg);
                            for (int i = 0; i < missingDll.Count; i++)
                            {
                                msg = missingDll[i];
                                WriterLog(msg);
                            }
                            //MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        WriterLog("应用启动成功!");
                        WriterLog("--------------------------------");
                        //AppMain();
                    }
                    catch(Exception err)
                    {
                        AppGlobal.WriterLog("应用启动失败!");
                        AppGlobal.WriterLog(err.Message);
                        AppGlobal.WriterLog("--------------------------------");
                        throw err;
                    }
                }
            }
        }
 /// <summary>
 /// 初始化Sql基本函数抽象
 /// </summary>
 /// <param name="baseDatabase">源数据库</param>
 protected AbstractSqlBasicFunction(AbstractDatabase baseDatabase)
 {
     this._baseDatabase = baseDatabase;
 }
示例#39
0
 /// <summary>
 /// 初始化Sql更新语句类
 /// </summary>
 /// <param name="database">数据库</param>
 /// <param name="tableName">数据表名称</param>
 internal UpdateCommand(AbstractDatabase database, String tableName)
     : base(database, tableName) { }
示例#40
0
 /// <summary>
 /// 初始化新的Sql内置函数
 /// </summary>
 /// <param name="baseDatabase">源数据库</param>
 /// <param name="funcType">函数类型</param>
 /// <param name="parameters">函数参数列表</param>
 internal SqlInnerFunction(AbstractDatabase baseDatabase, SqlInnerFunctionType funcType, params String[] parameters)
     : base(baseDatabase)
 {
     this._parameters = parameters;
     this._functionType = funcType;
 }
示例#41
0
 private static string Sql2000FormatSql(string strsql, PageInfo pageInfo, AbstractDatabase oleDb)
 {
     return null;
 }
示例#42
0
        private static string OracleFormatSql(string strsql, PageInfo pageInfo, AbstractDatabase oleDb)
        {
            int starRecordNum = pageInfo.startNum;
            int endRecordNum = pageInfo.endNum;

            string sql_totalRecord = "select count(*) from (" + strsql + ") A";
            Object obj = oleDb.GetDataResult(sql_totalRecord);
            pageInfo.totalRecord = Convert.ToInt32(obj == DBNull.Value ? 0 : obj);

            strsql = " select * from( select a.*,rownum rn from ( " + strsql + " ) a )  where rn between " + starRecordNum.ToString() + " and " + endRecordNum.ToString();
           
            return strsql;
        }
示例#43
0
 /// <summary>
 /// 初始化新的Sql自定义语句类
 /// </summary>
 /// <param name="database">数据库</param>
 /// <param name="commandType">语句类型</param>
 /// <param name="commandString">语句内容</param>
 internal CustomCommand(AbstractDatabase database, SqlCommandType commandType, String commandString)
     : base(database, String.Empty)
 {
     this._commandType = commandType;
     this._commandText = commandString;
 }
示例#44
0
 /// <summary>
 /// 创建新的Sql语句参数类
 /// </summary>
 /// <param name="database">数据库</param>
 /// <param name="columnName">字段名</param>
 /// <param name="action">赋值操作</param>
 /// <returns>Sql语句参数类</returns>
 internal static SqlParameter InternalCreateCustomAction(AbstractDatabase database, String columnName, String action)
 {
     return new SqlParameter(database, columnName, action);
 }
示例#45
0
        /// <summary>
        /// 创建新的Sql语句参数类
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="columnName">字段名</param>
        /// <param name="parameterIndex">参数索引</param>
        /// <param name="dbType">字段类型</param>
        /// <param name="value">赋值内容</param>
        /// <returns>Sql语句参数类</returns>
        internal static SqlParameter InternalCreate(AbstractDatabase database, String columnName, Int32 parameterIndex, DbType dbType, Object value)
        {
            SqlParameter param = new SqlParameter(database, columnName, parameterIndex, value);
            param._parameter.DbType = dbType;

            return param;
        }
示例#46
0
 /// <summary>
 /// 初始化Sql插入语句类
 /// </summary>
 /// <param name="database">数据库</param>
 /// <param name="tableName">数据表名称</param>
 internal InsertCommand(AbstractDatabase database, String tableName)
     : base(database, tableName) { }
示例#47
0
        /// <summary>
        /// 初始化Sql语句参数类
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="columnName">字段名</param>
        /// <param name="action">赋值操作</param>
        private SqlParameter(AbstractDatabase database, String columnName, String action)
        {
            this._parameter = new BaseSqlParameter();
            this._parameter.SourceColumn = columnName;
            this._parameter.Value = action;

            this._isUseParameter = false;
        }
        /// <summary>
        /// 初始化新的Sql语句抽象类
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="tableName">表格名称</param>
        /// <exception cref="ArgumentNullException">数据库不能为空</exception>
        protected AbstractSqlCommand(AbstractDatabase database, String tableName)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }

            this._database = database;
            this._tableName = tableName;
            this._parameters = new List<SqlParameter>();
            this._parameterIndex = 0;
        }
 /// <summary>
 /// 初始化新的有Where语句的Sql语句抽象类
 /// </summary>
 /// <param name="database">数据库</param>
 /// <param name="rootSource">创建时的根来源</param>
 /// <param name="tableName">表格名称</param>
 protected AbstractSqlCommandWithWhere(AbstractDatabase database, AbstractSqlCommand rootSource, String tableName)
     : base(database, rootSource, tableName)
 {
     this._conditionBuilder = new SqlConditionBuilder(this);
 }
示例#50
0
 /// <summary>
 /// 初始化新的Sql函数类
 /// </summary>
 /// <param name="baseDatabase">源数据库</param>
 public SqlFunctions(AbstractDatabase baseDatabase)
 {
     this._baseDatabase = baseDatabase;
 }