public void ConvertTemplate() { foreach (var item in Templates) { string datPath = item.Name.Substring(0, item.Name.Length - 3) + "dat"; DES.DesDecrypt(item.Name, datPath, "12345678"); TowerTemplateReader templateReader = new TowerTemplateReader(TowerTypeStringConvert.TowerStringToType(item.TowerType)); TowerTemplate template = templateReader.Read(datPath); string dirPath = datPath.Substring(0, datPath.LastIndexOf('\\')); string templateName = datPath.Substring(datPath.LastIndexOf('\\') + 1); string newDirPath = dirPath + "\\新模板\\"; if (!Directory.Exists(newDirPath)) { Directory.CreateDirectory(newDirPath); } string newTemplatePath = newDirPath + templateName; NewTowerTemplateReader newTemplateReader = new NewTowerTemplateReader(TowerTypeStringConvert.TowerStringToType(item.TowerType)); newTemplateReader.Save(newTemplatePath, template); } }
public void TestMethod1_NewTemplateReadAndSave() { var openFileDialog = new Microsoft.Win32.OpenFileDialog() { Filter = "DLL Files (*.dll)|*.dll" }; if (openFileDialog.ShowDialog() != true) { return; } string datPath = openFileDialog.FileName.Substring(0, openFileDialog.FileName.Length - 3) + "dat"; DES.DesDecrypt(openFileDialog.FileName, datPath, "12345678"); TowerTemplateReader templateReader = new TowerTemplateReader(TowerTypeEnum.LineTower); TowerTemplate template = templateReader.Read(datPath); string newDatPath = openFileDialog.FileName.Substring(0, openFileDialog.FileName.Length - 4) + "New.dat"; NewTowerTemplateReader newTemplateReader = new NewTowerTemplateReader(TowerTypeEnum.LineTower); newTemplateReader.Save(newDatPath, template); TowerTemplate newTemplate = newTemplateReader.Read(newDatPath); }
//只有工程模板才会调用这个函数 public void onConfirm() { var proUtils = ProjectUtils.GetInstance(); //新增模板时工程中已经在同类型的塔中塔名已经存在 if(proUtils.GetProjectTowerTemplate().Where(item=>item.Name == _template.Name && item.TowerType == _template.TowerType).Count() > 0 &&(oldName == null || oldName.Trim() == "") ) { MessageBox.Show("同名模板已经存在,请更换一个名字"); return; } for(int i = 0; i < WireNum; i++) { if (Wires[0].Wire[i]== null || Wires[0].Wire[i].Trim() == "") { MessageBox.Show("请完善导地线信息"); return; } } for (int i = 0; i < WorkConditionNum; i++) { if (WorkConditions[0].WorkCondition[i] == null || WorkConditions[0].WorkCondition[i].Trim() == "") { MessageBox.Show("请完善工况信息"); return; } } //新增模板 if (oldName == null || oldName == "") { proUtils.InsertProjectTowerTemplate(new TowerTemplateStorageInfo() { Name = _template.Name, //lcp文件中towerType是中文 TowerType = _template.TowerType }); } else { //旧模板改了新名字 if (oldName != _template.Name || oldType != _template.TowerType) { proUtils.UpdateProjectTowerTemplateName(oldName, oldType, _template.Name, _template.TowerType); } //删除旧模板 string oldTemplatePath = proUtils.GetProjectlTowerTemplatePath(_template.Name, _template.TowerType); if(File.Exists(oldTemplatePath)) { File.Delete(oldTemplatePath); } } //保存模板 _template.Wires.Clear(); int wireCnt = Wires[0].Wire.Where(w => w != null && w.Trim() != "").Count(); for (int i = 0; i < wireCnt; i++) { _template.Wires.Add(Wires[0].Wire[i]); } _template.WorkConditongs.Clear(); int wdCnt = WorkConditions[0].WorkCondition.Where(wd => wd != null && wd.Trim() != "").Count(); for (int i = 1; i <= wdCnt; i++) { _template.WorkConditongs[i] = WorkConditions[0].WorkCondition[i - 1]; } TowerTemplateReader.ConvertSpecToWorkCondition(_template, WorkConditionCombos.ToList()); string newTemplatePath = proUtils.GetProjectlTowerTemplatePath(_template.Name, _template.TowerType); NewTowerTemplateReader templateReader = new NewTowerTemplateReader(TowerTypeStringConvert.TowerStringToType(_template.TowerType)); templateReader.Save(newTemplatePath, _template); close(true); }