Example #1
0
        public static FrmQuery Create(DAL db)
        {
            if (db == null) throw new ArgumentNullException("db");

            FrmQuery frm = new FrmQuery();
            frm.Dal = db;

            return frm;
        }
Example #2
0
File: DAL.cs Project: tommybiteme/X
        /// <summary>创建一个数据访问层对象。</summary>
        /// <param name="connName">配置名</param>
        /// <returns>对应于指定链接的全局唯一的数据访问层对象</returns>
        public static DAL Create(String connName)
        {
            if (String.IsNullOrEmpty(connName)) throw new ArgumentNullException("connName");

            // 如果需要修改一个DAL的连接字符串,不应该修改这里,而是修改DAL实例的ConnStr属性
            DAL dal = null;
            if (_dals.TryGetValue(connName, out dal)) return dal;
            lock (_dals)
            {
                if (_dals.TryGetValue(connName, out dal)) return dal;

                dal = new DAL(connName);
                // 不用connName,因为可能在创建过程中自动识别了ConnName
                _dals.Add(dal.ConnName, dal);
            }

            return dal;
        }
Example #3
0
        /// <summary>创建一个数据访问层对象。</summary>
        /// <param name="connName">配置名,或链接字符串</param>
        /// <returns>对应于指定链接的全局唯一的数据访问层对象</returns>
        public static DAL Create(String connName)
        {
            if (String.IsNullOrEmpty(connName)) throw new ArgumentNullException("connName");

            DAL dal = null;
            if (_dals.TryGetValue(connName, out dal)) return dal;
            lock (_dals)
            {
                if (_dals.TryGetValue(connName, out dal)) return dal;

                ////检查数据库最大连接数授权。
                //if (License.DbConnectCount != _dals.Count + 1)
                //    License.DbConnectCount = _dals.Count + 1;

                dal = new DAL(connName);
                // 不用connName,因为可能在创建过程中自动识别了ConnName
                _dals.Add(dal.ConnName, dal);
            }

            return dal;
        }
Example #4
0
        /// <summary>
        /// 初始化数据库结构
        /// </summary>
        private void InitDataSchema()
        {
            try
            {
                XTrace.WriteLine(String.Format("开始对数据库[{0}]的架构加载...", m_conn.Database.DatabaseName));

                DAL.AddConnStr(m_conn.Database.ConnName, m_conn.ConnString, null, m_conn.Database.Provider);
                DAL dal = DAL.Create(m_conn.Database.ConnName);

                dal.Session.QuickTest();

                m_dal = dal;
                m_tableCount = dal.Tables.FindAll(x => !x.IsView).Count;
                m_viewCount = dal.Tables.FindAll(x => x.IsView).Count;

                m_initStatus = DataSchemaInitStatus.Initialized;

                XTrace.WriteLine(String.Format("完成对数据库[{0}]的架构加载...", m_conn.Database.DatabaseName));
            }
            catch (Exception ex)
            {
                m_initStatus = DataSchemaInitStatus.Error;
                m_initError = ex.Message;
            }
            finally
            {
                OnStatusChange(new StatusChangeEventArgs(m_initStatus));
            }
        }
Example #5
0
        /// <summary>����һ�����ݷ��ʲ����</summary>
        /// <param name="connName">���������������ַ���</param>
        /// <returns>��Ӧ��ָ�����ӵ�ȫ��Ψһ�����ݷ��ʲ����</returns>
        public static DAL Create(String connName)
        {
            if (String.IsNullOrEmpty(connName)) throw new ArgumentNullException("connName");

            DAL dal = null;
            if (_dals.TryGetValue(connName, out dal)) return dal;
            lock (_dals)
            {
                if (_dals.TryGetValue(connName, out dal)) return dal;

                ////������ݿ������������Ȩ��
                //if (License.DbConnectCount != _dals.Count + 1)
                //    License.DbConnectCount = _dals.Count + 1;

                dal = new DAL(connName);
                // ����connName����Ϊ�����ڴ����������Զ�ʶ����ConnName
                _dals.Add(dal.ConnName, dal);
            }

            return dal;
        }
Example #6
0
        /// <summary>代码生成测试</summary>
        /// <param name="dal"></param>
        public static void CodeTest(DAL dal)
        {
            //XTable table = dal.Tables[0];

            //foreach (XTable item in dal.Tables)
            //{
            //    if (item.Name == "Area")
            //    {
            //        table = item;
            //        break;
            //    }
            //}

            EntityAssembly asm = new EntityAssembly();
            asm.Dal = dal;
            asm.NameSpace = new System.CodeDom.CodeNamespace("XCode.Test.Entities");

            //EntityClass entity = asm.Create(table);
            //entity.Create();
            //entity.AddProperties();
            //entity.AddIndexs();
            //entity.AddNames();

            EntityClass entity = asm.Create("Area");
            String str = entity.GenerateCSharpCode();
            Console.WriteLine(str);

            CompilerResults rs = asm.Compile(null);
            foreach (String item in rs.Output)
            {
                Console.WriteLine(item);
            }

            //asm.CreateAll();

            //str = asm.GenerateCSharpCode();
            ////File.WriteAllText(dal.ConnName + ".cs", str);

            //Console.WriteLine(str);
        }