コード例 #1
0
        private void FormAddDictionary_Load(object sender, EventArgs e)
        {
            // MessageBox.Show("hi" + this.dictionary_parent_id);
            //this.Text = this.title;
            this.labelTitle.Text = this.title + this.typeName;
            //修改
            if (this.dictionary_id >= 0)
            {
                DataTable dt = DBDictionary.getInstance().getDictionarysById(this.dictionary_id);

                foreach (DataRow row in dt.Rows)
                {
                    this.tbRank.Text = row["d_order"].ToString();
                    this.tbName.Text = row["d_name"].ToString();
                    this.tbDesc.Text = row["d_desc"].ToString();
                    name_flag        = row["d_name"].ToString();
                    //this.dictionary_parent_id =
                }
            }
            else
            {
                setRank();
            }
        }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string rank = this.tbRank.Text;
            string name = this.tbName.Text;
            string desc = this.tbDesc.Text;

            if (string.IsNullOrEmpty(rank))
            {
                MessageBox.Show("序号不能为空");
                return;
            }

            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("名称不能为空");
                return;
            }
            // 此处任务 parent_id=8的就是 手术追踪期限字典
            else if (8 == this.dictionary_parent_id)
            {
                try
                {
                    Convert.ToInt32(name);
                }
                catch (Exception)
                {
                    MessageBox.Show("请输入数字,1代表每一月,2代表每两月!");
                    return;
                }
            }

            /*
             * if (string.IsNullOrEmpty(desc))
             * {
             *  MessageBox.Show("描述不能为空");
             *  return;
             * }*/

            //编辑
            if (this.dictionary_id >= 0)
            {
                DialogResult dr = MessageBox.Show("确定要编辑?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    if (!name_flag.Equals(name))
                    {
                        DataTable dt = DBDictionary.getInstance().getDictionarysByParentIdAndName(this.dictionary_parent_id, name);
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            MessageBox.Show("该名称已有,请重新编辑");
                            return;
                        }
                    }

                    int flag = DBDictionary.getInstance().editDictionary(this.dictionary_id, rank, this.dictionary_parent_id, name, desc);
                    if (flag > 0)
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("编辑失败");
                    }
                }
                else
                {
                    this.Close();//关闭容器
                }
            }
            //添加
            else
            {
                DataTable dt = DBDictionary.getInstance().getDictionarysByParentIdAndName(this.dictionary_parent_id, name);
                if (dt == null || dt.Rows.Count == 0)
                {
                    int flag = DBDictionary.getInstance().addDictionary(rank, this.dictionary_parent_id, name, desc);
                    if (flag > 0)
                    {
                        DialogResult dr = MessageBox.Show("添加成功,是否继续添加?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (dr == DialogResult.Yes)
                        {
                            //清理
                            setRank();
                            this.tbName.Text = "";
                            //this.cbSex.Text;
                            this.tbDesc.Text = "";
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                            this.Close();//关闭容器
                        }
                    }
                    else
                    {
                        MessageBox.Show("添加失败");
                    }
                }
                else
                {
                    MessageBox.Show("该名称已添加");
                }
            }
        }