Newer
Older
GHFX_REFACTOR / FrmRegion.cs
wxn on 9 Nov 2016 2 KB 冗余代码整理
using System;
using System.Data;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace Cyberpipe
{
    public partial class FrmRegion : Office2007Form
    {
        string name;
        int regionType;
        int parentId;
        int id;
        public FrmRegion(int _rid,int _pid,int _id,string _name)
        {
            InitializeComponent();
            name = _name;
            parentId = _pid;
            id = _id;
            regionType = _rid;
        }
        /// <summary>
        /// 窗体初始化事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmRegion_Load(object sender, EventArgs e)
        {
            txtName.Text = name;
        }
        /// <summary>
        /// 确定按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX1_Click(object sender, EventArgs e)
        {
            try
            {
                if (id == -1)
                {
                    string sql = "select * from casic_region where \"name\" ='" + txtName.Text.Trim() + "'";
                    DataTable dt = OledbHelper.QueryTable(sql);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        MessageBox.Show("该部门信息已录入!");
                        return;
                    }
                    sql = "insert into casic_region(\"name\",\"parent\",\"rid\") values('" + txtName.Text.Trim() + "'," + parentId + "," + regionType + ")";
                    if (OledbHelper.sqlExecuteNonQuery(sql) > 0)
                    {
                        MessageBox.Show("保存成功!");
                        DialogResult = DialogResult.OK;
                    }
                }
                else
                {
                    string sql = "select * from casic_region where \"name\" ='" + txtName.Text.Trim() + "' and \"id\" <> " + id;
                    DataTable dt = OledbHelper.QueryTable(sql);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        MessageBox.Show("该部门信息已录入!");
                        return;
                    }
                    sql = "update casic_region set \"name\" ='" + txtName.Text.Trim() + "' where \"id\" =" + id;

                    if (OledbHelper.sqlExecuteNonQuery(sql) > 0)
                    {
                        MessageBox.Show("保存成功!");
                        DialogResult = DialogResult.OK;
                    }
                }
            }
            catch (Exception ex)
            {
                LogError.PublishError(ex);
            }
        }
        /// <summary>
        /// 窗体关闭按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}