public JsonResult RefreshData(int PlantID = 0, int ShopID = 0, int CellID = 0, int WorkCenterID = 0)
        {
            //Don't Delete
            //retValList Order : OpTime,CutTime,PonTime,CycleTime,FeedRate,Spindal,Program,IP,MacInv,State,RunMode,Alarm,Emergency,ATCCounter.
            int    AxisCount       = 32;
            string IpAddress       = db.tblmachinedetails.Where(m => m.MachineID == WorkCenterID && m.IsDeleted == 0).Select(m => m.IPAddress).FirstOrDefault();
            string MacInvNo        = db.tblmachinedetails.Where(m => m.MachineID == WorkCenterID && m.IsDeleted == 0).Select(m => m.MachineDisplayName).FirstOrDefault();
            string AxisCountString = Convert.ToString(db.tblmachinedetails.Where(m => m.MachineID == WorkCenterID && m.IsDeleted == 0).Select(m => m.CurrentControlAxis).FirstOrDefault());
            int    MacType         = Convert.ToInt32(db.tblmachinedetails.Where(m => m.MachineID == WorkCenterID && m.IsDeleted == 0).Select(m => m.MacType).FirstOrDefault());

            if (AxisCountString != null)
            {
                AxisCount = Convert.ToInt32(AxisCountString);
            }

            VirtualHMI vhmi = new VirtualHMI(IpAddress, MacInvNo);  //Initializing the Class;
                                                                    // int NoOfAxis, out List<string> retValList, out List<AxisDetails> AxisDetailsList
            List <string>      retValList      = new List <string>();
            List <AxisDetails> AxisDetailsList = new List <AxisDetails>();

            vhmi.VirtualDispRefersh(AxisCount, out retValList, out AxisDetailsList);

            foreach (var row in AxisDetailsList)
            {
                int    AxisID   = row.AxisID;
                string AxisName = db.tbl_axisdet.Where(m => m.MachineID == WorkCenterID && m.AxisID == AxisID).Select(m => m.AxisName).FirstOrDefault();
                row.AxisName = AxisName;
            }

            ViewBag.RetValList      = retValList;
            ViewBag.AxisDetailsList = AxisDetailsList;

            List <string> ModelData     = new List <string>();
            var           ATCCounterVal = db.tblatccounters.Where(m => m.MachineID == WorkCenterID).FirstOrDefault();

            if (ATCCounterVal != null)
            {
                ModelData.Add(ATCCounterVal.Counter.ToString());
            }
            else
            {
                ModelData.Add(0.ToString());
            }
            vhmi.ModalData(ref ModelData);
            ViewBag.ModalData = ModelData;

            var result = new { RetVal = retValList, AxisDetailsList = AxisDetailsList, ModalData = ModelData };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Index(int PlantID = 0, int ShopID = 0, int CellID = 0, int WorkCenterID = 0)
        {
            if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty))
            {
                return(RedirectToAction("Login", "Login", null));
            }
            ViewBag.Logout = Session["Username"].ToString().ToUpper();
            ViewBag.roleid = Session["RoleID"];

            //int.TryParse( Convert.ToString( TempData["PlantID"]),out PlantID);
            //int.TryParse( Convert.ToString( TempData["ShopID"]),out ShopID);
            //int.TryParse( Convert.ToString( TempData["CellID"]),out CellID);
            //int.TryParse( Convert.ToString( TempData["WorkCenterID"]),out WorkCenterID);

            ViewBag.ModalData       = null;
            ViewBag.RetValList      = null;
            ViewBag.AxisDetailsList = null;

            if (WorkCenterID != 0)
            {
                //Don't Delete
                //retValList Order : OpTime,CutTime,PonTime,CycleTime,FeedRate,Spindal,Program,IP,MacInv,State,RunMode,Alarm,Emergency,ATCCounter.
                int    AxisCount       = 32;
                string IpAddress       = db.tblmachinedetails.Where(m => m.MachineID == WorkCenterID && m.IsDeleted == 0).Select(m => m.IPAddress).FirstOrDefault();
                string MacInvNo        = db.tblmachinedetails.Where(m => m.MachineID == WorkCenterID && m.IsDeleted == 0).Select(m => m.MachineDisplayName).FirstOrDefault();
                string AxisCountString = Convert.ToString(db.tblmachinedetails.Where(m => m.MachineID == WorkCenterID && m.IsDeleted == 0).Select(m => m.CurrentControlAxis).FirstOrDefault());
                int    MacType         = Convert.ToInt32(db.tblmachinedetails.Where(m => m.MachineID == WorkCenterID && m.IsDeleted == 0).Select(m => m.MacType).FirstOrDefault());
                if (AxisCountString != null)
                {
                    AxisCount = Convert.ToInt32(AxisCountString);
                }

                VirtualHMI vhmi = new VirtualHMI(IpAddress, MacInvNo);  //Initializing the Class;
                // int NoOfAxis, out List<string> retValList, out List<AxisDetails> AxisDetailsList
                List <string>      retValList      = new List <string>();
                List <AxisDetails> AxisDetailsList = new List <AxisDetails>();
                vhmi.VirtualDispRefersh(AxisCount, out retValList, out AxisDetailsList);

                foreach (var row in AxisDetailsList)
                {
                    int    AxisID   = row.AxisID;
                    string AxisName = db.tbl_axisdet.Where(m => m.MachineID == WorkCenterID && m.AxisID == AxisID).Select(m => m.AxisName).FirstOrDefault();
                    row.AxisName = AxisName;
                }

                ViewBag.RetValList      = retValList;
                ViewBag.AxisDetailsList = AxisDetailsList;

                List <string> ModelData     = new List <string>();
                var           ATCCounterVal = db.tblatccounters.Where(m => m.MachineID == WorkCenterID).FirstOrDefault();
                if (ATCCounterVal != null)
                {
                    ModelData.Add(ATCCounterVal.Counter.ToString());
                }
                else
                {
                    ModelData.Add(0.ToString());
                }
                vhmi.ModalData(ref ModelData);
                ViewBag.ModalData        = ModelData;
                ViewData["PlantID"]      = new SelectList(db.tblplants.Where(m => m.IsDeleted == 0), "PlantID", "PlantName", PlantID);
                ViewData["ShopID"]       = new SelectList(db.tblshops.Where(m => m.IsDeleted == 0 && m.PlantID == PlantID), "ShopID", "ShopName", ShopID);
                ViewData["CellID"]       = new SelectList(db.tblcells.Where(m => m.IsDeleted == 0 && m.PlantID == PlantID && m.ShopID == ShopID), "CellID", "CellName", CellID);
                ViewData["WorkCenterID"] = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0 && m.PlantID == PlantID && m.ShopID == ShopID && m.CellID == CellID && m.IsNormalWC == 0), "MachineID", "MachineDisplayName", WorkCenterID);
            }
            else
            {
                ViewData["PlantID"]      = new SelectList(db.tblplants.Where(m => m.IsDeleted == 0), "PlantID", "PlantName", PlantID);
                ViewData["ShopID"]       = new SelectList(db.tblshops.Where(m => m.IsDeleted == 0 && m.PlantID == PlantID), "ShopID", "ShopName", ShopID);
                ViewData["CellID"]       = new SelectList(db.tblcells.Where(m => m.IsDeleted == 0 && m.PlantID == PlantID && m.ShopID == ShopID), "CellID", "CellName", CellID);
                ViewData["WorkCenterID"] = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0 && m.PlantID == PlantID && m.ShopID == ShopID && m.CellID == CellID && m.IsNormalWC == 0), "MachineID", "MachineDisplayName", WorkCenterID);
            }

            return(View());
        }