diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Forms/FrmPipelineModelDataBase.cs b/Forms/FrmPipelineModelDataBase.cs index a0fc9a1..6cc915d 100644 --- a/Forms/FrmPipelineModelDataBase.cs +++ b/Forms/FrmPipelineModelDataBase.cs @@ -105,11 +105,17 @@ return; try { + ModelBuilder lineBuilder = new LineBuilder(ds); GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension( comboBoxExLayer.Text)); + FieldValidate fieldValidate = FieldValidateFactory.Create(ValidateConfig.LoadConfig(), + EnumValidateType.PipeLinePress); + fieldValidate.Validate(layer); + + /* if (isSh && !txtModelLayer.Text.StartsWith("SH")) txtModelLayer.Text = "SH" + txtModelLayer.Text; @@ -134,12 +140,14 @@ addLayerToGlobeControl(lineParam.layerName); DialogResult = DialogResult.OK; MessageBox.Show("入库完成!", "提示"); + * */ } catch (Exception ex) { LogError.PublishError(ex); LogHelper.WriteLog(typeof(FrmPipelineModelDB), ex.Message); } + } private void addLayerToGlobeControl(string layerName) diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Forms/FrmPipelineModelDataBase.cs b/Forms/FrmPipelineModelDataBase.cs index a0fc9a1..6cc915d 100644 --- a/Forms/FrmPipelineModelDataBase.cs +++ b/Forms/FrmPipelineModelDataBase.cs @@ -105,11 +105,17 @@ return; try { + ModelBuilder lineBuilder = new LineBuilder(ds); GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension( comboBoxExLayer.Text)); + FieldValidate fieldValidate = FieldValidateFactory.Create(ValidateConfig.LoadConfig(), + EnumValidateType.PipeLinePress); + fieldValidate.Validate(layer); + + /* if (isSh && !txtModelLayer.Text.StartsWith("SH")) txtModelLayer.Text = "SH" + txtModelLayer.Text; @@ -134,12 +140,14 @@ addLayerToGlobeControl(lineParam.layerName); DialogResult = DialogResult.OK; MessageBox.Show("入库完成!", "提示"); + * */ } catch (Exception ex) { LogError.PublishError(ex); LogHelper.WriteLog(typeof(FrmPipelineModelDB), ex.Message); } + } private void addLayerToGlobeControl(string layerName) diff --git a/MainFrm.cs b/MainFrm.cs index d22b2c9..bc962c4 100644 --- a/MainFrm.cs +++ b/MainFrm.cs @@ -7573,9 +7573,14 @@ private void buttonItemSJGL2_Click(object sender, EventArgs e) { //日志记录 + /* LogManager.saveLog(Utility.userName, buttonItemSJGL2.Text); FrmValiData frm = new FrmValiData(globeControl1); frm.ShowDialog(); + * **/ + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); + String ss = ""; + } /// /// 数据预处理 diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Forms/FrmPipelineModelDataBase.cs b/Forms/FrmPipelineModelDataBase.cs index a0fc9a1..6cc915d 100644 --- a/Forms/FrmPipelineModelDataBase.cs +++ b/Forms/FrmPipelineModelDataBase.cs @@ -105,11 +105,17 @@ return; try { + ModelBuilder lineBuilder = new LineBuilder(ds); GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension( comboBoxExLayer.Text)); + FieldValidate fieldValidate = FieldValidateFactory.Create(ValidateConfig.LoadConfig(), + EnumValidateType.PipeLinePress); + fieldValidate.Validate(layer); + + /* if (isSh && !txtModelLayer.Text.StartsWith("SH")) txtModelLayer.Text = "SH" + txtModelLayer.Text; @@ -134,12 +140,14 @@ addLayerToGlobeControl(lineParam.layerName); DialogResult = DialogResult.OK; MessageBox.Show("入库完成!", "提示"); + * */ } catch (Exception ex) { LogError.PublishError(ex); LogHelper.WriteLog(typeof(FrmPipelineModelDB), ex.Message); } + } private void addLayerToGlobeControl(string layerName) diff --git a/MainFrm.cs b/MainFrm.cs index d22b2c9..bc962c4 100644 --- a/MainFrm.cs +++ b/MainFrm.cs @@ -7573,9 +7573,14 @@ private void buttonItemSJGL2_Click(object sender, EventArgs e) { //日志记录 + /* LogManager.saveLog(Utility.userName, buttonItemSJGL2.Text); FrmValiData frm = new FrmValiData(globeControl1); frm.ShowDialog(); + * **/ + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); + String ss = ""; + } /// /// 数据预处理 diff --git a/Program.cs b/Program.cs index bd3fa95..a8ca4aa 100644 --- a/Program.cs +++ b/Program.cs @@ -16,7 +16,7 @@ [STAThread] static void Main() { - + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); string localConfigPath = Application.StartupPath + "/Config.xml"; //获取程序及版本信息 diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Forms/FrmPipelineModelDataBase.cs b/Forms/FrmPipelineModelDataBase.cs index a0fc9a1..6cc915d 100644 --- a/Forms/FrmPipelineModelDataBase.cs +++ b/Forms/FrmPipelineModelDataBase.cs @@ -105,11 +105,17 @@ return; try { + ModelBuilder lineBuilder = new LineBuilder(ds); GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension( comboBoxExLayer.Text)); + FieldValidate fieldValidate = FieldValidateFactory.Create(ValidateConfig.LoadConfig(), + EnumValidateType.PipeLinePress); + fieldValidate.Validate(layer); + + /* if (isSh && !txtModelLayer.Text.StartsWith("SH")) txtModelLayer.Text = "SH" + txtModelLayer.Text; @@ -134,12 +140,14 @@ addLayerToGlobeControl(lineParam.layerName); DialogResult = DialogResult.OK; MessageBox.Show("入库完成!", "提示"); + * */ } catch (Exception ex) { LogError.PublishError(ex); LogHelper.WriteLog(typeof(FrmPipelineModelDB), ex.Message); } + } private void addLayerToGlobeControl(string layerName) diff --git a/MainFrm.cs b/MainFrm.cs index d22b2c9..bc962c4 100644 --- a/MainFrm.cs +++ b/MainFrm.cs @@ -7573,9 +7573,14 @@ private void buttonItemSJGL2_Click(object sender, EventArgs e) { //日志记录 + /* LogManager.saveLog(Utility.userName, buttonItemSJGL2.Text); FrmValiData frm = new FrmValiData(globeControl1); frm.ShowDialog(); + * **/ + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); + String ss = ""; + } /// /// 数据预处理 diff --git a/Program.cs b/Program.cs index bd3fa95..a8ca4aa 100644 --- a/Program.cs +++ b/Program.cs @@ -16,7 +16,7 @@ [STAThread] static void Main() { - + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); string localConfigPath = Application.StartupPath + "/Config.xml"; //获取程序及版本信息 diff --git a/ValidateInfo.cs b/ValidateInfo.cs index 8cdb057..3c07b24 100644 --- a/ValidateInfo.cs +++ b/ValidateInfo.cs @@ -1,32 +1,55 @@ -using System.Collections.Generic; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Windows.Forms; using System.Xml.Serialization; +using GeoScene.Data; +using GeoScene.Engine; +using GeoScene.Globe; namespace Cyberpipe { [XmlType(TypeName = "FieldValidate")] public class ValidateInfo { - [XmlArray("types")] public List validateTypes; + [XmlArray("Types")] + public List validateTypes; } [XmlType(TypeName = "Type")] public class ValidateType { - [XmlAttribute] public string label; - [XmlArray("Fields")] public List fieldInfos; + [XmlAttribute] + public string label; + [XmlArray("Fields")] + public List fieldInfos; } - [XmlType(TypeName = "Field")] public class FieldInfo { - [XmlAttribute] public string label; - [XmlAttribute] public bool unique; - [XmlAttribute] public string type; - [XmlAttribute] public bool isNull; - [XmlAttribute] public string precise; + [XmlAttribute] + public string label; + [XmlAttribute] + public bool unique; + [XmlAttribute] + public string type; + [XmlAttribute] + public bool isNull; + [XmlAttribute] + public string precise; } + public enum EnumValidateType + { + PipeLinePress = 0, //待压管线 + PipeLineNoPress = 1,//不带压管线 + FangGou = 2,//方沟 + Attach = 3,//管线附属物 + Charac = 4,//特征管点 + Marker = 5,//标识器 + Valve = 6 //阀门 + } public class ValidateConfig { @@ -35,4 +58,384 @@ return XmlTools.DeserializeFromXml("FieldValidate.xml"); } } + + public abstract class FieldValidate + { + private FieldValidate _nextValidater; + + public FieldValidate NextValidater + { + get { return _nextValidater; } + set { _nextValidater = value; } + } + + private ValidateType _validateType; + + public ValidateType ValidateType + { + get { return _validateType; } + set { _validateType = value; } + } + + protected FieldValidate(ValidateType validateType) + { + this._validateType = validateType; + } + + /* public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + return this.Execute(layer); + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + }*/ + public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + if (this.Execute(layer)) + { + if (this.NextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + else + { + return false; + } + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + } + public abstract bool Match(); + public abstract bool Execute(GSOLayer layer); + } + + //唯一性验证 + public class FieldUniqueValidate : FieldValidate + { + private List uniqueFieldNames = new List(); + + public FieldUniqueValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.unique == true) + { + uniqueFieldNames.Add(fieldInfo.label); + } + } + return this.uniqueFieldNames.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + Dictionary> myDic = new Dictionary>(); + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + myDic.Add(uniqueFieldName, new Dictionary()); + } + + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary dic = myDic[uniqueFieldName]; + String fieldValue = feature.GetValue(uniqueFieldName).ToString(); + if (dic.ContainsKey(fieldValue)) + { + dic[fieldValue] += dic[fieldValue] + 1; + } + else + { + dic.Add(fieldValue, 1); + } + } + } + + //显示信息是否有重复 + bool isSuccess = true; + String logStr = "字段唯一性检查失败\r\n"; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary tmp = myDic[uniqueFieldName]; + foreach (KeyValuePair kvp in tmp) + { + if (kvp.Value != 1) + { + isSuccess = false; + logStr += "字段" + uniqueFieldName + "重复 " + kvp.Key + "次数:" + kvp.Value; + } + } + } + if (!isSuccess) + { + LogHelper.WriteLog(typeof(FieldUniqueValidate), logStr); + } + return isSuccess; + } + } + + //完整性验证 + public class FieldCountValidate : FieldValidate + { + public FieldCountValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + List unFoundFields = new List(); + + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + String name = fieldInfo.label; + String type = fieldInfo.type; + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + bool isFound = false; + + for (int i = 0; i < featDataSet.FieldCount; i++) + { + String fieldName = featDataSet.GetField(i).Name; + String fieldType = this.FieldTypeToString(featDataSet.GetField(i).Type); + if (name == fieldName && type == fieldType) + { + isFound = true; + break; + } + } + if (!isFound) + { + unFoundFields.Add(fieldInfo); + } + } + //日志输出不满足字段信息 + if (unFoundFields.Count != 0) + { + String err = "字段完整性检查失败\r\n"; + foreach (FieldInfo unFoundField in unFoundFields) + { + err += "未找到字段或其类型匹配:" + unFoundField.label + ":" + + unFoundField.type + "\r\n"; + } + LogHelper.WriteLog(typeof(FieldCountValidate), err); + return false; + } + return true; + } + + private String FieldTypeToString(EnumFieldType type) + { + String result = "string"; + switch (type) + { + case EnumFieldType.Text: + result = "string"; + break; + case EnumFieldType.INT32: + result = "int"; + break; + case EnumFieldType.INT16: + result = "int"; + break; + case EnumFieldType.Double: + result = "double"; + break; + case EnumFieldType.Date: + result = "date"; + break; + default: + result = "string"; + break; + } + return result; + } + } + + //字段顺序检查 + public class FieldOrderValidate : FieldValidate + { + public FieldOrderValidate(ValidateType validateType) + : base(validateType) + { + + } + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + List unFoundFields = new List(); + + for (int i = 0; i < this.ValidateType.fieldInfos.Count; i++) + { + String name = this.ValidateType.fieldInfos[i].label; + if (name != featDataSet.GetField(i).Name) + { + unFoundFields.Add(this.ValidateType.fieldInfos[i]); + } + } + + if (unFoundFields.Count != 0) + { + String err = "字段顺序检查失败\r\n"; + foreach (FieldInfo field in unFoundFields) + { + err += "字段:" + field.label + "出错\r\n"; + } + LogHelper.WriteLog(typeof(FieldOrderValidate), err); + return false; + } + return true; + + + } + } + + //字段非空检查 + public class FieldEmptyValidate : FieldValidate + { + private List noEmptyFieldInfos = new List(); + + public FieldEmptyValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.isNull == false) + { + this.noEmptyFieldInfos.Add(fieldInfo); + } + } + return this.noEmptyFieldInfos.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + bool isSuccess = true; + String err = ""; + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + err += "要素" + feature.ID + "\r\n"; + foreach (FieldInfo fieldInfo in noEmptyFieldInfos) + { + if (feature.GetValue(fieldInfo.label) == null) + { + err += "字段:" + fieldInfo.label + "为空\r\n"; + isSuccess = false; + } + else + { + //如果是double类型,精度检查 + if (fieldInfo.type == "double" && fieldInfo.precise != null) + { + Double val = feature.GetFieldAsDouble(fieldInfo.label); + String strVal = val.ToString(); + int index = strVal.IndexOf('.'); + if (index != -1) + { + int length = strVal.Substring(index+1, strVal.Length - (index+1)).Length; + if (length > Int16.Parse(fieldInfo.precise)) + { + err += "字段:" + fieldInfo.label + "精度错误 当前精度:" + + length + "requried:" + fieldInfo.precise + "\r\n"; + isSuccess = false; + } + } + } + } + } + } + if (isSuccess == false) + { + LogHelper.WriteLog(typeof(FieldEmptyValidate), + "字段为空检查失败:\r\n" + err); + } + return isSuccess; + } + } + + public class FieldValidateFactory + { + public static FieldValidate Create(ValidateInfo validateInfo, + EnumValidateType enumValidateType) + { + ValidateType validateType = null; + + switch (enumValidateType) + { + case EnumValidateType.PipeLinePress: + validateType = validateInfo.validateTypes[0]; + break; + case EnumValidateType.PipeLineNoPress: + validateType = validateInfo.validateTypes[1]; + break; + case EnumValidateType.FangGou: + validateType = validateInfo.validateTypes[2]; + break; + case EnumValidateType.Attach: + validateType = validateInfo.validateTypes[3]; + break; + case EnumValidateType.Charac: + validateType = validateInfo.validateTypes[4]; + break; + case EnumValidateType.Marker: + validateType = validateInfo.validateTypes[5]; + break; + default: + validateType = validateInfo.validateTypes[6]; + break; + } + FieldValidate fieldCountVal = new FieldCountValidate(validateType); + FieldValidate fieldUniqueVal = new FieldUniqueValidate(validateType); + FieldValidate fieldOrderVal = new FieldOrderValidate(validateType); + FieldValidate fieldEmptyVal = new FieldEmptyValidate(validateType); + fieldCountVal.NextValidater = fieldUniqueVal; + fieldUniqueVal.NextValidater = fieldOrderVal; + fieldOrderVal.NextValidater = fieldEmptyVal; + return fieldCountVal; + } + } } diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Forms/FrmPipelineModelDataBase.cs b/Forms/FrmPipelineModelDataBase.cs index a0fc9a1..6cc915d 100644 --- a/Forms/FrmPipelineModelDataBase.cs +++ b/Forms/FrmPipelineModelDataBase.cs @@ -105,11 +105,17 @@ return; try { + ModelBuilder lineBuilder = new LineBuilder(ds); GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension( comboBoxExLayer.Text)); + FieldValidate fieldValidate = FieldValidateFactory.Create(ValidateConfig.LoadConfig(), + EnumValidateType.PipeLinePress); + fieldValidate.Validate(layer); + + /* if (isSh && !txtModelLayer.Text.StartsWith("SH")) txtModelLayer.Text = "SH" + txtModelLayer.Text; @@ -134,12 +140,14 @@ addLayerToGlobeControl(lineParam.layerName); DialogResult = DialogResult.OK; MessageBox.Show("入库完成!", "提示"); + * */ } catch (Exception ex) { LogError.PublishError(ex); LogHelper.WriteLog(typeof(FrmPipelineModelDB), ex.Message); } + } private void addLayerToGlobeControl(string layerName) diff --git a/MainFrm.cs b/MainFrm.cs index d22b2c9..bc962c4 100644 --- a/MainFrm.cs +++ b/MainFrm.cs @@ -7573,9 +7573,14 @@ private void buttonItemSJGL2_Click(object sender, EventArgs e) { //日志记录 + /* LogManager.saveLog(Utility.userName, buttonItemSJGL2.Text); FrmValiData frm = new FrmValiData(globeControl1); frm.ShowDialog(); + * **/ + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); + String ss = ""; + } /// /// 数据预处理 diff --git a/Program.cs b/Program.cs index bd3fa95..a8ca4aa 100644 --- a/Program.cs +++ b/Program.cs @@ -16,7 +16,7 @@ [STAThread] static void Main() { - + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); string localConfigPath = Application.StartupPath + "/Config.xml"; //获取程序及版本信息 diff --git a/ValidateInfo.cs b/ValidateInfo.cs index 8cdb057..3c07b24 100644 --- a/ValidateInfo.cs +++ b/ValidateInfo.cs @@ -1,32 +1,55 @@ -using System.Collections.Generic; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Windows.Forms; using System.Xml.Serialization; +using GeoScene.Data; +using GeoScene.Engine; +using GeoScene.Globe; namespace Cyberpipe { [XmlType(TypeName = "FieldValidate")] public class ValidateInfo { - [XmlArray("types")] public List validateTypes; + [XmlArray("Types")] + public List validateTypes; } [XmlType(TypeName = "Type")] public class ValidateType { - [XmlAttribute] public string label; - [XmlArray("Fields")] public List fieldInfos; + [XmlAttribute] + public string label; + [XmlArray("Fields")] + public List fieldInfos; } - [XmlType(TypeName = "Field")] public class FieldInfo { - [XmlAttribute] public string label; - [XmlAttribute] public bool unique; - [XmlAttribute] public string type; - [XmlAttribute] public bool isNull; - [XmlAttribute] public string precise; + [XmlAttribute] + public string label; + [XmlAttribute] + public bool unique; + [XmlAttribute] + public string type; + [XmlAttribute] + public bool isNull; + [XmlAttribute] + public string precise; } + public enum EnumValidateType + { + PipeLinePress = 0, //待压管线 + PipeLineNoPress = 1,//不带压管线 + FangGou = 2,//方沟 + Attach = 3,//管线附属物 + Charac = 4,//特征管点 + Marker = 5,//标识器 + Valve = 6 //阀门 + } public class ValidateConfig { @@ -35,4 +58,384 @@ return XmlTools.DeserializeFromXml("FieldValidate.xml"); } } + + public abstract class FieldValidate + { + private FieldValidate _nextValidater; + + public FieldValidate NextValidater + { + get { return _nextValidater; } + set { _nextValidater = value; } + } + + private ValidateType _validateType; + + public ValidateType ValidateType + { + get { return _validateType; } + set { _validateType = value; } + } + + protected FieldValidate(ValidateType validateType) + { + this._validateType = validateType; + } + + /* public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + return this.Execute(layer); + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + }*/ + public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + if (this.Execute(layer)) + { + if (this.NextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + else + { + return false; + } + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + } + public abstract bool Match(); + public abstract bool Execute(GSOLayer layer); + } + + //唯一性验证 + public class FieldUniqueValidate : FieldValidate + { + private List uniqueFieldNames = new List(); + + public FieldUniqueValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.unique == true) + { + uniqueFieldNames.Add(fieldInfo.label); + } + } + return this.uniqueFieldNames.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + Dictionary> myDic = new Dictionary>(); + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + myDic.Add(uniqueFieldName, new Dictionary()); + } + + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary dic = myDic[uniqueFieldName]; + String fieldValue = feature.GetValue(uniqueFieldName).ToString(); + if (dic.ContainsKey(fieldValue)) + { + dic[fieldValue] += dic[fieldValue] + 1; + } + else + { + dic.Add(fieldValue, 1); + } + } + } + + //显示信息是否有重复 + bool isSuccess = true; + String logStr = "字段唯一性检查失败\r\n"; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary tmp = myDic[uniqueFieldName]; + foreach (KeyValuePair kvp in tmp) + { + if (kvp.Value != 1) + { + isSuccess = false; + logStr += "字段" + uniqueFieldName + "重复 " + kvp.Key + "次数:" + kvp.Value; + } + } + } + if (!isSuccess) + { + LogHelper.WriteLog(typeof(FieldUniqueValidate), logStr); + } + return isSuccess; + } + } + + //完整性验证 + public class FieldCountValidate : FieldValidate + { + public FieldCountValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + List unFoundFields = new List(); + + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + String name = fieldInfo.label; + String type = fieldInfo.type; + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + bool isFound = false; + + for (int i = 0; i < featDataSet.FieldCount; i++) + { + String fieldName = featDataSet.GetField(i).Name; + String fieldType = this.FieldTypeToString(featDataSet.GetField(i).Type); + if (name == fieldName && type == fieldType) + { + isFound = true; + break; + } + } + if (!isFound) + { + unFoundFields.Add(fieldInfo); + } + } + //日志输出不满足字段信息 + if (unFoundFields.Count != 0) + { + String err = "字段完整性检查失败\r\n"; + foreach (FieldInfo unFoundField in unFoundFields) + { + err += "未找到字段或其类型匹配:" + unFoundField.label + ":" + + unFoundField.type + "\r\n"; + } + LogHelper.WriteLog(typeof(FieldCountValidate), err); + return false; + } + return true; + } + + private String FieldTypeToString(EnumFieldType type) + { + String result = "string"; + switch (type) + { + case EnumFieldType.Text: + result = "string"; + break; + case EnumFieldType.INT32: + result = "int"; + break; + case EnumFieldType.INT16: + result = "int"; + break; + case EnumFieldType.Double: + result = "double"; + break; + case EnumFieldType.Date: + result = "date"; + break; + default: + result = "string"; + break; + } + return result; + } + } + + //字段顺序检查 + public class FieldOrderValidate : FieldValidate + { + public FieldOrderValidate(ValidateType validateType) + : base(validateType) + { + + } + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + List unFoundFields = new List(); + + for (int i = 0; i < this.ValidateType.fieldInfos.Count; i++) + { + String name = this.ValidateType.fieldInfos[i].label; + if (name != featDataSet.GetField(i).Name) + { + unFoundFields.Add(this.ValidateType.fieldInfos[i]); + } + } + + if (unFoundFields.Count != 0) + { + String err = "字段顺序检查失败\r\n"; + foreach (FieldInfo field in unFoundFields) + { + err += "字段:" + field.label + "出错\r\n"; + } + LogHelper.WriteLog(typeof(FieldOrderValidate), err); + return false; + } + return true; + + + } + } + + //字段非空检查 + public class FieldEmptyValidate : FieldValidate + { + private List noEmptyFieldInfos = new List(); + + public FieldEmptyValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.isNull == false) + { + this.noEmptyFieldInfos.Add(fieldInfo); + } + } + return this.noEmptyFieldInfos.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + bool isSuccess = true; + String err = ""; + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + err += "要素" + feature.ID + "\r\n"; + foreach (FieldInfo fieldInfo in noEmptyFieldInfos) + { + if (feature.GetValue(fieldInfo.label) == null) + { + err += "字段:" + fieldInfo.label + "为空\r\n"; + isSuccess = false; + } + else + { + //如果是double类型,精度检查 + if (fieldInfo.type == "double" && fieldInfo.precise != null) + { + Double val = feature.GetFieldAsDouble(fieldInfo.label); + String strVal = val.ToString(); + int index = strVal.IndexOf('.'); + if (index != -1) + { + int length = strVal.Substring(index+1, strVal.Length - (index+1)).Length; + if (length > Int16.Parse(fieldInfo.precise)) + { + err += "字段:" + fieldInfo.label + "精度错误 当前精度:" + + length + "requried:" + fieldInfo.precise + "\r\n"; + isSuccess = false; + } + } + } + } + } + } + if (isSuccess == false) + { + LogHelper.WriteLog(typeof(FieldEmptyValidate), + "字段为空检查失败:\r\n" + err); + } + return isSuccess; + } + } + + public class FieldValidateFactory + { + public static FieldValidate Create(ValidateInfo validateInfo, + EnumValidateType enumValidateType) + { + ValidateType validateType = null; + + switch (enumValidateType) + { + case EnumValidateType.PipeLinePress: + validateType = validateInfo.validateTypes[0]; + break; + case EnumValidateType.PipeLineNoPress: + validateType = validateInfo.validateTypes[1]; + break; + case EnumValidateType.FangGou: + validateType = validateInfo.validateTypes[2]; + break; + case EnumValidateType.Attach: + validateType = validateInfo.validateTypes[3]; + break; + case EnumValidateType.Charac: + validateType = validateInfo.validateTypes[4]; + break; + case EnumValidateType.Marker: + validateType = validateInfo.validateTypes[5]; + break; + default: + validateType = validateInfo.validateTypes[6]; + break; + } + FieldValidate fieldCountVal = new FieldCountValidate(validateType); + FieldValidate fieldUniqueVal = new FieldUniqueValidate(validateType); + FieldValidate fieldOrderVal = new FieldOrderValidate(validateType); + FieldValidate fieldEmptyVal = new FieldEmptyValidate(validateType); + fieldCountVal.NextValidater = fieldUniqueVal; + fieldUniqueVal.NextValidater = fieldOrderVal; + fieldOrderVal.NextValidater = fieldEmptyVal; + return fieldCountVal; + } + } } diff --git a/bin/x86/Debug/Cyberpipe.exe.config b/bin/x86/Debug/Cyberpipe.exe.config index 5753e1b..f4cbe66 100644 --- a/bin/x86/Debug/Cyberpipe.exe.config +++ b/bin/x86/Debug/Cyberpipe.exe.config @@ -29,30 +29,4 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Forms/FrmPipelineModelDataBase.cs b/Forms/FrmPipelineModelDataBase.cs index a0fc9a1..6cc915d 100644 --- a/Forms/FrmPipelineModelDataBase.cs +++ b/Forms/FrmPipelineModelDataBase.cs @@ -105,11 +105,17 @@ return; try { + ModelBuilder lineBuilder = new LineBuilder(ds); GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension( comboBoxExLayer.Text)); + FieldValidate fieldValidate = FieldValidateFactory.Create(ValidateConfig.LoadConfig(), + EnumValidateType.PipeLinePress); + fieldValidate.Validate(layer); + + /* if (isSh && !txtModelLayer.Text.StartsWith("SH")) txtModelLayer.Text = "SH" + txtModelLayer.Text; @@ -134,12 +140,14 @@ addLayerToGlobeControl(lineParam.layerName); DialogResult = DialogResult.OK; MessageBox.Show("入库完成!", "提示"); + * */ } catch (Exception ex) { LogError.PublishError(ex); LogHelper.WriteLog(typeof(FrmPipelineModelDB), ex.Message); } + } private void addLayerToGlobeControl(string layerName) diff --git a/MainFrm.cs b/MainFrm.cs index d22b2c9..bc962c4 100644 --- a/MainFrm.cs +++ b/MainFrm.cs @@ -7573,9 +7573,14 @@ private void buttonItemSJGL2_Click(object sender, EventArgs e) { //日志记录 + /* LogManager.saveLog(Utility.userName, buttonItemSJGL2.Text); FrmValiData frm = new FrmValiData(globeControl1); frm.ShowDialog(); + * **/ + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); + String ss = ""; + } /// /// 数据预处理 diff --git a/Program.cs b/Program.cs index bd3fa95..a8ca4aa 100644 --- a/Program.cs +++ b/Program.cs @@ -16,7 +16,7 @@ [STAThread] static void Main() { - + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); string localConfigPath = Application.StartupPath + "/Config.xml"; //获取程序及版本信息 diff --git a/ValidateInfo.cs b/ValidateInfo.cs index 8cdb057..3c07b24 100644 --- a/ValidateInfo.cs +++ b/ValidateInfo.cs @@ -1,32 +1,55 @@ -using System.Collections.Generic; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Windows.Forms; using System.Xml.Serialization; +using GeoScene.Data; +using GeoScene.Engine; +using GeoScene.Globe; namespace Cyberpipe { [XmlType(TypeName = "FieldValidate")] public class ValidateInfo { - [XmlArray("types")] public List validateTypes; + [XmlArray("Types")] + public List validateTypes; } [XmlType(TypeName = "Type")] public class ValidateType { - [XmlAttribute] public string label; - [XmlArray("Fields")] public List fieldInfos; + [XmlAttribute] + public string label; + [XmlArray("Fields")] + public List fieldInfos; } - [XmlType(TypeName = "Field")] public class FieldInfo { - [XmlAttribute] public string label; - [XmlAttribute] public bool unique; - [XmlAttribute] public string type; - [XmlAttribute] public bool isNull; - [XmlAttribute] public string precise; + [XmlAttribute] + public string label; + [XmlAttribute] + public bool unique; + [XmlAttribute] + public string type; + [XmlAttribute] + public bool isNull; + [XmlAttribute] + public string precise; } + public enum EnumValidateType + { + PipeLinePress = 0, //待压管线 + PipeLineNoPress = 1,//不带压管线 + FangGou = 2,//方沟 + Attach = 3,//管线附属物 + Charac = 4,//特征管点 + Marker = 5,//标识器 + Valve = 6 //阀门 + } public class ValidateConfig { @@ -35,4 +58,384 @@ return XmlTools.DeserializeFromXml("FieldValidate.xml"); } } + + public abstract class FieldValidate + { + private FieldValidate _nextValidater; + + public FieldValidate NextValidater + { + get { return _nextValidater; } + set { _nextValidater = value; } + } + + private ValidateType _validateType; + + public ValidateType ValidateType + { + get { return _validateType; } + set { _validateType = value; } + } + + protected FieldValidate(ValidateType validateType) + { + this._validateType = validateType; + } + + /* public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + return this.Execute(layer); + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + }*/ + public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + if (this.Execute(layer)) + { + if (this.NextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + else + { + return false; + } + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + } + public abstract bool Match(); + public abstract bool Execute(GSOLayer layer); + } + + //唯一性验证 + public class FieldUniqueValidate : FieldValidate + { + private List uniqueFieldNames = new List(); + + public FieldUniqueValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.unique == true) + { + uniqueFieldNames.Add(fieldInfo.label); + } + } + return this.uniqueFieldNames.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + Dictionary> myDic = new Dictionary>(); + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + myDic.Add(uniqueFieldName, new Dictionary()); + } + + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary dic = myDic[uniqueFieldName]; + String fieldValue = feature.GetValue(uniqueFieldName).ToString(); + if (dic.ContainsKey(fieldValue)) + { + dic[fieldValue] += dic[fieldValue] + 1; + } + else + { + dic.Add(fieldValue, 1); + } + } + } + + //显示信息是否有重复 + bool isSuccess = true; + String logStr = "字段唯一性检查失败\r\n"; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary tmp = myDic[uniqueFieldName]; + foreach (KeyValuePair kvp in tmp) + { + if (kvp.Value != 1) + { + isSuccess = false; + logStr += "字段" + uniqueFieldName + "重复 " + kvp.Key + "次数:" + kvp.Value; + } + } + } + if (!isSuccess) + { + LogHelper.WriteLog(typeof(FieldUniqueValidate), logStr); + } + return isSuccess; + } + } + + //完整性验证 + public class FieldCountValidate : FieldValidate + { + public FieldCountValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + List unFoundFields = new List(); + + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + String name = fieldInfo.label; + String type = fieldInfo.type; + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + bool isFound = false; + + for (int i = 0; i < featDataSet.FieldCount; i++) + { + String fieldName = featDataSet.GetField(i).Name; + String fieldType = this.FieldTypeToString(featDataSet.GetField(i).Type); + if (name == fieldName && type == fieldType) + { + isFound = true; + break; + } + } + if (!isFound) + { + unFoundFields.Add(fieldInfo); + } + } + //日志输出不满足字段信息 + if (unFoundFields.Count != 0) + { + String err = "字段完整性检查失败\r\n"; + foreach (FieldInfo unFoundField in unFoundFields) + { + err += "未找到字段或其类型匹配:" + unFoundField.label + ":" + + unFoundField.type + "\r\n"; + } + LogHelper.WriteLog(typeof(FieldCountValidate), err); + return false; + } + return true; + } + + private String FieldTypeToString(EnumFieldType type) + { + String result = "string"; + switch (type) + { + case EnumFieldType.Text: + result = "string"; + break; + case EnumFieldType.INT32: + result = "int"; + break; + case EnumFieldType.INT16: + result = "int"; + break; + case EnumFieldType.Double: + result = "double"; + break; + case EnumFieldType.Date: + result = "date"; + break; + default: + result = "string"; + break; + } + return result; + } + } + + //字段顺序检查 + public class FieldOrderValidate : FieldValidate + { + public FieldOrderValidate(ValidateType validateType) + : base(validateType) + { + + } + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + List unFoundFields = new List(); + + for (int i = 0; i < this.ValidateType.fieldInfos.Count; i++) + { + String name = this.ValidateType.fieldInfos[i].label; + if (name != featDataSet.GetField(i).Name) + { + unFoundFields.Add(this.ValidateType.fieldInfos[i]); + } + } + + if (unFoundFields.Count != 0) + { + String err = "字段顺序检查失败\r\n"; + foreach (FieldInfo field in unFoundFields) + { + err += "字段:" + field.label + "出错\r\n"; + } + LogHelper.WriteLog(typeof(FieldOrderValidate), err); + return false; + } + return true; + + + } + } + + //字段非空检查 + public class FieldEmptyValidate : FieldValidate + { + private List noEmptyFieldInfos = new List(); + + public FieldEmptyValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.isNull == false) + { + this.noEmptyFieldInfos.Add(fieldInfo); + } + } + return this.noEmptyFieldInfos.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + bool isSuccess = true; + String err = ""; + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + err += "要素" + feature.ID + "\r\n"; + foreach (FieldInfo fieldInfo in noEmptyFieldInfos) + { + if (feature.GetValue(fieldInfo.label) == null) + { + err += "字段:" + fieldInfo.label + "为空\r\n"; + isSuccess = false; + } + else + { + //如果是double类型,精度检查 + if (fieldInfo.type == "double" && fieldInfo.precise != null) + { + Double val = feature.GetFieldAsDouble(fieldInfo.label); + String strVal = val.ToString(); + int index = strVal.IndexOf('.'); + if (index != -1) + { + int length = strVal.Substring(index+1, strVal.Length - (index+1)).Length; + if (length > Int16.Parse(fieldInfo.precise)) + { + err += "字段:" + fieldInfo.label + "精度错误 当前精度:" + + length + "requried:" + fieldInfo.precise + "\r\n"; + isSuccess = false; + } + } + } + } + } + } + if (isSuccess == false) + { + LogHelper.WriteLog(typeof(FieldEmptyValidate), + "字段为空检查失败:\r\n" + err); + } + return isSuccess; + } + } + + public class FieldValidateFactory + { + public static FieldValidate Create(ValidateInfo validateInfo, + EnumValidateType enumValidateType) + { + ValidateType validateType = null; + + switch (enumValidateType) + { + case EnumValidateType.PipeLinePress: + validateType = validateInfo.validateTypes[0]; + break; + case EnumValidateType.PipeLineNoPress: + validateType = validateInfo.validateTypes[1]; + break; + case EnumValidateType.FangGou: + validateType = validateInfo.validateTypes[2]; + break; + case EnumValidateType.Attach: + validateType = validateInfo.validateTypes[3]; + break; + case EnumValidateType.Charac: + validateType = validateInfo.validateTypes[4]; + break; + case EnumValidateType.Marker: + validateType = validateInfo.validateTypes[5]; + break; + default: + validateType = validateInfo.validateTypes[6]; + break; + } + FieldValidate fieldCountVal = new FieldCountValidate(validateType); + FieldValidate fieldUniqueVal = new FieldUniqueValidate(validateType); + FieldValidate fieldOrderVal = new FieldOrderValidate(validateType); + FieldValidate fieldEmptyVal = new FieldEmptyValidate(validateType); + fieldCountVal.NextValidater = fieldUniqueVal; + fieldUniqueVal.NextValidater = fieldOrderVal; + fieldOrderVal.NextValidater = fieldEmptyVal; + return fieldCountVal; + } + } } diff --git a/bin/x86/Debug/Cyberpipe.exe.config b/bin/x86/Debug/Cyberpipe.exe.config index 5753e1b..f4cbe66 100644 --- a/bin/x86/Debug/Cyberpipe.exe.config +++ b/bin/x86/Debug/Cyberpipe.exe.config @@ -29,30 +29,4 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bin/x86/Debug/Cyberpipe.vshost.exe.manifest b/bin/x86/Debug/Cyberpipe.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/x86/Debug/Cyberpipe.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Forms/FrmPipelineModelDataBase.cs b/Forms/FrmPipelineModelDataBase.cs index a0fc9a1..6cc915d 100644 --- a/Forms/FrmPipelineModelDataBase.cs +++ b/Forms/FrmPipelineModelDataBase.cs @@ -105,11 +105,17 @@ return; try { + ModelBuilder lineBuilder = new LineBuilder(ds); GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension( comboBoxExLayer.Text)); + FieldValidate fieldValidate = FieldValidateFactory.Create(ValidateConfig.LoadConfig(), + EnumValidateType.PipeLinePress); + fieldValidate.Validate(layer); + + /* if (isSh && !txtModelLayer.Text.StartsWith("SH")) txtModelLayer.Text = "SH" + txtModelLayer.Text; @@ -134,12 +140,14 @@ addLayerToGlobeControl(lineParam.layerName); DialogResult = DialogResult.OK; MessageBox.Show("入库完成!", "提示"); + * */ } catch (Exception ex) { LogError.PublishError(ex); LogHelper.WriteLog(typeof(FrmPipelineModelDB), ex.Message); } + } private void addLayerToGlobeControl(string layerName) diff --git a/MainFrm.cs b/MainFrm.cs index d22b2c9..bc962c4 100644 --- a/MainFrm.cs +++ b/MainFrm.cs @@ -7573,9 +7573,14 @@ private void buttonItemSJGL2_Click(object sender, EventArgs e) { //日志记录 + /* LogManager.saveLog(Utility.userName, buttonItemSJGL2.Text); FrmValiData frm = new FrmValiData(globeControl1); frm.ShowDialog(); + * **/ + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); + String ss = ""; + } /// /// 数据预处理 diff --git a/Program.cs b/Program.cs index bd3fa95..a8ca4aa 100644 --- a/Program.cs +++ b/Program.cs @@ -16,7 +16,7 @@ [STAThread] static void Main() { - + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); string localConfigPath = Application.StartupPath + "/Config.xml"; //获取程序及版本信息 diff --git a/ValidateInfo.cs b/ValidateInfo.cs index 8cdb057..3c07b24 100644 --- a/ValidateInfo.cs +++ b/ValidateInfo.cs @@ -1,32 +1,55 @@ -using System.Collections.Generic; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Windows.Forms; using System.Xml.Serialization; +using GeoScene.Data; +using GeoScene.Engine; +using GeoScene.Globe; namespace Cyberpipe { [XmlType(TypeName = "FieldValidate")] public class ValidateInfo { - [XmlArray("types")] public List validateTypes; + [XmlArray("Types")] + public List validateTypes; } [XmlType(TypeName = "Type")] public class ValidateType { - [XmlAttribute] public string label; - [XmlArray("Fields")] public List fieldInfos; + [XmlAttribute] + public string label; + [XmlArray("Fields")] + public List fieldInfos; } - [XmlType(TypeName = "Field")] public class FieldInfo { - [XmlAttribute] public string label; - [XmlAttribute] public bool unique; - [XmlAttribute] public string type; - [XmlAttribute] public bool isNull; - [XmlAttribute] public string precise; + [XmlAttribute] + public string label; + [XmlAttribute] + public bool unique; + [XmlAttribute] + public string type; + [XmlAttribute] + public bool isNull; + [XmlAttribute] + public string precise; } + public enum EnumValidateType + { + PipeLinePress = 0, //待压管线 + PipeLineNoPress = 1,//不带压管线 + FangGou = 2,//方沟 + Attach = 3,//管线附属物 + Charac = 4,//特征管点 + Marker = 5,//标识器 + Valve = 6 //阀门 + } public class ValidateConfig { @@ -35,4 +58,384 @@ return XmlTools.DeserializeFromXml("FieldValidate.xml"); } } + + public abstract class FieldValidate + { + private FieldValidate _nextValidater; + + public FieldValidate NextValidater + { + get { return _nextValidater; } + set { _nextValidater = value; } + } + + private ValidateType _validateType; + + public ValidateType ValidateType + { + get { return _validateType; } + set { _validateType = value; } + } + + protected FieldValidate(ValidateType validateType) + { + this._validateType = validateType; + } + + /* public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + return this.Execute(layer); + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + }*/ + public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + if (this.Execute(layer)) + { + if (this.NextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + else + { + return false; + } + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + } + public abstract bool Match(); + public abstract bool Execute(GSOLayer layer); + } + + //唯一性验证 + public class FieldUniqueValidate : FieldValidate + { + private List uniqueFieldNames = new List(); + + public FieldUniqueValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.unique == true) + { + uniqueFieldNames.Add(fieldInfo.label); + } + } + return this.uniqueFieldNames.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + Dictionary> myDic = new Dictionary>(); + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + myDic.Add(uniqueFieldName, new Dictionary()); + } + + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary dic = myDic[uniqueFieldName]; + String fieldValue = feature.GetValue(uniqueFieldName).ToString(); + if (dic.ContainsKey(fieldValue)) + { + dic[fieldValue] += dic[fieldValue] + 1; + } + else + { + dic.Add(fieldValue, 1); + } + } + } + + //显示信息是否有重复 + bool isSuccess = true; + String logStr = "字段唯一性检查失败\r\n"; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary tmp = myDic[uniqueFieldName]; + foreach (KeyValuePair kvp in tmp) + { + if (kvp.Value != 1) + { + isSuccess = false; + logStr += "字段" + uniqueFieldName + "重复 " + kvp.Key + "次数:" + kvp.Value; + } + } + } + if (!isSuccess) + { + LogHelper.WriteLog(typeof(FieldUniqueValidate), logStr); + } + return isSuccess; + } + } + + //完整性验证 + public class FieldCountValidate : FieldValidate + { + public FieldCountValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + List unFoundFields = new List(); + + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + String name = fieldInfo.label; + String type = fieldInfo.type; + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + bool isFound = false; + + for (int i = 0; i < featDataSet.FieldCount; i++) + { + String fieldName = featDataSet.GetField(i).Name; + String fieldType = this.FieldTypeToString(featDataSet.GetField(i).Type); + if (name == fieldName && type == fieldType) + { + isFound = true; + break; + } + } + if (!isFound) + { + unFoundFields.Add(fieldInfo); + } + } + //日志输出不满足字段信息 + if (unFoundFields.Count != 0) + { + String err = "字段完整性检查失败\r\n"; + foreach (FieldInfo unFoundField in unFoundFields) + { + err += "未找到字段或其类型匹配:" + unFoundField.label + ":" + + unFoundField.type + "\r\n"; + } + LogHelper.WriteLog(typeof(FieldCountValidate), err); + return false; + } + return true; + } + + private String FieldTypeToString(EnumFieldType type) + { + String result = "string"; + switch (type) + { + case EnumFieldType.Text: + result = "string"; + break; + case EnumFieldType.INT32: + result = "int"; + break; + case EnumFieldType.INT16: + result = "int"; + break; + case EnumFieldType.Double: + result = "double"; + break; + case EnumFieldType.Date: + result = "date"; + break; + default: + result = "string"; + break; + } + return result; + } + } + + //字段顺序检查 + public class FieldOrderValidate : FieldValidate + { + public FieldOrderValidate(ValidateType validateType) + : base(validateType) + { + + } + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + List unFoundFields = new List(); + + for (int i = 0; i < this.ValidateType.fieldInfos.Count; i++) + { + String name = this.ValidateType.fieldInfos[i].label; + if (name != featDataSet.GetField(i).Name) + { + unFoundFields.Add(this.ValidateType.fieldInfos[i]); + } + } + + if (unFoundFields.Count != 0) + { + String err = "字段顺序检查失败\r\n"; + foreach (FieldInfo field in unFoundFields) + { + err += "字段:" + field.label + "出错\r\n"; + } + LogHelper.WriteLog(typeof(FieldOrderValidate), err); + return false; + } + return true; + + + } + } + + //字段非空检查 + public class FieldEmptyValidate : FieldValidate + { + private List noEmptyFieldInfos = new List(); + + public FieldEmptyValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.isNull == false) + { + this.noEmptyFieldInfos.Add(fieldInfo); + } + } + return this.noEmptyFieldInfos.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + bool isSuccess = true; + String err = ""; + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + err += "要素" + feature.ID + "\r\n"; + foreach (FieldInfo fieldInfo in noEmptyFieldInfos) + { + if (feature.GetValue(fieldInfo.label) == null) + { + err += "字段:" + fieldInfo.label + "为空\r\n"; + isSuccess = false; + } + else + { + //如果是double类型,精度检查 + if (fieldInfo.type == "double" && fieldInfo.precise != null) + { + Double val = feature.GetFieldAsDouble(fieldInfo.label); + String strVal = val.ToString(); + int index = strVal.IndexOf('.'); + if (index != -1) + { + int length = strVal.Substring(index+1, strVal.Length - (index+1)).Length; + if (length > Int16.Parse(fieldInfo.precise)) + { + err += "字段:" + fieldInfo.label + "精度错误 当前精度:" + + length + "requried:" + fieldInfo.precise + "\r\n"; + isSuccess = false; + } + } + } + } + } + } + if (isSuccess == false) + { + LogHelper.WriteLog(typeof(FieldEmptyValidate), + "字段为空检查失败:\r\n" + err); + } + return isSuccess; + } + } + + public class FieldValidateFactory + { + public static FieldValidate Create(ValidateInfo validateInfo, + EnumValidateType enumValidateType) + { + ValidateType validateType = null; + + switch (enumValidateType) + { + case EnumValidateType.PipeLinePress: + validateType = validateInfo.validateTypes[0]; + break; + case EnumValidateType.PipeLineNoPress: + validateType = validateInfo.validateTypes[1]; + break; + case EnumValidateType.FangGou: + validateType = validateInfo.validateTypes[2]; + break; + case EnumValidateType.Attach: + validateType = validateInfo.validateTypes[3]; + break; + case EnumValidateType.Charac: + validateType = validateInfo.validateTypes[4]; + break; + case EnumValidateType.Marker: + validateType = validateInfo.validateTypes[5]; + break; + default: + validateType = validateInfo.validateTypes[6]; + break; + } + FieldValidate fieldCountVal = new FieldCountValidate(validateType); + FieldValidate fieldUniqueVal = new FieldUniqueValidate(validateType); + FieldValidate fieldOrderVal = new FieldOrderValidate(validateType); + FieldValidate fieldEmptyVal = new FieldEmptyValidate(validateType); + fieldCountVal.NextValidater = fieldUniqueVal; + fieldUniqueVal.NextValidater = fieldOrderVal; + fieldOrderVal.NextValidater = fieldEmptyVal; + return fieldCountVal; + } + } } diff --git a/bin/x86/Debug/Cyberpipe.exe.config b/bin/x86/Debug/Cyberpipe.exe.config index 5753e1b..f4cbe66 100644 --- a/bin/x86/Debug/Cyberpipe.exe.config +++ b/bin/x86/Debug/Cyberpipe.exe.config @@ -29,30 +29,4 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bin/x86/Debug/Cyberpipe.vshost.exe.manifest b/bin/x86/Debug/Cyberpipe.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/x86/Debug/Cyberpipe.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/x86/Debug/FieldValidate.xml b/bin/x86/Debug/FieldValidate.xml index 5bea69e..94576c7 100644 --- a/bin/x86/Debug/FieldValidate.xml +++ b/bin/x86/Debug/FieldValidate.xml @@ -8,12 +8,12 @@ - + - + diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Forms/FrmPipelineModelDataBase.cs b/Forms/FrmPipelineModelDataBase.cs index a0fc9a1..6cc915d 100644 --- a/Forms/FrmPipelineModelDataBase.cs +++ b/Forms/FrmPipelineModelDataBase.cs @@ -105,11 +105,17 @@ return; try { + ModelBuilder lineBuilder = new LineBuilder(ds); GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension( comboBoxExLayer.Text)); + FieldValidate fieldValidate = FieldValidateFactory.Create(ValidateConfig.LoadConfig(), + EnumValidateType.PipeLinePress); + fieldValidate.Validate(layer); + + /* if (isSh && !txtModelLayer.Text.StartsWith("SH")) txtModelLayer.Text = "SH" + txtModelLayer.Text; @@ -134,12 +140,14 @@ addLayerToGlobeControl(lineParam.layerName); DialogResult = DialogResult.OK; MessageBox.Show("入库完成!", "提示"); + * */ } catch (Exception ex) { LogError.PublishError(ex); LogHelper.WriteLog(typeof(FrmPipelineModelDB), ex.Message); } + } private void addLayerToGlobeControl(string layerName) diff --git a/MainFrm.cs b/MainFrm.cs index d22b2c9..bc962c4 100644 --- a/MainFrm.cs +++ b/MainFrm.cs @@ -7573,9 +7573,14 @@ private void buttonItemSJGL2_Click(object sender, EventArgs e) { //日志记录 + /* LogManager.saveLog(Utility.userName, buttonItemSJGL2.Text); FrmValiData frm = new FrmValiData(globeControl1); frm.ShowDialog(); + * **/ + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); + String ss = ""; + } /// /// 数据预处理 diff --git a/Program.cs b/Program.cs index bd3fa95..a8ca4aa 100644 --- a/Program.cs +++ b/Program.cs @@ -16,7 +16,7 @@ [STAThread] static void Main() { - + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); string localConfigPath = Application.StartupPath + "/Config.xml"; //获取程序及版本信息 diff --git a/ValidateInfo.cs b/ValidateInfo.cs index 8cdb057..3c07b24 100644 --- a/ValidateInfo.cs +++ b/ValidateInfo.cs @@ -1,32 +1,55 @@ -using System.Collections.Generic; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Windows.Forms; using System.Xml.Serialization; +using GeoScene.Data; +using GeoScene.Engine; +using GeoScene.Globe; namespace Cyberpipe { [XmlType(TypeName = "FieldValidate")] public class ValidateInfo { - [XmlArray("types")] public List validateTypes; + [XmlArray("Types")] + public List validateTypes; } [XmlType(TypeName = "Type")] public class ValidateType { - [XmlAttribute] public string label; - [XmlArray("Fields")] public List fieldInfos; + [XmlAttribute] + public string label; + [XmlArray("Fields")] + public List fieldInfos; } - [XmlType(TypeName = "Field")] public class FieldInfo { - [XmlAttribute] public string label; - [XmlAttribute] public bool unique; - [XmlAttribute] public string type; - [XmlAttribute] public bool isNull; - [XmlAttribute] public string precise; + [XmlAttribute] + public string label; + [XmlAttribute] + public bool unique; + [XmlAttribute] + public string type; + [XmlAttribute] + public bool isNull; + [XmlAttribute] + public string precise; } + public enum EnumValidateType + { + PipeLinePress = 0, //待压管线 + PipeLineNoPress = 1,//不带压管线 + FangGou = 2,//方沟 + Attach = 3,//管线附属物 + Charac = 4,//特征管点 + Marker = 5,//标识器 + Valve = 6 //阀门 + } public class ValidateConfig { @@ -35,4 +58,384 @@ return XmlTools.DeserializeFromXml("FieldValidate.xml"); } } + + public abstract class FieldValidate + { + private FieldValidate _nextValidater; + + public FieldValidate NextValidater + { + get { return _nextValidater; } + set { _nextValidater = value; } + } + + private ValidateType _validateType; + + public ValidateType ValidateType + { + get { return _validateType; } + set { _validateType = value; } + } + + protected FieldValidate(ValidateType validateType) + { + this._validateType = validateType; + } + + /* public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + return this.Execute(layer); + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + }*/ + public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + if (this.Execute(layer)) + { + if (this.NextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + else + { + return false; + } + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + } + public abstract bool Match(); + public abstract bool Execute(GSOLayer layer); + } + + //唯一性验证 + public class FieldUniqueValidate : FieldValidate + { + private List uniqueFieldNames = new List(); + + public FieldUniqueValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.unique == true) + { + uniqueFieldNames.Add(fieldInfo.label); + } + } + return this.uniqueFieldNames.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + Dictionary> myDic = new Dictionary>(); + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + myDic.Add(uniqueFieldName, new Dictionary()); + } + + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary dic = myDic[uniqueFieldName]; + String fieldValue = feature.GetValue(uniqueFieldName).ToString(); + if (dic.ContainsKey(fieldValue)) + { + dic[fieldValue] += dic[fieldValue] + 1; + } + else + { + dic.Add(fieldValue, 1); + } + } + } + + //显示信息是否有重复 + bool isSuccess = true; + String logStr = "字段唯一性检查失败\r\n"; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary tmp = myDic[uniqueFieldName]; + foreach (KeyValuePair kvp in tmp) + { + if (kvp.Value != 1) + { + isSuccess = false; + logStr += "字段" + uniqueFieldName + "重复 " + kvp.Key + "次数:" + kvp.Value; + } + } + } + if (!isSuccess) + { + LogHelper.WriteLog(typeof(FieldUniqueValidate), logStr); + } + return isSuccess; + } + } + + //完整性验证 + public class FieldCountValidate : FieldValidate + { + public FieldCountValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + List unFoundFields = new List(); + + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + String name = fieldInfo.label; + String type = fieldInfo.type; + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + bool isFound = false; + + for (int i = 0; i < featDataSet.FieldCount; i++) + { + String fieldName = featDataSet.GetField(i).Name; + String fieldType = this.FieldTypeToString(featDataSet.GetField(i).Type); + if (name == fieldName && type == fieldType) + { + isFound = true; + break; + } + } + if (!isFound) + { + unFoundFields.Add(fieldInfo); + } + } + //日志输出不满足字段信息 + if (unFoundFields.Count != 0) + { + String err = "字段完整性检查失败\r\n"; + foreach (FieldInfo unFoundField in unFoundFields) + { + err += "未找到字段或其类型匹配:" + unFoundField.label + ":" + + unFoundField.type + "\r\n"; + } + LogHelper.WriteLog(typeof(FieldCountValidate), err); + return false; + } + return true; + } + + private String FieldTypeToString(EnumFieldType type) + { + String result = "string"; + switch (type) + { + case EnumFieldType.Text: + result = "string"; + break; + case EnumFieldType.INT32: + result = "int"; + break; + case EnumFieldType.INT16: + result = "int"; + break; + case EnumFieldType.Double: + result = "double"; + break; + case EnumFieldType.Date: + result = "date"; + break; + default: + result = "string"; + break; + } + return result; + } + } + + //字段顺序检查 + public class FieldOrderValidate : FieldValidate + { + public FieldOrderValidate(ValidateType validateType) + : base(validateType) + { + + } + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + List unFoundFields = new List(); + + for (int i = 0; i < this.ValidateType.fieldInfos.Count; i++) + { + String name = this.ValidateType.fieldInfos[i].label; + if (name != featDataSet.GetField(i).Name) + { + unFoundFields.Add(this.ValidateType.fieldInfos[i]); + } + } + + if (unFoundFields.Count != 0) + { + String err = "字段顺序检查失败\r\n"; + foreach (FieldInfo field in unFoundFields) + { + err += "字段:" + field.label + "出错\r\n"; + } + LogHelper.WriteLog(typeof(FieldOrderValidate), err); + return false; + } + return true; + + + } + } + + //字段非空检查 + public class FieldEmptyValidate : FieldValidate + { + private List noEmptyFieldInfos = new List(); + + public FieldEmptyValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.isNull == false) + { + this.noEmptyFieldInfos.Add(fieldInfo); + } + } + return this.noEmptyFieldInfos.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + bool isSuccess = true; + String err = ""; + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + err += "要素" + feature.ID + "\r\n"; + foreach (FieldInfo fieldInfo in noEmptyFieldInfos) + { + if (feature.GetValue(fieldInfo.label) == null) + { + err += "字段:" + fieldInfo.label + "为空\r\n"; + isSuccess = false; + } + else + { + //如果是double类型,精度检查 + if (fieldInfo.type == "double" && fieldInfo.precise != null) + { + Double val = feature.GetFieldAsDouble(fieldInfo.label); + String strVal = val.ToString(); + int index = strVal.IndexOf('.'); + if (index != -1) + { + int length = strVal.Substring(index+1, strVal.Length - (index+1)).Length; + if (length > Int16.Parse(fieldInfo.precise)) + { + err += "字段:" + fieldInfo.label + "精度错误 当前精度:" + + length + "requried:" + fieldInfo.precise + "\r\n"; + isSuccess = false; + } + } + } + } + } + } + if (isSuccess == false) + { + LogHelper.WriteLog(typeof(FieldEmptyValidate), + "字段为空检查失败:\r\n" + err); + } + return isSuccess; + } + } + + public class FieldValidateFactory + { + public static FieldValidate Create(ValidateInfo validateInfo, + EnumValidateType enumValidateType) + { + ValidateType validateType = null; + + switch (enumValidateType) + { + case EnumValidateType.PipeLinePress: + validateType = validateInfo.validateTypes[0]; + break; + case EnumValidateType.PipeLineNoPress: + validateType = validateInfo.validateTypes[1]; + break; + case EnumValidateType.FangGou: + validateType = validateInfo.validateTypes[2]; + break; + case EnumValidateType.Attach: + validateType = validateInfo.validateTypes[3]; + break; + case EnumValidateType.Charac: + validateType = validateInfo.validateTypes[4]; + break; + case EnumValidateType.Marker: + validateType = validateInfo.validateTypes[5]; + break; + default: + validateType = validateInfo.validateTypes[6]; + break; + } + FieldValidate fieldCountVal = new FieldCountValidate(validateType); + FieldValidate fieldUniqueVal = new FieldUniqueValidate(validateType); + FieldValidate fieldOrderVal = new FieldOrderValidate(validateType); + FieldValidate fieldEmptyVal = new FieldEmptyValidate(validateType); + fieldCountVal.NextValidater = fieldUniqueVal; + fieldUniqueVal.NextValidater = fieldOrderVal; + fieldOrderVal.NextValidater = fieldEmptyVal; + return fieldCountVal; + } + } } diff --git a/bin/x86/Debug/Cyberpipe.exe.config b/bin/x86/Debug/Cyberpipe.exe.config index 5753e1b..f4cbe66 100644 --- a/bin/x86/Debug/Cyberpipe.exe.config +++ b/bin/x86/Debug/Cyberpipe.exe.config @@ -29,30 +29,4 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bin/x86/Debug/Cyberpipe.vshost.exe.manifest b/bin/x86/Debug/Cyberpipe.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/x86/Debug/Cyberpipe.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/x86/Debug/FieldValidate.xml b/bin/x86/Debug/FieldValidate.xml index 5bea69e..94576c7 100644 --- a/bin/x86/Debug/FieldValidate.xml +++ b/bin/x86/Debug/FieldValidate.xml @@ -8,12 +8,12 @@ - + - + diff --git a/bin/x86/Debug/glVersion.txt b/bin/x86/Debug/glVersion.txt index 1fc46d0..3dc3245 100644 --- a/bin/x86/Debug/glVersion.txt +++ b/bin/x86/Debug/glVersion.txt Binary files differ diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Forms/FrmPipelineModelDataBase.cs b/Forms/FrmPipelineModelDataBase.cs index a0fc9a1..6cc915d 100644 --- a/Forms/FrmPipelineModelDataBase.cs +++ b/Forms/FrmPipelineModelDataBase.cs @@ -105,11 +105,17 @@ return; try { + ModelBuilder lineBuilder = new LineBuilder(ds); GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension( comboBoxExLayer.Text)); + FieldValidate fieldValidate = FieldValidateFactory.Create(ValidateConfig.LoadConfig(), + EnumValidateType.PipeLinePress); + fieldValidate.Validate(layer); + + /* if (isSh && !txtModelLayer.Text.StartsWith("SH")) txtModelLayer.Text = "SH" + txtModelLayer.Text; @@ -134,12 +140,14 @@ addLayerToGlobeControl(lineParam.layerName); DialogResult = DialogResult.OK; MessageBox.Show("入库完成!", "提示"); + * */ } catch (Exception ex) { LogError.PublishError(ex); LogHelper.WriteLog(typeof(FrmPipelineModelDB), ex.Message); } + } private void addLayerToGlobeControl(string layerName) diff --git a/MainFrm.cs b/MainFrm.cs index d22b2c9..bc962c4 100644 --- a/MainFrm.cs +++ b/MainFrm.cs @@ -7573,9 +7573,14 @@ private void buttonItemSJGL2_Click(object sender, EventArgs e) { //日志记录 + /* LogManager.saveLog(Utility.userName, buttonItemSJGL2.Text); FrmValiData frm = new FrmValiData(globeControl1); frm.ShowDialog(); + * **/ + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); + String ss = ""; + } /// /// 数据预处理 diff --git a/Program.cs b/Program.cs index bd3fa95..a8ca4aa 100644 --- a/Program.cs +++ b/Program.cs @@ -16,7 +16,7 @@ [STAThread] static void Main() { - + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); string localConfigPath = Application.StartupPath + "/Config.xml"; //获取程序及版本信息 diff --git a/ValidateInfo.cs b/ValidateInfo.cs index 8cdb057..3c07b24 100644 --- a/ValidateInfo.cs +++ b/ValidateInfo.cs @@ -1,32 +1,55 @@ -using System.Collections.Generic; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Windows.Forms; using System.Xml.Serialization; +using GeoScene.Data; +using GeoScene.Engine; +using GeoScene.Globe; namespace Cyberpipe { [XmlType(TypeName = "FieldValidate")] public class ValidateInfo { - [XmlArray("types")] public List validateTypes; + [XmlArray("Types")] + public List validateTypes; } [XmlType(TypeName = "Type")] public class ValidateType { - [XmlAttribute] public string label; - [XmlArray("Fields")] public List fieldInfos; + [XmlAttribute] + public string label; + [XmlArray("Fields")] + public List fieldInfos; } - [XmlType(TypeName = "Field")] public class FieldInfo { - [XmlAttribute] public string label; - [XmlAttribute] public bool unique; - [XmlAttribute] public string type; - [XmlAttribute] public bool isNull; - [XmlAttribute] public string precise; + [XmlAttribute] + public string label; + [XmlAttribute] + public bool unique; + [XmlAttribute] + public string type; + [XmlAttribute] + public bool isNull; + [XmlAttribute] + public string precise; } + public enum EnumValidateType + { + PipeLinePress = 0, //待压管线 + PipeLineNoPress = 1,//不带压管线 + FangGou = 2,//方沟 + Attach = 3,//管线附属物 + Charac = 4,//特征管点 + Marker = 5,//标识器 + Valve = 6 //阀门 + } public class ValidateConfig { @@ -35,4 +58,384 @@ return XmlTools.DeserializeFromXml("FieldValidate.xml"); } } + + public abstract class FieldValidate + { + private FieldValidate _nextValidater; + + public FieldValidate NextValidater + { + get { return _nextValidater; } + set { _nextValidater = value; } + } + + private ValidateType _validateType; + + public ValidateType ValidateType + { + get { return _validateType; } + set { _validateType = value; } + } + + protected FieldValidate(ValidateType validateType) + { + this._validateType = validateType; + } + + /* public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + return this.Execute(layer); + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + }*/ + public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + if (this.Execute(layer)) + { + if (this.NextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + else + { + return false; + } + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + } + public abstract bool Match(); + public abstract bool Execute(GSOLayer layer); + } + + //唯一性验证 + public class FieldUniqueValidate : FieldValidate + { + private List uniqueFieldNames = new List(); + + public FieldUniqueValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.unique == true) + { + uniqueFieldNames.Add(fieldInfo.label); + } + } + return this.uniqueFieldNames.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + Dictionary> myDic = new Dictionary>(); + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + myDic.Add(uniqueFieldName, new Dictionary()); + } + + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary dic = myDic[uniqueFieldName]; + String fieldValue = feature.GetValue(uniqueFieldName).ToString(); + if (dic.ContainsKey(fieldValue)) + { + dic[fieldValue] += dic[fieldValue] + 1; + } + else + { + dic.Add(fieldValue, 1); + } + } + } + + //显示信息是否有重复 + bool isSuccess = true; + String logStr = "字段唯一性检查失败\r\n"; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary tmp = myDic[uniqueFieldName]; + foreach (KeyValuePair kvp in tmp) + { + if (kvp.Value != 1) + { + isSuccess = false; + logStr += "字段" + uniqueFieldName + "重复 " + kvp.Key + "次数:" + kvp.Value; + } + } + } + if (!isSuccess) + { + LogHelper.WriteLog(typeof(FieldUniqueValidate), logStr); + } + return isSuccess; + } + } + + //完整性验证 + public class FieldCountValidate : FieldValidate + { + public FieldCountValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + List unFoundFields = new List(); + + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + String name = fieldInfo.label; + String type = fieldInfo.type; + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + bool isFound = false; + + for (int i = 0; i < featDataSet.FieldCount; i++) + { + String fieldName = featDataSet.GetField(i).Name; + String fieldType = this.FieldTypeToString(featDataSet.GetField(i).Type); + if (name == fieldName && type == fieldType) + { + isFound = true; + break; + } + } + if (!isFound) + { + unFoundFields.Add(fieldInfo); + } + } + //日志输出不满足字段信息 + if (unFoundFields.Count != 0) + { + String err = "字段完整性检查失败\r\n"; + foreach (FieldInfo unFoundField in unFoundFields) + { + err += "未找到字段或其类型匹配:" + unFoundField.label + ":" + + unFoundField.type + "\r\n"; + } + LogHelper.WriteLog(typeof(FieldCountValidate), err); + return false; + } + return true; + } + + private String FieldTypeToString(EnumFieldType type) + { + String result = "string"; + switch (type) + { + case EnumFieldType.Text: + result = "string"; + break; + case EnumFieldType.INT32: + result = "int"; + break; + case EnumFieldType.INT16: + result = "int"; + break; + case EnumFieldType.Double: + result = "double"; + break; + case EnumFieldType.Date: + result = "date"; + break; + default: + result = "string"; + break; + } + return result; + } + } + + //字段顺序检查 + public class FieldOrderValidate : FieldValidate + { + public FieldOrderValidate(ValidateType validateType) + : base(validateType) + { + + } + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + List unFoundFields = new List(); + + for (int i = 0; i < this.ValidateType.fieldInfos.Count; i++) + { + String name = this.ValidateType.fieldInfos[i].label; + if (name != featDataSet.GetField(i).Name) + { + unFoundFields.Add(this.ValidateType.fieldInfos[i]); + } + } + + if (unFoundFields.Count != 0) + { + String err = "字段顺序检查失败\r\n"; + foreach (FieldInfo field in unFoundFields) + { + err += "字段:" + field.label + "出错\r\n"; + } + LogHelper.WriteLog(typeof(FieldOrderValidate), err); + return false; + } + return true; + + + } + } + + //字段非空检查 + public class FieldEmptyValidate : FieldValidate + { + private List noEmptyFieldInfos = new List(); + + public FieldEmptyValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.isNull == false) + { + this.noEmptyFieldInfos.Add(fieldInfo); + } + } + return this.noEmptyFieldInfos.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + bool isSuccess = true; + String err = ""; + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + err += "要素" + feature.ID + "\r\n"; + foreach (FieldInfo fieldInfo in noEmptyFieldInfos) + { + if (feature.GetValue(fieldInfo.label) == null) + { + err += "字段:" + fieldInfo.label + "为空\r\n"; + isSuccess = false; + } + else + { + //如果是double类型,精度检查 + if (fieldInfo.type == "double" && fieldInfo.precise != null) + { + Double val = feature.GetFieldAsDouble(fieldInfo.label); + String strVal = val.ToString(); + int index = strVal.IndexOf('.'); + if (index != -1) + { + int length = strVal.Substring(index+1, strVal.Length - (index+1)).Length; + if (length > Int16.Parse(fieldInfo.precise)) + { + err += "字段:" + fieldInfo.label + "精度错误 当前精度:" + + length + "requried:" + fieldInfo.precise + "\r\n"; + isSuccess = false; + } + } + } + } + } + } + if (isSuccess == false) + { + LogHelper.WriteLog(typeof(FieldEmptyValidate), + "字段为空检查失败:\r\n" + err); + } + return isSuccess; + } + } + + public class FieldValidateFactory + { + public static FieldValidate Create(ValidateInfo validateInfo, + EnumValidateType enumValidateType) + { + ValidateType validateType = null; + + switch (enumValidateType) + { + case EnumValidateType.PipeLinePress: + validateType = validateInfo.validateTypes[0]; + break; + case EnumValidateType.PipeLineNoPress: + validateType = validateInfo.validateTypes[1]; + break; + case EnumValidateType.FangGou: + validateType = validateInfo.validateTypes[2]; + break; + case EnumValidateType.Attach: + validateType = validateInfo.validateTypes[3]; + break; + case EnumValidateType.Charac: + validateType = validateInfo.validateTypes[4]; + break; + case EnumValidateType.Marker: + validateType = validateInfo.validateTypes[5]; + break; + default: + validateType = validateInfo.validateTypes[6]; + break; + } + FieldValidate fieldCountVal = new FieldCountValidate(validateType); + FieldValidate fieldUniqueVal = new FieldUniqueValidate(validateType); + FieldValidate fieldOrderVal = new FieldOrderValidate(validateType); + FieldValidate fieldEmptyVal = new FieldEmptyValidate(validateType); + fieldCountVal.NextValidater = fieldUniqueVal; + fieldUniqueVal.NextValidater = fieldOrderVal; + fieldOrderVal.NextValidater = fieldEmptyVal; + return fieldCountVal; + } + } } diff --git a/bin/x86/Debug/Cyberpipe.exe.config b/bin/x86/Debug/Cyberpipe.exe.config index 5753e1b..f4cbe66 100644 --- a/bin/x86/Debug/Cyberpipe.exe.config +++ b/bin/x86/Debug/Cyberpipe.exe.config @@ -29,30 +29,4 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bin/x86/Debug/Cyberpipe.vshost.exe.manifest b/bin/x86/Debug/Cyberpipe.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/x86/Debug/Cyberpipe.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/x86/Debug/FieldValidate.xml b/bin/x86/Debug/FieldValidate.xml index 5bea69e..94576c7 100644 --- a/bin/x86/Debug/FieldValidate.xml +++ b/bin/x86/Debug/FieldValidate.xml @@ -8,12 +8,12 @@ - + - + diff --git a/bin/x86/Debug/glVersion.txt b/bin/x86/Debug/glVersion.txt index 1fc46d0..3dc3245 100644 --- a/bin/x86/Debug/glVersion.txt +++ b/bin/x86/Debug/glVersion.txt Binary files differ diff --git a/bin/x86/Debug/log.txt b/bin/x86/Debug/log.txt index e134074..8677e67 100644 --- a/bin/x86/Debug/log.txt +++ b/bin/x86/Debug/log.txt @@ -258,3 +258,95 @@ exception over ------------------------------------------------------------ + + exception begin -----------------2016/11/18 15:22:27--------------------- + + + + e.Message:索引和长度必须引用该字符串内的位置。 +参数名: length + + e.Source:mscorlib + + e.TargetSite:System.String Substring(Int32, Int32) + + e.StackTrace: 在 System.String.Substring(Int32 startIndex, Int32 length) + 在 Cyberpipe.FieldEmptyValidate.Execute(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 379 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 104 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.Forms.FrmPipelineModelDB.btnCreateModel_Click(Object sender, EventArgs e) 位置 F:\predator\codeReview\GHFX_SZ_64\Forms\FrmPipelineModelDataBase.cs:行号 116 + + + + exception over ------------------------------------------------------------ + + exception begin -----------------2016/11/18 15:23:05--------------------- + + + + e.Message:索引和长度必须引用该字符串内的位置。 +参数名: length + + e.Source:mscorlib + + e.TargetSite:System.String Substring(Int32, Int32) + + e.StackTrace: 在 System.String.Substring(Int32 startIndex, Int32 length) + 在 Cyberpipe.FieldEmptyValidate.Execute(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 379 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 104 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.Forms.FrmPipelineModelDB.btnCreateModel_Click(Object sender, EventArgs e) 位置 F:\predator\codeReview\GHFX_SZ_64\Forms\FrmPipelineModelDataBase.cs:行号 116 + + + + exception over ------------------------------------------------------------ + + exception begin -----------------2016/11/18 15:24:36--------------------- + + + + e.Message:索引和长度必须引用该字符串内的位置。 +参数名: length + + e.Source:mscorlib + + e.TargetSite:System.String Substring(Int32, Int32) + + e.StackTrace: 在 System.String.Substring(Int32 startIndex, Int32 length) + 在 Cyberpipe.FieldEmptyValidate.Execute(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 379 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 104 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.Forms.FrmPipelineModelDB.btnCreateModel_Click(Object sender, EventArgs e) 位置 F:\predator\codeReview\GHFX_SZ_64\Forms\FrmPipelineModelDataBase.cs:行号 116 + + + + exception over ------------------------------------------------------------ + + exception begin -----------------2016/11/18 15:26:25--------------------- + + + + e.Message:索引和长度必须引用该字符串内的位置。 +参数名: length + + e.Source:mscorlib + + e.TargetSite:System.String Substring(Int32, Int32) + + e.StackTrace: 在 System.String.Substring(Int32 startIndex, Int32 length) + 在 Cyberpipe.FieldEmptyValidate.Execute(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 379 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 104 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.Forms.FrmPipelineModelDB.btnCreateModel_Click(Object sender, EventArgs e) 位置 F:\predator\codeReview\GHFX_SZ_64\Forms\FrmPipelineModelDataBase.cs:行号 116 + + + + exception over ------------------------------------------------------------ diff --git a/Cyberpipe.suo b/Cyberpipe.suo index 9ef7394..5e92c70 100644 --- a/Cyberpipe.suo +++ b/Cyberpipe.suo Binary files differ diff --git a/Forms/FrmPipelineModelDataBase.cs b/Forms/FrmPipelineModelDataBase.cs index a0fc9a1..6cc915d 100644 --- a/Forms/FrmPipelineModelDataBase.cs +++ b/Forms/FrmPipelineModelDataBase.cs @@ -105,11 +105,17 @@ return; try { + ModelBuilder lineBuilder = new LineBuilder(ds); GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension( comboBoxExLayer.Text)); + FieldValidate fieldValidate = FieldValidateFactory.Create(ValidateConfig.LoadConfig(), + EnumValidateType.PipeLinePress); + fieldValidate.Validate(layer); + + /* if (isSh && !txtModelLayer.Text.StartsWith("SH")) txtModelLayer.Text = "SH" + txtModelLayer.Text; @@ -134,12 +140,14 @@ addLayerToGlobeControl(lineParam.layerName); DialogResult = DialogResult.OK; MessageBox.Show("入库完成!", "提示"); + * */ } catch (Exception ex) { LogError.PublishError(ex); LogHelper.WriteLog(typeof(FrmPipelineModelDB), ex.Message); } + } private void addLayerToGlobeControl(string layerName) diff --git a/MainFrm.cs b/MainFrm.cs index d22b2c9..bc962c4 100644 --- a/MainFrm.cs +++ b/MainFrm.cs @@ -7573,9 +7573,14 @@ private void buttonItemSJGL2_Click(object sender, EventArgs e) { //日志记录 + /* LogManager.saveLog(Utility.userName, buttonItemSJGL2.Text); FrmValiData frm = new FrmValiData(globeControl1); frm.ShowDialog(); + * **/ + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); + String ss = ""; + } /// /// 数据预处理 diff --git a/Program.cs b/Program.cs index bd3fa95..a8ca4aa 100644 --- a/Program.cs +++ b/Program.cs @@ -16,7 +16,7 @@ [STAThread] static void Main() { - + ValidateInfo validateInfo = ValidateConfig.LoadConfig(); string localConfigPath = Application.StartupPath + "/Config.xml"; //获取程序及版本信息 diff --git a/ValidateInfo.cs b/ValidateInfo.cs index 8cdb057..3c07b24 100644 --- a/ValidateInfo.cs +++ b/ValidateInfo.cs @@ -1,32 +1,55 @@ -using System.Collections.Generic; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Windows.Forms; using System.Xml.Serialization; +using GeoScene.Data; +using GeoScene.Engine; +using GeoScene.Globe; namespace Cyberpipe { [XmlType(TypeName = "FieldValidate")] public class ValidateInfo { - [XmlArray("types")] public List validateTypes; + [XmlArray("Types")] + public List validateTypes; } [XmlType(TypeName = "Type")] public class ValidateType { - [XmlAttribute] public string label; - [XmlArray("Fields")] public List fieldInfos; + [XmlAttribute] + public string label; + [XmlArray("Fields")] + public List fieldInfos; } - [XmlType(TypeName = "Field")] public class FieldInfo { - [XmlAttribute] public string label; - [XmlAttribute] public bool unique; - [XmlAttribute] public string type; - [XmlAttribute] public bool isNull; - [XmlAttribute] public string precise; + [XmlAttribute] + public string label; + [XmlAttribute] + public bool unique; + [XmlAttribute] + public string type; + [XmlAttribute] + public bool isNull; + [XmlAttribute] + public string precise; } + public enum EnumValidateType + { + PipeLinePress = 0, //待压管线 + PipeLineNoPress = 1,//不带压管线 + FangGou = 2,//方沟 + Attach = 3,//管线附属物 + Charac = 4,//特征管点 + Marker = 5,//标识器 + Valve = 6 //阀门 + } public class ValidateConfig { @@ -35,4 +58,384 @@ return XmlTools.DeserializeFromXml("FieldValidate.xml"); } } + + public abstract class FieldValidate + { + private FieldValidate _nextValidater; + + public FieldValidate NextValidater + { + get { return _nextValidater; } + set { _nextValidater = value; } + } + + private ValidateType _validateType; + + public ValidateType ValidateType + { + get { return _validateType; } + set { _validateType = value; } + } + + protected FieldValidate(ValidateType validateType) + { + this._validateType = validateType; + } + + /* public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + return this.Execute(layer); + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + }*/ + public bool Validate(GSOLayer layer) + { + if (this.Match()) + { + if (this.Execute(layer)) + { + if (this.NextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + else + { + return false; + } + } + else + { + if (this._nextValidater != null) + { + return _nextValidater.Validate(layer); + } + } + return true; + } + public abstract bool Match(); + public abstract bool Execute(GSOLayer layer); + } + + //唯一性验证 + public class FieldUniqueValidate : FieldValidate + { + private List uniqueFieldNames = new List(); + + public FieldUniqueValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.unique == true) + { + uniqueFieldNames.Add(fieldInfo.label); + } + } + return this.uniqueFieldNames.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + Dictionary> myDic = new Dictionary>(); + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + myDic.Add(uniqueFieldName, new Dictionary()); + } + + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary dic = myDic[uniqueFieldName]; + String fieldValue = feature.GetValue(uniqueFieldName).ToString(); + if (dic.ContainsKey(fieldValue)) + { + dic[fieldValue] += dic[fieldValue] + 1; + } + else + { + dic.Add(fieldValue, 1); + } + } + } + + //显示信息是否有重复 + bool isSuccess = true; + String logStr = "字段唯一性检查失败\r\n"; + foreach (string uniqueFieldName in this.uniqueFieldNames) + { + Dictionary tmp = myDic[uniqueFieldName]; + foreach (KeyValuePair kvp in tmp) + { + if (kvp.Value != 1) + { + isSuccess = false; + logStr += "字段" + uniqueFieldName + "重复 " + kvp.Key + "次数:" + kvp.Value; + } + } + } + if (!isSuccess) + { + LogHelper.WriteLog(typeof(FieldUniqueValidate), logStr); + } + return isSuccess; + } + } + + //完整性验证 + public class FieldCountValidate : FieldValidate + { + public FieldCountValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + List unFoundFields = new List(); + + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + String name = fieldInfo.label; + String type = fieldInfo.type; + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + bool isFound = false; + + for (int i = 0; i < featDataSet.FieldCount; i++) + { + String fieldName = featDataSet.GetField(i).Name; + String fieldType = this.FieldTypeToString(featDataSet.GetField(i).Type); + if (name == fieldName && type == fieldType) + { + isFound = true; + break; + } + } + if (!isFound) + { + unFoundFields.Add(fieldInfo); + } + } + //日志输出不满足字段信息 + if (unFoundFields.Count != 0) + { + String err = "字段完整性检查失败\r\n"; + foreach (FieldInfo unFoundField in unFoundFields) + { + err += "未找到字段或其类型匹配:" + unFoundField.label + ":" + + unFoundField.type + "\r\n"; + } + LogHelper.WriteLog(typeof(FieldCountValidate), err); + return false; + } + return true; + } + + private String FieldTypeToString(EnumFieldType type) + { + String result = "string"; + switch (type) + { + case EnumFieldType.Text: + result = "string"; + break; + case EnumFieldType.INT32: + result = "int"; + break; + case EnumFieldType.INT16: + result = "int"; + break; + case EnumFieldType.Double: + result = "double"; + break; + case EnumFieldType.Date: + result = "date"; + break; + default: + result = "string"; + break; + } + return result; + } + } + + //字段顺序检查 + public class FieldOrderValidate : FieldValidate + { + public FieldOrderValidate(ValidateType validateType) + : base(validateType) + { + + } + public override bool Match() + { + return this.ValidateType.fieldInfos.Count == 0 ? false : true; + } + + public override bool Execute(GSOLayer layer) + { + + GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset; + List unFoundFields = new List(); + + for (int i = 0; i < this.ValidateType.fieldInfos.Count; i++) + { + String name = this.ValidateType.fieldInfos[i].label; + if (name != featDataSet.GetField(i).Name) + { + unFoundFields.Add(this.ValidateType.fieldInfos[i]); + } + } + + if (unFoundFields.Count != 0) + { + String err = "字段顺序检查失败\r\n"; + foreach (FieldInfo field in unFoundFields) + { + err += "字段:" + field.label + "出错\r\n"; + } + LogHelper.WriteLog(typeof(FieldOrderValidate), err); + return false; + } + return true; + + + } + } + + //字段非空检查 + public class FieldEmptyValidate : FieldValidate + { + private List noEmptyFieldInfos = new List(); + + public FieldEmptyValidate(ValidateType validateType) + : base(validateType) + { + + } + + public override bool Match() + { + foreach (FieldInfo fieldInfo in this.ValidateType.fieldInfos) + { + if (fieldInfo.isNull == false) + { + this.noEmptyFieldInfos.Add(fieldInfo); + } + } + return this.noEmptyFieldInfos.Count != 0 ? true : false; + } + + public override bool Execute(GSOLayer layer) + { + GSOFeatures features = layer.GetAllFeatures(); + bool isSuccess = true; + String err = ""; + for (int i = 0; i < features.Length; i++) + { + GSOFeature feature = features[i]; + err += "要素" + feature.ID + "\r\n"; + foreach (FieldInfo fieldInfo in noEmptyFieldInfos) + { + if (feature.GetValue(fieldInfo.label) == null) + { + err += "字段:" + fieldInfo.label + "为空\r\n"; + isSuccess = false; + } + else + { + //如果是double类型,精度检查 + if (fieldInfo.type == "double" && fieldInfo.precise != null) + { + Double val = feature.GetFieldAsDouble(fieldInfo.label); + String strVal = val.ToString(); + int index = strVal.IndexOf('.'); + if (index != -1) + { + int length = strVal.Substring(index+1, strVal.Length - (index+1)).Length; + if (length > Int16.Parse(fieldInfo.precise)) + { + err += "字段:" + fieldInfo.label + "精度错误 当前精度:" + + length + "requried:" + fieldInfo.precise + "\r\n"; + isSuccess = false; + } + } + } + } + } + } + if (isSuccess == false) + { + LogHelper.WriteLog(typeof(FieldEmptyValidate), + "字段为空检查失败:\r\n" + err); + } + return isSuccess; + } + } + + public class FieldValidateFactory + { + public static FieldValidate Create(ValidateInfo validateInfo, + EnumValidateType enumValidateType) + { + ValidateType validateType = null; + + switch (enumValidateType) + { + case EnumValidateType.PipeLinePress: + validateType = validateInfo.validateTypes[0]; + break; + case EnumValidateType.PipeLineNoPress: + validateType = validateInfo.validateTypes[1]; + break; + case EnumValidateType.FangGou: + validateType = validateInfo.validateTypes[2]; + break; + case EnumValidateType.Attach: + validateType = validateInfo.validateTypes[3]; + break; + case EnumValidateType.Charac: + validateType = validateInfo.validateTypes[4]; + break; + case EnumValidateType.Marker: + validateType = validateInfo.validateTypes[5]; + break; + default: + validateType = validateInfo.validateTypes[6]; + break; + } + FieldValidate fieldCountVal = new FieldCountValidate(validateType); + FieldValidate fieldUniqueVal = new FieldUniqueValidate(validateType); + FieldValidate fieldOrderVal = new FieldOrderValidate(validateType); + FieldValidate fieldEmptyVal = new FieldEmptyValidate(validateType); + fieldCountVal.NextValidater = fieldUniqueVal; + fieldUniqueVal.NextValidater = fieldOrderVal; + fieldOrderVal.NextValidater = fieldEmptyVal; + return fieldCountVal; + } + } } diff --git a/bin/x86/Debug/Cyberpipe.exe.config b/bin/x86/Debug/Cyberpipe.exe.config index 5753e1b..f4cbe66 100644 --- a/bin/x86/Debug/Cyberpipe.exe.config +++ b/bin/x86/Debug/Cyberpipe.exe.config @@ -29,30 +29,4 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bin/x86/Debug/Cyberpipe.vshost.exe.manifest b/bin/x86/Debug/Cyberpipe.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/x86/Debug/Cyberpipe.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/x86/Debug/FieldValidate.xml b/bin/x86/Debug/FieldValidate.xml index 5bea69e..94576c7 100644 --- a/bin/x86/Debug/FieldValidate.xml +++ b/bin/x86/Debug/FieldValidate.xml @@ -8,12 +8,12 @@ - + - + diff --git a/bin/x86/Debug/glVersion.txt b/bin/x86/Debug/glVersion.txt index 1fc46d0..3dc3245 100644 --- a/bin/x86/Debug/glVersion.txt +++ b/bin/x86/Debug/glVersion.txt Binary files differ diff --git a/bin/x86/Debug/log.txt b/bin/x86/Debug/log.txt index e134074..8677e67 100644 --- a/bin/x86/Debug/log.txt +++ b/bin/x86/Debug/log.txt @@ -258,3 +258,95 @@ exception over ------------------------------------------------------------ + + exception begin -----------------2016/11/18 15:22:27--------------------- + + + + e.Message:索引和长度必须引用该字符串内的位置。 +参数名: length + + e.Source:mscorlib + + e.TargetSite:System.String Substring(Int32, Int32) + + e.StackTrace: 在 System.String.Substring(Int32 startIndex, Int32 length) + 在 Cyberpipe.FieldEmptyValidate.Execute(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 379 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 104 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.Forms.FrmPipelineModelDB.btnCreateModel_Click(Object sender, EventArgs e) 位置 F:\predator\codeReview\GHFX_SZ_64\Forms\FrmPipelineModelDataBase.cs:行号 116 + + + + exception over ------------------------------------------------------------ + + exception begin -----------------2016/11/18 15:23:05--------------------- + + + + e.Message:索引和长度必须引用该字符串内的位置。 +参数名: length + + e.Source:mscorlib + + e.TargetSite:System.String Substring(Int32, Int32) + + e.StackTrace: 在 System.String.Substring(Int32 startIndex, Int32 length) + 在 Cyberpipe.FieldEmptyValidate.Execute(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 379 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 104 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.Forms.FrmPipelineModelDB.btnCreateModel_Click(Object sender, EventArgs e) 位置 F:\predator\codeReview\GHFX_SZ_64\Forms\FrmPipelineModelDataBase.cs:行号 116 + + + + exception over ------------------------------------------------------------ + + exception begin -----------------2016/11/18 15:24:36--------------------- + + + + e.Message:索引和长度必须引用该字符串内的位置。 +参数名: length + + e.Source:mscorlib + + e.TargetSite:System.String Substring(Int32, Int32) + + e.StackTrace: 在 System.String.Substring(Int32 startIndex, Int32 length) + 在 Cyberpipe.FieldEmptyValidate.Execute(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 379 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 104 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.Forms.FrmPipelineModelDB.btnCreateModel_Click(Object sender, EventArgs e) 位置 F:\predator\codeReview\GHFX_SZ_64\Forms\FrmPipelineModelDataBase.cs:行号 116 + + + + exception over ------------------------------------------------------------ + + exception begin -----------------2016/11/18 15:26:25--------------------- + + + + e.Message:索引和长度必须引用该字符串内的位置。 +参数名: length + + e.Source:mscorlib + + e.TargetSite:System.String Substring(Int32, Int32) + + e.StackTrace: 在 System.String.Substring(Int32 startIndex, Int32 length) + 在 Cyberpipe.FieldEmptyValidate.Execute(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 379 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 104 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.FieldValidate.Validate(GSOLayer layer) 位置 F:\predator\codeReview\GHFX_SZ_64\ValidateInfo.cs:行号 108 + 在 Cyberpipe.Forms.FrmPipelineModelDB.btnCreateModel_Click(Object sender, EventArgs e) 位置 F:\predator\codeReview\GHFX_SZ_64\Forms\FrmPipelineModelDataBase.cs:行号 116 + + + + exception over ------------------------------------------------------------ diff --git a/bin/x86/Debug/log/2016/201611/20161118.txt b/bin/x86/Debug/log/2016/201611/20161118.txt new file mode 100644 index 0000000..d03145b --- /dev/null +++ b/bin/x86/Debug/log/2016/201611/20161118.txt @@ -0,0 +1,84 @@ + + +��¼ʱ�䣺2016-11-18 15:22:27,833 +�߳�ID:[9] +��־���� ERROR +�����ࣺCyberpipe.Forms.FrmPipelineModelDB property: [(null)] - +���������������ͳ��ȱ������ø��ַ����ڵ�λ�á� +������: length + + + +��¼ʱ�䣺2016-11-18 15:23:05,224 +�߳�ID:[9] +��־���� ERROR +�����ࣺCyberpipe.Forms.FrmPipelineModelDB property: [(null)] - +���������������ͳ��ȱ������ø��ַ����ڵ�λ�á� +������: length + + + +��¼ʱ�䣺2016-11-18 15:24:36,900 +�߳�ID:[9] +��־���� ERROR +�����ࣺCyberpipe.Forms.FrmPipelineModelDB property: [(null)] - +���������������ͳ��ȱ������ø��ַ����ڵ�λ�á� +������: length + + + +��¼ʱ�䣺2016-11-18 15:26:25,752 +�߳�ID:[9] +��־���� ERROR +�����ࣺCyberpipe.Forms.FrmPipelineModelDB property: [(null)] - +���������������ͳ��ȱ������ø��ַ����ڵ�λ�á� +������: length + + + +��¼ʱ�䣺2016-11-18 15:27:04,799 +�߳�ID:[9] +��־���� ERROR +�����ࣺCyberpipe.FieldOrderValidate property: [(null)] - +�����������ֶ�˳����ʧ�� +�ֶ�:��ʼ�ܶ��߳��� +�ֶ�:��ֹ����߳��� +�ֶ�:��ֹ������� +�ֶ�:��ֹ�ܶ��߳��� +�ֶ�:������·���� +�ֶ�:Ȩ����λ���� +�ֶ�:��ע���� + + + + +��¼ʱ�䣺2016-11-18 15:27:11,752 +�߳�ID:[9] +��־���� ERROR +�����ࣺCyberpipe.FieldOrderValidate property: [(null)] - +�����������ֶ�˳����ʧ�� +�ֶ�:��ʼ�ܶ��߳��� +�ֶ�:��ֹ����߳��� +�ֶ�:��ֹ������� +�ֶ�:��ֹ�ܶ��߳��� +�ֶ�:������·���� +�ֶ�:Ȩ����λ���� +�ֶ�:��ע���� + + + + +��¼ʱ�䣺2016-11-18 15:27:27,018 +�߳�ID:[9] +��־���� ERROR +�����ࣺCyberpipe.FieldOrderValidate property: [(null)] - +�����������ֶ�˳����ʧ�� +�ֶ�:��ʼ�ܶ��߳��� +�ֶ�:��ֹ����߳��� +�ֶ�:��ֹ������� +�ֶ�:��ֹ�ܶ��߳��� +�ֶ�:������·���� +�ֶ�:Ȩ����λ���� +�ֶ�:��ע���� + +