Newer
Older
GHFX_REFACTOR / Backup / FrmAPP.cs
wxn on 2 Nov 2016 3 KB 提交
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
namespace Cyberpipe
{
    public partial class FrmAPP : Office2007Form
    {
        int id;
        public FrmAPP(int _id)
        {
            InitializeComponent();
            id = _id;
        }
        /// <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;
            }
            if (txtCode.Text.Trim() == "")
            {                
                MessageBox.Show("请输入分系统代号!");
                return;
            }
            string sql = "";
            if (id == -1)
            {
                sql = "select * from casic_app where \"code\" ='" + txtCode.Text.Trim() + "'";
                if (OledbHelper.QueryTable(sql).Rows.Count > 0)
                {
                    MessageBox.Show("该分系统代号信息已录入!");
                    return;
                }
                sql = "select * from casic_app where \"name\" ='" + txtName.Text.Trim() + "'";
                if (OledbHelper.QueryTable(sql).Rows.Count > 0)
                {
                    MessageBox.Show("该分系统名称信息已录入!");
                    return;
                }
                sql = "insert into casic_app(\"code\",\"name\") values('" + txtCode.Text.Trim() + "','" + txtName.Text.Trim() + "')";
            }
            else
            {
                sql = "select * from casic_app where \"code\" ='" + txtCode.Text.Trim() + "' and \"name\"='" + txtName.Text.Trim() + "' and \"id\" <>" + id.ToString();
                if (OledbHelper.QueryTable(sql).Rows.Count > 0)
                {
                    MessageBox.Show("该分系统代号及名称的信息已录入!");
                    return;
                }
                sql = "update casic_app set \"code\" ='" + txtCode.Text.Trim() + "',\"name\"='" + txtName.Text.Trim() + "' where \"id\" =" + id.ToString();
            }
            try
            {
                if (OledbHelper.sqlExecuteNonQuery(sql) > 0)
                {
                    MessageBox.Show("保存成功!", "提示");
                    DialogResult = DialogResult.OK;
                    Close();
                }
            }
            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();
        }
        DataTable table;
        /// <summary>
        /// 窗体初始化事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmAPP_Load(object sender, EventArgs e)
        {
            if (id != -1)
            {
                Text = "添加分系统信息";
                buttonX1.Text = "保存";
                string sql = "select * from casic_app where \"id\" =" + id.ToString();
                table = OledbHelper.QueryTable(sql);
                if (table != null)
                {
                    if (table.Rows.Count > 0)
                    {
                        txtCode.Text = table.Rows[0]["code"].ToString().Trim(); 
                        txtName.Text = table.Rows[0]["name"].ToString();
                    }

                }
            }
        }
    }
}