示例#1
0
        void updateStationStatus(LineResponse lineResponse)
        {
            try
            {
                if (lineResponse.data == null || (lineResponse.data.Count == 0))
                {
                    return;
                }

                List <LogEntry> log = parseResponse(lineResponse.data);


                if (log != null)
                {
                    AndonAlertEventArgs alertEvent
                        = new AndonAlertEventArgs(lineResponse.timeStamp, lineResponse.id, log);

                    if (andonAlertEvent != null)
                    {
                        andonAlertEvent(this, alertEvent);
                    }
                }
            }
            catch (Exception te)
            {
                throw te;
            }
        }
        void simulationTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            simulationTimer.Stop();
            List <int> departments = new List <int>();

            departments.Add(1);
            departments.Add(2);
            //departments.Add(0);



            AndonAlertEventArgs alertEvent
                = new AndonAlertEventArgs(DateTime.Now, 1,
                                          createLog(departments));

            if (andonAlertEvent != null)
            {
                andonAlertEvent(this, alertEvent);
            }
        }
        void andonManager_andonAlertEvent(object sender, AndonAlertEventArgs e)
        {

            if (serverType == "SUB")
            {

                StringWriter writer = new StringWriter();
                xmlSerializer.Serialize(writer, e);
                String eventData = writer.ToString();
                dataAccess.addCommand(e.DeviceID,DeviceCommand.ISSUE, eventData);
                return;
            }


            int recordId = -1;

            try
            {
                

                foreach (LogEntry lg in e.DeviceLog)
                {
                    String logMsg = String.Empty;
                    if (lg.Station == 99)
                    {
                        string status = dataAccess.getDeviceStatus(e.DeviceID);
                        if (status == "ON")
                        {
                            dataAccess.updateDeviceStatus(e.DeviceID, "OFF",lg.Data);

                            tbMsg.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                               new Action(() =>
                               {
                                   tbMsg.Text += "Logoff : Line - " + lines.getLineName(e.DeviceID) + ";"
                                    + "By - " + lg.Data + "----at" + DateTime.Now.ToString()+ Environment.NewLine;
                               }));
                        }
                        else if( status == "OFF")
                        {
                            dataAccess.updateDeviceStatus(e.DeviceID, "ON",lg.Data);

                            tbMsg.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                           new Action(() =>
                           {
                               tbMsg.Text += "Logon : Line - " + lines.getLineName(e.DeviceID) + ";"
                                + "By - " + lg.Data + "----at" + DateTime.Now.ToString()+ Environment.NewLine;
                           }));
                        }
                        continue;
                    }
                    if (lg.Department == 0)
                    {
                         dataAccess.updateActualQuantity(e.DeviceID, Convert.ToInt32( lg.Data));

                        tbMsg.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                        new Action(() =>
                        {
                            tbMsg.Text +=lines.getLineName(e.DeviceID) + ":"+
                                "Production Quantity - " + lg.Data.ToString()+ "--AT "
                                + DateTime.Now.ToString()+Environment.NewLine;
                        }));

                        continue;
                    }
                    

                    logMsg += lines.getLineName(e.DeviceID) + ":";


                    if (e.DeviceID == whID)
                    {
                        logMsg += departmentTable.Rows[lg.Department - 1]["description"] + "-";
                        logMsg += "PART #" + lg.Data;
                        recordId = dataAccess.findIssueRecord(e.DeviceID, lg.Station, lg.Department, lg.Data);
                    }

                    else
                    {
                        String stationName = lines.getStationName(e.DeviceID, lg.Station);
                        if (stationName == string.Empty)
                            stationName = "Station #" + lg.Station.ToString();

                        logMsg += stationName + ":";
                        logMsg += departmentTable.Rows[lg.Department - 1]["description"] + "-";

                        if (lg.Department == 3)
                        {
                            logMsg += "PART #" + lg.Data;
                            recordId = dataAccess.findIssueRecord(e.DeviceID, lg.Station, lg.Department, lg.Data);
                        }
                        else
                        {
                            String className = lines.getClassName(e.DeviceID, lg.Station, lg.Department, Convert.ToInt32(lg.Data));

                            if (className == String.Empty)
                                lg.Data = "Class Code #" + Convert.ToInt32(lg.Data);
                            else lg.Data = className;
                            recordId = dataAccess.findIssueRecord(e.DeviceID, lg.Station, lg.Department, lg.Data);

                            logMsg += "--" + lg.Data;

                        }


                    }
                  
                    
                    


                    if (recordId == -1)     //new issue
                    {

                        recordId =
                            dataAccess.insertIssueRecord(e.DeviceID, lg.Station, lg.Department, lg.Data, logMsg);

                        Issue issue = new Issue(e.DeviceID,lg.Station,lg.Department,logMsg +"-at "+DateTime.Now.ToShortTimeString(),timeout);
                        issue.issueEscalationEvent+=new EventHandler<issueEscalateEventArgs>(issue_issueEscalationEvent);

                        Issues.Add(recordId,issue);

                        issue.raise();

                        logMsg += "--Issue Raised" + "----at: " + DateTime.Now.ToString() + Environment.NewLine;

                        

                        
                    }
                    else
                    {
                        if (dataAccess.getIssueStatus(recordId) == "raised")
                        {
                            dataAccess.updateIssueStatus(recordId, "acknowledged");
                            logMsg += "--Issue Acknowledged" + "----at: " + DateTime.Now.ToString(); 
                        }
                        else if (dataAccess.getIssueStatus(recordId) == "acknowledged")
                        {

                            dataAccess.updateIssueStatus(recordId);

                            if (Issues.ContainsKey(recordId))
                            {
                                Issues[recordId].resolve();
                                Issues.Remove(recordId);
                            }

                            logMsg += "--Issue Resolved" + "----at: " + DateTime.Now.ToString() ;
                        }
                        else return;
                    }
                    dataAccess.updateIssueMarquee();
                    tbMsg.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                            new Action(() => { tbMsg.Text += logMsg + Environment.NewLine; }));

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace, "Error", MessageBoxButton.OK);
            }

        }
        void updateStationStatus(LineResponse lineResponse)
        {
            try
            {
                if (lineResponse.data == null || (lineResponse.data.Count == 0))
                {
                    return;
                }

               // List<LogEntry> log = parseResponse(lineResponse.data);


                AndonAlertEventArgs alertEvent
                    = new AndonAlertEventArgs(lineResponse.timeStamp, lineResponse.id, lineResponse.data);

                if (andonAlertEvent != null)
                {
                    andonAlertEvent(this, alertEvent);
                }
                        
                

                        
            }
            catch( Exception te)
            {
                    throw te;
            }

        }
        void andonManager_andonAlertEvent(object sender, AndonAlertEventArgs e)
        {
            int recordId = -1;
            int cmd;
            int line;
            try
            {
                cmd = e.StationLog[0];
                
                e.StationLog.RemoveAt(0);
                switch (cmd)
                {

                    case (int) CMD.SYNCHRONIZE:
                        List<Byte> rtcData = new List<byte>();
                        DateTime now = DateTime.Now;
                        rtcData.Add(intToBCD(now.Second));
                        rtcData.Add(intToBCD(now.Minute));
                        rtcData.Add(intToBCD(now.Hour));

                        rtcData.Add((byte)(now.DayOfWeek+1));
                        rtcData.Add(intToBCD(now.Day));
                        rtcData.Add(intToBCD(now.Month));
                        rtcData.Add(intToBCD(now.Year -2000));
                        andonManager.addTransaction(01, AndonCommand.CMD_SET_RTC, rtcData);
                        break;


                    case (int) CMD.SET_REFERENCE:
                        line = e.StationLog[0];
                        e.StationLog.RemoveAt(0);
                        char[] refe = new char[e.StationLog.Count-1];
                        for(int i = 0; i< e.StationLog.Count-1; i++)
                            refe[i] = (char)e.StationLog[i];

                        reference.Code = new String(refe);

                        updateMsg("SET REFERENCE for line:" + LINES[line - 2]+"-"+reference.Code);

                        break;


                    case (int)CMD.SET_REFERENCE_CODE:
                        line = e.StationLog[0];
                        e.StationLog.RemoveAt(0);
                        char[] code = new char[e.StationLog.Count - 1];
                        for (int i = 0; i < e.StationLog.Count - 1; i++)
                            code[i] = (char)e.StationLog[i];

                        reference.Code = new String(code);

                        reference = dataAccess.getReference(line, reference);
                        if (reference.Name == String.Empty)
                        {
                            updateMsg("Invalid Code for:" + LINES[line - 2] + "-" + reference.Code);
                        }
                        else
                        {
                            updateMsg("Setting Reference for line:" + LINES[line - 2] + "-" + reference.Name);
                            var data = new List<Byte>();
                            data.Add((Byte)line);
                            data.AddRange(new List<Byte>(Encoding.ASCII.GetBytes(reference.Name)));
                            andonManager.addTransaction(01, AndonCommand.CMD_SET_REFERENCE, data);
                        }
                        

                        break;






                    case (int) CMD.SET_OPERATORS:
                        //line = e.StationId;
                        //int operators = e.StationLog[0];
                        //updateMsg("SET CYCLE TIME for line:" + LINES[line - 2]+"-"+operators.ToString());
                        break;

                    case (int)CMD.GET_CYCLE_TIME:
                        line = e.StationId;
                        reference = dataAccess.getCycleTime(line,  reference);
                        updateMsg("Setting Cycle Time for line:" + LINES[line - 2]);
                        if (reference.CycleTime != 0 && reference.BottleNeckTime != 0)
                        {
                            byte[] ct = BitConverter.GetBytes((short)reference.CycleTime);
                            byte[] bt = BitConverter.GetBytes((short)reference.BottleNeckTime);

                            var data = new List<Byte>();
                            data.Add((byte)line);
                            data.AddRange(ct.ToList());
                            data.AddRange(bt.ToList());

                            andonManager.addTransaction(01, AndonCommand.CMD_SET_CYCLE_TIME, data);
                        }

                        break;
                }
                        
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace, "Error", MessageBoxButton.OK);
            }

        }
        void updateStationStatus(LineResponse lineResponse,int deviceID)
        {
            try
            {
                List<LogEntry> log = null;
                if (lineResponse.data == null || (lineResponse.data.Count == 0))
                {
                    return;
                }
                if (deviceID == whID)
                {
                    log = parseWHResponse(lineResponse.data);
                }
                else
                log = parseResponse(lineResponse.data);


                if (log != null)
                {
                    AndonAlertEventArgs alertEvent
                        = new AndonAlertEventArgs(lineResponse.timeStamp, lineResponse.id, log);

                    if (andonAlertEvent != null)
                    {
                        andonAlertEvent(this, alertEvent);
                    }

                }


            }
            catch (Exception te)
            {
                throw te;
            }

        }
        void simulationTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
        	simulationTimer.Stop();
        	List<int> departments = new List<int>();
        	departments.Add(1);
        	departments.Add(2);
            //departments.Add(0);
        	
        	
        	
        	AndonAlertEventArgs alertEvent
                = new AndonAlertEventArgs(DateTime.Now,1,
        		                          createLog(departments));

            if (andonAlertEvent != null)
            {
                andonAlertEvent(this, alertEvent);
            }
        	
        }