2018-04-09

分析原函数

public void getWellGridView1Row()
    {
        //存储各个对象的信息
        ArrayList WellNews = new ArrayList();
        //循环获取单个油井信息
        //从数据库中读取Infor_Map()所需参数
        foreach (GridViewRow row in GridView1.Rows)
        {
            string WellNum = row.Cells[1].Text.Trim().ToString();
            string Section = row.Cells[2].Text.Trim().ToString();
            string BuildData = row.Cells[3].Text.Trim().ToString();
            string Principal = row.Cells[4].Text.Trim().ToString();
            string Position = row.Cells[5].Text.Trim().ToString();
            string aWellNews = WellNum + ";" + Position + ";" + Section + ";" + Principal + ";" + BuildData;
            WellNews.Add(aWellNews);
        }

        Array WellNewsArray = WellNews.ToArray();
        ArrayList aWellNum = new ArrayList();
        ArrayList aPosition = new ArrayList();
        ArrayList aSection = new ArrayList();
        ArrayList aPrincipal = new ArrayList();
        ArrayList aBuildData = new ArrayList();
        foreach (string aWellNewsArray in WellNewsArray)
        {
            string[] aWellNewsString = aWellNewsArray.Split(';');
            aWellNum.Add(aWellNewsString[0]);
            aPosition.Add(aWellNewsString[1]);
            aSection.Add(aWellNewsString[2]);
            aPrincipal.Add(aWellNewsString[3]);
            aBuildData.Add(aWellNewsString[4]);
        }
        string aWellNums = string.Join(";", (string[])aWellNum.ToArray(typeof(string)));
        string aPositions = string.Join(";", (string[])aPosition.ToArray(typeof(string)));
        string aSections = string.Join(";", (string[])aSection.ToArray(typeof(string)));
        string aPrincipals = string.Join(";", (string[])aPrincipal.ToArray(typeof(string)));
        string aBuildDatas = string.Join(";", (string[])aBuildData.ToArray(typeof(string)));

        //将调用Infor_Map()的js代码添加到前端页面中
        StringBuilder Sb1 = new StringBuilder();
        Sb1.Append("");
        ClientScript.RegisterStartupScript(this.GetType(), "LoadPicScript", Sb1.ToString());
    }

后端代码中有前端函数的执行,所以我觉得如果如果你要合并前端函数,后端代码也需要修改。
类似getWellGridView1Row()的函数其大致逻辑为

  1. 取得数据
  2. 处理数据
  3. 将处理结果作为前端函数的参数传出

将getWellGridView1Row()中取得的数据传到前台,以便js接收

后台代码

    //keyValue-后台中以字典方式存储参数数据的全局变量
    public System.Collections.Generic.Dictionary keyValue = new Dictionary();
    //dataJson-存储json格式的keyValue,前台js取得该变量便也就取得了所需参数
    public string dataJson;
    protected void Page_Load(object sender, EventArgs e)
    {//默认页面处理函数,理解为后台程序入口
        getWellGridView1Row();//执行类似函数,将所需参数数据存入keyValue
        //以下两行为keyValue的json化
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        dataJson = serializer.Serialize(keyValue);
        Response.Write(dataJson);//可删除,将dataJson打印到页面顶端
    }

    public void getWellGridView1Row()
    {
        //模拟从数据库中取得数据并处理为可用参数
        String aWellNums = "aWellNums";
        String aPositions = "aPositions";
        String aSections = "aSections";

        //将所需参数加入到keyValue
        keyValue.Add("aWellNums", aWellNums);
        keyValue.Add("aPositions", aPositions);
        keyValue.Add("aSections", aSections);
    }

主要逻辑为


2018-04-09_第1张图片
后台流程

前端代码


你可能感兴趣的:(2018-04-09)