using RGD.DBUtility;
using System;
using System.Data;

namespace RGD.DataService
{
    /// <summary>
    /// 设备指令服务类
    /// </summary>
    public class MonitorTaskService
    {
        /// <summary>
        /// 获取指令队列里的箱条码
        /// </summary>
        /// <param name="Monitorindex"></param>
        /// <returns></returns>
        public string GetBarCodeFromMonitor(int Monitorindex)
        {
            object ob = DbHelperSQL.GetSingle("SELECT  F_TxtParam  FROM T_Monitor_Task WHERE (F_MonitorIndex = " + Monitorindex + ")");
            if (ob != null)
            {
                return ob.ToString();
            }
            else
            {
                return "0";
            }
        }

        /// <summary>
        /// 根据前面得到的MonitorIndex值取得"关联调度任务"
        /// </summary>
        /// <returns>关联调度任务索引，0表示没有 0就不会发送该指令</returns>
        public int GetAssociateMonitor(int MonitorIndex)
        {
            DataView dv;
            DataView dvv;
            try
            {
                string sql = "select F_Associate from T_Monitor_Task where (F_Associate IS NOT NULL) and F_MonitorIndex=" + MonitorIndex;
                dv = DbHelperSQL.Query(sql).Tables[0].DefaultView;
                if (dv.Count > 0)
                {
                    string sql1 = "select F_MonitorIndex from T_Monitor_Task where F_MonitorIndex=" + dv[0]["F_Associate"];
                    dvv = DbHelperSQL.Query(sql1).Tables[0].DefaultView;
                    if (dvv.Count > 0)
                    {
                        return Convert.ToInt32(dvv[0]["F_MonitorIndex"].ToString());
                    }
                    else
                    {
                        return 0;
                    }
                }
                else
                {
                    return 0;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dv = null;
                dvv = null;
            }
        }
    }
}