// CombineLot.h: interface for the CCombineLot class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_COMBINELOT_H__987A2D4D_854E_4CD6_BB50_16FF1F1A5348__INCLUDED_)
#define AFX_COMBINELOT_H__987A2D4D_854E_4CD6_BB50_16FF1F1A5348__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "MyStringArray.h"
#include "SemiE10.h"
#include <afxdao.h>
#include <Afxcmn.h>

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

class MCCTRDLLCLASS CCombineLot
{
public:
//  constructor to set database file name, table name, field name, lot number, lot start time,
//  lot stop time and sort criteria
    CCombineLot(const char *ccsDbFileName = NULL, const char *ccsTableName = NULL,
                CStringArray *csaFieldName = NULL, CStringArray *csaFieldNameUnit = NULL,
                CStringArray *csaAvgFieldName = NULL, CStringArray *csaAvgFieldNameUnit = NULL,
                const char *ccsLotNum = NULL, double dStartTime = 0, double dStopTime = 0,
                int iSort = SORT_BY_LOT_NUM);

//  default destructor
    virtual ~CCombineLot();

//  set Database file name
    void SetDbFileName(const char *ccsDbFileName);

//  set table name
    void SetTableName(const char *ccsTableName);

//  set Field name
    void SetSumFieldName(CMyStringArray csaFieldName);

//  set Field name unit
    void SetSumFieldNameUnit(CMyStringArray csaFieldNameUnit);

//  set field name for average
    void SetAvgFieldName(CMyStringArray csaAvgFieldName);

//  set field name unit for average
    void SetAvgFieldNameUnit(CMyStringArray csaAvgFieldNameUnit);

//  set Lot Number
    void SetLotNo(const char *ccsLotNo);

//  set start and end time in double data type
    void SetStartEndTime(double dStartTime, double dStopTime);

//  set start and end time in COleDateTime data type
    void SetStartEndTime(COleDateTime odtStartTime, COleDateTime odtStopTime);

//  set start and end time CString
    void SetStartEndTime(CString csStartTime, CString csStopTime);

//  combine lot and display on list cotrol
    void DisplayCombineLotData(CListCtrl &listCtrl, int &iNextRowCount, CString csHeader);

//  Get All FieldName from database
//  void GetAllFieldName(int iStartFieldNo);

//  get field value in CString data type
    static CString GetFieldValue(short nType, COleVariant ovFieldValue);

//  Get SemiE10 combine lot data
    StSemiE10 GetSemiE10CombineLotData(StSemiE10 stSemiE10);

// read sum or avg combine lot data
    void ReadData(CMyStringArray csaFieldName, CMyStringArray &csaResult, CDaoRecordset &rs,
                  CDaoRecordset &rsDataType, int &iFieldCnt);

//  Read combine lot data
    void ReadCombineLotData();

//  return combine lot sum result
    CMyStringArray GetSumData();

//  return combine lot Avg result
    CMyStringArray GetAvgData();

    enum
    {
        SORT_BY_LOT_NUM,
        SORT_BY_DATE,
        SORT_BY_LOT_NUM_AND_DATE,
    };

private:
//  set sort criteria
    void SetSortCriteria(int iSort);

//  format sql statement
    CString FormatSqlStatement(int iStartFieldNo);

//  format data type sql statement
    CString FormatDataTypeSqlStatement(int iStartFieldNo);

//  insert ',' if not last loop
    void InsertComma(CString &csSQL, int iStartFieldNo, int iFieldNameSize, int iCount);

//  format sql Criteria statement
    void FormatSqlCriteria(CString &csSQL);

//  get field value and format to CString data type
    CString GetFieldValue(short nOrgType, short nFromatType, COleVariant ovFieldValue);

    CString m_csDbFileName;               // database file name
    CString m_csTableName;                // table name
    CString m_csLotNo;                    // lot number

    CMyStringArray m_csaSumFieldName;     // string array cotains field name
    CMyStringArray m_csaSumFieldNameUnit; // string array cotains field name unit
    CMyStringArray m_csaSumResult;        // string array containing sum results of combine lot

    CMyStringArray m_csaAvgFieldName;     // string array contains the field name to average
    CMyStringArray m_csaAvgFieldNameUnit; // string array contains the field unit name to average
    CMyStringArray m_csaAvgResult;        // string array containing Average results of combine lot

    CString m_csStartTime;                // start lot time
    CString m_csStopTime;                 // stop lot time

    int m_iSort;                          // sort criteria
    enum
    {
        READ_MAX_NUM_FIELDS = 31,
    };
};

#endif // !defined(AFX_COMBINELOT_H__987A2D4D_854E_4CD6_BB50_16FF1F1A5348__INCLUDED_)
