Beispiel #1
0
        /// <summary>
        /// 填充表格信息
        /// </summary>
        /// <param name="m_Sheet"></param>
        /// <param name="startrow"></param>
        public static void FillTableData(Excel._Worksheet m_Sheet, DataInterface dataInterfaceExcel, int startrow, bool IsQaulity, bool IsSize)
        {
            try
            {
                //客户信息
                #region
                m_Sheet.Cells[4, 2] = dataInterfaceExcel.CustomerName;                                               //客户名称
                m_Sheet.Cells[4, 5] = dataInterfaceExcel.FarmName;                                                   //农场名称
                m_Sheet.Cells[4, 8] = dataInterfaceExcel.FruitName;                                                  //水果品种
                m_Sheet.Cells[5, 2] = dataInterfaceExcel.IoStStatistics.nTotalCount;                                 //个数汇总
                m_Sheet.Cells[5, 5] = ((double)dataInterfaceExcel.IoStStatistics.nWeightCount / 1000000).ToString(); //重量汇总  //Modify by ChengSk - 20180305
                int sumBoxNum = FunctionInterface.GetSumValue(dataInterfaceExcel.IoStStatistics.nBoxGradeCount);     //总箱数
                m_Sheet.Cells[5, 8] = sumBoxNum;                                                                     //箱数汇总
                //平均果重
                if (dataInterfaceExcel.IoStStatistics.nTotalCount == 0)
                {
                    m_Sheet.Cells[6, 2] = 0.000;
                }
                else
                {
                    m_Sheet.Cells[6, 2] = ((double)dataInterfaceExcel.IoStStatistics.nWeightCount / dataInterfaceExcel.IoStStatistics.nTotalCount).ToString("0.000");
                }
                m_Sheet.Cells[6, 5] = dataInterfaceExcel.ProgramName; //分选程序
                m_Sheet.Cells[6, 8] = GlobalDataInterface.SerialNum;  //序列号 //add by xcw 20200701

                //开始时间
                Excel.Range range = m_Sheet.Range[m_Sheet.Cells[7, 2], m_Sheet.Cells[7, 3]]; //取得单元格范围
                range.MergeCells = true;                                                     //合并单元格
                range.Value2     = dataInterfaceExcel.StartTime;
                //结束时间
                range            = m_Sheet.Range[m_Sheet.Cells[7, 5], m_Sheet.Cells[7, 6]]; //取得单元格范围
                range.MergeCells = true;                                                    //合并单元格
                range.Value2     = dataInterfaceExcel.EndTime;
                #endregion

                //等级信息
                #region
                int    startrowex;//等级个数
                UInt64 uSumValue, uSumWeightValue;
                int    uSumBoxValue;
                //if(IsSize)
                uSumValue = FunctionInterface.GetSumValue(dataInterfaceExcel.IoStStatistics.nGradeCount);             //获取总个数
                //else
                uSumWeightValue = FunctionInterface.GetSumValue(dataInterfaceExcel.IoStStatistics.nWeightGradeCount); //获取总重量
                uSumBoxValue    = FunctionInterface.GetSumValue(dataInterfaceExcel.IoStStatistics.nBoxGradeCount);    //获取总箱数
                if (!IsQaulity)
                {
                    startrowex = dataInterfaceExcel.WeightOrSizeGradeSum;
                    for (int j = 0; j < dataInterfaceExcel.WeightOrSizeGradeSum; j++)
                    {
                        if (dataInterfaceExcel.QualityGradeSum == 0)
                        {
                            m_Sheet.Cells[j + startrow, 1] = Encoding.Default.GetString(dataInterfaceExcel.IoStStGradeInfo.strSizeGradeName,
                                                                                        j * ConstPreDefine.MAX_TEXT_LENGTH, ConstPreDefine.MAX_TEXT_LENGTH); //等级名称
                            m_Sheet.Cells[j + startrow, 2] = dataInterfaceExcel.IoStStGradeInfo.grades[j].nMinSize.ToString();                               //尺寸/重量
                            m_Sheet.Cells[j + startrow, 3] = dataInterfaceExcel.IoStStatistics.nGradeCount[j].ToString();                                    //等级个数
                                                                                                                                                             //个数百分比
                            if (uSumValue == 0)
                            {
                                m_Sheet.Cells[j + startrow, 4] = "0.00%";
                            }
                            else
                            {
                                m_Sheet.Cells[j + startrow, 4] = ((double)dataInterfaceExcel.IoStStatistics.nGradeCount[j] / uSumValue).ToString("0.00%");
                            }
                            m_Sheet.Cells[j + startrow, 5] = (dataInterfaceExcel.IoStStatistics.nWeightGradeCount[j] / 1000.0).ToString("#0.0"); //等级重量
                                                                                                                                                 //重量百分比
                            if (uSumWeightValue == 0)
                            {
                                m_Sheet.Cells[j + startrow, 6] = "0.00%";
                            }
                            else
                            {
                                m_Sheet.Cells[j + startrow, 6] = ((double)dataInterfaceExcel.IoStStatistics.nWeightGradeCount[j] / uSumWeightValue).ToString("0.00%");
                            }
                            m_Sheet.Cells[j + startrow, 7] = dataInterfaceExcel.IoStStatistics.nBoxGradeCount[j].ToString(); //箱数
                                                                                                                             //箱数百分比
                            if (uSumWeightValue == 0)
                            {
                                m_Sheet.Cells[j + startrow, 8] = "0.00%";
                            }
                            else
                            {
                                m_Sheet.Cells[j + startrow, 8] = ((double)dataInterfaceExcel.IoStStatistics.nBoxGradeCount[j] / uSumBoxValue).ToString("0.00%");
                            }
                        }
                        else
                        {
                            ulong  GradeCount  = 0;//add by xcw 20201104
                            double CountPer    = 0.0;
                            double GradeWeight = 0.0;
                            double WeightPer   = 0.0;
                            int    BoxSumValue = 0;
                            double BoxSumPer   = 0.0;
                            for (int i = 0; i < dataInterfaceExcel.QualityGradeSum; i++)
                            {
                                GradeCount += dataInterfaceExcel.IoStStatistics.nGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j];
                                if (uSumValue != 0)
                                {
                                    CountPer += ((double)dataInterfaceExcel.IoStStatistics.nGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j] / uSumValue);
                                }
                                GradeWeight += (dataInterfaceExcel.IoStStatistics.nWeightGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j] / 1000.0);
                                if (uSumWeightValue != 0)
                                {
                                    WeightPer += ((double)dataInterfaceExcel.IoStStatistics.nWeightGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j] / uSumWeightValue);
                                }
                                BoxSumValue += dataInterfaceExcel.IoStStatistics.nBoxGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j];

                                if (uSumBoxValue != 0)
                                {
                                    BoxSumPer += ((double)dataInterfaceExcel.IoStStatistics.nBoxGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j] / uSumBoxValue);
                                }
                            }
                            m_Sheet.Cells[j + startrow, 1] = Encoding.Default.GetString(dataInterfaceExcel.IoStStGradeInfo.strSizeGradeName,
                                                                                        j * ConstPreDefine.MAX_TEXT_LENGTH, ConstPreDefine.MAX_TEXT_LENGTH); //等级名称
                            m_Sheet.Cells[j + startrow, 2] = dataInterfaceExcel.IoStStGradeInfo.grades[j].nMinSize.ToString();                               //尺寸/重量
                            m_Sheet.Cells[j + startrow, 3] = GradeCount.ToString();                                                                          //等级个数
                                                                                                                                                             //个数百分比
                            m_Sheet.Cells[j + startrow, 4] = CountPer.ToString("0.00%");
                            m_Sheet.Cells[j + startrow, 5] = GradeWeight.ToString("#0.0");                                                                   //等级重量
                                                                                                                                                             //重量百分比  j
                            m_Sheet.Cells[j + startrow, 6] = WeightPer.ToString("0.00%");
                            m_Sheet.Cells[j + startrow, 7] = BoxSumValue.ToString();                                                                         //箱数
                                                                                                                                                             //箱数百分比
                            m_Sheet.Cells[j + startrow, 8] = BoxSumPer.ToString("0.00%");
                            //m_Sheet.Cells[j + startrow, 8] =((double)BoxSumValue/ uSumBoxValue).ToString("0.00%");
                        }
                    }
                }
                else
                {
                    string strSizeName;
                    string strQualityName;
                    string strMixName;
                    int    qualSum = 1;
                    if (dataInterfaceExcel.QualityGradeSum > qualSum)
                    {
                        qualSum = dataInterfaceExcel.QualityGradeSum;
                    }
                    int sizeSum = 1;
                    if (dataInterfaceExcel.WeightOrSizeGradeSum > sizeSum)
                    {
                        sizeSum = dataInterfaceExcel.WeightOrSizeGradeSum;
                    }
                    startrowex = qualSum * sizeSum;
                    for (int i = 0; i < qualSum; i++)
                    {
                        for (int j = 0; j < sizeSum; j++)
                        {
                            strSizeName    = Encoding.Default.GetString(dataInterfaceExcel.IoStStGradeInfo.strSizeGradeName, j * ConstPreDefine.MAX_TEXT_LENGTH, ConstPreDefine.MAX_TEXT_LENGTH);
                            strQualityName = Encoding.Default.GetString(dataInterfaceExcel.IoStStGradeInfo.strQualityGradeName, i * ConstPreDefine.MAX_TEXT_LENGTH, ConstPreDefine.MAX_TEXT_LENGTH);
                            int QualityGradeNameLength = strQualityName.IndexOf("\0");  //add by xcw 20201102
                            if (QualityGradeNameLength == -1)
                            {
                                QualityGradeNameLength = strQualityName.Length;
                            }
                            strMixName = strSizeName.Substring(0, strSizeName.IndexOf("\0")) + "." + strQualityName.Substring(0, QualityGradeNameLength);
                            m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 1] = strMixName;                                                                                               //等级名称
                            m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 2] = dataInterfaceExcel.IoStStGradeInfo.grades[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j].nMinSize.ToString(); //尺寸/重量
                            m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 3] = dataInterfaceExcel.IoStStatistics.nGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j].ToString();      //等级个数
                            //个数百分比
                            if (uSumValue == 0)
                            {
                                m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 4] = "0.00%";
                            }
                            else
                            {
                                m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 4] = ((double)dataInterfaceExcel.IoStStatistics.nGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j] / uSumValue).ToString("0.00%");
                            }

                            m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 5] = (dataInterfaceExcel.IoStStatistics.nWeightGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j] / 1000.0).ToString("#0.0").ToString();//等级重量
                            //重量百分比
                            if (uSumWeightValue == 0)
                            {
                                m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 6] = "0.00%";
                            }
                            else
                            {
                                m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 6] = ((double)dataInterfaceExcel.IoStStatistics.nWeightGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j] / uSumWeightValue).ToString("0.00%");
                            }
                            m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 7] = dataInterfaceExcel.IoStStatistics.nBoxGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j].ToString();//箱数
                            //箱数百分比
                            if (uSumBoxValue == 0)
                            {
                                m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 8] = "0.00%";
                            }
                            else
                            {
                                m_Sheet.Cells[i * dataInterfaceExcel.WeightOrSizeGradeSum + j + startrow, 8] = ((double)dataInterfaceExcel.IoStStatistics.nBoxGradeCount[i * ConstPreDefine.MAX_SIZE_GRADE_NUM + j] / uSumBoxValue).ToString("0.00%");
                            }
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                Trace.WriteLine("ExcelReportFunc中函数备份设置FillTableData出错" + ex);
#if REALEASE
                GlobalDataInterface.WriteErrorInfo("ExcelReportFunc中函数备份设置FillTableData出错" + ex);
#endif
            }
        }