示例#1
0
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="en"></param>
        /// <returns></returns>
        public static int Insert_del(Entity en)
        {
            if (en.EnMap.EnType == EnType.Ext)
            {
                throw new Exception("@实体[" + en.EnDesc + "]是扩展类型,不能执行插入。");
            }

            if (en.EnMap.EnType == EnType.View)
            {
                throw new Exception("@实体[" + en.EnDesc + "]是视图类型,不能执行插入。");
            }

            try
            {
                switch (en.EnMap.EnDBUrl.DBUrlType)
                {
                case DBUrlType.AppCenterDSN:
                    return(DBAccess.RunSQL(SqlBuilder.Insert(en)));

                case DBUrlType.DBAccessOfMSMSSQL:
                    return(DBAccessOfMSMSSQL.RunSQL(SqlBuilder.Insert(en)));

                case DBUrlType.DBAccessOfOracle:
                    return(DBAccessOfOracle.RunSQL(SqlBuilder.Insert(en)));

                default:
                    throw new Exception("@没有设置类型。");
                }
            }
            catch (Exception ex)
            {
                en.CheckPhysicsTable();                 // 检查物理表。
                throw ex;
            }
        }
示例#2
0
        public static int Update(Entity en)
        {
            try
            {
                switch (en.EnMap.EnDBUrl.DBUrlType)
                {
                case DBUrlType.AppCenterDSN:
                    switch (SystemConfig.AppCenterDBType)
                    {
                    case DBType.Oracle:
                        return(DBAccess.RunSQL(en.SQLCash.Update, SqlBuilder.GenerParas(en, null)));

                    case DBType.Access:
                        return(DBAccess.RunSQL(SqlBuilder.UpdateOfMSAccess(en, null)));

                    default:
                        return(DBAccess.RunSQL(SqlBuilder.Update(en, null)));
                    }

                case DBUrlType.DBAccessOfMSSQL1:
                    return(DBAccessOfMSSQL1.RunSQL(SqlBuilder.Update(en, null)));

                case DBUrlType.DBAccessOfMSSQL2:
                    return(DBAccessOfMSSQL2.RunSQL(SqlBuilder.Update(en, null)));

                case DBUrlType.DBAccessOfOracle1:
                    return(DBAccessOfOracle1.RunSQL(SqlBuilder.Update(en, null)));

                case DBUrlType.DBAccessOfOracle2:
                    return(DBAccessOfOracle2.RunSQL(SqlBuilder.Update(en, null)));

                default:
                    throw new Exception("@没有设置类型。");
                }
            }
            catch (Exception ex)
            {
                if (BP.Sys.SystemConfig.IsDebug)
                {
                    en.CheckPhysicsTable();
                }
                throw ex;
            }
        }
示例#3
0
        public string SystemClass_EnsCheck()
        {
            try
            {
                BP.En.Entity en  = BP.En.ClassFactory.GetEn(this.EnName);
                BP.En.Map    map = en.EnMap;
                en.CheckPhysicsTable();
                string msg = "";
                // string msg = "";
                string table  = "";
                string sql    = "";
                string sql1   = "";
                string sql2   = "";
                int    COUNT1 = 0;
                int    COUNT2 = 0;

                DataTable dt    = new DataTable();
                Entity    refen = null;
                foreach (Attr attr in map.Attrs)
                {
        public void BindCheck()
        {
            BP.En.Entity en  = BP.En.ClassFactory.GetEn(this.EnsName);
            BP.En.Map    map = en.EnMap;
            en.CheckPhysicsTable();
            string msg = "";
            // string msg = "";
            string table  = "";
            string sql    = "";
            string sql1   = "";
            string sql2   = "";
            int    COUNT1 = 0;
            int    COUNT2 = 0;

            DataTable dt    = new DataTable();
            Entity    refen = null;

            foreach (Attr attr in map.Attrs)
            {
                /**/
                if (attr.MyFieldType == FieldType.FK || attr.MyFieldType == FieldType.PKFK)
                {
                    refen = ClassFactory.GetEns(attr.UIBindKey).GetNewEntity;
                    table = refen.EnMap.PhysicsTable;
                    sql1  = "SELECT COUNT(*) FROM " + table;

                    Attr pkAttr = refen.EnMap.GetAttrByKey(refen.PK);
                    sql2 = "SELECT COUNT( distinct " + pkAttr.Field + ") FROM " + table;

                    COUNT1 = DBAccess.RunSQLReturnValInt(sql1);
                    COUNT2 = DBAccess.RunSQLReturnValInt(sql2);

                    if (COUNT1 != COUNT2)
                    {
                        msg += "<BR>@关联表(" + refen.EnMap.EnDesc + ")主键不唯一,它会造成数据查询不准确或者意向不到的错误:<BR>sql1=" + sql1 + " <BR>sql2=" + sql2;
                        msg += "@SQL= SELECT * FROM (  select " + refen.PK + ",  COUNT(*) AS NUM  from " + table + " GROUP BY " + refen.PK + " ) WHERE NUM!=1";
                    }

                    sql = "SELECT " + attr.Field + " FROM " + map.PhysicsTable + " WHERE " + attr.Field + " NOT IN (SELECT " + pkAttr.Field + " FROM " + table + " )";
                    dt  = DBAccess.RunSQLReturnTable(sql);
                    if (dt.Rows.Count == 0)
                    {
                        continue;
                    }
                    else
                    {
                        msg += "<BR>:有" + dt.Rows.Count + "个错误。" + attr.Desc + " sql= " + sql;
                    }
                }
                if (attr.MyFieldType == FieldType.PKEnum || attr.MyFieldType == FieldType.Enum)
                {
                    sql = "SELECT " + attr.Field + " FROM " + map.PhysicsTable + " WHERE " + attr.Field + " NOT IN ( select Intkey from sys_enum WHERE ENUMKEY='" + attr.UIBindKey + "' )";
                    dt  = DBAccess.RunSQLReturnTable(sql);
                    if (dt.Rows.Count == 0)
                    {
                        continue;
                    }
                    else
                    {
                        msg += "<BR>:有" + dt.Rows.Count + "个错误。" + attr.Desc + " sql= " + sql;
                    }
                }
            }

            // 检查pk是否一致。
            if (en.PKs.Length == 1)
            {
                sql1   = "SELECT COUNT(*) FROM " + map.PhysicsTable;
                COUNT1 = DBAccess.RunSQLReturnValInt(sql1);

                Attr attrMyPK = en.EnMap.GetAttrByKey(en.PK);
                sql2   = "SELECT COUNT(DISTINCT " + attrMyPK.Field + ") FROM " + map.PhysicsTable;
                COUNT2 = DBAccess.RunSQLReturnValInt(sql2);
                if (COUNT1 != COUNT2)
                {
                    msg += "@物理表(" + map.EnDesc + ")中主键不唯一;它会造成数据查询不准确或者意向不到的错误:<BR>sql1=" + sql1 + " <BR>sql2=" + sql2;
                    msg += "@SQL= SELECT * FROM (  select " + en.PK + ",  COUNT(*) AS NUM  from " + map.PhysicsTable + " GROUP BY " + en.PK + " ) WHERE NUM!=1";
                }
            }

            if (msg == "")
            {
                this.UCSys1.AddMsgOfInfo(map.EnDesc + ":数据体检信息:", "体检成功。");
            }
            else
            {
                this.UCSys1.AddMsgOfWarning(map.EnDesc + ":数据体检信息:", "体检失败<BR>" + msg.Replace("@", "<BR>@"));
            }

            string help = "";

            help += "@什么是数据体检?";
            help += "&nbsp;&nbsp;数据体检就是检查数据的完整性。";
            help += "@如果系统升级,一些字段的长度发生变化,字段的类型发生变化系统就会自动修复。";
            help += "@系统会检查出来,外键枚举对应不上的信息,并把该信息列出来让管理员处理。";

            this.UCSys1.AddMsgOfInfo("什么是数据体检?", help);
        }
示例#5
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="en">产生要更新的语句</param>
        /// <param name="keys">要更新的属性(null,认为更新全部)</param>
        /// <returns>sql</returns>
        public static int Update(Entity en, string[] keys)
        {
            if (en.EnMap.EnType == EnType.View)
            {
                return(0);
            }

            var    paras = SqlBuilder.GenerParas(en, keys);
            string sql   = en.SQLCash.GetUpdateSQL(en, keys);

            try
            {
                switch (en.EnMap.EnDBUrl.DBUrlType)
                {
                case DBUrlType.AppCenterDSN:
                    switch (SystemConfig.AppCenterDBType)
                    {
                    case DBType.MSSQL:
                    case DBType.Oracle:
                    case DBType.MySQL:
                        return(DBAccess.RunSQL(sql, paras));

                    case DBType.Informix:
                        return(DBAccess.RunSQL(en.SQLCash.GetUpdateSQL(en, keys), SqlBuilder.GenerParas_Update_Informix(en, keys)));

                    case DBType.Access:
                        return(DBAccess.RunSQL(SqlBuilder.UpdateOfMSAccess(en, keys)));

                    default:
                        //return DBAccess.RunSQL(en.SQLCash.GetUpdateSQL(en, keys),
                        //    SqlBuilder.GenerParas(en, keys));
                        if (keys != null)
                        {
                            Paras ps   = new Paras();
                            Paras myps = SqlBuilder.GenerParas(en, keys);
                            foreach (Para p in myps)
                            {
                                foreach (string s in keys)
                                {
                                    if (s == p.ParaName)
                                    {
                                        ps.Add(p);
                                        break;
                                    }
                                }
                            }
                            return(DBAccess.RunSQL(en.SQLCash.GetUpdateSQL(en, keys), ps));
                        }
                        else
                        {
                            return(DBAccess.RunSQL(en.SQLCash.GetUpdateSQL(en, keys),
                                                   SqlBuilder.GenerParas(en, keys)));
                        }
                        break;
                    }

                //case DBUrlType.DBAccessOfMSSQL1:
                //    return DBAccessOfMSSQL1.RunSQL(SqlBuilder.Update(en, keys));
                //case DBUrlType.DBAccessOfMSSQL2:
                //    return DBAccessOfMSSQL2.RunSQL(SqlBuilder.Update(en, keys));
                //case DBUrlType.DBAccessOfOracle1:
                //    return DBAccessOfOracle1.RunSQL(SqlBuilder.Update(en, keys));
                //case DBUrlType.DBAccessOfOracle2:
                //    return DBAccessOfOracle2.RunSQL(SqlBuilder.Update(en, keys));
                default:
                    throw new Exception("@没有设置类型。");
                }
            }
            catch (Exception ex)
            {
                if (BP.Sys.SystemConfig.IsDebug)
                {
                    en.CheckPhysicsTable();
                }
                throw ex;
            }
        }