// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// General information section.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// $Author:yongkiang$ User who last changed the file
// $Date:1/2/2013 12:16:38 PM$ Date and time of last check in
// $Revision:1.0$ Visual SourceSafe version number
// $Workfile::   MotorRS.h                                             $ Filename
// End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#pragma once

#include <vector>
#include <string>

#include "Structure.h"
#include "ado2.h"
#include "DllDefines.h"

// MotorRS.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CMotorRS recordset

class MCCTRDLLCLASS CMotorRS
{
public:
    CMotorRS();
    virtual ~CMotorRS();

    // Field/Param Data
    long m_ID;
    std::string m_Module_Name;
    std::string m_Motor_Name;
    std::string m_Position_Name;
    BOOL m_Teach_Enable;
    BOOL m_Save_All_Pkg;

    // Overrides
public:
    virtual std::string GetDefaultDBName(); // Default database name
    virtual std::string GetDefaultSQL();    // Default SQL for Recordset


    //  Close Recordset and close database
    virtual void Close();

// Implementation
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif

    void InitMotorModule(std::vector<stModule>& modules); // Function to init motor module to maintenance page

    //  get Save all pkg
    BOOL GetSaveAllPkg(std::string csPosName);

    int GetNoOfMtrs(std::vector<stModule>& modules);

    //  set the motor position name from Motor and MotorSubField table
    [[deprecated("For Legacy GUI use case")]] 
    void SetMtrPosName(std::vector<stModule>& modules);
    //  get motor and pos name
    [[deprecated("For Legacy GUI use case")]] 
    bool GetMtrAndPosName(std::vector<stModule>& modules, int iMtrNo, int iMtrPos, std::string& csMtrName, std::string& csMtrPos);
    //  get motor pos name
    [[deprecated("For Legacy GUI use case")]] 
    int GetMtrPosNo(std::vector<stModule>& module, std::string csModuleName, int iMtrNo, std::string csMtrPos,
        std::string csSubPosName);

private:
    CADODatabase m_db;
    CADORecordset m_rs;

    std::vector<std::string> m_vecMtrPos[MAX_MODULE][MAX_MOTOR]; // store Motor Position Name

    bool Open(std::string sqlQuery);
    void GetAllFieldsValue();

    int GetModuleIndex(std::vector<stModule>& modules); // return the module index
    void initNoOfMtr(std::vector<stModule>& modules);   // initialised no of motor to 0
};
