示例#1
0
        public string PcToCNC(string ncProgramData, string MacId, string filename, string vernoval)
        {
            string reply     = "";
            int    RetVal    = 0;
            int    userId    = Convert.ToInt32(Session["UserId"]);
            int    MacID     = Convert.ToInt32(MacId);
            int    versionNo = Convert.ToInt32(vernoval);
            tblprogramtransferhistory pth = new tblprogramtransferhistory();

            pth.IsDeleted    = 0;
            pth.MachineID    = MacID;
            pth.ProgramName  = filename;
            pth.UploadedTime = DateTime.Now;
            pth.Version      = versionNo;
            pth.UserID       = userId;
            db.tblprogramtransferhistories.Add(pth);
            db.SaveChanges();

            int             programTransferHistoryId = pth.PTHID;
            object          ip           = db.tblmachinedetails.Where(m => m.MachineID == MacID).Select(m => m.IPAddress).FirstOrDefault();
            ushort          port         = 8193;
            ProgramTransfer PT           = new ProgramTransfer(ip.ToString());
            string          fileLocation = @"C:\NCProgram\NcProgram.txt";

            PT.CreateFileForProgramTransfer(ncProgramData);
            reply = PT.UploadCNCProgram(programTransferHistoryId, fileLocation, out RetVal);
            PT.DeleteFileProgramTransfer();
            return(reply);
        }
示例#2
0
        //Get Program List for the Machine Connected
        public JsonResult ProgramList(int MacID)
        {
            PrgDetList = new List <ProgramListDet>();
            object          ip = db.tblmachinedetails.Where(m => m.MachineID == MacID).Select(m => m.IPAddress).FirstOrDefault();
            ProgramTransfer PT = new ProgramTransfer(ip.ToString());

            PrgDetList = PT.GetProgramList();
            return(Json(PrgDetList, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        //get Program data
        public JsonResult ProgramData(int MacID, string ProgNo)
        {
            String          ProgData = null;// = new StringBuilder();
            object          ip       = db.tblmachinedetails.Where(m => m.MachineID == MacID).Select(m => m.IPAddress).FirstOrDefault();
            ProgramTransfer PT       = new ProgramTransfer(ip.ToString());

            PT.GetProgramDataNC(ProgNo, out ProgData);
            return(Json(ProgData.ToString(), JsonRequestBehavior.AllowGet));
        }
示例#4
0
        //Get the version list of the program from the Program selected for the connected machine.
        public JsonResult PCProgramList(int MacID, String ProgNo)
        {
            List <ProgramVersionListDet> PrgVerDetList = new List <ProgramVersionListDet>();
            object          ip     = db.tblmachinedetails.Where(m => m.MachineID == MacID).Select(m => m.IPAddress).FirstOrDefault();
            String          MacInv = db.tblmachinedetails.Where(m => m.MachineID == MacID).Select(m => m.MachineDisplayName).FirstOrDefault();
            ProgramTransfer PT     = new ProgramTransfer(ip.ToString());

            PT.GetVersionListPCProgram(MacInv.ToString(), ProgNo.ToString(), out PrgVerDetList);
            return(Json(PrgVerDetList, JsonRequestBehavior.AllowGet));
        }
示例#5
0
        //Get Program data from the Version selected of the Program or by default the Latest Version Number Present
        public JsonResult ProgramDataPC(int MacID, string ProgNo, int VerNo)
        {
            String          ProgData; //= "";
            object          ip     = db.tblmachinedetails.Where(m => m.MachineID == MacID).Select(m => m.IPAddress).FirstOrDefault();
            String          MacInv = db.tblmachinedetails.Where(m => m.MachineID == MacID).Select(m => m.MachineDisplayName).FirstOrDefault();
            ProgramTransfer PT     = new ProgramTransfer(ip.ToString());

            PT.GetProgramDataPC(MacInv, ProgNo.ToString(), VerNo, out ProgData);
            return(Json(ProgData.ToString(), JsonRequestBehavior.AllowGet));
        }
示例#6
0
        public JsonResult ProgramDelete(int MacID, string ProgNo)
        {
            string          retStatus = null;
            object          ip        = db.tblmachinedetails.Where(m => m.MachineID == MacID).Select(m => m.IPAddress).FirstOrDefault();
            String          MacInv    = db.tblmachinedetails.Where(m => m.MachineID == MacID).Select(m => m.MachineDisplayName).FirstOrDefault();
            ProgramTransfer PT        = new ProgramTransfer(ip.ToString());

            retStatus = PT.DeleteProgram(MacInv, ProgNo);

            return(Json(retStatus, JsonRequestBehavior.AllowGet));
        }
示例#7
0
        public ActionResult Index(HttpPostedFileBase file, string PlantID, string ShopID = null, string CellID = null, string WorkCenterID = null)
        {
            if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty))
            {
                return(RedirectToAction("Login", "Login", null));
            }

            ViewBag.Logout          = Session["Username"].ToString().ToUpper();
            ViewBag.roleid          = Session["RoleID"];
            Session["MachineID"]    = WorkCenterID;
            ViewBag.ReturnStatusMsg = null;
            if (Request.Files["file"].ContentLength > 0)
            {
                //Folder Names also MachineID
                //Based on MachineID Push the File into Respective Directory.
                //string Path = @"D:\SRKSSoftwareSolutions-Bangalore\Applications\ProgramTransferData";
                string Path         = @"C:\TataReport\ProgramTransferData";
                int    WCID         = Convert.ToInt32(WorkCenterID);
                String MachineInv   = db.tblmachinedetails.Where(m => m.MachineID == WCID).Select(m => m.MachineDisplayName).FirstOrDefault();
                string fileLocation = Server.MapPath("~/Content/") + Request.Files["file"].FileName;
                if (System.IO.File.Exists(fileLocation))
                {
                    System.IO.File.Delete(fileLocation);
                }

                Request.Files["file"].SaveAs(fileLocation);

                //Copy File into machine Folder
                string filename = Request.Files["file"].FileName;

                string MacWiseFolder = @Path + @"\" + MachineInv;
                if (!System.IO.Directory.Exists(MacWiseFolder))
                {
                    System.IO.Directory.CreateDirectory(MacWiseFolder);
                }
                string destinationPathWithFileName = @Path + @"\" + MachineInv + @"\" + Request.Files["file"].FileName;
                System.IO.File.Copy(fileLocation, destinationPathWithFileName, true);

                //var dirName = new DirectoryInfo(System.IO.Path.GetDirectoryName(destinationPathWithFileName)).Name; //Works
                ////string [] PathArray = destinationPathWithFileName.Split('\\');
                ////string FolderName = PathArray[PathArray.Length - 2];
                //var dirName1 = new DirectoryInfo(System.IO.Path.GetDirectoryName(dirName)).Name; //Works
                //var a = 0;

                //object ip = "192.168.0.1";   // "192.168.0.1" or "CNC-1.FACTORY"
                //ushort port = 0 ;            //  FOCAS1/Ethernet or FOCAS2/Ethernet (TCP) function
                //int timeout = 0;           //seconds if 0 infinitely waits

                //Log this event.
                int MacID = Convert.ToInt32(WorkCenterID);
                tblprogramtransferhistory pth = new tblprogramtransferhistory();
                pth.IsDeleted    = 0;
                pth.MachineID    = MacID;
                pth.ProgramName  = Request.Files["file"].FileName;
                pth.UploadedTime = DateTime.Now;
                pth.Version      = 1;
                pth.UserID       = Convert.ToInt32(Session["UserId"]);
                db.tblprogramtransferhistories.Add(pth);
                db.SaveChanges();


                //Based on WorkCenterID get IpAddress.
                object ip      = db.tblmachinedetails.Where(m => m.MachineID == MacID).Select(m => m.IPAddress).FirstOrDefault();
                ushort port    = 8193;     //  FOCAS1/Ethernet or FOCAS2/Ethernet (TCP) function
                int    timeout = 0;        //seconds if 0 infinitely waits

                int RetVal = 0;
                int pthID  = pth.PTHID;
                //Session["pthID"] = pthID;
                //DownloadNCProg d = new DownloadNCProg(ip, port, timeout, fileLocation);
                //string retString = d.UploadCNCProgram(pthID, out RetVal);

                ProgramTransfer PT        = new ProgramTransfer(ip.ToString());
                string          retString = PT.UploadCNCProgram(pthID, fileLocation, out RetVal);
                //System.Threading.Thread.Sleep(100000);

                if (retString == "Success")
                {
                    var pthData = db.tblprogramtransferhistories.Find(pthID);
                    if (pthData != null)
                    {
                        pthData.ReturnStatus    = 1;
                        pthData.ReturnDesc      = "Success";
                        pthData.ReturnTime      = DateTime.Now;
                        pthData.IsCompleted     = 1;
                        db.Entry(pthData).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        ViewBag.ReturnStatusMsg     = "The NC Program : " + filename.Split('.')[0].ToString() + " wsa successfully uploaded on the CNC Machine " + MachineInv;
                        TempData["toaster_success"] = "The NC Program : " + filename.Split('.')[0].ToString() + " wsa successfully uploaded on the CNC Machine " + MachineInv;
                    }
                    else //Hope fully this don't get executed.
                    {
                        retString = "Success but Unable to comply.";
                        TempData["toaster_warning"] = retString;
                    }
                }
                else //Upload failed.
                {
                    var pthData = db.tblprogramtransferhistories.Find(pthID);
                    if (pthData != null)
                    {
                        pthData.ReturnStatus    = 0;
                        pthData.ReturnDesc      = retString;
                        pthData.ReturnTime      = DateTime.Now;
                        pthData.IsCompleted     = 1;
                        db.Entry(pthData).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        ViewBag.ReturnStatusMsg = retString;
                    }
                    else //Hope fully this don't get executed.
                    {
                        retString += "Failure and Unable to comply.";
                        TempData["toaster_error"] = retString;
                    }
                }
            }
            else
            {
                //Not a Valid File.
                try
                {
                    //Log this event.
                    tblprogramtransferhistory pth = new tblprogramtransferhistory();
                    pth.IsDeleted    = 0;
                    pth.MachineID    = Convert.ToInt32(WorkCenterID);
                    pth.ProgramName  = Request.Files["file"].FileName;
                    pth.UploadedTime = DateTime.Now;
                    pth.UserID       = Convert.ToInt32(Session["UserId"]);
                    pth.ReturnTime   = DateTime.Now;
                    pth.ReturnStatus = 999;
                    pth.ReturnDesc   = "Not a Valid File(FileLength).";
                    pth.IsCompleted  = 1;
                    db.tblprogramtransferhistories.Add(pth);
                    db.SaveChanges();

                    ViewBag.ReturnStatusMsg   = "Not a Valid File(FileLength).";
                    TempData["toaster_error"] = "Not a Valid File(FileLength).";

                    // int pthID = pth.PTHID;
                    // Session["pthID"] = pthID;
                    //System.Threading.Thread.Sleep(30000);
                }
                catch (Exception e)
                {
                    ViewBag.ReturnStatusMsg = "Error." + e;
                }
            }
            ViewBag.GetConnected     = 1;
            ViewData["GetConnected"] = 1;
            int PlantIDInt = 0, ShopIDInt = 0, CellIDInt = 0, MacIDInt = 0;

            int.TryParse(PlantID, out PlantIDInt);
            int.TryParse(ShopID, out ShopIDInt);
            int.TryParse(CellID, out CellIDInt);
            int.TryParse(WorkCenterID, out MacIDInt);
            ViewData["PlantID"]      = new SelectList(db.tblplants.Where(m => m.IsDeleted == 0), "PlantID", "PlantName", PlantIDInt);
            ViewData["ShopID"]       = new SelectList(db.tblshops.Where(m => m.IsDeleted == 0 && m.PlantID == PlantIDInt), "ShopID", "ShopName", ShopIDInt);
            ViewData["CellID"]       = new SelectList(db.tblcells.Where(m => m.IsDeleted == 0 && m.PlantID == PlantIDInt && m.ShopID == ShopIDInt), "CellID", "CellName", CellIDInt);
            ViewData["WorkCenterID"] = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0 && m.PlantID == PlantIDInt && m.ShopID == ShopIDInt && m.CellID == CellIDInt), "MachineID", "MachineDisplayName", MacIDInt);

            return(View());
        }