Пример #1
0
 public static void SetMap(string clName, BP.En.Map map)
 {
     if (clName == null)
     {
         return;
     }
     //    throw new Exception("clName.不能为空。");
     if (map == null)
     {
         Map_Cash.Remove(clName);
         return;
     }
     Map_Cash[clName] = map;
 }
Пример #2
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);
        }
        public void BindEn(Entity en)
        {
            BP.En.Map map = en.EnMap;
            en.CheckPhysicsTable();


            this.UCSys1.AddTable();

            if (this.EnsName == null)
            {
                this.UCSys1.AddCaptionLeft("数据结构:" + map.EnDesc + "," + map.PhysicsTable);
            }
            else
            {
                this.UCSys1.AddCaptionLeft("数据结构:" + map.EnDesc + "," + map.PhysicsTable);
            }

            this.UCSys1.AddTR();
            this.UCSys1.AddTDTitle("序号");
            this.UCSys1.AddTDTitle("描述");
            this.UCSys1.AddTDTitle("属性");
            this.UCSys1.AddTDTitle("物理字段");
            this.UCSys1.AddTDTitle("数据类型");
            this.UCSys1.AddTDTitle("关系类型");
            this.UCSys1.AddTDTitle("长度");
            this.UCSys1.AddTDTitle("对应");
            this.UCSys1.AddTDTitle("默认值");
            this.UCSys1.AddTREnd();

            int i = 0;

            foreach (Attr attr in map.Attrs)
            {
                if (attr.MyFieldType == FieldType.RefText)
                {
                    continue;
                }
                i++;
                this.UCSys1.AddTR();
                this.UCSys1.AddTDIdx(i);
                this.UCSys1.AddTD(attr.Desc);
                this.UCSys1.AddTD(attr.Key);
                this.UCSys1.AddTD(attr.Field);
                this.UCSys1.AddTD(attr.MyDataTypeStr);
                this.UCSys1.AddTD(attr.MyFieldType.ToString());

                if (attr.MyDataType == DataType.AppBoolean ||
                    attr.MyDataType == DataType.AppDouble ||
                    attr.MyDataType == DataType.AppFloat ||
                    attr.MyDataType == DataType.AppInt ||
                    attr.MyDataType == DataType.AppMoney ||
                    attr.MyDataType == DataType.AppRate
                    )
                {
                    this.UCSys1.AddTD("无");
                }
                else
                {
                    this.UCSys1.AddTD(attr.MaxLength);
                }


                switch (attr.MyFieldType)
                {
                case FieldType.Enum:
                case FieldType.PKEnum:
                    try
                    {
                        SysEnums ses = new SysEnums(attr.UIBindKey);
                        string   str = "";
                        foreach (SysEnum se in ses)
                        {
                            str += se.IntKey + "&nbsp;" + se.Lab + ",";
                        }
                        this.UCSys1.AddTD(str);
                    }
                    catch
                    {
                        this.UCSys1.AddTD("未使用");
                    }
                    break;

                case FieldType.FK:
                case FieldType.PKFK:
                    Entities ens = ClassFactory.GetEns(attr.UIBindKey);
                    this.UCSys1.AddTD("表/视图:" + ens.GetNewEntity.EnMap.PhysicsTable + " 关联字段:" + attr.UIRefKeyValue + "," + attr.UIRefKeyText);
                    break;

                default:
                    this.UCSys1.AddTD("无");
                    break;
                }

                this.UCSys1.AddTD(attr.DefaultVal.ToString());
                this.UCSys1.AddTREnd();
            }
            this.UCSys1.AddTableEnd();
        }
Пример #5
0
        /// <summary>
        /// 执行导入
        /// </summary>
        /// <returns></returns>
        public string ImpData_Done()
        {
            HttpFileCollection files = context.Request.Files;

            if (files.Count == 0)
            {
                return("err@请选择要导入的数据信息。");
            }

            string errInfo = "";

            string ext      = ".xls";
            string fileName = System.IO.Path.GetFileName(files[0].FileName);

            if (fileName.Contains(".xlsx"))
            {
                ext = ".xlsx";
            }


            //设置文件名
            string fileNewName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ext;

            //文件存放路径
            string filePath = BP.Sys.SystemConfig.PathOfTemp + "\\" + fileNewName;

            files[0].SaveAs(filePath);

            //从excel里面获得数据表.
            DataTable dt = BP.DA.DBLoad.ReadExcelFileToDataTable(filePath);

            //删除临时文件
            System.IO.File.Delete(filePath);

            if (dt.Rows.Count == 0)
            {
                return("err@无导入的数据");
            }

            //获得entity.
            Entities ens = ClassFactory.GetEns(this.EnsName);
            Entity   en  = ens.GetNewEntity;

            if (en.PK.Equals("MyPK") == true)
            {
                return(this.ImpData_DoneMyPK(ens, dt));
            }

            if (en.IsNoEntity == false)
            {
                return("err@必须是EntityNo或者EntityMyPK实体,才能导入.");
            }

            string noColName   = ""; //实体列的编号名称.
            string nameColName = ""; //实体列的名字名称.

            Attr attr = en.EnMap.GetAttrByKey("No");

            noColName = attr.Desc; //
            BP.En.Map map        = en.EnMap;
            String    codeStruct = map.CodeStruct;

            attr        = map.GetAttrByKey("Name");
            nameColName = attr.Desc; //

            //定义属性.
            Attrs attrs = en.EnMap.Attrs;

            int impWay = this.GetRequestValInt("ImpWay");

            #region 清空方式导入.
            //清空方式导入.
            int    count       = 0; //导入的行数
            int    changeCount = 0; //更新的行数
            String successInfo = "";
            if (impWay == 0)
            {
                ens.ClearTable();
                foreach (DataRow dr in dt.Rows)
                {
                    string no   = dr[noColName].ToString();
                    string name = dr[nameColName].ToString();

                    //判断是否是自增序列,序列的格式
                    if (!DataType.IsNullOrEmpty(codeStruct))
                    {
                        no = no.PadLeft(System.Int32.Parse(codeStruct), '0');
                    }

                    EntityNoName myen = ens.GetNewEntity as EntityNoName;
                    myen.No = no;
                    if (myen.IsExits == true)
                    {
                        errInfo += "err@编号[" + no + "][" + name + "]重复.";
                        continue;
                    }

                    myen.Name = name;

                    en = ens.GetNewEntity;

                    //给实体赋值
                    errInfo += SetEntityAttrVal(no, dr, attrs, en, dt, 0);
                    count++;
                    successInfo += "&nbsp;&nbsp;<span>" + noColName + "为" + no + "," + nameColName + "为" + name + "的导入成功</span><br/>";
                }
            }

            #endregion 清空方式导入.

            #region 更新方式导入
            if (impWay == 1 || impWay == 2)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    string no   = dr[noColName].ToString();
                    string name = dr[nameColName].ToString();
                    //判断是否是自增序列,序列的格式
                    if (!DataType.IsNullOrEmpty(codeStruct))
                    {
                        no = no.PadLeft(System.Int32.Parse(codeStruct), '0');
                    }
                    EntityNoName myen = ens.GetNewEntity as EntityNoName;
                    myen.No = no;
                    if (myen.IsExits == true)
                    {
                        //给实体赋值
                        errInfo += SetEntityAttrVal(no, dr, attrs, myen, dt, 1);
                        changeCount++;
                        successInfo += "&nbsp;&nbsp;<span>" + noColName + "为" + no + "," + nameColName + "为" + name + "的更新成功</span><br/>";
                        continue;
                    }
                    myen.Name = name;

                    //给实体赋值
                    errInfo += SetEntityAttrVal(no, dr, attrs, en, dt, 0);
                    count++;
                    successInfo += "&nbsp;&nbsp;<span>" + noColName + "为" + no + "," + nameColName + "为" + name + "的导入成功</span><br/>";
                }
            }
            #endregion

            return("errInfo=" + errInfo + "@Split" + "count=" + count + "@Split" + "successInfo=" + successInfo + "@Split" + "changeCount=" + changeCount);
        }
Пример #6
0
        public string ImpData_Done()
        {
            HttpFileCollection files = context.Request.Files;

            if (files.Count == 0)
            {
                return("err@请选择要导入的数据信息。");
            }

            string errInfo = "";

            string ext      = ".xls";
            string fileName = System.IO.Path.GetFileName(files[0].FileName);

            if (fileName.Contains(".xlsx"))
            {
                ext = ".xlsx";
            }


            //设置文件名
            string fileNewName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ext;

            //文件存放路径
            string filePath = BP.Sys.SystemConfig.PathOfTemp + "\\" + fileNewName;

            files[0].SaveAs(filePath);

            //从excel里面获得数据表.
            DataTable dt = BP.DA.DBLoad.ReadExcelFileToDataTable(filePath);

            //删除临时文件
            System.IO.File.Delete(filePath);

            if (dt.Rows.Count == 0)
            {
                return("err@无导入的数据");
            }

            //获得entity.
            FrmBill   bill = new FrmBill(this.FrmID);
            GEEntitys rpts = new GEEntitys(this.FrmID);
            GERpt     en   = new GERpt(this.FrmID);


            string noColName   = ""; //实体列的编号名称.
            string nameColName = ""; //实体列的名字名称.

            BP.En.Map map  = en.EnMap;
            Attr      attr = map.GetAttrByKey("BillNo");

            noColName = attr.Desc; //
            String codeStruct = bill.EnMap.CodeStruct;

            attr        = map.GetAttrByKey("Title");
            nameColName = attr.Desc; //

            //定义属性.
            Attrs attrs = map.Attrs;

            int impWay = this.GetRequestValInt("ImpWay");

            #region 清空方式导入.
            //清空方式导入.
            int    count       = 0; //导入的行数
            int    changeCount = 0; //更新的行数
            String successInfo = "";
            if (impWay == 0)
            {
                rpts.ClearTable();
                foreach (DataRow dr in dt.Rows)
                {
                    string no   = dr[noColName].ToString();
                    string name = dr[nameColName].ToString();

                    //判断是否是自增序列,序列的格式
                    if (!DataType.IsNullOrEmpty(codeStruct))
                    {
                        no = no.PadLeft(System.Int32.Parse(codeStruct), '0');
                    }

                    GERpt myen = new BP.WF.Data.GERpt(this.FrmID);

                    myen.SetValByKey("BillNo", no);

                    if (myen.Retrieve("BillNo", no) == 1)
                    {
                        errInfo += "err@编号[" + no + "][" + name + "]重复.";
                        continue;
                    }


                    //给实体赋值
                    errInfo += SetEntityAttrVal(no, dr, attrs, myen, dt, 0);
                    count++;
                    successInfo += "&nbsp;&nbsp;<span>" + noColName + "为" + no + "," + nameColName + "为" + name + "的导入成功</span><br/>";
                }
            }

            #endregion 清空方式导入.

            #region 更新方式导入
            if (impWay == 1 || impWay == 2)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    string no   = dr[noColName].ToString();
                    string name = dr[nameColName].ToString();
                    //判断是否是自增序列,序列的格式
                    if (!DataType.IsNullOrEmpty(codeStruct))
                    {
                        no = no.PadLeft(System.Int32.Parse(codeStruct), '0');
                    }
                    GERpt myen = rpts.GetNewEntity as GERpt;
                    myen.SetValByKey("BillNo", no);
                    if (myen.Retrieve("BillNo", no) == 1)
                    {
                        //给实体赋值
                        errInfo += SetEntityAttrVal(no, dr, attrs, myen, dt, 1);
                        changeCount++;
                        successInfo += "&nbsp;&nbsp;<span>" + noColName + "为" + no + "," + nameColName + "为" + name + "的更新成功</span><br/>";
                        continue;
                    }


                    //给实体赋值
                    errInfo += SetEntityAttrVal(no, dr, attrs, myen, dt, 0);
                    count++;
                    successInfo += "&nbsp;&nbsp;<span>" + noColName + "为" + no + "," + nameColName + "为" + name + "的导入成功</span><br/>";
                }
            }
            #endregion

            return("errInfo=" + errInfo + "@Split" + "count=" + count + "@Split" + "successInfo=" + successInfo + "@Split" + "changeCount=" + changeCount);
        }