/// <summary> /// 判断工程名书写规范 /// 必须以大写字母开头只能包括字母数字和下划线 /// </summary> /// <param name="projectname"></param> /// <returns></returns> private bool judgeProjectName(string projectName) { char[] tempArray = projectName.ToCharArray(); if (tempArray.Length > 0) { string newName = null; for (int i = 0; i < tempArray.Length; i++) { if (tempArray[i] >= 'a' && tempArray[i] <= 'z') { tempArray[i] = (char)(tempArray[i] - 'a' + 'A');//从小写到大些相差32阿斯克马值 } else if (!((tempArray[i] >= 'A' && tempArray[i] <= 'Z') || (tempArray[i] >= '0' && tempArray[i] <= '9') || tempArray[i] == '_')) { CassMessageBox.Information("工程名中不能含有字母数字下划线以外的符号!"); return(false); } newName += tempArray[i]; } ProjectName.Text = newName; return(true); } return(false); }
//读取图片坐标信息,生成featureArea.h public string AnalyseFeatherHeaderFile(string savePath, string inputFilePath) { try { if (!File.Exists(savePath + FeatherName)) { // CassMessageBox.Information("当前工程不存在" + FeatherName + "文件!"); return("当前工程不存在" + FeatherName + "文件!"); } //读取feather.h文件 string fileContent = FileOperator.ReadFromFile2(savePath + FeatherName); string writeContent = null; if (fileContent == null)//当feather.h文件为空时,默认读取全图尺寸 { writeContent = GenerateDefaltFeatureAreaFile(inputFilePath); CassMessageBox.Information("当前为默认状态,全图操作。"); } else { writeContent = AnalyseFeatherContent(fileContent); } FileOperator.WriteToFile(savePath + FeatureAreaName, writeContent, Encoding.UTF8); } catch (Exception ex) { return(ex.ToString()); } return(null); }
/// <summary> /// 关闭事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddressTable_FormClosing(object sender, FormClosingEventArgs e) { this.AddressTableView.EndEdit(); //结束表格的编辑状态 if (isSaved) { SaveListInfo(this.AddressInfo);//把当前地址信息保存到外部所用的ReturnTable列表 CountSize(); this.DialogResult = DialogResult.Yes; this.Dispose(); } else {//修改后没有保存则询问 DialogResult result = CassMessageBox.QuestionT("是否保存现有地址?"); if (result == DialogResult.Yes) { UpdateCurrentInfo(); //SelectErrorRows(); SaveAddress(this.SetPath); CountSize(); this.DialogResult = DialogResult.Yes; this.Dispose(); //释放资源 } else if (result == DialogResult.No) { this.DialogResult = DialogResult.No; this.Dispose(); //释放资源 } else if (result == DialogResult.Cancel) { e.Cancel = true; } } }
private void btn_Ok_Click(object sender, EventArgs e) { //3.调用委托,将参数传给主界面中的programPath dele_workSpace(this._currentWorkSpace); this.Close(); //提示完成切换 CassMessageBox.Information("工作目录切换成功!"); }
/// <summary> /// 关闭窗口检验填写信息函数 /// </summary> private void CloseForm() { bool Pass1 = CassViewGenerator.JudgeName(ProjectName.Text, "工程文件名") && judgeProjectName(ProjectName.Text); bool Pass2 = Directory.Exists(CassViewGenerator.programPath + "\\" + ProjectName.Text); if (Pass1 == false) { //this.DialogResult = DialogResult.Cancel; //this.Dispose(); //释放资源 } else if (Pass2 == true) { DialogResult result = new DialogResult(); if (this.Text == "新建工程") { result = CassMessageBox.Question("存在相同的工程,是否删除原有的工程?"); if (result == DialogResult.Yes) { Directory.Delete(CassViewGenerator.programPath + "\\" + ProjectName.Text, true);//删除原有工程 this.Pname = ProjectName.Text; this.Pinfo = ProjectInfo.Text; this.DialogResult = DialogResult.OK; this.Dispose(); //释放资源 } } else if (this.Text == "修改工程") { if (this.Pname == ProjectName.Text) {//工程名相同 为修改信息 this.Pinfo = ProjectInfo.Text; this.DialogResult = DialogResult.OK; } else {//与其他工程冲突 CassMessageBox.Warning("存在相同的工程,修改工程名失败!"); this.DialogResult = DialogResult.Cancel; } this.Dispose(); //释放资源 } } //else if (result == DialogResult.No) //{ } else { this.Pname = ProjectName.Text; this.Pinfo = ProjectInfo.Text; this.DialogResult = DialogResult.OK; this.Dispose(); //释放资源 } }
/// <summary> /// 另存为事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuItem_SaveAs_Click(object sender, EventArgs e) { try { SaveFileDialog dialog = new SaveFileDialog(); //打开文件对话框 dialog.DefaultExt = "txt"; dialog.Filter = "Save Address(*.txt)|(*.txt)"; if (dialog.ShowDialog() == DialogResult.OK) { SaveAddress(dialog.FileName); } } catch { CassMessageBox.Error("保存地址表失败!"); } }
/// <summary> /// 从XML文件导入原有设定进行地址写入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuItem_Load_Click(object sender, EventArgs e) { try { OpenFileDialog dialog = new OpenFileDialog(); //打开文件对话框 dialog.DefaultExt = "txt"; dialog.Filter = "Load Address(*.txt)|*.txt"; if (dialog.ShowDialog() == DialogResult.OK) { LoadAddress(dialog.FileName); } } catch { CassMessageBox.Error("导入地址表失败!"); } }
/// <summary> /// 创建与原删除控件相同的控件 /// </summary> /// <param name="info"></param> /// <returns></returns> private void CreateControl(ref Operation info) { HostDesign design = (HostDesign)info.Change[0]; Control Oldctrl = (Control)info.Item; IDesignerHost tems = design.GetService(typeof(IDesignerHost)) as IDesignerHost; Control Newctrl = (Control)tems.CreateComponent(Oldctrl.GetType()); Attribute[] tempAtr = new Attribute[] { new CategoryAttribute(PublicVariable.ControlCategoryName) }; PropertyDescriptor portNameProperty = TypeDescriptor.GetProperties(Newctrl)["PortName"]; PropertyDescriptorCollection OldPropertyDescriptors = TypeDescriptor.GetProperties(Oldctrl, tempAtr); PropertyDescriptorCollection NewPropertyDescriptors = TypeDescriptor.GetProperties(Newctrl, tempAtr); foreach (PropertyDescriptor elementA in OldPropertyDescriptors) { foreach (PropertyDescriptor elementB in NewPropertyDescriptors) { if (elementA.Name == elementB.Name) { elementB.SetValue(Newctrl, elementA.GetValue(Oldctrl)); } } } Newctrl.Tag = Newctrl.Site.Name; if (info.Change[1].ToString() != Newctrl.Site.Name) {//新旧控件名不同时需更新 UpdateCtrlInfo(ref info, info.Change[1].ToString(), Newctrl.Site.Name); } info.Item = Newctrl; if (portNameProperty != null) { string[] tempCodeinfo = ((ControlInfo)info.Change[2]).CodeInfo; string curPnum = tempCodeinfo[2].Substring(tempCodeinfo[1].Length); for (int i = 0; i < CassViewGenerator.PortInfoList.Count; i++) { if (((string[])(CassViewGenerator.PortInfoList[i][0]))[0] == tempCodeinfo[0]) {//找到的对应的控件类 ((List <string>)(CassViewGenerator.PortInfoList[i][1])).Add(curPnum); break; } } if (tempCodeinfo[1] + curPnum != tempCodeinfo[2]) { CassMessageBox.Error("撤销控件点名出错!"); } } }
/// <summary> /// 选出所有出错的地址格 /// </summary> /// <returns></returns> private bool SelectErrorRows() { List <string[]> infos = checkRepeatAdres(this.AddressInfo); if (infos.Count == 0) { return(false); } else { //for (int i = 0; i < infos.Count; i++) //{ // this.AddressTableView.Rows[indexs[i]].Cells[4].Selected = true; //} CassMessageBox.Error("地址中出现" + infos.Count.ToString() + "处地址重复!"); return(true); } }
//<summary> /// /获取当前设计器的视图,并将当前的类控件设置为设计器视图的根组件。 /// </summary> /// <param name="hostDesignSurface">HostDesign类型变量,该变量为设计器类型变量,函数中获取该设计器的视图</param> private void InitializeHost(HostDesign hostDesignSurface) { try { hostDesign = hostDesignSurface; if (hostDesign == null || hostDesign.View == null) { return; } Control control = (Control)hostDesign.View; //获取根设计器的视图,该View并不是类; control.Parent = this; control.Dock = DockStyle.Fill; control.Visible = true; loadFlag = true; } catch (NotSupportedException e) { loadFlag = false; CassMessageBox.Error("未提供与此设计图面兼容的视图"); } catch (ObjectDisposedException e) { loadFlag = false; CassMessageBox.Error("设计器对象被释放!"); } catch (InvalidOperationException e) { loadFlag = false; CassMessageBox.Error("设计器加载程序尚未创建根设计器或加载失败!"); } catch (Exception ex) { CassMessageBox.Error("加载程序发生致命性错误!"); this.Dispose();//20090603便于加载至梯形图内部,关闭当前程序窗口 //Application.Exit(); } }
/// <summary> /// 确定后修改自动保存定时器的设置 /// </summary> /// <param name="sender">buttonOk对象</param> /// <param name="e">所触发的Click事件</param> private void buttonOK_Click(object sender, EventArgs e) { FileStream fStream = null; StreamWriter sWriter = null; try { timeInterval = Convert.ToInt16(timetextBox.Text); if (timeInterval > 0 && timeInterval <= 60) { if (timeEnablecheckBox.CheckState == CheckState.Checked) { timeEnabeFlag = true; } else { timeEnabeFlag = false; } //将当前配置保存到安装目录下的TimerSetParament.inf文件中 fStream = new FileStream(Path.Combine(CassViewGenerator.designerPath, PublicVariable.TimeSetFileName), FileMode.Create); sWriter = new StreamWriter(fStream); sWriter.WriteLine(timeEnabeFlag.ToString().ToLower()); sWriter.WriteLine(timeInterval); sWriter.Close(); fStream.Close(); updateFlag = true; this.Close(); //成功后关闭 } else { CassMessageBox.Warning("时间范围设置错误!"); } } catch (FileNotFoundException ex) { CassMessageBox.Error("安装文件被损坏!"); } catch (DirectoryNotFoundException ex) { CassMessageBox.Error("安装文件被损坏!"); } catch (SecurityException ex) { CassMessageBox.Error("文件权限被修改!"); } catch (Exception ex) { CassMessageBox.Error("保存过程发生异常,可能是输入的保存时间格示错误!"); } finally { if (sWriter != null) { sWriter.Dispose(); } if (fStream != null) { fStream.Dispose(); } } }