年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

593 lines
25 KiB

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.Core.Services;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Utility;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using UserControl = System.Windows.Controls.UserControl;
namespace Kingo.Plugin.SystemSetting.View.ViewSystemSetting
{
/// <summary>
/// ViewAuthoriza.xaml 的交互逻辑
/// </summary>
public partial class ViewAuthoriza : UserControl
{
private AxMapControl mapControl = null;
KGIS.Framework.Core.Services.RunIDService2 SQInfo = null;
public static IGeometryFactory3 GeometryFactory3 { get; set; }
public ViewAuthoriza()
{
InitializeComponent();
InitData();
}
public void InitData()
{
SQInfo = RunIDService2.Instance;
txtXZQ.Text = GetXZQDic(SQInfo.Codes).ToString();
txtJZSJ.Text = SQInfo.ExpirationTime.ToString();
}
private void DispalySQ_Click(object sender, RoutedEventArgs e)
{
string SQstring = SQInfo.Area.Replace('\r', ' ').ToTrim();
if (!string.IsNullOrWhiteSpace(SQstring))
{
string[] rings = SQstring.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
string coord = string.Empty;
if (rings.Length == 1)
{
foreach (var geoRing in rings)
{
string strGeo = geoRing.Replace('\r', ' ').ToTrim();
if (strGeo.Split(new char[] { ';' }).Length < 10)
strGeo = geoRing.Replace(";", ",");
if (strGeo.Contains(";"))
{
coord = string.Format("POLYGON((");
string[] ps = strGeo.TrimEnd(';').Split(';');
foreach (var item in ps)
{
coord += item.Replace('\r', ' ').Replace(',', ' ') + ",";
}
}
else
{
coord = string.Format("POLYGON((");
coord += strGeo;
}
coord = coord.TrimEnd(',');
coord += "))";
}
}
else if (rings.Length > 1)
{
coord = "MULTIPOLYGON(";
foreach (var ring in rings)
{
string Temp_Coordinate = string.Empty;
string[] points = ring.TrimEnd(';').Split(';');
string strRing = "((";
if (points.Length == 1)
{
strRing += points[0];
}
else
{
foreach (var item in points)
{
strRing += item.Replace(',', ' ') + ",";
}
}
strRing = strRing.TrimEnd(',');
strRing += ")),";
coord += strRing;
}
coord = coord.TrimEnd(',');
coord += ")";
}
IGeometry geo = GetPolygonFromWkt(coord);
ISpatialReferenceFactory NewSpatialReference = new SpatialReferenceEnvironmentClass();
geo.SpatialReference = NewSpatialReference.CreateGeographicCoordinateSystem(4490);
geo.Project(MapsManager.Instance.MapService.getAxMapControl().SpatialReference);
ITopologicalOperator topo = geo as ITopologicalOperator;
geo = topo.Buffer(2000);
DrawPolygonElement(geo, "授权范围");
AreaEnvOfeat(geo);
}
//AreaEnvOfeat(ConvertWKTToIGeometry(SQstring));
}
private IGeometry GetPolygonFromWkt(string pointsStr)
{
try
{
IGeometry geometry = new PolygonClass();
OSGeo.OGR.Geometry rstGeometry = OSGeo.OGR.Geometry.CreateFromWkt(pointsStr);
byte[] geometryBytes = new byte[rstGeometry.WkbSize()];
rstGeometry.ExportToWkb(geometryBytes);
IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;
int bytesLen = geometryBytes.Length;
factory.CreateGeometryFromWkbVariant(geometryBytes, out geometry, out bytesLen);
IPolygon polygon = geometry as IPolygon;
polygon.Close();
ITopologicalOperator pBoundaryTop = polygon as ITopologicalOperator;
pBoundaryTop.Simplify();
return geometry;
}
catch (Exception ex)
{
throw ex;
}
}
public string GetXZQDic(List<string> Codes)
{
IRDBHelper rdbHelper = null;
string SQXZQs = string.Empty;
try
{
string systemPath = SysAppPath.GetDataBasePath() + "System.mdb";
if (File.Exists(systemPath))
{
string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection");
connStr = string.Format(connStr, systemPath);
rdbHelper = RDBFactory.CreateDbHelper(connStr, DatabaseType.MSAccess);
string strPrWhere = "1=2";
string strWhere = string.Empty;
if (Codes != null)
{
foreach (var item in Codes)
{
if (item.IndexOf("00") == 4)
strWhere += string.Format(" or XZQ Like '{0}%'", item.Replace("00", ""));
else if (item.IndexOf("0000") == 2)
strWhere += string.Format(" or XZQ Like '{0}%'", item.Replace("0000", ""));
else
strWhere += string.Format(" or XZQ Like '{0}%'", item);
}
}
if (!string.IsNullOrWhiteSpace(strWhere))
strWhere = strPrWhere + strWhere;
else
strWhere = "1=1";
string strSQL = "select OBJECTID AS ID, XZQ AS CODE,XZQMC AS NAME from XZQ Where " + strWhere + "";
DataTable dt = rdbHelper.ExecuteDatatable("Dic", strSQL, true);
if (dt != null)
{
foreach (var item in TBToList.ToList<DataDicTionary>(dt))
{
SQXZQs += string.Format("{0}({1}),", item.NAME, item.CODE);
}
SQXZQs.Trim(',');
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
}
if (!string.IsNullOrWhiteSpace(SQXZQs) && SQXZQs.Split(',').Length >= 2800)
return "全国";
else
return SQXZQs.Trim(',');
}
public void AreaEnvOfeat(IGeometry geometry)
{
try
{
mapControl = MapsManager.Instance.MapService.getAxMapControl() as AxMapControl;
EnvelopeClass pEnvelope = new EnvelopeClass();
IEnvelope pEnvOfFeat = geometry.Envelope;
//投影到当前地图坐标系定位缩放到当前要素
pEnvOfFeat.Project(mapControl.SpatialReference);
IUnitConverter pUnitConverter = new UnitConverterClass();
double dScale = pUnitConverter.ConvertUnits(50, esriUnits.esriMeters, mapControl.MapUnits);
pEnvelope.PutCoords(pEnvOfFeat.XMin - dScale, pEnvOfFeat.YMin - dScale, pEnvOfFeat.XMax + dScale, pEnvOfFeat.YMax + dScale);
mapControl.ActiveView.Extent = pEnvelope;
mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, mapControl.ActiveView.Extent);
}
catch (Exception ex)
{
MessageHelper.ShowError("操作异常!异常信息:" + ex.Message);
LogAPI.Debug(ex);
}
}
private void DrawPolygonElement(IGeometry pGeo, string pName)
{
ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass
{
Style = esriSimpleFillStyle.esriSFSNull
};
//设置线宽和线的颜色
ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass
{
Color = Symbol.GetRGBColor(255, 0, 0),
Width = 2
};
pSimpleFillSymbol.Outline = pLineSymbol;
PolygonElementClass element = new PolygonElementClass
{
Name = pName,
Symbol = pSimpleFillSymbol,
Geometry = pGeo
};
IGraphicsLayer grapLayer = AddSubGraphicsLayer("TempSQFWGrapLayer");
(grapLayer as IGraphicsContainer).AddElement(element, 0);
MapsManager.Instance.MapService.getAxMapControl().ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, MapsManager.Instance.MapService.getAxMapControl().ActiveView.Extent);
}
public IGraphicsLayer AddSubGraphicsLayer(string subgraphicsLayername)
{
ICompositeGraphicsLayer pCompositeGLayer = MapsManager.Instance.MapService.getAxMapControl().Map.BasicGraphicsLayer as ICompositeGraphicsLayer;
IGraphicsLayer pGLayer = null;
try
{
//查找是否已存在,如果不存在,跳转到catch内容.
//如果查到不到,说明集合中并没有指定名称的graphicslayer
pGLayer = pCompositeGLayer.FindLayer(subgraphicsLayername);
}
catch
{
//若不存在,则添加一个指定名称的GraphicsLayer
pGLayer = pCompositeGLayer.AddLayer(subgraphicsLayername, null);
}
return pGLayer;
}
/// <summary>
/// 更换本地文件授权范围
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DispalyGH_Click(object sender, RoutedEventArgs e)
{
try
{
#region 非授权区域置灰
if (!Validity(UIShell.OSGi.BundleRuntime.Instance) || string.IsNullOrWhiteSpace(RunIDService2.Instance.Area))
return;
string ring = SysConfigsOprator.GetAppsetingValueByKey("Ring");
ring = Decrypt(ring, RunIDService2.Instance.Secretkey);
IPointCollection py = new PolygonClass();
ring = ring.Replace("POLYGON((", "").Replace("))", "");
string[] points = ring.Split(',');
foreach (var item in points)
{
string[] xy = item.Split(' ');
py.AddPoint(new PointClass() { X = xy[0].ToDouble(), Y = xy[1].ToDouble() });
}
IGeometry geo = py as IPolygon;
ISpatialReferenceFactory NewSpatialReference = new SpatialReferenceEnvironmentClass();
geo.SpatialReference = NewSpatialReference.CreateGeographicCoordinateSystem(4490);
if (mapControl == null) mapControl = MapsManager.Instance.MapService.getAxMapControl() as AxMapControl;
geo.Project(mapControl.Map.SpatialReference);
ITopologicalOperator topo = geo as ITopologicalOperator;
geo = topo.Buffer(2000);
string[] rings = RunIDService2.Instance.Area.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
string coord = string.Empty;
if (rings.Length > 1)
{
coord = "MULTIPOLYGON(";
foreach (var r in rings)
{
string Temp_Coordinate = string.Empty;
string[] ps = r.TrimEnd(';').Split(';');
string strRing = "((";
foreach (var item in ps)
{
strRing += item.Replace(',', ' ') + ",";
}
strRing = strRing.TrimEnd(',');
strRing += ")),";
coord += strRing;
}
coord = coord.TrimEnd(',');
coord += ")";
}
else
{
coord = string.Format("POLYGON((");
string[] ps = RunIDService2.Instance.Area.TrimEnd(';').Split(';');
foreach (var item in ps)
{
coord += item.Replace(',', ' ') + ",";
}
coord = coord.TrimEnd(',');
coord += "))";
}
if (!string.IsNullOrWhiteSpace(coord))
{
IGeometry geo2 = GetPolygonFromWkt(coord);
geo2.SpatialReference = NewSpatialReference.CreateGeographicCoordinateSystem(4490);
geo2.Project(mapControl.Map.SpatialReference);
topo = geo2 as ITopologicalOperator;
geo2 = topo.Buffer(2000);
topo = geo as ITopologicalOperator;
geo = topo.Difference(geo2);
if (geo.IsEmpty) return;
DrawBaseGraph(geo, 150, 150, 150);
}
#endregion
MessageHelper.ShowTips("更换授权成功!");
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
MessageHelper.ShowError("非授权区域操作失败:" + ex.Message);
}
}
public string Decrypt(string content, string strKey)
{
string result = string.Empty;
try
{
if (string.IsNullOrWhiteSpace(content))
return string.Empty;
System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
{
Key = Encoding.UTF8.GetBytes(strKey),
Mode = System.Security.Cryptography.CipherMode.ECB,
Padding = System.Security.Cryptography.PaddingMode.PKCS7
};
//将base64字符串转换成byte数组
byte[] contentArray = Convert.FromBase64String(content);
//创建解密转换器
System.Security.Cryptography.ICryptoTransform cDecryptTransform = rm.CreateDecryptor();
//对byte数组进行解密转换
Byte[] DecryptArray = cDecryptTransform.TransformFinalBlock(contentArray, 0, contentArray.Length);
//将解密后的byte[]转换成字符串(base64)
string strDecrypt = Encoding.UTF8.GetString(DecryptArray);
//将base64字符串转换成8位无符号整数数组
byte[] base64ToByte = Convert.FromBase64String(strDecrypt);
//string s = Encoding.UTF8.GetString(base64ToByte);
//将8位无符号整数数组转换成等效字符串,并返回
return Encoding.UTF8.GetString(base64ToByte);
}
catch (Exception ex)
{
throw new Exception("解密工程文件异常:" + ex.Message);
}
finally
{
GC.Collect();
}
}
public IElement DrawBaseGraph(IGeometry geoDraw, int R = 255, int G = 0, int B = 0)
{
try
{
IElement result = null;
IGraphicsContainer iGraphicsContainer = null;
IElement CameraPointElm = null;
while ((CameraPointElm = mapControl.ActiveView.GraphicsContainer.Next()) != null)
{
if ((CameraPointElm as IElementProperties).Name == "BaseElement")
break;
}
if (CameraPointElm == null)
{
CameraPointElm = new GroupElementClass();
(CameraPointElm as IElementProperties).Name = "BaseElement";
(mapControl.Object as IMapControlDefault).ActiveView.GraphicsContainer.AddElement(CameraPointElm, 2);
}
(CameraPointElm as IGroupElement).ClearElements();
if (geoDraw == null) return null;
// 获取IRGBColor接口
IRgbColor color = new RgbColor
{
// 设置颜色属性
Red = R,
Green = G,
Blue = B
};
switch (geoDraw.GeometryType)
{
case esriGeometryType.esriGeometryPoint:
result = new MarkerElementClass();
IMarkerSymbol symbol = new SimpleMarkerSymbolClass();
symbol.Color = color;
symbol.Size = 10;
(result as IMarkerElement).Symbol = symbol;
result.Geometry = geoDraw;
break;
case esriGeometryType.esriGeometryPolygon:
result = new KGIS.Framework.Maps.PolygonElement() { Opacity = 100 };
// 获取ILine符号接口
ILineSymbol lineSymbol = new SimpleLineSymbol();
// 设置线符号属
lineSymbol.Width = 2;
ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
simpleFillSymbol.Color = color;
IRgbColor colorLine = new RgbColor();
colorLine.Red = 0;
colorLine.Green = 0;
colorLine.Blue = 0;
lineSymbol.Color = colorLine;
// 设置填充符号属性
simpleFillSymbol.Outline = lineSymbol;
simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;//esriSimpleFillStyle.esriSFSSolid;
(result as IFillShapeElement).Symbol = simpleFillSymbol;
result.Geometry = geoDraw;
break;
case esriGeometryType.esriGeometryPolyline:
result = new LineElementClass();
// 获取ILine符号接口
ILineSymbol outline = new SimpleLineSymbol();
// 设置线符号属
outline.Width = 3;
outline.Color = color;
(outline as SimpleLineSymbol).Style = esriSimpleLineStyle.esriSLSSolid;
(result as ILineElement).Symbol = outline;
result.Geometry = geoDraw;
break;
default:
break;
}
(CameraPointElm as IGroupElement).AddElement(result);
if (iGraphicsContainer != null)
{
iGraphicsContainer.AddElement(result, 0);
}
mapControl.ActiveView.Refresh();
return result;
}
catch (Exception ex)
{
LogAPI.Debug("执行DrawGraph方法时异常:" + ex);
return null;
}
}
/// <summary>
/// 更换授权文件
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
private bool Validity(object obj)
{
bool IsLoadSuccessful = true;
string jkrjSQ = System.IO.Path.Combine(SysAppPath.GetCurrentAppPath(), "jkrj.lic");
string SQTemp = System.IO.Path.Combine(SysAppPath.GetCurrentAppPath(), "SQTemp");
try
{
var type = ConfigurationManager.AppSettings.Get("LicenseType");
if (type == "F")//本地授权
{
if (File.Exists(jkrjSQ))
{
if (Directory.Exists(SQTemp)) Directory.Delete(SQTemp, true);
Directory.CreateDirectory(SQTemp);
File.Copy(jkrjSQ, System.IO.Path.Combine(SQTemp, "jkrj.lic"), true);
File.Delete(jkrjSQ);
}
try
{
KGIS.PlatformPlugin.Views.License.LicenseView lic = new KGIS.PlatformPlugin.Views.License.LicenseView(obj, "BGDCPRO", "300", "3x")
{
Code = "10eaa61"
};
DialogResult dialog = lic.ShowDialog();
if (dialog != DialogResult.Yes && dialog != DialogResult.OK)
{
IsLoadSuccessful = false;
File.Copy(System.IO.Path.Combine(SQTemp, "jkrj.lic"), jkrjSQ, true);
Directory.Delete(SQTemp, true);
}
}
catch (Exception ex)
{
MessageHelper.Show(ex.Message);
LogAPI.Debug(ex);
KGIS.PlatformPlugin.Views.License.LicenseView lic = new KGIS.PlatformPlugin.Views.License.LicenseView(obj, "BGDCPRO", "300", "3x")
{
Code = "10eaa61"
};
DialogResult dialog = lic.ShowDialog();
if (dialog != DialogResult.Yes || dialog != DialogResult.OK)
{
IsLoadSuccessful = false;
File.Copy(System.IO.Path.Combine(SQTemp, "jkrj.lic"), jkrjSQ, true);
Directory.Delete(SQTemp, true);
}
}
}
return IsLoadSuccessful;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
File.Copy(System.IO.Path.Combine(SQTemp, "jkrj.lic"), jkrjSQ, true);
Directory.Delete(SQTemp, true);
return IsLoadSuccessful;
}
finally
{
if (IsLoadSuccessful == true)
{ InitData(); Directory.Delete(SQTemp, true); }
}
}
}
public enum EnumSymbolType
{
SimpleMarkerSymbol,
SimpleLineSymbol,
SimpleFillSymbol,
FormattedTextSymbol
}
public class Symbol
{
public static ISymbol CreateDefaultSymbol(EnumSymbolType pSymbolType)
{
ISymbol symbol = null;
IRgbColor color = new RgbColorClass();
color = GetRGBColor(0xff, 0, 0);
switch (pSymbolType)
{
case EnumSymbolType.SimpleMarkerSymbol:
return symbol;
case EnumSymbolType.SimpleLineSymbol:
{
ISimpleLineSymbol symbol2 = new SimpleLineSymbolClass();
symbol2.Color = color;
symbol2.Width = 1.5;
return (ISymbol)symbol2;
}
case EnumSymbolType.SimpleFillSymbol:
{
ISimpleFillSymbol symbol3 = new SimpleFillSymbolClass();
symbol3.Outline.Color = color;
symbol3.Color = color;
symbol3.Style = esriSimpleFillStyle.esriSFSDiagonalCross;
return (ISymbol)symbol3;
}
}
return symbol;
}
public static IRgbColor GetRGBColor(int pRed, int pGreen, int pBlue)
{
try
{
IRgbColor color = new RgbColorClass();
color.Red = pRed;
color.Green = pGreen;
color.Blue = pBlue;
return color;
}
catch
{
return null;
}
}
}
}