using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
//using System.Windows.Forms;

namespace bizFacade//MESPC
{
    /// <summary>
    /// 
    /// </summary>
    public class MaterialData
    {
        /// <summary>
        /// 验证物料全部信息（包括订单信息、验证物料信息）
        /// 用来保存到数据库表[MES_装配数据_零部件追溯]
        /// </summary>
        public static DataTable MaterialTableForSave=null;
        /// <summary>
        /// [MES_计划BOM_发动机订单计划]
        /// </summary>
        public static DataTable dt_OrderFormPlan=null;
        /// <summary>
        /// [MES_计划BOM_发动机号]
        /// </summary>
        public static DataTable dt_EngineNumber=null;
        /// <summary>
        /// 原始物料表
        /// </summary>
        public static DataTable dt_Material=null;
        /// <summary>
        /// 需要验证的物料表
        /// </summary>
        public static DataTable dt_Material_Verify=null;
        /// <summary>
        /// 需要强制验证的物料表
        /// </summary>
        public static DataTable dt_MaterialUnchecked=null;
        /// <summary>
        /// ID
        /// 物料号表索引号
        /// </summary>
        public static string MaterialIndexField = "物料号表索引号";
        /// <summary>
        /// 上线工位追溯代码
        /// </summary>
        public static string FirstOpNameTraceCodeField = "上线工位追溯代码";
        /// <summary>
        /// 上线工位追溯代码
        /// </summary>
        public static int firstOpNameTraceCode;

        /// <summary>
        /// 追溯代码
        /// </summary>
        public static int traceID ;

        /// <summary>
        /// 1：设备返修
        /// 2：MES放行
        /// </summary>
        public static string RepairReasonID = "1";
        /// <summary>
        /// 1：设备返修
        /// 2：MES放行
        /// </summary>
        public static string RepairReasonText = "设备返修";

        
        /// <summary>
        /// 订单号traceID
        /// </summary>
        public static string OrderFormField = "订单号";
        /// <summary>
        /// 订单号
        /// </summary>
        public static string orderForm;
        /// <summary>
        /// 主配厂家
        /// </summary>
        public static string MainPruduceFatoryField = "主配厂家";
        /// <summary>
        /// 主配厂家
        /// </summary>
        public static string mainPruduceFatory ;
        /// <summary>
        /// 订单计划发动机号
        /// </summary>
        public static string EngineNumber_OrderPlanField = "订单计划发动机号";
        /// <summary>
        /// 订单计划发动机号
        /// </summary>
        public static string engineNumber_OrderPlan;
        /// <summary>
        /// 发动机号
        /// </summary>
        public static string EngineNumberField = "发动机号";
        /// <summary>
        /// 发动机号
        /// </summary>
        public static string engineNumber;
        /// <summary>
        /// 追踪代码
        /// </summary>
        public static string EngineTraceCodeField = "追踪代码";
        /// <summary>
        /// 追踪代码
        /// </summary>
        public static string engineTraceCode;

        
        /// <summary>
        /// 工位号
        /// </summary>
        public static string OpNameField = "工位号";
        /// <summary>
        /// 工位号
        /// </summary>
        public static string opName;
        /// <summary>
        /// 到达时间
        /// </summary>
        public static string CycleActualCycleTime = "实际循环时间";
        /// <summary>
        /// 到达时间
        /// </summary>
        public static int cycleActualCycleTime;
        /// <summary>
        /// 到达时间
        /// </summary>
        public static string ArrivedTimeField = "到达时间";
        /// <summary>
        /// 到达时间
        /// </summary>
        public static DateTime arrivedTime;
        /// <summary>
        /// 离开时间
        /// </summary>
        public static string LeavedTimeField = "离开时间";
        /// <summary>
        /// 离开时间
        /// </summary>
        public static DateTime leavedTime;
        /// <summary>
        /// 操作者工号
        /// </summary>
        public static string OperatorCodeField = "操作者工号";
        /// <summary>
        /// 操作者工号
        /// </summary>
        public static string operatorCode;
        /// <summary>
        /// 操作者姓名
        /// </summary>
        public static string OperatorNameField = "操作者姓名";
        /// <summary>
        /// 操作者姓名
        /// </summary>
        public static string operatorName;
        /// <summary>
        /// 班次代码
        /// </summary>
        public static string OperatorShiftField = "班次代码";
        /// <summary>
        /// 班次代码
        /// </summary>
        public static string operatorShift;
        /// <summary>
        /// 班次名称
        /// </summary>
        public static string OperatorShiftNameField = "班次名称";
        /// <summary>
        /// 班次名称
        /// </summary>
        public static string operatorShiftName;
        /// <summary>
        /// 工位名称
        /// </summary>
        public static string PositionIDNameField = "工位名称";
        /// <summary>
        /// 工位名称
        /// </summary>
        public static string positionIDName;
        /// <summary>
        /// SAP物料号
        /// </summary>
        public static string SAPMaterialNumberField = "SAP物料号";
        /// <summary>
        /// SAP物料号
        /// </summary>
        public static string sAPMaterialNumber;
        /// <summary>
        /// 发动机型号
        /// </summary>
        public static string EngineNumberTypeField = "发动机型号";
        /// <summary>
        /// 发动机型号
        /// </summary>
        public static string engineNumberType;
        /// <summary>
        /// 发动机型号代码
        /// </summary>
        public static string EngineNumberCodeField = "发动机型号代码";
        ///// <summary>
        ///// 发动机型号代码
        ///// </summary>
        //public static string EngineNumberTypeCodeField = "发动机型号代码";
        /// <summary>
        /// 发动机型号代码
        /// </summary>
        public static int engineNumberCode;
        ///// <summary>
        ///// 发动机型号代码
        ///// </summary>
        //public static int engineNumberTypeCode;
        /// <summary>
        /// 发动机机型
        /// </summary>
        public static string EngineNumberBasicTypeField = "发动机机型";
        /// <summary>
        /// 发动机机型
        /// </summary>
        public static string engineNumberBasicType;
        /// <summary>
        /// 发动机数量
        /// </summary>
        public static string EngineCountField = "发动机数量";
        /// <summary>
        /// 发动机数量
        /// </summary>
        public static string engineCount;
        /// <summary>
        /// 厂牌编号起始号
        /// </summary>
        public static string EngineNumberFirstIDField = "厂牌编号起始号";
        /// <summary>
        /// 厂牌编号起始号
        /// </summary>
        public static string engineNumberFirstID;
        /// <summary>
        /// 客户名称
        /// </summary>
        public static string CustomesNameField = "客户名称";
        /// <summary>
        /// 客户名称
        /// </summary>
        public static string customesName;
        /// <summary>
        /// 投料日期
        /// </summary>
        public static string PrepareMaterialDateTimeField = "投料日期";
        /// <summary>
        /// 投料日期
        /// </summary>
        public static DateTime prepareMaterialDateTime;
        /// <summary>
        /// 文件编号
        /// </summary>
        public static string FileCodeField = "文件编号";
        /// <summary>
        /// 文件编号
        /// </summary>
        public static string fileCode;
        /// <summary>
        /// 集团名称
        /// </summary>
        public static string GroupNameField = "集团名称";
        /// <summary>
        /// 集团名称
        /// </summary>
        public static string groupName;
        /// <summary>
        /// 通知号
        /// </summary>
        public static string NotifyCodeField = "通知号";
        /// <summary>
        /// 通知号
        /// </summary>
        public static string notifyCode;
        /// <summary>
        /// 功率
        /// </summary>
        public static string N_ForceField = "功率";
        /// <summary>
        /// 功率
        /// </summary>
        public static string n_Force;
        /// <summary>
        /// 指南文件编号
        /// </summary>
        public static string DirectFileCodeField = "指南文件编号";
        /// <summary>
        /// 指南文件编号
        /// </summary>
        public static string directFileCode;
        /// <summary>
        /// 装机状态
        /// </summary>
        public static string WorkEngineStatusField = "装机状态";
        /// <summary>
        /// 装机状态
        /// </summary>
        public static string workEngineStatus;
        /// <summary>
        /// 适用状态
        /// </summary>
        public static string AdaptDateTimeField = "适用状态";
        /// <summary>
        /// 适用状态
        /// </summary>
        public static DateTime adaptDateTime;
        /// <summary>
        /// 订单装配指导
        /// </summary>
        public static string OrderFormDirectField = "订单装配指导";
        /// <summary>
        /// 物料描述
        /// </summary>
        public static string MaterialDescriptField = "物料描述";
        /// <summary>
        /// 物料描述
        /// </summary>
        public static string materialDescript;
        /// <summary>
        /// 计划下达日期
        /// </summary>
        public static string PlanSendedDateTimeField = "计划下达日期";
        /// <summary>
        /// 计划下达日期
        /// </summary>
        public static DateTime planSendedDateTime;
        /// <summary>
        /// 计划完工日期
        /// </summary>
        public static string PlanFinishDateTimeField = "计划完工日期";
        /// <summary>
        /// 计划完工日期
        /// </summary>
        public static DateTime planFinishDateTime;
        /// <summary>
        /// 生产厂家
        /// </summary>
        public static string ProduceFatoryField = "生产厂家";
        /// <summary>
        /// 生产厂家
        /// </summary>
        public string produceFatory;
        /// <summary>
        /// 零件类型
        /// </summary>
        public static string PartTypeField = "零件类型";
        /// <summary>
        /// 零件类型
        /// </summary>
        public static int partType;
        /// <summary>
        /// 是否合格
        /// </summary>
        public static int isGoodQuality;


        
        
        /// <summary>
        /// 物料号
        /// </summary>
        public static string MaterialNumberField = "物料号";
        /// <summary>
        /// 物料号
        /// </summary>
        public string materialNumber;
        /// <summary>
        /// 主物料号
        /// </summary>
        public static string MainMaterialNumberField = "主物料号";
        /// <summary>
        /// 主物料号
        /// </summary>
        public static string mainMaterialNumber;
        /// <summary>
        /// 零件图号
        /// </summary>
        public static string PartDrawNumberField = "零件图号";
        /// <summary>
        /// 零件图号
        /// </summary>
        public string partDrawNumber;
        /// <summary>
        /// 零件名称
        /// </summary>
        public static string PartDrawNameField = "零件名称";
        /// <summary>
        /// 零件名称
        /// </summary>
        public string partDrawName;
        /// <summary>
        /// 零件数量
        /// </summary>
        public static string PartCountField = "零件数量";
        /// <summary>
        /// 零件数量
        /// </summary>
        public int partCount;
        /// <summary>
        /// 零件数量验证
        /// </summary>
        public static string PartCountVerifyField = "零件数量验证";
        /// <summary>
        /// 零件数量验证
        /// </summary>
        public int partCountVerify;
        /// <summary>
        /// 是否扫描
        /// =1需要扫描
        /// =0不需要扫描
        /// </summary>
        public static string MaterialTraceField = "是否扫描";
        /// <summary>
        /// 是否扫描
        /// =0需要扫描
        /// =1不需要扫描
        /// </summary>
        public int materialTrace;
        /// <summary>
        /// 扫描方式
        /// =0，多个零件只扫描一次
        /// =1，几个零件只扫描几次，分别进行扫描。
        /// </summary>
        public static string MaterialVerifyIDField = "扫描方式";
        /// <summary>
        /// 扫描方式
        /// </summary>
        public int materialVerifyID;
        /// <summary>
        /// 是否主物料
        /// =0，否主物料
        /// =1，是主物料
        /// </summary>
        public static string IsMainMaterialField = "是否主物料";
        /// <summary>
        /// 是否主物料
        /// </summary>
        public static int isMainMaterial;
        /// <summary>
        /// 厂家代码
        /// </summary>
        public static string ProduceFatoryCodeField = "厂家代码";
        /// <summary>
        /// 厂家代码
        /// </summary>
        public string produceFatoryCode;
        /// <summary>
        /// 物料条码
        /// </summary>
        public static string BarCodeField = "物料条码";
        /// <summary>
        /// 物料条码
        /// </summary>
        public string barCode;
        /// <summary>
        /// 物料条码物料号
        /// </summary>
        public static string BarCode_MaterialField = "物料条码物料号";
        /// <summary>
        /// 物料条码物料号
        /// </summary>
        public string barCode_Material;
        /// <summary>
        /// 物料条码批次
        /// </summary>
        public static string BarCode_SerailNumberField = "物料条码批次";
        /// <summary>
        /// 物料条码批次
        /// </summary>
        public string barCode_SerailNumber;
        /// <summary>
        /// 验证结果
        /// 验证结果
        /// 验证结果 CheckState.Unchecked  0没有验证
        /// 验证结果 CheckState.Checked 1 已经验证
        /// 验证结果 CheckState.Indeterminate 2 已经强制验证
        /// </summary>
        public static string MaterialVerifyResultField = "验证结果";


        /// <summary>
        /// 强制验证原因
        /// </summary>
        public static string MaterialVerifyReasonField = "强制验证原因";


        /// <summary>
        /// 登录时间
        /// </summary>
        public static string OperatorLoginTimeField = "登录时间";
        /// <summary>
        /// 登录时间
        /// </summary>
        public static DateTime operatorLoginTime;
        /// <summary>
        /// 退出时间
        /// </summary>
        public static string OperatorLogoutTimeField = "退出时间";
        /// <summary>
        /// 退出时间
        /// </summary>
        public static DateTime operatorLogoutTime;



        

            
        /// <summary>
        /// 验证   选项
        /// </summary>
        public static string MaterialVerifySelectField = "验证";
        /// <summary>
        /// 日实际产量
        /// </summary>
        public static string DayActualCountField = "日实际产量";
        /// <summary>
        /// 日实际产量
        /// </summary>
        public static int dayActualCount;


        /// <summary>
        /// 日计划产量
        /// </summary>
        public static string DayPlanCountField = "日计划产量";
        /// <summary>
        /// 返修标志
        /// 0 装配正常  ； 1 需要返修
        /// </summary>
        public static int isRepairID;
        /// <summary>
        /// 返修标志
        /// </summary>
        public static string IsRepairIDField = "返修标志";
        /// <summary>
        /// 日计划产量
        /// </summary>
        public static int dayPlanCount;




        /// <summary>
        /// ID
        /// </summary>
        public static int ID;
        ///// <summary>
        ///// 发动机机型
        ///// </summary>
        //public static string engineNumberBasicType;

        /// <summary>
        /// 物料号表索引号确认
        /// </summary>
        public static int materialIndexConfirm;
        /// <summary>
        /// 物料号确认
        /// </summary>
        public static string materialNumberConfirm;
        /// <summary>
        /// 物料条码确认(待强制确认物料条码号)
        /// </summary>
        public static string barCodeInputForConfirm;
        /// <summary>
        /// 物料条码物料号(待强制确认物料条码号)
        /// </summary>
        public static string barCode_MaterialInputForConfirm;
        /// <summary>
        /// 物料条码批次(待强制确认物料条码号)
        /// </summary>
        public static string barCode_SerailNumberInputForConfirm;
        /// <summary>
        /// 物料条码确认
        /// </summary>
        public static string barCodeConfirm;
        /// <summary>
        /// 物料条码物料号确认
        /// </summary>
        public static string barCode_MaterialConfirm;
        /// <summary>
        /// 物料条码批次确认
        /// </summary>
        public static string barCode_SerailNumberConfirm;
        /// <summary>
        /// 物料号表索引号
        /// </summary>
        public static int materialIndex;

        /// <summary>
        /// 验证结果
        /// 验证结果
        /// 验证结果 CheckState.Unchecked  0没有验证
        /// 验证结果 CheckState.Checked 1 已经验证
        /// 验证结果 CheckState.Indeterminate 2 已经强制验证
        /// </summary>
        public int materialVerifyResult;
        /// <summary>
        /// 强制验证原因
        /// </summary>
        public static string materialVerifyReason;

        /// <summary>
        /// 创建需要验证的物料表
        /// </summary>
        /// <returns></returns>
        public static DataTable MaterialTable()
        {
            DataTable dt;
            DataColumn dc;
            dt = new DataTable();
            
            // <summary>
            // 物料号表索引号
            // </summary>
            dc = new DataColumn(MaterialIndexField, typeof(Int32));
            dt.Columns.Add(dc);

            // <summary>
            // 订单号
            // </summary>
            dc = new DataColumn(OrderFormField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 主配厂家
            // </summary>
            dc = new DataColumn(MainPruduceFatoryField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 发动机号
            // </summary>
            dc = new DataColumn(EngineNumberField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 发动机型号代码
            // </summary>
            dc = new DataColumn(EngineNumberCodeField, typeof(Int32));
            dt.Columns.Add(dc);
            // <summary>
            // 工位号
            // </summary>
            dc = new DataColumn(OpNameField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 工位名称
            // </summary>
            dc = new DataColumn(PositionIDNameField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  SAP物料号
            // </summary>
            dc = new DataColumn(SAPMaterialNumberField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  发动机型号
            // </summary>
            dc = new DataColumn(EngineNumberTypeField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  发动机机型
            // </summary>
            dc = new DataColumn(EngineNumberBasicTypeField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  客户名称
            // </summary>
            dc = new DataColumn(CustomesNameField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  投料日期
            // </summary>
            dc = new DataColumn(PrepareMaterialDateTimeField, typeof(DateTime));
            dt.Columns.Add(dc);
            // <summary>
            //  文件编号
            // </summary>
            dc = new DataColumn(FileCodeField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  集团名称
            // </summary>
            dc = new DataColumn(GroupNameField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  通知号
            // </summary>
            dc = new DataColumn(NotifyCodeField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  功率
            // </summary>
            dc = new DataColumn(N_ForceField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  指南文件编号
            // </summary>
            dc = new DataColumn(DirectFileCodeField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  装机状态
            // </summary>
            dc = new DataColumn(WorkEngineStatusField, typeof(DateTime));
            dt.Columns.Add(dc);
            // <summary>
            //  适用状态
            // </summary>
            dc = new DataColumn(AdaptDateTimeField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  订单装配指导
            // </summary>
            dc = new DataColumn(OrderFormDirectField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  物料描述
            // </summary>
            dc = new DataColumn(MaterialDescriptField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            //  计划下达日期
            // </summary>
            dc = new DataColumn(PlanSendedDateTimeField, typeof(DateTime));
            dt.Columns.Add(dc);
            // <summary>
            // 物料号
            // </summary>
            dc = new DataColumn(MaterialNumberField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 零件图号
            // </summary>
            dc = new DataColumn(PartDrawNumberField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 零件名称
            // </summary>
            dc = new DataColumn(PartDrawNameField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 零件数量
            // </summary>
            dc = new DataColumn(PartCountField, typeof(Int32));
            dt.Columns.Add(dc);
            // <summary>
            // 零件数量验证
            // </summary>
            dc = new DataColumn(PartCountVerifyField, typeof(Int32));
            dt.Columns.Add(dc);
            // <summary>
            // 是否扫描
            // </summary>
            dc = new DataColumn(MaterialTraceField, typeof(Int32));
            dt.Columns.Add(dc);
            // <summary>
            // 扫描方式
            // </summary>
            dc = new DataColumn(MaterialVerifyIDField, typeof(Int32));
            dt.Columns.Add(dc);
            // <summary>
            // 厂家代码
            // </summary>
            dc = new DataColumn(ProduceFatoryCodeField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 生产厂家
            // </summary>
            dc = new DataColumn(ProduceFatoryField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 物料条码
            // </summary>
            dc = new DataColumn(BarCodeField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 物料条码物料号
            // </summary>
            dc = new DataColumn(BarCode_MaterialField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 物料条码批次
            // </summary>
            dc = new DataColumn(BarCode_SerailNumberField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 验证结果
            // 验证结果
            // 验证结果 CheckState.Unchecked  0没有验证
            // 验证结果 CheckState.Checked 1 已经验证
            // 验证结果 CheckState.Indeterminate 2 已经强制验证
            // </summary>
            dc = new DataColumn(MaterialVerifyResultField, typeof(Int32));
            dt.Columns.Add(dc);
            // <summary>
            // 强制验证原因
            // </summary>
            dc = new DataColumn(MaterialVerifyReasonField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 操作者工号
            // </summary>
            dc = new DataColumn(OperatorCodeField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 操作者姓名
            // </summary>
            dc = new DataColumn(OperatorNameField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 班次代码
            // </summary>
            dc = new DataColumn(OperatorShiftField, typeof(string));
            dt.Columns.Add(dc);

            // <summary>
            // 验证
            // </summary>
            dc = new DataColumn(MaterialVerifySelectField, typeof(string));
            dt.Columns.Add(dc);
            // <summary>
            // 返修标志
            // </summary>
            dc = new DataColumn(IsRepairIDField, typeof(int));
            dt.Columns.Add(dc);

            //DataTable dt;
            //DataColumn dc;
            //dt = new DataTable();

            return dt;
        }

        /// <summary>
        /// 获得需要强制验证的物料表，条件："验证结果 = 0"
        /// 验证结果 CheckState.Unchecked  0没有验证
        /// 验证结果 CheckState.Checked 1 已经验证
        /// 验证结果 CheckState.Indeterminate 2 已经强制验证
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DataTable GetVerifyBarCodeTableUnchecked(DataTable dt)
        {
            DataTable dt_MaterialUnchecked;
            DataRow dr;
            DataRow[] drs;
            dt_MaterialUnchecked = MaterialData.MaterialTable();

            drs = dt.Select("验证结果 = 0");
            for (int i = 0; i < drs.Length; i++)
            {
                dr = dt_MaterialUnchecked.NewRow();
                MaterialTableSetDataRowValue(drs[i], dr);
                dt_MaterialUnchecked.Rows.Add(dr);
            }

            return dt_MaterialUnchecked;
        }



        /// <summary>
        /// 初始化物料表行赋值
        /// </summary>
        /// <param name="index"></param>
        /// <param name="dr"></param>
        /// <param name="drOut"></param>
        public static void MaterialTableSetDataRowValue(int index, DataRow dr, DataRow drOut)
        {
            if (dr == null) return;
            try
            {
                // <summary>
                // 物料号表索引号
                // </summary>
                drOut[MaterialIndexField] = index;
                // <summary>
                // 订单号
                // </summary>
                drOut[OrderFormField] = orderForm;

                // <summary>
                // 发动机号
                // </summary>
                drOut[EngineNumberField] = engineNumber;
                // <summary>
                // 发动机型号代码
                // </summary>
                drOut[EngineNumberCodeField] = engineNumberCode;
                // <summary>
                // 工位号
                // </summary>
                drOut[OpNameField] = opName;
                // <summary>
                // 工位名称
                // </summary>
                drOut[PositionIDNameField] = positionIDName;
                // <summary>
                // 物料号
                // </summary>
                drOut[MaterialNumberField] = dr[MaterialNumberField];
                // <summary>
                // 零件图号
                // </summary>
                drOut[PartDrawNumberField] = dr[PartDrawNumberField];
                // <summary>
                // 零件名称
                // </summary>
                drOut[PartDrawNameField] = dr[PartDrawNameField];
                // <summary>
                // 零件数量
                // </summary>
                drOut[PartCountField] = dr[PartCountField];
                // <summary>
                // 生产厂家
                // </summary>
                drOut[ProduceFatoryField] = dr[ProduceFatoryField];
                // <summary>
                // 厂家代码
                // </summary>
                drOut[ProduceFatoryCodeField] = dr[ProduceFatoryCodeField];
                // <summary>
                // 是否扫描
                // </summary>
                drOut[MaterialTraceField] = dr[MaterialTraceField];
                // <summary>
                // 扫描方式
                // </summary>
                drOut[MaterialVerifyIDField] = dr[MaterialVerifyIDField];

                // <summary>
                // 操作者工号
                // </summary>
                drOut[OperatorCodeField] = operatorCode;
                // <summary>
                // 操作者姓名
                // </summary>
                drOut[OperatorNameField] = operatorName;
                // <summary>
                // 班次代码
                // </summary>
                drOut[OperatorShiftField] = operatorShift;

                // <summary>
                // 验证结果
                // 验证结果
                // 验证结果 CheckState.Unchecked  0没有验证
                // 验证结果 CheckState.Checked 1 已经验证
                // 验证结果 CheckState.Indeterminate 2 已经强制验证
                drOut[MaterialVerifyResultField] = 0;
                drOut[MaterialVerifyIDField] = dr[MaterialVerifyIDField];
                // <summary>
                // 强制验证原因
                // </summary>
                drOut[MaterialVerifyReasonField] = "";
                //
                drOut[MaterialVerifySelectField] = "选择";

            }
            catch
            {
                //MessageBox.Show(err.Message);
            }

        }
        /// <summary>
        /// 物料表行赋值
        /// </summary>
        /// <param name="dr"></param>
        /// <param name="drOut"></param>
        public static void MaterialTableSetDataRowValue(DataRow dr, DataRow drOut)
        {
            if (dr == null) return;
            try
            {
                // <summary>
                // 物料号表索引号
                // </summary>
                drOut[MaterialIndexField] = dr[MaterialIndexField];
                // <summary>
                // 订单号
                // </summary>
                drOut[OrderFormField] = dr[OrderFormField];

                // <summary>
                // 发动机型号
                // </summary>
                drOut[EngineNumberField] = dr[EngineNumberField];
                // <summary>
                // 发动机型号代码
                // </summary>
                drOut[EngineNumberCodeField] = dr[EngineNumberCodeField];
                // <summary>
                // 工位号
                // </summary>
                drOut[OpNameField] = dr[OpNameField];
                // <summary>
                // 工位名称
                // </summary>
                drOut[PositionIDNameField] = dr[PositionIDNameField];
                // <summary>
                // 物料号
                // </summary>
                drOut[MaterialNumberField] = dr[MaterialNumberField];
                // <summary>
                // 零件图号
                // </summary>
                drOut[PartDrawNumberField] = dr[PartDrawNumberField];
                // <summary>
                // 零件名称
                // </summary>
                drOut[PartDrawNameField] = dr[PartDrawNameField];
                // <summary>
                // 零件数量
                // </summary>
                drOut[PartCountField] = dr[PartCountField];
                // <summary>
                // 零件数量验证
                // </summary>
                drOut[PartCountVerifyField] = dr[PartCountVerifyField];
                // <summary>
                // 生产厂家
                // </summary>
                drOut[ProduceFatoryField] = dr[ProduceFatoryField];
                // <summary>
                // 厂家代码
                // </summary>
                drOut[ProduceFatoryCodeField] = dr[ProduceFatoryCodeField];
                // <summary>
                // 物料条码
                // </summary>
                drOut[BarCodeField] = dr[BarCodeField];
                // <summary>
                // 物料条码物料号
                // </summary>
                drOut[BarCode_MaterialField] = dr[BarCode_MaterialField];
                // <summary>
                // 物料条码批次
                // </summary>
                drOut[BarCode_SerailNumberField] = dr[BarCode_SerailNumberField];
                // <summary>
                // 是否扫描
                // </summary>
                drOut[MaterialTraceField] = dr[MaterialTraceField];
                // <summary>
                // 扫描方式
                // </summary>
                drOut[MaterialVerifyIDField] = dr[MaterialVerifyIDField];

                // <summary>
                // 操作者工号
                // </summary>
                drOut[OperatorCodeField] = dr[OperatorCodeField];
                // <summary>
                // 操作者姓名
                // </summary>
                drOut[OperatorNameField] = dr[OperatorNameField];
                // <summary>
                // 班次代码
                // </summary>
                drOut[OperatorShiftField] = dr[OperatorShiftField];

                // <summary>
                // 验证结果
                // 验证结果
                // 验证结果 CheckState.Unchecked  0没有验证
                // 验证结果 CheckState.Checked 1 已经验证
                // 验证结果 CheckState.Indeterminate 2 已经强制验证
                drOut[MaterialVerifyResultField] = dr[MaterialVerifyResultField];
                // <summary>
                // 强制验证原因
                // </summary>
                drOut[MaterialVerifyReasonField] = dr[MaterialVerifyReasonField];
                //验证
                //drOut[MaterialVerifySelectField] = dr[MaterialVerifySelectField];

            }
            catch
            {
                
                //MessageBox.Show(err.Message);
            }

        }

        /// <summary>
        /// 获得index行对应的数据
        /// </summary>
        /// <param name="index"></param>
        public void MaterialTable(int index)
        {
            DataTable dt = dt_Material_Verify;
            DataRow[] dr;
            dr = dt.Select(MaterialIndexField + "= " + index.ToString());
            if (dr == null) return;

            // <summary>
            // 物料号表索引号
            // </summary>
            materialIndex = (int)dr[0][MaterialIndexField];
            // <summary>
            // 订单号
            // </summary>
            orderForm = dr[0][OrderFormField].ToString();

            // <summary>
            // 发动机型号
            // </summary>
            engineNumber = dr[0][EngineNumberField].ToString();
            // <summary>
            // 发动机型号代码
            // </summary>
            engineNumberCode = (int)dr[0][EngineNumberCodeField];
            // <summary>
            // 工位号
            // </summary>
            opName = dr[0][OpNameField].ToString();
            // <summary>
            // 工位名称
            // </summary>
            positionIDName = dr[0][PositionIDNameField].ToString();
            // <summary>
            // 物料号
            // </summary>
            materialNumber = dr[0][MaterialNumberField].ToString();
            // <summary>
            // 零件图号
            // </summary>
            partDrawNumber = dr[0][PartDrawNumberField].ToString();
            // <summary>
            // 零件名称
            // </summary>
            partDrawName = dr[0][PartDrawNameField].ToString();
            // <summary>
            // 零件数量
            // </summary>
            partCount = (int)dr[0][PartCountField];
            // <summary>
            // 零件数量验证
            // </summary>
            partCountVerify = (int)dr[0][PartCountVerifyField];
            // <summary>
            // 生产厂家
            // </summary>
            produceFatory = dr[0][ProduceFatoryField].ToString();
            // <summary>
            // 厂家代码
            // </summary>
            produceFatoryCode = dr[0][ProduceFatoryCodeField].ToString();
            // <summary>
            // 物料条码
            // </summary>
            barCode = dr[0][BarCodeField].ToString();
            // <summary>
            // 物料条码物料号
            // </summary>
            barCode_Material = dr[0][BarCode_MaterialField].ToString();
            // <summary>
            // 物料条码批次
            // </summary>
            barCode_SerailNumber = dr[0][BarCode_SerailNumberField].ToString();
            // <summary>
            // 是否扫描
            // </summary>
            materialTrace = (int)dr[0][MaterialTraceField];
            // <summary>
            // 扫描方式
            // </summary>
            materialVerifyID = (int)dr[0][MaterialVerifyIDField];
            // <summary>
            // 操作者工号
            // </summary>
            operatorCode = dr[0][OperatorCodeField].ToString();
            // <summary>
            // 操作者姓名
            // </summary>
            operatorName = dr[0][OperatorNameField].ToString();
            // <summary>
            // 班次代码
            // </summary>
            operatorShift = dr[0][OperatorShiftField].ToString();

            // <summary>
            // 验证结果
            // 验证结果
            // 验证结果 CheckState.Unchecked  0没有验证
            // 验证结果 CheckState.Checked 1 已经验证
            // 验证结果 CheckState.Indeterminate 2 已经强制验证
            materialVerifyResult = (int)dr[0][MaterialVerifyResultField];
            // <summary>
            // 强制验证原因
            // </summary>
            materialVerifyReason = dr[0][MaterialVerifyReasonField].ToString();

        }
        /// <summary>
        /// 分解条码，获得物料号和批次
        /// M/13009130/6800811001
        /// </summary>
        /// <param name="barCode">物料条码</param>
        /// <param name="barCode_Material">物料条码_物料号</param>
        /// <param name="barCode_SerailNumber">物料条码_批次</param>
        public static void SplitBarCode(string barCode, out string barCode_Material, out string barCode_SerailNumber)
        {
            barCode_Material = null;
            barCode_SerailNumber = null;
            try
            {
                string[] str = barCode.Split('/');
                if (str != null)
                {
                    if (str.Length >= 2)
                    {
                        try
                        {
                            barCode_Material = str[1];
                        }
                        catch { barCode_Material = ""; }
                        try
                        {
                            barCode_SerailNumber = str[2];
                        }
                        catch { barCode_SerailNumber = ""; }
                    }
                }
                
            }
            catch 
            {
                //MessageBox.Show(err.Message);

            }
        }

        ///// <summary>
        ///// 
        ///// </summary>
        //public static void CreateMaterialTableForSave()
        //{
        //    DataTable dt;
        //    DataColumn dc;
        //    dt = new DataTable();

        //    /// <summary>
        //    /// 订单号
        //    /// </summary>
        //    dc = new DataColumn(OrderFormField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 主配厂家
        //    /// </summary>
        //    dc = new DataColumn(MainPruduceFatoryField, typeof(string));
        //    dt.Columns.Add(dc);
        //   /// <summary>
        //    /// 发动机号
        //    /// </summary>
        //    dc = new DataColumn(EngineNumberField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 发动机型号代码
        //    /// </summary>
        //    dc = new DataColumn(EngineNumberCodeField, typeof(Int32));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 工位号
        //    /// </summary>
        //    dc = new DataColumn(OpNameField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 工位名称
        //    /// </summary>
        //    dc = new DataColumn(PositionIDNameField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  SAP物料号
        //    /// </summary>
        //    dc = new DataColumn(SAPMaterialNumberField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  发动机型号
        //    /// </summary>
        //    dc = new DataColumn(EngineNumberTypeField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  发动机机型
        //    /// </summary>
        //    dc = new DataColumn(EngineNumberBasicTypeField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  客户名称
        //    /// </summary>
        //    dc = new DataColumn(CustomesNameField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  投料日期
        //    /// </summary>
        //    dc = new DataColumn(PrepareMaterialDateTimeField, typeof(DateTime));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  文件编号
        //    /// </summary>
        //    dc = new DataColumn(FileCodeField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  集团名称
        //    /// </summary>
        //    dc = new DataColumn(GroupNameField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  通知号
        //    /// </summary>
        //    dc = new DataColumn(NotifyCodeField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  功率
        //    /// </summary>
        //    dc = new DataColumn(N_ForceField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  指南文件编号
        //    /// </summary>
        //    dc = new DataColumn(DirectFileCodeField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  装机状态
        //    /// </summary>
        //    dc = new DataColumn(WorkEngineStatusField, typeof(DateTime));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  适用状态
        //    /// </summary>
        //    dc = new DataColumn(AdaptDateTimeField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  订单装配指导
        //    /// </summary>
        //    dc = new DataColumn(OrderFormDirectField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  物料描述
        //    /// </summary>
        //    dc = new DataColumn(MaterialDescriptField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    ///  计划下达日期
        //    /// </summary>
        //    dc = new DataColumn(PlanSendedDateTimeField, typeof(DateTime));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 物料号
        //    /// </summary>
        //    dc = new DataColumn(MaterialNumberField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 零件图号
        //    /// </summary>
        //    dc = new DataColumn(PartDrawNumberField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 零件名称
        //    /// </summary>
        //    dc = new DataColumn(PartDrawNameField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 零件数量
        //    /// </summary>
        //    dc = new DataColumn(PartCountField, typeof(Int32));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 零件数量验证
        //    /// </summary>
        //    dc = new DataColumn(PartCountVerifyField, typeof(Int32));
        //    dt.Columns.Add(dc);
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 是否扫描
        //    /// </summary>
        //    dc = new DataColumn(MaterialTraceField, typeof(Int32));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 扫描方式
        //    /// </summary>
        //    dc = new DataColumn(MaterialVerifyIDField, typeof(Int32));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 厂家代码
        //    /// </summary>
        //    dc = new DataColumn(ProduceFatoryCodeField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 生产厂家
        //    /// </summary>
        //    dc = new DataColumn(ProduceFatoryField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 物料条码
        //    /// </summary>
        //    dc = new DataColumn(BarCodeField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 物料条码物料号
        //    /// </summary>
        //    dc = new DataColumn(BarCode_MaterialField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 物料条码批次
        //    /// </summary>
        //    dc = new DataColumn(BarCode_SerailNumberField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 验证结果
        //    /// 验证结果
        //    /// 验证结果 CheckState.Unchecked  0没有验证
        //    /// 验证结果 CheckState.Checked 1 已经验证
        //    /// 验证结果 CheckState.Indeterminate 2 已经强制验证
        //    /// </summary>
        //    dc = new DataColumn(MaterialVerifyResultField, typeof(Int32));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 强制验证原因
        //    /// </summary>
        //    dc = new DataColumn(MaterialVerifyReasonField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 操作者工号
        //    /// </summary>
        //    dc = new DataColumn(OperatorCodeField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 操作者姓名
        //    /// </summary>
        //    dc = new DataColumn(OperatorNameField, typeof(string));
        //    dt.Columns.Add(dc);
        //    /// <summary>
        //    /// 班次代码
        //    /// </summary>
        //    dc = new DataColumn(OperatorShiftField, typeof(string));
        //    dt.Columns.Add(dc);

        //    MaterialTableForSave = dt;
        //}



        /// <summary>
        /// 测试是否需要验证。
        /// 返回值 false ，没有全部验证完成，需要验证。
        /// 返回值 true ，全部验证完成，不需要验证。
        /// 验证结果 CheckState.Unchecked  0没有验证
        /// 验证结果 CheckState.Checked 1 已经验证
        /// 验证结果 CheckState.Indeterminate 2 已经强制验证
        /// </summary>
        /// <returns></returns>
        public static bool CheckVeriftBarCode()
        {
            DataTable dt;
            bool check = true;

            //dt = dt_Material_Verify;
            dt = MaterialData.dt_Material_Verify;//.dt_Material_Verify;
            if (dt == null) return check;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if ((int)dt.Rows[i]["验证结果"] == 0)
                {
                    check = false;
                    break;
                }
            }
            return check;
        }

        /// <summary>
        /// 创建数据表
        /// </summary>TagID，测量位置，测量项目，测量值，合格标志
        /// <returns></returns>
        public static DataTable QualityTable()
        {
            DataTable dt;
            DataColumn dc;
            dt = new DataTable();

            // 物料号表索引号
            dc = new DataColumn("TagID", typeof(string));
            dt.Columns.Add(dc);
            dc = new DataColumn("工位号", typeof(string));
            dt.Columns.Add(dc);
            dc = new DataColumn("测量位置", typeof(string));
            dt.Columns.Add(dc);

            dc = new DataColumn("测量项目", typeof(string));
            dt.Columns.Add(dc);
            dc = new DataColumn("测量值", typeof(double));
            dt.Columns.Add(dc);
            dc = new DataColumn("合格标志", typeof(Int32));
            dt.Columns.Add(dc);
            return dt;
        }

    }
}
