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 DBFactory;

namespace wcfControlMonitorClient
{
    public partial class FrmDeskStatus : Form
    {
        DBOperator dbo = CStaticClass.dbo;

        private static FrmDeskStatus _formInstance;
        public static FrmDeskStatus FormInstance
        {
            get
            {
                if (_formInstance == null)
                {
                    _formInstance = new FrmDeskStatus();
                }
                return _formInstance;
            }
            set { _formInstance = value; }
        }
        public FrmDeskStatus()
        {
            InitializeComponent();
        }

        private void Form_Load(object sender, EventArgs e)
        {


            string CommomSql = "select DESKNO as 复合台索引, DESKINDEX as 站台编号, STATUS as 状态, IFDESKFULL as 满货标识 from T_DESK_STATUS";

            DataView dv = dbo.ExceSQL(CommomSql).Tables[0].DefaultView;
            this.dataGridView1.DataSource = dv;
        }

        private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if ((e.ColumnIndex >= 0) && (e.RowIndex >= 0) && (e.Button == MouseButtons.Right))
            {
                dataGridView1.ClearSelection();
                dataGridView1.Rows[e.RowIndex].Selected = true;
                dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];

            }
        }

        private void tsmEdit_Click(object sender, EventArgs e)
        {
            if (dataGridView1.RowCount <= 0)
            {
                return;
            }

            this.tbUserID.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            this.tbDeskNO.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
            this.tbStatus.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
        }

        private void btSave_Click(object sender, EventArgs e)
        {
            if ((tbStatus.Text.Trim() == "") || (tbUserID.Text == ""))
            {
                MessageBox.Show("保存失败!未选定待修改复核台!", "操作提示:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if ((tbStatus.Text != "0") && (tbStatus.Text != "1"))
            {
                MessageBox.Show("保存失败!状态只能为0或者1!", "操作提示:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            string sql = "update T_DESK_STATUS set STATUS=" + tbStatus.Text + " where DESKNO=" + tbUserID.Text;

            int i_ret = dbo.ExecuteSql(sql);
            if (i_ret == 1)
            {
                MessageBox.Show("保存成功!", "操作提示:");
                string CommomSql = "select DESKNO as 复合台索引, DESKINDEX as 站台编号, STATUS as 状态, IFDESKFULL as 满货标识 from T_DESK_STATUS";

                DataView dv = dbo.ExceSQL(CommomSql).Tables[0].DefaultView;
                this.dataGridView1.DataSource = dv;
            }
            else
            {
                MessageBox.Show("保存失败!", "操作提示:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void FrmLanePile_FormClosing(object sender, FormClosingEventArgs e)
        {
            _formInstance = null;
        }
    }
}