Beispiel #1
0
        //列表
        private static DataTable CreateView_T(string _selCol, string _strTestNo, int ab)
        {
            BLL.TestSample bllts = new HR_Test.BLL.TestSample();
            DataSet        dst   = bllts.GetFinishList1(_selCol, " testNo = '" + _strTestNo + "' and isFinish=true ", ab);

            return(dst.Tables[0]);
        }
Beispiel #2
0
        public static DataTable CreateAverageViewReport(StringBuilder _selSqlAver, StringBuilder _strSelcol, string _arrTestSample, int ab)
        {
            BLL.TestSample bllts = new HR_Test.BLL.TestSample();
            //求平均
            DataSet dsaver = bllts.GetFinishSumList1(_selSqlAver.ToString(), " testSampleNo in ('" + _arrTestSample + ") and isFinish=true ");

            //获取选择试样的数量和试样编号
            string selCol = _strSelcol.ToString();

            selCol = selCol.Substring(0, selCol.LastIndexOf(','));

            DataSet dsfinish = bllts.GetFinishList1(selCol, " testSampleNo in ('" + _arrTestSample + ") and isFinish=true ", ab);

            int fcount = dsfinish.Tables[0].Rows.Count;

            //变异系数 = sd/mean
            StringBuilder strCV = new StringBuilder();

            //中间值
            StringBuilder strMid = new StringBuilder();


            //创建新的数据计算结果表
            DataSet dsaverto = new DataSet();

            dsaverto.Tables.Add();
            dsaverto.Tables[0].Columns.Add("数量(" + fcount + ")").SetOrdinal(0);
            for (int i = 0; i < dsaver.Tables[0].Columns.Count; i++)
            {
                dsaverto.Tables[0].Columns.Add(dsaver.Tables[0].Columns[i].Caption).SetOrdinal(i + 1);
            }
            //给新数据表添加平均值列
            List <object> objmean = new List <object>();

            objmean.Add("Mean.:");
            for (int i = 0; i < dsaver.Tables[0].Columns.Count; i++)
            {
                if (double.Parse(dsaver.Tables[0].Rows[0][i].ToString()) != 0)
                {
                    objmean.Add(dsaver.Tables[0].Rows[0][i].ToString());
                }
                else
                {
                    objmean.Add("-");
                }
            }
            dsaverto.Tables[0].Rows.Add(objmean.ToArray());
            double sumsd = 0;
            double sd    = 0;
            double cv    = 0;
            double ctrue = 0;
            double caver = 0;
            double temp  = 1000000;
            double mid   = 0;

            List <object> objsd = new List <object>();

            objsd.Add("S.D.:");
            List <object> objcv = new List <object>();

            objcv.Add("C.V.:");
            List <object> objmid = new List <object>();

            objmid.Add("Mid.:");


            //计算标准偏差
            for (int i = 0; i < dsaver.Tables[0].Columns.Count; i++)
            {
                for (int j = 0; j < dsfinish.Tables[0].Rows.Count; j++)
                {
                    //  求和 (真实值-平均值)^2
                    if (ab == 2)
                    {
                        ctrue = Convert.ToDouble(dsfinish.Tables[0].Rows[j][i + 4].ToString());
                        caver = Convert.ToDouble(dsaver.Tables[0].Rows[0][i].ToString());
                    }
                    else
                    {
                        ctrue = Convert.ToDouble(dsfinish.Tables[0].Rows[j][i + 5].ToString());
                        caver = Convert.ToDouble(dsaver.Tables[0].Rows[0][i].ToString());
                    }
                    double c1 = (ctrue - caver) * (ctrue - caver);
                    sumsd += c1;
                    //查找中间值,最接近平均值的
                    double d_value = Math.Abs(ctrue - caver);
                    if (d_value < temp)
                    {
                        temp = d_value;
                        mid  = ctrue;
                    }
                }
                if (fcount - 1 != 0)
                {
                    sd = Math.Sqrt(sumsd / (fcount - 1));
                }
                else
                {
                    sd = 0;
                }

                //变异系数 =( 标准偏差 / 平均值 ) *100
                if (caver != 0)
                {
                    cv = (sd / caver) * 100;
                }
                else
                {
                    cv = 0;
                }

                if (sd != 0)
                {
                    objsd.Add(sd.ToString("f4"));
                }
                else
                {
                    objsd.Add("-");
                }
                if (cv != 0)
                {
                    objcv.Add(cv.ToString("f4"));
                }
                else
                {
                    objcv.Add("-");
                }
                if (mid != 0)
                {
                    objmid.Add(mid.ToString("f4"));
                }
                else
                {
                    objmid.Add("-");
                }


                temp  = 1000000;
                sumsd = 0;
            }
            //S.D.标准偏差行
            if (_isSelSD)
            {
                dsaverto.Tables[0].Rows.Add(objsd.ToArray());
            }
            //变异系数行
            if (_isSelCV)
            {
                dsaverto.Tables[0].Rows.Add(objcv.ToArray());
            }
            //中间值行
            if (_isSelMid)
            {
                dsaverto.Tables[0].Rows.Add(objmid.ToArray());
            }

            dsfinish.Dispose();
            return(dsaverto.Tables[0]);
        }