// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// General information section.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// $Author:yongkiang$ User who last changed the file
// $Date:1/2/2013 12:16:45 PM$ Date and time of last check in
// $Revision:1.0$ Visual SourceSafe version number
// $Workfile::   RecipeManagementPage.h                                $ Filename
// End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// {{AFX_INCLUDES()
#include "GridTable.h"
#include "RecipeManagement.h"
#include "MyPropertyPage.h"
// }}AFX_INCLUDES
#if !defined(AFX_RECIPEMANAGEMENTPAGE_H__485D4E33_88A8_11D6_A806_005004C029CA__INCLUDED_)
#define AFX_RECIPEMANAGEMENTPAGE_H__485D4E33_88A8_11D6_A806_005004C029CA__INCLUDED_

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

#ifdef  BUILD_GUIDLL
#define     DLLCLASS    __declspec(dllexport)
#else
#define     DLLCLASS    __declspec(dllimport)
#endif

#include "ShadeButtonST.h"
// RecipeManagementPage.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CRecipeManagementPage dialog

class DLLCLASS CRecipeManagementPage : public CMyPropertyPage // public CPropertyPage
{
DECLARE_DYNCREATE(CRecipeManagementPage)

// Construction
public:
    CRecipeManagementPage();
    ~CRecipeManagementPage();
    static CString GetFieldName(int nCol);
    static int     GetEditType(int nCol);

//  fill list box with items in database
    static void FillListBoxItem(int nCol, CListBox* pList);

    static CStringArray  m_aFieldName;
    static CStringArray  m_aRecipeName;
    static CUIntArray    m_anEditType;
    static BOOL          m_bModified;
    static CStringArray *m_aOutputMode;

    CString GetSelectedRecipeName();
    CString GetCurrentRecipe();

    virtual bool CopyRecipeWizard();
    virtual bool EditRecipeWizard();
    virtual void CreateGridCtrlImageList();
    virtual bool AddRecipeWizard();
    virtual void SetPagesTabText();

// Gary 4Feb10, added option for custom sql command for sorting the data
// for grid ctrl
    virtual CString ReadCustomGridCtrlSortSql();
    virtual void    CustomGridCtrl();

    class CGridEx : public CGridTable
    {
// Override this function to fill InPlaceListBoxes
    void FillListItems(int nCol, LPARAM cltList);
    public:
        int          m_nRecord;
        CStringArray m_aPackage;
    };

// flag to indicate whether to use Wizard method
    bool m_bUseWizardMethod;

    CImageList m_ImageList;

// Dialog Data
// {{AFX_DATA(CRecipeManagementPage)
    enum {
        IDD = IDD_RECIPE_MANAGEMENT_PAGE
    };
    CShadeButtonST m_syncBtn;
    CShadeButtonST m_cbCopyBtn;
    CShadeButtonST m_undoBtn;
    CShadeButtonST m_saveBtn;
    CShadeButtonST m_deleteBtn;
    CShadeButtonST m_addBtn;
// }}AFX_DATA

// Overrides
// ClassWizard generate virtual function overrides
// {{AFX_VIRTUAL(CRecipeManagementPage)
public:
    virtual BOOL OnSetActive();
    virtual BOOL OnKillActive();
protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// }}AFX_VIRTUAL

// Implementation
protected:
    virtual bool SynchronizeRecipes();
// Generated message map functions
// {{AFX_MSG(CRecipeManagementPage)
    virtual BOOL OnInitDialog();
    afx_msg void OnAddButton();
    afx_msg void OnDeleteButton();

#if _MSC_VER > 1200 // Version Higher than VC6
    afx_msg void OnSaveButton();
#else // VC 6 Version
    afx_msg BOOL OnSaveButton(BOOL bPrompt = TRUE);
#endif

    afx_msg void OnGridCtrl();
    afx_msg void OnDestroy();
    afx_msg void OnUndoButton();
    afx_msg void OnCopyButton();
    afx_msg void OnSyncRecipesButton();
// }}AFX_MSG
    DECLARE_MESSAGE_MAP()

//  read form database and write to recipe file for sec gem
    bool ReadDbWriteRecipeFile(const char *ccDb, FILE *fp, const char *ccTable,
                               const char *ccFieldName, const char *ccFieldValue);

//  write recipe info to recipe file for secgem
    bool WriteRecipeInfoFile(CString csRecipeName);

private:
    bool    CheckUseWizardMethod();
    BOOL    CheckLotInfoUsingRecipe(int nRow);
    CString CheckCurrentRecipe(void);
    void    CheckRecipeNameModified(int row, BOOL bPrevious);
    void    DeleteRecipe(int nRow);
    void    ClearArray(void);
    bool    VerifyRecipeBeforeChange(CString csRecipeName /*CCellID cell*/);
    void    DisplayIn2ndLang();
    void    CheckModifiedRecipe(int row, BOOL bPrevious = FALSE);
    BOOL    SaveRecipe(BOOL bPrompt = TRUE);
    void    AddPackageToListBox();
    void    InitGridCtrlBox();
    void    InitIconButtons();

// Gary 02Nov09, change the method to private
//  read form database and write to recipe file for sec gem
// bool ReadDbWriteRecipeFile(const char *ccDb, FILE *fp, const char *ccTable,
//  const char *ccFieldName, const char *ccFieldValue);

// Gary 02Nov09, change the method to private
//  write recipe info to recipe file for secgem
// bool WriteRecipeInfoFile(CString csRecipeName);

//  delete recipe lot to file for SecGem
    BOOL DeleteRecipeFile(CString csRecipeName);

//  CFont m_fontLogo;
    int nPrevRow;
    int m_nNoOfRecipe;

    CRecipeManagement m_recipeManagement;
/*
    class CGridEx : public CGridTable
    {
            // Override this function to fill InPlaceListBoxes
            void FillListItems(int nCol, LPARAM cltList);
        public:
            int     m_nRecord;
            CStringArray    m_aPackage;
    };
 */
    CGridEx m_gridTable;
    BOOL    m_bSavePrevious;
    BOOL    m_bAddBefore;

#if _MSC_VER > 1200 // Version Higher than VC6
    bool m_bPrompt;
    bool m_bSaveSuccess;
#endif

public:
    CRecipeManagementPage::CGridEx *GetGridCtrl();
};

// {{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_RECIPEMANAGEMENTPAGE_H__485D4E33_88A8_11D6_A806_005004C029CA__INCLUDED_)
