Newer
Older
EMS_REFACTOR / FrmRegionType.cs
nn-203 on 26 Jul 2017 2 KB first commit
using System;
using System.Data;
using System.Windows.Forms;
using DevComponents.DotNetBar;

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