首页 > 代码库 > .NET下的并行开发(案例代码)

.NET下的并行开发(案例代码)

以下主要是通过一个报表处理程序来说明并行开发的方式。对于数据冲突和共享,可以通过对象数组解决。设计到并行的核心代码已用红色标出。在并行程序的处理上,需要把原来串行的子公司变成一个一个类的对象,让所有的类对象一起并行运行就达到提高响应速率的目的了。并行设计中,主要的还是编程的思想,并行的语法,规则都是规划好的。好的工具就看你如何使用了。

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using Excel = Microsoft.Office.Interop.Excel;
using gcdb;
using System.Data.Odbc;
using gc;
using ExcelQuicker.Framework;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace scbb
{

    //企业营业额完成情况一览表
    //具体注释,请参考 建筑业总产值分类完成情况表
    // h 开头为海外项目统计参数
    //"企业营业额完成情况表.xls";//模板文件名称



    public class scbb_b7
    {
        string downExcelFile;

        string c_yhid, c_yhdw, c_xmmxf, c_sfgz, c_ddlb, c_yearmonth, c_yhjb, c_ybtime;
        int c_dlml;//是否存储到独立目录
        string yearmonth;
        string jibie;
        string year;
        string month;
        string ddlb;
      
      public   object[,] objDataExcel;
        System.Collections.Queue q = new Queue();
        System.Collections.Queue q2 = new Queue();

        protected string tbn(int n)
        {
            if (n <= 0 || n > 10)
                return "";
            string[] bigNum = new string[] { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
            return bigNum[n - 1];

        }
        protected string toBigNumber(int num)
        {
            string b = "";
            if (num > 100 || num <= 0)
                return "";
            if (num <= 10)
                b = tbn(num);
            else if (num < 20)
            {
                b = "十" + tbn(num % 10);
            }
            else
            {
                b = tbn(num / 10) + "十" + tbn(num % 10);
            }

            b = b + "、";
            return b;
        }

        DB db = new DB();

        public void Initialize()
        {
            if (Directory.Exists(HttpRuntime.AppDomainAppPath + "ExcelQuicker\\gf\\" + c_ybtime.Substring(0, 7)) == false)
            {
                Directory.CreateDirectory(HttpRuntime.AppDomainAppPath + "ExcelQuicker\\gf\\" + c_ybtime.Substring(0, 7));
            }
            EQConfiguration.XmlFileName = HttpRuntime.AppDomainAppPath + "ExcelQuicker\\Lib\\Message.xml";
            EQConfiguration.Language = "EN";
            if (c_dlml == 1)
            {
                EQConfiguration.TemporaryFilePath = HttpRuntime.AppDomainAppPath + "ExcelQuicker\\gf\\";
                EQConfiguration.OutputFilePath = HttpRuntime.AppDomainAppPath + "ExcelQuicker\\gf\\" + c_ybtime.Substring(0, 7) + "\\";
            }
            else
            {
                if (Directory.Exists(HttpRuntime.AppDomainAppPath + "ExcelQuicker\\TempReports\\" + c_yhdw.Substring(0, 4)) == false)
                {
                    Directory.CreateDirectory(HttpRuntime.AppDomainAppPath + "ExcelQuicker\\TempReports\\" + c_yhdw.Substring(0, 4));
                }
                EQConfiguration.TemporaryFilePath = HttpRuntime.AppDomainAppPath + "ExcelQuicker\\TempReports\\" + c_yhdw.Substring(0, 4);
                EQConfiguration.OutputFilePath = HttpRuntime.AppDomainAppPath + "ExcelQuicker\\TempReports\\" + c_yhdw.Substring(0, 4);
            }
            EQConfiguration.TemplateFilePath = HttpRuntime.AppDomainAppPath + "ExcelQuicker\\Template\\";

        }


        public void setSpeficedRange(int x0, int y0, int x1, int y1, EQWorksheet xlWorkSheet, string content)
        {
            string[,] dwfzr = new string[1, 1];  //建立二維數組對象
            dwfzr[0, 0] = content;
            EQRange range = new EQRange(dwfzr, x0, y0, x1, y1);
            range.MergeCells = true;
            xlWorkSheet.Add(range);

        }
        void set_Excel(string strFileName, string strTemplate, DwObject[] dwmobjdata)
        {

            OdbcDataReader tempOdr;
            EQApplication objApp = new EQApplication(strFileName, EQReportFormat.Excel, strTemplate, false);
            //objApp.AddOutputFile(strFileName, EQReportFormat.HTML);    //Command to output a html format report file at the same time
            EQWorksheet objWS = new EQWorksheet("报表数据");
            EQRange zrange = new EQRange(objDataExcel, 8, 1, 9, 140);
            zrange.AddStyle(EQStyleFactory.BlackAndGrayBorder);
            zrange.AddStyle(EQStyleFactory.OuterBorder);
            zrange.AddStyle(EQStyleFactory.AlignRight);
            zrange.Type = EQType.General;
            setRowColor(8, 19, 10, objWS);
            objWS.Add(zrange);
            EQRange[] range = new EQRange[dwmobjdata.Length];
            int sum = 0;
            int sun = 0;
            for (int p = 0; p < dwmobjdata.Length; p++)
            {

                sum += dwmobjdata[p].objData .GetLength(0);
                sun = sum - dwmobjdata[p].objData.GetLength(0);

                range[p] = new EQRange(dwmobjdata[p].objData, 10+ sun, 1, 10 + sum - 1, 140);
                range[p].Type = EQType.General;

                //設置單元格整體風格
                range[p].AddStyle(EQStyleFactory.BlackAndGrayBorder);
                range[p].AddStyle(EQStyleFactory.OuterBorder);
                range[p].AddStyle(EQStyleFactory.AlignRight); //設置所有單元格右對齊
                //設置第一列左對齊
                EQColumnStyle mycolumnstyle = new EQColumnStyle();
                mycolumnstyle.SetColumnStyle(1, EQStyleFactory.AlignCenter);
                mycolumnstyle.SetColumnStyle(2, EQStyleFactory.AlignLeft);
                setRowColor(10 + sun, 19, 10, objWS);

                objWS.Add(range[p]);
                objWS.Add(mycolumnstyle);
            }




            //设置特定行的格式

            //设置表头部信息
            string sql_yhdw = "select dwmc from t_dw where dwid = ‘" + c_yhdw + "‘";
            tempOdr = db.getReader(sql_yhdw);
            tempOdr.Read();
            string mydwmc = tempOdr.GetValue(0).ToString();//设置选定区域的文本,可用于设置填报公司
            mydwmc = "填报单位:" + mydwmc;
            tempOdr.Close();
            setSpeficedRange(4, 1, 4, 1, objWS, mydwmc);
            setSpeficedRange(3, 1, 3, 12, objWS, "单位建设项目主要实物工程量完成情况(" + c_ddlb + ")");
            string mytime = year + "年" + month + "月";
            setSpeficedRange(4, 6, 4, 7, objWS, mytime);
            //设置表尾信息
            FillIn(sum, objWS);
            objApp.Add(objWS);
            try
            {
                objApp.Output();
            }
            catch (Exception)
            {
                objApp.Dispose();
                zdscbb.xrbbhcwcyy("b7", c_yhdw, c_xmmxf, c_sfgz, c_ddlb, c_ybtime, "Output Error");
            }
        }




        public void setRowColor(int rowNum, int colorIndex, int fontSize, EQWorksheet xlWorkSheet)
        {

            EQRowStyle mystyle = new EQRowStyle();
            EQRangeStyle mystyle2 = new EQRangeStyle();
            mystyle2.BackColor = colorIndex;
            mystyle2.Size = fontSize;
            //mystyle2.Bond = true;
            string endColumn1 = "e";   //结束时的列
            string endColumn2 = "j";  //结束时的列
            mystyle.SetRowStyle(rowNum, endColumn1, endColumn2, mystyle2);
            xlWorkSheet.Add(mystyle);
        }


        public int get_Count_From_Sql(string sql)
        {

            OdbcDataReader tempOdr;
            int tempNum;
            tempOdr = db.getReader(sql);
            tempOdr.Read();
            tempNum = int.Parse(tempOdr.GetValue(0).ToString());//公司数目
            tempOdr.Close();

            return tempNum;
        }






        public void xrbb(string cl_yhid, string cl_yhdw, string cl_xmmxf, string cl_sfgz, string cl_ddlb, string cl_yearmonth, string cl_yhjb, string cl_ybtime, int cl_dlml)
        {
            c_dlml = cl_dlml;
            c_yhid = cl_yhid;
            c_yhdw = cl_yhdw;
            c_xmmxf = cl_xmmxf;
            c_sfgz = cl_sfgz;
            c_ddlb = cl_ddlb;
            c_yearmonth = cl_yearmonth;
            c_yhjb = cl_yhjb;
            c_ybtime = cl_ybtime;
            string strFileName = "b7_" + c_yhdw + "_" + c_ddlb + c_xmmxf + c_ybtime + c_sfgz + ".xls";//生成的临时文件名称
            zdscbb.xrbbhc("b7", cl_yhdw, cl_xmmxf, cl_sfgz, cl_ddlb, cl_ybtime, strFileName);
            downExcelFile = "../ExcelQuicker/TempReports/" + strFileName;



            yearmonth = c_yearmonth;
            jibie = c_yhjb.ToString().Trim();
            ddlb = c_ddlb.ToString();
            year = yearmonth.Substring(0, 4);
            month = yearmonth.Substring(5, 2);

            int iMonth = Convert.ToInt32(month);

            if (iMonth < 10)
                month = month.Substring(1, 1);

            ////项目数
            //string sql_xmmc_count1 = "select count(*) from (  select id,sgdw,xmmc,sfgz" + c_yhjb + ",ddlb  from T_gcxm where  (lrrq is null or year(lrrq)<" + year + " or (YEAR(lrrq)=" + year + " and MONTH(lrrq)<=" + month + "))and (xmjd<>‘竣工‘  or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id ) or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and" +
            //                " sgdw like‘" + c_yhdw + "%‘  or (sgdw like ‘" + c_yhdw + "%‘ and fgcid is null ) "
            //    +
            //     " union (select id,sgdw,xmmc,sfgz" + c_yhjb + ",ddlb from T_gcxm where (lrrq is null or year(lrrq)<" + year + " or (YEAR(lrrq)=" + year + " and MONTH(lrrq)<=" + month + "))and  (xmjd<>‘竣工‘  or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id ) or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and fgcid in (select id from T_gcxm where (xmjd<>‘竣工‘  or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id ) or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and  xmgldw = ‘" +
            //        c_yhdw + "‘ ) and sgdw !=‘" + c_yhdw + "‘) ) as table_name  where 1=1 ";


        string sql_xmmc_count=  " select count(*) from t_gcxm where (lrrq is null or year(lrrq)<" + year + " or (YEAR(lrrq)=" + year + " and MONTH(lrrq)<=" + month + "))and (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)";
            //所有项目
            string sql_xmmc = "select * from ( select id, xmmc, sgdw,sfgz" + c_yhjb + ",ddlb from T_gcxm where  (lrrq is null or year(lrrq)<" + year + " or (YEAR(lrrq)=" + year + " and MONTH(lrrq)<=" + month + "))and (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and " +
              " sgdw like‘" + c_yhdw + "%‘ and ((sgdw <>‘" + c_yhdw
              + "‘ and fgcid is  null)or(sgdw =‘";
           
            string sql_xmmc_part2 = "‘ )) " + " union (select id,xmmc, sgdw,sfgz" + c_yhjb + ",ddlb from T_gcxm where  (lrrq is null or year(lrrq)<" + year + " or (YEAR(lrrq)=" + year + " and MONTH(lrrq)<=" + month + "))and (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and fgcid in (select id from T_gcxm where (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and  xmgldw = ‘" + c_yhdw + "‘ ) and sgdw !=‘" + c_yhdw + "‘) ) as table_name where 1=1   ";

            //        土石方    隧道  桥梁(设计折合 米)     其中:大中桥        其中:立交、高架桥        正线铺轨(公里)    其中:高速    站线铺轨(公里)  铁路制梁(片)    铁路架梁(孔)    机械化整道(公里)    无砟轨道通信线路(公里)自动闭塞(区间公里)    电气集中(联锁道岔)    供电线路(公里)变配电所(站)    接触网(正线公里)    牵引变电所(处)    房屋施工面积    房屋竣工面积    地铁成洞(折合米)        地铁车站(座)        轻轨(折合米)        公路(折合公里)        其中:高速公路        其中:路面(平方米)        



            string sql_sum_klwc = " select sum(byxmzcz),sum(sw_tsf),sum(sw_sdsjcd),sum(sw_qlsjcd),sum(sw_dzq),sum(sw_ljgs),sum(tdq),sum(sw_tlzhxpg),sum(sw_gstl),sum(sw_tlzxpg),null,sum(sw_tljl),null,null,sum(sd_gdxl),sum(sd_bpds),sum(sd_jcw),sum(sd_qybds),sum(sd_txxl),sum(sd_xlgl),sum(sd_txsb),sum(sd_zdbs),sum(sd_dqjz),sum(fj_fwjzmj),sum(fj_fjzhmj),sum(fj_fjjgmj),sum(sw_dt),sum(sw_dtcz),sum(sw_qg),sum(sw_gl),sum(sw_gl_gs),sum(sw_gl_lm) from VIEW_YB_ALL where " +
                "  (lrrq is null or year(lrrq)<" + year + " or (YEAR(lrrq)=" + year + " and MONTH(lrrq)<=" + month + "))and sgdw like‘" + c_yhdw + "%‘";

            //(a.bqswl <> 1) OR (a.bqswl IS NULL)
            //本年完成
            string sql_sum_bnwc = " select sum(byxmzcz),sum(sw_tsf),sum(sw_sdsjcd),sum(sw_qlsjcd),sum(sw_dzq),sum(sw_ljgs),sum(tdq),sum(sw_tlzhxpg),sum(sw_gstl),sum(sw_tlzxpg),null,sum(sw_tljl),null,null,sum(sd_gdxl),sum(sd_bpds),sum(sd_jcw),sum(sd_qybds),sum(sd_txxl),sum(sd_xlgl),sum(sd_txsb),sum(sd_zdbs),sum(sd_dqjz),sum(fj_fwjzmj),sum(fj_fjzhmj),sum(fj_fjjgmj),sum(sw_dt),sum(sw_dtcz),sum(sw_qg),sum(sw_gl),sum(sw_gl_gs),sum(sw_gl_lm) from VIEW_YB_XM where " +
                " sgdw like‘" + c_yhdw + "%‘ and  year(ybsj)= ‘" + year + "‘" + " and month(ybsj)<= " + month + " ";

            //string subproject_yb = " or  fgcid in ( select xmid from view_yb_xm where sgdw like ‘" +c_yhdw + "%‘  and  year(ybsj)= ‘" + year + "‘ ";

            if (c_sfgz.ToString() == "关注项目")
            {
                sql_xmmc_count = sql_xmmc_count + " and sfgz" + c_yhjb + "=1";
                sql_xmmc_part2 = sql_xmmc_part2 + " and sfgz" + c_yhjb + "=1";
                sql_sum_klwc = sql_sum_klwc + " and sfgz" + c_yhjb + "=1";
                sql_sum_bnwc = sql_sum_bnwc + " and sfgz" + c_yhjb + "=1";

            }
            if (c_sfgz.ToString() == "非关注项目")
            {
                sql_xmmc_count = sql_xmmc_count + " and sfgz" + c_yhjb + "=0";
                sql_xmmc_part2 = sql_xmmc_part2 + " and sfgz" + c_yhjb + "=0";
                sql_sum_klwc = sql_sum_klwc + " and sfgz" + c_yhjb + "=0";
                sql_sum_bnwc = sql_sum_bnwc + " and sfgz" + c_yhjb + "=0";

            }

            string sql_sum_klwc_total = sql_sum_klwc;
            string sql_sum_bnwc_total = sql_sum_bnwc;


            if (c_ddlb.ToString() == "海外")
            {
                sql_xmmc_count = sql_xmmc_count + "and ddlb = ‘海外‘";
                sql_xmmc_part2 = sql_xmmc_part2 + "and ddlb = ‘海外‘";
                sql_sum_klwc = sql_sum_klwc + "and ddlb = ‘海外‘";
                sql_sum_bnwc = sql_sum_bnwc + "and ddlb = ‘海外‘";

            }

            if (c_ddlb.ToString() == "国内")
            {
                sql_xmmc_count = sql_xmmc_count + "and (ddlb = ‘省内‘ or ddlb = ‘省外‘)";
                sql_xmmc_part2 = sql_xmmc_part2 + "and (ddlb = ‘省内‘ or ddlb = ‘省外‘)";
                sql_sum_klwc = sql_sum_klwc + "and (ddlb = ‘省内‘ or ddlb = ‘省外‘)";
                sql_sum_bnwc = sql_sum_bnwc + "and (ddlb = ‘省内‘ or ddlb = ‘省外‘)";
            }



            int cnum = 140;

            objDataExcel = new object[2, cnum];  //分配两行,一行显示总计数据,一行显示范围


            for (int i2 = 0; i2 < 2; i2++)
            {
                for (int j2 = 0; j2 < cnum; j2++)
                    objDataExcel[i2, j2] = "";
            }



            objDataExcel[0, 1] = "总计";

          if (c_ddlb.ToString() == "国内" || c_ddlb.ToString() == "海外" || c_ddlb.ToString()=="全部")
              objDataExcel[1, 1] = "  " + c_ddlb.ToString() + "项目计";

         
            //单位名称分类
            //支公司检阅信息
            string sql_dw_fid = "select id from t_dw  where dwid = ‘" + c_yhdw + "‘ ";  //查询单位的编号
            OdbcDataReader odr_dw_fid = db.getReader(sql_dw_fid);
            odr_dw_fid.Read();
          string   dw_fid = odr_dw_fid["id"].ToString ();
            odr_dw_fid.Close();



            string sql_dw = "select dwmc,dwid,dwjb,fdwid from t_dw where (dwid = ‘" + c_yhdw + "‘ or fdwid =  ‘" + dw_fid  + "‘ ) and bbxs is null order by dwxh";
        
           
            OdbcDataReader odr_dw = db.getReader(sql_dw);


        

         
            int dw_count = 0;    //记录总的单位数量
            string sql_dw_count2 = "select count(*) from t_dw where (dwid = ‘" + c_yhdw + "‘ or fdwid =  ‘" + dw_fid + "‘ ) and bbxs is null  ";
           
            OdbcDataReader odr = db.getReader(sql_dw_count2);
            odr.Read();
            dw_count = (int)odr[0];
            odr.Close();
            int dws = 0;//记录单位的数量
            string[] arry = new string[dw_count];//记录单位的编号

            while (odr_dw.Read())
            {
                arry[dws] = odr_dw.GetValue(1).ToString();
                dws++;
            }
            odr_dw.Close();
            DwObject[] dwmess = new DwObject[dw_count];

         
            Parallel.For(0, dw_count, (y) =>
            {
                dwmess[y] = new DwObject();
                dwmess[y].post( year,c_yhdw,sql_sum_bnwc, sql_xmmc_part2, sql_sum_klwc, sql_xmmc, c_xmmxf, c_yhjb,  c_ybtime, y, sql_xmmc_count);
                dwmess[y].dws(arry[y]);
              

            });


            /********************
             *
             * 统计总计数据
             * *********************/
            if (c_yhjb.ToString() == "3")
            {
                for (int z = 0; z < cnum; z++)
                { objDataExcel[0, z] = ""; }
            }
            else
            {
                double[] sum = new double[150];
                for (int z = 2; z < cnum; z++)
                {
                    for (int p = 0; p < dwmess.Length; p++)
                    {
                        if ( dwmess[p].objData[0, z].ToString() != "")
                            sum[z] += Convert.ToDouble(dwmess[p].objData[0, z]);

                    }

                    if (c_yhdw.ToString() != "gf" && dwmess[0].objData[0, z].ToString() != "")
                    {
                        sum[z] -= 2 * Convert.ToDouble(dwmess[0].objData[0, z]); /*分公司项目存在局指,项目重复显示*/
                    }
                    objDataExcel[0, z] = sum[z];


                }
            }

         
            string strTemplate = "单位实物量统计表.xls";
            Initialize();//调用excel quicker初始化函数
            set_Excel(strFileName, strTemplate,dwmess );//生成并设置此excel表
            zdscbb.xrbbhcwc("b7", cl_yhdw, cl_xmmxf, cl_sfgz, cl_ddlb, cl_ybtime, strFileName);
        }

        private void FillIn(int num, EQWorksheet xlWorkSheet)
        {
            string sql_user = "select  dwfzr,tjfzr,yhmc,lxfs from t_user where yhid = ‘" + c_yhid + "‘";

            OdbcDataReader odr_user = db.getReader(sql_user);
            odr_user.Read();

            int Allnum = num + 11;
            string[,] dwfzr = new string[1, 1];
            dwfzr[0, 0] = "单位负责人:" + odr_user.GetValue(0).ToString() + "          统计负责人:" + odr_user.GetValue(1).ToString() + "           填报人:" + odr_user.GetValue(2).ToString() + "          联系电话:" + odr_user.GetValue(3).ToString() + "          上报日期:" + DateTime.Today.ToShortDateString();
            EQRange range = new EQRange(dwfzr, Allnum, 1, Allnum, 10);

            range.MergeCells = true;
            range.AddStyle(EQStyleFactory.AlignCenter);






            xlWorkSheet.Add(range);

            odr_user.Close();
            //完成填报
        }


     
    }

  public class DwObject
    {
          int xmxh = 0;
          Hashtable ht;
        int row_position = 0;
        int control_col = 139;
        int gclb_row = 0;
        int zj_row = 0;
        int gnxm_row = 0;
        public int rnum = 0;
        public int cnum = 140;  // 列
        public object[,] objData;
        DB db = new DB();
        int flxh=0;   //工程项目序号
    
      
        //由scbb_b7中赋值后传过来的变量
        string sql_sum_bnwc = "";
       string sql_xmmc_part2 ="";
        string sql_sum_klwc = "";
        string sql_xmmc = "";
        string sql_xmmc_count;
        string c_xmmxf, c_yhjb, c_ybtime,c_yhdw,year;
        //在调用函数时要先赋值给他们
        public void post(string year1,string c_yhdw1,string sql_sum_bnwc1, string sql_xmmc_part21, string sql_sum_klwc1, string sql_xmmc1, string c_xmmxf1, string c_yhjb1, string c_ybtime1, int flxh1,string  sql_xmmc_count1)
        {
            c_yhdw=c_yhdw1;
            sql_sum_bnwc = sql_sum_bnwc1;
           sql_xmmc_part2 =sql_xmmc_part21;
            sql_sum_klwc = sql_sum_klwc1;
            sql_xmmc = sql_xmmc1;
            c_xmmxf = c_xmmxf1;
            c_yhjb = c_yhjb1;
            c_ybtime = c_ybtime1;
            flxh = flxh1;
            sql_xmmc_count= sql_xmmc_count1;
              year=year1;

        }

        public int rnumber(string dwid, string sql_xmmc_count)
        {



            int gclb_count = 1;

            int gcxm_count = 0;  //记录具体的项目数量
            if (c_xmmxf == "True")    //是否显示明细
            {
                // 统计行数
                OdbcDataReader odr;
                 string sql_xmmc_count_dw = sql_xmmc_count + "and sgdw = ‘" + dwid + "‘";
                  if (dwid == c_yhdw.ToString())

               sql_xmmc_count_dw = sql_xmmc_count + "and sgdw = ‘" + dwid + "‘";
                  else  
                  
                      sql_xmmc_count_dw = sql_xmmc_count + "and sgdw like ‘" + dwid + "%‘";


                  odr = db.getReader(sql_xmmc_count_dw);       //工程项目行数
                  odr.Read();
                  gcxm_count = (int)odr[0];
                  odr.Close();

                  int zgc_count = 0;
                /***********************************
                 * 对于股份公司,在求它空间的时候,应该去掉相应重复的跨单位工程
                 *
                 * *************************************/
                  if (c_yhdw.ToString() == "gf" && dwid != c_yhdw.ToString())   
                  {
                      //跨单位管理的工程将显示两遍,
                     
                      string sql_zgcxm = "select count(*) from T_gcxm where (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and fgcid is not null and sgdw like‘" + dwid + "%‘";
                      odr = db.getReader(sql_zgcxm);
                      odr.Read();
                      zgc_count = (int)odr[0];
                      odr.Close();
                     

                  }

                  gcxm_count -= zgc_count;

                //====================================================================统计子项目个数       
                    string odr_gcxm_gclb = "";
                    if (dwid == c_yhdw.ToString())
                        odr_gcxm_gclb = sql_xmmc + dwid + sql_xmmc_part2 + " and sgdw =‘" + dwid + "‘ order by id desc";

                    else
                        odr_gcxm_gclb = sql_xmmc + dwid + sql_xmmc_part2 + " and sgdw like‘" + dwid + "%‘ order by id desc";

                    OdbcDataReader odr_gcxm_count = db.getReader(odr_gcxm_gclb);



                    while (odr_gcxm_count.Read())
                    {
                        string s_sql_sfyzxm = "select isnull(fgcid,0) from t_gcxm where id=" + odr_gcxm_count.GetValue(0).ToString() + " ";
                        OdbcDataReader odr_zxm = db.getReader(s_sql_sfyzxm);
                        if (odr_zxm.Read())
                        {
                            if (odr_zxm[0].ToString() != "0" && dwid != c_yhdw)
                            {
                                string sql1 = "select xmgldw,xmmc,id from T_gcxm where (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and  id=(select fgcid from T_gcxm where (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and id=‘" + odr_gcxm_count.GetValue(0).ToString() + "‘)";
                                OdbcDataReader reader = db.getReader(sql1);
                                while (reader.Read())
                                {
                                    if (reader.GetValue(0).ToString() == dwid)
                                    {
                                        //表明当前项目的父项目的项目管理单位是用户单位
                                        string sql_zxm_count = "select count(*) from T_gcxm where (xmjd<>‘竣工‘  or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id ) or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and fgcid=(select fgcid from T_gcxm where (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and id=‘" + odr_gcxm_count.GetValue(0).ToString() + "‘) ";
                                        OdbcDataReader odr_zxm_count = db.getReader(sql_zxm_count);
                                        odr_zxm_count.Read();
                                        gcxm_count += (int)odr_zxm_count[0];
                                        odr_zxm_count.Close();
                                    }

                                }
                                reader.Close();
                            }
                        }
                    }
                    odr_gcxm_count.Close();
                }

            
            int total = gcxm_count  + gclb_count;
            return total;

        }




        
        protected string toBigNumber(int num)
        {
            string[] bigNum = new string[] { "", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十" };
            if (num > 0 && num <= 20)
                return bigNum[num] + "、";
            else
                if (num < 100)
                {
                    return bigNum[num / 10] + bigNum[num % 10 + 10] + "、";
                }
                else
                    return "";
        }

      
      public object[,] dws(string dwid)
        {

            rnum = rnumber(dwid,sql_xmmc_count );
            objData = http://www.mamicode.com/new object[rnum, cnum];
            for (int i2 = 0; i2 < rnum; i2++)
            {
                for (int j2 = 0; j2 < cnum; j2++)
                    objData[i2, j2] = "";
            }
            
            gclb_row = row_position;
           
          string sql_dw = "select dwmc from t_dw where dwid = ‘" + dwid + "‘";
            OdbcDataReader odr_dw = db.getReader(sql_dw);
            string dwmc = "";
            odr_dw.Read();
            dwmc = odr_dw.GetValue(0).ToString();
            odr_dw.Close();
            objData[row_position, 0] = toBigNumber(flxh + 1);   //计量单位的编号,序号为生成的对象
            objData[row_position, 1] = dwmc;
                //记录分类位置

             //   q.Enqueue(row_position);

                string sql_sum_bnwc_gclb = "";
                if (dwid == c_yhdw.ToString())
                    sql_sum_bnwc_gclb = sql_sum_bnwc + "and sgdw = ‘" + dwid + "‘";  // //工程分类
                else
                    sql_sum_bnwc_gclb = sql_sum_bnwc + "and sgdw like ‘" + dwid + "%‘";  // //工程分类
             
                OdbcDataReader odr_sum_gclb_bnwc;//= db.getReader(sql_sum_bnwc_gclb);

                //同一类别项目总计行本年完成
                // odr_sum_gclb_bnwc.Read();

              int   n = 1;
              int   k = 1;

                while (n < control_col)
                {

                    objData[row_position, n + 1] = "";// odr_sum_gclb_bnwc.GetValue(k).ToString(); //在range中的位置 (1,1)
                    n += 3;
                    k++;
                }
                string sql_sum_klwc_gclb = "";
                if (dwid == c_yhdw.ToString())
                    sql_sum_klwc_gclb = sql_sum_klwc + "and sgdw = ‘" + dwid + "‘";  //
                else
                    sql_sum_klwc_gclb = sql_sum_klwc + "and sgdw like ‘" + dwid + "%‘";  //
                OdbcDataReader odr_sum_gclb_klwc;// = db.getReader(sql_sum_klwc_gclb);

                //同一类别项目总计行开累完成
                // odr_sum_gclb_klwc.Read();
            int   m = 3;
            int   i = 1;
                while (m < control_col + 1)
                {
                    objData[row_position, m] = "";// odr_sum_gclb_klwc.GetValue(i).ToString(); //在range中的位置 (1,1)
                    m += 2;
                    i++;
                }


                row_position++;

                //不同项目 列循环

                string odr_gcxm_gclb = "";
                //if(Session["yhjb"].ToString()=="3")
                //    odr_gcxm_gclb = sql_xmmc;
                //  else
                if (dwid == c_yhdw.ToString())
                    odr_gcxm_gclb = sql_xmmc + dwid + sql_xmmc_part2 + " and sgdw =‘" + dwid + "‘ order by id desc";

                else
                    odr_gcxm_gclb = sql_xmmc + dwid + sql_xmmc_part2 + " and sgdw like‘" + dwid + "%‘ order by id desc";

                //odr_gcxm_gclb = sql_xmmc + dwid + sql_xmmc_part2 + " and sgdw =‘" + dwid + "‘ order by id desc";
                OdbcDataReader odr_gcxm = db.getReader(odr_gcxm_gclb);



                //gclb = 3;
                ht = new Hashtable();
                while (odr_gcxm.Read())    //同一单位,不同项目循环
                {
                    int i_sfjs;//标志是改项目数据是否参与总计行的合计。
                    i_sfjs = 0;


                    string s_xmid;
                    s_xmid = odr_gcxm.GetValue(0).ToString();
                    string s_sql_sfyzxm = "select isnull(fgcid,0) from t_gcxm where id=" + s_xmid + " ";
                    OdbcDataReader odr_zxm = db.getReader(s_sql_sfyzxm);
                    if (odr_zxm.Read())
                    {
                        if (odr_zxm[0].ToString() == "0" || dwid == c_yhdw)
                            i_sfjs = 1;

                    }
                    odr_zxm.Close();


                    if (check_is_xmgldw(odr_gcxm.GetValue(0).ToString(), dwid))//检查当前项目是不是项目管理单位,传递项目id和单位id
                    {
                        continue;
                    }
                    //填写项目序号
                    xmxh++;
                    if (c_xmmxf.ToString() == "True")
                    {
                        objData[row_position, 0] = xmxh;


                        objData[row_position, 1] = "" + odr_gcxm.GetValue(1).ToString();   //项目名称
                    }
                    //同一项目列循环的本年完成

                    //存储过程返回的是---年累产值  type=2
                    //
                    string sql_sum_bnwc_gclbtemp = "p_sum_yb_cz_swl_dw  " + odr_gcxm.GetValue(0).ToString() + " , ‘"
                                + c_ybtime.ToString().Trim() + "‘," + c_yhjb
                                + ", 2";          //

                    odr_sum_gclb_bnwc = db.getReader(sql_sum_bnwc_gclbtemp);

                    odr_sum_gclb_bnwc.Read();

                    n = 2;
                    k = 1;

                    while (n < control_col)  //同一项目列循环的本年完成
                    {
                        if (c_xmmxf.ToString() == "True")
                        {
                            objData[row_position, n + 1] = odr_sum_gclb_bnwc.GetValue(k).ToString(); //在range中的位置 (1,1)
                        }
                        decimal d_gclb = 0, d_gcxm = 0, d_zj = 0;
                        if (objData[gclb_row, n + 1].ToString() != "")
                            d_gclb = Convert.ToDecimal((objData[gclb_row, n + 1]));
                        if (objData[zj_row, n + 1].ToString() != "")
                            d_zj = Convert.ToDecimal((objData[zj_row, n + 1]));
                        //if (objData[gnxm_row, n + 1].ToString() != "")
                        //    d_gnxm = Convert.ToDecimal((objData[gnxm_row, n + 1]));
                        if (odr_sum_gclb_bnwc.GetValue(k).ToString() != "")
                            d_gcxm = Convert.ToDecimal(odr_sum_gclb_bnwc.GetValue(k));



                        if (d_gcxm + d_gclb != 0 || d_gcxm != 0)
                            objData[gclb_row, n + 1] = (d_gcxm + d_gclb).ToString();
                        if (d_gcxm + d_zj != 0 && i_sfjs == 1)
                            objData[zj_row, n + 1] = (d_gcxm + d_zj).ToString();
                        // if (d_gcxm + d_gnxm != 0)
                        //     objData[gnxm_row, n + 1] = (d_gcxm + d_gnxm).ToString();
                        n += 3;
                        k++;
                    }
                    odr_sum_gclb_bnwc.Close();
                    //同一项目列循环的   开累完成
                    //存储过程返回的是---开累产值  type=3
                    //
                    string sql_sum_klwc_gclbtemp = "p_sum_yb_cz_swl_dw  " + odr_gcxm.GetValue(0).ToString() + " , ‘"
                                + c_ybtime.ToString().Trim() + "‘," + c_yhjb
                                + ", 3";          //

                    odr_sum_gclb_klwc = db.getReader(sql_sum_klwc_gclbtemp);

                    odr_sum_gclb_klwc.Read();

                    m = 4;
                    i = 1;
                    while (m < control_col + 1)//同一项目列循环的开累完成
                    {
                        if (c_xmmxf.ToString() == "True")
                        {
                            objData[row_position, m] = odr_sum_gclb_klwc.GetValue(i).ToString(); //在range中的位置 (1,1)
                        }
                        /*  d_zj     总计行
                         *  d_gnxm   国内项目或海外项目行 总计值
                         *  d_gclb   工程类别行
                         */

                        decimal d_gclb = 0, d_gcxm = 0, d_zj = 0;

                        if (objData[gclb_row, m].ToString() != "")
                            d_gclb = Convert.ToDecimal((objData[gclb_row, m]));
                        if (objData[zj_row, m].ToString() != "")
                            d_zj = Convert.ToDecimal((objData[zj_row, m]));
                        //if (objData[gnxm_row, m].ToString() != "")
                        //    d_gnxm = Convert.ToDecimal((objData[gnxm_row, m]));
                        if (odr_sum_gclb_klwc.GetValue(i).ToString() != "")
                            d_gcxm = Convert.ToDecimal(odr_sum_gclb_klwc.GetValue(i).ToString());

                        if (d_gcxm + d_gclb != 0 || d_gcxm != 0)
                            objData[gclb_row, m] = (d_gcxm + d_gclb).ToString();
                        if (d_gcxm + d_zj != 0 && i_sfjs == 1)
                            objData[zj_row, m] = (d_gcxm + d_zj).ToString();
                        // if (d_gcxm + d_gnxm != 0)
                        //     objData[gnxm_row, m] = (d_gcxm + d_gnxm).ToString();

                        m += 3;
                        i++;
                    }
                    odr_sum_gclb_klwc.Close();

                    //同一项目列循环的本月完成
                    string sql_sum_bywc_gclbtemp = "p_sum_yb_cz_swl_dw  " + odr_gcxm.GetValue(0).ToString() + " , ‘"
                              + c_ybtime.ToString().Trim() + "‘," + c_yhjb
                              + ", 1";          //

                    OdbcDataReader odr_sum_gclb_bywc = db.getReader(sql_sum_bywc_gclbtemp);

                    odr_sum_gclb_bywc.Read();

                    m = 2;
                    i = 1;
                    while (m < control_col + 1)//同一项目列循环的开累完成
                    {
                        if (c_xmmxf.ToString() == "True")
                        {
                            objData[row_position, m] = odr_sum_gclb_bywc.GetValue(i).ToString(); //在range中的位置 (1,1)
                        }
                        /*  d_zj     总计行
                         *  d_gnxm   国内项目或海外项目行 总计值
                         *  d_gclb   工程类别行
                         */

                        decimal d_gclb = 0, d_gcxm = 0, d_zj = 0;

                        if (objData[gclb_row, m].ToString() != "")
                            d_gclb = Convert.ToDecimal((objData[gclb_row, m]));
                        if (objData[zj_row, m].ToString() != "")
                            d_zj = Convert.ToDecimal((objData[zj_row, m]));
                        // if (objData[gnxm_row, m].ToString() != "")
                        //    d_gnxm = Convert.ToDecimal((objData[gnxm_row, m]));
                        if (odr_sum_gclb_bywc.GetValue(i).ToString() != "")
                            d_gcxm = Convert.ToDecimal(odr_sum_gclb_bywc.GetValue(i).ToString());

                        if (d_gcxm + d_gclb != 0 || d_gcxm != 0)
                            objData[gclb_row, m] = (d_gcxm + d_gclb).ToString();
                        if (d_gcxm + d_zj != 0 && i_sfjs == 1)
                            objData[zj_row, m] = (d_gcxm + d_zj).ToString();
                        // if (d_gcxm + d_gnxm != 0)
                        //     objData[gnxm_row, m] = (d_gcxm + d_gnxm).ToString();

                        m += 3;
                        i++;
                    }
                    odr_sum_gclb_bywc.Close();
                    if (c_xmmxf.ToString() == "True")
                    {
                        row_position = row_position + 1;
                    }




                }  //while (odr_gcxm.Read())    //同一类别,不同项目循环     
                odr_gcxm.Close();
               // rnum = row_position;
                return objData;
               
            }   
          
          
            //设置队列中单元格字体


            //for (int i2 = 0; i2 < rnum; i2++)
            //    for (int j = 0; j < cnum; j++)
            //    {
            //        if (j == 1 || j == 0)
            //            continue;
            //        if (objData[i2, j] != null && objData[i2, j].ToString() != "")
            //            objData[i2, j] = decimal.Parse(objData[i2, j].ToString());
            //    }

            //以下处理房屋施工面积,房屋竣工面积
            //  for (int i2 = 0; i2 < rnum; i2++)
            // {
            //     objData[i2, 75] = objData[i2, 74];
            //     objData[i2, 74] = "";
            //objData[i2, 82] = objData[i2, 80];
            //objData[i2, 81] = objData[i2, 80];
            //objData[i2, 39] = objData[i2, 38];
            // objData[i2, 40] = objData[i2, 38];
            // objData[i2, 39] = Convert.ToDouble(objData[i2, 38].ToString() != "" ? objData[i2, 38].ToString() : "0") - Convert.ToDouble(objData[i2, 43].ToString() != "" ? objData[i2, 43].ToString() : "0") + Convert.ToDouble(objData[i2, 42].ToString() != "" ? objData[i2, 42].ToString() : "0");//房屋设计面积 - 开累竣工面积+本年竣工面积;
            //  if (objData[i2, 39].ToString() == "0")
            //      objData[i2, 39] = "";
            //  objData[i2, 40] = objData[i2, 38];
            //  objData[i2, 38] = "";
            //  }
            //清除3级单位的总计行,三级单位总计计算有误,而且也不需要总计
         
        bool check_is_xmgldw(string xmid, string dwid)
        {
            //if (Session["yhdw"].ToString() != dwid)
            //     return;
            bool flag = false;
            string xmmc = "";
            string fxmid = "";
            string sql1 = "select xmgldw,xmmc,id from T_gcxm where (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and  id=(select fgcid from T_gcxm where (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and id=‘" + xmid + "‘)";
            OdbcDataReader reader = db.getReader(sql1);
            while (reader.Read())
            {
                if (reader.GetValue(0).ToString() == dwid)
                    flag = true;//表明当前项目的父项目的项目管理单位是用户单位
                xmmc = reader.GetValue(1).ToString();
                fxmid = reader.GetValue(2).ToString();
            }

            reader.Close();

            if (flag)
            {
                if (!ht.Contains(fxmid))
                {
                    ht.Add(fxmid, "");
                }
                else
                {
                    return flag;
                }
                if (c_xmmxf.ToString() == "True")
                {
                   // q2.Enqueue(row_position);
                    objData[row_position, 1] = "" + xmmc;
                    gnxm_row = row_position;
                    row_position++;
                }
                string sql = "select id,xmmc from T_gcxm where (xmjd<>‘竣工‘  or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id ) or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and fgcid=(select fgcid from T_gcxm where (xmjd<>‘竣工‘ or exists(select t_xmyb.id from t_xmyb,t_fgcid_xmid where year(ybsj)=" + year + " and t_fgcid_xmid.id=  xmid  and t_fgcid_xmid.fgcid= t_gcxm.id )  or year(jgrq)>=" + c_ybtime.Substring(0, 4) + " and xmjd=‘竣工‘)and id=‘" + xmid + "‘) ";
                reader = db.getReader(sql);
                while (reader.Read())
                {
                    int i_hj;
                    i_hj = 0;
                    if (xmid == reader.GetValue(0).ToString() && dwid == c_yhdw)
                        i_hj = 1;//项目管理单位参与合计
                    fill_zxm(reader.GetValue(0).ToString(), reader.GetValue(1).ToString(), i_hj);
                }
                reader.Close();
            }


            return flag;

        }
        //填充子项目
        void fill_zxm(string xmid, string xmmc, int sfhj)
        {




            //填写项目序号
            xmxh++;
            if (c_xmmxf.ToString() == "True")
            {
                objData[row_position, 0] = xmxh;


                objData[row_position, 1] = "" + xmmc;   //项目名称
            }
            //同一项目列循环的本年完成
            //   string sql_sum_bnwc_gclbtemp = " select sum(byxmzcz),sum(sw_tsf),sum(sw_sdsjcd),sum(sw_qlsjcd),sum(sw_dzq),sum(sw_ljgs),sum(sw_tlzhxpg),sum(sw_gstl),sum(sw_tlzxpg),sum(sw_tlzl),sum(sw_tljl),sum(sw_jxhzd),sum(sw_wzgd),sum(sd_txxl) ,sum(sd_zdbs),sum(sd_dqjz),sum(sd_gdxl),sum(sd_bpds),sum(sd_jcw),sum(sd_qybds),sum(fj_fwjzmj),sum(fj_fjjgmj),sum(sw_dt),sum(sw_dtcz),sum(sw_qg),sum(sw_gl),sum(sw_gl_gs),sum(sw_gl_lm),sum(sw_gljl) " +

            //存储过程返回的是---年累产值  type=2
            //
            string sql_sum_bnwc_gclbtemp = "p_sum_yb_cz_swl_dw  " + xmid + " , ‘"
                        + c_ybtime.ToString().Trim() + "‘," + c_yhjb
                        + ", 2";          //

            OdbcDataReader odr_sum_gclb_bnwc = db.getReader(sql_sum_bnwc_gclbtemp);

            odr_sum_gclb_bnwc.Read();

            int n = 2;
            int k = 1;

            while (n < control_col)  //同一项目列循环的本年完成
            {
                if (c_xmmxf.ToString() == "True")
                {
                    objData[row_position, n + 1] = odr_sum_gclb_bnwc.GetValue(k).ToString(); //在range中的位置 (1,1)
                }
                decimal d_gclb = 0, d_gcxm = 0, d_gnxm = 0, d_zj = 0;
                if (objData[gclb_row, n + 1].ToString() != "")
                    d_gclb = Convert.ToDecimal((objData[gclb_row, n + 1]));
                if (objData[zj_row, n + 1].ToString() != "")
                    d_zj = Convert.ToDecimal((objData[zj_row, n + 1]));
                if (objData[gnxm_row, n + 1].ToString() != "")
                    d_gnxm = Convert.ToDecimal((objData[gnxm_row, n + 1]));
                if (odr_sum_gclb_bnwc.GetValue(k).ToString() != "")
                    d_gcxm = Convert.ToDecimal(odr_sum_gclb_bnwc.GetValue(k).ToString());



                if (d_gcxm + d_gclb != 0 || d_gcxm != 0)
                    objData[gclb_row, n + 1] = (d_gcxm + d_gclb).ToString();
                if ((d_gcxm + d_zj != 0 || d_gcxm != 0) && sfhj == 1)
                    objData[zj_row, n + 1] = (d_gcxm + d_zj).ToString();
                if (d_gcxm + d_gnxm != 0 || d_gcxm != 0)
                    objData[gnxm_row, n + 1] = (d_gcxm + d_gnxm).ToString();
                n += 3;
                k++;
            }
            odr_sum_gclb_bnwc.Close();
            //同一项目列循环的   开累完成
            //存储过程返回的是---开累产值  type=3
            //
            string sql_sum_klwc_gclbtemp = "p_sum_yb_cz_swl_dw  " + xmid + " , ‘"
                        + c_ybtime.ToString().Trim() + "‘," + c_yhjb
                        + ", 3";          //

            OdbcDataReader odr_sum_gclb_klwc = db.getReader(sql_sum_klwc_gclbtemp);

            odr_sum_gclb_klwc.Read();

            int m = 4;
            int i = 1;
            while (m < control_col + 1)//同一项目列循环的开累完成
            {
                if (c_xmmxf.ToString() == "True")
                {
                    objData[row_position, m] = odr_sum_gclb_klwc.GetValue(i).ToString(); //在range中的位置 (1,1)
                }
                /*  d_zj     总计行
                 *
                 */

                decimal d_gclb = 0, d_gcxm = 0, d_gnxm = 0, d_zj = 0;

                if (objData[gclb_row, m].ToString() != "")
                    d_gclb = Convert.ToDecimal((objData[gclb_row, m]));
                if (objData[zj_row, m].ToString() != "")
                    d_zj = Convert.ToDecimal((objData[zj_row, m]));
                if (objData[gnxm_row, m].ToString() != "")
                    d_gnxm = Convert.ToDecimal((objData[gnxm_row, m]));
                if (odr_sum_gclb_klwc.GetValue(i).ToString() != "")
                    d_gcxm = Convert.ToDecimal(odr_sum_gclb_klwc.GetValue(i).ToString());

                if (d_gcxm + d_gclb != 0 || d_gcxm != 0)
                    objData[gclb_row, m] = (d_gcxm + d_gclb).ToString();
                if ((d_gcxm + d_zj != 0 || d_gcxm != 0) && sfhj == 1)
                    objData[zj_row, m] = (d_gcxm + d_zj).ToString();
                if (d_gcxm + d_gnxm != 0 || d_gcxm != 0)
                    objData[gnxm_row, m] = (d_gcxm + d_gnxm).ToString();

                m += 3;
                i++;
            }
            odr_sum_gclb_klwc.Close();


            //同一项目列循环的本月完成
            string sql_sum_bywc_gclbtemp = "p_sum_yb_cz_swl_dw  " + xmid + " , ‘"
                      + c_ybtime.ToString().Trim() + "‘," + c_yhjb
                      + ", 1";          //

            OdbcDataReader odr_sum_gclb_bywc = db.getReader(sql_sum_bywc_gclbtemp);

            odr_sum_gclb_bywc.Read();

            m = 2;
            i = 1;
            while (m < control_col + 1)//同一项目列循环的开累完成
            {
                if (c_xmmxf.ToString() == "True")
                {
                    objData[row_position, m] = odr_sum_gclb_bywc.GetValue(i).ToString(); //在range中的位置 (1,1)
                }
                /*  d_zj     总计行
                 *
                 */

                decimal d_gclb = 0, d_gcxm = 0, d_gnxm = 0, d_zj = 0;

                if (objData[gclb_row, m].ToString() != "")
                    d_gclb = Convert.ToDecimal((objData[gclb_row, m]));
                if (objData[zj_row, m].ToString() != "")
                    d_zj = Convert.ToDecimal((objData[zj_row, m]));
                if (objData[gnxm_row, m].ToString() != "")
                    d_gnxm = Convert.ToDecimal((objData[gnxm_row, m]));
                if (odr_sum_gclb_bywc.GetValue(i).ToString() != "")
                    d_gcxm = Convert.ToDecimal(odr_sum_gclb_bywc.GetValue(i).ToString());

                if (d_gcxm + d_gclb != 0 || d_gcxm != 0)
                    objData[gclb_row, m] = (d_gcxm + d_gclb).ToString();
                if ((d_gcxm + d_zj != 0 || d_gcxm != 0) && sfhj == 1)
                    objData[zj_row, m] = (d_gcxm + d_zj).ToString();
                if (d_gcxm + d_gnxm != 0 || d_gcxm != 0)
                    objData[gnxm_row, m] = (d_gcxm + d_gnxm).ToString();

                m += 3;
                i++;
            }
            odr_sum_gclb_bywc.Close();
            if (c_xmmxf.ToString() == "True")
            {
                row_position = row_position + 1;
            }




        }
      
    }
    }

.NET下的并行开发(案例代码)