Newer
Older
GHFX_REFACTOR / FrmEquipmentEdit.cs
wxn on 28 Nov 2016 3 KB 管线定位
using System;
using System.Data;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace Cyberpipe
{
    public delegate void ReloadEquipmentGrid();
    public partial class FrmEquipmentEdit : Office2007Form
    {
        public event ReloadEquipmentGrid reloadGrid;

        private void InitForm()
        {
            String sql = "select t.username from patroler t";
            DataTable table = OracleUtils.ExecuteDataset(OracleUtils.ConnectionString, CommandType.Text, sql).Tables[0];
            comboPerson.DataSource = table;
        }

        private void restForm()
        {
            this.txtDescn.Text = "";
            this.txtMacId.Text = "";
            this.comboPerson.SelectedIndex = 0;
        }

        public FrmEquipmentEdit()
        {
            try
            {
                InitializeComponent();
                InitForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show("窗体加载失败:" + ex.ToString(), "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public FrmEquipmentEdit(String dbid, String macid, String username, String descn)
        {
            try
            {
                InitializeComponent();
                InitForm();
                this.labDBID.Text = dbid;
                this.txtMacId.Text = macid;
                this.comboPerson.SelectedValue = username;
                this.txtDescn.Text = descn;
            }
            catch (Exception ex)
            {
                MessageBox.Show("窗体加载失败:" + ex.ToString(), "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnSaveDev_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtMacId.Text))
            {
                MessageBox.Show("MAC地址不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMacId.Focus();
                return;
            }
            if (String.IsNullOrEmpty(comboPerson.Text))
            {
                MessageBox.Show("设备所有人不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                comboPerson.Focus();
                return;
            }
            try
            {
                if (String.IsNullOrEmpty(labDBID.Text.Trim()))
                {
                    String sql = "insert into equipment t (t.descirption,t.macid,t.owner,t.status) values ('" + txtDescn.Text.Trim() + "','" + txtMacId.Text.Trim() + "','" + comboPerson.SelectedValue.ToString() + "','USING')";
                    OracleUtils.ExecuteNonQuery(OracleUtils.ConnectionString, CommandType.Text, sql);
                    reloadGrid();
                }
                else
                {
                    String sql = "update equipment t set t.descirption='" + txtDescn.Text.Trim() + "',t.macid='" + txtMacId.Text.Trim() + "',t.owner='" + comboPerson.SelectedValue + "' where t.dbid=" + labDBID.Text.Trim();
                    OracleUtils.ExecuteNonQuery(OracleUtils.ConnectionString, CommandType.Text, sql);
                    reloadGrid();
                    this.Close();
                }
                restForm();
                MessageBox.Show("探测仪信息保存成功!", "结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("探测仪信息保存失败:" + ex.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}