// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// General information section.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// $Author:yongkiang$ User who last changed the file
// $Date:1/2/2013 12:17:39 PM$ Date and time of last check in
// $Revision:1.0$ Visual SourceSafe version number
// $Workfile::   lotmsg.h                                              $ Filename
// End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#if !defined __LOTMSG_H__
#define __LOTMSG_H__

#include <afxmt.h>

class CRun;

class CMsgItem
{
// Attributes
public:
    int m_id;
    int m_nMsgID;

    bool m_bStored;

    int  m_nCategory;
    BOOL m_bCount;

    CString m_msgID;
    CString m_msg;
    CString m_module;
    CString m_csRemedy1;
    CString m_csRemedy2;
    CString m_csRemedy3;

    COleDateTime m_msgTime;
    CString      m_csFaultFilename;
    CString      m_csMainDisplayFilename;
    CPoint       m_cpMainIndicator;
    CPoint       m_cpFaultIndicator;
};

#define MSG_JAM_STR "Jam"
#define MSG_WARNING_STR "Warning"
#define MSG_BUZZER_STR "Buzzer"

#define BUZZER      9999
#define CLEAR_ALL   0

#define STORE_WARN          true
#define DO_NOT_STORE_WARN   false

#ifdef  BUILD_MCCTRDLL
#define     MCCTRDLLCLASS   __declspec(dllexport)
#else
#define     MCCTRDLLCLASS   __declspec(dllimport)
#endif

class CLotMsgRS;

class MCCTRDLLCLASS CLotMsg
{
public:
    void DeleteRecord(CString csLotNumber, double dStartDateTime);
    void GetWarningMsg(CPtrList *pList);
    void GetJamMsg(CPtrList *pList);
    CLotMsg();
    ~CLotMsg();

// Clear Message
    void ClearAllMsg();
    void ClearAllJamMsg();
    bool ClearWarningMsg(int nID, COleDateTime odtWarnEndTime);
    void ClearBuzzer(CRun *pRun);
    void ClearBuzzers(CRun *pRun);

// Pause and continue message logging

// Jam
    void SetJamMsg(int nID, COleDateTime odtJamStartTime, BOOL bCount);
    bool HasJam()
    {
        return m_jamMsgList.GetHeadPosition() != NULL;
    }

// Warnings
    bool SetWarningMsg(int nID, COleDateTime odtWarnTime, bool bStoreWarn = STORE_WARN);
    bool HasWarning()
    {
        return m_warningMsgList.GetHeadPosition() != NULL;
    }

// Buzzer
    void SetBuzzer(CRun *pRun);
    bool HasBuzzer()
    {
        return m_buzzerList.GetHeadPosition() != NULL;
    }

// Message Record
    void BeginMsgRecord(LPCSTR pLotNumber, CString LotStartDateTime);
    void StoreMsg();
    void StoreMsgList(CPtrList &pMsg);

    void EndMsgRecord();

//  set jam End Time
    void SetJamEndTime(COleDateTime odtJamEndTime);

//  set end time to list
    void SetEndTimeList(CPtrList &pMsg, COleDateTime odtEndTime);

// Message changed
    inline bool IsModified()
    {
        return m_bModified;
    }

    inline void ClearModified()
    {
        m_bModified = false;
    }

    inline bool HasMsg()
    {
        return (HasJam() || HasWarning());
    }

    CString GetSecGemWarningMessage(int iMsgID); // phyu 24-Sep-2012
// Attributes : Message Lists and count

private:
    // Prevent accidental copy
    CLotMsg(const CLotMsg& rhs);
// Attributes
    bool     m_bModified;
    CPtrList m_jamMsgList;
    CPtrList m_warningMsgList;
    CPtrList m_buzzerList;
    int      m_jamCount;

// Mutex
    CMutex m_msgMutex;

// Attributes: Message Record
    CLotMsgRS *m_pMsgRec;
    CString    m_lotNumber;
    bool       m_bMsgRecordStart;

// Operations
    void AddNSaveMsg(CPtrList &pMsg, int nID, COleDateTime odtStartTime, BOOL bCount = TRUE);

//  clear waring list
    bool ClearMsg(CPtrList &pMsg, int nMsgID, COleDateTime odtWarnEndTime);
    void ClearMsgList(CPtrList &pMsg);

// Message Record Operations
    void StoreMsgItem(CMsgItem *msg);

//  post jam message to sec gem jam task thread
    void PostSecGemJamMessage(CMsgItem *msg);

    CString m_LotStartDateTime;
};

#endif // !defined __LOTMSG_H__
