using System;
using System.Data;
using System.Windows.Forms;
using CRVM.Utility;

namespace CRVM
{
    public partial class Statusmodify : Form
    {
        private LogicCon logicConn;
        public EDBItem Access
        {
            get;
            set;
        }
        public EDBItem Oracle
        {
            get;
            set;
        }
        public Statusmodify()
        {
            InitializeComponent();
        }
        private void DataBaseSql(LogicCon logicConn, string sql)
        {
            logicConn.DataBase(sql);
        }
        private void btnAccModify_Click(object sender, EventArgs e)
        {
            if (AccessEvent.Text == "1000"||AccessEvent.Text == "2000"||AccessEvent.Text == "3000")
            {
                if (Access.DataType == "" || Access.Password == "" || Access.Database == "")
                {
                    MessageBox.Show("请确认Access数据库信息是否输入完全");
                    this.Close();
                }
                else
                {
                    if (AccessStatus.Text == "" || AccessEvent.Text == "")
                    {
                        MessageBox.Show("请输入完整的修改数据");
                    }
                    else
                    {
                        ModifyStatus(Access);
                    }
                }
            }
            else if (AccessEvent.Text != "1000")
            {
                MessageBox.Show("找不到你所输入的事件");
            }
        }
        private void btnOraModify_Click(object sender, EventArgs e)
        {
            if (oracleEventno.Text != "4000")
            {
                MessageBox.Show("找不到你所输入的事件");
            }
            else
            {
                if (Oracle.Database == "" || Oracle.DataType == "" || Oracle.Ipaddress == "" || Oracle.Password == "" || Oracle.Userid == "")
                {
                    MessageBox.Show("请确认oracle数据库信息是否输入完全");
                    this.Close();
                }
                else
                {
                    if (oracleStatus.Text == "" || oracleEventno.Text == "")
                    {

                        MessageBox.Show("请输入完整的修改数据");
                    }
                    else
                    {
                        ModifyStatus(Oracle);
                    }
                }
            }
        }
        private void ModifyStatus(EDBItem conItem)
        {
            if (conItem.DataType == "oracle")
            {
                logicConn = new LogicCon(conItem, conItem.Userid);
                DataTable dt = new DataTable();
                string IsModify = string.Format("select * from T_STATUS where status={0} and eventno={1}", oracleStatus.Text, oracleEventno.Text);
                dt = logicConn.SelTableData("T_STATUS", IsModify);
                if (dt != null && dt.Rows.Count != 0)
                {
                    MessageBox.Show("请验证你输入需要修改的数据是否正确！");
                }
                else
                {
                    string update = string.Format("update T_STATUS set status={0} where eventno={1}", oracleStatus.Text, oracleEventno.Text);
                    DataBaseSql(logicConn, update);
                    dt = logicConn.SelTableData("T_STATUS", IsModify);
                    if (dt != null && dt.Rows.Count != 0)
                    {
                        MessageBox.Show("修改成功！");
                    }
                }
            }
            else if (conItem .DataType =="access")
            {
                logicConn = new LogicCon(conItem, conItem.Userid);
                DataTable dt = new DataTable();
                string IsModify = string.Format("select * from ZT_Inf where AlarmStatus={0} and Alarmevent={1}", AccessStatus.Text, AccessEvent.Text);
                dt = logicConn.SelTableData("ZT_Inf", IsModify);
                if (dt != null && dt.Rows.Count != 0)
                {
                    MessageBox.Show("请验证你输入需要修改的数据是否正确！");
                }
                else
                {
                    string update = string.Format("update ZT_Inf set AlarmStatus={0} where Alarmevent={1}", AccessStatus.Text, AccessEvent.Text);
                    DataBaseSql(logicConn, update);
                    dt = logicConn.SelTableData("ZT_Inf", IsModify);
                    if (dt != null && dt.Rows.Count != 0)
                    {
                        MessageBox.Show("修改成功！");
                    }
                }
            }
        }
    }
}
