Пример #1
0
        private string ConstructErrorInfo()
        {
            string        strInfo;
            string        strFields = "";
            StandardLayer lyr       = LayerReader.GetLayerByName(m_structInvalidPara.strFtName, this.m_StandarID);

            if (lyr == null)
            {
                return("");
            }
            int lyrID = lyr.ID;

            if (m_structInvalidPara.fieldArray.Count > 0)
            {
                for (int i = 0; i < m_structInvalidPara.fieldArray.Count; i++)
                {
                    string strTFields = FieldReader.GetNameByAliasName(m_structInvalidPara.fieldArray[i], lyrID);
                    strFields = strFields + "|" + strTFields;
                }
            }
            string strCharset;

            strCharset = m_structInvalidPara.charSetArray[0];
            for (int j = 1; j < m_structInvalidPara.charSetArray.Count; j++)
            {
                strCharset += "," + m_structInvalidPara.charSetArray[j];
            }
            strInfo = "字段 " + strFields + " 值中含有不符合要求的字符(" + strCharset + ")中的一个或多个";

            return(strInfo);
        }
Пример #2
0
        public override bool Verify()
        {
            // 获取标准ID
            int nStdID = SysDbHelper.GetStandardID(this.m_strStdName);

            lyr = LayerReader.GetLayerByAliasName(m_psPara.strFtName, nStdID);
            if (lyr == null)
            {
                SendMessage(enumMessageType.VerifyError, string.Format("标准中不存在图层“{0}”", m_psPara.strFtName));
                return(false);
            }

            // 获取实际字值名
            Helper.StandardHelper helper = new Hy.Check.Rule.Helper.StandardHelper(this.m_QueryConnection);
            strFieldCode = FieldReader.GetNameByAliasName(m_psPara.strCodeField, lyr.ID);
            if (string.IsNullOrEmpty(strFieldCode))
            {
                SendMessage(enumMessageType.VerifyError, string.Format("标准图层中不存在字段“{0}”", m_psPara.strCodeField));
                return(false);
            }

            strFieldCodeType = helper.GetLayerFieldType(strFieldCode, lyr.AttributeTableName);
            if (string.IsNullOrEmpty(strFieldCodeType))
            {
                SendMessage(enumMessageType.VerifyError, string.Format("数据图层中不存在字段“{0}”", m_psPara.strCodeField));
                return(false);
            }

            if (m_psPara.strNameField != "")
            {
                strFieldName = FieldReader.GetNameByAliasName(m_psPara.strNameField, lyr.ID);
            }
            else
            {
                SendMessage(enumMessageType.VerifyError, "没有配置字段");
                return(false);
            }

            return(true);
        }
Пример #3
0
        public override bool Verify()
        {
            standarID = SysDbHelper.GetStandardIDBySchemaID(this.m_SchemaID);

            StandardLayer lyr = LayerReader.GetLayerByAliasName(m_psPara.strTargetLayer, standarID);

            if (lyr == null)
            {
                SendMessage(enumMessageType.VerifyError, "当前方案所在的标准中找不到名为“" + m_psPara.strTargetLayer + "”的图层");
                return(false);
            }

            strLayerName = lyr.Name;
            strCodeField = FieldReader.GetNameByAliasName(m_psPara.strCodeField, lyr.ID);
            if (string.IsNullOrEmpty(strCodeField))
            {
                SendMessage(enumMessageType.VerifyError, string.Format("当前方案所在的标准中找不到名为“{0}”的图层", m_psPara.strCodeField));
                return(false);
            }

            return(true);
        }
Пример #4
0
        public override bool Verify()
        {
            //先取得要进行空间关系查询的ILayer
            IFeatureWorkspace ipFtWS = (IFeatureWorkspace)m_BaseWorkspace;

            int standarID = SysDbHelper.GetStandardIDBySchemaID(this.m_SchemaID);

            StandardLayer lyrSource = LayerReader.GetLayerByAliasName(m_pPara.strGeographyObject, standarID);

            if (lyrSource == null)
            {
                SendMessage(enumMessageType.VerifyError, string.Format("当前方案所在的标准中批不到名为“{0}”的图层", m_pPara.strGeographyObject));
                return(false);
            }

            strSrcLayer = lyrSource.Name;
            if (m_pPara.arrayGraphSpeckleField.Count > 0)
            {
                strSrcFiled = FieldReader.GetNameByAliasName(m_pPara.arrayGraphSpeckleField[0], lyrSource.ID);
                if (string.IsNullOrEmpty(strSrcFiled))
                {
                    SendMessage(enumMessageType.VerifyError, string.Format("当前方案所在的标准中批不到名为“{0}”的图层", m_pPara.arrayGraphSpeckleField[0]));
                    return(false);
                }
            }

            StandardLayer lyrRel = LayerReader.GetLayerByAliasName(m_pPara.strGraphSpeckle, standarID);

            strRelLayer = lyrRel.Name;
            if (m_pPara.arrayGeographyObjectField.Count > 0)
            {
                strRelField = FieldReader.GetNameByAliasName(m_pPara.arrayGeographyObjectField[0], lyrRel.ID);
                if (string.IsNullOrEmpty(strRelField))
                {
                    SendMessage(enumMessageType.VerifyError, string.Format("当前方案所在的标准中批不到名为“{0}”的图层", m_pPara.arrayGeographyObjectField[0]));
                    return(false);
                }
            }
            //得到目标图层和关系图层的featureclass
            IFeatureClass pSrcFeatClass = null;
            IFeatureClass pRelFeatClass = null;
            IWorkspace    TempWorkspace = null;

            IWorkspace2 wsTest = ipFtWS as IWorkspace2;

            // 原始数据准备
            // 打开“源”
            try
            {
                pSrcFeatClass = ipFtWS.OpenFeatureClass(strSrcLayer);
            }
            catch
            {
                SendMessage(enumMessageType.VerifyError, "当前工作数据库的关系图层" + strSrcLayer + "不存在,无法执行检查!");
                return(false);
            }
            m_srcfcname = strSrcLayer;
            if (pSrcFeatClass.FeatureCount(null) == 0)
            {
                Marshal.ReleaseComObject(pSrcFeatClass);
                SendMessage(enumMessageType.VerifyError, "当前工作数据库的关系图层" + strSrcLayer + "为空,无法执行检查!");
                return(false);
            }
            if (pSrcFeatClass != null)
            {
                Marshal.ReleaseComObject(pSrcFeatClass);
                pSrcFeatClass = null;
            }
            // 打开“目标”
            try
            {
                pRelFeatClass = ipFtWS.OpenFeatureClass(strRelLayer);
            }
            catch
            {
                SendMessage(enumMessageType.VerifyError, "当前工作数据库的目标图层" + strRelLayer + "不存在,无法执行检查!");
                return(false);
            }

            if (pRelFeatClass.FeatureCount(null) == 0)
            {
                Marshal.ReleaseComObject(pRelFeatClass);
                SendMessage(enumMessageType.VerifyError, "当前工作数据库的关系图层" + strSrcLayer + "为空,无法执行检查!");
                return(false);
            }

            if (pRelFeatClass != null)
            {
                Marshal.ReleaseComObject(pRelFeatClass);
                pRelFeatClass = null;
            }

            return(true);
        }
Пример #5
0
        public override bool Check(ref List <Error> checkResult)
        {
            try
            {
                //根据别名取图层名
                string       layerName  = lyr.Name;
                List <Error> m_pResAttr = new List <Error>();

                if (m_structFrePara.strAlias.Equals("频度_BSM全局唯一性检查"))
                {
                    // 2012-07-03 暂时不实现
                    //long longCount = 0;
                    //CCommonCheck.g_pBsmResAttr.GetResultCount(ref longCount);
                    //if (longCount == 0)
                    //{
                    //    CCommonCheck.GetBsmErrorForXml(m_TaskPath);
                    //}
                    //CCommonCheck.g_pBsmResAttr.SetFcAlias(ref Xstand);
                    //ppResult = CCommonCheck.g_pBsmResAttr as ICheckResult;
                }
                else
                {
                    //通过ADO来检测,并将结果放入m_arrResult
                    if (m_QueryConnection == null)
                    {
                        return(false);
                    }
                    string strField = m_structFrePara.arrayFields[0];

                    // 字段别名转换为真实名称
                    for (int j = 0; j < m_structFrePara.arrayFields.Count; j++)
                    {
                        strField = FieldReader.GetNameByAliasName(m_structFrePara.arrayFields[j], lyr.ID);
                        m_structFrePara.arrayFields[j] = strField;
                    }

                    string strSql, strGroup = "";
                    string strNullWhere = "";
                    for (int i = 0; i < m_structFrePara.arrayFields.Count; i++)
                    {
                        if (!string.IsNullOrEmpty(m_structFrePara.arrayFields[i]))
                        {
                            strGroup     += m_structFrePara.arrayFields[i] + ",";
                            strNullWhere += "((" + m_structFrePara.arrayFields[i] + " is not null) or " + m_structFrePara.arrayFields[i] + " <>'') and ";
                        }
                    }

                    if (strGroup == "")
                    {
                        return(false);
                    }
                    strGroup = strGroup.Substring(0, strGroup.Length - 1);

                    strNullWhere = strNullWhere.Substring(0, strNullWhere.Length - 4);

                    strSql = "Select TOTAL," + strGroup + " from (Select count(*) as TOTAL," + strGroup + " From " + layerName + " GROUP BY " + strGroup + ") where ( TOTAL>=2 and " + strNullWhere + ")";

                    //打开记录集,并分组
                    DataTable ipRecordset = new DataTable();
                    ipRecordset = Hy.Common.Utility.Data.AdoDbHelper.GetDataTable(this.m_QueryConnection, strSql);
                    if (ipRecordset == null)
                    {
                        return(false);
                    }

                    int           index           = 0;
                    List <string> listWhereClause = new List <string>();

                    foreach (DataRow dr in ipRecordset.Rows) //遍历结果集
                    {
                        string strFieldsValue = "";

                        for (int i = 0; i < m_structFrePara.arrayFields.Count; i++)
                        {
                            string strValue = "";
                            if (m_structFrePara.arrayFields[i] != "")
                            {
                                object varValue = dr[m_structFrePara.arrayFields[i]];

                                Type     t        = varValue.GetType();
                                TypeCode typeCode = Type.GetTypeCode(t);

                                switch (typeCode)
                                {
                                case TypeCode.Int32:
                                case TypeCode.Int64:
                                case TypeCode.Double:
                                {
                                    if (varValue == null || Convert.ToString(varValue) == "")
                                    {
                                        strValue = "(" + m_structFrePara.arrayFields[i] + " is null) and";
                                    }
                                    else
                                    {
                                        strValue = "(" + m_structFrePara.arrayFields[i] + " = " + varValue.ToString() +
                                                   ") and";
                                    }

                                    break;
                                }

                                case TypeCode.String:
                                case TypeCode.Char:
                                {
                                    if (varValue == null || Convert.ToString(varValue) == "")
                                    {
                                        strValue = "(" + m_structFrePara.arrayFields[i] + " is null or " +
                                                   m_structFrePara.arrayFields[i] + " = '' ) and ";
                                    }
                                    else
                                    {
                                        strValue = "(" + m_structFrePara.arrayFields[i] + " = '" + varValue.ToString() +
                                                   "') and ";
                                    }
                                    break;
                                }
                                }
                                strFieldsValue += strValue;
                            }
                        }
                        strFieldsValue = strFieldsValue.Substring(0, strFieldsValue.Length - 4);
                        listWhereClause.Add(strFieldsValue);

                        index++;
                    }

                    ipRecordset.Dispose();

                    if (listWhereClause.Count == 0)
                    {
                        return(true);
                    }

                    // 目标字段字符串
                    string    strTargetField = GetTargetField();
                    string    strSql1        = "Select " + strGroup + ",BSM,ObjectID From " + layerName;
                    DataTable ipRecordsetRes = new DataTable();
                    ipRecordsetRes = Hy.Common.Utility.Data.AdoDbHelper.GetDataTable(this.m_QueryConnection, strSql1);
                    if (ipRecordsetRes == null)
                    {
                        return(false);
                    }

                    DataRow[] listRow = null;
                    for (int i = 0; i < listWhereClause.Count; i++)
                    {
                        string strWhere = listWhereClause[i];
                        listRow = ipRecordsetRes.Select(strWhere);
                        if (listRow != null && listRow.Length > 0)
                        {
                            string strListBSM = "";  //重复的BSM字符串
                            int    nIndex     = 0;
                            int    nOID       = 0;
                            int    BSM        = 0;
                            foreach (DataRow dr in listRow) //遍历结果集
                            {
                                nIndex++;
                                if (nIndex >= 2)
                                {
                                    strListBSM += dr["BSM"].ToString() + "|";
                                }
                                else
                                {
                                    BSM  = Convert.ToInt32(dr["BSM"]);
                                    nOID = Convert.ToInt32(dr["ObjectID"]);
                                }
                            }
                            strListBSM = strListBSM.Substring(0, strListBSM.Length - 1);

                            // 添加结果记录
                            Error pResInfo = new Error();
                            pResInfo.DefectLevel = this.m_DefectLevel;
                            pResInfo.RuleID      = this.InstanceID;

                            // OID
                            pResInfo.OID      = nOID;
                            pResInfo.BSM      = BSM.ToString();
                            pResInfo.ReferBSM = strListBSM;

                            // 目标图层
                            pResInfo.LayerName = m_structFrePara.strFtName;
                            // 目标字段
                            pResInfo.ReferLayerName = strTargetField;
                            // 错误信息
                            pResInfo.Description = string.Format("'{0}'层中标识码为'{1}'的图形与标识码为'{2}'的图形'{3}({4})'字段值({5})存在重复", pResInfo.LayerName, BSM, strListBSM, strField, m_structFrePara.arrayFields[0], listRow[0][0]);

                            m_pResAttr.Add(pResInfo);

                            ipRecordsetRes.Dispose();
                        }
                    }

                    checkResult = m_pResAttr;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                SendMessage(enumMessageType.Exception, ex.ToString());
                return(false);
            }

            return(true);
        }