根据NUM字段的不同 线路颜色
private
void
Button5_Click(
object
sender, System.EventArgs e)
... {
try
...{
string cables="";
for(int i=0;i<this.ListBox_CableInfo.Items.Count;i++)
...{
if(i==0)
...{
cables=this.ListBox_CableInfo.Items[i].Value;
}
else
...{
cables=cables+","+this.ListBox_CableInfo.Items[i].Value;
}
}
string con_Str=System.Configuration.ConfigurationSettings.AppSettings["con_Str"].ToString().Trim();
string INS_OCABLE_ID=this.ListBox_CableInfo.SelectedValue.ToString();
string SQL="SELECT ins_sec_id , CASE when count(ins_ocable_id) = 1 then 1 WHEN count(ins_ocable_id) = 2 THEN 2 WHEN count(ins_ocable_id) >2 THEN 3 END NUM from ZHTrcm.INSPECTS_SEC_OPTICAL WHERE INS_OCABLE_ID IN("+cables+") group by ins_sec_id order by ins_sec_id";
System.Data.DataTable dt=new DataTable();
System.Data.OleDb.OleDbDataAdapter Adapter=new System.Data.OleDb.OleDbDataAdapter(SQL,con_Str);
Adapter.Fill(dt);
this.ShowLineCables("ShowCable",dt,2,3,System.Drawing.Color.GhostWhite);
}
catch(System.Exception ex)
...{
this.Label_ERRORINFO.Text=ex.Message;
}
}
... {
try
...{
string cables="";
for(int i=0;i<this.ListBox_CableInfo.Items.Count;i++)
...{
if(i==0)
...{
cables=this.ListBox_CableInfo.Items[i].Value;
}
else
...{
cables=cables+","+this.ListBox_CableInfo.Items[i].Value;
}
}
string con_Str=System.Configuration.ConfigurationSettings.AppSettings["con_Str"].ToString().Trim();
string INS_OCABLE_ID=this.ListBox_CableInfo.SelectedValue.ToString();
string SQL="SELECT ins_sec_id , CASE when count(ins_ocable_id) = 1 then 1 WHEN count(ins_ocable_id) = 2 THEN 2 WHEN count(ins_ocable_id) >2 THEN 3 END NUM from ZHTrcm.INSPECTS_SEC_OPTICAL WHERE INS_OCABLE_ID IN("+cables+") group by ins_sec_id order by ins_sec_id";
System.Data.DataTable dt=new DataTable();
System.Data.OleDb.OleDbDataAdapter Adapter=new System.Data.OleDb.OleDbDataAdapter(SQL,con_Str);
Adapter.Fill(dt);
this.ShowLineCables("ShowCable",dt,2,3,System.Drawing.Color.GhostWhite);
}
catch(System.Exception ex)
...{
this.Label_ERRORINFO.Text=ex.Message;
}
}
private
void
ShowLineCables(
string
layerName,System.Data.DataTable dt_Line,
int
LineWidth,
int
pattern,System.Drawing.Color color)
... {
MapInfo.Data.TableInfo ti;
MapInfo.Data.Table table;
table = MapInfo.Engine.Session.Current.Catalog.GetTable(layerName);
ti = MapInfo.Data.TableInfoFactory.CreateTemp(layerName);
MapInfo.Data.Column colLine_ID=MapInfo.Data.ColumnFactory.CreateIntColumn("INS_SEC_ID");//添加列 线路名称
ti.Columns.Add(colLine_ID);
MapInfo.Data.Column colLine_NUM=MapInfo.Data.ColumnFactory.CreateIntColumn("NUM");//添加列 线路名称
ti.Columns.Add(colLine_NUM);;
if(table!=null)
...{
table.Close();
}
table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
System.Data.DataTable dt=new DataTable();
for(int i=0;i<dt_Line.Rows.Count;i++)
...{
string SQL = "SELECT INS_STARTSPOTID,INS_ENDSPOTID FROM INSPECTS_SECTION WHERE INS_SEC_ID='"+dt_Line.Rows[i]["INS_SEC_ID"].ToString()+"'";
string con_Str=System.Configuration.ConfigurationSettings.AppSettings["con_Str"];
System.Data.OleDb.OleDbDataAdapter Adapter=new System.Data.OleDb.OleDbDataAdapter(SQL,con_Str);
Adapter.Fill(dt);
}
for(int j=0;j<dt.Rows.Count;j++)
...{
System.Data.DataTable dt_s = new DataTable();
System.Data.DataTable dt_e = new DataTable();
string SQL_s = "SELECT SPOT_AFTER,SPOT_LATITUE FROM INSPECTS_SPOT_TYPE WHERE SPOT_ID='"+dt.Rows[j]["INS_STARTSPOTID"]+"'";
string SQL_e = "SELECT SPOT_AFTER,SPOT_LATITUE FROM INSPECTS_SPOT_TYPE WHERE SPOT_ID='"+dt.Rows[j]["INS_ENDSPOTID"]+"'";
string con_Str=System.Configuration.ConfigurationSettings.AppSettings["con_Str"];
System.Data.OleDb.OleDbDataAdapter adp_s = new System.Data.OleDb.OleDbDataAdapter(SQL_s,con_Str);
adp_s.Fill(dt_s);
System.Data.OleDb.OleDbDataAdapter adp_e = new System.Data.OleDb.OleDbDataAdapter(SQL_e,con_Str);
adp_e.Fill(dt_e);
double begin_x=Convert.ToDouble(dt_s.Rows[0]["SPOT_AFTER"]);
double begin_y=Convert.ToDouble(dt_s.Rows[0]["SPOT_LATITUE"]);
MapInfo.Geometry.DPoint beginPoint=new MapInfo.Geometry.DPoint(begin_x,begin_y);
double end_x=Convert.ToDouble(dt_e.Rows[0]["SPOT_AFTER"]);
double end_y=Convert.ToDouble(dt_e.Rows[0]["SPOT_LATITUE"]);
MapInfo.Geometry.DPoint endPoint=new MapInfo.Geometry.DPoint(end_x,end_y);
//create line
MapInfo.Geometry.MultiCurve mc=MapInfo.Geometry.MultiCurve.CreateLine(this.MapControl1.Map.GetDisplayCoordSys(),beginPoint,endPoint);
//create style
MapInfo.Styles.SimpleLineStyle bl=new MapInfo.Styles.SimpleLineStyle(new MapInfo.Styles.LineWidth(2,MapInfo.Styles.LineWidthUnit.Pixel),3,Color.Red);
MapInfo.Styles.CompositeStyle cs=new MapInfo.Styles.CompositeStyle(null,bl,null,null);
//create feature with geometry, style and name
MapInfo.Data.Feature f=new Feature(table.TableInfo.Columns);
f.Geometry=mc;
f.Style=cs;
f["INS_SEC_ID"]=dt_Line.Rows[j]["INS_SEC_ID"];
f["NUM"]=dt_Line.Rows[j]["NUM"];
table.InsertFeature(f);
}
this.txtShowLine.Value="";
MapInfo.Mapping.FeatureLayer layer = new MapInfo.Mapping.FeatureLayer(table);
this.MapControl1.Map.Layers.Insert(0,layer);
MapInfo.Mapping.Thematics.IndividualValueTheme itheme=new MapInfo.Mapping.Thematics.IndividualValueTheme(layer,"NUM",layerName);
while(layer.Modifiers.Count>0)
...{
layer.Modifiers.RemoveAt(0);
}
layer.Modifiers.Append(itheme);
if(itheme.Bins[0]!=null)
...{
(itheme.Bins[0].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Color=Color.Red;
(itheme.Bins[0].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Pattern=42;
}
if(itheme.Bins[1]!=null)
...{
(itheme.Bins[1].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Color=Color.Gold;
(itheme.Bins[1].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Pattern=43;
}
if(itheme.Bins[2]!=null)
...{
(itheme.Bins[2].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Color=Color.DarkOrange;
(itheme.Bins[2].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Pattern=44;
}
if(itheme.Bins[3]!=null)
...{
(itheme.Bins[3].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Color=Color.DeepPink;
(itheme.Bins[3].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Pattern=5;
}
if(itheme.Bins[4]!=null)
...{
(itheme.Bins[4].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Color=Color.Pink;
(itheme.Bins[4].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Pattern=6;
}
int x=itheme.Bins.Count;
itheme.RecomputeBins();
}
... {
MapInfo.Data.TableInfo ti;
MapInfo.Data.Table table;
table = MapInfo.Engine.Session.Current.Catalog.GetTable(layerName);
ti = MapInfo.Data.TableInfoFactory.CreateTemp(layerName);
MapInfo.Data.Column colLine_ID=MapInfo.Data.ColumnFactory.CreateIntColumn("INS_SEC_ID");//添加列 线路名称
ti.Columns.Add(colLine_ID);
MapInfo.Data.Column colLine_NUM=MapInfo.Data.ColumnFactory.CreateIntColumn("NUM");//添加列 线路名称
ti.Columns.Add(colLine_NUM);;
if(table!=null)
...{
table.Close();
}
table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
System.Data.DataTable dt=new DataTable();
for(int i=0;i<dt_Line.Rows.Count;i++)
...{
string SQL = "SELECT INS_STARTSPOTID,INS_ENDSPOTID FROM INSPECTS_SECTION WHERE INS_SEC_ID='"+dt_Line.Rows[i]["INS_SEC_ID"].ToString()+"'";
string con_Str=System.Configuration.ConfigurationSettings.AppSettings["con_Str"];
System.Data.OleDb.OleDbDataAdapter Adapter=new System.Data.OleDb.OleDbDataAdapter(SQL,con_Str);
Adapter.Fill(dt);
}
for(int j=0;j<dt.Rows.Count;j++)
...{
System.Data.DataTable dt_s = new DataTable();
System.Data.DataTable dt_e = new DataTable();
string SQL_s = "SELECT SPOT_AFTER,SPOT_LATITUE FROM INSPECTS_SPOT_TYPE WHERE SPOT_ID='"+dt.Rows[j]["INS_STARTSPOTID"]+"'";
string SQL_e = "SELECT SPOT_AFTER,SPOT_LATITUE FROM INSPECTS_SPOT_TYPE WHERE SPOT_ID='"+dt.Rows[j]["INS_ENDSPOTID"]+"'";
string con_Str=System.Configuration.ConfigurationSettings.AppSettings["con_Str"];
System.Data.OleDb.OleDbDataAdapter adp_s = new System.Data.OleDb.OleDbDataAdapter(SQL_s,con_Str);
adp_s.Fill(dt_s);
System.Data.OleDb.OleDbDataAdapter adp_e = new System.Data.OleDb.OleDbDataAdapter(SQL_e,con_Str);
adp_e.Fill(dt_e);
double begin_x=Convert.ToDouble(dt_s.Rows[0]["SPOT_AFTER"]);
double begin_y=Convert.ToDouble(dt_s.Rows[0]["SPOT_LATITUE"]);
MapInfo.Geometry.DPoint beginPoint=new MapInfo.Geometry.DPoint(begin_x,begin_y);
double end_x=Convert.ToDouble(dt_e.Rows[0]["SPOT_AFTER"]);
double end_y=Convert.ToDouble(dt_e.Rows[0]["SPOT_LATITUE"]);
MapInfo.Geometry.DPoint endPoint=new MapInfo.Geometry.DPoint(end_x,end_y);
//create line
MapInfo.Geometry.MultiCurve mc=MapInfo.Geometry.MultiCurve.CreateLine(this.MapControl1.Map.GetDisplayCoordSys(),beginPoint,endPoint);
//create style
MapInfo.Styles.SimpleLineStyle bl=new MapInfo.Styles.SimpleLineStyle(new MapInfo.Styles.LineWidth(2,MapInfo.Styles.LineWidthUnit.Pixel),3,Color.Red);
MapInfo.Styles.CompositeStyle cs=new MapInfo.Styles.CompositeStyle(null,bl,null,null);
//create feature with geometry, style and name
MapInfo.Data.Feature f=new Feature(table.TableInfo.Columns);
f.Geometry=mc;
f.Style=cs;
f["INS_SEC_ID"]=dt_Line.Rows[j]["INS_SEC_ID"];
f["NUM"]=dt_Line.Rows[j]["NUM"];
table.InsertFeature(f);
}
this.txtShowLine.Value="";
MapInfo.Mapping.FeatureLayer layer = new MapInfo.Mapping.FeatureLayer(table);
this.MapControl1.Map.Layers.Insert(0,layer);
MapInfo.Mapping.Thematics.IndividualValueTheme itheme=new MapInfo.Mapping.Thematics.IndividualValueTheme(layer,"NUM",layerName);
while(layer.Modifiers.Count>0)
...{
layer.Modifiers.RemoveAt(0);
}
layer.Modifiers.Append(itheme);
if(itheme.Bins[0]!=null)
...{
(itheme.Bins[0].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Color=Color.Red;
(itheme.Bins[0].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Pattern=42;
}
if(itheme.Bins[1]!=null)
...{
(itheme.Bins[1].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Color=Color.Gold;
(itheme.Bins[1].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Pattern=43;
}
if(itheme.Bins[2]!=null)
...{
(itheme.Bins[2].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Color=Color.DarkOrange;
(itheme.Bins[2].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Pattern=44;
}
if(itheme.Bins[3]!=null)
...{
(itheme.Bins[3].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Color=Color.DeepPink;
(itheme.Bins[3].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Pattern=5;
}
if(itheme.Bins[4]!=null)
...{
(itheme.Bins[4].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Color=Color.Pink;
(itheme.Bins[4].Style.LineStyle as MapInfo.Styles.SimpleLineStyle).Pattern=6;
}
int x=itheme.Bins.Count;
itheme.RecomputeBins();
}