Example #1
0
 // 设置主窗体指针
 public void setMainFormPointer(MainForm mf, SymbolForm sf)
 {
     this.mainFormRef = mf;
     this.symbolFormRef = sf;
 }
Example #2
0
        // 确定或应用
        private void button1_Click(object sender, EventArgs e)
        {
            // 处理参数列表
            List <string> argvList = new List <string>();
            int           nrows    = this.argsGridDataView.Rows.Count - 1;

            for (int i = 0; i < nrows; i++)
            {
                string varname = this.argsGridDataView.Rows[i].Cells[0].Value.ToString();
                // 类型不能为空
                if (this.argsGridDataView.Rows[i].Cells[1].Value == null)
                {
                    MessageBox.Show(String.Format("变量 {0} 类型不合法", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                string vartype = this.argsGridDataView.Rows[i].Cells[1].Value.ToString();
                // 符号合法性
                if (Consta.IsStdCSymbol(varname) == false)
                {
                    MessageBox.Show(String.Format("变量 {0} 命名不合法", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // 符号唯一性
                if (argvList.Find((x) => x.Split('@')[0] == varname) != null)
                {
                    MessageBox.Show(String.Format("变量名 {0} 重复", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // 类型合法性
                if (Consta.basicType.Find((x) => x == vartype) == null)
                {
                    MessageBox.Show(String.Format("变量 {0} 类型不合法", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                argvList.Add(String.Format("{0}@{1}", varname, vartype));
            }
            // 处理函数头部
            string callname = this.textBox1.Text;

            if (Consta.IsStdCSymbol(callname) == false)
            {
                MessageBox.Show(String.Format("函数命名不合法"), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // 处理返回类型
            string rettype = (string)this.comboBox1.SelectedItem;

            // 如果是新建函数
            if (this.Text == "新建函数")
            {
                // 通过控制器传递给后台
                bool flag = core.addFunction(callname, argvList, rettype);
                // 重名错误时
                if (flag == false)
                {
                    MessageBox.Show("函数名已经存在,\n请修改函数名!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // 刷新前台
                MainForm father = (MainForm)this.Owner;
                father.functionListBox.Items.Add(callname);
                father.addTabCard(callname);
                this.Close();
            }
            else if (this.Text == "从管理器新建函数")
            {
                // 通过控制器传递给后台
                bool flag = core.addFunction(callname, argvList, rettype);
                // 重名错误时
                if (flag == false)
                {
                    MessageBox.Show("函数名已经存在,\n请修改函数名!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // 刷新前台
                SymbolForm parentForm = (SymbolForm)this.Owner;
                parentForm.funListBox.Items.Add(callname);
                parentForm.funListBox.SelectedItem = callname;
                MainForm father = (MainForm)(parentForm.Owner);
                father.functionListBox.Items.Add(callname);
                father.addTabCard(callname);
                this.Close();
            }
            // 如果是编辑函数
            else
            {
                // 通过控制器传递给后台
                bool flag = core.editFunction(this.oldfcname, callname, argvList, rettype);
                // 重名错误时
                if (flag == false)
                {
                    MessageBox.Show("函数名已经存在,\n请修改函数名!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // 刷新前台
                if (this.Text == "编辑函数")
                {
                    MainForm father = (MainForm)(this.Owner);
                    father.closeTabCard(this.oldfcname);
                    father.functionListBox.Items.Remove(this.oldfcname);
                    father.functionListBox.Items.Add(callname);
                    father.addTabCard(callname);
                    this.Close();
                }
                else if (this.Text == "管理函数")
                {
                    if (this.mainFormRef != null)
                    {
                        this.mainFormRef.tabControl1.TabPages[this.oldfcname].Text = callname;
                        this.mainFormRef.tabControl1.TabPages[this.oldfcname].Name = callname;
                        int flid = this.mainFormRef.functionListBox.Items.IndexOf(this.oldfcname);
                        this.mainFormRef.functionListBox.Items[flid] = callname;
                        SymbolForm ownSf = (SymbolForm)this.symbolFormRef;
                        ownSf.funListBox.Items.Clear();
                        List <string> funList = core.getAllFunction();
                        foreach (string s in funList)
                        {
                            ownSf.funListBox.Items.Add(s);
                        }
                        flid = ownSf.funListBox.Items.IndexOf(callname);
                        ownSf.funListBox.SelectedIndex = flid;
                        this.refreshContext(callname);
                    }
                }
            }
        }
Example #3
0
 // 菜单->变量管理器
 private void 变量管理器ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SymbolForm sf = new SymbolForm(1);
     sf.ShowDialog(this);
 }
Example #4
0
 // 设置主窗体指针
 public void setMainFormPointer(MainForm mf, SymbolForm sf)
 {
     this.mainFormRef   = mf;
     this.symbolFormRef = sf;
 }