using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;


namespace OnlineStore.Common
{
    public class LineGetPosOp
    {
        public LineGetPosOp(string cids, string code)
        {
            this.cids = cids;
            this.code = code;
        }
        public string cids = "";
        public string code = "";
    }

    public class LineOperation
    {
        //  //{"result":"0","msg":"","pos":"11#AC1_18_4_28","barcode":"R506072019102200414","cid":"line-ac-11"}
        //    返回: {"code": 0, "msg":"ok", data:7}
        /// <summary>
        /// 0=成功
        /// </summary>
        public int result;
        public string cid;
        public string msg = "";
        public string pos = "";
        public string barcode = "";

    }
    /// <summary>
    /// 与服务器通信用对象
    /// </summary>
    public class Operation
    {
        /// <summary>
        /// 料仓唯一标识,分号分割
        /// </summary>
        private string _cid = "";
        public string cid
        {
            get { return _cid; }
            set { _cid = value; }
        }

        /// <summary>
        /// 请求序列号
        /// </summary>
        public int seq { get; set; }
        /// <summary>
        /// 操作码(0无操作(发送料仓状态给服务器),
        /// 1扫码入库(扫码成功后发送给服务器),
        /// 2 出库(服务器发送),3表示错误信息 )
        /// 4,发送给服务表示二维码扫码入库,收到开始扫码
        /// </summary>
        public int op { get; set; }
        /// <summary>
        /// 操作相关数据,
        /// op=1时,客户端发送 code 二维码给服务器,服务器返回时有:posId库位编号,plateW:料盘宽度,plateH:料盘高度
        /// 如果需要更新温湿度的报警值,服务器会发送alarmTemperature,alarmHumidity给客户端,客户端缓存,如果没有发送,不处理 
        /// op=3时,data发送BoxID和AlarmCode
        /// =4时扫码入库
        /// =5时服务器发送预警温度
        /// </summary>
        private Dictionary<string, string> _data = new Dictionary<string, string>();
        public Dictionary<string, string> data
        {
            get { return _data; }
            set { _data = value; }
        }
        //public Dictionary<String, Dictionary<String, String>> mimoOpMap = new Dictionary<string, Dictionary<string, string>>();
        /// <summary>
        /// agv的日志信息
        /// </summary>
        //public List<AgvLogInfo> logList = new List<AgvLogInfo>();
        /// <summary>
        /// 整体料仓状态
        /// 1=正常运行中
        /// 2=急停中
        /// 3=故障(气压检测不到等,用msg发送详细故障说明)
        /// 4=警告(用msg发送提醒,如出库到达工位但是没有工人操作)
        /// </summary>
        public int status { get; set; }
        /// <summary>
        /// 提示消息
        /// 出入库错误: BOX正在调试中,不能出入库
        /// 出入库错误: 急停了不能出入库
        /// 入库错误:料盘过大,放不到指定的位置中去
        /// 故障:气压信号检测不到
        /// 警告:出库盘到达工位但是没有工人操作
        /// </summary>
        public string msg { get; set; }
        //public Dictionary<string, string> msgData { get; set; } = new Dictionary<string, string>() { {"zh","" },{ "en", "" }, { "jp", "" } };
        public Dictionary<string, string> msgData { get; set; } = new Dictionary<string, string>();
        public string msgParam { get; set; }
        public string msgCode { get; set; }
        public string msgEn { get; set; }
        public string msgJp { get; set; }
        /// <summary>
        /// 包含的多个 BOX 的状态信息
        /// </summary>
        //public Dictionary<int, BoxStatus> boxStatus = new Dictionary<int, BoxStatus>();
        /// <summary>
        /// 报警集合
        /// </summary>
        public List<AlarmInfo> alarmList = new List<AlarmInfo>();

        public List<EquipMsg> showLogs = new List<EquipMsg>();
        public String type { get; set; } = "NS200";
    }
    /**
* agv日志信息
*/
    public class AgvLogInfo
    {
        /**
         * 消息字符串Code
         */
        public String msgCode { get; set; }
        /**
         * 消息内容
         */
        public String msg { get; set; }
        /**
         * 参数
         */
        public String[] msgParams { get; set; }
        /**
         * 出现时间
         */
        public long time { get; set; }
        public AgvLogInfo(string msg)
        {
            this.msgCode = msgCode;
            this.msg = msg;
            this.msgParams = msgParams;
            this.time = DateTime.Now.Ticks;
        }
    }
    /// <summary>
    /// 单台料仓状态(包含流水线)
    /// </summary>
    public class BoxStatus
    {
        /// <summary>
        /// Box编号,从1开始
        /// </summary>
        public int boxId { get; set; }
        /// <summary>
        /// 单台BOX状态
        /// 急停,故障,调试中,就绪状态(正常待机)
        /// 入库执行中,入库完成,入库失败
        /// 出库执行中,出库完成,出库失败
        /// </summary>
        public int status { get; set; }
        /// <summary>
        /// 单台BOX的消息
        /// 正在调试中,不能出入库
        /// 入库失败原因:
        /// 出库失败原因:
        /// </summary>
        public string msg { get; set; }
        /// <summary>
        /// 温度
        /// </summary>
        public string temperature { get; set; }
        /// <summary>
        /// 湿度
        /// </summary>
        public string humidity { get; set; }

        /// <summary>
        /// 操作相关数据,
        /// 出库完成后发送posId库位编号给服务器  
        /// 需要将打印数量和ng数量发送给服务器
        /// </summary>
        private Dictionary<string, string> _data = new Dictionary<string, string>();
        public Dictionary<string, string> data
        {
            get { return _data; }
            set { _data = value; }
        }
    }
    public class AlarmInfo
    {

        public AlarmInfo(int StoreID, int aType, string alarmDetial, string WarnMsg, int inoutStatus)
        {
            // TODO: Complete member initialization
            this.boxId = StoreID;
            this.alarmType = aType;
            this.alarmDetail = alarmDetial;
            this.alarmMsg = WarnMsg;
            this.inOutStatus = inoutStatus;
        }

        public AlarmInfo()
        {
            // TODO: Complete member initialization
        }
        /// <summary>
        /// 料仓ID,0表示流水线
        /// </summary>
        public int boxId { get; set; }
        /// <summary>
        /// 报警类型,
        /// </summary>
        public int alarmType { get; set; }
        /// <summary>
        /// 报警详情
        ///AlarmType= 0	消息	"1=原点返回
        //AlarmType= 0	消息   2=复位"
        //AlarmType=1	总体错误	"1=急停
        //AlarmType=1	总体错误    2=没有气压信号
        //AlarmType=1	总体错误,3=盘错乱"
        //AlarmType=2		运动轴错误	1=第一轴(旋转)
        //AlarmType=2		运动轴错误	2=第二轴(上下轴)
        //AlarmType=2		运动轴错误	3=第三轴(前进轴)
        //AlarmType=2		运动轴错误	4=第四轴(压紧轴)"
        //AlarmType=2 	电钢报警	    5=上下电钢
        //AlarmType=3		 IO报警,信号超时	io电器定义(电器定义)
        /// </summary>
        public string alarmDetail { get; set; }
        /// <summary>
        /// 报警消息
        /// </summary>
        public string alarmMsg { get; set; }
        /// <summary>
        /// 0,1=入库,2=出库
        /// </summary>
        public int inOutStatus { get; set; }
    }

    public class ParamDefine
    {
        /// <summary>
        /// 库位 ID
        /// </summary>
        public static string posId = "posId";
        /// <summary>
        /// 料盘宽
        /// </summary>
        public static string plateW = "plateW";
        /// <summary>
        /// 料盘高
        /// </summary>
        public static string plateH = "plateH";
        /// <summary>
        /// 料仓ID
        /// </summary>
        public static string storeId = "storeId";
        /// <summary>
        /// 报警码
        /// </summary>
        public static string alarmCode = "alarmCode";
        /// <summary>
        /// 报警详情或参数
        /// </summary>
        public static string alarmDetial = "alarmDetial";
        /// <summary>
        /// 湿度报警值
        /// </summary>
        public static string maxHumidity = "humi";
        /// <summary>
        /// 温度报警值
        /// </summary>
        public static string maxTemperature = "temp";

        /// <summary>
        /// urgentReel: true 表示紧急料,需要出到料串上
        /// </summary>
        public static string urgentReel = "urgentReel";
        /// <summary>
        /// cutReel: true 表示分盘料,需要出到料串上
        /// </summary>
        public static string cutReel = "cutReel";
        /// <summary>
        /// smallReel: true  小料(7x8),放置到小料串上
        /// </summary>
        public static string smallReel = "smallReel";
        /// <summary>
        /// rfid: 分配的料串RFID
        /// </summary>
        public static string rfid = "rfid";
        /// <summary>
        /// rfidLoc: 料串的架位,值为 - 1时,可以自由分配皮带线, 小料时,架位为1 - 46优先走1 / 2号皮带线,47 - 92优先走3 / 4号皮带线, 
        /// 70,71,72时只能分配到3 / 4号皮带线; 大料时,架位1 - 6优先走1 / 2号皮带线, 7 - 12优先走3 / 4号皮带线
        /// </summary>
        public static string rfidLoc = "rfidLoc";

        public static string barcode = "barcode";

        /// <summary>
        /// 贴标机交互按钮,出口 满料串取出
        /// </summary>
        public static string SendFullShelf = "SendFullShelf";
        /// <summary>
        /// 贴标机交互按钮,出口 空料串送入
        /// </summary>
        public static string NeedEmptySHelf = "NeedEmptySHelf";
        /// <summary>
        /// 贴标机交互按钮,入口 满料串送入
        /// </summary>
        public static string NeedFullShelf = "NeedFullShelf";
        /// <summary>
        /// 贴标机交互按钮,入口 空料串取出
        /// </summary>
        public static string SendEmptyShelf = "SendEmptyShelf";
        public static string doit = "doit";
        public static string disable = "disable";
        public static string enable = "enable";
    }

    /// <summary>
    /// 步骤消息类
    /// </summary>
    public class EquipMsg
    {
        /// <summary>
        /// 设备模块
        /// </summary>
        public String module;
        /// <summary>
        /// 消息类型,为:INFO,WARNING,ERROR,DATA
        /// </summary>
        //private String type;
        /// <summary>
        /// 中英文字符串 key
        /// </summary>
        public String msgCode;
        /// <summary>
        /// 消息内容
        /// </summary>
        public String msg;
        /// <summary>
        /// 参数
        /// </summary>
        public String[] msgParams;
    }

    public class NsMesInfo
    {
        private String status = "OK";

        private DateTime time;

        private String request = "";

        private String response = "";
    }

    public enum ShelfEnum
    {
        IDLE ,//= 空闲;
        LOADING,//= 入库中;
        UNLOADING,//= 出库中;
        NEED_EMPTY,//= 需要空料串出库;
        EMPTY_OUT,//= 空料串需要取走
        FULL_OUT,//= 满料串需要取走
    }

    public enum ShelfType
    {
        smallReel, 
        bigReel,
        tray
    }
}