Exemple #1
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            #region 新增
            if (type == 0)//新增
            {
                if (string.IsNullOrEmpty(txtbox_Code.Text) || string.IsNullOrWhiteSpace(txtbox_Code.Text))
                {
                    MessageBox.Show("常用SQL编码不能为空!");
                    txtbox_Code.Focus();
                }
                else
                {
                    if (string.IsNullOrEmpty(txtbox_Name.Text) || string.IsNullOrWhiteSpace(txtbox_Name.Text))
                    {
                        MessageBox.Show("常用SQL名称不能为空!");
                        txtbox_Name.Focus();
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(richtxtbox_Value.Text) || string.IsNullOrWhiteSpace(richtxtbox_Value.Text))
                        {
                            MessageBox.Show("常用SQL语句不能为空!");
                            richtxtbox_Value.Focus();
                        }
                        else
                        {
                            code  = txtbox_Code.Text.Trim();
                            name  = txtbox_Name.Text.Trim();
                            value = richtxtbox_Value.Text.Trim();

                            string result = ConfigSettings.setCommonlyUsedSQLCodeNameValue(code, name, value);

                            if (result == "新增成功")
                            {
                                MessageBox.Show(code + result);
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show(result);
                                txtbox_Code.Focus();
                                txtbox_Code.SelectAll();
                            }
                        }
                    }
                }
            }
            #endregion
            #region 非新增
            else
            {
                #region 编辑
                if (type == 1)//编辑
                {
                    if (string.IsNullOrEmpty(txtbox_Code.Text) || string.IsNullOrWhiteSpace(txtbox_Code.Text))
                    {
                        MessageBox.Show("常用SQL编码不能为空!");
                        txtbox_Code.Focus();
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(txtbox_Name.Text) || string.IsNullOrWhiteSpace(txtbox_Name.Text))
                        {
                            MessageBox.Show("常用SQL名称不能为空!");
                            txtbox_Name.Focus();
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(richtxtbox_Value.Text) || string.IsNullOrWhiteSpace(richtxtbox_Value.Text))
                            {
                                MessageBox.Show("常用SQL语句不能为空!");
                                richtxtbox_Value.Focus();
                            }
                            else
                            {
                                code  = txtbox_Code.Text.Trim();
                                name  = txtbox_Name.Text.Trim();
                                value = richtxtbox_Value.Text.Trim();

                                string result = ConfigSettings.editCommonlyUsedSQLCodeNameValue(code, name, value);

                                if (result == "修改成功")
                                {
                                    MessageBox.Show(code + result);
                                    this.Close();
                                }
                                else
                                {
                                    MessageBox.Show(result);
                                    txtbox_Name.Focus();
                                    txtbox_Name.SelectAll();
                                }
                            }
                        }
                    }
                }
                #endregion
                else
                {
                    MessageBox.Show("出错!");
                    this.Close();
                }
            }
            #endregion
        }