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 FrmWmsRecall : Form
    {//20151120
        DBOperator dbo = CStaticClass.dbo;

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

        public FrmWmsRecall()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {


            string CommomSql = "select control_apply_id as 申请ID,control_apply_type as 申请类型,device_code as 位置,stock_barcode as 条码,apply_task_status as 状态,create_time as 申请时间 from IO_CONTROL_APPLY order by create_time desc";

            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.tbApplyID.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString() + "";
            this.tbBarcode.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString() + "";
            this.tbStatus.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString() + "";
        }

        private void btSave_Click(object sender, EventArgs e)
        {
            if ((tbStatus.Text.Trim() == "") || (tbApplyID.Text == ""))
            {
                MessageBox.Show("保存失败!请右键选择记录并修改状态!", "操作提示:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            string sql = "update IO_CONTROL_APPLY set apply_task_status=" + tbStatus.Text.Trim() + " where control_apply_id=" + tbApplyID.Text;

            int i_ret = dbo.ExecuteSql(sql);
            if (i_ret == 1)
            {
                MessageBox.Show("保存成功!", "操作提示:");
                string CommomSql = "select control_apply_id as 申请ID,control_apply_type as 申请类型,device_code as 位置,stock_barcode as 条码,apply_task_status as 状态,create_time as 申请时间 from IO_CONTROL_APPLY order by create_time desc";

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

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