コード例 #1
0
 /// <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("保存地址表失败!"); }
 }
コード例 #2
0
 /// <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("导入地址表失败!"); }
 }
コード例 #3
0
        /// <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("撤销控件点名出错!");
                }
            }
        }
コード例 #4
0
        /// <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);
            }
        }
コード例 #5
0
        //<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();
            }
        }
コード例 #6
0
        /// <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();
                }
            }
        }