using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using bizFacade;
using System.Data;
//using SystemFramework;

namespace MesWebFun_base
{
    public partial class MesWebFun_base
    {
        /// <summary>
        /// 电子看板_发动机号_合格放行_记录_增加
        /// </summary>
        /// <returns></returns>
        private string Insert_ConfirmOk(string opName, string operatorNum, string type)
        {
            string text = "";
            try
            {
               // string operatorNum = HttpContext.Current.Request["userName"];//放行者工号
               // string type = HttpContext.Current.Request["recordType"];//放行类型
                MES.InsertRecord_ComfirmOkGO(opName, operatorNum, type);
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:Insert_ConfirmOk");
            }
            return text;
        }

        /// <summary>
        /// 订单完工，上线数量大于计划数量，界面提示
        /// </summary>
        /// <returns></returns>
        private string OrderFormList_OrderComplete(string opName)
        {
            string text = "";
            try
            {
                int isCompleted;//订单数量是否完全上线
                int num_plan;//计划数量
                int num_complete;//上线数量
                MES.Select_OrderFormList_OrderComplete(opName, out isCompleted, out num_plan, out num_complete);
                text = "{\"isCompleted\":\"" + isCompleted + "\",\"num_plan\":\"" + num_plan + "\",\"num_complete\":\"" + num_complete + "\"}";
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:OrderFormList_OrderComplete");
            }
            return text;
        }

        /// <summary>
        /// 初始化节拍数据
        /// </summary>
        /// <returns></returns>
        private string InitOpNameOuputCount(string opnameValue)
        {
            string text = "";
            try
            {
                int outputValue = 0; //工位产量
                int nowOutputValue = 0; //在线产量
                int opNameBeatValue = 0; //工位节拍
                int NowOpNameBeatValue = 0; //在线节拍
                int classNumber = 0;//班次代码
                MES.InitOpNameOuputCount(opnameValue, out outputValue, out nowOutputValue, out opNameBeatValue, out NowOpNameBeatValue, out classNumber);
                text = "{\"outputValue\":\"" + outputValue + "\",\"nowOutputValue\":\"" + nowOutputValue + "\",\"opNameBeatValue\":\"" + opNameBeatValue + "\",\"NowOpNameBeatValue\":\"" + NowOpNameBeatValue + "\",\"classNumber\":\"" + classNumber + "\"}";
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:InitOpNameOuputCount");
            }
            return text;
        }

        /// <summary>
        /// 功能按钮 - 从数据库中初始化在线 / 离线 / 屏蔽的combobox
        /// </summary>
        /// <returns></returns>
        private string Init_OnlineOutline(string opnameValue)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;
                MES.Init_OnlineOutline(opnameValue, out dt);
                string value = "";
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        value = dt.Rows[0]["工位状态"].ToString();
                    }
                }
                text = "{\"value\":\"" + value + "\"}";
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:Init_OnlineOutline");
            }
            return text;
        }

        /// <summary>
        /// 功能按钮---将在线,离线,屏蔽更新到数据库中
        /// </summary>
        /// <returns></returns>
        private string Insert_OnlineOutline(string opnameValue, string selectValue)
        {
            string text = "";
            try
            {
                //string opnameValue = HttpContext.Current.Request["opnameValue"];//工位号
                //string selectValue = HttpContext.Current.Request["selectValue"];//选择的值
                if (selectValue == "")
                {
                    selectValue = "0";
                }
                int selectValueint = Convert.ToInt32(selectValue);
                bool falg = MES.Insert_OnlineOutline(opnameValue, selectValueint);
                if (falg)
                {
                    text = "{\"falg\":\"1\"}";
                }
                else
                {
                    text = "{\"falg\":\"0\"}";
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:Insert_OnlineOutline");
            }
            return text;
        }

        /// <summary>
        /// 合格放行
        /// </summary>
        /// <returns></returns>
        private string functionButtonConfirmOk(string userName, string passWord)
        {
            string text = "";
            try
            {
                string roleFlag = "";
                string loginFlag = "";
                System.Data.DataTable dt_User = null;
                //string userName = HttpContext.Current.Request["function_button_confirmOkGo_userName"];
                //string passWord = HttpContext.Current.Request["function_button_confirmOkGo_passWord"];

                BaseDataSystemMES.UserInfo_Login(userName, passWord, out dt_User);
                if (dt_User != null)
                {
                    if (dt_User.Rows.Count == 1)
                    {
                        int roleCodSum = Convert.ToInt32(dt_User.Rows[0][0].ToString());
                        bool IsOK = false;
                        RoleDistribution(roleCodSum, out IsOK);
                        if (IsOK == true)
                        {
                            roleFlag = "1";
                            loginFlag = "1";
                        }
                        else
                        {
                            roleFlag = "0";
                        }
                    }
                    else
                    {
                        loginFlag = "0";
                    }
                }
                else
                {
                    loginFlag = "0";
                }
                text = "{\"roleFlag\":\"" + roleFlag + "\",\"loginFlag\":\"" + loginFlag + "\"}";
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:functionButtonConfirmOk");
            }
            return text;
        }

        /// <summary>
        /// 看用户是否有权限访问该页面
        /// </summary>
        /// <param name="roleCodSum"></param>
        /// <param name="IsOK"></param>
        private void RoleDistribution(int roleCodSum, out bool IsOK)
        {
            IsOK = false;
            //登录工位MES的权限是256 如果role&256>0则有权限登录MES软件
            int roleCode = 64;
            //ArrayList aList = new ArrayList();
            if ((roleCodSum & roleCode) > 0)
            {
                ////加了没用上
                //aList.Add(roleCode);

                switch (roleCode)
                {
                    case 64:
                        {
                            //一级用户管理
                            IsOK = true;
                        }
                        break;

                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// 选择订单_增加订单号
        /// </summary>
        /// <returns></returns>
        private string InsertOrderNum(string orderlist, string opName)
        {
            //string orderlist = HttpContext.Current.Request["orderNum"];
            MES.OrderNum_Add(opName, orderlist);
            return orderlist;
        }

        /// <summary>
        /// 选择订单_增加发动机型号
        /// </summary>
        /// <returns></returns>
        private string InsertEngineNum(string opName, string enginetype, string enginetypecode)
        {
            string orderlist = "";
            //string enginetype = HttpContext.Current.Request["enginetype"];
            //string enginetypecode = HttpContext.Current.Request["enginetypecode"];
            int enginetypeID = Convert.ToInt32(enginetypecode);
            MES.EngineNum_Add(opName, enginetype, enginetypeID);
            return orderlist;
        }

        /// <summary>
        /// 物料拉动_确认接受
        /// </summary>
        /// <returns></returns>
        private string AffirmReceive(string opName, string DistributionNums)
        {
            string text = "";
            try
            {
                bool falg = false;
                //string DistributionNums = HttpContext.Current.Request["DistributionNums"];
                string[] array = DistributionNums.Split(',');
                string DistributionNum = "";
                for (int i = 0; i < array.Length; i++)
                {
                    DistributionNum = array[i];
                    falg = MaterialPull.DistributionNum(opName, DistributionNum);
                }
                if (falg)
                {
                    text = "{\"falg\":\"1\"}";
                }
                else
                {
                    text = "{\"falg\":\"0\"}";
                }
            }
            catch (Exception err)
            {
                //////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:AffirmReceive");
            }
            return text;
        }

        /// <summary>
        /// 设备管理_设备保养记录增加
        /// </summary>
        /// <returns></returns>
        private string equipmentmanagementSubmit(string opname, string mark)
        {
            string text = "";
            try
            {
                bool flag;
               // string mark = HttpContext.Current.Request["mark"];
                flag = bizFacade.MES_MachineManage.Mes_MachineTakeCare_Insert(opname, mark);
                if (flag)
                {
                    text = "{\"flag\":\"1\"}";
                }
                else
                {
                    text = "{\"flag\":\"0\"}";
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:equipmentmanagementSubmit");
            }
            return text;
        }

        /// <summary>
        /// 获取对应工位的质量数据
        /// </summary>
        /// <returns></returns>
        private string QualityDataSelect(string opName, string opname)
        {
            string qualitydata = "";
            try
            {
                System.Data.DataTable dt = null;
                //string opName = HttpContext.Current.Request["value"];
                //string opname = HttpContext.Current.Request["opname"];
                MES.QualityDataSelect(opName, opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        qualitydata = JsonHelper.CreateJsonParameters(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:QualityDataSelect");
            }
            return qualitydata;
        }

        

        /// 获取设备保养类型
        /// </summary>
        /// <returns></returns>
        private string LoadMachineType(string opName)
        {
            string Maintain = "";
            try
            {
                System.Data.DataTable dt = null;
                //string opName = HttpContext.Current.Request["value"];
                MES.LoadMachineType(opName, out dt);
                if (dt.Rows.Count > 0)
                {
                    Maintain = JsonHelper.DataTableToJson(dt);
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:LoadMachineType");
            }
            return Maintain;
        }


        /// 获取设备保养内容
        /// </summary>
        /// <returns></returns>
        private string ShowMaintainData(string opName, string MachineType)
        {
            string Maintain = "";
            try
            {
                System.Data.DataTable dt = null;
                //string opName = HttpContext.Current.Request["value"];
                //string MachineType = HttpContext.Current.Request["machinetype"];
                MES.ShowMaintainData(opName, MachineType, out dt);
                if (dt.Rows.Count > 0)
                {
                    Maintain = JsonHelper.CreateJsonParameters(dt);
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:ShowMaintainData");
            }
            return Maintain;
        }

        /// <summary>
        /// 获取设备保养图片
        /// </summary>
        /// <returns></returns>
        private string ShowMaintainPic(string opName, string MachineType)
        {
            string Maintain = "";
            try
            {
                //string opName = HttpContext.Current.Request["value"];
                //string MachineType = HttpContext.Current.Request["machinetype"];
                byte[] imgBytesIn;
                MES.GetMaintainImageFile(opName, MachineType, out imgBytesIn);
                if (imgBytesIn == null)
                {
                    return Maintain;
                }
                Maintain = Convert.ToBase64String(imgBytesIn);
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:ShowMaintainPic");
            }
            return Maintain;
        }

        /// <summary>
        /// 物料ando复位
        /// </summary>
        /// <returns></returns>
        private string submitAndoMaterialReset(string opname, string andoTypeCode, string andoListCode, string number)
        {
            string text = "";
            try
            {
                string number1 = "";
                //string andoTypeCode = HttpContext.Current.Request["andoTypeCode"];
                //string andoListCode = HttpContext.Current.Request["andoListCode"];
                //string number = HttpContext.Current.Request["number"];

                string[] number_array = number.Split(',');
                string number_value = "";
                string callInfo = "复位信息";

                for (int i = 0; i < number_array.Length - 1; i++)
                {
                    number_value = number_array[i].ToString();
                    string[] valuelist = number_value.Split('_');
                    if (valuelist.Length >= 4)
                    {
                        number1 = valuelist[3];
                        bizFacade.ando_matertial.AndoMaterialReset(opname, number1, andoTypeCode, andoListCode, callInfo);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:submitAndoMaterialReset");
            }

            return text;
        }

        /// <summary>
        /// ando界面_质量ando复位
        /// </summary>
        /// <returns></returns>
        private string submitAndoQualityReset(string opname, string andoTypeCode, string andoListCode, string number)
        {
            string text = "";
            try
            {
                string number1 = "";
                //string andoTypeCode = HttpContext.Current.Request["andoTypeCode"];
                //string andoListCode = HttpContext.Current.Request["andoListCode"];
                //string number = HttpContext.Current.Request["number"];
                string[] valuelist = number.Split('_');
                if (valuelist.Length >= 4)
                {
                    number1 = valuelist[3];
                }

                //呼叫内容
                string callInfo = "复位信息";
                bool flag = bizFacade.ando_matertial.AndoMaterialReset(opname, number1, andoTypeCode, andoListCode, callInfo);
                if (flag)
                {
                    text = "{\"flag\":\"1\"}";
                }
                else
                {
                    text = "{\"flag\":\"0\"}";
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:submitAndoQualityReset");
            }
            return text;
        }

        /// <summary>
        /// 物料ando_更新ando的具体的tabel
        /// </summary>
        /// <returns></returns>
        private string updataAndoMaterialTabel(string opname, string andoTypeCode)
        {
            string text = "";
            try
            {
                //string andoTypeCode = HttpContext.Current.Request["andoTypeCode"];
                text = bizFacade.ando_matertial.CreatAndo_Material_table(opname, andoTypeCode);
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:updataAndoMaterialTabel");
            }
            return text;
        }

        /// <summary>
        /// 质量ando_更新ando的具体的tabel
        /// </summary>
        /// <returns></returns>
        private string updataAndoQualityTabel(string opname, string andoTypeCode)
        {
            string text = "";
            try
            {
               // string andoTypeCode = HttpContext.Current.Request["andoTypeCode"];
                text = bizFacade.ando_quality.CreatAndo_quality_table(opname, andoTypeCode);
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:updataAndoQualityTabel");
            }
            return text;
        }

        /// <summary>
        /// ando界面_提交物料ando信息(插入呼叫信息)
        /// </summary>
        /// <returns></returns>
        private string submitAndoMaterialCall(string opname, string andoTypeCode, string andoListCode, string number)
        {
            string text = "";
            try
            {
                string number1 = "";
                //System.Data.DataTable tb;
                //string andoTypeCode = HttpContext.Current.Request["andoTypeCode"];
                //string andoListCode = HttpContext.Current.Request["andoListCode"];
                //string number = HttpContext.Current.Request["number"];
                string[] number_array = number.Split(',');
                string number_value = "";
                string callInfo = "0";
                int callCount = 0;
                string cardNumber = "0";
                string noNumber = "0";

                for (int i = 0; i < number_array.Length - 1; i++)
                {
                    number_value = number_array[i].ToString();
                    string[] valuelist = number_value.Split('_');
                    if (valuelist.Length >= 4)
                    {
                        number1 = valuelist[3];
                        bizFacade.ando_matertial.andoMaterialCall(opname, andoTypeCode, andoListCode, number1, callInfo, callCount, cardNumber, noNumber);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:submitAndoMaterialCall");
            }
            return text;
        }

        /// <summary>
        /// 安东界面_质量ando_呼叫提交
        /// </summary>
        /// <returns></returns>
        private string submitAndoQualityCall()
        {
            string text = "";
            //string number1 = "";
            //string opname = HttpContext.Current.Request["opname"];
            //string andoTypeCode = HttpContext.Current.Request["andoTypeCode"];
            //string andoListCode = HttpContext.Current.Request["andoListCode"];
            //string number = HttpContext.Current.Request["number"];
            //string[] valuelist = number.Split('_');
            //if (valuelist.Length >= 4)
            //{
            //    number1 = valuelist[3];
            //}
            //string callInfo = "0";
            //int callCount = 5;
            //string cardNumber = "0";
            //string noNumber = "0";
            //bool flag = bizFacade.ando_matertial.andoMaterialCall(opname, andoTypeCode, andoListCode, number1, callInfo, callCount, cardNumber, noNumber);
            //if (flag)
            //{
            //    text = "{\"flag\":\"1\"}";
            //}
            //else
            //{
            //    text = "{\"flag\":\"0\"}";
            //}
            return text;
        }

        /// <summary>
        /// 查询物料ando条数,为了左移动的
        /// </summary>
        /// <returns></returns>
        private string InitMaterailAndoCount(string opname, string andoTypeCode)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt_material;
                System.Data.DataTable dt_quality;
                System.Data.DataTable dt_machine;
                //string andoTypeCode = HttpContext.Current.Request["andoTypeCode"];
                //查询物料ando具体的button个数
                bizFacade.ando_matertial.andoListSelect(opname, "1", out dt_material);
                int count_material = 0;

                //不为空
                if (dt_material != null)
                {
                    if (dt_material.Rows.Count == 0)
                    {
                        count_material = 0;
                    }
                    else
                    {
                        count_material = dt_material.Rows.Count;
                    }
                }
                //查询质量ando具体的button个数
                bizFacade.ando_matertial.andoListSelect(opname, "2", out dt_quality);
                int count_quality = 0;
                if (dt_quality != null)
                {
                    if (dt_quality.Rows.Count == 0)
                    {
                        count_quality = 0;
                    }
                    else
                    {
                        count_quality = dt_quality.Rows.Count;
                    }
                }
                //查询设备ando具体的button个数
                bizFacade.ando_matertial.andoListSelect(opname, "3", out dt_machine);

                int count_machine = 0;
                if (dt_machine != null)
                {
                    if (dt_machine.Rows.Count == 0)
                    {
                        count_machine = 0;
                    }
                    else
                    {
                        count_machine = dt_machine.Rows.Count;
                    }
                }
                text = "{\"material_count\":\"" + count_material + "\",\"machine_count\":\"" + count_machine + "\",\"quality_count\":\"" + count_quality + "\"}";
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:InitMaterailAndoCount");
            }
            return text;
        }

        /// <summary>
        /// 初始化ando
        /// </summary>
        /// <returns></returns>
        private string InitMaterailAndo(string opname)
        {
            string text = "";
            try
            {
                text = bizFacade.ando_load.ando_loading(opname);
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:InitMaterailAndo");
            }
            return text;
        }

        /// <summary>
        /// ando_查询具体ando类型明细
        /// </summary>
        /// <returns></returns>
        private string InitComboboxAndoDetail()
        {
            string text = "";
            //System.Data.DataTable dt = null;
            //string andoType="1";
            //bizFacade.ando.select_ando_detail(andoType, out dt);
            //text = JsonHelper.DataTableToJson(dt);
            return text;
        }

        /// <summary>
        /// 初始化装配线MES
        /// </summary>
        /// <returns></returns>
        private string MesloadingSelect(string opname, string languageType, string mainModule)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;

                //string languageType = HttpContext.Current.Request["mainModule"];
                //string mainModule = HttpContext.Current.Request["MesWebCode"];
                bizFacade.MES_Loading.MES_Loading_select(languageType, mainModule, opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = JsonHelper.DataTableToJson(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MesloadingSelect");
            }
            return text;
        }

        /// <summary>
        /// 查询托盘信息
        /// </summary>
        /// <returns></returns>
        private string MobySelect(string OpName)
        {
            string data = "";
            try
            {
                string orderNum = "";
                int EngineTypeID = 0;
                string EngineType = "";
                string EngineID = "";
                string PartPallet_Code = "";
                int IsrepairBarcode = 0;
                string repairBarcode = "";
                string workCode = ""; // 制造编号
                string projectName = ""; // 项目名称
                string splitCode = ""; // 间隔号
                string unidCode = ""; // 单元号
                string engineType = ""; // 本体类型
                string engineTypeModel = ""; // 附件类型
                string startTime = ""; // 开始时间
                MES.Moby_Select(OpName, out orderNum, out EngineTypeID, out EngineType, out EngineID, out PartPallet_Code, out IsrepairBarcode, out repairBarcode,
                    out workCode, out projectName, out splitCode, out unidCode, out engineType, out engineTypeModel,out startTime);
                data = orderNum + "&" + EngineTypeID + "&" + EngineType + "&" + EngineID + "&" + PartPallet_Code + "&" + IsrepairBarcode + "&" + repairBarcode + "&" +
                    workCode + "&" + projectName + "&" + splitCode + "&" + unidCode + "&" + engineType + "&" + engineTypeModel + "&" + startTime;
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MobySelect");
            }
            return data;
        }

        /// <summary>
        /// 查询操作图片
        /// </summary>
        /// <returns></returns>
        private string PictureShow(string OpName)
        {
            string data = "";
            try
            {
                string orderNum = "";
                int EngineTypeID = 0;
                string EngineType = "";
                string EngineID = "";
                string PartPallet_Code = "";
                int IsrepairBarcode = 0;
                string repairBarcode = "";
                string workCode = ""; // 制造编号
                string projectName = ""; // 项目名称
                string splitCode = ""; // 间隔号
                string unidCode = ""; // 单元号
                string engineType = ""; // 本体类型
                string engineTypeModel = ""; // 附件类型
                string startTime = ""; // 开始时间
                MES.Moby_Select(OpName, out orderNum, out EngineTypeID, out EngineType, out EngineID, out PartPallet_Code, out IsrepairBarcode, out repairBarcode,
                    out workCode, out projectName, out splitCode, out unidCode, out engineType, out engineTypeModel, out startTime);
                byte[] imgBytesIn;
                BaseDataSystemMES.GetImageFile(OpName, EngineTypeID.ToString(), out imgBytesIn);
                if (imgBytesIn == null)
                {
                    return data;
                }
                data = Convert.ToBase64String(imgBytesIn);
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:PictureShow");
            }
            return data;
        }

        /// <summary>
        /// 查询物料
        /// </summary>
        /// <returns></returns>
        private string MaterialList(string OpName)
        {
            string jsonStr_Materail = "";
            try
            {
                string orderNum = "";
                int EngineTypeID = 0;
                string EngineType = "";
                string EngineID = "";
                string PartPallet_Code = "";
                int IsrepairBarcode = 0;
                string repairBarcode = "";
                string workCode = ""; // 制造编号
                string projectName = ""; // 项目名称
                string splitCode = ""; // 间隔号
                string unidCode = ""; // 单元号
                string engineType = ""; // 本体类型
                string engineTypeModel = ""; // 附件类型
                string startTime = ""; // 开始时间
                MES.Moby_Select(OpName, out orderNum, out EngineTypeID, out EngineType, out EngineID, out PartPallet_Code, out IsrepairBarcode, out repairBarcode,
                    out workCode, out projectName, out splitCode, out unidCode, out engineType, out engineTypeModel, out startTime);
                DataTable dt_Material;

                MES.PartMaterialVerify_Select(OpName, EngineTypeID, EngineType, out dt_Material);
                if (dt_Material != null)
                {
                    if (dt_Material.Rows.Count > 0)
                    {
                        jsonStr_Materail = JsonHelper.CreateJsonParameters(dt_Material);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MaterialList");
            }
            return jsonStr_Materail;
        }

        /// <summary>
        /// 查询物料库存信息
        /// </summary>
        /// <returns></returns>
        private string MaterialListStock(string OpName)
        {
            string jsonStr_Materail = "";
            try
            {
                string orderNum = "";
                int EngineTypeID = 0;
                string EngineType = "";
                string EngineID = "";
                string PartPallet_Code = "";
                int IsrepairBarcode = 0;
                string repairBarcode = "";
                string workCode = ""; // 制造编号
                string projectName = ""; // 项目名称
                string splitCode = ""; // 间隔号
                string unidCode = ""; // 单元号
                string engineType = ""; // 本体类型
                string engineTypeModel = ""; // 附件类型
                string startTime = ""; // 开始时间
                MES.Moby_Select(OpName, out orderNum, out EngineTypeID, out EngineType, out EngineID, out PartPallet_Code, out IsrepairBarcode, out repairBarcode,
                    out workCode, out projectName, out splitCode, out unidCode, out engineType, out engineTypeModel, out startTime);
                DataTable dt_Material;

                MES.PartMaterialVerify_Select(OpName, EngineTypeID, EngineType, out dt_Material);
                if (dt_Material != null)
                {
                    if (dt_Material.Rows.Count > 0)
                    {
                        jsonStr_Materail = JsonHelper.CreateJsonParameters(dt_Material);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MaterialList");
            }
            return jsonStr_Materail;
        }

        /// <summary>
        /// 查询操作指南
        /// </summary>
        /// <returns></returns>
        private string ProcessList(string OpName)
        {
            string jsonStr_Process = "";
            try
            {
                string orderNum = "";
                int EngineTypeID = 0;
                string EngineType = "";
                string EngineID = "";
                string PartPallet_Code = "";
                int IsrepairBarcode = 0;
                string repairBarcode = "";
                string workCode = ""; // 制造编号
                string projectName = ""; // 项目名称
                string splitCode = ""; // 间隔号
                string unidCode = ""; // 单元号
                string engineType = ""; // 本体类型
                string engineTypeModel = ""; // 附件类型
                string startTime = ""; // 开始时间
                MES.Moby_Select(OpName, out orderNum, out EngineTypeID, out EngineType, out EngineID, out PartPallet_Code, out IsrepairBarcode, out repairBarcode,
                    out workCode, out projectName, out splitCode, out unidCode, out engineType, out engineTypeModel, out startTime);

                DataTable dt_Proccess;
                MES.Process_Select(OpName, EngineTypeID, EngineType, out dt_Proccess);
                if (dt_Proccess != null)
                {
                    if (dt_Proccess.Rows.Count > 0)
                    {
                        jsonStr_Process = JsonHelper.CreateJsonParameters(dt_Proccess);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:ProcessList");
            }
            return jsonStr_Process;
        }

        /// <summary>
        /// 创建动态div
        /// </summary>
        /// <returns></returns>
        private string ShaftPotion_Select(string OpName)
        {
            string text = "";
            try
            {
                string orderNum = "";
                int EngineTypeID = 0;
                string EngineType = "";
                string EngineID = "";
                string PartPallet_Code = "";
                int IsrepairBarcode = 0;
                string repairBarcode = "";
                string workCode = ""; // 制造编号
                string projectName = ""; // 项目名称
                string splitCode = ""; // 间隔号
                string unidCode = ""; // 单元号
                string engineType = ""; // 本体类型
                string engineTypeModel = ""; // 附件类型
                string startTime = ""; // 开始时间
                MES.Moby_Select(OpName, out orderNum, out EngineTypeID, out EngineType, out EngineID, out PartPallet_Code, out IsrepairBarcode, out repairBarcode,
                    out workCode, out projectName, out splitCode, out unidCode, out engineType, out engineTypeModel, out startTime);

                DataTable dt;
                MES.ShaftPositionSelect(OpName, EngineTypeID, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = JsonHelper.DataTableToJson(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:ShaftPotion_Select");
            }
            return text;
        }

        /// <summary>
        /// 实时显示质量数据
        /// </summary>
        /// <returns></returns>
        private string Quality_Select(string OpName)
        {
            string text = "";
            try
            {
                string orderNum = "";
                int EngineTypeID = 0;
                string EngineType = "";
                string EngineID = "";
                string PartPallet_Code = "";
                int IsrepairBarcode = 0;
                string repairBarcode = "";
                string workCode = ""; // 制造编号
                string projectName = ""; // 项目名称
                string splitCode = ""; // 间隔号
                string unidCode = ""; // 单元号
                string engineType = ""; // 本体类型
                string engineTypeModel = ""; // 附件类型
                string startTime = ""; // 开始时间
                MES.Moby_Select(OpName, out orderNum, out EngineTypeID, out EngineType, out EngineID, out PartPallet_Code, out IsrepairBarcode, out repairBarcode,
                    out workCode, out projectName, out splitCode, out unidCode, out engineType, out engineTypeModel, out startTime);

                DataTable dt;
                MES.QualitySelect(OpName, EngineID, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = JsonHelper.CreateJsonParameters(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:Quality_Select");
            }
            return text;
        }

        /// <summary>
        /// 获得工步属性
        /// </summary>
        /// <returns></returns>
        private string StepProperty(string opName)
        {
            string stepProperty = "512";
            System.Data.DataTable dt = null;
            bizFacade.UserLogin.GetUrl(opName, out dt);
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    stepProperty = dt.Rows[0]["工步属性"].ToString();
                }
            }
            return stepProperty;
        }

        /// <summary>
        /// 获得订单信息
        /// </summary>
        /// <returns></returns>
        private string OrderFormList(string opName)
        {
            string orderlist = "";
            try
            {
                System.Data.DataTable dt = null;
                MES.OrderFormList_Select(opName, out dt);
                //对其进行判断
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        int planCount;//计划数量
                        int finishCount;//完成数量
                        int isOverCount;//是否超标,0表示未完成,1表示正好完成,2表示超过预期
                        int isSelect;//选择标志
                        int isCanSelect;//是否有订单选择权限
                        string status;//状态
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            planCount = 0;
                            finishCount = 0;
                            isOverCount = 0;
                            isSelect = 0;
                            isCanSelect = 0;
                            status = "";

                            if (dt.Rows[i]["计划数量"].ToString() != "")
                            {
                                planCount = Convert.ToInt32(dt.Rows[i]["计划数量"]);
                            }
                            if (dt.Rows[i]["完成数量"].ToString() != "")
                            {
                                finishCount = Convert.ToInt32(dt.Rows[i]["完成数量"]);
                            }
                            if (dt.Rows[i]["选择标志"].ToString() != "")
                            {
                                isSelect = Convert.ToInt32(dt.Rows[i]["选择标志"]);
                            }
                            if (dt.Rows[i]["订单选择权限"].ToString() != "")
                            {
                                isCanSelect = Convert.ToInt32(dt.Rows[i]["订单选择权限"]);
                            }
                            if (isSelect == 1)//表示选择当前订单,显示"√"
                            {
                                status = "√";
                            }
                            if (finishCount == planCount)//完成数量>计划数量则表示超标
                            {
                                isOverCount = 1;
                            }
                            if (finishCount > planCount)//完成数量>计划数量则表示超标
                            {
                                isOverCount = 2;
                            }
                            //重新赋值
                            dt.Rows[i]["状态"] = status;
                            dt.Rows[i]["是否超标"] = isOverCount;//0表示未完成,1表示正好完成,2表示超过预期
                            dt.Rows[i]["选择标志"] = isSelect;
                            dt.Rows[i]["订单选择权限"] = isCanSelect;
                        }
                    }
                }

                orderlist = JsonHelper.CreateJsonParameters(dt);
                //orderlist = CreateJsonParameters(dt);
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:OrderFormList");
            }
            return orderlist;
        }

        private static string CreateJsonParameters(DataTable dt)
        {
            StringBuilder JsonString = new StringBuilder();
            //Exception Handling
            if (dt != null)
            {
                JsonString.Append("{ ");
                JsonString.Append("\"total\":");
                JsonString.Append(dt.Rows.Count);
                JsonString.Append(",");
                JsonString.Append("\"rows\":[ ");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    JsonString.Append("{ ");
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        if (j < dt.Columns.Count - 1)
                        {
                            //if (dt.Rows[i][j] == DBNull.Value) continue;
                            if (dt.Columns[j].DataType == typeof(bool))
                            {
                                JsonString.Append("\"JSON_" + dt.Columns[j].ColumnName.ToLower() + "\":" +
                                                  dt.Rows[i][j].ToString().ToLower() + ",");
                            }
                            else if (dt.Columns[j].DataType == typeof(string))
                            {
                                JsonString.Append("\"JSON_" + dt.Columns[j].ColumnName.ToLower() + "\":" + "\"" +
                                                  dt.Rows[i][j].ToString().Replace("\"", "\\\"") + "\",");
                            }
                            else
                            {
                                JsonString.Append("\"JSON_" + dt.Columns[j].ColumnName.ToLower() + "\":" + "\"" + dt.Rows[i][j] + "\",");
                            }
                        }
                        else if (j == dt.Columns.Count - 1)
                        {
                            //if (dt.Rows[i][j] == DBNull.Value) continue;
                            if (dt.Columns[j].DataType == typeof(bool))
                            {
                                JsonString.Append("\"JSON_" + dt.Columns[j].ColumnName.ToLower() + "\":" +
                                                  dt.Rows[i][j].ToString().ToLower());
                            }
                            else if (dt.Columns[j].DataType == typeof(string))
                            {
                                JsonString.Append("\"JSON_" + dt.Columns[j].ColumnName.ToLower() + "\":" + "\"" +
                                                  dt.Rows[i][j].ToString().Replace("\"", "\\\"") + "\"");
                            }
                            else
                            {
                                JsonString.Append("\"JSON_" + dt.Columns[j].ColumnName.ToLower() + "\":" + "\"" + dt.Rows[i][j] + "\"");
                            }
                        }
                    }
                    /*end Of String*/
                    if (i == dt.Rows.Count - 1)
                    {
                        JsonString.Append("} ");
                    }
                    else
                    {
                        JsonString.Append("}, ");
                    }
                }
                JsonString.Append("]");
                JsonString.Append("}");
                return JsonString.ToString().Replace("\n", "");
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得机型
        /// </summary>
        /// <returns></returns>
        private string Orderenginetypeselect()
        {
            string enginetypelist = "";
            try
            {
                System.Data.DataTable dt = null;
                ShaftPosition.EngineType_Select(out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        enginetypelist = JsonHelper.DataTableToJson(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:Orderenginetypeselect");
            }
            return enginetypelist;
        }

        /// <summary>
        /// 物料拉动_获取单号
        /// </summary>
        /// <returns></returns>
        private string MaterialPush_ListNumer(string opName)
        {
            string listNumber = "";
            try
            {
                System.Data.DataTable dt = null;
                MaterialPull.MaterialPush_ListNumer_Select(0, "", 1, opName, 0, "", out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        listNumber = JsonHelper.CreateJsonParameters(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MaterialPush_ListNumer");
            }
            return listNumber;
        }

        /// <summary>
        /// 物料拉动_根据单号获取详细信息
        /// </summary>
        /// <returns></returns>
        private string MaterialPush_Details(string opname, string listNumer)
        {
            string listDetails = "";
            try
            {
                System.Data.DataTable dt = null;
                //单号
                //string listNumer = HttpContext.Current.Request["listNumber"];
                MaterialPull.MaterialPush_Details_Select(listNumer, opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        listDetails = JsonHelper.CreateJsonParameters(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MaterialPush_Details");
            }
            return listDetails;
        }

        /// <summary>
        /// 物料拉动_根据单号获取详细信息
        /// </summary>
        /// <returns></returns>
        private string QualityDataButton_bgColor_Select(string opname)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;
                //单号
                MES.QualityDataButton_bgColor_Select(opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count >= 0)
                    {
                        text = Buttons.Createbuttons(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:QualityDataButton_bgColor_Select");
            }
            return text;
        }

        /// <summary>
        /// 消息提醒
        /// </summary>
        /// <returns></returns>
        private string ShowWindowNotice(string opname)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;
                MES.ShowWindowNotice(opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = JsonHelper.DataTableToJson(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:ShowWindowNotice");
            }
            return text;
        }

        /// <summary>
        /// 消息滚动
        /// </summary>
        /// <returns></returns>
        private string ShowLEDNotice(string opname)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;
                MES.ShowLEDNotice(opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = JsonHelper.DataTableToJson(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:ShowLEDNotice");
            }
            return text;
        }

        /// <summary>
        /// 获取生产订单
        /// </summary>
        /// <returns></returns>
        private string GetOrderForm(string opname)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;
                MES.OpName_MIS_OrderForm_Select(opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = dt.Rows[0]["订单号"].ToString();
                        return text;
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:GetOrderForm");
            }
            return text;
        }

        /// <summary>
        /// 获取发动机型号
        /// </summary>
        /// <returns></returns>
        private string GetEngineType(string opname)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;
                MES.OpName_MIS_EngineType_Select(opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = dt.Rows[0]["产品型号代码"].ToString() + "&" + dt.Rows[0]["发动机型号"].ToString();
                        return text;
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:GetEngineType");
            }
            return ("" + "&" + "");
        }

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private string ShowOpNameMessage(string opname)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;
                BaseDataSystemMES.GetOpNameByOpName(opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = dt.Rows[0]["工序名称"].ToString() + "&" + dt.Rows[0]["操作者工号"].ToString() + "&" + dt.Rows[0]["是否启用物料拉动"].ToString();
                        return text;
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:ShowOpNameMessage");
            }
            return ("" + "&" + "" + "&" + "0");
        }

        /// <summary>
        /// 系统初始化时
        /// </summary>
        /// <returns></returns>
        private string WebLoginIn(string opname)
        {
            string text = "";
            MES.WebLoginIn(opname);
            return text;
        }

        /// <summary>
        /// 物料检测
        /// </summary>
        /// <returns></returns>
        private string MaterialCheckPosition(string OpName)
        {
            string text = "";
            try
            {
                DataTable dt;
                
                MES.MaterialCheckSelect(OpName, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = JsonHelper.DataTableToJson(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MaterialCheckPosition");
            }
            return text;
        }

        /// <summary>
        /// 获取对应工位的物料数据
        /// </summary>
        /// <returns></returns>
        private string MaterialDataSelect(string opName, string opname)
        {
            string qualitydata = "";
            try
            {
                System.Data.DataTable dt = null;
                //string opName = HttpContext.Current.Request["value"];
                //string opname = HttpContext.Current.Request["opname"];
                MES.MaterialDataSelect(opName, opname, out dt);
                if (dt != null)
                {
                    //if (dt.Rows.Count > 0)
                    {
                        qualitydata = JsonHelper.CreateJsonParameters(dt);
                    }
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MaterialDataSelect");
            }
            return qualitydata;
        }

        /// <summary>
        /// 电子看板_装配零件_查询
        /// </summary>
        /// <returns></returns>
        private string MaterialSelect(string opName, string enginetypeid, string enginetype)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;
                //string enginetypeid = HttpContext.Current.Request["enginetypeid"];
                //string enginetype = HttpContext.Current.Request["enginetype"];
                ShaftPosition.Material_Select(opName, enginetypeid, enginetype, out dt);

                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = JsonHelper.CreateJsonParameters(dt);
                    }
                }
            }
            catch (Exception err)
            {
                //ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MaterialSelect");
            }
            return text;
        }

        public string GetLoginOutUrl()
        {
            string url = System.Configuration.ConfigurationManager.AppSettings["Linklogin"].ToString();
            return url;
        }

        /// <summary>
        /// 手动修改批次信息
        /// </summary>
        /// <returns></returns>
        private string MaterialManualUpdateBetch(string opName,string arrays, string enginetype)
        {
            string text = "";
            try
            {
                //string arrays = HttpContext.Current.Request["arrays"];//组合
                //string enginetype = HttpContext.Current.Request["enginetype"];//产品型号

                //创建datatable
                DataRow row;
                DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[] {
                new DataColumn("零件图号"),
                new DataColumn("零件批号"),
                new DataColumn("生产厂家") });

                string[] collection = arrays.Split('^');//获取
                if (collection.Length > 0)
                {
                    for (int i = 0; i < collection.Length; i++)
                    {
                        string a = collection[i];
                        string[] a_array = a.Split('&');
                        if (a_array.Length > 2)
                        {
                            row = dt.NewRow();
                            string materialid = a_array[0].ToString();
                            string betch = a_array[1].ToString();
                            string factory = a_array[2].ToString();
                            row["零件图号"] = materialid;
                            row["零件批号"] = betch;
                            row["生产厂家"] = factory;
                            dt.Rows.Add(row);
                        }
                    }

                    //修改到数据库
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            MES.Material_Betch_Update(opName, enginetype, dt);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                //ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MaterialManualUpdateBetch");
            }
            return text;
        }

        /// <summary>
        /// 获得返修数量信息
        /// </summary>
        /// <returns></returns>
        private string GetRepaireNum(string opname)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;
                MES.OpName_MIS_RepiareNum_Select(opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = dt.Rows[0]["当前数量"].ToString() + "&" + dt.Rows[0]["设置数量"].ToString();
                        return text;
                    }
                    else
                    {
                        return text = "0&0";
                    }
                }
                else
                {
                    return text = "0&0";
                }
            }
            catch (Exception err)
            {
                //ApplicationLog.WriteLog(err, "MesWebFun_baseFun:GetEngineType");
            }
            return ("" + "&" + "");
        }

        /// <summary>
        /// 插入返修数量
        /// </summary>
        /// <returns></returns>
        private string Insert_RepiareNum(string opnameValue, string selectValue)
        {
            string text = "";
            try
            {
                //string selectValue = HttpContext.Current.Request["CurrentNum"];//选择值
                if (selectValue == "")
                {
                    selectValue = "0";
                }
                int selectValueint = Convert.ToInt32(selectValue);
                bool falg = MES.Insert_RepiareNum(opnameValue, selectValueint);
                if (falg)
                {
                    text = "{\"falg\":\"1\"}";
                }
                else
                {
                    text = "{\"falg\":\"0\"}";
                }
            }
            catch (Exception err)
            {
                //ApplicationLog.WriteLog(err, "MesWebFun_baseFun:Insert_RepiareNum");
            }
            return text;
        }

        /// <summary>
        /// 初始化返修选择tree数据
        /// </summary>
        /// <returns></returns>
        private string Init_TreeData(string opnameValue)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt;
                //string opnameValue = HttpContext.Current.Request["Opname"];//工位号
                MES.Init_TreeData(opnameValue, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = JsonHelper.CreateJsonParameters(dt);
                    }
                }
            }
            catch (Exception err)
            {
                //ApplicationLog.WriteLog(err, "MesWebFun_baseFun:Init_TreeData");
            }
            return text;
        }

        /// <summary>
        /// 返修上线--初始化质量数据
        /// </summary>
        /// <returns></returns>
        private string Quality_Select_Repair(string OpName, string EngineID)
        {
            string text = "";
            try
            {
                DataTable dt;
                MES.QualitySelect(OpName, EngineID, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        text = JsonHelper.CreateJsonParameters(dt);
                    }
                }
            }
            catch (Exception err)
            {
                //ApplicationLog.WriteLog(err, "MesWebFun_baseFun:Quality_Select_Repair");
            }
            return text;
        }

        /// <summary>
        /// 返修上线-将选择的根节点数据更新到数据库中
        /// </summary>
        /// <returns></returns>
        private string Insert_selectTreeData(string opName, string engineTypeId, string selectIdsArray)
        {
            string text = "";
            try
            {
                //string engineTypeId = HttpContext.Current.Request["engineTypeId"];//产品型号代码
                //string selectIdsArray = HttpContext.Current.Request["selectId"];//选中的节点数据数据
                //创建datatable
                DataRow row;
                DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[] {
                new DataColumn("工位号"),
                new DataColumn("产品型号代码"),
                new DataColumn("序号") });
                string[] collection = selectIdsArray.Split(',');//获取
                if (collection.Length > 0)
                {
                    for (int i = 0; i < collection.Length - 1; i++)
                    {
                        string idValue = collection[i];
                        row = dt.NewRow();
                        string opNameValue = opName;
                        int engineTypeIdValue = Convert.ToInt32(engineTypeId);
                        int selectId = Convert.ToInt32(idValue);
                        row["工位号"] = opNameValue;
                        row["产品型号代码"] = engineTypeIdValue;
                        row["序号"] = selectId;
                        dt.Rows.Add(row);
                    }
                    //修改到数据库
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            MES.Insert_selectTreeData(dt);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                //ApplicationLog.WriteLog(err, "MesWebFun_baseFun:Insert_selectTreeData");
            }

            return text;
        }

        /// <summary>
        /// 质量报警_根据按钮获取详细信息 20170318
        /// </summary>
        /// <returns></returns>
        private string QualityDataButton_bgColor_alert_Select(string opname)
        {
            string text = "";
            try
            {
                System.Data.DataTable dt = null;
                //单号
                //string opname = HttpContext.Current.Request["value"];
                //string lineout_barcode = HttpContext.Current.Request["lineout_barcode"];
                MES.QualityDataButton_bgColor_alert_Select(opname, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count >= 0)
                    {
                        text = Buttons.Createbuttons_alert(dt);
                    }
                }
            }
            catch (Exception err)
            {
                //ApplicationLog.WriteLog(err, "MesWebFun_baseFun:QualityDataButton_bgColor_alert_Select");
            }
            return text;
        }

        /// <summary>
        /// 获取对应工位的物料数据_根据发动机 20170319
        /// </summary>
        /// <returns></returns>
        private string MaterialDataSelect_F_EnergineID(string opname, string energineID)
        {
            string qualitydata = "";
            try
            {
                System.Data.DataTable dt = null;
                //string energineID = HttpContext.Current.Request["value"];
                MES.MaterialDataSelect_F_EnergineID(opname, energineID, out dt);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        qualitydata = JsonHelper.CreateJsonParameters(dt);
                    }
                }
            }
            catch (Exception err)
            {
                //ApplicationLog.WriteLog(err, "MesWebFun_baseFun:MaterialDataSelect");
            }
            return qualitydata;
        }

        /// <summary>
        /// 获取操作指南的PDF路径
        /// </summary>
        /// <returns></returns>
        private string GetPdfSrc(string opName)
        {
            string PdfSrc = "";
            try
            {
                System.Data.DataTable dt = null;

                string orderNum = "";
                int EngineTypeID = 0;
                string EngineType = "";
                string EngineID = "";
                string PartPallet_Code = "";
                int IsrepairBarcode = 0;
                string repairBarcode = "";
                string workCode = ""; // 制造编号
                string projectName = ""; // 项目名称
                string splitCode = ""; // 间隔号
                string unidCode = ""; // 单元号
                string engineType = ""; // 本体类型
                string engineTypeModel = ""; // 附件类型
                string startTime = ""; // 开始时间
                MES.Moby_Select(opName, out orderNum, out EngineTypeID, out EngineType, out EngineID, out PartPallet_Code, out IsrepairBarcode, out repairBarcode,
                    out workCode, out projectName, out splitCode, out unidCode, out engineType, out engineTypeModel, out startTime);
                BaseDataSystemMES.GetPdfSrc(opName, EngineTypeID.ToString(), out PdfSrc);
            }
            catch (Exception err)
            {
                //ApplicationLog.WriteLog(err, "MesWebFun_baseFun:GetPdfSrc");
            }
            return PdfSrc;
        }

    }
}