using RGD.DBUtility;
using RGD.MdsAPI;
using RGD.MdsAPI.WMS;
using System;
using System.Data;
using System.Windows.Forms;

namespace RGD.WCS
{
    public partial class FrmInterfaceRestart : Form
    {
        private static FrmInterfaceRestart _formInstance;

        public FrmInterfaceRestart()
        {
            InitializeComponent();
            _formInstance = this;
        }

        public static FrmInterfaceRestart FormInstance
        {
            get
            {
                if (_formInstance != null)
                {
                    _formInstance.Dispose();
                    _formInstance = null;
                }
                if (_formInstance == null)
                {
                    _formInstance = new FrmInterfaceRestart();
                }
                return _formInstance;
            }
            set { _formInstance = value; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox1.Text == null)
            {
                MessageBox.Show("请输入储位号");
                return;
            }
            string cell_num = textBox1.Text;
            string loc_num = Base.getWMS_LOC_NO(cell_num);
            DataView dv = DbHelperSQL.Query("select * from t_warehouse").Tables[0].DefaultView;
            string task_no = dv[0]["F_TASK_NO"].ToString();
            DataView tas = DbHelperSQL.Query("select * from t_manage_task where FSTARTCELL='" + cell_num + "'").Tables[0].DefaultView;

            string sResult = string.Empty;
            bool bResult = (new uploadStackIODet()).Notify(task_no, "01", cell_num, out sResult);
            if (bResult)
            {
                MessageBox.Show("出库成功");
                //DbHelperSQL.ExecuteSql("delete from t_manage_task where FSTARTCELL='" + cell_num + "'");
                // DbHelperSQL.ExecuteSql("delete from t_monitor_task where F_ManageTaskIndex='" + tas[0]["FID"].ToString() + "'");
            }
            else
            {
                MessageBox.Show("校验失败");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "" || textBox2.Text == null)
            {
                MessageBox.Show("请输入储位号");
                return;
            }
            string cell_num = textBox2.Text;
            string loc_num = Base.getWMS_LOC_NO(cell_num);
            DataView dv = DbHelperSQL.Query("select * from t_warehouse").Tables[0].DefaultView;
            string task_no = dv[0]["F_TASK_NO"].ToString();
            string sResult = string.Empty;
            bool bResult = (new uploadStackIODet()).Notify(task_no, "02", cell_num, out sResult);
            if (bResult)
            {
                MessageBox.Show("入库成功");
            }
            else
            {
                MessageBox.Show("校验失败");
            }
        }
    }
}