/// <summary> /// 基于新建 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnJYNew_Click(object sender, EventArgs e) { if (selNode == null || selNode.Level == 0) { XLog.Write("请选择型号重量数据"); return; } strOperType = CommonMessage.operJYNew; SetPageButton(); SetOperTitle(strOperType); typeWeightData = typeWeightData = GetTypeWeightData(selNode.Name); }
/// <summary> /// 新建 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNew_Click(object sender, EventArgs e) { typeWeightData = new TypeWeightData(); strOperType = CommonMessage.operNew; SetPageButton(); IntiControl(); SetOperTitle(strOperType); }
/// <summary> /// 取消修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnConfirmCancle_Click(object sender, EventArgs e) { strOperType = CommonMessage.operCancle; SetPageButton(); SetOperTitle(strOperType); SettingPageData(); typeWeightData = null; }
/// <summary> /// 确认修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnConfirmModify_Click(object sender, EventArgs e) { //页面验证信息 string strErroInfo = PageVerificationInfo(); if (strErroInfo != string.Empty) { XLog.Write(strErroInfo); return; } GetPageTypeWeightData(); if (strOperType == CommonMessage.operNew || strOperType == CommonMessage.operJYNew) { bool IsAdd = bllTypeWeight.Add(typeWeightData); if (IsAdd) { if (strOperType == CommonMessage.operJYNew) { XLog.Write("基于新建成功"); } else { XLog.Write("新建成功"); } } } if (strOperType == CommonMessage.operEdit) { bool IsEdit = bllTypeWeight.Update(typeWeightData); if (IsEdit) { XLog.Write("修改成功"); } } strOperType = CommonMessage.operConfirm; SetPageButton(); BindWeightData(); SetOperTitle(strOperType); foreach (TreeNode node in treeViewTypeList.Nodes[0].Nodes) { if (node.Name == typeWeightData.Id.ToString()) { treeViewTypeList.SelectedNode = node; selNode = node; } } typeWeightData = null; }
/// <summary> /// 获取型号重量数据 /// </summary> /// <param name="strPath"></param> /// <returns></returns> private TypeWeightData GetXmlWeightTypeData(string strPath) { TypeWeightData weightData = null; try { if (!File.Exists(strPath)) { return weightData; } weightData = new TypeWeightData(); weightData.Id = bllTypeWeight.GetMaxId() + 1; string path = string.Empty; XmlNode node = null; XmlDocument doc = new XmlDocument(); doc.Load(strPath); //直升机名称 path = "型号重量数据/直升机名称"; node = doc.SelectSingleNode(path); weightData.Helicopter_Name = node.InnerText; //直升机类型 path = "型号重量数据/直升机类型"; node = doc.SelectSingleNode(path); weightData.Helicopter_Type = node.InnerText; //直升机国籍 path = "型号重量数据/直升机国籍"; node = doc.SelectSingleNode(path); weightData.Helicoter_Country = node.InnerText; //最大起飞重量 path = "型号重量数据/最大起飞重量"; node = doc.SelectSingleNode(path); weightData.MaxTaking_Weight = Convert.ToDouble(node.InnerText); //设计起飞重量 path = "型号重量数据/设计起飞重量"; node = doc.SelectSingleNode(path); weightData.DesignTaking_Weight = Convert.ToDouble(node.InnerText); //空机重量 path = "型号重量数据/空机重量"; node = doc.SelectSingleNode(path); weightData.EmptyWeight = Convert.ToDouble(node.InnerText); //空机重量 path = "型号重量数据/空机重量"; node = doc.SelectSingleNode(path); weightData.EmptyWeight = Convert.ToDouble(node.InnerText); //最后修改时间 path = "型号重量数据/最后修改时间"; weightData.Last_ModifyTime = doc.SelectSingleNode(path).InnerText; //重量分类名称 path = "型号重量数据/重量分类名称"; string strSortName = doc.SelectSingleNode(path).InnerText; //重量列表 path = "型号重量数据/重量列表"; node = doc.SelectSingleNode(path); XmlNodeList nodelist = node.ChildNodes; if (nodelist.Count > 0) { string strMainSystemWeight = strSortName + "|"; string strFH = "、"; foreach (XmlNode childNode in node.ChildNodes) { strMainSystemWeight += childNode.ChildNodes[1].InnerText + strFH + childNode.ChildNodes[0].InnerText + strFH + childNode.ChildNodes[2].InnerText + strFH + childNode.ChildNodes[3].InnerText + strFH + childNode.ChildNodes[5].InnerText + strFH + "|"; } weightData.MainSystem_Name = strMainSystemWeight; } } catch { XLog.Write("导入文件\"" + strPath + "\"格式错误"); MessageBox.Show("导入文件\"" + strPath + "\"格式错误"); return null; } return weightData; }
/// <summary> /// 单击节点事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeViewTypeList_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { selNode = e.Node; treeViewTypeList.SelectedNode = e.Node; typeWeightData = new TypeWeightData(); SettingPageData(); }
/// <summary> /// 获取tables数据 /// </summary> /// <param name="data"></param> /// <returns></returns> private DataTable GetTableExcleData(TypeWeightData weightData, WeightSortData sortData) { DataTable table = GetTableExcleStruct(); DataRow drFirst = table.NewRow(); drFirst["Helicopter_Name"] = weightData.Helicopter_Name; drFirst["Helicopter_Type"] = weightData.Helicopter_Type; drFirst["Helicopter_Country"] = weightData.Helicoter_Country; drFirst["MaxTaking_Weight"] = weightData.MaxTaking_Weight; drFirst["DesignTaking_Weight"] = weightData.DesignTaking_Weight; drFirst["Empty_Weight"] = weightData.EmptyWeight; drFirst["LastModify_Time"] = weightData.Last_ModifyTime; table.Rows.Add(drFirst); DataRow dr = null; if (sortData != null && sortData.lstWeightData.Count > 0) { foreach (WeightData data in sortData.lstWeightData) { if (data == sortData.lstWeightData[0]) { if (table.Rows.Count > 0) { table.Rows[0]["Sort_Name"] = sortData.sortName; table.Rows[0]["ID"] = data.nID; table.Rows[0]["Weight_Name"] = data.weightName; table.Rows[0]["Weight_Unit"] = "千克"; table.Rows[0]["Weight_Remark"] = data.strRemark; table.Rows[0]["Prarent_ID"] = data.nParentID; table.Rows[0]["Weight_Value"] = data.weightValue; } } else { dr = table.NewRow(); dr["Helicopter_Name"] = string.Empty; dr["Helicopter_Type"] = string.Empty; dr["Helicopter_Country"] = string.Empty; dr["MaxTaking_Weight"] = string.Empty; dr["DesignTaking_Weight"] = string.Empty; dr["Empty_Weight"] = string.Empty; dr["Sort_Name"] = string.Empty; dr["ID"] = data.nID; dr["Weight_Name"] = data.weightName; dr["Weight_Unit"] = "千克"; dr["Weight_Remark"] = data.strRemark; dr["Prarent_ID"] = data.nParentID; dr["Weight_Value"] = data.weightValue; table.Rows.Add(dr); } } } return table; }
/// <summary> /// 从XML文件中读取数据并转换成List<TypeWeightData>类型 /// </summary> /// <param name="strFileName"></param> /// <returns></returns> private List<TypeWeightData> GetListTypeWeightDataExt(string strFileName) { List<TypeWeightData> lstWeightData = new List<TypeWeightData>(); if (!File.Exists(strFileName)) { return lstWeightData; } XmlDocument doc = new XmlDocument(); doc.Load(strFileName);//加载XML //机型列表 XmlNodeList modelList=doc.SelectNodes("edccategory/inclass/node1"); //XmlNodeList lstNodeDB = doc.GetElementsByTagName("inclass"); //string dbId = string.Empty; //if (lstNodeDB != null && lstNodeDB.Count > 0) //{ // dbId = lstNodeDB[0].Attributes["id"].Value; // lstNode1 = doc.GetElementsByTagName("node1"); //机型 // lstNode2 = doc.GetElementsByTagName("node2"); //参数类:第一个,基本数据;第二个,重量分类 // lstNode3 = doc.GetElementsByTagName("node3"); //重量分类-重量分类参数 // lstModel = doc.GetElementsByTagName("model"); //基本数据-参数名-值 //} int count = bllTypeWeight.GetMaxId() + 1; //机型循环 foreach (XmlNode modelNode in modelList) { TypeWeightData data = new TypeWeightData(); data.Id = count++; XmlNodeList node2List = modelNode.SelectNodes("node2"); //重量分类 WeightSortData sortData = new WeightSortData(); sortData.lstWeightData = new List<WeightData>(); //基础信息 data.Helicopter_Name = modelNode.Attributes["name"].Value;//直升机名称 if(node2List[0]!=null) { XmlNode childNode = node2List[0].SelectSingleNode("model"); if (childNode.Attributes["zsjlx"].Value != null)//直升机类型 { data.Helicopter_Type = childNode.Attributes["zsjlx"].Value; } if (childNode.Attributes["zsjgj"].Value !=null)//直升机国籍 { data.Helicoter_Country = childNode.Attributes["zsjgj"].Value; } if (childNode.Attributes["zsjkjzl"].Value !=null)//直升机空机重量 { data.EmptyWeight = childNode.Attributes["zsjkjzl"].Value == null ? 0 : Convert.ToDouble(childNode.Attributes["zsjkjzl"].Value); } if (childNode.Attributes["zdqfzl"].Value!=null)//最大起飞重量 { data.MaxTaking_Weight = childNode.Attributes["zdqfzl"].Value == null ? 0 : Convert.ToDouble(childNode.Attributes["zdqfzl"].Value); } if (childNode.Attributes["zsjsjqfzl"].Value != null)// "设计起飞重量" { data.DesignTaking_Weight = childNode.Attributes["zsjsjqfzl"].Value == null ? 0 : Convert.ToDouble(childNode.Attributes["zsjsjqfzl"].Value); } if (childNode.Attributes["updated"].Value != null)//"最后修改时间" { data.Last_ModifyTime = childNode.Attributes["updated"].Value; } if (childNode.Attributes["zlflmc"].Value != null )//"重量分类名称" { sortData.sortName = childNode.Attributes["zlflmc"].Value; } } //层次结构 //" zlid="0" zlmc="空机重量" zldw="千克" zlsz="3138.502" zlfjd="-1" XmlNode levelData=node2List[1]; XmlNode topNode = levelData.SelectNodes("model")[0];//顶层结构结点 XmlNodeList node3List = levelData.SelectNodes("node3"); WeightData weightData = new WeightData(); weightData.nID = int.Parse(topNode.Attributes["zlid"].Value);// "xlID" weightData.nParentID = int.Parse(topNode.Attributes["zlfjd"].Value); //"zlparentId" weightData.weightName = topNode.Attributes["zlmc"].Value; //"zlName" //weightData.weightUnit = topNode.Attributes["zldw"].Value; weightData.weightValue = topNode.Attributes["zlsz"].Value == null ? 0 : Convert.ToDouble(topNode.Attributes["zlsz"].Value);//zlsz //weightData.strRemark = topNode.Attributes["remarks"].Value;//zldesc List<WeightData> wdList= new List<WeightData>(); wdList.Add(weightData); generateStruct(node3List,wdList); sortData.lstWeightData = wdList; sortData.lstWeightData = sortData.lstWeightData.OrderBy(s => s.nID).ToList(); data.MainSystem_Name = GetMainSystemWeight(sortData); lstWeightData.Add(data); } return lstWeightData; }
private List<TypeWeightData> GetListTypeWeightData(string strFileName) { List<TypeWeightData> lstWeightData = new List<TypeWeightData>(); if (!File.Exists(strFileName)) { return lstWeightData; } XmlDocument doc = new XmlDocument(); doc.Load(strFileName); XmlNodeList lstNodeDB = doc.GetElementsByTagName("inclass"); string dbId = string.Empty; if (lstNodeDB != null && lstNodeDB.Count > 0) { dbId = lstNodeDB[0].Attributes["id"].Value; lstNode1 = doc.GetElementsByTagName("node1"); //机型 lstNode2 = doc.GetElementsByTagName("node2"); //参数类:第一个,基本数据;第二个,重量分类 lstNode3 = doc.GetElementsByTagName("node3"); //重量分类-重量分类参数 lstModel = doc.GetElementsByTagName("model"); //基本数据-参数名-值 } int count = 0; //机型循环 foreach (XmlNode typeNode in lstNode1) { TypeWeightData data = new TypeWeightData(); string strID = string.Empty; //型号ID if (typeNode.Attributes["pid"].Value == dbId) { strID = typeNode.Attributes["id"].Value; data.Id = bllTypeWeight.GetMaxId() + count; count++; string strSortName = string.Empty; foreach (XmlNode node in lstNode2) { //基本信息 if (node.Attributes["pid"].Value == strID && node.Attributes["name"].Value == "基本信息" ) { //机型名称 data.Helicopter_Name = typeNode.Attributes["name"].Value; string strBasicId = node.Attributes["id"].Value; foreach (XmlNode childNode in lstModel) { if (childNode.Attributes["pid"].Value == strBasicId && childNode.Attributes["name"].Value == "类型") { data.Helicopter_Type = childNode.Attributes["value"].Value; } if (childNode.Attributes["pid"].Value == strBasicId && childNode.Attributes["name"].Value == "国籍") { data.Helicoter_Country = childNode.Attributes["value"].Value; } if (childNode.Attributes["pid"].Value == strBasicId && childNode.Attributes["name"].Value == "空机重量") { data.EmptyWeight = childNode.Attributes["value"].Value == null ? 0 : Convert.ToDouble(childNode.Attributes["value"].Value); } //if (childNode.Attributes["pid"].Value == strBasicId && childNode.Attributes["name"].Value == "直升机名称") //{ // data.Helicopter_Name = childNode.Attributes["value"].Value; //} if (childNode.Attributes["pid"].Value == strBasicId && childNode.Attributes["name"].Value == "最大起飞重量") { data.MaxTaking_Weight = childNode.Attributes["value"].Value == null ? 0 : Convert.ToDouble(childNode.Attributes["value"].Value); } if (childNode.Attributes["pid"].Value == strBasicId && childNode.Attributes["name"].Value == "设计起飞重量") { data.DesignTaking_Weight = childNode.Attributes["value"].Value == null ? 0 : Convert.ToDouble(childNode.Attributes["value"].Value); } if (childNode.Attributes["pid"].Value == strBasicId && childNode.Attributes["name"].Value == "最后修改时间") { data.Last_ModifyTime = childNode.Attributes["value"].Value; } if (childNode.Attributes["pid"].Value == strBasicId && childNode.Attributes["name"].Value == "重量分类名称") { strSortName = childNode.Attributes["value"].Value; } } } //重量数据 if (node.Attributes["pid"].Value == strID && node.Attributes["name"].Value == "空机重量") { WeightSortData sortData = new WeightSortData(); sortData.lstWeightData = new List<WeightData>(); //重量分类名称 sortData.sortName = strSortName; foreach (XmlNode node3 in lstNode3) { if (node3.Attributes["pid"].Value == node.Attributes["id"].Value) { foreach (XmlNode childNode in lstModel) { if (childNode.Attributes["pid"].Value == node3.Attributes["id"].Value) { WeightData weightData = new WeightData(); weightData.nID = int.Parse(childNode.Attributes["ID"].Value);// "xlID" weightData.nParentID = int.Parse(childNode.Attributes["PARENTID"].Value); //"zlparentId" weightData.weightName = childNode.Attributes["name"].Value; //"zlName" weightData.weightValue = childNode.Attributes["value"].Value == null ? 0 : Convert.ToDouble(childNode.Attributes["value"].Value);//zlsz weightData.strRemark = childNode.Attributes["remarks"].Value;//zldesc sortData.lstWeightData.Add(weightData); break; } } } } foreach (XmlNode childNode in lstModel) { //空机重量 if (childNode.Attributes["pid"].Value == node.Attributes["id"].Value && childNode.Attributes["xlID"].Value == "0")//xlID { WeightData weightData = new WeightData(); weightData.nID = int.Parse(childNode.Attributes["ID"].Value);//xlID weightData.nParentID = int.Parse(childNode.Attributes["PARENTID"].Value);//zlparentId weightData.weightName = childNode.Attributes["name"].Value;//zlName weightData.weightValue = childNode.Attributes["value"].Value == null ? 0 : Convert.ToDouble(childNode.Attributes["value"].Value);//zlsz weightData.strRemark = childNode.Attributes["remarks"].Value;//zldesc sortData.lstWeightData.Add(weightData); break; } } sortData.lstWeightData = sortData.lstWeightData.OrderBy(s => s.nID).ToList(); data.MainSystem_Name = GetMainSystemWeight(sortData); } } } lstWeightData.Add(data); } return lstWeightData; }
/// <summary> /// 获取重量结果内容 /// </summary> /// <returns></returns> private List<string> GetListContent(TypeWeightData weightData) { List<string> lstContent = null; if (weightData != null) { lstContent = new List<string>(); WeightSortData sortData = WeightDesignDataForm.clsStringToWeightSortData(weightData.MainSystem_Name); string strSortName = sortData == null ? string.Empty : sortData.sortName; lstContent.Insert(0, "<?xml version=" + "\"1.0\"" + " encoding=" + "\"gb2312\"" + " ?> "); List<double> lstValue = GetListWeightData(gridWeightData); List<string> lstTitle = GetListWeightTitle(); lstContent.Add("<型号重量数据>"); lstContent.Add(CommonFunction.mStrModifyToString8(1) + "<直升机名称>" + weightData.Helicopter_Name + "</直升机名称>"); lstContent.Add(CommonFunction.mStrModifyToString8(1) + "<直升机类型>" + weightData.Helicopter_Type + "</直升机类型>"); lstContent.Add(CommonFunction.mStrModifyToString8(1) + "<直升机国籍>" + weightData.Helicoter_Country + "</直升机国籍>"); lstContent.Add(CommonFunction.mStrModifyToString8(1) + "<设计起飞重量>" + weightData.DesignTaking_Weight.ToString() + "</设计起飞重量>"); lstContent.Add(CommonFunction.mStrModifyToString8(1) + "<最大起飞重量>" + weightData.MaxTaking_Weight.ToString() + "</最大起飞重量>"); lstContent.Add(CommonFunction.mStrModifyToString8(1) + "<空机重量>" + weightData.EmptyWeight.ToString() + "</空机重量>"); lstContent.Add(CommonFunction.mStrModifyToString8(1) + "<最后修改时间>" + weightData.Last_ModifyTime + "</最后修改时间>"); lstContent.Add(CommonFunction.mStrModifyToString8(1) + "<重量分类名称>" + strSortName + "</重量分类名称>"); lstContent.Add(CommonFunction.mStrModifyToString8(1) + "<重量列表>"); //重量数据 List<string> lstWeightContent = MainForm.GetDesignWeightDataContent(3, sortData); foreach (string strContent in lstWeightContent) { lstContent.Add(strContent); } lstContent.Add(CommonFunction.mStrModifyToString8(1) + "</重量列表>"); lstContent.Add("</型号重量数据>"); } return lstContent; }
private TypeWeightData GetExcelTypeWeightData(string strFilePath) { TypeWeightData weightData = null; try { if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return weightData; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; if (count > 0) { weightData = new TypeWeightData(); weightData.Id = bllTypeWeight.GetMaxId() + 1; weightData.Helicopter_Name = table.Rows[0][0].ToString(); weightData.Helicopter_Type = table.Rows[0][1].ToString(); weightData.Helicoter_Country = table.Rows[0][2].ToString(); weightData.MaxTaking_Weight = Convert.ToDouble(table.Rows[0][3]); weightData.DesignTaking_Weight = Convert.ToDouble(table.Rows[0][4]); weightData.EmptyWeight = Convert.ToDouble(table.Rows[0][5]); weightData.Last_ModifyTime = table.Rows[0][6].ToString(); string strMainSystemWeight = string.Empty; string strSortName = table.Rows[0][7].ToString(); if (strSortName != string.Empty) { strMainSystemWeight = strSortName + "|"; string strFH = "、"; for (int i = 0; i < count; i++) { strMainSystemWeight += table.Rows[i][9].ToString() + strFH + table.Rows[i][8].ToString() + strFH + table.Rows[i][10].ToString() + strFH + table.Rows[i][11].ToString() + strFH + table.Rows[i][13].ToString() + "|"; } } weightData.MainSystem_Name = strMainSystemWeight; } } } catch { XLog.Write("导入文件\"" + strFilePath + "\"格式错误"); MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误"); return null; } return weightData; }