public void ProcessRequest(HttpContext context)
        {
            //机台生产状态
            Int32 workId = 0;

            if (Int32.TryParse(context.Request["workId"], out workId))
            {
            }
            else
            {
                return;
            }
            int LocationID = workId;//车间位置主键ID
            List <DeviceStateInfo> deviceStateInfos = new List <DeviceStateInfo>();

            using (JDJS_WMS_DB_USEREntities wms = new  JDJS_WMS_DB_USEREntities())
            {
                var devices = wms.JDJS_WMS_Device_Info.Where(r => r.Position == LocationID);
                foreach (var item in devices)
                {
                    int             cncID           = item.ID;
                    DeviceStateInfo deviceStateInfo = new DeviceStateInfo();
                    deviceStateInfo.CncNum = item.MachNum;
                    var realstate = wms.JDJS_WMS_Device_RealTime_Data.Where(r => r.CncID == cncID);
                    if (realstate.Count() > 0)
                    {
                        deviceStateInfo.state = Convert.ToInt32(realstate.FirstOrDefault().ProgState);
                    }

                    var processing = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.CncID == cncID && r.isFlag == 2);
                    if (processing.Count() > 0)
                    {
                        int    id         = Convert.ToInt32(processing.FirstOrDefault().ProcessID);
                        int    processNum = Convert.ToInt32(wms.JDJS_WMS_Order_Process_Info_Table.Where(r => r.ID == id).FirstOrDefault().ProcessID);
                        string OrderNum   = wms.JDJS_WMS_Order_Entry_Table.Where(r => r.Order_ID == processing.FirstOrDefault().OrderID).FirstOrDefault().Order_Number.ToString();

                        deviceStateInfo.CurrTask = OrderNum + "-" + processNum.ToString() + "序";
                        var pro3 = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.ProcessID == id && r.isFlag == 3 && r.CncID == cncID);
                        var pro1 = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.ProcessID == id && r.isFlag == 1 && r.CncID == cncID);
                        var pro2 = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.ProcessID == id && r.isFlag == 2 && r.CncID == cncID);

                        deviceStateInfo.CurrTaskRate = (pro3.Count() / (pro1.Count() + pro2.Count() + pro3.Count())).ToString();

                        var nextTask = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.CncID == cncID && r.isFlag == 1 && r.ProcessID != processing.FirstOrDefault().ProcessID).OrderBy(r => r.StartTime);
                        if (nextTask.Count() > 0)
                        {
                            int    ids         = Convert.ToInt32(nextTask.FirstOrDefault().ProcessID);
                            int    processNums = Convert.ToInt32(wms.JDJS_WMS_Order_Process_Info_Table.Where(r => r.ID == ids).FirstOrDefault().ProcessID);
                            string OrderNums   = wms.JDJS_WMS_Order_Entry_Table.Where(r => r.Order_ID == nextTask.FirstOrDefault().OrderID).FirstOrDefault().Order_Number.ToString();
                            deviceStateInfo.NextTask = OrderNums + "-" + processNums.ToString() + "序";
                        }
                    }
                    else
                    {
                        processing = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.CncID == cncID && r.isFlag == 1).OrderBy(r => r.StartTime);
                        if (processing.Count() > 0)
                        {
                            if (processing.Count() > 1)
                            {
                                var    pro        = processing.ToList();
                                int    id         = Convert.ToInt32(processing.FirstOrDefault().ProcessID);
                                int    processNum = Convert.ToInt32(wms.JDJS_WMS_Order_Process_Info_Table.Where(r => r.ID == id).FirstOrDefault().ProcessID);
                                string OrderNum   = wms.JDJS_WMS_Order_Entry_Table.Where(r => r.Order_ID == processing.FirstOrDefault().OrderID).FirstOrDefault().Order_Number.ToString();

                                deviceStateInfo.CurrTask = OrderNum + "-" + processNum.ToString() + "序";
                                var pro3 = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.ProcessID == id && r.isFlag == 3 && r.CncID == cncID);
                                var pro1 = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.ProcessID == id && r.isFlag == 1 && r.CncID == cncID);
                                var pro2 = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.ProcessID == id && r.isFlag == 2 && r.CncID == cncID);

                                deviceStateInfo.CurrTaskRate = (pro3.Count() / (pro1.Count() + pro2.Count() + pro3.Count())).ToString();

                                var willdo = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.CncID == cncID && r.ProcessID == processing.FirstOrDefault().ProcessID&& r.isFlag == 1);



                                int processID = Convert.ToInt32(pro[1].ProcessID);

                                var nextTask = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.CncID == cncID && r.isFlag == 1 && r.ProcessID != processID).OrderBy(r => r.StartTime);
                                if (nextTask.Count() > 0)
                                {
                                    int    idss         = Convert.ToInt32(nextTask.FirstOrDefault().ProcessID);
                                    int    processNumss = Convert.ToInt32(wms.JDJS_WMS_Order_Process_Info_Table.Where(r => r.ID == idss).FirstOrDefault().ProcessID);
                                    string OrderNumss   = wms.JDJS_WMS_Order_Entry_Table.Where(r => r.Order_ID == nextTask.FirstOrDefault().OrderID).FirstOrDefault().Order_Number.ToString();
                                    deviceStateInfo.NextTask = OrderNumss + "-" + processNumss.ToString() + "序";
                                }
                            }
                            else
                            {
                                int    id         = Convert.ToInt32(processing.FirstOrDefault().ProcessID);
                                int    processNum = Convert.ToInt32(wms.JDJS_WMS_Order_Process_Info_Table.Where(r => r.ID == id).FirstOrDefault().ProcessID);
                                string OrderNum   = wms.JDJS_WMS_Order_Entry_Table.Where(r => r.Order_ID == processing.FirstOrDefault().OrderID).FirstOrDefault().Order_Number.ToString();

                                deviceStateInfo.CurrTask = OrderNum + "-" + processNum.ToString() + "序";
                                var willdo = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.CncID == cncID && r.ProcessID == processing.FirstOrDefault().ProcessID&& r.isFlag == 1);
                            }
                        }
                    }
                    DateTime timenow = DateTime.Now;
                    var      jdjs    = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.CncID == cncID && r.isFlag == 3);
                    foreach (var real in jdjs)
                    {
                        DateTime endtime = Convert.ToDateTime(real.EndTime);
                        if (endtime.Date == timenow.Date)
                        {
                            deviceStateInfo.WorkPieceCount++;
                        }
                    }
                    DateTime         nowTime        = DateTime.Now;
                    DateTime         toDayTimeBegin = DateTime.Now.Date;
                    var              states         = wms.JDJS_WMS_Device_ProgState_Info.Where(r => (r.CncID == cncID) && (r.StartTime > toDayTimeBegin || r.EndTime > toDayTimeBegin || r.EndTime == null));
                    List <progState> progStates     = new List <progState>();
                    foreach (var real in states)
                    {
                        progState progState = new progState();
                        progState.ProgState = Convert.ToInt32(real.ProgState);
                        progState.startTime = Convert.ToDateTime(real.StartTime);
                        if (Convert.ToDateTime(real.StartTime) < toDayTimeBegin)
                        {
                            progState.startTime = toDayTimeBegin;
                        }
                        if (real.EndTime == null)
                        {
                            progState.EndTime = nowTime;
                        }
                        else
                        {
                            progState.EndTime = Convert.ToDateTime(real.EndTime);
                        }
                        progStates.Add(progState);
                    }
                    double runTime  = 0;
                    double openTime = 0;
                    foreach (var real in progStates)
                    {
                        if (real.ProgState != -1)
                        {
                            openTime += Convert.ToDouble((real.EndTime - real.startTime).Minutes);
                        }
                        if (real.ProgState == 1)
                        {
                            runTime += Convert.ToDouble((real.EndTime - real.startTime).Minutes);
                        }
                    }
                    double time = (nowTime - toDayTimeBegin).Minutes;
                    deviceStateInfo.OpenRate    = (openTime / time).ToString("0.0000");
                    deviceStateInfo.RunRate     = (runTime / time).ToString("0.0000");
                    deviceStateInfo.ProcessRate = (runTime / openTime).ToString("0.0000");
                    deviceStateInfo.OpenTime    = openTime.ToString("0.0000");
                    deviceStateInfo.RunTime     = runTime.ToString("0.0000");
                    deviceStateInfos.Add(deviceStateInfo);
                }
            }
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            var json = serializer.Serialize(deviceStateInfos);

            context.Response.Write(json);
        }
Beispiel #2
0
        public void ProcessRequest(HttpContext context)
        {
            //设备利用占比
            Int32 workId = 0;

            if (Int32.TryParse(context.Request["workId"], out workId))
            {
            }
            else
            {
                return;
            }

            List <DeviceUseRate> deviceUseRates = new List <DeviceUseRate>();
            List <string>        timeList       = new List <string>();

            using (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities())
            {
                var realTime = wms.JDJS_WMS_Device_ProgState_Info;
                List <progState> progStates = new List <progState>();
                foreach (var item in realTime)
                {
                    progState state = new progState();
                    if (item.EndTime == null)
                    {
                        state.EndTime = DateTime.Now;
                    }
                    else
                    {
                        state.EndTime = Convert.ToDateTime(item.EndTime);
                    }
                    state.startTime = Convert.ToDateTime(item.StartTime);
                    state.ProgState = Convert.ToInt32(item.ProgState);
                    DateTime startTime = state.startTime;
                    DateTime endtime   = state.startTime;
                    int      day       = 1;
                    while (startTime.Date != endtime.Date)
                    {
                        progState progState = new progState();
                        progState.ProgState = Convert.ToInt32(item.ProgState);
                        progState.startTime = state.startTime;
                        progState.EndTime   = state.startTime.AddDays(1).Date.AddSeconds(-1);
                        progStates.Add(progState);
                        state.startTime = state.startTime.AddDays(1).Date;
                        startTime       = state.startTime;
                        day++;
                    }
                    progState progStateover = new progState();
                    progStateover.startTime = state.startTime;
                    progStateover.EndTime   = state.EndTime;
                    progStateover.ProgState = state.ProgState;
                    progStates.Add(progStateover);
                }
                progStates.OrderByDescending(r => r.startTime);
                foreach (var item in progStates)
                {
                    double time    = (item.EndTime - item.startTime).TotalMinutes;
                    string timestr = item.startTime.Year.ToString() + "-" + item.startTime.Month.ToString() + "-" + item.startTime.Day.ToString();
                    if (timeList.Contains(timestr))
                    {
                        var rate = deviceUseRates.Where(r => r.time == timestr).FirstOrDefault();
                        switch (item.ProgState)
                        {
                        case -1:
                            rate.other += time;
                            break;

                        case 0:
                            rate.stop = +time;
                            break;

                        case 1:
                            rate.run += time;
                            break;

                        case 2:
                            rate.other += time;
                            break;

                        case 3:
                            rate.stop += time;
                            break;

                        case 4:
                            rate.alarm += time;

                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        timeList.Add(timestr);
                        DeviceUseRate deviceUseRate = new DeviceUseRate();
                        deviceUseRate.time = timestr;
                        switch (item.ProgState)
                        {
                        case -1:
                            deviceUseRate.other = time;
                            break;

                        case 0:
                            deviceUseRate.stop = time;
                            break;

                        case 1:
                            deviceUseRate.run = time;
                            break;

                        case 2:
                            deviceUseRate.other = time;
                            break;

                        case 3:
                            deviceUseRate.stop = time;
                            break;

                        case 4:
                            deviceUseRate.alarm = time;

                            break;

                        default:
                            break;
                        }
                        deviceUseRates.Add(deviceUseRate);
                    }
                }
            }
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            var json = serializer.Serialize(deviceUseRates);

            context.Response.Write(json);
        }
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request["workId"] == "全部")
            {
                {
                    //稼动率top5
                    //int LocationID = workId;
                    List <CropMobility> cropMobilitiesUse = new List <CropMobility>();

                    List <CropMobility> cropMobilities = new List <CropMobility>();
                    using (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities())
                    {
                        var devices = wms.JDJS_WMS_Device_Info;
                        foreach (var item in devices)
                        {
                            CropMobility crops  = new CropMobility();
                            int          cncID  = Convert.ToInt32(item.ID);
                            string       cncNum = item.MachNum;
                            crops.cncNum = cncNum;
                            DateTime CancleStartTime = DateTime.Now.AddDays(-1); //计算稼动率的开始时间
                            DateTime CancleEndTime   = DateTime.Now;             //计算稼动率的结束时间

                            double           runTime    = 0;
                            double           openTime   = 0;
                            var              states     = wms.JDJS_WMS_Device_ProgState_Info.Where(r => r.CncID == cncID && ((r.StartTime >= CancleStartTime && r.StartTime <= CancleEndTime) || (r.EndTime >= CancleStartTime && r.EndTime <= CancleEndTime) || (r.StartTime <= CancleStartTime && r.EndTime >= CancleEndTime)));
                            List <progState> progStates = new List <progState>();
                            foreach (var real in states)
                            {
                                progState progState = new progState();
                                progState.ProgState = Convert.ToInt32(real.ProgState);
                                progState.startTime = Convert.ToDateTime(real.StartTime);
                                if (Convert.ToDateTime(real.StartTime) < CancleStartTime)
                                {
                                    progState.startTime = CancleStartTime;
                                }
                                if (real.EndTime == null)
                                {
                                    progState.EndTime = DateTime.Now;
                                }
                                else
                                {
                                    if (real.EndTime > CancleEndTime)
                                    {
                                        progState.EndTime = Convert.ToDateTime(CancleEndTime);
                                    }
                                    else
                                    {
                                        progState.EndTime = Convert.ToDateTime(real.EndTime);
                                    }
                                }
                                progStates.Add(progState);
                            }

                            foreach (var real in progStates)
                            {
                                if (real.ProgState != -1)
                                {
                                    openTime += Convert.ToDouble((real.EndTime - real.startTime).TotalMinutes);
                                }
                                if (real.ProgState == 1)
                                {
                                    runTime += Convert.ToDouble((real.EndTime - real.startTime).TotalMinutes);
                                }
                            }
                            if (openTime != 0)
                            {
                                crops.progress = runTime / openTime;
                            }
                            else
                            {
                                crops.progress = 0;
                            }
                            cropMobilities.Add(crops);
                        }
                    }

                    cropMobilities = cropMobilities.OrderByDescending(r => r.progress).ToList();

                    for (int i = 0; i < 5; i++)
                    {
                        if (cropMobilities.Count() > i)
                        {
                            CropMobility crop = new CropMobility();
                            crop.cncNum   = cropMobilities[i].cncNum;
                            crop.progress = Math.Round(cropMobilities[i].progress, 4);
                            cropMobilitiesUse.Add(crop);
                        }
                        else
                        {
                            CropMobility crop = new CropMobility();
                            crop.cncNum   = "";
                            crop.progress = 0;
                            cropMobilitiesUse.Add(crop);
                        }
                    }

                    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    var model = new { code = 0, data = cropMobilitiesUse };
                    var json  = serializer.Serialize(model);
                    context.Response.Write("data:" + json + "\n\n");
                    context.Response.ContentType = "text/event-stream";
                }
            }
            else if (context.Request["workId"] == "34台")
            {
                {
                    List <int> cncIDs = new List <int>();
                    for (int i = 95; i < 112; i++)
                    {
                        cncIDs.Add(i);
                    }
                    for (int i = 122; i < 139; i++)
                    {
                        cncIDs.Add(i);
                    }
                    //稼动率top5
                    //int LocationID = workId;
                    List <CropMobility> cropMobilitiesUse = new List <CropMobility>();

                    List <CropMobility> cropMobilities = new List <CropMobility>();
                    using (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities())
                    {
                        var devices = wms.JDJS_WMS_Device_Info;
                        foreach (var item in devices)
                        {
                            CropMobility crops = new CropMobility();
                            int          cncID = Convert.ToInt32(item.ID);
                            if (cncIDs.Contains(cncID))
                            {
                                string cncNum = item.MachNum;
                                crops.cncNum = cncNum;
                                DateTime CancleStartTime = DateTime.Now.AddDays(-1); //计算稼动率的开始时间
                                DateTime CancleEndTime   = DateTime.Now;             //计算稼动率的结束时间

                                double           runTime    = 0;
                                double           openTime   = 0;
                                var              states     = wms.JDJS_WMS_Device_ProgState_Info.Where(r => r.CncID == cncID && ((r.StartTime >= CancleStartTime && r.StartTime <= CancleEndTime) || (r.EndTime >= CancleStartTime && r.EndTime <= CancleEndTime) || (r.StartTime <= CancleStartTime && r.EndTime >= CancleEndTime)));
                                List <progState> progStates = new List <progState>();
                                foreach (var real in states)
                                {
                                    progState progState = new progState();
                                    progState.ProgState = Convert.ToInt32(real.ProgState);
                                    progState.startTime = Convert.ToDateTime(real.StartTime);
                                    if (Convert.ToDateTime(real.StartTime) < CancleStartTime)
                                    {
                                        progState.startTime = CancleStartTime;
                                    }
                                    if (real.EndTime == null)
                                    {
                                        progState.EndTime = DateTime.Now;
                                    }
                                    else
                                    {
                                        if (real.EndTime > CancleEndTime)
                                        {
                                            progState.EndTime = Convert.ToDateTime(CancleEndTime);
                                        }
                                        else
                                        {
                                            progState.EndTime = Convert.ToDateTime(real.EndTime);
                                        }
                                    }
                                    progStates.Add(progState);
                                }

                                foreach (var real in progStates)
                                {
                                    if (real.ProgState != -1)
                                    {
                                        openTime += Convert.ToDouble((real.EndTime - real.startTime).TotalMinutes);
                                    }
                                    if (real.ProgState == 1)
                                    {
                                        runTime += Convert.ToDouble((real.EndTime - real.startTime).TotalMinutes);
                                    }
                                }
                                if (openTime != 0)
                                {
                                    crops.progress = runTime / openTime;
                                }
                                else
                                {
                                    crops.progress = 0;
                                }
                                cropMobilities.Add(crops);
                            }
                        }
                    }

                    cropMobilities = cropMobilities.OrderByDescending(r => r.progress).ToList();

                    for (int i = 0; i < 5; i++)
                    {
                        if (cropMobilities.Count() > i)
                        {
                            CropMobility crop = new CropMobility();
                            crop.cncNum   = cropMobilities[i].cncNum;
                            crop.progress = Math.Round(cropMobilities[i].progress, 4);
                            cropMobilitiesUse.Add(crop);
                        }
                        else
                        {
                            CropMobility crop = new CropMobility();
                            crop.cncNum   = "";
                            crop.progress = 0;
                            cropMobilitiesUse.Add(crop);
                        }
                    }

                    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    var model = new { code = 0, data = cropMobilitiesUse };
                    var json  = serializer.Serialize(model);
                    context.Response.Write("data:" + json + "\n\n");
                    context.Response.ContentType = "text/event-stream";
                }
            }
            else
            {
                var workId = int.Parse(context.Request["workId"]);
                {
                    //稼动率top5
                    int LocationID = workId;
                    List <CropMobility> cropMobilitiesUse = new List <CropMobility>();

                    List <CropMobility> cropMobilities = new List <CropMobility>();
                    using (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities())
                    {
                        var works  = wms.JDJS_WMS_Location_Info.ToList();
                        var device = wms.JDJS_WMS_Device_Info.ToList();
                        List <WebApplication2.Kanban.现场.CncRead> objs = new List <WebApplication2.Kanban.现场.CncRead>();
                        List <int> workIds = new List <int>();
                        WebApplication2.Kanban.现场.机台状态 funs = new WebApplication2.Kanban.现场.机台状态();
                        var devices = funs.fun(workId, works, device, objs, workIds);


                        //var devices = wms.JDJS_WMS_Device_Info.Where(r => r.Position == LocationID);

                        foreach (var item in devices)
                        {
                            CropMobility crops  = new CropMobility();
                            int          cncID  = Convert.ToInt32(item.ID);
                            string       cncNum = item.MachNum;
                            crops.cncNum = cncNum;
                            DateTime CancleStartTime = DateTime.Now.AddDays(-1); //计算稼动率的开始时间
                            DateTime CancleEndTime   = DateTime.Now;             //计算稼动率的结束时间

                            double           runTime    = 0;
                            double           openTime   = 0;
                            var              states     = wms.JDJS_WMS_Device_ProgState_Info.Where(r => r.CncID == cncID && ((r.StartTime >= CancleStartTime && r.StartTime <= CancleEndTime) || (r.EndTime >= CancleStartTime && r.EndTime <= CancleEndTime) || (r.StartTime <= CancleStartTime && r.EndTime >= CancleEndTime)));
                            List <progState> progStates = new List <progState>();
                            foreach (var real in states)
                            {
                                progState progState = new progState();
                                progState.ProgState = Convert.ToInt32(real.ProgState);
                                progState.startTime = Convert.ToDateTime(real.StartTime);
                                if (Convert.ToDateTime(real.StartTime) < CancleStartTime)
                                {
                                    progState.startTime = CancleStartTime;
                                }
                                if (real.EndTime == null)
                                {
                                    progState.EndTime = DateTime.Now;
                                }
                                else
                                {
                                    if (real.EndTime > CancleEndTime)
                                    {
                                        progState.EndTime = Convert.ToDateTime(CancleEndTime);
                                    }
                                    else
                                    {
                                        progState.EndTime = Convert.ToDateTime(real.EndTime);
                                    }
                                }
                                progStates.Add(progState);
                            }

                            foreach (var real in progStates)
                            {
                                if (real.ProgState != -1)
                                {
                                    openTime += Convert.ToDouble((real.EndTime - real.startTime).TotalMinutes);
                                }
                                if (real.ProgState == 1)
                                {
                                    runTime += Convert.ToDouble((real.EndTime - real.startTime).TotalMinutes);
                                }
                            }
                            if (openTime != 0)
                            {
                                crops.progress = runTime / openTime;
                            }
                            else
                            {
                                crops.progress = 0;
                            }
                            cropMobilities.Add(crops);
                        }
                    }

                    cropMobilities = cropMobilities.OrderByDescending(r => r.progress).ToList();

                    for (int i = 0; i < 5; i++)
                    {
                        if (cropMobilities.Count() > i)
                        {
                            CropMobility crop = new CropMobility();
                            crop.cncNum   = cropMobilities[i].cncNum;
                            crop.progress = Math.Round(cropMobilities[i].progress, 4);
                            cropMobilitiesUse.Add(crop);
                        }
                        else
                        {
                            CropMobility crop = new CropMobility();
                            crop.cncNum   = "";
                            crop.progress = 0;
                            cropMobilitiesUse.Add(crop);
                        }
                    }

                    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    var model = new { code = 0, data = cropMobilitiesUse };
                    var json  = serializer.Serialize(model);
                    context.Response.Write("data:" + json + "\n\n");
                    context.Response.ContentType = "text/event-stream";
                }
            }
        }
Beispiel #4
0
        public void ProcessRequest(HttpContext context)
        {
            int workId = 0;

            if (Int32.TryParse(context.Request["workId"], out workId))
            {
                {
                    int    LocationID = workId;
                    double TimeC      = 0;
                    double xingnnegC  = 0;
                    {
                        //稼动率评估

                        DateTime nowTime        = DateTime.Now;
                        DateTime toDayTimeBegin = DateTime.Now.AddDays(-1);

                        double runTime   = 0;
                        double openTime  = 0;
                        double lilunTime = 0;
                        double shijiTime = 0;
                        using (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities())
                        {
                            var works   = wms.JDJS_WMS_Location_Info.ToList();
                            var devices = wms.JDJS_WMS_Device_Info.ToList();
                            List <WebApplication2.Kanban.现场.CncRead> objs = new List <WebApplication2.Kanban.现场.CncRead>();
                            List <int> workIds = new List <int>();
                            WebApplication2.Kanban.现场.机台状态 funs = new 现场.机台状态();
                            var Devices = funs.fun(workId, works, devices, objs, workIds);

                            //var Devices = wms.JDJS_WMS_Device_Info.Where(r => r.Position == LocationID);
                            foreach (var item in Devices)
                            {
                                int cncID  = Convert.ToInt32(item.ID);
                                var states = wms.JDJS_WMS_Device_ProgState_Info.Where(r => r.CncID == cncID && (r.StartTime > toDayTimeBegin || r.EndTime > toDayTimeBegin || r.EndTime == null));
                                List <progState> progStates = new List <progState>();
                                foreach (var real in states)
                                {
                                    progState progState = new progState();
                                    progState.ProgState = Convert.ToInt32(real.ProgState);
                                    progState.startTime = Convert.ToDateTime(real.StartTime);
                                    if (Convert.ToDateTime(real.StartTime) < toDayTimeBegin)
                                    {
                                        progState.startTime = toDayTimeBegin;
                                    }
                                    if (real.EndTime == null)
                                    {
                                        progState.EndTime = nowTime;
                                    }
                                    else
                                    {
                                        progState.EndTime = Convert.ToDateTime(real.EndTime);
                                    }
                                    progStates.Add(progState);
                                }

                                foreach (var real in progStates)
                                {
                                    if (real.ProgState != -1)
                                    {
                                        openTime += Convert.ToDouble((real.EndTime - real.startTime).TotalMinutes);
                                    }
                                    if (real.ProgState == 1)
                                    {
                                        runTime += Convert.ToDouble((real.EndTime - real.startTime).TotalMinutes);
                                    }
                                }
                            }
                            if (openTime != 0)
                            {
                                TimeC = runTime / openTime;
                            }
                            else
                            {
                                TimeC = 0;
                            }
                            foreach (var item in Devices)
                            {
                                int cncID = Convert.ToInt32(item.ID);

                                var processes = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.CncID == cncID && r.EndTime > toDayTimeBegin && r.isFlag == 3);
                                foreach (var real in processes)
                                {
                                    int    processID   = Convert.ToInt32(real.ProcessID);
                                    var    processInfo = wms.JDJS_WMS_Order_Process_Info_Table.Where(r => r.ID == processID).FirstOrDefault();
                                    double processTime = Convert.ToDouble(processInfo.ProcessTime);
                                    lilunTime += processTime;
                                    double processTimeLilun = (Convert.ToDateTime(real.EndTime) - Convert.ToDateTime(real.StartTime)).TotalMinutes;
                                    shijiTime += processTimeLilun;
                                }
                            }
                            if (shijiTime == 0)
                            {
                                xingnnegC = 0;
                            }
                            else
                            {
                                xingnnegC = lilunTime / shijiTime;
                            }
                        }
                    }

                    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    var model = new { TimeC = TimeC, xingnnegC = xingnnegC };
                    var json  = serializer.Serialize(model);

                    context.Response.Write("data:" + json + "\n\n");
                    context.Response.ContentType = "text/event-stream";
                }
            }
            else
            {
                return;
            }
        }