qq_35202555 2016-06-19 13:38 采纳率: 66.7%
浏览 1275
已采纳

新人求教。下面代码各什么意思

private void all_track(int id)
{
//datagridview中写入数据
string scn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据表.mdb";
OleDbConnection mycn = new OleDbConnection(scn);

        mycn.Open();
        OleDbCommand mycmd = new OleDbCommand();
        mycmd.Connection = mycn;
        mycmd.CommandType = CommandType.Text;

        string c = "select * from point1 where id='" + id + "'";

        mycmd.CommandText = c;
        OleDbDataAdapter add = new OleDbDataAdapter(mycmd);
        DataSet ds = new DataSet();
        add.Fill(ds, "a");
        DataTable dt = new DataTable();
        dt = ds.Tables["a"];


        string name;
        IPointCollection ppc = new PolylineClass();
        for (int i = 0; i < dt.Rows.Count; i++)
        {

            name = dt.Rows[i]["id"].ToString();
            name = name.Trim();
            double x = Convert.ToDouble(dt.Rows[i]["x"]);
            double y = Convert.ToDouble(dt.Rows[i]["y"]);
            ITextElement pte = new TextElementClass();
            ISimpleTextSymbol psts = new TextSymbolClass();
            IRgbColor prc = new RgbColorClass();

            IFont mf = new StdFontClass();
            mf.Name = "宋体";//Courier New
            IFontDisp mt = mf as IFontDisp;
            psts.Font = mt;
            psts.Size = 18;
            pte.Symbol = psts;
            pte.Text = name;
            IElement pelt = pte as IElement;
            IElementProperties pelet = pelt as IElementProperties;
            pelet.Name = name;
            IElement pel = new MarkerElementClass();
            IPoint pp = new PointClass();
            pp.PutCoords(x, y);
            ppc.AddPoints(1, ref pp);
            pel.Geometry = pp;
            pelt.Geometry = pp;
            IElementProperties pele = pel as IElementProperties;
            pele.Name = name;
            ISimpleMarkerSymbol psm = new SimpleMarkerSymbolClass();
            IRgbColor prg = new RgbColorClass();
            IMarkerElement pme = pel as IMarkerElement;
            IRgbColor prgb = new RgbColorClass();

            pgc.AddElement(pel, 0);

            pgc.AddElement(pelt, 0);

            this.axMapControl1.ActiveView.Refresh();

        }

        IPolyline ppl = ppc as IPolyline;
        IElement pele1 = new LineElementClass();
        pele1.Geometry = ppl;

        ILineElement ple = pele1 as ILineElement;
        ISimpleLineSymbol psl = new SimpleLineSymbolClass();
        //psl.Style = esriSimpleLineStyle.esriSLSSolid;   // ctrl + J
        IRgbColor prg1 = new RgbColorClass();

        pgc.AddElement(pele1, 0);
        this.axMapControl1.ActiveView.Refresh();
  • 写回答

2条回答 默认 最新

  • devmiao 2016-06-19 13:45
    关注

    private void all_track(int id)
    {
    //datagridview中写入数据
    string scn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据表.mdb"; 读取access数据源
    OleDbConnection mycn = new OleDbConnection(scn); 建立连接
    mycn.Open(); 打开连接
    OleDbCommand mycmd = new OleDbCommand(); 初始化命令
    mycmd.Connection = mycn; 打开连接
    mycmd.CommandType = CommandType.Text; 设置数据库命令

        string c = "select * from point1 where id='" + id + "'"; 查询符合的id
    
        mycmd.CommandText = c; 设置sql语句
        OleDbDataAdapter add = new OleDbDataAdapter(mycmd); 创建适配器
        DataSet ds = new DataSet(); 创建数据集
        add.Fill(ds, "a"); 填充数据
        DataTable dt = new DataTable(); 初始化表
        dt = ds.Tables["a"]; 获取表
    
    
        string name; 定义名字变量
        IPointCollection ppc = new PolylineClass(); 定义点
        for (int i = 0; i < dt.Rows.Count; i++) 遍历数据库
        {
    
            name = dt.Rows[i]["id"].ToString(); 取得id
            name = name.Trim(); 对名字截取,去到空格
            double x = Convert.ToDouble(dt.Rows[i]["x"]); x坐标
            double y = Convert.ToDouble(dt.Rows[i]["y"]); y坐标
            ITextElement pte = new TextElementClass(); 文字元素
            ISimpleTextSymbol psts = new TextSymbolClass(); 字符
            IRgbColor prc = new RgbColorClass( 颜色);
    
            IFont mf = new StdFontClass(); 字体类
            mf.Name = "宋体";//Courier New 宋体字体
            IFontDisp mt = mf as IFontDisp; 字体
            psts.Font = mt; 字体
            psts.Size = 18; 大小
            pte.Symbol = psts; 设置符号
            pte.Text = name; 设置名称
            IElement pelt = pte as IElement; 元素
            IElementProperties pelet = pelt as IElementProperties; 属性
            pelet.Name = name; 设置名称
            IElement pel = new MarkerElementClass(); 元素
            IPoint pp = new PointClass(); 画点
            pp.PutCoords(x, y); 放线
            ppc.AddPoints(1, ref pp); 添加点
            pel.Geometry = pp; 设置坐标
            pelt.Geometry = pp; 设置坐标
            IElementProperties pele = pel as IElementProperties; 属性
            pele.Name = name; 设置名称
            ISimpleMarkerSymbol psm = new SimpleMarkerSymbolClass(); 添加符号
            IRgbColor prg = new RgbColorClass(); 颜色
            IMarkerElement pme = pel as IMarkerElement; 标记元素
            IRgbColor prgb = new RgbColorClass(); 颜色
    
            pgc.AddElement(pel, 0); 添加pel
    
            pgc.AddElement(pelt, 0); 添加元素
    
            this.axMapControl1.ActiveView.Refresh(); 刷新界面
    
        }
    
        IPolyline ppl = ppc as IPolyline;点
        IElement pele1 = new LineElementClass(); 画线
        pele1.Geometry = ppl; 地理坐标
    
        ILineElement ple = pele1 as ILineElement; 线条元素
        ISimpleLineSymbol psl = new SimpleLineSymbolClass(); 画线条
        //psl.Style = esriSimpleLineStyle.esriSLSSolid;   // ctrl + J 实心画笔
        IRgbColor prg1 = new RgbColorClass(); 颜色类
    
        pgc.AddElement(pele1, 0); 添加元素
        this.axMapControl1.ActiveView.Refresh(); 刷新
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 cmd批处理参数如果含有双引号,该如何传入?
  • ¥15 fx2n系列plc的自控成型机模拟
  • ¥15 时间序列LSTM模型归回预测代码问题
  • ¥50 使用CUDA如何高效的做并行化处理,是否可以多个分段同时进行匹配计算处理?目前数据传输速度有些慢,如何提高速度,使用gdrcopy是否可行?请给出具体意见。
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),如何通过环岛的原理及完整代码
  • ¥20 机器学习或深度学习问题?困扰了我一个世纪,晚来天欲雪,能饮一杯无?
  • ¥15 c语言数据结构高铁订票系统
  • ¥15 关于wkernell.PDB加载的问题,如何解决?(语言-c#|开发工具-vscode)
  • ¥100 某宝多次访问被拒绝,求解
  • ¥15 (标签-STM32|关键词-智能小车)