private void coreAssesslistView_ItemChecked(object sender, ItemCheckedEventArgs e) { CorePointExt cpe = this.assessCoreDatas.Find(item => item.pointName == e.Item.Name); if (e.Item.Checked) { cpe.weightedValue = cpe.isAssess?cpe.weightedValue:1; cpe.isAssess = true; this.assessSum += cpe.weightedValue; int i = this.weightedGridView.Rows.Add(); this.weightedGridView.Rows[i].Cells[0].Value = cpe.pointName; this.weightedGridView.Rows[i].Cells[1].Value = cpe.weightedValue; } else { foreach (DataGridViewRow row in this.weightedGridView.Rows) { if (row.Cells[0].Value.ToString() == e.Item.Name) { this.assessSum -= cpe.weightedValue; cpe.isAssess = false; cpe.weightedValue = 0; this.weightedGridView.Rows.Remove(row); return; } } } }
private void btnConfirm_Click(object sender, EventArgs e) { TreeNode node = this.WDMTree.SelectedNode; if (node == null||node.Level!=1) { MessageBox.Show("请选择机型"); return; } WDMIntegrationModule.Air air = airs[Convert.ToInt32(node.Tag)]; WDMIntegrationModule.TStmc[] tstmcs = WDMIntegrationModule.GetStmcs(node.Name); //Random r = new Random(); List <CorePointExt> cpdList=new List<CorePointExt>(); //List<WeightData> lstWeightData = new List<WeightData>(); //CorePointExt parentWD = new CorePointExt(); //parentWD.pointName = air.MC; //parentWD. = 0; //parentWD.nParentID = -1; //lstWeightData.Add(parentWD); //int i = r.Next(10); //double weightValueSum = 0; foreach (WDMIntegrationModule.TStmc tstmc in tstmcs) { if (node.Name == air.ID) { CorePointExt cpe = new CorePointExt(); // gridView.Rows[i].Cells[0].Value = cpe.pointName; //gridView.Rows[i].Cells[1].Value = Math.Round(cpe.pointXValue, 6); //gridView.Rows[i].Cells[2].Value = Math.Round(cpe.pointYValue, 6); //WeightData wd = new WeightData(); cpe.pointName = tstmc.MC; cpe.pointYValue = tstmc.ZTW; cpe.pointXValue =(this.actualDataRadio.Checked?tstmc.XCG:tstmc.YCG)*1000; //wd.nID = r.Next(10);// Convert.ToInt32(toper.ID); //wd.weightValue = this.actualDataRadio.Checked ? // (tstmc.SCW == 0 && this.useTestData.Checked ? // tstmc.ZTW : tstmc.SCW) : tstmc.ZTW; //wd.nParentID = 0; // 添加重量数据至重量数据列表 cpdList.Add(cpe); // weightValueSum += wd.weightValue; } } //parentWD.weightValue = weightValueSum; ((CoreEnvelopeAssessForm)this.Owner).saveCoreGridView(cpdList, "1"); this.Close(); }
public void ExportCoreEstimatedToExcle(string strFileName, CoreAssessResult 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 <CorePointExt> lstCorePoint = result.assessCoreDataList; for (int i = 0; i < lstCorePoint.Count; ++i) { CorePointExt core = lstCorePoint[i]; string cellid = "A" + (i + 2).ToString(); DataCell = wSheet.get_Range(cellid, cellid); DataCell.Value2 = core.pointName; DataCell.Next.Value2 = "毫米"; DataCell.Next.Next.Value2 = "千克"; DataCell.Next.Next.Next.Value2 = core.pointXValue; DataCell.Next.Next.Next.Next.Value2 = core.pointYValue; DataCell.Next.Next.Next.Next.Next.Value2 = core.isAssess; DataCell.Next.Next.Next.Next.Next.Next.Value2 = core.weightedValue; DataCell.Next.Next.Next.Next.Next.Next.Next.Value2 = core.assessValue; } //设置禁止弹出保存和覆盖的询问提示框 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); } }
public static CorePointExt corePointDataToCorePoinExt(CorePointData cpd) { CorePointExt cpe = new CorePointExt(); var cpdType = typeof(CorePointData); foreach (var propertie in cpdType.GetProperties()) { propertie.SetValue(cpe, propertie.GetValue(cpd, null), null); } return(cpe); }
/// <summary> /// 读取XML文件转换成List<CorePointExt>类型 /// </summary> /// <param name="strFilePath">文件路径</param> /// <returns>CorePointData集合类型</returns> public static List <CorePointExt> LoadXmlToPointList(string strFilePath) { List <CorePointExt> lstCorePointExt = null; try { if (!File.Exists(strFilePath)) { return(lstCorePointExt); } string path = string.Empty; XmlNode node = null; XmlDocument doc = new XmlDocument(); doc.Load(strFilePath); //重量列表 path = "重心数据/重心坐标列表"; node = doc.SelectSingleNode(path); XmlNodeList nodeList = node.ChildNodes; if (nodeList.Count > 0) { lstCorePointExt = new List <CorePointExt>(); foreach (XmlNode childNode in nodeList) { CorePointExt pt = new CorePointExt(); pt.pointName = childNode.ChildNodes[0].InnerText; pt.pointXValue = Convert.ToDouble(childNode.ChildNodes[3].InnerText); pt.pointYValue = Convert.ToDouble(childNode.ChildNodes[4].InnerText); if (childNode.ChildNodes.Count > 5) { pt.isAssess = Convert.ToBoolean(childNode.ChildNodes[5].InnerText); } lstCorePointExt.Add(pt); } } } catch { XCommon.XLog.Write("导入原始重心包线数据格式错误"); MessageBox.Show("导入原始重心包线数据格式错误!"); return(null); } return(lstCorePointExt); }
public static bool ImportExcelToPointList(List <CorePointExt> ptlst, string strfilename) { ptlst.Clear(); Excel.Application app = new Excel.ApplicationClass(); try { Object missing = System.Reflection.Missing.Value; app.Visible = false; Excel.Workbook wBook = app.Workbooks.Open(strfilename, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); Excel.Worksheet wSheet = wBook.Worksheets[1] as Excel.Worksheet; if (wSheet.Rows.Count > 1) { for (int i = 2; i <= wSheet.Rows.Count; ++i) { string cellid = "A" + i.ToString(); Excel.Range DataCell = wSheet.get_Range(cellid, cellid); string ParaName = (string)DataCell.Text; DataCell = DataCell.Next.Next.Next; if ((string)DataCell.Text == "") { break; } ParaName = ParaName.Trim(); CorePointExt node = new CorePointExt(); node.pointName = ParaName; node.pointXValue = (double)DataCell.Value2; node.pointYValue = (double)DataCell.Next.Value2; node.isAssess = Convert.ToBoolean(DataCell.Next.Next.Value2); ptlst.Add(node); } } app.Quit(); app = null; XCommon.XLog.Write("成功从文件\"" + strfilename + "\"导入数据!"); } catch (Exception err) { MessageBox.Show("导入Excel出错!错误原因:" + err.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(true); }
private void weightedGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { double NewVal = 0; if (e.ColumnIndex == 1) { if (!double.TryParse(e.FormattedValue.ToString(), out NewVal) || NewVal < 0 || NewVal > 1) { e.Cancel = true; MessageBox.Show("只能输入大于0小于1的数字"); return; } else { string pointName = this.weightedGridView.Rows[e.RowIndex].Cells[0].Value.ToString(); CorePointExt cpe = this.assessCoreDatas.Find(item => item.pointName == pointName); this.assessSum -= (cpe.weightedValue - Convert.ToDouble(e.FormattedValue)); cpe.weightedValue = Convert.ToDouble(e.FormattedValue); } } }
private void btnConfirm_Click(object sender, EventArgs e) { if (this.treeCoreEnvelope.SelectedNode == null) { MessageBox.Show("请选择结点"); return; } CoreEnvelopeAssessForm parentForm=((CoreEnvelopeAssessForm)this.Owner); TreeNode selNode = this.treeCoreEnvelope.SelectedNode; if (flag == 0) { //从重心设计中加载数据 for (int i = 0; i < lstCoreEnvelopeDesign.Count; i++) { if (selNode.ToolTipText == i.ToString()) { List<CorePointExt> cpeList = new List<CorePointExt>(); foreach (NodeFormula nf in lstCoreEnvelopeDesign[i].FormulaList) { CorePointExt cpe = new CorePointExt(); cpe.pointName = nf.NodeName; cpe.pointXValue = nf.XFormula.Value; cpe.pointYValue = nf.YFormula.Value; cpe.isAssess = false; cpeList.Add(cpe); } parentForm.saveCoreGridView(cpeList, "0"); break; } } } else if (flag == 1) { //从重心裁剪中加载数据 for (int i = 0; i < lstCutResultData.Count; i++) { if (selNode.ToolTipText == i.ToString()) { List<CorePointExt> cpeList = new List<CorePointExt>(); foreach (CorePointData cpd in lstCutResultData[i].lstCutEnvelopeCore) { cpeList.Add(CommonUtil.corePointDataToCorePoinExt(cpd)); } parentForm.saveCoreGridView(cpeList, "0"); break; } } } else if (flag == 2) { //从重心数据库中加载数据 foreach (XCommon.CoreEnvelopeDesign core in this.lstCoreEnvelope) { if (core.Id.ToString() == selNode.Name) { List<CorePointExt> cpeList=new List<CorePointExt>(); List<CorePointData> list=CoreEnvelopeDesign.GetStringToListCorePointData(core.CoreEnvelope); foreach (CorePointData cpd in list) { cpeList.Add(CommonUtil.corePointDataToCorePoinExt(cpd)); } parentForm.saveCoreGridView(cpeList, "0"); break; } } } this.Close(); }
private void btnConfirm_Click(object sender, EventArgs e) { if (this.treeCoreEnvelope.SelectedNode == null) { MessageBox.Show("请选择结点"); return; } CoreEnvelopeAssessForm parentForm = ((CoreEnvelopeAssessForm)this.Owner); TreeNode selNode = this.treeCoreEnvelope.SelectedNode; if (flag == 0) { //从重心设计中加载数据 for (int i = 0; i < lstCoreEnvelopeDesign.Count; i++) { if (selNode.ToolTipText == i.ToString()) { List <CorePointExt> cpeList = new List <CorePointExt>(); foreach (NodeFormula nf in lstCoreEnvelopeDesign[i].FormulaList) { CorePointExt cpe = new CorePointExt(); cpe.pointName = nf.NodeName; cpe.pointXValue = nf.XFormula.Value; cpe.pointYValue = nf.YFormula.Value; cpe.isAssess = false; cpeList.Add(cpe); } parentForm.saveCoreGridView(cpeList, "0"); break; } } } else if (flag == 1) { //从重心裁剪中加载数据 for (int i = 0; i < lstCutResultData.Count; i++) { if (selNode.ToolTipText == i.ToString()) { List <CorePointExt> cpeList = new List <CorePointExt>(); foreach (CorePointData cpd in lstCutResultData[i].lstCutEnvelopeCore) { cpeList.Add(CommonUtil.corePointDataToCorePoinExt(cpd)); } parentForm.saveCoreGridView(cpeList, "0"); break; } } } else if (flag == 2) { //从重心数据库中加载数据 foreach (Model.CoreEnvelopeDesign core in this.lstCoreEnvelope) { if (core.Id.ToString() == selNode.Name) { List <CorePointExt> cpeList = new List <CorePointExt>(); List <CorePointData> list = CoreEnvelopeDesign.GetStringToListCorePointData(core.CoreEnvelope); foreach (CorePointData cpd in list) { cpeList.Add(CommonUtil.corePointDataToCorePoinExt(cpd)); } parentForm.saveCoreGridView(cpeList, "0"); break; } } } this.Close(); }
/// <summary> /// 读取XML文件转换成List<CorePointExt>类型 /// </summary> /// <param name="strFilePath">文件路径</param> /// <returns>CorePointData集合类型</returns> public static List<CorePointExt> LoadXmlToPointList(string strFilePath) { List<CorePointExt> lstCorePointExt = null; try { if (!File.Exists(strFilePath)) { return lstCorePointExt; } string path = string.Empty; XmlNode node = null; XmlDocument doc = new XmlDocument(); doc.Load(strFilePath); //重量列表 path = "重心数据/重心坐标列表"; node = doc.SelectSingleNode(path); XmlNodeList nodeList = node.ChildNodes; if (nodeList.Count > 0) { lstCorePointExt = new List<CorePointExt>(); foreach (XmlNode childNode in nodeList) { CorePointExt pt = new CorePointExt(); pt.pointName = childNode.ChildNodes[0].InnerText; pt.pointXValue = Convert.ToDouble(childNode.ChildNodes[3].InnerText); pt.pointYValue = Convert.ToDouble(childNode.ChildNodes[4].InnerText); if (childNode.ChildNodes.Count > 5) { pt.isAssess = Convert.ToBoolean(childNode.ChildNodes[5].InnerText); } lstCorePointExt.Add(pt); } } } catch { XCommon.XLog.Write("导入原始重心包线数据格式错误"); MessageBox.Show("导入原始重心包线数据格式错误!"); return null; } return lstCorePointExt; }
public static bool ImportExcelToPointList(List<CorePointExt> ptlst, string strfilename) { ptlst.Clear(); Excel.Application app = new Excel.ApplicationClass(); try { Object missing = System.Reflection.Missing.Value; app.Visible = false; Excel.Workbook wBook = app.Workbooks.Open(strfilename, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); Excel.Worksheet wSheet = wBook.Worksheets[1] as Excel.Worksheet; if (wSheet.Rows.Count > 1) { for (int i = 2; i <= wSheet.Rows.Count; ++i) { string cellid = "A" + i.ToString(); Excel.Range DataCell = wSheet.get_Range(cellid, cellid); string ParaName = (string)DataCell.Text; DataCell = DataCell.Next.Next.Next; if ((string)DataCell.Text == "") { break; } ParaName = ParaName.Trim(); CorePointExt node = new CorePointExt(); node.pointName = ParaName; node.pointXValue = (double)DataCell.Value2; node.pointYValue = (double)DataCell.Next.Value2; node.isAssess = Convert.ToBoolean(DataCell.Next.Next.Value2); ptlst.Add(node); } } app.Quit(); app = null; XCommon.XLog.Write("成功从文件\"" + strfilename + "\"导入数据!"); } catch (Exception err) { MessageBox.Show("导入Excel出错!错误原因:" + err.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } return true; }
public static CorePointExt corePointDataToCorePoinExt(CorePointData cpd) { CorePointExt cpe = new CorePointExt(); var cpdType = typeof(CorePointData); foreach (var propertie in cpdType.GetProperties()) { propertie.SetValue(cpe, propertie.GetValue(cpd, null), null); } return cpe; }
private void btnConfirm_Click(object sender, EventArgs e) { TreeNode node = this.WDMTree.SelectedNode; if (node == null || node.Level != 1) { MessageBox.Show("请选择机型"); return; } WDMIntegrationModule.Air air = airs[Convert.ToInt32(node.Tag)]; WDMIntegrationModule.TStmc[] tstmcs = WDMIntegrationModule.GetStmcs(node.Name); Random r = new Random(); List <CorePointExt> cpdList = new List <CorePointExt>(); //List<WeightData> lstWeightData = new List<WeightData>(); //CorePointExt parentWD = new CorePointExt(); //parentWD.pointName = air.MC; //parentWD. = 0; //parentWD.nParentID = -1; //lstWeightData.Add(parentWD); //int i = r.Next(10); //double weightValueSum = 0; foreach (WDMIntegrationModule.TStmc tstmc in tstmcs) { if (node.Name == air.ID) { CorePointExt cpe = new CorePointExt(); // gridView.Rows[i].Cells[0].Value = cpe.pointName; //gridView.Rows[i].Cells[1].Value = Math.Round(cpe.pointXValue, 6); //gridView.Rows[i].Cells[2].Value = Math.Round(cpe.pointYValue, 6); //WeightData wd = new WeightData(); cpe.pointName = tstmc.MC; cpe.pointYValue = tstmc.ZTW; cpe.pointXValue = (this.actualDataRadio.Checked?tstmc.XCG:tstmc.YCG) * 1000; //wd.nID = r.Next(10);// Convert.ToInt32(toper.ID); //wd.weightValue = this.actualDataRadio.Checked ? // (tstmc.SCW == 0 && this.useTestData.Checked ? // tstmc.ZTW : tstmc.SCW) : tstmc.ZTW; //wd.nParentID = 0; // 添加重量数据至重量数据列表 cpdList.Add(cpe); // weightValueSum += wd.weightValue; } } //parentWD.weightValue = weightValueSum; ((CoreEnvelopeAssessForm)this.Owner).saveCoreGridView(cpdList, "1"); this.Close(); }