Exemplo n.º 1
0
        /// <summary>
        /// 导出重量评估数据到excle
        /// </summary>
        /// <param name="strFileName"></param>
        /// <param name="lstPara"></param>
        public void ExportWeightEstimatedToExcle(string strFileName, WeightAssessResult result)
        {
            Excel.Application app = new Excel.ApplicationClass();
            try
            {
                Object missing = System.Reflection.Missing.Value;
                app.Visible = false;

                Excel.Workbook wBook = app.Workbooks.Add(missing);

                Excel.Worksheet wSheet = wBook.Worksheets[1] as Excel.Worksheet;

                Excel.Range DataCell = wSheet.get_Range("A1", "A1");
                DataCell.Value2                                    = "重量名称";
                DataCell.Next.Value2                               = "基准重量";
                DataCell.Next.Next.Value2                          = "评估重量";
                DataCell.Next.Next.Next.Value2                     = "最小值";
                DataCell.Next.Next.Next.Next.Value2                = "最大值";
                DataCell.Next.Next.Next.Next.Next.Value2           = "权重值";
                DataCell.Next.Next.Next.Next.Next.Next.Value2      = "合理指标";
                DataCell.Next.Next.Next.Next.Next.Next.Next.Value2 = "先进指标";

                List <WeightAssessParameter> lstPara = result.weightAssessParamList;
                for (int i = 0; i < lstPara.Count; ++i)
                {
                    WeightAssessParameter wp = lstPara[i];

                    string cellid = "A" + (i + 2).ToString();
                    DataCell                                           = wSheet.get_Range(cellid, cellid);
                    DataCell.Value2                                    = wp.weightName;
                    DataCell.Next.Value2                               = wp.datumWeight;
                    DataCell.Next.Next.Value2                          = wp.assessWeight;
                    DataCell.Next.Next.Next.Value2                     = wp.minValue;
                    DataCell.Next.Next.Next.Next.Value2                = wp.maxValue;
                    DataCell.Next.Next.Next.Next.Next.Value2           = wp.weightedValue;
                    DataCell.Next.Next.Next.Next.Next.Next.Value2      = wp.rationalityInflation;
                    DataCell.Next.Next.Next.Next.Next.Next.Next.Value2 = wp.advancedInflation;
                }

                //设置禁止弹出保存和覆盖的询问提示框
                app.DisplayAlerts          = false;
                app.AlertBeforeOverwriting = false;
                //保存工作簿
                wBook.SaveAs(strFileName, Excel.XlFileFormat.xlWorkbookNormal, missing, missing, missing, missing, Excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing);
                wBook.Close(false, missing, missing);
                app.Quit();
                app = null;
            }
            catch (Exception err)
            {
                MessageBox.Show("导出Excel出错!错误原因:" + err.Message, "提示信息",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 加载评估参数表格
        /// </summary>
        /// <param name="waList"></param>
        private void loadGridView(List <WeightAssessParameter> waList)
        {
            if (waList == null)
            {
                return;
            }
            this.ConfigurationGridView.Rows.Clear();

            for (int i = 0; i < waList.Count; i++)
            {
                WeightAssessParameter wa = waList[i];

                this.ConfigurationGridView.Rows.Add();
                this.ConfigurationGridView.Rows[i].Cells[0].Value = wa.weightName;
                this.ConfigurationGridView.Rows[i].Cells[1].Value = wa.minValue;
                this.ConfigurationGridView.Rows[i].Cells[2].Value = wa.maxValue;
                this.ConfigurationGridView.Rows[i].Cells[3].Value = wa.weightedValue;
            }
        }
        /// <summary>
        /// 保存基准/评估重量数据
        /// </summary>
        /// <param name="wsd"></param>
        /// <param name="i">1:基准重量;2:评估重量</param>
        public void saveWeightDataGridView(WeightSortData wsd, int i)
        {
            this.weightSortData = wsd;//临时存储,方便数据导出.

            if (!InspectWeightName(wsd.lstWeightData))
            {
                if (i == 1 && this.weightDataGridView.Rows.Count != 0)
                {
                    //对已生成的评估结果上重新导入基准重量
                    if (MessageBox.Show("待导入的基准重量分类名称与已导入表格的名称不匹配,确认是否继续,并清空评估重量及相关参数?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        this.weightDataGridView.Rows.Clear();
                        this.weightAssessResult     = new WeightAssessResult();
                        this.btnPreferences.Enabled = false;
                    }
                    else
                    {
                        return;
                    }
                }
                else if (i == 2)
                {
                    if (MessageBox.Show("待导入的评估重量分类名称与已导入表格的名称不匹配,确认是否继续,并不匹配值以0代替?", "确认", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return;
                    }
                }
            }

            //判断是否首次加载重量数据.(判断重量分类"节点名称"是否加载完成,否则进行加载节点名称.)
            if (weightDataGridView.Rows.Count == 0)
            {
                weightAssessResult.weightAssessParamList = new List <WeightAssessParameter>();
                foreach (WeightData wd in wsd.lstWeightData)
                {
                    if (wd.nParentID == 0 && wd.weightName != null)
                    {
                        int index = this.weightDataGridView.Rows.Add();
                        this.weightDataGridView.Rows[index].Cells[0].Value = wd.weightName;

                        WeightAssessParameter wa = new WeightAssessParameter();
                        this.weightAssessResult.weightAssessParamList.Add(wa);
                        wa.weightName = wd.weightName;
                        wa.minValue   = 0.8; //初始化最小值
                        wa.maxValue   = 1.2; //初始化最大值
                    }
                }
            }

            //加载基准重量数据或评估重量数据
            for (int j = 0; j < this.weightDataGridView.Rows.Count; j++)
            {
                DataGridViewRow row = this.weightDataGridView.Rows[j];
                foreach (WeightData wd in wsd.lstWeightData)
                {
                    if (wd.nParentID == 0 && wd.weightName != null)
                    {
                        if (row.Cells[0].Value.Equals(wd.weightName))
                        {
                            row.Cells[i].Value = Math.Round(wd.weightValue, 6);

                            WeightAssessParameter wa = this.weightAssessResult.weightAssessParamList[j];
                            if (i == 1)
                            {
                                wa.datumWeight = Math.Round(wd.weightValue, 6);

                                //当i==1(赋值基准重量)时,计算初始化权重值.
                                wa.weightedValue = Math.Round(wd.weightValue / weightAssessResult.datumWeightTotal, 6);
                            }
                            else if (i == 2)
                            {
                                wa.assessWeight = Math.Round(wd.weightValue, 6);
                            }
                            break;
                        }
                        else
                        {
                            row.Cells[i].Value = 0;
                        }
                    }
                    else if (wd.nParentID == -1 && i == 1)
                    {
                        //存储基准重量数据对象
                        this.weightAssessResult.datumWeightDataList = wsd.lstWeightData;

                        //计算基准重量总值
                        this.weightAssessResult.datumWeightTotal = Math.Round(wd.weightValue, 6);

                        //开启基准重量导出菜单
                        this.ExportDatumFileMenuItem.Enabled = true;

                        //开启评估重量菜单
                        this.AssessWeightMenuItem.Enabled = true;
                    }
                    else if (wd.nParentID == -1 && i == 2)
                    {
                        //存储评估数据重量对象
                        this.weightAssessResult.assessWeightDataList = wsd.lstWeightData;

                        //计算评估重量总值
                        this.weightAssessResult.assessWeightTotal = Math.Round(wd.weightValue, 6);

                        //开启评估重量导出菜单
                        this.ExprotAssessFileMenuItem.Enabled = true;

                        //开启重量评估参数配置按钮菜单
                        this.btnPreferences.Enabled = true;
                    }
                }
            }
        }
        /// <summary>
        /// 保存基准/评估重量数据
        /// </summary>
        /// <param name="wsd"></param>
        /// <param name="i">1:基准重量;2:评估重量</param>
        public void saveWeightDataGridView(WeightSortData wsd, int i)
        {
            this.weightSortData = wsd;//临时存储,方便数据导出.

            if (i == 1)
            {
                for (int k = 0; k < wsd.lstWeightData.Count; k++)
                {
                    if (wsd.lstWeightData[k].weightValue == 0)
                    {
                        MessageBox.Show("基准数据中不能存在为0的重量值!");
                        return;
                    }
                }
            }

            if (wsd == null)
            {
                return;
            }

            if (!InspectWeightName(wsd.lstWeightData))
            {
                if (i == 1 && this.weightDataGridView.Rows.Count != 0)
                {
                    //对已生成的评估结果上重新导入基准重量
                    if (MessageBox.Show("待导入的基准重量分类名称与已导入表格的名称不匹配,确认是否继续,并清空评估重量及相关参数?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        this.weightDataGridView.Rows.Clear();
                        if (this.weightAssessResult == null)
                        {
                            this.weightAssessResult = new WeightAssessResult();
                        }
                        this.btnPreferences.Enabled = false;
                    }
                    else
                    {
                        return;
                    }
                }
                else if (i == 2)
                {
                    MessageBox.Show("待导入的评估重量不匹配");
                    return;
                }

            }

            //判断是否首次加载重量数据.(判断重量分类"节点名称"是否加载完成,否则进行加载节点名称.)
            if (weightDataGridView.Rows.Count == 0)
            {
                this.weightAssessResult.weightAssessParamList = new List<WeightAssessParameter>();
                foreach (WeightData wd in wsd.lstWeightData)
                {
                    if (wd.nParentID == 0 && wd.weightName != null)
                    {

                        int index = this.weightDataGridView.Rows.Add();
                        this.weightDataGridView.Rows[index].Cells[0].Value = wd.weightName;

                        WeightAssessParameter wa = new WeightAssessParameter();
                        this.weightAssessResult.weightAssessParamList.Add(wa);
                        wa.weightName = wd.weightName;
                        wa.minValue = 0.8;//初始化最小值
                        wa.maxValue = 1.2;//初始化最大值
                    }
                }
            }

            //加载基准重量数据或评估重量数据
            for (int j = 0; j < this.weightDataGridView.Rows.Count; j++)
            {
                DataGridViewRow row = this.weightDataGridView.Rows[j];
                foreach (WeightData wd in wsd.lstWeightData)
                {
                    if (wd.nParentID == 0 && wd.weightName != null)
                    {
                        if (row.Cells[0].Value.Equals(wd.weightName))
                        {
                            row.Cells[i].Value = Math.Round(wd.weightValue, 6);

                            WeightAssessParameter wa = this.weightAssessResult.weightAssessParamList[j];
                            wa.weightUnit = wd.weightUnit;
                            if (i == 1)
                            {
                                wa.datumWeight = Math.Round(wd.weightValue, 6);

                                //当i==1(赋值基准重量)时,计算初始化权重值.
                                wa.weightedValue = Math.Round(wd.weightValue / weightAssessResult.datumWeightTotal, 6);
                            }
                            else if (i == 2)
                            {
                                wa.assessWeight = Math.Round(wd.weightValue, 6);
                            }
                            break;
                        }
                        else
                        {
                            row.Cells[i].Value = 0;
                        }
                    }
                    else if (wd.nParentID == -1 && i == 1)
                    {
                        //存储基准重量数据对象
                        this.weightAssessResult.datumWeightDataList = wsd.lstWeightData;

                        //计算基准重量总值
                        this.weightAssessResult.datumWeightTotal = Math.Round(wd.weightValue, 6);

                        //开启基准重量导出菜单
                        this.ExportDatumFileMenuItem.Enabled = true;

                        //开启评估重量菜单
                        this.AssessWeightMenuItem.Enabled = true;
                    }
                    else if (wd.nParentID == -1 && i == 2)
                    {

                        ////评估数据对象进行排序
                        List<WeightData> temList = new List<WeightData>();
                        foreach (WeightData datumWD in this.weightAssessResult.datumWeightDataList)
                        {
                            for (int k = 0; k < wsd.lstWeightData.Count; k++)
                            {
                                WeightData assessWD = wsd.lstWeightData[k];
                                if (datumWD.weightName == assessWD.weightName && assessWD.nParentID != -1)
                                {
                                    temList.Add(assessWD);
                                    break;
                                }
                                else if (datumWD.nParentID == -1 && assessWD.nParentID == -1)
                                {
                                    temList.Add(assessWD);
                                    break;
                                }
                            }
                        }
                        wsd.lstWeightData = temList;

                        //存储评估数据重量对象
                        this.weightAssessResult.assessWeightDataList = wsd.lstWeightData;

                        //计算评估重量总值
                        this.weightAssessResult.assessWeightTotal = Math.Round(wd.weightValue, 6);

                        //开启评估重量导出菜单
                        this.ExprotAssessFileMenuItem.Enabled = true;

                        //开启重量评估参数配置按钮菜单
                        this.btnPreferences.Enabled = true;
                    }
                }
            }
        }