public WeightAssessmentForm(WeightAssessResult war) { InitializeComponent(); IsEdited = true; this.weightAssessResult = war; this.loadWeightAssessResult(war); }
/// <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); } }
/// <summary> /// 转换重量评估对象为SyswareDataObejct /// </summary> /// <param name="result"></param> /// <returns></returns> private static List <SyswareDataObject> transFormWeightAssessToDataObject(WeightAssessResult result) { List <SyswareDataObject> sdoList = new List <SyswareDataObject>(); foreach (WeightAssessParameter wap in result.weightAssessParamList) { SyswareDataObject sdo = new SyswareDataObject(); sdo.name = wap.weightName; sdo.value = wap.advancedInflation.ToString(); sdo.unit = wap.weightUnit; sdoList.Add(sdo); } return(sdoList); }
/// <summary> /// 加载重量评估结果集 /// </summary> /// <param name="WeightAssessResult"></param> private void loadWeightAssessResult(WeightAssessResult war) { this.resultNameTxt.Text = war.resultName; foreach (WeightAssessParameter wap in war.weightAssessParamList) { int i = this.weightDataGridView.Rows.Add(); this.weightDataGridView.Rows[i].Cells[0].Value = wap.weightName; this.weightDataGridView.Rows[i].Cells[1].Value = wap.datumWeight; this.weightDataGridView.Rows[i].Cells[2].Value = wap.assessWeight; //开启基准重量导出菜单 this.ExportDatumFileMenuItem.Enabled = true; //开启评估重量菜单 this.AssessWeightMenuItem.Enabled = true; //开启评估重量导出菜单 this.ExprotAssessFileMenuItem.Enabled = true; //开启重量评估参数配置按钮菜单 this.btnPreferences.Enabled = true; } }
public static string GetWeightEstimatedDataToString(WeightAssessResult result) { StringBuilder strBuilder = new StringBuilder(); if (result.weightAssessParamList != null && result.weightAssessParamList.Count > 0) { string str = "、"; strBuilder.Append(result.resultName); foreach (WeightAssessParameter para in result.weightAssessParamList) { strBuilder.Append("|"); strBuilder.Append(para.weightName + str); strBuilder.Append(para.datumWeight.ToString() + str); strBuilder.Append(para.assessWeight.ToString() + str); strBuilder.Append(para.minValue.ToString() + str); strBuilder.Append(para.maxValue.ToString() + str); strBuilder.Append(para.weightedValue.ToString() + str); strBuilder.Append(para.rationalityInflation.ToString() + str); strBuilder.Append(para.advancedInflation.ToString()); } } return(strBuilder.ToString()); }
public static string GetWeightEstimatedDataToString(WeightAssessResult result) { StringBuilder strBuilder = new StringBuilder(); if (result.weightAssessParamList != null && result.weightAssessParamList.Count > 0) { string str = "、"; strBuilder.Append(result.resultName); foreach (WeightAssessParameter para in result.weightAssessParamList) { strBuilder.Append("|"); strBuilder.Append(para.weightName + str); strBuilder.Append(para.datumWeight.ToString() + str); strBuilder.Append(para.assessWeight.ToString() + str); strBuilder.Append(para.minValue.ToString() + str); strBuilder.Append(para.maxValue.ToString() + str); strBuilder.Append(para.weightedValue.ToString() + str); strBuilder.Append(para.rationalityInflation.ToString() + str); strBuilder.Append(para.advancedInflation.ToString()); } } return strBuilder.ToString(); }
/// <summary> /// 显示柱状图 /// </summary> /// <param name="chart1"></param> /// <param name="result"></param> public static void DisplayColumnInPic(System.Windows.Forms.DataVisualization.Charting.Chart chart1, WeightAssessResult result) { chart1.Titles.Clear(); chart1.Series.Clear(); chart1.ChartAreas.Clear(); chart1.Legends.Clear(); if (result.datumWeightDataList.Count > 0 && result.assessWeightDataList.Count > 0) { //标题 Title title1 = new Title(); title1.Text = "重量对比"; title1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold); chart1.Titles.Add(title1); AddChartSeries(chart1, result.datumWeightDataList, "基准重量", Color.Blue); AddChartSeries(chart1, result.assessWeightDataList, "评估重量", Color.Red); if (chart1.ChartAreas.Count > 0) { chart1.ChartAreas[0].AxisX.IsLabelAutoFit = true; chart1.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微软雅黑", 9); //X坐标显示不全 chart1.ChartAreas[0].AxisX.Interval = 1; chart1.ChartAreas[0].AxisX.IntervalOffset = 1; chart1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = false; //放大缩小 chart1.ChartAreas[0].CursorX.Interval = 0.001D; chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; chart1.ChartAreas[0].CursorY.Interval = 0.001D; chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; } } }
/// <summary> /// 导出重量评估数据到xml /// </summary> /// <param name="strFileName"></param> /// <param name="lstPara"></param> public void ExportWeightEstimatedToXml(string strFileName, WeightAssessResult result) { if (result.weightAssessParamList != null && result.weightAssessParamList.Count > 0) { XmlDocument xmldoc = new XmlDocument(); XmlTextWriter writeXml = null; try { writeXml = new XmlTextWriter(strFileName, Encoding.GetEncoding("gb2312")); } catch { MessageBox.Show("创建或写入文件失败!"); return; } writeXml.Formatting = Formatting.Indented; writeXml.Indentation = 5; writeXml.WriteStartDocument(); writeXml.WriteStartElement("重量评估"); writeXml.WriteStartElement("重量评估参数列表"); foreach (WeightAssessParameter para in result.weightAssessParamList) { writeXml.WriteStartElement("重量评估参数"); { writeXml.WriteStartElement("重量名称"); writeXml.WriteString(para.weightName); writeXml.WriteEndElement(); writeXml.WriteStartElement("基准重量"); writeXml.WriteString(para.datumWeight.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("评估重量"); writeXml.WriteString(para.assessWeight.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("重量单位"); writeXml.WriteString(para.weightUnit); writeXml.WriteEndElement(); writeXml.WriteStartElement("最小值"); writeXml.WriteString(para.minValue.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("最大值"); writeXml.WriteString(para.maxValue.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("权重值"); writeXml.WriteString(para.weightedValue.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("合理指标"); writeXml.WriteString(para.rationalityInflation.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("先进指标"); writeXml.WriteString(para.advancedInflation.ToString()); writeXml.WriteEndElement(); } writeXml.WriteEndElement(); } writeXml.WriteEndElement(); writeXml.WriteEndElement(); writeXml.WriteEndDocument(); writeXml.Close(); } }
/// <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); } }
/// <summary> /// 导出重量调整结果为对应的SyswareDataObject.xml /// </summary> /// <param name="result"></param> /// <param name="isAddChildren"></param> /// <returns></returns> public static string saveWeightAssessDataObjectToXml(WeightAssessResult result, bool isAddChildren) { string path = null; try { SyswareDataObject sdo = new SyswareDataObject(); SyswareDataObject subSdo = new SyswareDataObject(); subSdo.id = result.resultID; subSdo.name = result.resultName; //subSdo.children = new List<SyswareDataObject>(); //基准重量 SyswareDataObject basicSdo = new SyswareDataObject(); basicSdo.name = "基准重量"; basicSdo.value = Math.Round(result.datumWeightTotal, 6).ToString(); basicSdo.unit = "Kilogram"; basicSdo.children = transFormWeightArithmeticToDataObject(-1, result.datumWeightDataList); subSdo.children.Add(basicSdo); //评估重量 SyswareDataObject assessSdo = new SyswareDataObject(); assessSdo.name = "评估重量"; assessSdo.value = Math.Round(result.assessWeightTotal, 6).ToString(); assessSdo.unit = "Kilogram"; assessSdo.children = transFormWeightArithmeticToDataObject(-1, result.assessWeightDataList); subSdo.children.Add(assessSdo); //先进性评估 SyswareDataObject advancedSdo = new SyswareDataObject(); advancedSdo.name = "先进性评估"; advancedSdo.value = result.advancedInflationTotal.ToString(); advancedSdo.children = transFormWeightAssessToDataObject(result); subSdo.children.Add(advancedSdo); //合理性评估 SyswareDataObject rationalitySdo = new SyswareDataObject(); rationalitySdo.name = "合理性评估"; rationalitySdo.value = result.rationalityInflationTotal.ToString(); rationalitySdo.children = transFormWeightAssessToDataObject(result); subSdo.children.Add(rationalitySdo); if (isAddChildren) { sdo = subSdo; } else { sdo.name = "重量评估结果"; sdo.children.Add(subSdo); } XmlDocument myXmlDoc = saveSyswareDataObjectToXML(null, null, sdo); path = System.IO.Path.GetTempPath() + System.IO.Path.GetRandomFileName() + ".xml"; //将xml文件保存到临时路径下 myXmlDoc.Save(path); } catch { //XLog.Write("无法保存重量评估XML." + e.Message); return(null); } return(path); }
/// <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; } } } }
/// <summary> /// 导出重量评估数据到xml /// </summary> /// <param name="strFileName"></param> /// <param name="lstPara"></param> public void ExportWeightEstimatedToXml(string strFileName, WeightAssessResult result) { if (result.weightAssessParamList != null && result.weightAssessParamList.Count > 0) { XmlDocument xmldoc = new XmlDocument(); XmlTextWriter writeXml = null; try { writeXml = new XmlTextWriter(strFileName, Encoding.GetEncoding("gb2312")); } catch { MessageBox.Show("创建或写入文件失败!"); return; } writeXml.Formatting = Formatting.Indented; writeXml.Indentation = 5; writeXml.WriteStartDocument(); writeXml.WriteStartElement("重量评估"); writeXml.WriteStartElement("重量评估参数列表"); foreach (WeightAssessParameter para in result.weightAssessParamList) { writeXml.WriteStartElement("重量评估参数"); { writeXml.WriteStartElement("重量名称"); writeXml.WriteString(para.weightName); writeXml.WriteEndElement(); writeXml.WriteStartElement("基准重量"); writeXml.WriteString(para.datumWeight.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("评估重量"); writeXml.WriteString(para.assessWeight.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("最小值"); writeXml.WriteString(para.minValue.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("最大值"); writeXml.WriteString(para.maxValue.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("权重值"); writeXml.WriteString(para.weightedValue.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("合理指标"); writeXml.WriteString(para.rationalityInflation.ToString()); writeXml.WriteEndElement(); writeXml.WriteStartElement("先进指标"); writeXml.WriteString(para.advancedInflation.ToString()); writeXml.WriteEndElement(); } writeXml.WriteEndElement(); } writeXml.WriteEndElement(); writeXml.WriteEndElement(); writeXml.WriteEndDocument(); writeXml.Close(); } }