#pragma once

// SemiE10RS.h : header file
//

#include <vector>
#include <string>

#include "SemiE10.h"
#include "ado2.h"

#include "DllDefines.h"

/////////////////////////////////////////////////////////////////////////////
// CSemiE10RS recordset

class MCCTRDLLCLASS CSemiE10RS : public CSemiE10
{
public:
    //  default constructor
    explicit CSemiE10RS();

    //  default destructor
    virtual ~CSemiE10RS();

    // Field/Param Data
    double m_Assist_Time;
    double m_Engineering_Runs;
    double m_Equipment_Experiments;
    double m_Failure_Time;
    double m_Installation_Modification_Rebuild_Upgrade;
    double m_Jam;
    std::string m_Lot_Number;
    double m_No_Material;
    double m_No_Operator;
    double m_No_Support_Tool;
    double m_OffLine_Training;
    double m_Out_Of_Spec_Input;
    double m_Preventive_Maintenance;
    double m_Process_Experiments;
    double m_Production_Test;
    double m_Regular_Production;
    double m_Rework;
    double m_Scheduled_Change_Of_Consumables_Chemicals;
    double m_Scheduled_Facilities_Related;
    double m_Scheduled_Maintenance_Delay;
    double m_Setup;
    double m_Shutdown_Startup;
    double m_Software_Qualification;
    COleDateTime m_Start_Lot_Time;
    double m_Stop_Machine;
    long m_Unit_Count;
    double m_UnScheduled_Change_Of_Consumables_Chemicals;
    double m_UnScheduled_Facilities_Related;
    double m_UnScheduled_Maintenance_Delay;
    double m_Unworked_Shifts_Days;
    double m_Work_For_3rd_Party;
    long m_Assist_Count;
    long m_Failure_Count;


    // 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();

    //  set the database record number according to the lot number and lot start time
    StSemiE10 GetLotRecord(std::string lpLotNo, std::string csLotStartTime);


    //  save lot time to database
    void SaveLotInfo(LPCTSTR lpLotNo, LPCTSTR lpLotStartTime);

    //  Delete lot record
    void DeleteLotRecord(std::string csLotNumber, double dStartDateTime);

    //  get all equipment substate field name
    std::vector<std::string> GetAllFieldName();

    //  Get Table Name
    std::string GetTableName();

    //  record lot no to Lot time info
    //  void RecordLotNo(LPCTSTR lpLotNo, LPCTSTR lpCurTime);
    enum
    {
        EQUIP_SUBSTATE_INDEX = 2,
    };

private:
    //  set ini file key name
    void SetIniKeyName();

    //  convert time to 1 decimal places
    void ConvertTo1DecimalPlaces(double& dTime);

//    CCombineLot m_combineLot;

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

    CADODatabase m_db;
    CADORecordset m_rs;

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