You are on page 1of 150

// MAIN FILE OF THE APPLICATION

// CRMProject.h : Main header file for the CRMPROJECT application

#include"Resource.h"

class CCRMProject : public CWinApp


{
public:
CCRMProject();

//{{AFX_VIRTUAL (CCRMProject)
virtual BOOL InitInstance();
//}}AFX_VIRTUAL

//{{AFX_MSG
afx_msg void OnHelpMe();
afx_msg void OnHelpCRM();
afx_msg void OnHelpUse();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// CRMProject.cpp : Defines the Class Behaviors for the Application.

#include"StdAfx.h"
#include"CRMProject.h"
#include"MainFrame.h"
#include"HelpDlg.h"
#include"SplashWnd.h"
#include"UserLogin.h"

// Add Construction Code Here, Place All Significant Initialization in InitInstance


CCRMProject :: CCRMProject()
{
}

// Windows Allows Several Copies of the Same Program to Run at the Same Time.
BOOL CCRMProject :: InitInstance()
{
// Enable the SPLASH SCREEN Component Based on the Command Line Information.
CSplashWnd :: ShowSplashScreen(IDB_SPLASH24, NULL);

AfxEnableControlContainer();

// Change the Registry Key Under Which Our Settings are Stored.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));

CUserLogin Dlg(IDD_LOGON);
int nResponse = Dlg.DoModal();

93
if (nResponse == IDOK)
{
AfxMessageBox(_T("Succesfull Login."), MB_OK|MB_ICONINFORMATION);

// Destroy SPLESH SCREEN Window


AfxGetMainWnd()->DestroyWindow();

// To Creates a New Main Frame Window


CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame;

// Create and Load the Frame With its Resources


pFrame->LoadFrame(IDR_LONG, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
NULL);

// Sets the Visibility State of the Window


pFrame->ShowWindow(SW_SHOW);

// Updates the Client Area


pFrame->UpdateWindow();
}
else if (nResponse == IDCANCEL)
{
CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame;
pFrame->LoadFrame(IDR_SHORT, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
NULL);

// Load the SHORT Menu Wher User not Login


pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
}
return TRUE;
}

// Display a Programmer Dialog box


void CCRMProject :: OnHelpMe()
{
CHelpDlg Dlg(IDD_ABOUTME);
Dlg.DoModal();
}

// Display a CRM Project Dialog box


void CCRMProject :: OnHelpCRM()
{
CHelpDlg Dlg(IDD_ABOUTCRM);
Dlg.DoModal();
}
// Display a Help
void CCRMProject :: OnHelpUse()
{

94
AfxMessageBox(_T("Under Construction"), MB_OK | MB_ICONEXCLAMATION);
}

BEGIN_MESSAGE_MAP(CCRMProject, CWinApp)
//{{AFX_MSG_MAP (CCRMProject)
ON_COMMAND(ID_HELP_ABOUTME, OnHelpMe)
ON_COMMAND(ID_HELP_ABBOUTCRM, OnHelpCRM)
ON_COMMAND(ID_HELP_HOWTOUSE, OnHelpUse)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// MAIN OBJECT OF THE APPLICATION


CCRMProject theApp;

95
// THIS FILE GENARATE A INTERFACE OF THE WINDOW
// MainFrame.h : Interface of the CMainFrame class

#include"ChildView.h"

class CMainFrame : public CFrameWnd


{
DECLARE_DYNAMIC(CMainFrame)

protected:
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
CChildView m_wndView;
CString strReportFile;
CString strReportTitle;

public:
CMainFrame();
virtual ~CMainFrame();

//{{AFX_VIRTUAL (CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
//}}AFX_VIRTUAL

//{{AFX_MSG (CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSetFocus(CWnd *pOldWnd);

afx_msg void OnLogOn();

afx_msg void OnAddNewCustomer();


afx_msg void OnUpdateCustomer();
afx_msg void OnViewCustomer();
afx_msg void OnReportCustomer();

afx_msg void OnAddNewProduct();


afx_msg void OnUpdateProduct();
afx_msg void OnViewProduct();
afx_msg void OnReportProduct();

afx_msg void OnAddNewOffer();


afx_msg void OnViewOffer();

afx_msg void OnAddNewComplain();


afx_msg void OnPendingComplain();
afx_msg void OnViewComplain();

afx_msg void OnAddNewOrder();


afx_msg void OnViewBill();
afx_msg void OnReportSales();

96
afx_msg void OnAddNewSalesman();
afx_msg void OnUpdateSalesman();
afx_msg void OnViewSalesman();
afx_msg void OnReportSalesman();

afx_msg void OnQuotaManager();


afx_msg void OnReportQuota();

afx_msg void OnUpdateStock();


afx_msg void OnViewStock();
afx_msg void OnReportInventory();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// MainFrame.cpp : Implementation of the CMainFrame class

#include"StdAfx.h"
#include"CRMProject.h"
#include"MainFrame.h"
#include"StatusBar.h"
#include"UserLogin.h"
#include"AddNewCustomer.h"
#include"ViewCustomer.h"
#include"AddNewProduct.h"
#include"UpdateProduct.h"
#include"ViewProduct.h"
#include"AddNewOffer.h"
#include"ViewOffer.h"
#include"AddNewComplain.h"
#include"PendingComplain.h"
#include"ViewComplain.h"
#include"AddNewOrder.h"
#include"AddNewSalesman.h"
#include"UpdateSalesman.h"
#include"ViewSalesman.h"
#include"QuotaManager.h"
#include"UpdateStock.h"
#include"ViewStock.h"
#include"ReportViewer.h"

IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)

// STATUS Line Indicator


static const UINT indicators[] = {
ID_SEPARATOR,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,

97
ID_PANE_FOUR,
};

// Class Costructer, Initialization the Class Here


CMainFrame :: CMainFrame()
{
}

// Class Destructer, Destroy the Class Here


CMainFrame :: ~CMainFrame()
{
}

// Modify the Window Class or Styles Here by Modifying the CREATESTRUCT


BOOL CMainFrame :: PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;

cs.dwExStyle &= ~WS_EX_CLIENTEDGE;


cs.lpszClass = AfxRegisterWndClass(0);
return TRUE;
}

// To ROUTE and DISPATCH Command Messages and to Handle the Update of Command USER-INTERFACE
objects.
BOOL CMainFrame :: OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// The View Have First Crack at the Command
if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;

// Otherwise, do DEFAULT Handling


return CFrameWnd :: OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

// The Windows Window be CREATED by Calling the Create or CreateEx Member Function
int CMainFrame :: OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd :: OnCreate(lpCreateStruct) == -1)
return -1;

// Create a VIEW to Occupy the Client Area of the Frame


if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
{
TRACE0("Failed to create view window\n");
return -1;
}

// Create a TOOLBAR in a Main Window

98
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1;
}

// Create a STATUSBAR in a Main Window


if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1;
}

// Delete these three lines if you don't want the TOOLBAR to be DOCKABLE
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);

return 0;
}

// Forward FOCUS to the View Window


void CMainFrame :: OnSetFocus(CWnd* pOldWnd)
{
m_wndView.SetFocus();
}

// USER LOGIN Interface is Open


void CMainFrame :: OnLogOn()
{
CUserLogin Dlg(IDD_LOGON);
if(Dlg.DoModal() == IDOK)
{
CMenu MyMenu;
MyMenu.LoadMenu(IDR_LONG);
SetMenu(&MyMenu);
DrawMenuBar();
}
}

// CUSTOMER(New) Dialog Box is Open


void CMainFrame :: OnAddNewCustomer()
{
CAddNewCustomer Dlg(IDD_ADDNEWCUSTOMER);
Dlg.DoModal();
}

99
// CUSTOMER(Update) Dialog Box is Open
void CMainFrame :: OnUpdateCustomer()
{
CAddNewCustomer Dlg(IDD_MODIFYCUSTOMER);
Dlg.DoModal();
}

// CUSTOMER(View) Dialog Box is Open


void CMainFrame :: OnViewCustomer()
{
CViewCustomer Dlg;
Dlg.DoModal();
}

// CUSTOMER(Report) Dialog Box is Open


void CMainFrame :: OnReportCustomer()
{
strReportFile = _T("\\Report\\Customer.rpt");
strReportTitle = _T("Customer Information");
CReportViewer Dlg(strReportFile, strReportTitle);
Dlg.DoModal();
}

// PRODUCT(New) Dialog Box is Open


void CMainFrame :: OnAddNewProduct()
{
CAddNewProduct Dlg;
Dlg.DoModal();
}

// PRODUCT(Update) Dialog Box is Open


void CMainFrame :: OnUpdateProduct()
{
CUpdateProduct Dlg;
Dlg.DoModal();
}

// PRODUCT(View) Dialog Box is Open


void CMainFrame :: OnViewProduct()
{
CViewProduct Dlg;
Dlg.DoModal();
}

// PRODUCT(Report) Dialog Box is Open


void CMainFrame :: OnReportProduct()
{
strReportFile = _T("\\Report\\Product.rpt");
strReportTitle = _T("Product Information");
CReportViewer Dlg(strReportFile, strReportTitle);
Dlg.DoModal();

100
}

// OFFER_LETTER(New) Dialog Box is Open


void CMainFrame :: OnAddNewOffer()
{
CAddNewOffer Dlg;
Dlg.DoModal();
}

// OFFER_LETTER(View) Window is Open


void CMainFrame :: OnViewOffer()
{
CViewOffer Dlg;
Dlg.DoModal();
}

// COMPLAIN(New) Dialog Box is Open


void CMainFrame :: OnAddNewComplain()
{
CAddNewComplain Dlg;
Dlg.DoModal();
}

// COMPLAIN(Pending) Dialog Box is Open


void CMainFrame :: OnPendingComplain()
{
CPendingComplain Dlg;
Dlg.DoModal();
}

// COMPLAIN(View) Window is Open


void CMainFrame :: OnViewComplain()
{
CViewComplain Dlg;
Dlg.DoModal();
}

// ORDER(New) Window is Open


void CMainFrame :: OnAddNewOrder()
{
CAddNewOrder Dlg;
Dlg.DoModal();
}

// BILL(View) Dialog Box is Open


void CMainFrame :: OnViewBill()
{
strReportFile = _T("\\Report\\Bill.rpt");
strReportTitle = _T("Customer Bill");
CReportViewer Dlg(strReportFile, strReportTitle);
Dlg.DoModal();

101
}

// SALES(Report) Dialog Box is Open


void CMainFrame :: OnReportSales()
{
strReportFile = _T("\\Report\\Sales.rpt");
strReportTitle = _T("Sales Information");
CReportViewer Dlg(strReportFile, strReportTitle);
Dlg.DoModal();
}

// SALESMAN(New) Window is Open


void CMainFrame :: OnAddNewSalesman()
{
CAddNewSalesman Dlg;
Dlg.DoModal();
}

// SALESMAN(Update) Window is Open


void CMainFrame :: OnUpdateSalesman()
{
CUpdateSalesman Dlg;
Dlg.DoModal();
}

// SALESMAN(View) Dialog Box is Open


void CMainFrame :: OnViewSalesman()
{
CViewSalesman Dlg;
Dlg.DoModal();
}

// SALESMAN(Report) Dialog Box is Open


void CMainFrame :: OnReportSalesman()
{
strReportFile = _T("\\Report\\Salesman.rpt");
strReportTitle = _T("Salesman Information");
CReportViewer Dlg(strReportFile, strReportTitle);
Dlg.DoModal();
}

// SALESMAN_QUOTA(NEW) Window is Open


void CMainFrame :: OnQuotaManager()
{
CQuotaManager Dlg;
Dlg.DoModal();
}

// SALESMAN_QUOTA(Report) Dialog Box is Open


void CMainFrame :: OnReportQuota()
{

102
strReportFile = _T("\\Report\\Quota.rpt");
strReportTitle = _T("Quota Information");
CReportViewer Dlg(strReportFile, strReportTitle);
Dlg.DoModal();
}

// STOCK(Update) Dialog Box is Open


void CMainFrame :: OnUpdateStock()
{
CUpdateStock Dlg;
Dlg.DoModal();
}

// STOCK(View) Dialog Box is Open


void CMainFrame :: OnViewStock()
{
CViewStock Dlg;
Dlg.DoModal();
}

// INVENTORY(Report) Dialog Box is Open


void CMainFrame :: OnReportInventory()
{
strReportFile = _T("\\Report\\Inventory.rpt");
strReportTitle = _T("Inventory Information");
CReportViewer Dlg(strReportFile, strReportTitle);
Dlg.DoModal();
}

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP
ON_WM_CREATE()
ON_WM_SETFOCUS()
//}}AFX_MSG_MAP

//{{AFX_MSG_MAP (Login)
ON_COMMAND(ID_APP_LOGON, OnLogOn)
//}}AFX_MSG_MAP

//{{AFX_MSG_MAP (Customer)
ON_COMMAND(ID_CUSTOMERDATA_NEW, OnAddNewCustomer)
ON_COMMAND(ID_CUSTOMERDATA_UPDATE, OnUpdateCustomer)
ON_COMMAND(ID_CUSTOMERDATA_VIEW, OnViewCustomer)
ON_COMMAND(ID_REPORT_CUSTOMER, OnReportCustomer)
//}}AFX_MSG_MAP

//{{AFX_MSG_MAP (Product)
ON_COMMAND(ID_PRODUCTDATA_NEW, OnAddNewProduct)
ON_COMMAND(ID_PRODUCTDATA_UPDATE, OnUpdateProduct)
ON_COMMAND(ID_PRODUCTDATA_VIEW, OnViewProduct)
ON_COMMAND(ID_REPORT_PRODUCT, OnReportProduct)

103
//}}AFX_MSG_MAP

//{{AFX_MSG_MAP (OfferLetter)
ON_COMMAND(ID_OFFERLETTER_NEW, OnAddNewOffer)
ON_COMMAND(ID_OFFERLETTER_PRINT, OnViewOffer)
//}}AFX_MSG_MAP

//{{AFX_MSG_MAP (Customer Complain)


ON_COMMAND(ID_COMPLAINT_NEW, OnAddNewComplain)
ON_COMMAND(ID_COMPLAINT_PENDING, OnPendingComplain)
ON_COMMAND(ID_COMPLAINT_VIEW, OnViewComplain)
//}}AFX_MSG_MAP

//{{AFX_MSG_MAP (Order)
ON_COMMAND(ID_ORDER_NEWORDER, OnAddNewOrder)
ON_COMMAND(ID_ORDER_VIEWBILL, OnViewBill)
ON_COMMAND(ID_REPORT_SALES, OnReportSales)
//}}AFX_MSG_MAP

//{{AFX_MSG_MAP (Salesman)
ON_COMMAND(ID_SALESMANDATA_NEW, OnAddNewSalesman)
ON_COMMAND(ID_SALESMANDATA_UPDATE, OnUpdateSalesman)
ON_COMMAND(ID_SALESMANDATA_VIEW, OnViewSalesman)
ON_COMMAND(ID_REPORT_SALESMAN, OnReportSalesman)
//}}AFX_MSG_MAP

//{{AFX_MSG_MAP (Quota Management)


ON_COMMAND(ID_SALES_QUOTAMANAGER, OnQuotaManager)
ON_COMMAND(ID_REPORT_QUOTA, OnReportQuota)
//}}AFX_MSG_MAP

//{{AFX_MSG_MAP (Stock)
ON_COMMAND(ID_STOCK_UPDATE, OnUpdateStock)
ON_COMMAND(ID_STOCK_VIEW, OnViewStock)
ON_COMMAND(ID_REPORT_INVENTORY, OnReportInventory)
//}}AFX_MSG_MAP

END_MESSAGE_MAP()

104
// THIS FILE GENARATE A CHILD WINDOW
// ChildView.h : Interface of the CChildView class

class CChildView : public CWnd


{
public:
CChildView();
~CChildView();

virtual BOOL PreCreateWindow(CREATESTRUCT& cs);

//{{AFX_MSG (Complain)
afx_msg void OnPaint();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// ChildView.cpp : Implementation of the CChildView class

#include"StdAfx.h"
#include"CRMProject.h"
#include"ChildView.h"

// Constructer of the CChildView


CChildView :: CChildView()
{
}

// Destructer of the CChildView


CChildView :: ~CChildView()
{
}

// Set the Property of the Child Window


BOOL CChildView :: PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;

cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);

return TRUE;
}

// Paint on Child Window

105
void CChildView :: OnPaint()
{
CPaintDC dc(this);
}

BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP (CChildView)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

106
// THIS FILE IS USED FOR USER LOGIN
// UserLogin.h : Interface of the CUserLogin class

class CUserLogin : public CDialog


{
public:
//{{AFX_DATA (CUserLogin)
enum { IDD = IDD_LOGON };
CDatabase db;
CString strPassword;
CString strUserName;
//}}AFX_DATA

public:
CUserLogin(int nID, CWnd* pParent = NULL);

protected:
//{{AFX_VIRTUAL (CUserLogin)
virtual afx_msg void OnOK();
virtual afx_msg void OnCancel();
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL

DECLARE_MESSAGE_MAP()
};

// UserLogin.cpp : Implementation of the CUserLogin class

#include"Stdafx.h"
#include"UserLogin.h"

CUserLogin :: CUserLogin(int nID, CWnd* pParent) : CDialog(CUserLogin::IDD, pParent)


{
//{{AFX_DATA_INIT (CUserLogin)
strPassword = _T("");
strUserName = _T("");
//}}AFX_DATA_INIT
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CUserLogin :: OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}

// Initiate the CONTROLS of the IDD_LOGIN DialogBox


void CUserLogin :: DoDataExchange(CDataExchange* pDX)
{

107
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CUserLogin)
DDX_Text(pDX, IDC_PASSWORD, strPassword);
DDX_Text(pDX, IDC_USERNAME, strUserName);
//}}AFX_DATA_MAP
}

// Click SAVE Button Save a Record in Record Source


void CUserLogin :: OnOK()
{
BOOL flag = TRUE;
if(UpdateData(TRUE))
{
CRecUserLogin ULRec(&db);
TRY
{
if(strUserName.IsEmpty())
{
AfxMessageBox(_T("Please Enter User Name"),
MB_OK|MB_ICONINFORMATION);
GetDlgItem(IDC_USERNAME)->SetFocus();
flag = FALSE;
}
else if(strPassword.IsEmpty())
{
AfxMessageBox(_T(""), MB_OK|MB_ICONINFORMATION);
GetDlgItem(IDC_PASSWORD)->SetFocus();
flag = FALSE;
}
if(flag)
{
ULRec.m_strFilter = "USER_LOGIN_ID = '" + strUserName + "' AND
USER_PASSWORD = '" + strPassword + "'";
ULRec.Open(CRecordset::snapshot);
if(ULRec.IsEOF())
{
AfxMessageBox(_T("Incorrect User Name and Password."),
MB_OK|MB_ICONINFORMATION);
GetDlgItem(IDC_USERNAME)->SetFocus();
}
else
{
ULRec.Close();
CDialog::OnOK();
}
ULRec.Close();
}
}
CATCH_ALL(e)
{

108
ULRec.Close();
AfxMessageBox(_T("Unable to Check User Name and Password. Please Try Again."),
MB_OK|MB_ICONERROR);
}
END_CATCH_ALL
}
}

// Click CANCEL Button Then It is Called to Close the Interface


void CUserLogin :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

BEGIN_MESSAGE_MAP(CUserLogin, CDialog)
//{{AFX_MSG_MAP(CUserLogin)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

109
// THIS FILE IS A RECORD SOURCE OF A USER_LOGIN
// RecUserLogin.h : Interface of the CRecUserLogin class

class CRecUserLogin : public CRecordset


{
DECLARE_DYNAMIC(CRecUserLogin)

public:
// Variable of the USER_LOGIN Data Source Fields
//{{AFX_FIELD (USER_LOGIN)
CString m_USER_LOGIN_ID;
CString m_USER_PASSWORD;
CString m_USER_CATEGORY;
//}}AFX_FIELD

public:
CRecUserLogin(CDatabase* pDatabase = NULL);

//{{AFX_VIRTUAL (CRecUserLogin)
virtual CString GetDefaultConnect(); // Default connection string
virtual CString GetDefaultSQL(); // Default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
//}}AFX_VIRTUAL
};

// RecUserLogin.cpp : Implementation of the CRecUserLogin class

#include"Stdafx.h"
#include"RecUserLogin.h"

IMPLEMENT_DYNAMIC(CRecUserLogin, CRecordset)

CRecUserLogin :: CRecUserLogin(CDatabase* pdb) : CRecordset(pdb)


{
//{{AFX_FIELD_INIT(CRecUserLogin)
m_USER_LOGIN_ID = _T("");
m_USER_PASSWORD = _T("");
m_USER_CATEGORY = _T("");
//}}AFX_FIELD_INIT

m_nFields = 3;
m_nDefaultType = snapshot;
}

// Default Connection String


CString CRecUserLogin::GetDefaultConnect()
{
return _T("ODBC;DSN=crm;UID=crm;PWD=crm;");
}

110
// Used to Default SQL for Recordset
CString CRecUserLogin::GetDefaultSQL()
{
return _T("[CRM].[USER_LOGIN]");
}

// To Exchange Data (IN BOTH DIRECTION) Between the Record Source Data Members
// and the Corresponding Record on the Data Variable.
void CRecUserLogin::DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);

//{{AFX_FIELD_MAP(CRecUserLogin)
RFX_Text(pFX, _T("[USER_LOGIN_ID]"), m_USER_LOGIN_ID);
RFX_Text(pFX, _T("[USER_PASSWORD]"), m_USER_PASSWORD);
RFX_Text(pFX, _T("[USER_CATEGORY]"), m_USER_CATEGORY);
//}}AFX_FIELD_MAP
}

111
// THIS FILE IS USED FOR ADD NEW CUSTOMER
// AddNewCustomer.h : Interface of the CAddNewCustomer Class

class CRecCustomerMaster;

class CAddNewCustomer : public CDialog


{
public:
BOOL ModifyDialog;
CDatabase db;
CEdit *wndEdit[9];
CString strSQL;
CButton *wndButton[10];
CBitmap MyBitmap[3];
CButton MyButton[3];

//{{AFX_DATA (CAddNewCustomer)
CString strCustomerID;
CString strCustomerName;
CString strAddress;
CString strCity;
CString strPhone;
CString strMobile;
CString strEmail;
CString strSalary;
CString strOccupation;
CTime tDOB;
CDateTimeCtrl *wndDateTime;
//}}AFX_DATE

public:
CAddNewCustomer(int nID);
void InitiatVariables();
void InitiatFields(CRecCustomerMaster &rec);
void ReadOnlyIDControl(BOOL bFlag);

protected:
//{{AFX_VIRTUAL (CAddNewCustomer)
virtual afx_msg void OnCancel();
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange *pDX);
//}}AFX_VIRTUAL

//{{AFX_MSG (IDD_ADDNEWCUSTOMER)
afx_msg void OnRefresh();
afx_msg void OnSave();
//}}AFX_MSG

//{{AFX_MSG (IDD_MODIFYCUSTOMER)
void OnFirst();
void OnPrevious();

112
void OnNext();
void OnLast();
void OnSearch();
void OnModify();
void OnDelete();
void OnMCancel();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// AddNewCustomer.cpp : Implementation of the CAddNewCustomer class

#include"StdAfx.h"
#include"AddNewCustomer.h"
#include"RecCustomerMaster.h"

// Constructer of the CAddNewCustomer to Initiate the Variables


CAddNewCustomer :: CAddNewCustomer(int nID) : CDialog(nID)
{
ModifyDialog = FALSE;
if(nID == IDD_ADDNEWCUSTOMER)
{
InitiatVariables();
}
else if(nID == IDD_MODIFYCUSTOMER)
{
ModifyDialog = TRUE;
}

// This Function is Used to Initiate the Memory Variables


void CAddNewCustomer :: InitiatVariables()
{
strCustomerName = _T("");
strAddress = _T("");
strCity = _T("");
strPhone = _T("");
strMobile = _T("");
strEmail = _T("");
strSalary = _T("");
strOccupation = _T("");
tDOB = CTime::GetCurrentTime();

// Initialization of the CUSTOMER_ID EditBox With Unique ID


CRecCustomerMaster CMRec(&db);
CString strFile = _T("CUSTOMER_MASTER");
CString strField = _T("CUSTOMER_ID");

113
// Read MAX_ID of the PRODUCT_OFFER Data Source.
strCustomerID = "CM" + Max_ID(CMRec, strFile, strField);
}

// This Function is Used to Initiate the Fields Variables


void CAddNewCustomer :: InitiatFields(CRecCustomerMaster &rec)
{
strCustomerID = rec.m_CUSTOMER_ID;
strCustomerName = rec.m_CUSTOMER_NAME;
strAddress = rec.m_CUSTOMER_ADDRESS;
strCity = rec.m_CUSTOMER_CITY;
strPhone = rec.m_CUSTOMER_PHONE;
strMobile = rec.m_CUSTOMER_MOBILE;
strEmail = rec.m_CUSTOMER_EMAIL;
tDOB = rec.m_CUSTOMER_DOB;
strSalary = rec.m_CUSTOMER_SALARY;
strOccupation = rec.m_CUSTOMER_OCCUPATION;
}

// This Fuction is Used to Enable/Desable AND Hide/Show the Control


void CAddNewCustomer :: ReadOnlyIDControl(BOOL bFlag)
{
UINT Show, Hide;
if(bFlag)
{
Show = SW_SHOW;
Hide = SW_HIDE;
}
else
{
Show = SW_HIDE;
Hide = SW_SHOW;
}

// Enable or Desable the DialogBox Edit Window


wndEdit[0]->SetReadOnly(!bFlag); // IDC_ID
wndEdit[1]->SetReadOnly(bFlag); // IDC_NAME
wndEdit[2]->SetReadOnly(bFlag); // IDC_ADDRESS
wndEdit[3]->SetReadOnly(bFlag); // IDC_CITY
wndEdit[4]->SetReadOnly(bFlag); // IDC_PHONE
wndEdit[5]->SetReadOnly(bFlag); // IDC_MOBILE
wndEdit[6]->SetReadOnly(bFlag); // IDC_EMAIL
wndDateTime->EnableWindow(!bFlag); // IDC_DATEOFBIRTH
wndEdit[7]->SetReadOnly(bFlag); // IDC_SALARY
wndEdit[8]->SetReadOnly(bFlag); // IDC_OCCUPATION

// Enable or Desable the DialogBox Commond Button


wndButton[0]->ShowWindow(Show); // IDC_FIRST
wndButton[1]->ShowWindow(Show); // IDC_PRE
wndButton[2]->ShowWindow(Show); // IDC_NEXT
wndButton[3]->ShowWindow(Show); // IDC_LAST

114
wndButton[4]->ShowWindow(Show); // IDC_SEARCH
wndButton[5]->ShowWindow(Show); // IDC_MODIFY
wndButton[6]->ShowWindow(Show); // IDC_DELETE
wndButton[7]->ShowWindow(Show); // IDCANCEL
wndButton[8]->ShowWindow(Hide); // IDC_SAVE
wndButton[9]->ShowWindow(Hide); // IDC_CANCEL
}

//This Function Call Before the DialogBox is Displayed


BOOL CAddNewCustomer :: OnInitDialog()
{
CDialog::OnInitDialog();

if(ModifyDialog == TRUE)
{
// Get the address of the DialogBox Edit Window
wndEdit[0] = (CEdit*)GetDlgItem(IDC_ID);
wndEdit[1] = (CEdit*)GetDlgItem(IDC_NAME);
wndEdit[2] = (CEdit*)GetDlgItem(IDC_ADDRESS);
wndEdit[3] = (CEdit*)GetDlgItem(IDC_CITY);
wndEdit[4] = (CEdit*)GetDlgItem(IDC_PHONE);
wndEdit[5] = (CEdit*)GetDlgItem(IDC_MOBILE);
wndEdit[6] = (CEdit*)GetDlgItem(IDC_EMAIL);
wndDateTime = (CDateTimeCtrl*)GetDlgItem(IDC_DATEOFBIRTH);
wndEdit[7] = (CEdit*)GetDlgItem(IDC_SALARY);
wndEdit[8] = (CEdit*)GetDlgItem(IDC_OCCUPATION);

// Get the address of the DialogBox Commond Button


wndButton[0] = (CButton*)GetDlgItem(IDC_FIRST);
wndButton[1] = (CButton*)GetDlgItem(IDC_PRE);
wndButton[2] = (CButton*)GetDlgItem(IDC_NEXT);
wndButton[3] = (CButton*)GetDlgItem(IDC_LAST);
wndButton[4] = (CButton*)GetDlgItem(IDC_SEARCH);
wndButton[5] = (CButton*)GetDlgItem(IDC_MODIFY);
wndButton[6] = (CButton*)GetDlgItem(IDC_DELETE);
wndButton[7] = (CButton*)GetDlgItem(IDCANCEL);
wndButton[8] = (CButton*)GetDlgItem(IDC_SAVE);
wndButton[9] = (CButton*)GetDlgItem(IDC_CANCEL);

// This member is used to GOTO 1st record


OnFirst();
}
return TRUE;
}

// Initiate the CONTROLS of the IDD_ADDNEWCUSTOMER DialogBox


void CAddNewCustomer :: DoDataExchange(CDataExchange *pDX)
{
CDialog :: DoDataExchange(pDX);

//{{AFX_DATA_MAP (CAddNewCustomer)

115
// Do Data Exchange (DDX) Funtion
DDX_Text(pDX, IDC_ID, strCustomerID);
DDX_Text(pDX, IDC_NAME, strCustomerName);

// Dialog Data Validation (DDV) Funtion


DDV_MaxChars(pDX, strCustomerName, 30);
DDX_Text(pDX, IDC_ADDRESS, strAddress);
DDV_MaxChars(pDX, strAddress, 40);
DDX_Text(pDX, IDC_CITY, strCity);
DDV_MaxChars(pDX, strCity, 20);
DDX_Text(pDX, IDC_PHONE, strPhone);
DDV_MaxChars(pDX, strPhone, 11);
DDX_Text(pDX, IDC_MOBILE, strMobile);
DDV_MaxChars(pDX, strMobile, 11);
DDX_Text(pDX, IDC_EMAIL, strEmail);
DDX_DateTimeCtrl(pDX, IDC_DATEOFBIRTH, tDOB);
DDV_MaxChars(pDX, strEmail, 40);
DDX_Text(pDX, IDC_SALARY, strSalary);
DDV_MaxChars(pDX, strSalary, 6);
DDX_Text(pDX, IDC_OCCUPATION, strOccupation);
DDV_MaxChars(pDX, strOccupation, 30);
//}}AFX_DATA_MAP
}

// Click REFRESH Button Then It is Called to Clear the DialogBox


void CAddNewCustomer :: OnRefresh()
{
InitiatVariables();

// Call This Member to Initialize Data in a DialogBox Using DoDataExchange()


CWnd::UpdateData(FALSE);

// Setfocus on the Edit Control


CEdit *txtName = (CEdit*)GetDlgItem(IDC_NAME);
txtName->SetFocus();
}

// Click SAVE Button Then It is Called to Save the Record


void CAddNewCustomer :: OnSave()
{
BOOL bTest = TRUE;

// Call This Member to Retrive Data From a DialogBox Using DoDataExchange()


if(UpdateData(TRUE))
{
if(strCustomerName.IsEmpty())
{
AfxMessageBox("Please Enter Customer Name.");
GetDlgItem(IDC_NAME)->SetFocus();
bTest = FALSE;

116
}
else if(strAddress.IsEmpty())
{
AfxMessageBox("Please Enter Address.");
GetDlgItem(IDC_ADDRESS)->SetFocus();
bTest = FALSE;
}
else if(strCity.IsEmpty())
{
AfxMessageBox("Please Enter City.");
GetDlgItem(IDC_CITY)->SetFocus();
bTest = FALSE;
}
else if(strSalary.IsEmpty())
{
AfxMessageBox("Please Enter Salary.");
GetDlgItem(IDC_SALARY)->SetFocus();
bTest = FALSE;
}
else if(strOccupation.IsEmpty())
{
AfxMessageBox("Please Enter Occupation.");
GetDlgItem(IDC_OCCUPATION)->SetFocus();
bTest = FALSE;
}
if(bTest)
{
BOOL bOpen = FALSE;
CRecCustomerMaster CMRec(&db);

// if IDD_MODIFYCUSTOMER DialogBox is EDIT Then RecordSet


if(ModifyDialog)
{
CString strID;
GetDlgItemText(IDC_ID, strID);

// ERROR Handling in VISUAL C++


TRY
{
strSQL = _T("SELECT * FROM CUSTOMER_MASTER WHERE
CUSTOMER_ID = '" + strID + "'");
if(CMRec.Open(CRecordset::snapshot, strSQL))
{
CMRec.Edit();
bOpen = TRUE;
}
}
CATCH_ALL(e)
{
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK |
MB_ICONERROR);

117
CMRec.Close();
}
END_CATCH_ALL
}
else
{
TRY
{
// If IDD_ADDNEWCUSTOMER DialogBox is OPEN Then RecordSet is
Open
if(CMRec.Open())
CMRec.AddNew();
bOpen = TRUE;
}
CATCH_ALL(e)
{
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK |
MB_ICONERROR);
CMRec.Close();
}
END_CATCH_ALL
}

// If RecordSet is Succesfull Open


if(bOpen)
{
CMRec.m_CUSTOMER_ID = strCustomerID;
CMRec.m_CUSTOMER_NAME = strCustomerName;
CMRec.m_CUSTOMER_ADDRESS = strAddress;
CMRec.m_CUSTOMER_CITY = strCity;
CMRec.m_CUSTOMER_PHONE = strPhone;
CMRec.m_CUSTOMER_MOBILE = strMobile;
CMRec.m_CUSTOMER_EMAIL = strEmail;
CMRec.m_CUSTOMER_DOB = tDOB;
CMRec.m_CUSTOMER_SALARY = strSalary;
CMRec.m_CUSTOMER_OCCUPATION = strOccupation;
if(!CMRec.Update())
{
AfxMessageBox(_T("Record not added; no field values were set."));
}
else
{
if(ModifyDialog)
{
ReadOnlyIDControl(TRUE);
}
else
{
CMRec.Close();
AfxMessageBox(_T("Succesfully Save Record."), MB_OK |
MB_ICONINFORMATION);

118
InitiatVariables();
CEdit *txtName = (CEdit*)GetDlgItem(IDC_NAME);
txtName->SetFocus();
UpdateData(FALSE);
}
}
}
}
}
}

// Click CANCEL Button Then CLOSE the Interface


void CAddNewCustomer :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

// Click FIRST Button Then GoTo FIRST Record


void CAddNewCustomer :: OnFirst()
{
CRecCustomerMaster CMRec(&db);
strSQL = _T("SELECT * FROM CUSTOMER_MASTER ORDER BY TO_NUMBER(SUBSTR(CUSTOMER_ID, 3))");
if(CMRec.Open(CRecordset::snapshot, strSQL))
{
CMRec.MoveFirst();
InitiatFields(CMRec);
UpdateData(FALSE);
}
CMRec.Close();
}

// Click PREVIOUS Button Then GoTo PREVIOUS Record


void CAddNewCustomer :: OnPrevious()
{
CRecCustomerMaster CMRec(&db);
strSQL = _T("SELECT * FROM CUSTOMER_MASTER ORDER BY TO_NUMBER(SUBSTR(CUSTOMER_ID, 3))");
if(CMRec.Open(CRecordset::snapshot, strSQL))
{
for(CMRec.MoveFirst(); !CMRec.IsEOF(); CMRec.MoveNext())
{
if(strCustomerID == CMRec.m_CUSTOMER_ID)
break;
}
CMRec.MovePrev();
InitiatFields(CMRec);
UpdateData(FALSE);
}
CMRec.Close();
}

119
// Click NEXT Button Then GoTo NEXT Record
void CAddNewCustomer :: OnNext()
{
CRecCustomerMaster CMRec(&db);
strSQL = _T("SELECT * FROM CUSTOMER_MASTER ORDER BY TO_NUMBER(SUBSTR(CUSTOMER_ID, 3))");
if(CMRec.Open(CRecordset::snapshot, strSQL))
{
for(CMRec.MoveFirst(); !CMRec.IsEOF(); CMRec.MoveNext())
{
if(strCustomerID == CMRec.m_CUSTOMER_ID)
break;
}
CMRec.MoveNext();
InitiatFields(CMRec);
UpdateData(FALSE);
}
CMRec.Close();
}

// Click LAST Button Then GoTo LAST Record


void CAddNewCustomer :: OnLast()
{
CRecCustomerMaster CMRec(&db);
strSQL = _T("SELECT * FROM CUSTOMER_MASTER ORDER BY TO_NUMBER(SUBSTR(CUSTOMER_ID, 3))");
if(CMRec.Open(CRecordset::snapshot, strSQL))
{
CMRec.MoveLast();
InitiatFields(CMRec);
UpdateData(FALSE);
}
CMRec.Close();
}

// Click SEARCH Button Then GoTo Desired Record


void CAddNewCustomer :: OnSearch()
{
CString str;
GetDlgItemText(IDC_ID, str);
BOOL bFound = FALSE;
CRecCustomerMaster CMRec(&db);
strSQL = _T("SELECT * FROM CUSTOMER_MASTER ORDER BY TO_NUMBER(SUBSTR(CUSTOMER_ID, 3))");
if(CMRec.Open(CRecordset::snapshot, strSQL))
{
for(CMRec.MoveFirst(); !CMRec.IsEOF(); CMRec.MoveNext())
{
if(str == CMRec.m_CUSTOMER_ID)
{
bFound = TRUE;
break;
}
}

120
if(bFound)
{
InitiatFields(CMRec);
UpdateData(FALSE);
CMRec.Close();
}
else
{
AfxMessageBox(_T("Record not found. Please try again."), MB_OK |
MB_ICONEXCLAMATION);
SetDlgItemText(IDC_ID, strCustomerID);
}
}
}

// Click MODIFY Button Then MODIFY Record


void CAddNewCustomer :: OnModify()
{
CString str;
GetDlgItemText(IDC_ID, str);
BOOL bFound = FALSE;
CRecCustomerMaster CMRec(&db);
strSQL = _T("SELECT * FROM CUSTOMER_MASTER ORDER BY TO_NUMBER(SUBSTR(CUSTOMER_ID, 3))");
if(CMRec.Open(CRecordset::snapshot, strSQL))
{
for(CMRec.MoveFirst(); !CMRec.IsEOF(); CMRec.MoveNext())
{
if(str == CMRec.m_CUSTOMER_ID)
{
bFound = TRUE;
break;
}
}
if(bFound)
{
InitiatFields(CMRec);
UpdateData(FALSE);
CMRec.Close();

// Enable or Desable & Show or Hide the Control


ReadOnlyIDControl(FALSE);
}
else
{
AfxMessageBox(_T("Record not found. Please try again."), MB_OK |
MB_ICONEXCLAMATION);
SetDlgItemText(IDC_ID, strCustomerID);
}
}
}

121
// Click CANCEL Button After MODIFY Button
void CAddNewCustomer :: OnMCancel()
{
ReadOnlyIDControl(TRUE);

// Refrash the DialogBox values


UpdateData(FALSE);
}

// Click DELETE Button Then DELETE Existing Record


void CAddNewCustomer :: OnDelete()
{
CString str;
GetDlgItemText(IDC_ID, str);
BOOL bFound = FALSE;
CRecCustomerMaster CMRec(&db);
strSQL = _T("SELECT * FROM CUSTOMER_MASTER ORDER BY TO_NUMBER(SUBSTR(CUSTOMER_ID, 3))");
if(CMRec.Open(CRecordset::snapshot, strSQL))
{
for(CMRec.MoveFirst(); !CMRec.IsEOF(); CMRec.MoveNext())
{
if(str == CMRec.m_CUSTOMER_ID)
{
bFound = TRUE;
break;
}
}
if(bFound)
{
InitiatFields(CMRec);
UpdateData(FALSE);
if(AfxMessageBox(_T("Do you want to sure Delete Record?"), MB_YESNO |
MB_ICONQUESTION) == IDYES)
{
CMRec.Delete();
db.CommitTrans();
CMRec.Close();
}
else
{
db.Rollback();
CMRec.Close();
}
}
else
{
AfxMessageBox(_T("Record not found. Please try again."), MB_OK |
MB_ICONEXCLAMATION);
SetDlgItemText(IDC_ID, strCustomerID);
}
}

122
}

BEGIN_MESSAGE_MAP(CAddNewCustomer, CDialog)
//{{AFX_MSG (IDD_ADDNEWCUSTOMER)
ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG

//{{AFX_MSG (IDD_MODIFYCUSTOMER)
ON_BN_CLICKED(IDC_FIRST, OnFirst)
ON_BN_CLICKED(IDC_PRE, OnPrevious)
ON_BN_CLICKED(IDC_NEXT, OnNext)
ON_BN_CLICKED(IDC_LAST, OnLast)
ON_BN_CLICKED(IDC_SEARCH, OnSearch)
ON_BN_CLICKED(IDC_MODIFY, OnModify)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_CANCEL, OnMCancel)
//}}AFX_MSG
END_MESSAGE_MAP()

123
// THIS FILE IS USED FOR VIEW ALL CUSTOMER
// ViewCustomer.h : Interface of the CViewCustomer class

#define IDC_GRID 100

class CViewCustomer : public CDialog


{
public:
enum { IDD = IDD_VIEW };
CWnd wndGrid;
CString strSQL;
CDatabase db;
IVSFlexGridPtr VSGrid;

public:
CViewCustomer(CWnd* pParent = NULL);
void GridFormating();

protected:
//{{AFX_VIRTUAL (CViewCustomer)
virtual afx_msg void OnCancel();
virtual BOOL OnInitDialog();
//}}AFX_VIRTUAL

//{{AFX_MAP (CViewCustomer)
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MAP

DECLARE_MESSAGE_MAP()
};

// ViewCustomer.cpp : Implementation of the CViewCustomer class

#include"StdAfx.h"
#include"ViewCustomer.h"
#include"RecCustomerMaster.h"

// Construction of the CViewProduct class


CViewCustomer :: CViewCustomer(CWnd* pParent) : CDialog(CViewCustomer::IDD, pParent)
{
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CViewCustomer :: OnInitDialog()
{
CDialog::OnInitDialog();

RECT rc;
GetClientRect(&rc);
InflateRect(&rc, 0, -50);
rc.top = 0;

124
// This Member Function to Create an ActiveX Control
wndGrid.CreateControl("VSFlexGrid8.VSFlexGridL.1", NULL, WS_VISIBLE, rc, this, IDC_GRID);

// Retrieve a Pointer to an Unknown OLE Control


VSGrid = wndGrid.GetControlUnknown();
VSGrid->put_Rows(1);
SetWindowText(_T("Customer Information"));

CRecCustomerMaster CMRec(&db);
TRY
{
strSQL = _T("SELECT * FROM CUSTOMER_MASTER ORDER BY
TO_NUMBER(SUBSTR(CUSTOMER_ID, 3))");
CMRec.Open(CRecordset::snapshot, strSQL);
if(!CMRec.IsEOF())
{
int nRW = 0;
CString strRW, strDOB;

// Display the HEADER on the Grid


VSGrid->put_Cols(CMRec.m_nResultCols - 1);
VSGrid->PutTextMatrix(nRW, 0, _T("Seq."));
VSGrid->PutTextMatrix(nRW, 1, _T("Customer ID"));
VSGrid->PutTextMatrix(nRW, 2, _T("Customer Name"));
VSGrid->PutTextMatrix(nRW, 3, _T("Address"));
VSGrid->PutTextMatrix(nRW, 4, _T("City"));
VSGrid->PutTextMatrix(nRW, 5, _T("Phone"));
VSGrid->PutTextMatrix(nRW, 6, _T("Mobile"));
VSGrid->PutTextMatrix(nRW, 7, _T("E_Mail"));
VSGrid->PutTextMatrix(nRW, 8, _T("Date of Birth"));
VSGrid->PutTextMatrix(nRW, 8, _T("Salary"));
VSGrid->PutTextMatrix(nRW, 8, _T("Occupation"));
for(CMRec.MoveFirst(); !CMRec.IsEOF(); CMRec.MoveNext())
{
nRW++;
strRW.Format(_T("%d"), nRW);
VSGrid->put_Rows(VSGrid->GetRows() + 1);

// Display the Values in the Grid


VSGrid->PutTextMatrix(nRW, 0, _bstr_t(strRW));
VSGrid->PutTextMatrix(nRW, 1, _bstr_t(CMRec.m_CUSTOMER_ID));
VSGrid->PutTextMatrix(nRW, 2, _bstr_t(CMRec.m_CUSTOMER_NAME));
VSGrid->PutTextMatrix(nRW, 3, _bstr_t(CMRec.m_CUSTOMER_ADDRESS));
VSGrid->PutTextMatrix(nRW, 4, _bstr_t(CMRec.m_CUSTOMER_CITY));
VSGrid->PutTextMatrix(nRW, 5, _bstr_t(CMRec.m_CUSTOMER_PHONE));
VSGrid->PutTextMatrix(nRW, 6, _bstr_t(CMRec.m_CUSTOMER_MOBILE));
VSGrid->PutTextMatrix(nRW, 8, _bstr_t(CMRec.m_CUSTOMER_EMAIL));
strDOB = CMRec.m_CUSTOMER_DOB.Format(_T("%d/%m/%Y"));
VSGrid->PutTextMatrix(nRW, 7, _bstr_t(strDOB));
VSGrid->PutTextMatrix(nRW, 8, _bstr_t(CMRec.m_CUSTOMER_SALARY));

125
VSGrid->PutTextMatrix(nRW, 8,
_bstr_t(CMRec.m_CUSTOMER_OCCUPATION));
}
}
else
{
AfxMessageBox(_T("Record(s) are not present."), MB_OK |
MB_ICONINFORMATION);
CMRec.Close();
CDialog::OnCancel();
}
}
CATCH_ALL(e)
{
CMRec.Close();
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL

// Set the PROPERTY of the Grid


VSGrid->ExplorerBar = (ExplorerBarSettings)(flexExMoveRows | flexExSortShowAndMove);
VSGrid->AllowUserResizing = (AllowUserResizeSettings)(flexResizeColumns);
VSGrid->AllowUserFreezing = (AllowUserFreezeSettings) (flexFreezeBoth);
VSGrid->BackColorFrozen = RGB(200, 200, 255);
VSGrid->AutoSize(0, (VSGrid->GetCols() -1 ), vtMissing, 300 );
VSGrid->AutoSearch = (AutoSearchSettings) (flexSearchFromTop);
VSGrid->SelectionMode = flexSelectionListBox;
VSGrid->put_BackColorSel(RGB(153, 172, 145));
GridFormating();
return TRUE;
}

// Click CLOSE Button Then Close the Interface


void CViewCustomer :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

// This Fuction is Called When DialogBox is Resized.


void CViewCustomer :: OnSize(UINT nType, int cx, int cy)
{
if (!m_hWnd || !wndGrid.m_hWnd) return;
RECT rc;
GetClientRect(&rc);

// Resize the GRID Control


InflateRect(&rc, 0, - 50);
rc.top = 0;
CWnd *wndGrid = GetDlgItem(IDC_GRID);
wndGrid->MoveWindow(&rc);

126
// Move the BUTTON Control
CWnd *wndButton = GetDlgItem(IDCANCEL);
rc.left = rc.right - 100;
rc.top = rc.bottom + 10;
rc.right = rc.right - 12;
rc.bottom = rc.bottom + 40;
wndButton->MoveWindow(&rc);
GridFormating();
}

// This Fuction is Used to Format Grid


void CViewCustomer :: GridFormating()
{
VSGrid->PutCell(flexcpFontBold, 0, 0, 0, (VSGrid->GetCols() - 1), 1L);
VSGrid->PutCell(flexcpFontBold, 0, 0, (VSGrid->GetRows() - 1), 0, 1L);
}

BEGIN_MESSAGE_MAP(CViewCustomer, CDialog)
//{{AFX_MSG_MAP(CViewProduct)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

127
// THIS FILE IS A RECORD SOURCE OF THE SALESMAN_MASTER
// RecSalesmanMaster.h : Interface of the CRecSalesmanMaster class

class CRecSalesmanMaster : public CRecordset


{
DECLARE_DYNAMIC(CRecSalesmanMaster)

public:
// Variable of the SALESMAN_MASTER Data Source Fields
//{{AFX_FIELD (SALESMAN_MASTER)
CString m_SALESMAN_ID;
CString m_SALESMAN_NAME;
CString m_SALESMAN_ADDRESS;
CString m_SALESMAN_CITY;
CString m_SALESMAN_PHONE;
CString m_SALESMAN_MOBILE;
CString m_SALESMAN_EMAIL;
CTime m_SALESMAN_DOB;
CTime m_SALESMAN_DATE_OF_JOIN;
CString m_SALESMAN_MANAGER;
CString m_SALESMAN_DESIGNATION;
//}}AFX_FIELD

public:
CRecSalesmanMaster(CDatabase* pDatabase = NULL);

//{{AFX_VIRTUAL (CRecSalesmanMaster)
virtual CString GetDefaultConnect();
virtual CString GetDefaultSQL();
virtual void DoFieldExchange(CFieldExchange* pFX);
//}}AFX_VIRTUAL
};

// RecSalesmanMaster.cpp : implementation of the CRecSalesmanMaster class

#include"StdAfx.h"
#include"RecSalesmanMaster.h"

IMPLEMENT_DYNAMIC(CRecSalesmanMaster, CRecordset)

CRecSalesmanMaster :: CRecSalesmanMaster(CDatabase* pdb) : CRecordset(pdb)


{
//{{AFX_FIELD_INIT (SALESMAN_MASTER)
m_SALESMAN_ID = _T("");
m_SALESMAN_NAME = _T("");
m_SALESMAN_ADDRESS = _T("");
m_SALESMAN_CITY = _T("");
m_SALESMAN_PHONE = _T("");
m_SALESMAN_MOBILE = _T("");
m_SALESMAN_EMAIL = _T("");

128
m_SALESMAN_DESIGNATION = _T("");
m_SALESMAN_MANAGER = _T("");
//}}AFX_FIELD_INIT

m_nFields = 11;
m_nDefaultType = snapshot;
}

// Default Connection String


CString CRecSalesmanMaster::GetDefaultConnect()
{
return _T("ODBC;DSN=crm;UID=crm;PWD=crm;");
}

// Used to Default SQL for Recordset


CString CRecSalesmanMaster::GetDefaultSQL()
{
return _T("[CRM].[SALESMAN_MASTER]");
}

// To Exchange Data (IN BOTH DIRECTION) Between the Record Source Data Members
// and the Corresponding Record on the Data Variable.
void CRecSalesmanMaster::DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);

//{{AFX_FIELD_MAP(SALESMAN_MASTER)
RFX_Text(pFX, _T("[SALESMAN_ID]"), m_SALESMAN_ID);
RFX_Text(pFX, _T("[SALESMAN_NAME]"), m_SALESMAN_NAME);
RFX_Text(pFX, _T("[SALESMAN_ADDRESS]"), m_SALESMAN_ADDRESS);
RFX_Text(pFX, _T("[SALESMAN_CITY]"), m_SALESMAN_CITY);
RFX_Text(pFX, _T("[SALESMAN_PHONE]"), m_SALESMAN_PHONE);
RFX_Text(pFX, _T("[SALESMAN_MOBILE]"), m_SALESMAN_MOBILE);
RFX_Text(pFX, _T("[SALESMAN_EMAIL]"), m_SALESMAN_EMAIL);
RFX_Date(pFX, _T("[SALESMAN_DOB]"), m_SALESMAN_DOB);
RFX_Text(pFX, _T("[SALESMAN_DESIGNATION]"), m_SALESMAN_DESIGNATION);
RFX_Date(pFX, _T("[SALESMAN_DATE_OF_JOIN]"), m_SALESMAN_DATE_OF_JOIN);
RFX_Text(pFX, _T("[SALESMAN_MANAGER]"), m_SALESMAN_MANAGER);
//}}AFX_FIELD_MAP
}

129
// THIS FILE IS USED FOR ADD NEW PRODUCT
// AddNewProduct.h : Interface of the CAddNewProduct class

class CAddNewProduct : public CDialog


{
public:
enum {IDD = IDD_ADDNEWPRODUCT};
CDatabase db;
CString strSQL;

//{{AFX_DATA (CAddNewProduct)
CString strProductID;
CString strProductName;
CString strBrand;
CString strType;
CString strModelNo;
CString strSize;
CString strColor;
CString strGaurentee;
int nStock;
int nLevel;
int nPrice;
int nMRP;
int nMax;
int nMin;
CString strDeatils;
//}}AFX_DATA

public:
CAddNewProduct(CWnd* pParent = NULL);
void InitiatVariables();

protected:
//{{AFX_VIRTUAL (CAddNewProduct)
virtual afx_msg void OnOK();
virtual afx_msg void OnCancel();
virtual void DoDataExchange(CDataExchange* pDX);
virtual BOOL OnInitDialog();
//}}AFX_VIRTUAL

//{{AFX_MSG (CAddNewProduct)
afx_msg void OnRefresh();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// AddNewProduct.cpp : Implementation of the CAddNewProduct class

#include"StdAfx.h"

130
#include"AddNewProduct.h"
#include"RecProductMaster.h"
#include"RecProductDiscount.h"
#include"RecProductInventory.h"

// Constructer of the CAddNewProduct to Initiate the Variables


CAddNewProduct :: CAddNewProduct(CWnd* pParent) : CDialog(CAddNewProduct::IDD, pParent)
{
InitiatVariables();
}

// Initialization of the IDD_ADDNEWPRODUCT DialogBox Variables


void CAddNewProduct :: InitiatVariables()
{
//{{AFX_DATA_INIT (CAddNewProduct)
strProductID = _T("");
strProductName = _T("");
strBrand = _T("");
strType = _T("");
strModelNo = _T("");
strSize = _T("");
strColor = _T("");
strGaurentee = _T("");
nStock = 0;
nLevel = 0;
nPrice = 0;
nMRP = 0;
nMax = 0;
nMin = 0;
strDeatils = _T("");
//}}AFX_DATA_INIT

// Initialization of the PRODUCTID EditBox with Unique ID


CRecProductMaster PMRec(&db);
CString strFile = _T("PRODUCT_MASTER");
CString strField = _T("PRODUCT_ID");

// Read MAX_ID of the PRODUCT_MASTER Data Source.


strProductID = "PM" + Max_ID(PMRec, strFile, strField);
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CAddNewProduct :: OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}

// Initiate the CONTROLS of the IDD_ADDNEWPRODUCT DialogBox


void CAddNewProduct :: DoDataExchange(CDataExchange* pDX)
{

131
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAddNewProduct)
DDX_Text(pDX, IDC_PRODUCTID, strProductID);
DDX_Text(pDX, IDC_PRODUCTNAME, strProductName);
DDV_MaxChars(pDX, strProductName, 20);
DDX_Text(pDX, IDC_BRAND, strBrand);
DDV_MaxChars(pDX, strBrand, 50);
DDX_Text(pDX, IDC_TYPE, strType);
DDV_MaxChars(pDX, strType, 20);
DDX_Text(pDX, IDC_MODELNO, strModelNo);
DDV_MaxChars(pDX, strModelNo, 20);
DDX_Text(pDX, IDC_PSIZE, strSize);
DDV_MaxChars(pDX, strSize, 20);
DDX_Text(pDX, IDC_COLOR, strColor);
DDV_MaxChars(pDX, strColor, 20);
DDX_CBString(pDX, IDC_GAURENTEE, strGaurentee);
DDX_Text(pDX, IDC_STOCK, nStock);
DDV_MinMaxInt(pDX, nStock, 1, 99999);
DDX_Text(pDX, IDC_LEVEL, nLevel);
DDV_MinMaxInt(pDX, nLevel, 1, 99999);
DDX_Text(pDX, IDC_PRICE, nPrice);
DDV_MinMaxInt(pDX, nPrice, 1, 99999);
DDX_Text(pDX, IDC_MRP, nMRP);
DDV_MinMaxInt(pDX, nMRP, 1, 99999);
DDX_Text(pDX, IDC_MAX, nMax);
DDV_MinMaxInt(pDX, nMax, 1, 99999);
DDX_Text(pDX, IDC_MIN, nMin);
DDV_MinMaxInt(pDX, nMin, 1, 99999);
DDX_Text(pDX, IDC_DEATILS, strDeatils);
DDV_MaxChars(pDX, strDeatils, 200);
//}}AFX_DATA_MAP
}

// Click REFRESH Button Then It is Clear the Dialog Box


void CAddNewProduct :: OnRefresh()
{
InitiatVariables();

// Call This Member to Initialize Data in a DialogBox Using DoDataExchange()


CWnd::UpdateData(FALSE);

// Setfocus on the Edit Control


CEdit *txtName = (CEdit*)GetDlgItem(IDC_PRODUCTNAME);
txtName->SetFocus();
}

// Click SAVE Button Then It is Called to Save the Record


void CAddNewProduct :: OnOK()
{
BOOL bTest = TRUE;

132
// Call This Member to Retrive Data From a DialogBox Using DoDataExchange()
if(UpdateData(TRUE))
{
if(strProductName.IsEmpty())
{
AfxMessageBox("Please Enter Product Name.");
GetDlgItem(IDC_PRODUCTNAME)->SetFocus();
bTest = FALSE;
}
else if(strBrand.IsEmpty())
{
AfxMessageBox("Please Enter Product Brand.");
GetDlgItem(IDC_BRAND)->SetFocus();
bTest = FALSE;
}
if(bTest)
{
// ERROR Handling in VISUAL C++
TRY
{
db.BeginTrans();
CRecProductMaster PMRec(&db);
if(PMRec.Open(CRecordset::snapshot))
{
PMRec.AddNew();

// Add Value in PRODUCT_MASTER Record Source.


PMRec.m_PRODUCT_ID = strProductID;
PMRec.m_PRODUCT_NAME = strProductName;
PMRec.m_PRODUCT_BRAND = strBrand;
PMRec.m_PRODUCT_TYPE = strType;
PMRec.m_PRODUCT_SIZE = strSize;
PMRec.m_PRODUCT_COLOR_AVAILABLE = strColor;
PMRec.m_PRODUCT_MODEL_NO = strModelNo;
PMRec.m_PRODUCT_DETAIL = strDeatils;
PMRec.m_PRODUCT_GUARANTEE = strGaurentee;
PMRec.m_PRODUCT_PRICE = nPrice;
if(PMRec.Update())
{
PMRec.Close();

// Add Product Discount in PRODUCT_DISCOUNT Record Source


CRecProductDiscount PDRec(&db);
if(PDRec.Open(CRecordset::snapshot))
{
PDRec.AddNew();
PDRec.m_PRODUCT_ID = strProductID;
PDRec.m_PRODUCT_PURCHASE_PRICE = nPrice;
PDRec.m_PRODUCT_MRP = nMRP;
PDRec.m_PRODUCT_MAX_DISCOUNT = nMax;

133
PDRec.m_PRODUCT_MIN_DISCOUNT = nMin;
if(PDRec.Update())
{
PDRec.Close();

// Add Product Inventory in PRODUCT_INVENTORY Record


Source
CRecProductInventory PIRec(&db);
if(PIRec.Open(CRecordset::snapshot))
{
PIRec.AddNew();
PIRec.m_PRODUCT_ID =
strProductID;
PIRec.m_PRODUCT_STOCK = nStock;
PIRec.m_PRODUCT_REORDER_LEVEL = nLevel;
PIRec.m_PRODUCT_LAST_UPDATE =
CTime::GetCurrentTime();
if(PIRec.Update())
{
PIRec.Close();
AfxMessageBox(_T("Record Succesfull Save."),
MB_OK | MB_ICONINFORMATION);
db.CommitTrans();

CRecProductMaster PMRec(&db);
CString strFile = _T("PRODUCT_MASTER");
CString strField = _T("PRODUCT_ID");

PMRec.Close();
InitiatVariables();
CEdit *txtName =
(CEdit*)GetDlgItem(IDC_PRODUCTNAME);
txtName->SetFocus();
UpdateData(FALSE);
}
}
}
}
}
}
}
CATCH_ALL(e)
{
db.Rollback();
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK |
MB_ICONERROR);
}
END_CATCH_ALL
}
}
}

134
// Click CANCEL Button Then It is Called to Close the Interface
void CAddNewProduct :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

BEGIN_MESSAGE_MAP(CAddNewProduct, CDialog)
//{{AFX_MSG_MAP(CAddNewProduct)
ON_BN_CLICKED(IDC_PREFRESH, OnRefresh)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

135
// THIS FILE IS UDSED FOR UPDATE PRODUCT INFORMATION
// UpdateProduct.h : interface of the CUpdateProduct class

class CRecProductMaster;

class CUpdateProduct : public CDialog


{
public:
enum { IDD = IDD_UPDATEPRODUCT };
CDatabase db;
CString strSQL;

//{{AFX_DATA (CUpdateProduct)
CString strProductID;
CString strProductName;
CString strBrand;
CString strType;
CString strModelNo;
int nPrice;
CString strSize;
CString strColor;
CString strGaurentee;
CString strDeatils;
//}}AFX_DATA

public:
CUpdateProduct(CWnd* pParent = NULL);
void InitiatVariables();
void InitiatFields(CRecProductMaster &rec);
void EnableControl(BOOL bEdit, UINT bCmd);

protected:
//{{AFX_VIRTUAL (CUpdateProduct)
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL

protected:
//{{AFX_MSG (IDD_UpdateProduct)
afx_msg void OnFirst();
afx_msg void OnPre();
afx_msg void OnNext();
afx_msg void OnLast();

afx_msg void OnSearch();


afx_msg void OnModify();
afx_msg void OnDelete();
virtual void OnCancel();

afx_msg void OnMCancel();


afx_msg void OnSave();

136
afx_msg void OnFind();
afx_msg void OnSelChangeProductID();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// UpdateProduct.cpp : Implementation of the CUpdateProduct class

#include"StdAfx.h"
#include"UpdateProduct.h"
#include"RecProductMaster.h"

// Constructer of the CUpdateProduct to Initiate the Variables


CUpdateProduct :: CUpdateProduct(CWnd* pParent) : CDialog(CUpdateProduct::IDD, pParent)
{
InitiatVariables();
}

// Initialization of the IDD_UPDATEPRODUCT DialogBox Variables


void CUpdateProduct :: InitiatVariables()
{
//{{AFX_DATA_INIT (CUpdateProduct)
strProductID = _T("");
strProductName = _T("");
strBrand = _T("");
strType = _T("");
strModelNo = _T("");
nPrice = 0;
strSize = _T("");
strColor = _T("");
strGaurentee = _T("");
strDeatils = _T("");
//}}AFX_DATA_INIT
}

// This Function is Used to Initiate the Fields Variables


void CUpdateProduct :: InitiatFields(CRecProductMaster &rec)
{
strProductID = rec.m_PRODUCT_ID;
strProductName = rec.m_PRODUCT_NAME;
strBrand = rec.m_PRODUCT_BRAND;
strType = rec.m_PRODUCT_TYPE;
strModelNo = rec.m_PRODUCT_MODEL_NO;
nPrice = (int)rec.m_PRODUCT_PRICE;
strSize = rec.m_PRODUCT_SIZE;
strColor = rec.m_PRODUCT_COLOR_AVAILABLE;
strGaurentee = rec.m_PRODUCT_GUARANTEE;
strDeatils = rec.m_PRODUCT_DETAIL;
}

137
// This Fuction Set the Control Properties (ReadOnly, Hide, Show)
void CUpdateProduct :: EnableControl(BOOL bEdit, UINT bCmd)
{
UINT Show, Hide;
if(bCmd == SW_HIDE)
{
Show = SW_SHOW;
Hide = SW_HIDE;
}
else
{
Show = SW_HIDE;
Hide = SW_SHOW;
}

// Show & Hide the DialogBox Commond Button


GetDlgItem(IDC_SAVE)->ShowWindow(Show);
GetDlgItem(IDC_MCANCEL)->ShowWindow(Show);
GetDlgItem(IDC_FIND)->ShowWindow(Hide);
GetDlgItem(IDC_FIRST)->ShowWindow(Hide);
GetDlgItem(IDC_PRE)->ShowWindow(Hide);
GetDlgItem(IDC_NEXT)->ShowWindow(Hide);
GetDlgItem(IDC_LAST)->ShowWindow(Hide);
GetDlgItem(IDC_SEARCH)->ShowWindow(Hide);
GetDlgItem(IDC_MODIFY)->ShowWindow(Hide);
GetDlgItem(IDC_DELETE)->ShowWindow(Hide);
GetDlgItem(IDCANCEL)->ShowWindow(Hide);
GetDlgItem(IDC_GAURENTE)->ShowWindow(Show);
GetDlgItem(IDC_GAURENTEE)->ShowWindow(Hide);

// Enable or Desable the DialogBox Edit Window


((CEdit*)GetDlgItem(IDC_PRODUCTID))->SetReadOnly(bEdit);
((CEdit*)GetDlgItem(IDC_PRODUCTNAME))->SetReadOnly(!bEdit);
((CEdit*)GetDlgItem(IDC_BRAND))->SetReadOnly(!bEdit);
((CEdit*)GetDlgItem(IDC_TYPE))->SetReadOnly(!bEdit);
((CEdit*)GetDlgItem(IDC_MODELNO))->SetReadOnly(!bEdit);
((CEdit*)GetDlgItem(IDC_PSIZE))->SetReadOnly(!bEdit);
((CEdit*)GetDlgItem(IDC_COLOR))->SetReadOnly(!bEdit);
((CEdit*)GetDlgItem(IDC_PRICE))->SetReadOnly(!bEdit);
((CEdit*)GetDlgItem(IDC_DEATILS))->SetReadOnly(!bEdit);
}

//This Function Call Before the DialogBox is Displayed


BOOL CUpdateProduct :: OnInitDialog()
{
// Populate the Values of the PRODUCT_ID in ComboBox
CComboBox *wndProductID;
wndProductID = (CComboBox*)GetDlgItem(IDC_PID);
CRecProductMaster PMRec(&db);

138
strSQL = _T("SELECT * FROM PRODUCT_MASTER ORDER BY TO_NUMBER(SUBSTR(PRODUCT_ID,
3))");
if(PMRec.Open(CRecordset::snapshot, strSQL))
{
for(PMRec.MoveFirst(); !PMRec.IsEOF(); PMRec.MoveNext())

// ADDING Item in ComboBox Control


wndProductID->AddString(_T(PMRec.m_PRODUCT_ID));
PMRec.Close();
}
else
{
AfxMessageBox(_T("Unable to Open Record Source. Please try again."),MB_OK |
MB_ICONSTOP);
}

// Display 1st Record From Record Source.


OnFirst();
return FALSE;
}

// Initiate the CONTROLS of the IDD_ADDNEWCUSTOMER DialogBox


void CUpdateProduct :: DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP (CUpdateProduct)
DDX_Text(pDX, IDC_PRODUCTID, strProductID);
DDX_Text(pDX, IDC_PRODUCTNAME, strProductName);
DDV_MaxChars(pDX, strProductName, 20);
DDX_Text(pDX, IDC_BRAND, strBrand);
DDV_MaxChars(pDX, strBrand, 50);
DDX_Text(pDX, IDC_TYPE, strType);
DDV_MaxChars(pDX, strType, 20);
DDX_Text(pDX, IDC_MODELNO, strModelNo);
DDV_MaxChars(pDX, strModelNo, 20);
DDX_Text(pDX, IDC_PSIZE, strSize);
DDV_MaxChars(pDX, strSize, 20);
DDX_Text(pDX, IDC_COLOR, strColor);
DDV_MaxChars(pDX, strColor, 20);
DDX_Text(pDX, IDC_GAURENTEE, strGaurentee);
DDX_Text(pDX, IDC_PRICE, nPrice);
DDV_MinMaxInt(pDX, nPrice, 1, 9999);
DDX_Text(pDX, IDC_DEATILS, strDeatils);
DDV_MaxChars(pDX, strDeatils, 200);
//}}AFX_DATA_MAP
}

// Select PRODUCT_ID then Select Corresponding Record From PRODUCT_MASTER


void CUpdateProduct :: OnSelChangeProductID()
{

139
CString strTempPID = _T("");
GetDlgItemText(IDC_PID, strTempPID);
CRecProductMaster PMRec(&db);
PMRec.m_strFilter = "PRODUCT_ID = '" + strTempPID + "' ";
if(PMRec.Open())
{
if(!PMRec.IsEOF())
{
InitiatFields(PMRec);
UpdateData(FALSE);
}
}
PMRec.Close();
GetDlgItem(IDC_PRODUCTID)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_PID)->ShowWindow(SW_HIDE);
}

// Click FIND Button Then Genarate PRODUCT_ID List


void CUpdateProduct :: OnFind()
{
CString strPID;
GetDlgItemText(IDC_PRODUCTID, strPID);
GetDlgItem(IDC_PID)->ShowWindow(SW_SHOW);
SetDlgItemText(IDC_PID, strPID);
GetDlgItem(IDC_PRODUCTID)->ShowWindow(SW_HIDE);
AfxMessageBox(_T("Please Select Product ID From List."), MB_OK | MB_ICONINFORMATION);
}

// Click FIRST Button Then GoTo FIRST Record


void CUpdateProduct :: OnFirst()
{
CRecProductMaster PMRec(&db);
strSQL = _T("SELECT * FROM PRODUCT_MASTER ORDER BY TO_NUMBER(SUBSTR(PRODUCT_ID,
3))");
if(PMRec.Open(CRecordset::snapshot, strSQL ))
{
PMRec.MoveFirst();
InitiatFields(PMRec);
UpdateData(FALSE);
}
PMRec.Close();
}

// Click PRE Button Then GoTo PREVIOUS Record


void CUpdateProduct :: OnPre()
{
CRecProductMaster PMRec(&db);
strSQL = _T("SELECT * FROM PRODUCT_MASTER ORDER BY TO_NUMBER(SUBSTR(PRODUCT_ID, 3),
'99999')");
if(PMRec.Open(CRecordset::snapshot, strSQL))
{

140
for(PMRec.MoveFirst(); !PMRec.IsEOF(); PMRec.MoveNext())
{
if(strProductID == PMRec.m_PRODUCT_ID)
break;
}
PMRec.MovePrev();
InitiatFields(PMRec);
UpdateData(FALSE);
}
PMRec.Close();
}

// Click NEXT Button Then GoTo NEXT Record


void CUpdateProduct :: OnNext()
{
CRecProductMaster PMRec(&db);
strSQL = _T("SELECT * FROM PRODUCT_MASTER ORDER BY TO_NUMBER(SUBSTR(PRODUCT_ID, 3),
'99999')");
if(PMRec.Open(CRecordset::snapshot, strSQL))
{
for(PMRec.MoveFirst(); !PMRec.IsEOF(); PMRec.MoveNext())
{
if(strProductID == PMRec.m_PRODUCT_ID)
break;
}
PMRec.MoveNext();
InitiatFields(PMRec);
UpdateData(FALSE);
}
PMRec.Close();
}

// Click LAST Button Then GoTo LAST Record


void CUpdateProduct :: OnLast()
{
CRecProductMaster PMRec(&db);
strSQL = _T("SELECT * FROM PRODUCT_MASTER ORDER BY TO_NUMBER(SUBSTR(PRODUCT_ID, 3),
'99999')");
if(PMRec.Open(CRecordset::snapshot, strSQL))
{
// MOVE Record Cursor on Last Record
PMRec.MoveLast();
InitiatFields(PMRec);
UpdateData(FALSE);
}
PMRec.Close();
}

// Click SEARCH Button Then GoTo Desired Record


void CUpdateProduct :: OnSearch()
{

141
CString strPID;
GetDlgItemText(IDC_PRODUCTID, strPID);
CRecProductMaster PMRec(&db);

// FILTER Record From Record Source


PMRec.m_strFilter = "PRODUCT_ID = '" + strPID + "' ";

if(PMRec.Open(CRecordset::snapshot))
{
if(!PMRec.IsEOF())
{
InitiatFields(PMRec);
UpdateData(FALSE);
PMRec.Close();
}
else
{
AfxMessageBox(_T("Record not Found. Please try again."), MB_OK |
MB_ICONINFORMATION);
SetDlgItemText(IDC_PRODUCTID, strProductID);
}
}
}

// Click MODIFY Button Then Enable the Controls For Editing Records.
void CUpdateProduct :: OnModify()
{
EnableControl(TRUE, SW_HIDE);
}

// Click SAVE Button Then It is Called to Save the Record


void CUpdateProduct :: OnSave()
{
CString strGrnte;
GetDlgItemText(IDC_GAURENTE, strGrnte);
SetDlgItemText(IDC_GAURENTEE, strGrnte);

// Call This Member to Retrive Data From a DialogBox Using DoDataExchange()


if(UpdateData(TRUE))
{
// ERROR Handling in VC++
TRY
{
db.BeginTrans();
CRecProductMaster PMRec(&db);
PMRec.m_strFilter = "PRODUCT_ID = '" + strProductID + "' ";
if(PMRec.Open(CRecordset::snapshot))
{
// Edit Record Source for Modify Record Source
PMRec.Edit();
PMRec.m_PRODUCT_NAME = strProductName;

142
PMRec.m_PRODUCT_BRAND = strBrand;
PMRec.m_PRODUCT_TYPE = strType;
PMRec.m_PRODUCT_SIZE = strSize;
PMRec.m_PRODUCT_COLOR_AVAILABLE = strColor;
PMRec.m_PRODUCT_MODEL_NO = strModelNo;
PMRec.m_PRODUCT_DETAIL = strDeatils;
PMRec.m_PRODUCT_GUARANTEE = strGaurentee;
PMRec.m_PRODUCT_PRICE = nPrice;
if(PMRec.Update())
{
PMRec.Close();

// COMMIT the Record Source


db.CommitTrans();
AfxMessageBox(_T("Record is Modified."), MB_OK |
MB_ICONINFORMATION);
}
}
}
CATCH_ALL(e)
{
AfxMessageBox(_T("Unable to Modify Record. Please try again."), MB_OK |
MB_ICONERROR);
db.Rollback();
}
END_CATCH_ALL
}
OnMCancel();
}

// Click CANCEL Button After MODIFY Button


void CUpdateProduct :: OnMCancel()
{
EnableControl(FALSE, SW_SHOW);

// Refrash the DialogBox Values


UpdateData(FALSE);
}

// Click DELETE Button Then DELETE Existing Record


void CUpdateProduct :: OnDelete()
{
CString strPID;
GetDlgItemText(IDC_PRODUCTID , strPID);
BOOL bFound = FALSE;
CRecProductMaster PMRec(&db);
PMRec.m_strFilter = "PRODUCT_ID = '" + strPID + "' ";
if(PMRec.Open(CRecordset::snapshot))
{
if(!PMRec.IsEOF())
{

143
InitiatFields(PMRec);
UpdateData(FALSE);
if(AfxMessageBox("Do You Want to Sure Delete Record.", MB_YESNO |
MB_ICONQUESTION) == IDYES)
{
// DELETE Record From Record Source
PMRec.Delete();
db.CommitTrans();
PMRec.Close();
}
else
{
PMRec.Close();
}
}
else
{
AfxMessageBox(_T("Record not Found. Please try again."), MB_OK |
MB_ICONINFORMATION);
SetDlgItemText(IDC_PRODUCTID, strPID);
}
}
}

// Click CANCEL Button Then Close the Interface.


void CUpdateProduct :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

BEGIN_MESSAGE_MAP(CUpdateProduct, CDialog)
//{{AFX_MSG_MAP(CUpdateProduct)
ON_BN_CLICKED(IDC_FIRST, OnFirst)
ON_BN_CLICKED(IDC_PRE, OnPre)
ON_BN_CLICKED(IDC_NEXT, OnNext)
ON_BN_CLICKED(IDC_LAST, OnLast)

ON_BN_CLICKED(IDC_SEARCH, OnSearch)
ON_BN_CLICKED(IDC_MODIFY, OnModify)
ON_BN_CLICKED(IDC_DELETE, OnDelete)

ON_BN_CLICKED(IDC_MCANCEL, OnMCancel)
ON_BN_CLICKED(IDC_SAVE, OnSave)

ON_BN_CLICKED(IDC_FIND, OnFind)
ON_CBN_SELCHANGE(IDC_PID, OnSelChangeProductID)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

144
// THIS FILE IS USED FOR VIEW ALL PRODUCT
// ViewProduct.h : Interface of the CViewProduct class

#define IDC_GRID 100

class CViewProduct : public CDialog


{
public:
enum { IDD = IDD_VIEW };
CWnd wndGrid;
CString strSQL;
CDatabase db;
IVSFlexGridPtr VSGrid;

public:
CViewProduct(CWnd* pParent = NULL);
void GridFormating();

protected:
//{{AFX_VIRTUAL (CViewProduct)
virtual afx_msg void OnCancel();
virtual BOOL OnInitDialog();
//}}AFX_VIRTUAL

//{{AFX_MAP (CViewProduct)
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MAP

DECLARE_MESSAGE_MAP()
};

// ViewProduct.cpp : Implementation of the CViewProduct class

#include"StdAfx.h"
#include"RecProductMaster.h"
#include"ViewProduct.h"

// Construction of the CViewProduct class


CViewProduct :: CViewProduct(CWnd* pParent) : CDialog(CViewProduct::IDD, pParent)
{
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CViewProduct :: OnInitDialog()
{
CDialog::OnInitDialog();

RECT rc;
GetClientRect(&rc);
InflateRect(&rc, 0, -50);

145
rc.top = 0;

// This Member Function to Create an ActiveX Control


wndGrid.CreateControl("VSFlexGrid8.VSFlexGridL.1", NULL, WS_VISIBLE, rc, this, IDC_GRID);

// Retrieve a Pointer to an Unknown OLE Control


VSGrid = wndGrid.GetControlUnknown();
VSGrid->put_Rows(1);
SetWindowText(_T("Product Information"));

CRecProductMaster PMRec(&db);
TRY
{
strSQL = _T("SELECT * FROM PRODUCT_MASTER ORDER BY
TO_NUMBER(SUBSTR(PRODUCT_ID, 3))");
PMRec.Open(CRecordset::snapshot, strSQL);
if(!PMRec.IsEOF())
{
int nRW = 0;
CString strRW, strPrice;

// Display the HEADER on the Grid


VSGrid->put_Cols(PMRec.m_nResultCols - 1);
VSGrid->PutTextMatrix(nRW, 0, _T("Seq."));
VSGrid->PutTextMatrix(nRW, 1, _T("Product ID"));
VSGrid->PutTextMatrix(nRW, 2, _T("Product Name"));
VSGrid->PutTextMatrix(nRW, 3, _T("Brand"));
VSGrid->PutTextMatrix(nRW, 4, _T("Size"));
VSGrid->PutTextMatrix(nRW, 5, _T("Color"));
VSGrid->PutTextMatrix(nRW, 6, _T("Model No."));
VSGrid->PutTextMatrix(nRW, 7, _T("Price"));
VSGrid->PutTextMatrix(nRW, 8, _T("Guarantee"));
for(PMRec.MoveFirst(); !PMRec.IsEOF(); PMRec.MoveNext())
{
nRW++;
strRW.Format(_T("%d"), nRW);
VSGrid->put_Rows(VSGrid->GetRows() + 1);

// Display the Values in the Grid


VSGrid->PutTextMatrix(nRW, 0, _bstr_t(strRW));
VSGrid->PutTextMatrix(nRW, 1, _bstr_t(PMRec.m_PRODUCT_ID));
VSGrid->PutTextMatrix(nRW, 2, _bstr_t(PMRec.m_PRODUCT_NAME));
VSGrid->PutTextMatrix(nRW, 3, _bstr_t(PMRec.m_PRODUCT_BRAND));
VSGrid->PutTextMatrix(nRW, 4, _bstr_t(PMRec.m_PRODUCT_SIZE));
VSGrid->PutTextMatrix(nRW, 5,
_bstr_t(PMRec.m_PRODUCT_COLOR_AVAILABLE));
VSGrid->PutTextMatrix(nRW, 6, _bstr_t(PMRec.m_PRODUCT_MODEL_NO));
strPrice.Format(_T("%f"), _T(PMRec.m_PRODUCT_PRICE));
VSGrid->PutTextMatrix(nRW, 7, _bstr_t(strPrice));
VSGrid->PutTextMatrix(nRW, 8, _bstr_t(PMRec.m_PRODUCT_GUARANTEE));
}

146
}
else
{
AfxMessageBox(_T("Record(s) are not present."), MB_OK |
MB_ICONINFORMATION);
PMRec.Close();
CDialog::OnCancel();
}
}
CATCH_ALL(e)
{
PMRec.Close();
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL

// Set the PROPERTY of the Grid


VSGrid->ExplorerBar = (ExplorerBarSettings)(flexExMoveRows | flexExSortShowAndMove);
VSGrid->AllowUserResizing = (AllowUserResizeSettings)(flexResizeColumns);
VSGrid->AllowUserFreezing = (AllowUserFreezeSettings) (flexFreezeBoth);
VSGrid->BackColorFrozen = RGB(200, 200, 255);
VSGrid->AutoSize(0, (VSGrid->GetCols() -1 ), vtMissing, 300 );
VSGrid->AutoSearch = (AutoSearchSettings) (flexSearchFromTop);
VSGrid->SelectionMode = flexSelectionListBox;
VSGrid->put_BackColorSel(RGB(153, 172, 145));
GridFormating();
return TRUE;
}

// Click CLOSE Button Then Close the Interface


void CViewProduct :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

// This Fuction is Called When DialogBox is Resized.


void CViewProduct :: OnSize(UINT nType, int cx, int cy)
{
if (!m_hWnd || !wndGrid.m_hWnd) return;
RECT rc;
GetClientRect(&rc);

// Resize the GRID Control


InflateRect(&rc, 0, - 50);
rc.top = 0;
CWnd *wndGrid = GetDlgItem(IDC_GRID);
wndGrid->MoveWindow(&rc);

// Move the BUTTON Control


CWnd *wndButton = GetDlgItem(IDCANCEL);

147
rc.left = rc.right - 100;
rc.top = rc.bottom + 10;
rc.right = rc.right - 12;
rc.bottom = rc.bottom + 40;
wndButton->MoveWindow(&rc);
GridFormating();
}

// This Fuction is Used to Format Grid


void CViewProduct :: GridFormating()
{
VSGrid->PutCell(flexcpFontBold, 0, 0, 0, (VSGrid->GetCols() - 1), 1L);
VSGrid->PutCell(flexcpFontBold, 0, 0, (VSGrid->GetRows() - 1), 0, 1L);
}

BEGIN_MESSAGE_MAP(CViewProduct, CDialog)
//{{AFX_MSG_MAP(CViewProduct)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

148
// THIS FILE IS RECORD SOURCE OF THE PRODUCT_MASTER
// RecProductMaster.h : Interface of the CRecProductMaster class

class CRecProductMaster : public CRecordset


{
DECLARE_DYNAMIC(CRecProductMaster)

public:
CRecProductMaster(CDatabase* pDatabase = NULL);

// Variable of the PRODUCT_MASTER Data Source Fields


//{{AFX_FIELD (PRODUCT_MASTER)
CString m_PRODUCT_ID;
CString m_PRODUCT_NAME;
CString m_PRODUCT_BRAND;
CString m_PRODUCT_TYPE;
CString m_PRODUCT_SIZE;
CString m_PRODUCT_COLOR_AVAILABLE;
CString m_PRODUCT_MODEL_NO;
CString m_PRODUCT_DETAIL;
CString m_PRODUCT_GUARANTEE;
double m_PRODUCT_PRICE;
//}}AFX_FIELD

public:
//{{AFX_VIRTUAL (CRecProductMaster)
virtual CString GetDefaultConnect();
virtual CString GetDefaultSQL();
virtual void DoFieldExchange(CFieldExchange* pFX);
//}}AFX_VIRTUAL
};

// RecProductMaster.cpp : Implementation of the CRecProductMaster class

#include"StdAfx.h"
#include"CRMProject.h"
#include"RecProductMaster.h"

IMPLEMENT_DYNAMIC(CRecProductMaster, CRecordset)

CRecProductMaster :: CRecProductMaster(CDatabase* pdb) : CRecordset(pdb)


{
//{{AFX_FIELD_INIT (PRODUCT_MASTER)
m_PRODUCT_ID = _T("");
m_PRODUCT_NAME = _T("");
m_PRODUCT_BRAND = _T("");
m_PRODUCT_TYPE = _T("");
m_PRODUCT_SIZE = _T("");
m_PRODUCT_COLOR_AVAILABLE = _T("");
m_PRODUCT_MODEL_NO = _T("");

149
m_PRODUCT_DETAIL = _T("");
m_PRODUCT_GUARANTEE = _T("");
m_PRODUCT_PRICE = 0.0;
//}}AFX_FIELD_INIT

m_nFields = 10;
m_nDefaultType = snapshot;
}

// Default Connection String


CString CRecProductMaster :: GetDefaultConnect()
{
return _T("ODBC;DSN=CRM;UID=CRM;PWD=CRM;");
}

// Used to Default SQL for Recordset


CString CRecProductMaster :: GetDefaultSQL()
{
return _T("[CRM].[PRODUCT_MASTER]");
}

// To Exchange Data (IN BOTH DIRECTION) Between the Record Source Data Members
// and the Corresponding Record on the Data Variable.
void CRecProductMaster :: DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);

//{{AFX_FIELD_MAP (PRODUCT_MASTER)
RFX_Text(pFX, _T("[PRODUCT_ID]"), m_PRODUCT_ID);
RFX_Text(pFX, _T("[PRODUCT_NAME]"), m_PRODUCT_NAME);
RFX_Text(pFX, _T("[PRODUCT_BRAND]"), m_PRODUCT_BRAND);
RFX_Text(pFX, _T("[PRODUCT_TYPE]"), m_PRODUCT_TYPE);
RFX_Text(pFX, _T("[PRODUCT_SIZE]"), m_PRODUCT_SIZE);
RFX_Text(pFX, _T("[PRODUCT_COLOR_AVAILABLE]"), m_PRODUCT_COLOR_AVAILABLE);
RFX_Text(pFX, _T("[PRODUCT_MODEL_NO]"), m_PRODUCT_MODEL_NO);
RFX_Text(pFX, _T("[PRODUCT_DETAIL]"), m_PRODUCT_DETAIL);
RFX_Text(pFX, _T("[PRODUCT_GUARANTEE]"), m_PRODUCT_GUARANTEE);
RFX_Double(pFX, _T("[PRODUCT_PRICE]"), m_PRODUCT_PRICE);
//}}AFX_FIELD_MAP
}

150
// THIS FILE IS USED FOR ADD NEW OFFER
// AddNewOffer.h : Interface of the CAddNewOffer

class CAddNewOffer : public CDialog


{
public:
enum {IDD = IDD_ADDNEWOFFER};
CDatabase db;
CString strSQL;
CComboBox cmbProductID;

public:
CAddNewOffer(CWnd* pParent = NULL);
void InitiatVariables();

//{{AFX_DATA (CAddNewOffer)
CString strLetterID;
CString strProductID;
CString strGroup;
CTime tValidDate;
CString strLetter;
CString strLetterDescription;
//}}AFX_DATA

protected:
//{{AFX_VIRTUAL (CAddNewOffer)
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL

//{{AFX_MSG (IDD_ADDNEWOFFER)
afx_msg void OnOK();
afx_msg void OnCancel();
//}}AFX_MSG

// Declares That the Class Defines a MESSAGE MAP


DECLARE_MESSAGE_MAP()
};

// AddNewOffer.cpp : Implementation of the CAddNewOffer class

#include"StdAfx.h"
#include"AddNewOffer.h"
#include"RecProductOffer.h"
#include"RecProductMaster.h"

// Construction of the CAddNewOffer class


CAddNewOffer :: CAddNewOffer(CWnd* pParent) : CDialog(CAddNewOffer::IDD, pParent)
{
InitiatVariables();

151
}

// Initialization of the IDD_ADDNEWOFFER DialogBox Variables


void CAddNewOffer :: InitiatVariables()
{
//{{AFX_DATA_INIT (CAddNewOffer)
strLetterID = _T("");
strProductID = _T("");
strGroup = _T("");
tValidDate = CTime::GetCurrentTime();
strLetter = _T("");
strLetterDescription = _T("");
//}}AFX_DATA_INIT

// Initialization of the LETTERID EditBox with Unique ID


CRecProductOffer Rec(&db);
CString strFile = _T("PRODUCT_OFFER");
CString strField = _T("OFFER_LETTER_ID");

// Read MAX_ID of the PRODUCT_OFFER Data Source.


strLetterID = "PO" + Max_ID(Rec, strFile, strField);
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CAddNewOffer :: OnInitDialog()
{
CDialog::OnInitDialog();
CComboBox *wndProductID;
wndProductID = (CComboBox*)GetDlgItem(IDC_PRODUCTID);

// Populate the Values of the PRODUCT_ID in ComboBox


CRecProductMaster Rec(&db);
strSQL = _T("SELECT * FROM PRODUCT_MASTER ORDER BY TO_NUMBER(SUBSTR(PRODUCT_ID, 3),
'99999')");
if(Rec.Open(CRecordset::snapshot, strSQL))
{
if(Rec.GetRecordCount())
{
for(Rec.MoveFirst(); !Rec.IsEOF(); Rec.MoveNext())
wndProductID->AddString(_T(Rec.m_PRODUCT_ID));
Rec.Close();
return TRUE;
}
else
{
AfxMessageBox(_T("Product(s) not present."), MB_OK | MB_ICONINFORMATION );
Rec.Close();
CDialog::OnCancel();
return FALSE;
}
}

152
else
{
AfxMessageBox(_T("Unable to Open Record Source. Please try again."),MB_OK |
MB_ICONSTOP);
return FALSE;
}
}

// Initiate the CONTROLS of the IDD_ADDNEWOFFER DialogBox


void CAddNewOffer::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP (CAddNewOffer)
DDX_Text(pDX, IDC_LETTERID, strLetterID);
DDX_Control(pDX, IDC_PRODUCTID, cmbProductID);
DDX_Text(pDX, IDC_GROUP, strGroup);
DDV_MaxChars(pDX, strGroup, 20);
DDX_DateTimeCtrl(pDX, IDC_VALIDDATE, tValidDate);
DDX_Text(pDX, IDC_LETTER, strLetter);
DDV_MaxChars(pDX, strLetter, 50);
DDX_Text(pDX, IDC_OFFERDESC, strLetterDescription);
DDV_MaxChars(pDX, strLetterDescription, 200);
//}}AFX_DATA_MAP
}

// Click SAVE Button to Store the Values in the PRODUCT_OFFER Table


void CAddNewOffer :: OnOK()
{
BOOL bTest = TRUE;

// Call this member to Retrive Data from a DialogBox using DoDataExchange()


if(UpdateData(TRUE))
{
GetDlgItemText(IDC_PRODUCTID, strProductID);
if(strProductID.IsEmpty())
{
AfxMessageBox(_T("Please Select Product Id."));
GetDlgItem(IDC_PRODUCTID)->SetFocus();
bTest = FALSE;
}
else if(strLetter.IsEmpty())
{
AfxMessageBox(_T("Please write a Offer Letter."));
GetDlgItem(IDC_LETTER)->SetFocus();
bTest = FALSE;
}
if(bTest)
{
CRecProductOffer Rec(&db);
if(Rec.Open(CRecordset::snapshot))

153
{
TRY
{
// To Begin a Transaction With the Connected Data Source.
db.BeginTrans();

// ADD New Record in The Record Source.


Rec.AddNew();
Rec.m_OFFER_LETTER_ID = strLetterID;
Rec.m_OFFER_PRODUCT_ID = strProductID;
Rec.m_OFFER_TARGET_GROUP = strGroup;
Rec.m_OFFER_DATE_VALIDITY = tValidDate;
Rec.m_OFFER_SUMMARY = strLetter;
Rec.m_OFFER_DESCRIPTION = strLetterDescription;

// Completes an ADDNEW or EDIT Operation by Saving the New or


Edited Data On the Data Source.
if(Rec.Update())
{
// Closes the Recordset.
Rec.Close();

// Call This Member Function Upon Completing


Transactions.
db.CommitTrans();
AfxMessageBox(_T("Record is Save."),
MB_OK|MB_ICONINFORMATION);
InitiatVariables();
UpdateData(FALSE);
GetDlgItem(IDC_PRODUCTID)->SetFocus();
}
else
{
AfxMessageBox( "Record not added; no field values were
set." );
}
}
CATCH_ALL(e)
{
AfxMessageBox("Process is Rollback.");

// Call This Member Function to Reverse the Changes Made During a


Transaction.
db.Rollback();
}
END_CATCH_ALL
}
else
{
// If PRODUCT_OFFER Table is Not Open.

154
AfxMessageBox(_T("Unable to Open Record Source. Please try again"),
MB_OK | MB_ICONSTOP);
}
}
}
}

// Click CANCEL Button then CLOSE the DATABASE Connection and Interface
void CAddNewOffer :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

// Begins the Definition of Your MESSAGE MAP.


BEGIN_MESSAGE_MAP(CAddNewOffer, CDialog)
//{{AFX_MSG_MAP (CAddNewOffer)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

155
// THIS FILE IS USED FOR VIEW ALL OFFER
// ViewOffer.h : Interface of the CViewOffer class

//{{AFX_INCLUDES()
#include"CrystalReportViewer10.h"
//}}AFX_INCLUDES

class CViewOffer : public CDialog


{
public:
enum { IDD = IDD_VIEWOFFER };
VARIANT dummy;
IReportPtr m_Report;
IApplicationPtr m_Application;
CCrystalReportViewer10 m_Viewer;

public:
CViewOffer(CWnd* pParent = NULL);
void HandleError(_com_error &e);
void ResizeViewer(CRect crRect);

protected:
//{{AFX_VIRTUAL (CViewOffer)
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL

//{{AFX_MSG (CViewOffer)
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// ViewOffer.cpp : Implementation of the CViewOffer class

#include "stdafx.h"
#include "ViewOffer.h"

#define BUFFER_LENGTH 1000

CViewOffer :: CViewOffer(CWnd* pParent) : CDialog(CViewOffer::IDD, pParent)


{
try
{
// Create instance of Application object
m_Application.CreateInstance("CrystalRuntime.Application.10");
}
catch (_com_error& e)

156
{
// if errors occur, handle and display errors
HandleError(e);
}
// initialise the m_Report variable to NULL
m_Report = NULL;
}

BOOL CViewOffer::OnInitDialog()
{
CDialog::OnInitDialog();

// A dummy variant
VariantInit (&dummy);
CString strPath;
char lpPath[BUFFER_LENGTH];
CRect rect;

dummy.vt = VT_EMPTY;
::GetCurrentDirectory(BUFFER_LENGTH, lpPath);
strPath.Format(_T("%s"), lpPath);

// Specify the Path to the REPORT You Want to PRINT


strPath = strPath + "\\Report\\offer.rpt";

_bstr_t ReportPath(strPath);
_variant_t vtEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);

//Open the Report using the OpenReport method


m_Report = m_Application->OpenReport(ReportPath, dummy);

//Print the Resize Report to Window


GetClientRect(&rect);
ResizeViewer(rect);
m_Viewer.SetReportSource(m_Report);
m_Viewer.ViewReport();

return TRUE;
}

void CViewOffer :: DoDataExchange(CDataExchange* pDX)


{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CComplainView)
DDX_Control(pDX, IDC_OFFERVIEWER, m_Viewer);
//}}AFX_DATA_MAP
}

// Fired When Dialog is RESIZED


void CViewOffer :: OnSize(UINT nType, int cx, int cy)
{

157
// test to see if the viewer has been drawn yet or not...
if( !::IsWindow(m_Viewer.m_hWnd ) )
{
return;
}
try
{
// move and redraw the viewer's window
CRect rect(0, 0, cx, cy);
ResizeViewer(rect);
}
catch (_com_error& e)
{
HandleError(e);
}
}

// RESIZE the CRYSTAL VIEWER


void CViewOffer :: ResizeViewer(CRect crRect)
{
m_Viewer.MoveWindow(crRect);
m_Viewer.Invalidate();
m_Viewer.UpdateWindow();
}

// A Utility COM error handler...


void CViewOffer :: HandleError(_com_error &e)
{
IErrorInfo* pErrorInfo = e.ErrorInfo();
HRESULT hr = e.Error();
if (pErrorInfo)
{
BSTR bsDesc = NULL;
pErrorInfo->GetDescription( &bsDesc );
_bstr_t sDesc( bsDesc, false );
::MessageBox(0, sDesc.operator LPCTSTR(), "", MB_OK );
pErrorInfo->Release();
}
}

BEGIN_MESSAGE_MAP(CViewOffer, CDialog)
//{{AFX_MSG_MAP(CViewOffer)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

158
// THIS FILE IS RECORD SOURCE OF THE PRODUCT_OFFER
// RecProductOffer.h : Interface of the COfferRecord class

class CRecProductOffer : public CRecordset


{
DECLARE_DYNAMIC(CRecProductOffer)

public:
CRecProductOffer(CDatabase* pDatabase = NULL);

// Variable of the PRODUCT_OFFER Data Source Fields


//{{AFX_FIELD (PRODUCT_OFFER)
CString m_OFFER_LETTER_ID;
CString m_OFFER_PRODUCT_ID;
CString m_OFFER_TARGET_GROUP;
CTime m_OFFER_DATE_VALIDITY;
CString m_OFFER_SUMMARY;
CString m_OFFER_DESCRIPTION;
//}}AFX_FIELD

public:
//{{AFX_VIRTUAL (CRecProductOffer)
virtual CString GetDefaultConnect();
virtual CString GetDefaultSQL();
virtual void DoFieldExchange(CFieldExchange* pFX);
//}}AFX_VIRTUAL
};

// RecProductOffer.cpp : Implementation file of CAddNewCustomer class

#include"StdAfx.h"
#include "RecProductOffer.h"

IMPLEMENT_DYNAMIC(CRecProductOffer, CRecordset)

CRecProductOffer :: CRecProductOffer(CDatabase* pdb) : CRecordset(pdb)


{
//{{AFX_FIELD_INIT (PRODUCT_OFFER)
m_OFFER_LETTER_ID = _T("");
m_OFFER_PRODUCT_ID = _T("");
m_OFFER_TARGET_GROUP = _T("");
m_OFFER_SUMMARY = _T("");
m_OFFER_DESCRIPTION = _T("");
//}}AFX_FIELD_INIT

m_nFields = 6;
m_nDefaultType = snapshot;
}

159
// Default Connection String
CString CRecProductOffer :: GetDefaultConnect()
{
return _T("ODBC;DSN=CRM;UID=CRM;PWD=CRM;");
}

// Used to Default SQL for Recordset


CString CRecProductOffer :: GetDefaultSQL()
{
return _T("[CRM].[PRODUCT_OFFER]");
}

// To Exchange Data (IN BOTH DIRECTION) Between the Record Source Data Members
// and the Corresponding Record on the Data Variable.
void CRecProductOffer :: DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);

//{{AFX_FIELD_MAP (PRODUCT_OFFER)
RFX_Text(pFX, _T("[OFFER_LETTER_ID]"), m_OFFER_LETTER_ID);
RFX_Text(pFX, _T("[CRM].[PRODUCT_OFFER].[PRODUCT_ID]"), m_OFFER_PRODUCT_ID);
RFX_Text(pFX, _T("[PRODUCT_ID]"), m_OFFER_PRODUCT_ID);
RFX_Text(pFX, _T("[OFFER_TARGET_GROUP]"), m_OFFER_TARGET_GROUP);
RFX_Date(pFX, _T("[OFFER_DATE_VALIDITY]"), m_OFFER_DATE_VALIDITY);
RFX_Text(pFX, _T("[OFFER_LETTER]"), m_OFFER_SUMMARY);
RFX_Text(pFX, _T("[OFFER_DESCRIPTION]"), m_OFFER_DESCRIPTION);
//}}AFX_FIELD_MAP
}

160
// THIS FILE IS USED FOR ADD NEW COMPLAIN
// AddNewComplain.h : Interface of the CAddNewComplain class

class CAddNewComplain : public CDialog


{
public:
enum { IDD = IDD_ADDNEWCOMPLAIN };
CDatabase db;
CString strSQL;

//{{AFX_DATA (CAddNewComplain)
CString strComplainID;
CComboBox cmbProductID;
CString strProductID;
CString strProductName;
CString strCustomerID;
CString strCustomerName;
int nComplexcity;
CTime tDate;
CString strDate;
CString strDescription;
//}}AFX_DATA

public:
CAddNewComplain(CWnd* pParent = NULL);
void InitiatVariables();

protected:
//{{AFX_VIRTUAL(CAddNewComplain)
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL

//{{AFX_MSG (CAddNewComplain)
afx_msg void OnRefresh();
afx_msg void OnOK();
afx_msg void OnCancel();
afx_msg void OnSelChangeProductID();
afx_msg void OnSelChangeCustomerID();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// AddNewComplain.cpp : implementation file

#include"StdAfx.h"
#include"AddNewComplain.h"
#include"RecProductMaster.h"

161
#include"RecCustomerMaster.h"
#include"RecCustomerComplain.h"

// Construction of the CAddNewComplain class


CAddNewComplain :: CAddNewComplain(CWnd* pParent) : CDialog(CAddNewComplain::IDD, pParent)
{
InitiatVariables();
}

// Initialization of the IDD_ADDNEWCOMPLAIN DialogBox Variables


void CAddNewComplain :: InitiatVariables()
{
//{{AFX_DATA_INIT(CAddNewComplain)
strComplainID = _T("");
strProductName = _T("");;
strCustomerID = _T("");
strCustomerName = _T("");
nComplexcity = 0;
tDate = CTime::GetCurrentTime();
strDate = tDate.Format(_T("%d/%m/%Y"));
strDescription = _T("");
//}}AFX_DATA_INIT

// Initialization of the COMPLAINID EditBox with Unique ID


CRecCustomerComplain Rec(&db);
CString strFile = _T("CUSTOMER_COMPLAIN");
CString strField = _T("COMPLAIN_ID");

// Read MAX_ID of the CUSTOMER_COMPLAIN Data Source.


strComplainID = "CC" + Max_ID(Rec, strFile, strField);
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CAddNewComplain :: OnInitDialog()
{
CDialog::OnInitDialog();
CComboBox *wndProductID;
wndProductID = (CComboBox*)GetDlgItem(IDC_PRODUCTID);

// Populate the Values of the PRODUCT_ID in ComboBox


CRecProductMaster Rec(&db);
strSQL = _T("SELECT * FROM PRODUCT_MASTER ORDER BY
TO_NUMBER(SUBSTR(PRODUCT_ID,3))");
if(Rec.Open(CRecordset::snapshot, strSQL))
{
if(Rec.GetRecordCount())
{
for(Rec.MoveFirst(); !Rec.IsEOF(); Rec.MoveNext())
{
wndProductID->AddString(_T(Rec.m_PRODUCT_ID));
}

162
Rec.Close();
}
else
AfxMessageBox(_T("Product is not present."), MB_OK|MB_ICONSTOP);
}
return TRUE;
}

// Initiate the CONTROLS of the IDD_ADDNEWCOMPLAIN DialogBox


void CAddNewComplain :: DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP (CAddNewComplain)
DDX_Text(pDX, IDC_COMPLAINID, strComplainID);
DDX_Control(pDX, IDC_PRODUCTID, cmbProductID);
DDX_Text(pDX, IDC_PRODUCTNAME, strProductName);
DDX_Text(pDX, IDC_CUSTOMERID, strCustomerID);
DDV_MaxChars(pDX, strCustomerID, 10);
DDX_Text(pDX, IDC_CUSTOMERNAME, strCustomerName);
DDX_CBIndex(pDX, IDC_COMPLEXCITY, nComplexcity);
DDX_Text(pDX, IDC_DATE, strDate);
DDX_Text(pDX, IDC_DESCRIPTION, strDescription);
DDV_MaxChars(pDX, strDescription, 50);
//}}AFX_DATA_MAP
}

// Select PRODUCT_ID then Select Corresponding PRODUCT_NAME From PRODUCT_MASTER


void CAddNewComplain :: OnSelChangeProductID()
{
CString strTempPID;

// Gets a SELECTED String From the ListBox of a ComboBox.


cmbProductID.GetLBText(cmbProductID.GetCurSel(), strTempPID);
CRecProductMaster Rec(&db);

// Use This DATA MEMBER (m_strFilter) to Store a CString Containing a SQL WHERE clause.
Rec.m_strFilter = "PRODUCT_ID = '" + strTempPID + "' ";
if(Rec.Open())
{
strProductName = _T(Rec.m_PRODUCT_NAME);
UpdateData(FALSE);
}
else
{
AfxMessageBox(_T("Product not found."), MB_OK|MB_ICONINFORMATION);
}
}

163
// Enter CUSTOMER_ID then Select Corresponding CUSTOMER_NAME From CUSTOMER_MASTER
void CAddNewComplain :: OnSelChangeCustomerID()
{
CString strTempCID = _T("");;
GetDlgItemText(IDC_CUSTOMERID, strTempCID);
CRecCustomerMaster Rec(&db);
Rec.m_strFilter = "CUSTOMER_ID = '" + strTempCID + "' ";
if(Rec.Open())
{
if(!Rec.IsEOF())
{
strCustomerName = _T(Rec.m_CUSTOMER_NAME);
GetDlgItemText(IDC_CUSTOMERID, strCustomerID);
UpdateData(FALSE);
}
else
{
AfxMessageBox(_T("Customer not found. Please try again."),
MB_OK|MB_ICONINFORMATION);
SetDlgItemText(IDC_PRODUCTID, "");
SetDlgItemText(IDC_PRODUCTNAME, "");
UpdateData(FALSE);
}
}
}

// Click REFRESH Button to Clear the DialogBox


void CAddNewComplain :: OnRefresh()
{
InitiatVariables();
UpdateData(FALSE);
GetDlgItem(IDC_PRODUCTID)->SetFocus();
}

// Click SAVE Button to Store the Values in the CUSTOMER_COMPLAIN Table


void CAddNewComplain :: OnOK()
{
BOOL bTest = TRUE;

// Call this member to Retrive Data from a DialogBox using DoDataExchange()


if(UpdateData(TRUE))
{
GetDlgItemText(IDC_PRODUCTID, strProductID);
if(strProductID.IsEmpty())
{
AfxMessageBox(_T("Please Select Product Id."));
GetDlgItem(IDC_PRODUCTID)->SetFocus();
bTest = FALSE;
}
else
{

164
GetDlgItemText(IDC_CUSTOMERID, strCustomerID);
if(strCustomerID.IsEmpty())
{
AfxMessageBox(_T("Please Select Customer Id."));
GetDlgItem(IDC_CUSTOMERID)->SetFocus();
bTest = FALSE;
}
}
if(bTest)
{
TRY
{
CRecCustomerComplain Rec(&db);
if(Rec.Open(CRecordset::snapshot))
{
// To Begin a Transaction With the Connected Data Source.
db.BeginTrans();

// ADD New Record in The Record Source.


Rec.AddNew();
Rec.m_COMPLAIN_ID = strComplainID;
Rec.m_PRODUCT_ID = strProductID;
Rec.m_CUSTOMER_ID = strCustomerID;
Rec.m_COMPLAIN_COMPLEXITY = (nComplexcity + 1);
Rec.m_COMPLAINTEGER_DATE = CTime::GetCurrentTime();
Rec.m_DATE_OF_ACTION = CTime::GetCurrentTime();
Rec.m_TECHNICIAN = _T("NONE");
Rec.m_COMPLAIN_DESCRIPTION = strDescription;
Rec.m_ACTION_TAKEN = _T("PENDING");
Rec.m_PAYMENT_RECIEVED = 0.0;

// Completes an ADDNEW or EDIT Operation by Saving the New or


Edited Data On the Data Source.
if(Rec.Update())
{
// Closes the Recordset.
Rec.Close();

// Call This Member Function Upon Completing


Transactions.
db.CommitTrans();
AfxMessageBox(_T("Record is Save."),
MB_OK|MB_ICONINFORMATION);
InitiatVariables();
UpdateData(FALSE);
GetDlgItem(IDC_PRODUCTID)->SetFocus();
}
}
}
CATCH_ALL(e)
{

165
AfxMessageBox(_T("Record Source is not Open. Please try again."), MB_OK
| MB_ICONERROR);

// Call This Member Function to Reverse the Changes Made During a


Transaction.
db.Rollback();
}
END_CATCH_ALL
}
}
}

// Click CANCEL Button then CLOSE the DATABASE Connection and Interface
void CAddNewComplain :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

BEGIN_MESSAGE_MAP(CAddNewComplain, CDialog)
//{{AFX_MSG_MAP(CAddNewComplain)
ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
ON_CBN_SELCHANGE(IDC_PRODUCTID, OnSelChangeProductID)
ON_EN_KILLFOCUS(IDC_CUSTOMERID, OnSelChangeCustomerID)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

166
// THIS FILE IS USED FOR PENDING COMPLAIN
// PendingComplain.h : Interface of the CPendingComplain class

class CPendingComplain : public CDialog


{
public:
enum { IDD = IDD_PENDINGCOMPLAIN };
CDatabase db;
CString strSQL;
CComboBox *wndComplainID;

//{{AFX_DATA (CPendingComplain)
CString strComplainID;
int nComplainID;
CString strProductID;
CString strProductName;
CString strCustomerID;
CString strCustomerName;
UINT nComplex;
CTime tComplainDate;
CString strComplainDate;
CString strDescription;
CString strTechnician;
CTime tActionDate;
CString strAmount;
int nAmount;
CString strActionTaken;
//}}AFX_DATA

public:
CPendingComplain(CWnd* pParent = NULL);
void InitiatVariables();

protected:
//{{AFX_VIRTUAL (CPendingComplain)
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL

//{{AFX_MSG (CPendingComplain)
afx_msg void OnRefresh();
afx_msg void OnOK();
afx_msg void OnCancel();
afx_msg void OnSelChangeCustomerID();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

167
// PendingComplain.cpp : Implementation of the CPendingComplain class

#include"StdAfx.h"
#include"PendingComplain.h"
#include"RecCustomerComplain.h"
#include"RecCustomerMaster.h"
#include"RecProductMaster.h"

// Construction of the CPendingComplain class


CPendingComplain :: CPendingComplain(CWnd* pParent) : CDialog(CPendingComplain::IDD, pParent)
{
InitiatVariables();
}

// Initialization of the IDD_PENDINGCOMPLAIN DialogBox Variables


void CPendingComplain :: InitiatVariables()
{
//{{AFX_DATA_INIT (CPendingComplain)
strComplainID = _T("");
strProductID = _T("");
strProductName = _T("");
strCustomerID = _T("");
strCustomerName = _T("");
nComplex = 0;
tComplainDate = CTime::GetCurrentTime();
strComplainDate = tComplainDate.Format(_T("%d/%m/%Y"));
strDescription = _T("");
strTechnician = _T("");
tActionDate = CTime::GetCurrentTime();
nAmount = 150;
strActionTaken = _T("");
//}}AFX_DATA_INIT
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CPendingComplain :: OnInitDialog()
{
CDialog::OnInitDialog();
wndComplainID = (CComboBox*)GetDlgItem(IDC_COMPLAINID);

// Populate the Values of the COMPLAIN_ID in ComboBox


CRecCustomerComplain Rec(&db);
strSQL = _T("SELECT * FROM CUSTOMER_COMPLAIN WHERE ACTION_TAKEN = 'PENDING' ORDER BY
TO_NUMBER(SUBSTR(COMPLAIN_ID,3))");
if(Rec.Open(CRecordset::snapshot, strSQL))
{
if(Rec.GetRecordCount())
{
for(Rec.MoveFirst(); !Rec.IsEOF(); Rec.MoveNext())
{
wndComplainID->AddString(_T(Rec.m_COMPLAIN_ID));

168
}
Rec.Close();
GetDlgItem(IDC_TECHNICIAN)->SetFocus();
}
else
{
AfxMessageBox(_T("Complain(s) are not present."),
MB_OK|MB_ICONINFORMATION);
db.Close();
CDialog::OnCancel();
}
}
return TRUE;
}

// Initiate the CONTROLS of the IDD_PENDINGCOMPLAIN DialogBox


void CPendingComplain :: DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CPendingComplain)
DDX_CBIndex(pDX, IDC_COMPLAINID, nComplainID);
DDX_Text(pDX, IDC_PRODUCTID, strProductID);
DDX_Text(pDX, IDC_PRODUCTNAME, strProductName);
DDX_Text(pDX, IDC_CUSTOMERID, strCustomerID);
DDX_Text(pDX, IDC_CUSTOMERNAME, strCustomerName);
DDX_Text(pDX, IDC_COMPLEX, nComplex);
DDX_Text(pDX, IDC_COMPLAINDATE, strComplainDate);
DDX_Text(pDX, IDC_DESCRIPTION, strDescription);
DDX_Text(pDX, IDC_TECHNICIAN, strTechnician);
DDV_MaxChars(pDX, strTechnician, 30);
DDX_DateTimeCtrl(pDX, IDC_ACTIONDATE, tActionDate);
DDX_Text(pDX, IDC_AMOUNT, nAmount);
DDV_MinMaxInt(pDX, nAmount, 150, 99999);
DDX_Text(pDX, IDC_ACTIONTAKEN, strActionTaken);
DDV_MaxChars(pDX, strActionTaken, 50);
//}}AFX_DATA_MAP
}

// Enter COMPLAIN_ID then Select Corresponding Information From CUSTOMER_COMPLAIN


void CPendingComplain :: OnSelChangeCustomerID()
{
CString strTempCID = _T("");
GetDlgItemText(IDC_COMPLAINID, strTempCID);

// Populate Information About SELECTED COMPLAIN_ID


CRecCustomerComplain Rec(&db);
Rec.m_strFilter = "COMPLAIN_ID = '" + strTempCID + "' ";
if(Rec.Open())
{
if(!Rec.IsEOF())

169
{
strProductID = _T(Rec.m_PRODUCT_ID);
strCustomerID = _T(Rec.m_CUSTOMER_ID);
nComplex = _T(Rec.m_COMPLAIN_COMPLEXITY);
strComplainDate = Rec.m_COMPLAINTEGER_DATE.Format(_T("%d/%m/%Y"));
strDescription = _T(Rec.m_COMPLAIN_DESCRIPTION);
Rec.Close();

// Retrive the PRODUCT_NAME of the Given PRODUCT_ID


CRecProductMaster PRec(&db);
PRec.m_strFilter = "PRODUCT_ID = '" + strProductID + "' ";
if(PRec.Open())
{
strProductName = _T(PRec.m_PRODUCT_NAME);
PRec.Close();
}

// Retrive the CUSTOMER_NAME of the Given CUSTOMER_NAME


CRecCustomerMaster CRec(&db);
CRec.m_strFilter = "CUSTOMER_ID = '" + strCustomerID + "' ";
if(CRec.Open())
{
strCustomerName = _T(CRec.m_CUSTOMER_NAME);
CRec.Close();
}
UpdateData(FALSE);
}
else
{
AfxMessageBox(_T("Complain(s) are not found. Please try again."),
MB_OK|MB_ICONINFORMATION);
}
}
}

// Click REFRESH Button to Clear the DialogBox


void CPendingComplain :: OnRefresh()
{
InitiatVariables();
UpdateData(FALSE);
GetDlgItem(IDC_COMPLAINID)->SetFocus();
}

// Click SAVE Button to Store the Values in the CUSTOMER_COMPLAIN Table


void CPendingComplain :: OnOK()
{
BOOL bTest = TRUE;

// Call this member to Retrive Data from a DialogBox using DoDataExchange()


if(UpdateData(TRUE))
{

170
if(strTechnician.IsEmpty())
{
AfxMessageBox(_T("Please Enter Technician Name."));
GetDlgItem(IDC_TECHNICIAN)->SetFocus();
bTest = FALSE;
}
if(bTest)
{
strSQL = _T("");
CString strTempCID = _T("");
GetDlgItemText(IDC_COMPLAINID, strTempCID);

CString strTempTime = _T("");


strTempTime = tActionDate.Format(_T("%d/%m/%Y"));
TRY
{
CRecCustomerComplain Rec(&db);
Rec.m_strFilter = "COMPLAIN_ID = '" + strTempCID + "' ";
if(Rec.Open())
{
if(!Rec.IsEOF())
{
Rec.Edit();
Rec.m_TECHNICIAN = strTechnician;
Rec.m_DATE_OF_ACTION = tActionDate;
Rec.m_PAYMENT_RECIEVED = nAmount;
Rec.m_ACTION_TAKEN = strActionTaken;
if(Rec.Update())
{
Rec.Close();
AfxMessageBox(_T("Record Save."));
InitiatVariables();
UpdateData(FALSE);
}
}
}
}
CATCH_ALL(e)
{
AfxMessageBox("Unable to Update Data Source. Process is Rollback.");
}
END_CATCH_ALL
}
}
}

// Click CANCEL Button then CLOSE the DATABASE Connection and Interface
void CPendingComplain :: OnCancel()
{
db.Close();
CDialog::OnCancel();

171
}

BEGIN_MESSAGE_MAP(CPendingComplain, CDialog)
//{{AFX_MSG_MAP(CPendingComplain)
ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
ON_CBN_SELCHANGE(IDC_COMPLAINID, OnSelChangeCustomerID)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

172
// THIS FILE IS USED FOR VIW ALL COMPLAIN
// ViewComplain.h : Interface of the CViewComplain class

#define IDC_GRID 100

class CViewComplain : public CDialog


{
public:
enum { IDD = IDD_VIEW };
CWnd wndGrid;
CString strSQL;
CDatabase db;
IVSFlexGridPtr VSGrid;

public:
CViewComplain(CWnd* pParent = NULL);
void GridFormating();

protected:
//{{AFX_VIRTUAL (CViewComplain)
virtual afx_msg void OnCancel();
virtual BOOL OnInitDialog();
//}}AFX_VIRTUAL

//{{AFX_MAP (CViewComplain)
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MAP

DECLARE_MESSAGE_MAP()
};

// ViewComplain.cpp : Implementation of the CViewComplain class

#include"StdAfx.h"
#include"ViewComplain.h"
#include"RecCustomerComplain.h"

// Construction of the ViewSalesman class


CViewComplain :: CViewComplain(CWnd* pParent) : CDialog(CViewComplain::IDD, pParent)
{
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CViewComplain :: OnInitDialog()
{
CDialog::OnInitDialog();

RECT rc;
GetClientRect(&rc);
InflateRect(&rc, 0, -50);

173
rc.top = 0;

// This Member Function to Create an ActiveX Control


wndGrid.CreateControl("VSFlexGrid8.VSFlexGridL.1", NULL, WS_VISIBLE, rc, this, IDC_GRID);

// Retrieve a Pointer to an Unknown OLE Control


VSGrid = wndGrid.GetControlUnknown();
VSGrid->put_Rows(1);
SetWindowText(_T("Customer Complain"));

CRecCustomerComplain CCRec(&db);
TRY
{
strSQL = _T("SELECT * FROM CUSTOMER_COMPLAIN ORDER BY
TO_NUMBER(SUBSTR(COMPLAIN_ID, 3))");
CCRec.Open(CRecordset::snapshot, strSQL);
if(!CCRec.IsEOF())
{
int nRW = 0;
CString strRW, strComplainDate, strActionDate, strPayment, strComplex;

// Display the HEADER on the Grid


VSGrid->put_Cols(11);
VSGrid->PutTextMatrix(nRW, 0, _T("Seq."));
VSGrid->PutTextMatrix(nRW, 1, _T("Comaplin ID"));
VSGrid->PutTextMatrix(nRW, 2, _T("Product ID"));
VSGrid->PutTextMatrix(nRW, 3, _T("Customer ID"));
VSGrid->PutTextMatrix(nRW, 4, _T("Description"));
VSGrid->PutTextMatrix(nRW, 5, _T("Complexity"));
VSGrid->PutTextMatrix(nRW, 6, _T("Complain Date"));
VSGrid->PutTextMatrix(nRW, 7, _T("Date of Action"));
VSGrid->PutTextMatrix(nRW, 8, _T("Technician"));
VSGrid->PutTextMatrix(nRW, 9, _T("Action Taken"));
VSGrid->PutTextMatrix(nRW, 10, _T("Payment"));
for(CCRec.MoveFirst(); !CCRec.IsEOF(); CCRec.MoveNext())
{
nRW++;
strRW.Format(_T("%d"), nRW);
VSGrid->put_Rows(VSGrid->GetRows() + 1);

// Display the Values in the Grid


VSGrid->PutTextMatrix(nRW, 0, _bstr_t(strRW));
VSGrid->PutTextMatrix(nRW, 1, _bstr_t(CCRec.m_COMPLAIN_ID));
VSGrid->PutTextMatrix(nRW, 2, _bstr_t(CCRec.m_PRODUCT_ID));
VSGrid->PutTextMatrix(nRW, 3, _bstr_t(CCRec.m_CUSTOMER_ID));
VSGrid->PutTextMatrix(nRW, 4,
_bstr_t(CCRec.m_COMPLAIN_DESCRIPTION));
strComplex.Format(_T("%d"), CCRec.m_COMPLAIN_COMPLEXITY);
VSGrid->PutTextMatrix(nRW, 5, _bstr_t(strComplex));
strComplainDate =
CCRec.m_COMPLAINTEGER_DATE.Format(_T("%d/%m/%Y"));

174
VSGrid->PutTextMatrix(nRW, 6, _bstr_t(strComplainDate));
if(CCRec.m_ACTION_TAKEN == "PENDING")
{
strActionDate = _T("");
VSGrid->PutTextMatrix(nRW, 8, _bstr_t(""));
strPayment = _T("0");
}
else
{
strActionDate =
CCRec.m_DATE_OF_ACTION.Format(_T("%d/%m/%Y"));
VSGrid->PutTextMatrix(nRW, 8, _bstr_t(CCRec.m_TECHNICIAN));
strPayment.Format(_T("%f"), CCRec.m_PAYMENT_RECIEVED);
}
VSGrid->PutTextMatrix(nRW, 7, _bstr_t(strActionDate));
VSGrid->PutTextMatrix(nRW, 9, _bstr_t(CCRec.m_ACTION_TAKEN));
VSGrid->PutTextMatrix(nRW, 10, _bstr_t(strPayment));

}
}
else
{
AfxMessageBox(_T("Record(s) are not present."), MB_OK |
MB_ICONINFORMATION);
CCRec.Close();
CDialog::OnCancel();
}
}
CATCH_ALL(e)
{
CCRec.Close();
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL

// Set the PROPERTY of the Grid


VSGrid->ExplorerBar = (ExplorerBarSettings)(flexExMoveRows | flexExSortShowAndMove);
VSGrid->AllowUserResizing = (AllowUserResizeSettings)(flexResizeColumns);
VSGrid->AllowUserFreezing = (AllowUserFreezeSettings) (flexFreezeBoth);
VSGrid->BackColorFrozen = RGB(200, 200, 255);
VSGrid->AutoSize(0, (VSGrid->GetCols() -1 ), vtMissing, 300 );
VSGrid->AutoSearch = (AutoSearchSettings) (flexSearchFromTop);
VSGrid->SelectionMode = flexSelectionListBox;
VSGrid->put_BackColorSel(RGB(153, 172, 145));
GridFormating();
return TRUE;
}

// Click CLOSE Button Then Close the Interface


void CViewComplain :: OnCancel()
{

175
db.Close();
CDialog::OnCancel();
}

// This Fuction is Called When DialogBox is Resized.


void CViewComplain :: OnSize(UINT nType, int cx, int cy)
{
if (!m_hWnd || !wndGrid.m_hWnd) return;
RECT rc;
GetClientRect(&rc);

// Resize the GRID Control


InflateRect(&rc, 0, - 50);
rc.top = 0;
CWnd *wndGrid = GetDlgItem(IDC_GRID);
wndGrid->MoveWindow(&rc);

// Move the BUTTON Control


CWnd *wndButton = GetDlgItem(IDCANCEL);
rc.left = rc.right - 100;
rc.top = rc.bottom + 10;
rc.right = rc.right - 12;
rc.bottom = rc.bottom + 40;
wndButton->MoveWindow(&rc);
GridFormating();
}

// This Fuction is Used to Format Grid


void CViewComplain :: GridFormating()
{
VSGrid->PutCell(flexcpFontBold, 0, 0, 0, (VSGrid->GetCols() - 1), 1L);
VSGrid->PutCell(flexcpFontBold, 0, 0, (VSGrid->GetRows() - 1), 0, 1L);
}

BEGIN_MESSAGE_MAP(CViewComplain, CDialog)
//{{AFX_MSG_MAP(CViewComplain)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

176
// THIS FILE IS A RECORD SOURCE OF CUSTOMER_COMPLAIN
// RecCustomerComplain.h : Interface of the CRecCustomerComplain class

class CRecCustomerComplain : public CRecordset


{
DECLARE_DYNAMIC(CRecCustomerComplain)

public:
CRecCustomerComplain(CDatabase* pDatabase = NULL);

// Variable of the CUSTOMER_COMPLAIN Data Source Fields


//{{AFX_FIELD (CUSTOMER_COMPLAIN)
CString m_COMPLAIN_ID;
CString m_PRODUCT_ID;
CString m_CUSTOMER_ID;
CString m_COMPLAIN_DESCRIPTION;
int m_COMPLAIN_COMPLEXITY;
CTime m_COMPLAINTEGER_DATE;
CTime m_DATE_OF_ACTION;
CString m_TECHNICIAN;
CString m_ACTION_TAKEN;
double m_PAYMENT_RECIEVED;
//}}AFX_FIELD

public:
//{{AFX_VIRTUAL (CRecCustomerComplain)
virtual CString GetDefaultConnect();
virtual CString GetDefaultSQL();
virtual void DoFieldExchange(CFieldExchange* pFX);
//}}AFX_VIRTUAL
};

// RecCustomerComplain.cpp : implementation file

#include"StdAfx.h"
#include"RecCustomerComplain.h"

IMPLEMENT_DYNAMIC(CRecCustomerComplain, CRecordset)

CRecCustomerComplain :: CRecCustomerComplain(CDatabase* pdb) : CRecordset(pdb)


{
//{{AFX_FIELD_INIT (CUSTOMER_COMPLAIN)
m_COMPLAIN_ID = _T("");
m_PRODUCT_ID = _T("");
m_CUSTOMER_ID = _T("");
m_COMPLAIN_DESCRIPTION = _T("");
m_COMPLAIN_COMPLEXITY = 1;
m_TECHNICIAN = _T("");
m_ACTION_TAKEN = _T("");
m_PAYMENT_RECIEVED = 0.0;

177
//}}AFX_FIELD_INIT

m_nFields = 10;
m_nDefaultType = snapshot;
}

// Default Connection String


CString CRecCustomerComplain :: GetDefaultConnect()
{
return _T("ODBC;DSN=CRM;UID=CRM;PWD=CRM;");
}

// Used to Default SQL for Recordset


CString CRecCustomerComplain :: GetDefaultSQL()
{
return _T("[CRM].[CUSTOMER_COMPLAIN]");
}

// To Exchange Data (IN BOTH DIRECTION) Between the Record Source Data Members
// and the Corresponding Record on the Data Variable.
void CRecCustomerComplain :: DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);

//{{AFX_FIELD_MAP (CUSTOMER_COMPLAIN)
RFX_Text(pFX, _T("[COMPLAIN_ID]"), m_COMPLAIN_ID);
RFX_Text(pFX, _T("[PRODUCT_ID]"), m_PRODUCT_ID);
RFX_Text(pFX, _T("[CUSTOMER_ID]"), m_CUSTOMER_ID);
RFX_Text(pFX, _T("[COMPLAIN_DESCRIPTION]"), m_COMPLAIN_DESCRIPTION);
RFX_Int(pFX, _T("[COMPLAIN_COMPLEXITY]"), m_COMPLAIN_COMPLEXITY);
RFX_Date(pFX, _T("[COMPLAINTEGER_DATE]"), m_COMPLAINTEGER_DATE);
RFX_Date(pFX, _T("[DATE_OF_ACTION]"), m_DATE_OF_ACTION);
RFX_Text(pFX, _T("[TECHNICIAN]"), m_TECHNICIAN);
RFX_Text(pFX, _T("[ACTION_TAKEN]"), m_ACTION_TAKEN);
RFX_Double(pFX, _T("[PAYMENT_RECIEVED]"), m_PAYMENT_RECIEVED);
//}}AFX_FIELD_MAP
}

178
// THIS FILE IS USED FOR ADD NEW ORDER
// AddNewOrder.h : Interface of the CAddNewOrder

//{{AFX_INCLUDES()
#include "vsflexgrid.h"
//}}AFX_INCLUDES

class CAddNewOrder : public CDialog


{
public:
enum { IDD = IDD_ADDNEWORDER };
CDatabase db;
CString strSQL;
int MaxDiscount, MinDiscount, MaxStock;
COleVariant vtDefault;

//{{AFX_DATA (CAddNewOrder)
CString strBillNo;
CString strProductID;
CString strCustomerID;
CString strCustomerName;
CString strSalesmanID;
CString strSalesmanName;
double fGrandTotal;
CTime tBillDate;
CVSFlexGrid Grid;
//}}AFX_DATA

public:
CAddNewOrder(CWnd* pParent = NULL);
void InitiatVariables();
POINT MouseToScreen(HWND hWnd, float X, float Y);
void AddRow();
void DeleteRow();
void GridFormat();

protected:
//{{AFX_VIRTUAL (CAddNewOrder)
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL

//{{AFX_MSG (CAddNewOrder)
virtual BOOL OnInitDialog();
afx_msg void OnRefresh();
virtual void OnOK();
virtual void OnCancel();
afx_msg void OnSelchangeSalesmanID();
afx_msg void OnSelchangeCustomerID();
//}}AFX_MSG

179
//{{AFX_EVENTSINK_MAP (CAddNewOrder)
afx_msg void OnMouseDownGrid(short Button, short Shift, float X, float Y);
afx_msg void OnAfterEditGrid(long Row, long Col);
//}}AFX_EVENTSINK_MAP

DECLARE_EVENTSINK_MAP()

DECLARE_MESSAGE_MAP()
};

// AddNewOrder.cpp : Iplementation of the CAddNewOrder class

#include"StdAfx.h"
#include"AddNewOrder.h"
#include"RecCustomerBill.h"
#include"RecCustomerMaster.h"
#include"RecSalesmanMaster.h"
#include"RecProductMaster.h"
#include"RecProductDiscount.h"
#include"RecProductInventory.h"

CAddNewOrder :: CAddNewOrder(CWnd* pParent) : CDialog(CAddNewOrder::IDD, pParent)


{
InitiatVariables();
}

// Initialization of the IDD_ADDNEWORDER DialogBox Variables


void CAddNewOrder :: InitiatVariables()
{
vtDefault = new COleVariant(0L, VT_ERROR);

//{{AFX_DATA_INIT(CAddNewOrder)
strCustomerID = _T("");
strCustomerName = _T("");
strSalesmanID = _T("");
strSalesmanName = _T("");
tBillDate = CTime::GetCurrentTime();
fGrandTotal = 0.0;
//}}AFX_DATA_INIT

// Initialization of the BILLNO EditBox with Unique ID


CRecCustomerBill CBRec(&db);
CString strFile = _T("CUSTOMER_BILL");
CString strField = _T("BILL_NO");

// Read MAX_ID of the SALESMAN_MASTER Data Source.


strBillNo = "CB" + Max_ID(CBRec, strFile, strField);
CBRec.Close();
}

180
void CAddNewOrder :: DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP (CAddNewOrder)
DDX_Text(pDX, IDC_BILLNO, strBillNo);
DDX_CBString(pDX, IDC_CUSTOMERID, strCustomerID);
DDX_Text(pDX, IDC_CUSTOMERNAME, strCustomerName);
DDX_CBString(pDX, IDC_SALESMANID, strSalesmanID);
DDX_Text(pDX, IDC_SALESMANNAME, strSalesmanName);
DDX_DateTimeCtrl(pDX, IDC_BILLDATE, tBillDate);
DDX_Control(pDX, IDC_ORDERGRID, Grid);
DDX_Text(pDX, IDC_GRANDTOTAL, fGrandTotal);
//}}AFX_DATA_MAP
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CAddNewOrder :: OnInitDialog()
{
CDialog::OnInitDialog();
CComboBox cmbCustomerID, cmbSalesmanID;
cmbCustomerID.Attach (GetDlgItem(IDC_CUSTOMERID)->m_hWnd);
cmbSalesmanID.Attach (GetDlgItem(IDC_SALESMANID)->m_hWnd);
cmbCustomerID.ResetContent();
cmbSalesmanID.ResetContent();
CRecCustomerMaster CMRec(&db);
CRecSalesmanMaster SMRec(&db);
TRY
{
// Populate CUSTOMER_ID From CUSTOMER_MASTER Record Sourec
strSQL = _T("SELECT * FROM CUSTOMER_MASTER ORDER BY TO_NUMBER(SUBSTR(CUSTOMER_ID,
3))");
CMRec.Open(CRecordset::snapshot, strSQL);
for(CMRec.MoveFirst(); !CMRec.IsEOF(); CMRec.MoveNext())
cmbCustomerID.AddString (_T(CMRec.m_CUSTOMER_ID));
cmbCustomerID.Detach ();
CMRec.Close();

// Populate SALESMAN_ID From SALESMAN_MASTER Record Sourec


strSQL = _T("SELECT * FROM SALESMAN_MASTER ORDER BY TO_NUMBER(SUBSTR(SALESMAN_ID, 3))");
SMRec.Open(CRecordset::snapshot, strSQL);
for(SMRec.MoveFirst(); !SMRec.IsEOF(); SMRec.MoveNext())
cmbSalesmanID.AddString (_T(SMRec.m_SALESMAN_ID));
cmbSalesmanID.Detach ();
SMRec.Close();
}
CATCH_ALL(e)
{
// If ERRROR is Generated
CMRec.Close();
SMRec.Close();

181
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL

// Set Grid Header


Grid.SetTextMatrix(0, 0, "Seq.");
Grid.SetTextMatrix(0, 1, "Product ID");
Grid.SetTextMatrix(0, 2, "Product Name");
Grid.SetTextMatrix(0, 3, "Quantity.");
Grid.SetTextMatrix(0, 4, "MRP");
Grid.SetTextMatrix(0, 5, "Discount");
Grid.SetTextMatrix(0, 6, "Total");

// Set Grid Property


Grid.SetCell(flexcpFontBold, _variant_t(0), _variant_t(0), _variant_t(0), _variant_t(6), _variant_t(1));
Grid.AutoSize(0, _variant_t(6), vtDefault, _variant_t(200));
Grid.SetAllowUserResizing(1L);
return TRUE;
}

// Click REFRESH Button Then It is Clear the Dialog Box


void CAddNewOrder :: OnRefresh()
{
InitiatVariables();
UpdateData(FALSE);
Grid.SetRows(1L);
}

// Click SAVE Button Save a Record in Record Source


void CAddNewOrder :: OnOK()
{
int Row;
if(UpdateData(TRUE))
{
CRecCustomerBill CBRec(&db);
CRecProductInventory PIRec(&db);
TRY
{
db.BeginTrans();

// ADD Record in CUSTOMER_BILL Record Source


CBRec.Open(CRecordset::snapshot);
CBRec.AddNew();
CBRec.m_BILL_NO = strBillNo;
CBRec.m_BILL_DATE = tBillDate;
CBRec.m_SALESMAN_ID = strSalesmanID;
CBRec.m_CUSTOMER_ID = strCustomerID;
CBRec.m_TOTAL = fGrandTotal;
CBRec.Update();
CBRec.Close();

182
// UPDATE Information in PRODUCT_INVENTORY Record Source
for(Row = 1; Row <= (Grid.GetRows()-1); Row++)
{
PIRec.m_strFilter = "PRODUCT_ID = '" + strProductID + "'";
PIRec.Open(CRecordset::snapshot);
PIRec.Edit();

int nStock = 0;
sscanf(Grid.GetTextMatrix(Row, 3), "%d", &nStock);
PIRec.m_PRODUCT_STOCK = PIRec.m_PRODUCT_STOCK - nStock;
PIRec.Update();
PIRec.Close();
}

db.CommitTrans();
AfxMessageBox(_T("Succesfull Save."), MB_OK | MB_ICONINFORMATION);
}
CATCH_ALL(e)
{
db.Rollback();
CBRec.Close();
PIRec.Close();
AfxMessageBox(_T("Unable to Save Information."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL
}

// REFREAS the DialogBox


OnRefresh();
}

// Click CANCEL Button Then It is Called to Close the Interface


void CAddNewOrder :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

// READ Currentaly Selected SALESMAN From Record Source


void CAddNewOrder :: OnSelchangeSalesmanID()
{
GetDlgItemText(IDC_SALESMANID, strSalesmanID);
CRecSalesmanMaster SMRec(&db);
SMRec.m_strFilter = "SALESMAN_ID = '" + strSalesmanID + "'";
TRY
{
SMRec.Open(CRecordset::snapshot);
strSalesmanName = _T(SMRec.m_SALESMAN_NAME);
SMRec.Close();
UpdateData(FALSE);
GetDlgItem(IDC_ORDERGRID)->SetFocus();

183
}
CATCH_ALL(e)
{
SMRec.Close();
AfxMessageBox(_T("Unable to Open Record Source. Please try again."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL
}

// READ Currentaly Selected CUSTOMER From Record Source


void CAddNewOrder :: OnSelchangeCustomerID()
{
GetDlgItemText(IDC_CUSTOMERID, strCustomerID);
CRecCustomerMaster CMRec(&db);
CMRec.m_strFilter = "CUSTOMER_ID = '" + strCustomerID + "'";
TRY
{
CMRec.Open(CRecordset::snapshot);
strCustomerName = _T(CMRec.m_CUSTOMER_NAME);
CMRec.Close();
UpdateData(FALSE);
GetDlgItem(IDC_SALESMANID)->SetFocus();
}
CATCH_ALL(e)
{
CMRec.Close();
AfxMessageBox(_T("Unable to Open Record Source. Please try again."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL
}

// Click RIGHT MOUSE Button Then Display Popup Menu and Select Option
void CAddNewOrder :: OnMouseDownGrid(short Button, short Shift, float X, float Y)
{
if (Button != 2)
return;

CWnd* wndGrid = GetDlgItem(IDC_ORDERGRID);


POINT ptScreen = MouseToScreen(wndGrid->m_hWnd, X, Y);

// Build Menu
CMenu MyMenu;
MyMenu.CreatePopupMenu();
LPTSTR arrItems[] = { "Add New", "Delete", "Save", "Refresh", NULL };
for (int i = 0; arrItems[i]; i++)
MyMenu.AppendMenu(0, 1000 + i, arrItems[i]);

// Show Popup Menu


UINT flags = TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD;
int option = MyMenu.TrackPopupMenu(flags, ptScreen.x, ptScreen.y, this);
MyMenu.DestroyMenu();

184
if (option > 0)
{
switch(option)
{
case 1000:
AddRow();
break;
case 1001:
DeleteRow();
break;
case 1002:
OnOK();
break;
case 1003:
OnRefresh();
break;
}
}
}

// AFTER Edit Grid Cell Then Call This Function


void CAddNewOrder :: OnAfterEditGrid(long Row, long Col)
{
if(Col == 1)
{
CString strMRP;
CRecProductMaster PMRec(&db);
CRecProductDiscount PDRec(&db);
CRecProductInventory PIRec(&db);
TRY
{
strProductID = Grid.GetTextMatrix(Row, Col);

// Find Product Detail(s)


PMRec.m_strFilter = "PRODUCT_ID = '" + strProductID + "'";
PMRec.Open(CRecordset::snapshot);
if(!PMRec.IsEOF())
{
Grid.SetTextMatrix(Row, 2, _T(PMRec.m_PRODUCT_NAME));
PMRec.Close();

// Find MRP of Product Item


PDRec.m_strFilter = "PRODUCT_ID = '" + strProductID + "'";
PDRec.Open(CRecordset::snapshot);
strMRP.Format(_T("%d"), PDRec.m_PRODUCT_MRP);
Grid.SetTextMatrix(Row, 3, _T(""));
Grid.SetTextMatrix(Row, 4, _T(strMRP));
Grid.SetTextMatrix(Row, 5, _T(""));
MaxDiscount = PDRec.m_PRODUCT_MAX_DISCOUNT;
MinDiscount = PDRec.m_PRODUCT_MIN_DISCOUNT;
PDRec.Close();

185
// Find Maximum Number of Items
PIRec.m_strFilter = "PRODUCT_ID = '" + strProductID + "'";
PIRec.Open(CRecordset::snapshot);
MaxStock = PIRec.m_PRODUCT_STOCK;
PIRec.Close();

Grid.Select(Row, 3, _variant_t(Row), _variant_t(3));


}
else
{
PMRec.Close();
AfxMessageBox(_T("Product not found. Please try again."), MB_OK |
MB_ICONINFORMATION);
Grid.Select(Row, 1, _variant_t(Row), _variant_t(1));
}
}
CATCH_ALL(e)
{
PMRec.Close();
AfxMessageBox(_T("Product not open Record Sourec. Please try again."), MB_OK |
MB_ICONERROR);
}
END_CATCH_ALL
}
// Check Maximum Number of QUANTITY
else if(Col == 3)
{
float fQty;
sscanf(Grid.GetTextMatrix(Row, 3), "%f", &fQty);
if(fQty > MaxStock)
{
AfxMessageBox(_T("Quantity is More than Stock. Please try again."), MB_OK |
MB_ICONEXCLAMATION);
Grid.SetTextMatrix(Row, 3, _T(""));
Grid.Select(Row, Col, vtDefault, vtDefault);
}
}
// CALCULATE Price AND Grand Total of Ordered Product
if(Col == 3 || Col == 5)
{
CString strGrandTotal, strTotal;
float fPrice;
float fQty, fMRP, fDiscount, fTotal;
int RW;

if(Grid.GetTextMatrix(Row, 3) == "")
fQty = 0;
else
sscanf(Grid.GetTextMatrix(Row, 3), "%f", &fQty);

186
if(Grid.GetTextMatrix(Row, 5) == "")
fDiscount = 0;
else
sscanf(Grid.GetTextMatrix(Row, 5), "%f", &fDiscount);

if(fDiscount > MaxDiscount)


{
AfxMessageBox(_T("Invalid Discount. Please enter Valid Discount."), MB_OK |
MB_ICONINFORMATION);
fDiscount = 0;
Grid.SetTextMatrix(Row, 5, _T(""));
}

// READ MRP, Discount and Total From Grid


sscanf(Grid.GetTextMatrix(Row, 4), "%f", &fMRP);
fDiscount = (1 - (fDiscount / 100));
fTotal = fQty * (fMRP * fDiscount);
strTotal.Format(_T("%f"), fTotal);
Grid.SetTextMatrix(Row, 6, _T(strTotal));

// CALCULATE Grand Total


fGrandTotal = 0.0;
for(RW = 1; RW <= (Grid.GetRows()-1); RW++)
{
sscanf(Grid.GetTextMatrix(Row, 6), "%f", &fPrice);
fGrandTotal += fPrice;
}
strGrandTotal.Format(_T("%f"), fGrandTotal);
SetDlgItemText(IDC_GRANDTOTAL, strGrandTotal);
}
//COleVariant vtDefault(0L, VT_ERROR);
Grid.AutoSize(0, _variant_t(6), vtDefault, _variant_t(200));
}

// ADD New Row From Grid


void CAddNewOrder :: AddRow()
{
Grid.SetRows(Grid.GetRows() + 1);
GridFormat();
Grid.Select((Grid.GetRows()-1), 1, _variant_t(Grid.GetRows()-1), _variant_t(1));
}

// DELETE Selected Row From Grid


void CAddNewOrder :: DeleteRow()
{
if(Grid.GetRows()>1 && Grid.GetRowSel()!=0)
{
Grid.RemoveItem(_variant_t(Grid.GetRowSel()));
GridFormat();
}
}

187
// Convert MOUSE Coordinate to Screen Coordinate
POINT CAddNewOrder :: MouseToScreen(HWND hWnd, float X, float Y)
{
// Get Screen Resolution
static POINT logPix = {0,0};
if (logPix.x == 0)
{
HDC hdc = ::GetDC(NULL);
logPix.x = GetDeviceCaps(hdc, LOGPIXELSX);
logPix.y = GetDeviceCaps(hdc, LOGPIXELSY);
::ReleaseDC(NULL, hdc);
}

// Convert CLIENT TWIPS to Client Pixels


POINT pt;
pt.x = MulDiv(logPix.x, (int)X, 1440);
pt.y = MulDiv(logPix.y, (int)Y, 1440);

// Convert CLIENT PIXELS to Screen Pixels


::ClientToScreen(hWnd, &pt);
return pt;
}

// Set GRID Property


void CAddNewOrder :: GridFormat()
{
int nRow;
CString strRow;
for(nRow = 1; nRow <= (Grid.GetRows()-1); nRow++)
{
//sprintf(strRow, "%l", nRow);
strRow.Format(_T("%d"), nRow);
Grid.SetTextMatrix(nRow, 0, _T(strRow));
}
Grid.SetCell(flexcpFontBold, _variant_t(0), _variant_t(0), _variant_t(Grid.GetRows()-1), _variant_t(0),
_variant_t(1));
}

BEGIN_EVENTSINK_MAP(CAddNewOrder, CDialog)
//{{AFX_EVENTSINK_MAP(CAddNewOrder)
ON_EVENT(CAddNewOrder, IDC_ORDERGRID, -605 /* MouseDown */, OnMouseDownGrid, VTS_I2
VTS_I2 VTS_R4 VTS_R4)
ON_EVENT(CAddNewOrder, IDC_ORDERGRID, 24 /* AfterEdit */, OnAfterEditGrid, VTS_I4 VTS_I4)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

BEGIN_MESSAGE_MAP(CAddNewOrder, CDialog)
//{{AFX_MSG_MAP(CAddNewOrder)
ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
ON_CBN_SELCHANGE(IDC_SALESMANID, OnSelchangeSalesmanID)

188
ON_CBN_SELCHANGE(IDC_CUSTOMERID, OnSelchangeCustomerID)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

189
THIS FILE IS A RECORD SOURCE OF CUSTOMER_BILL
// RecCustomerBill.h : Interface of the CRecCustomerBill class

class CRecCustomerBill : public CRecordset


{
DECLARE_DYNAMIC(CRecCustomerBill)

public:
// Variable of the CUSTOMER_BILL Data Source Fields
//{{AFX_FIELD (CUSTOMER_BILL)
CString m_BILL_NO;
CString m_CUSTOMER_ID;
CString m_SALESMAN_ID;
CTime m_BILL_DATE;
double m_TOTAL;
//}}AFX_FIELD

public:
CRecCustomerBill(CDatabase* pDatabase = NULL);

//{{AFX_VIRTUAL(CRecCustomerBill)
virtual CString GetDefaultConnect();
virtual CString GetDefaultSQL();
virtual void DoFieldExchange(CFieldExchange* pFX);
//}}AFX_VIRTUAL
};

// RecCustomerBill.cpp : Implementation of the CRecCustomerBill class

#include"StdAfx.h"
#include"RecCustomerBill.h"

IMPLEMENT_DYNAMIC(CRecCustomerBill, CRecordset)

CRecCustomerBill :: CRecCustomerBill(CDatabase* pdb) : CRecordset(pdb)


{
//{{AFX_FIELD_INIT (CRecCustomerBill)
m_BILL_NO = _T("");
m_CUSTOMER_ID = _T("");
m_SALESMAN_ID = _T("");
m_TOTAL = 0.0;
//}}AFX_FIELD_INIT

m_nFields = 5;
m_nDefaultType = snapshot;
}

190
// Default Connection String
CString CRecCustomerBill::GetDefaultConnect()
{
return _T("ODBC;DSN=crm;UID=crm;PWD=crm;");
}

// Used to Default SQL for Recordset


CString CRecCustomerBill::GetDefaultSQL()
{
return _T("[CRM].[CUSTOMER_BILL]");
}

// To Exchange Data (IN BOTH DIRECTION) Between the Record Source Data Members
// and the Corresponding Record on the Data Variable.
void CRecCustomerBill::DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);

//{{AFX_FIELD_MAP(CRecCustomerBill)
RFX_Text(pFX, _T("[BILL_NO]"), m_BILL_NO);
RFX_Date(pFX, _T("[BILL_DATE]"), m_BILL_DATE);
RFX_Text(pFX, _T("[CUSTOMER_ID]"), m_CUSTOMER_ID);
RFX_Text(pFX, _T("[SALESMAN_ID]"), m_SALESMAN_ID);
RFX_Double(pFX, _T("[TOTAL]"), m_TOTAL);
//}}AFX_FIELD_MAP
}

191
THIS FILE IS USED FOR ADD NEW SALESMAN
// AddNewSalesman.h : Interface of the CAddNewSalesman class

class CAddNewSalesman : public CDialog


{
public:
enum { IDD = IDD_ADDNEWSALESMAN };
CDatabase db;
CString strSQL;

//{{AFX_DATA (CAddNewSalesman)
CString strSalesmanID;
CString strSalesmanName;
CString strAddress;
CString strCity;
CString strPhone;
CString strMobile;
CString strEMail;
CTime tDateOfBirth;
CTime tDateOfJoin;
CString strManager;
CString strDesignation;
//}}AFX_DATA

public:
CAddNewSalesman(CWnd* pParent = NULL);
void InitiatVariables();

protected:
//{{AFX_VIRTUAL (CAddNewSalesman)
virtual void OnOK();
virtual void OnCancel();
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL

//{{AFX_MSG (CAddNewSalesman)
afx_msg void OnRefersh();
afx_msg void OnSelchangeDesignation();
afx_msg void OnDropdownDesignation();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// AddNewSalesman.cpp : Implementation of the CAddNewSalesman class

#include"StdAfx.h"
#include"AddNewSalesman.h"
#include"RecSalesmanMaster.h"

192
// Constructer of the CAddNewSalesman to Initiate the Variables
CAddNewSalesman :: CAddNewSalesman(CWnd* pParent) : CDialog(CAddNewSalesman::IDD, pParent)
{
InitiatVariables();
}

// Initialization of the IDD_ADDNEWPRODUCT DialogBox Variables


void CAddNewSalesman :: InitiatVariables()
{
//{{AFX_DATA_INIT (CAddNewSalesman)
strSalesmanID = _T("");
strSalesmanName = _T("");
strAddress = _T("");
strCity = _T("");
strPhone = _T("");
strMobile = _T("");
strEMail = _T("");
tDateOfBirth = CTime::GetCurrentTime();
tDateOfJoin = CTime::GetCurrentTime();
strManager = _T("");
strDesignation = _T("");
//}}AFX_DATA_INIT

// Initialization of the SALESMANID EditBox with Unique ID


CRecSalesmanMaster SMRec(&db);
CString strFile = _T("SALESMAN_MASTER");
CString strField = _T("SALESMAN_ID");

// Read MAX_ID of the SALESMAN_MASTER Data Source.


strSalesmanID = "SM" + Max_ID(SMRec, strFile, strField);
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CAddNewSalesman :: OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}

// Initiate the CONTROLS of the IDD_ADDNEWSALESMAN DialogBox


void CAddNewSalesman :: DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAddNewSalesman)
DDX_Text(pDX, IDC_SALESMANID, strSalesmanID);
DDX_Text(pDX, IDC_SALESMANNAME, strSalesmanName);
DDV_MaxChars(pDX, strSalesmanName, 25);
DDX_Text(pDX, IDC_ADDRESS, strAddress);
DDV_MaxChars(pDX, strAddress, 30);

193
DDX_Text(pDX, IDC_CITY, strCity);
DDV_MaxChars(pDX, strCity, 15);
DDX_Text(pDX, IDC_PHONE, strPhone);
DDV_MaxChars(pDX, strPhone, 12);
DDX_Text(pDX, IDC_MOBILE, strMobile);
DDV_MaxChars(pDX, strMobile, 12);
DDX_DateTimeCtrl(pDX, IDC_DATEOFBIRTH, tDateOfBirth);
DDX_DateTimeCtrl(pDX, IDC_DATEOFJOIN, tDateOfJoin);
DDX_Text(pDX, IDC_EMAIL, strEMail);
DDV_MaxChars(pDX, strEMail, 40);
DDX_Text(pDX, IDC_MANAGER, strManager);
DDV_MaxChars(pDX, strManager, 20);
//}}AFX_DATA_MAP
}

// Click SAVE Button Save a Record in Record Source


void CAddNewSalesman::OnOK()
{
BOOL bTest = TRUE;

// Call This Member to Retrive Data From a DialogBox Using DoDataExchange()


if(UpdateData(TRUE))
{
if(strSalesmanName.IsEmpty())
{
AfxMessageBox(_T("Please Enter Salesman Name."), MB_OK |
MB_ICONINFORMATION);
GetDlgItem(IDC_SALESMANNAME)->SetFocus();
bTest = FALSE;
}
else if(strAddress.IsEmpty())
{
AfxMessageBox(_T("Please Enter Salesman Address."), MB_OK |
MB_ICONINFORMATION);
GetDlgItem(IDC_ADDRESS)->SetFocus();
bTest = FALSE;
}
else if(strCity.IsEmpty())
{
AfxMessageBox(_T("Please Enter Salesman City."), MB_OK |
MB_ICONINFORMATION);
GetDlgItem(IDC_CITY)->SetFocus();
bTest = FALSE;
}
else if(strManager.IsEmpty())
{
AfxMessageBox(_T("Please Enter Manager Name."), MB_OK |
MB_ICONINFORMATION);
GetDlgItem(IDC_MANAGER)->SetFocus();
bTest = FALSE;
}

194
else if(strDesignation.IsEmpty())
{
AfxMessageBox(_T("Please Enter Designation."), MB_OK |
MB_ICONINFORMATION);
GetDlgItem(IDC_DESIGNATION)->SetFocus();
bTest = FALSE;
}
if(bTest)
{
// ERROR Handling in VISUAL C++
TRY
{
db.BeginTrans();
CRecSalesmanMaster SMRec(&db);
if(SMRec.Open(CRecordset::snapshot))
{
SMRec.AddNew();

// Add Value in SALESMAN_MASTER Record Source.


SMRec.m_SALESMAN_ID = strSalesmanID;
SMRec.m_SALESMAN_NAME = strSalesmanName;
SMRec.m_SALESMAN_ADDRESS = strAddress;
SMRec.m_SALESMAN_CITY = strCity;
SMRec.m_SALESMAN_PHONE = strPhone;
SMRec.m_SALESMAN_MOBILE = strMobile;
SMRec.m_SALESMAN_EMAIL = strEMail;
SMRec.m_SALESMAN_DOB = tDateOfBirth;
SMRec.m_SALESMAN_DATE_OF_JOIN = tDateOfJoin;
SMRec.m_SALESMAN_MANAGER = strManager;
SMRec.m_SALESMAN_DESIGNATION = strDesignation;
if(SMRec.Update())
{
SMRec.Close();
AfxMessageBox(_T("Succesfull Save."), MB_OK |
MB_ICONINFORMATION);
db.CommitTrans();

// Get Next Salesman ID And Initiate Variables


InitiatVariables();
GetDlgItem(IDC_SALESMANNAME)->SetFocus();
UpdateData(FALSE);
}
}
}
CATCH_ALL(e)
{
// IF Any Error Process ROLLBACK
db.Rollback();
AfxMessageBox(_T("Unable to Save Information."), MB_OK |
MB_ICONERROR);
}

195
END_CATCH_ALL
}
}
}

// Click CANCEL Button Then It is Called to Close the Interface


void CAddNewSalesman::OnCancel()
{
db.Close();
CDialog::OnCancel();
}

// Click REFRESH Button Then It is Clear the Dialog Box


void CAddNewSalesman::OnRefersh()
{
InitiatVariables();

// Call This Member to Initialize Data in a DialogBox Using DoDataExchange()


CWnd::UpdateData(FALSE);

// Setfocus on the Edit Control


GetDlgItem(IDC_SALESMANNAME)->SetFocus();
}

// READ Currentaly Selected DESIGNATION From Record Source


void CAddNewSalesman::OnSelchangeDesignation()
{
CComboBox *wndDeDesignation;
wndDeDesignation = (CComboBox*)GetDlgItem(IDC_DESIGNATION);
wndDeDesignation->GetLBText(wndDeDesignation->GetCurSel(), strDesignation);
}

// ADD STRING in the ComboBox When ComboBox DropDown


void CAddNewSalesman::OnDropdownDesignation()
{
CComboBox cmbDesignation;
cmbDesignation.Attach (GetDlgItem (IDC_DESIGNATION)->m_hWnd);
cmbDesignation.ResetContent();
cmbDesignation.AddString (_T ("One"));
cmbDesignation.AddString (_T ("Two"));
cmbDesignation.AddString (_T ("Three"));
cmbDesignation.Detach ();
}

BEGIN_MESSAGE_MAP(CAddNewSalesman, CDialog)
//{{AFX_MSG_MAP (CAddNewSalesman)
ON_BN_CLICKED(IDC_REFERSH, OnRefersh)
ON_CBN_SELCHANGE(IDC_DESIGNATION, OnSelchangeDesignation)
ON_CBN_DROPDOWN(IDC_DESIGNATION, OnDropdownDesignation)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

196
// THIS FILE IS USED FOR UPDATE SALESMAN INFORMATION
// UpdateSalesman.h : Interface of the CUpdateSalesman class

//{{AFX_INCLUDES()
#include "vsflexgrid.h"
//}}AFX_INCLUDES

class CUpdateSalesman : public CDialog


{
public:
enum { IDD = IDD_UPDATESALESMAN };
CDatabase db;
CString strSQL;

//{{AFX_DATA(CUpdateSalesman)
CDateTimeCtrl m_Date;
CVSFlexGrid m_Grid;
//}}AFX_DATA

public:
CUpdateSalesman(CWnd* pParent = NULL); // standard constructor
void PopulateValue();

protected:
BOOL m_bDropped;
CString strLastValue;

protected:
//{{AFX_VIRTUAL (CUpdateSalesman)
virtual void OnOK();
virtual void OnCancel();
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

//{{AFX_MSG (CUpdateSalesman)
afx_msg void OnDelete();

afx_msg void OnClickGrid();


afx_msg void OnAfterEditGrid(long Row, long Col);
afx_msg void OnBeforeEditGrid(long Row, long Col, BOOL FAR* Cancel);

afx_msg void OnBeforeScrollGrid(long OldTopRow, long OldLeftCol, long NewTopRow, long


NewLeftCol, BOOL FAR* Cancel);
afx_msg void OnBeforeUserResizeGrid(long Row, long Col, BOOL FAR* Cancel);
afx_msg void OnStartEditGrid(long Row, long Col, BOOL FAR* Cancel);

afx_msg void OnKillfocusDate(NMHDR* pNMHDR, LRESULT* pResult);


afx_msg void OnCloseupDate(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnDropdownDate(NMHDR* pNMHDR, LRESULT* pResult);

197
//}}AFX_MSG

DECLARE_EVENTSINK_MAP()

DECLARE_MESSAGE_MAP()
};

// UpdateSalesman.cpp : Iplementation of the CUpdateSalesman class

#include"StdAfx.h"
#include"UpdateSalesman.h"
#include"RecSalesmanMaster.h"

#define DATE_FORMAT "%m/%d/%y"

// Constructer of the CUpdateSalesman to Initiate the Variables


CUpdateSalesman :: CUpdateSalesman(CWnd* pParent) : CDialog(CUpdateSalesman::IDD, pParent)
{
}

// DISPLAY Salesman Information on GRID


void CUpdateSalesman :: PopulateValue()
{
CRecSalesmanMaster SMRec(&db);
TRY
{
strSQL = _T("SELECT * FROM SALESMAN_MASTER ORDER BY TO_NUMBER(SUBSTR(SALESMAN_ID, 3))");
SMRec.Open(CRecordset::snapshot, strSQL);
if(!SMRec.IsEOF())
{
int nSeq = 1;
CString strSeq;
m_Grid.SetRows(1L);
for(SMRec.MoveFirst(); !SMRec.IsEOF(); SMRec.MoveNext(), nSeq++)
{
strSeq.Format(_T("%d"), nSeq);
m_Grid.SetRows(m_Grid.GetRows()+1);

// Display the Values in the Grid


m_Grid.SetTextMatrix(nSeq, 0, _T(strSeq));
m_Grid.SetTextMatrix(nSeq, 1, _T(SMRec.m_SALESMAN_ID));
m_Grid.SetTextMatrix(nSeq, 2, _T(SMRec.m_SALESMAN_NAME));
m_Grid.SetTextMatrix(nSeq, 3, _T(SMRec.m_SALESMAN_ADDRESS));
m_Grid.SetTextMatrix(nSeq, 4, _T(SMRec.m_SALESMAN_CITY));
m_Grid.SetTextMatrix(nSeq, 5, _T(SMRec.m_SALESMAN_PHONE));
m_Grid.SetTextMatrix(nSeq, 6, _T(SMRec.m_SALESMAN_MOBILE));
m_Grid.SetTextMatrix(nSeq, 7, _T(SMRec.m_SALESMAN_EMAIL));
m_Grid.SetTextMatrix(nSeq, 8,
_T(SMRec.m_SALESMAN_DOB.Format(DATE_FORMAT)));
m_Grid.SetTextMatrix(nSeq, 9,
_T(SMRec.m_SALESMAN_DATE_OF_JOIN.Format(DATE_FORMAT)));

198
m_Grid.SetTextMatrix(nSeq, 10, _T(SMRec.m_SALESMAN_DESIGNATION));
m_Grid.SetTextMatrix(nSeq, 11, _T(SMRec.m_SALESMAN_MANAGER));
m_Grid.SetTextMatrix(nSeq, 12, _T("No"));
}
SMRec.Close();

}
else
{
AfxMessageBox(_T("Record(s) Not Present."), MB_OK | MB_ICONINFORMATION);
SMRec.Close();
db.Close();
CDialog::OnCancel();
}
}
CATCH_ALL(e)
{
SMRec.Close();
AfxMessageBox(_T("Unable to Open Record Source"), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL
}

// Initiate the CONTROLS of the IDD_UPDATESALESMAN DialogBox


void CUpdateSalesman :: DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CUpdateSalesman)
DDX_Control(pDX, IDC_DATE, m_Date);
DDX_Control(pDX, IDC_SALESMANGRID, m_Grid);
//}}AFX_DATA_MAP
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CUpdateSalesman :: OnInitDialog()
{
CDialog::OnInitDialog();

// DISPLAY Salesman Information on GRID


PopulateValue();

// Set Grid Property


m_Grid.SetAllowUserResizing(flexResizeBoth);
m_Grid.SetExplorerBar(flexExSortShowAndMove );
m_Grid.AutoSize(0, _variant_t(m_Grid.GetCols() -1 ), vtMissing, _variant_t(200));
m_Grid.SetColDataType(8, flexDTDate);
m_Grid.SetColDataType(9, flexDTDate);
m_Grid.SetColComboList(8, "Hesham|Rafi");
m_Grid.SetColComboList(9, "Hesham|Rafi");
m_Grid.SetColComboList(10, "Executive|Sr.Executive|Sales Manager|Technician|Manager");

199
return TRUE;
}

// Press DELETE Button Then Delete Selected Rows


void CUpdateSalesman :: OnDelete()
{
int nRow, nCount;
CString strCount;
for(nRow = 1, nCount = 0; nRow <= m_Grid.GetSelectedRows(); nRow++)
nCount++;
if(nCount > 0)
{
strCount.Format(_T("Do you want to Delete %d Record?"), nCount);
if(AfxMessageBox(_T(strCount), MB_YESNO | MB_ICONQUESTION) == IDYES)
{
CRecSalesmanMaster SMRec(&db);
for(nRow = (m_Grid.GetRows()-1); nRow >= 1 ; nRow--)
{
TRY
{
if(m_Grid.GetIsSelected(nRow))
{
db.BeginTrans();
SMRec.m_strFilter = "SALESMAN_ID = '" +
m_Grid.GetTextMatrix(nRow, 1) + "'";
SMRec.Open(CRecordset::snapshot);
SMRec.Delete();
SMRec.Close();
db.CommitTrans();
m_Grid.RemoveItem(_variant_t(nRow));
}
}
CATCH_ALL(e)
{
SMRec.Close();
db.Rollback();
AfxMessageBox(_T("Unable to Delete Record."), MB_OK |
MB_ICONERROR);
}
END_CATCH_ALL
}
AfxMessageBox(_T("Record Sussesfull Deleted."), MB_OK |
MB_ICONINFORMATION);
}
}
}

200
// Press SAVE Button Then Save Modified Records
void CUpdateSalesman :: OnOK()
{
int nRow;
BOOL bFlag = FALSE;
CRecSalesmanMaster SMRec(&db);
for(nRow = 1; nRow <= (m_Grid.GetRows()-1); nRow++)
{
TRY
{
if(m_Grid.GetTextMatrix(nRow, 12) == "Yes")
{
if(!bFlag)
{
if(AfxMessageBox(_T("Do you want to Update Record"), MB_YESNO
| MB_ICONQUESTION) == IDYES)
bFlag = TRUE;
else
break;
}
db.BeginTrans();
SMRec.m_strFilter = "SALESMAN_ID = '" + m_Grid.GetTextMatrix(nRow, 1) +
"'";
SMRec.Open(CRecordset::snapshot);
SMRec.Edit();
SMRec.m_SALESMAN_NAME = m_Grid.GetTextMatrix(nRow, 2);
SMRec.m_SALESMAN_ADDRESS = m_Grid.GetTextMatrix(nRow, 3);
SMRec.m_SALESMAN_CITY = m_Grid.GetTextMatrix(nRow, 4);
SMRec.m_SALESMAN_PHONE = m_Grid.GetTextMatrix(nRow, 5);
SMRec.m_SALESMAN_MOBILE = m_Grid.GetTextMatrix(nRow, 6);
SMRec.m_SALESMAN_EMAIL = m_Grid.GetTextMatrix(nRow, 7);
SMRec.m_SALESMAN_DOB = m_Grid.GetTextMatrix(nRow, 8);
SMRec.m_SALESMAN_DATE_OF_JOIN = m_Grid.GetTextMatrix(nRow, 9);
SMRec.m_SALESMAN_DESIGNATION = m_Grid.GetTextMatrix(nRow, 10);
SMRec.m_SALESMAN_MANAGER = m_Grid.GetTextMatrix(nRow,
11);
m_Grid.SetTextMatrix(nRow, 12, _T("No"));
SMRec.Update();
SMRec.Close();
db.CommitTrans();
}
}
CATCH_ALL(e)
{
SMRec.Close();
db.Rollback();
AfxMessageBox(_T("Unable to Update Information."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL
}
if(bFlag)

201
AfxMessageBox(_T("Salesman Information Update."), MB_OK | MB_ICONINFORMATION);
else
PopulateValue();
}

// Click CANCEL Button Then It is Called to Close the Interface


void CUpdateSalesman :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

// STOP Scrolling While Editing Dates


void CUpdateSalesman :: OnBeforeScrollGrid(long OldTopRow, long OldLeftCol, long NewTopRow, long
NewLeftCol, BOOL FAR* Cancel)
{
if (m_Date.IsWindowVisible())
*Cancel = TRUE;
}

// STOP Scrolling While Editing Dates


void CUpdateSalesman :: OnBeforeUserResizeGrid(long Row, long Col, BOOL FAR* Cancel)
{
if (m_Date.IsWindowVisible())
*Cancel = TRUE;
}

void CUpdateSalesman :: OnStartEditGrid(long Row, long Col, BOOL FAR* Cancel)


{
// if this is a date column, edit it with the date picker control
if (m_Grid.GetColDataType(Col) == flexDTDate)
{
// we'll handle the editing ourselves
*Cancel = TRUE;

// position date picker control over cell


int x = MulDiv(0, (int)m_Grid.GetCellLeft(), 1440);
int y = MulDiv(0, (int)m_Grid.GetCellTop(), 1440);
int nWidth = MulDiv(0, (int)m_Grid.GetCellWidth(), 1440);
int nHeight = MulDiv(0, (int)m_Grid.GetCellHeight(), 1440);

m_Date.SetParent((CWnd*)&m_Grid);
m_Date.MoveWindow(x, y, nWidth, nHeight, FALSE);

// initialize date on control


COleVariant v = m_Grid.GetText();
v.ChangeType(VT_DATE);
COleDateTime Date;
Date.m_dt = v.date;
m_Date.SetTime(Date);

202
// show and activate date picker control
m_Date.ShowWindow(SW_SHOW);
m_Date.SetFocus();

// make it drop down the calendar


m_bDropped = FALSE;
m_Date.SendMessage(WM_KEYDOWN, VK_F4, 0);
}
}

void CUpdateSalesman :: OnKillfocusDate(NMHDR* pNMHDR, LRESULT* pResult)


{
if (!m_bDropped)
{
// Copy Date Back Into GRID
COleDateTime Date;
m_Date.GetTime(Date);
m_Grid.SetTextMatrix(m_Grid.GetRow(), m_Grid.GetCol(), Date.Format(DATE_FORMAT));
m_Date.ShowWindow(SW_HIDE);
}

// DONE
*pResult = 0;
}

void CUpdateSalesman :: OnCloseupDate(NMHDR* pNMHDR, LRESULT* pResult)


{
m_bDropped = FALSE;
*pResult = 0;
}

void CUpdateSalesman :: OnDropdownDate(NMHDR* pNMHDR, LRESULT* pResult)


{
m_bDropped = TRUE;
*pResult = 0;
}

// Set the GRID Editable Property on CLICK


void CUpdateSalesman :: OnClickGrid()
{
if(m_Grid.GetCol() < 2 || m_Grid.GetRow() == 0)
m_Grid.SetEditable(flexEDNone);
else
{
m_Grid.SetEditable(flexEDKbdMouse);
}
}

// READ Value AFTER Edit a Grid CELL


void CUpdateSalesman :: OnAfterEditGrid(long Row, long Col)
{

203
if(strLastValue != m_Grid.GetTextMatrix(Row, Col))
m_Grid.SetTextMatrix(Row, 12, _T("Yes"));
m_Grid.AutoSize(Col, _variant_t(Col), vtMissing, _variant_t(200));
}

// READ Value BEFOR Edit a Grid CELL


void CUpdateSalesman :: OnBeforeEditGrid(long Row, long Col, BOOL FAR* Cancel)
{
strLastValue = m_Grid.GetTextMatrix(Row, Col);
}

BEGIN_MESSAGE_MAP(CUpdateSalesman, CDialog)
//{{AFX_MSG_MAP (CUpdateSalesman)
ON_COMMAND(IDC_DELETE, OnDelete)
ON_NOTIFY(NM_KILLFOCUS, IDC_DATE, OnKillfocusDate)
ON_NOTIFY(DTN_CLOSEUP, IDC_DATE, OnCloseupDate)
ON_NOTIFY(DTN_DROPDOWN, IDC_DATE, OnDropdownDate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_EVENTSINK_MAP(CUpdateSalesman, CDialog)
//{{AFX_EVENTSINK_MAP (CUpdateSalesman)
ON_EVENT(CUpdateSalesman, IDC_SALESMANGRID, -600 /* Click */, OnClickGrid, VTS_NONE)
ON_EVENT(CUpdateSalesman, IDC_SALESMANGRID, 24 /* AfterEdit */, OnAfterEditGrid, VTS_I4
VTS_I4)
ON_EVENT(CUpdateSalesman, IDC_SALESMANGRID, 21 /* BeforeEdit */, OnBeforeEditGrid, VTS_I4
VTS_I4 VTS_PBOOL)

ON_EVENT(CUpdateSalesman, IDC_SALESMANGRID, 10 /* BeforeScroll */, OnBeforeScrollGrid,


VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL)
ON_EVENT(CUpdateSalesman, IDC_SALESMANGRID, 17 /* BeforeUserResize */,
OnBeforeUserResizeGrid, VTS_I4 VTS_I4 VTS_PBOOL)
ON_EVENT(CUpdateSalesman, IDC_SALESMANGRID, 22 /* StartEdit */, OnStartEditGrid, VTS_I4
VTS_I4 VTS_PBOOL)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

204
// THIS FILE IS USED FOR VIEW ALL SALESMAN INFORMATION
// ViewSalesman.h : Interface of the CViewSalesman class

#define IDC_GRID 100

class CViewSalesman : public CDialog


{
public:
enum { IDD = IDD_VIEW };
CWnd wndGrid;
CDatabase db;
CString strSQL;
IVSFlexGridPtr VSGrid;

public:
CViewSalesman(CWnd* pParent = NULL);
void GridFormating();

protected:
//{{AFX_VIRTUAL (CViewSalesman)
virtual afx_msg void OnCancel();
virtual BOOL OnInitDialog();
//}}AFX_VIRTUAL

//{{AFX_MAP (CViewSalesman)
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MAP

DECLARE_MESSAGE_MAP()
};

// ViewSalesman.cpp : Implementation of the CViewSalesman class

#include"StdAfx.h"
#include"ViewSalesman.h"
#include"RecSalesmanMaster.h"

// Construction of the ViewSalesman class


CViewSalesman :: CViewSalesman(CWnd* pParent) : CDialog(CViewSalesman::IDD, pParent)
{
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CViewSalesman :: OnInitDialog()
{
CDialog::OnInitDialog();

RECT rc;
GetClientRect(&rc);
InflateRect(&rc, 0, -50);

205
rc.top = 0;

// This Member Function to Create an ActiveX Control


wndGrid.CreateControl("VSFlexGrid8.VSFlexGridL.1", NULL, WS_VISIBLE, rc, this, IDC_GRID);

// Retrieve a Pointer to an Unknown OLE Control


VSGrid = wndGrid.GetControlUnknown();
VSGrid->put_Rows(1);
SetWindowText(_T("Salesman Information"));

CRecSalesmanMaster SMRec(&db);
TRY
{
strSQL = _T("SELECT * FROM SALESMAN_MASTER ORDER BY TO_NUMBER(SUBSTR(SALESMAN_ID, 3))");
SMRec.Open(CRecordset::snapshot, strSQL);
if(!SMRec.IsEOF())
{
int nRW = 0;
CString strRW, strDOB, strDOJ;

// Display the HEADER on the Grid


VSGrid->put_Cols(SMRec.m_nResultCols + 1);
VSGrid->PutTextMatrix(nRW, 0, _T("Seq."));
VSGrid->PutTextMatrix(nRW, 1, _T("Salesman ID"));
VSGrid->PutTextMatrix(nRW, 2, _T("Salesman Name"));
VSGrid->PutTextMatrix(nRW, 3, _T("Address"));
VSGrid->PutTextMatrix(nRW, 4, _T("City"));
VSGrid->PutTextMatrix(nRW, 5, _T("Phone"));
VSGrid->PutTextMatrix(nRW, 6, _T("Mobile"));
VSGrid->PutTextMatrix(nRW, 7, _T("E_Mail"));
VSGrid->PutTextMatrix(nRW, 8, _T("Date of Birth"));
VSGrid->PutTextMatrix(nRW, 9, _T("Date of join"));
VSGrid->PutTextMatrix(nRW, 10, _T("Manager"));
VSGrid->PutTextMatrix(nRW, 11, _T("Designation"));
for(SMRec.MoveFirst(); !SMRec.IsEOF(); SMRec.MoveNext())
{
nRW++;
strRW.Format(_T("%d"), nRW);
VSGrid->put_Rows(VSGrid->GetRows() + 1);

// Display the Values in the Grid


VSGrid->PutTextMatrix(nRW, 0, _bstr_t(strRW));
VSGrid->PutTextMatrix(nRW, 1, _bstr_t(SMRec.m_SALESMAN_ID));
VSGrid->PutTextMatrix(nRW, 2, _bstr_t(SMRec.m_SALESMAN_NAME));
VSGrid->PutTextMatrix(nRW, 3, _bstr_t(SMRec.m_SALESMAN_ADDRESS));
VSGrid->PutTextMatrix(nRW, 4, _bstr_t(SMRec.m_SALESMAN_CITY));
VSGrid->PutTextMatrix(nRW, 5, _bstr_t(SMRec.m_SALESMAN_PHONE));
VSGrid->PutTextMatrix(nRW, 6, _bstr_t(SMRec.m_SALESMAN_MOBILE));
VSGrid->PutTextMatrix(nRW, 7, _bstr_t(SMRec.m_SALESMAN_EMAIL));
strDOB = SMRec.m_SALESMAN_DOB.Format(_T("%d/%m/%Y"));
VSGrid->PutTextMatrix(nRW, 8, _bstr_t(strDOB));

206
strDOJ = SMRec.m_SALESMAN_DATE_OF_JOIN.Format(_T("%d/%m/%Y"));
VSGrid->PutTextMatrix(nRW, 9, _bstr_t(strDOJ));
VSGrid->PutTextMatrix(nRW, 10,
_bstr_t(SMRec.m_SALESMAN_MANAGER));
VSGrid->PutTextMatrix(nRW, 11,
_bstr_t(SMRec.m_SALESMAN_DESIGNATION));
}
}
else
{
AfxMessageBox(_T("Record(s) are not present."), MB_OK |
MB_ICONINFORMATION);
SMRec.Close();
CDialog::OnCancel();
}
}
CATCH_ALL(e)
{
SMRec.Close();
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL

// Set the PROPERTY of the Grid


VSGrid->ExplorerBar = (ExplorerBarSettings)(flexExMoveRows | flexExSortShowAndMove);
VSGrid->AllowUserResizing = (AllowUserResizeSettings)(flexResizeColumns);
VSGrid->AllowUserFreezing = (AllowUserFreezeSettings) (flexFreezeBoth);
VSGrid->BackColorFrozen = RGB(200, 200, 255);
VSGrid->AutoSize(0, (VSGrid->GetCols() -1 ), vtMissing, 300 );
VSGrid->AutoSearch = (AutoSearchSettings) (flexSearchFromTop);
VSGrid->SelectionMode = flexSelectionListBox;
VSGrid->put_BackColorSel(RGB(153, 172, 145));
GridFormating();
return TRUE;
}

// Click CANCEL Button Then Close the Interface.


void CViewSalesman :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

// This Fuction is Called When DialogBox is Resized.


void CViewSalesman :: OnSize(UINT nType, int cx, int cy)
{
if (!m_hWnd || !wndGrid.m_hWnd) return;
RECT rc;
GetClientRect(&rc);

// Resize the GRID Control

207
InflateRect(&rc, 0, - 50);
rc.top = 0;
CWnd *wndGrid = GetDlgItem(IDC_GRID);
wndGrid->MoveWindow(&rc);

// Move the BUTTON Control


CWnd *wndButton = GetDlgItem(IDCANCEL);
rc.left = rc.right - 100;
rc.top = rc.bottom + 10;
rc.right = rc.right - 12;
rc.bottom = rc.bottom + 40;
wndButton->MoveWindow(&rc);
GridFormating();
}

// This Fuction is Used to Format Grid


void CViewSalesman :: GridFormating()
{
VSGrid->PutCell(flexcpFontBold, 0, 0, 0, (VSGrid->GetCols() - 1), 1L);
VSGrid->PutCell(flexcpFontBold, 0, 0, (VSGrid->GetRows() - 1), 0, 1L);
}

BEGIN_MESSAGE_MAP(CViewSalesman, CDialog)
//{{AFX_MSG_MAP(CViewSalesman)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

208
// THIS FILE IS A RECORD SOURCE OF THE SALESMAN_MASTER
// RecSalesmanMaster.h : Interface of the CRecSalesmanMaster class

class CRecSalesmanMaster : public CRecordset


{
DECLARE_DYNAMIC(CRecSalesmanMaster)

public:
// Variable of the SALESMAN_MASTER Data Source Fields
//{{AFX_FIELD (SALESMAN_MASTER)
CString m_SALESMAN_ID;
CString m_SALESMAN_NAME;
CString m_SALESMAN_ADDRESS;
CString m_SALESMAN_CITY;
CString m_SALESMAN_PHONE;
CString m_SALESMAN_MOBILE;
CString m_SALESMAN_EMAIL;
CTime m_SALESMAN_DOB;
CTime m_SALESMAN_DATE_OF_JOIN;
CString m_SALESMAN_MANAGER;
CString m_SALESMAN_DESIGNATION;
//}}AFX_FIELD

public:
CRecSalesmanMaster(CDatabase* pDatabase = NULL);

//{{AFX_VIRTUAL (CRecSalesmanMaster)
virtual CString GetDefaultConnect();
virtual CString GetDefaultSQL();
virtual void DoFieldExchange(CFieldExchange* pFX);
//}}AFX_VIRTUAL
};

// RecSalesmanMaster.cpp : implementation of the CRecSalesmanMaster class

#include"StdAfx.h"
#include"RecSalesmanMaster.h"

IMPLEMENT_DYNAMIC(CRecSalesmanMaster, CRecordset)

CRecSalesmanMaster :: CRecSalesmanMaster(CDatabase* pdb) : CRecordset(pdb)


{
//{{AFX_FIELD_INIT (SALESMAN_MASTER)
m_SALESMAN_ID = _T("");
m_SALESMAN_NAME = _T("");
m_SALESMAN_ADDRESS = _T("");
m_SALESMAN_CITY = _T("");
m_SALESMAN_PHONE = _T("");
m_SALESMAN_MOBILE = _T("");
m_SALESMAN_EMAIL = _T("");
m_SALESMAN_DESIGNATION = _T("");
m_SALESMAN_MANAGER = _T("");

209
//}}AFX_FIELD_INIT

m_nFields = 11;
m_nDefaultType = snapshot;
}

// Default Connection String


CString CRecSalesmanMaster::GetDefaultConnect()
{
return _T("ODBC;DSN=crm;UID=crm;PWD=crm;");
}

// Used to Default SQL for Recordset


CString CRecSalesmanMaster::GetDefaultSQL()
{
return _T("[CRM].[SALESMAN_MASTER]");
}

// To Exchange Data (IN BOTH DIRECTION) Between the Record Source Data Members
// and the Corresponding Record on the Data Variable.
void CRecSalesmanMaster::DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);

//{{AFX_FIELD_MAP(SALESMAN_MASTER)
RFX_Text(pFX, _T("[SALESMAN_ID]"), m_SALESMAN_ID);
RFX_Text(pFX, _T("[SALESMAN_NAME]"), m_SALESMAN_NAME);
RFX_Text(pFX, _T("[SALESMAN_ADDRESS]"), m_SALESMAN_ADDRESS);
RFX_Text(pFX, _T("[SALESMAN_CITY]"), m_SALESMAN_CITY);
RFX_Text(pFX, _T("[SALESMAN_PHONE]"), m_SALESMAN_PHONE);
RFX_Text(pFX, _T("[SALESMAN_MOBILE]"), m_SALESMAN_MOBILE);
RFX_Text(pFX, _T("[SALESMAN_EMAIL]"), m_SALESMAN_EMAIL);
RFX_Date(pFX, _T("[SALESMAN_DOB]"), m_SALESMAN_DOB);
RFX_Text(pFX, _T("[SALESMAN_DESIGNATION]"), m_SALESMAN_DESIGNATION);
RFX_Date(pFX, _T("[SALESMAN_DATE_OF_JOIN]"), m_SALESMAN_DATE_OF_JOIN);
RFX_Text(pFX, _T("[SALESMAN_MANAGER]"), m_SALESMAN_MANAGER);
//}}AFX_FIELD_MAP
}

210
// THIS FILE IS USED FOR QUOTA ASSIGNMENT
// QuotaManager.h : Interface of the CQuotaManager class

class CQuotaManager : public CDialog


{
public:
enum { IDD = IDD_QUOTA };
CDatabase db;
CString strSQL;

//{{AFX_DATA( CQuotaManager)
CString strProductID;
CString strProductName;
CString strSalesmanID;
CString strSalesmanName;
UINT nPresentQuota;
int nQuota;
//}}AFX_DATA

public:
CQuotaManager(CWnd* pParent = NULL);
void InitiatVariables();
void FindQuota();

protected:
//{{AFX_VIRTUAL(CQuotaManager)
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

//{{AFX_MSG(CQuotaManager)
virtual BOOL OnInitDialog();
virtual void OnOK();
virtual void OnCancel();
afx_msg void OnRefresh();
afx_msg void OnSelchangeProductid();
afx_msg void OnSelchangeSalesmanid();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// QuotaManager.cpp : Implementation of the CQuotaManager class

#include"StdAfx.h"
#include"QuotaManager.h"
#include"RecSalesmanQuota.h"
#include"RecProductMaster.h"
#include"RecSalesmanMaster.h"

211
// Constructer of the CQuotaManager to Initiate the Variables
CQuotaManager :: CQuotaManager(CWnd* pParent) : CDialog(CQuotaManager::IDD, pParent)
{
InitiatVariables();
}

// Initialization of the IDD_QUOTA DialogBox Variables


void CQuotaManager :: InitiatVariables()
{
//{{AFX_DATA_INIT (CQuotaManager)
strProductID = _T("");
strProductName = _T("");
strSalesmanID = _T("");
strSalesmanName = _T("");
nPresentQuota = 0;
nQuota = 0;
//}}AFX_DATA_INIT
}

// Initiate the CONTROLS of the IDD_QUOTA DialogBox


void CQuotaManager :: DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CQuotaManager)
DDX_CBString(pDX, IDC_PRODUCTID, strProductID);
DDX_Text(pDX, IDC_PRODUCTNAME, strProductName);
DDX_CBString(pDX, IDC_SALESMANID, strSalesmanID);
DDX_Text(pDX, IDC_SALESMANNAME, strSalesmanName);
DDX_Text(pDX, IDC_PRESENTQUOTA, nPresentQuota);
DDX_Text(pDX, IDC_QUOTA, nQuota);
DDV_MinMaxUInt(pDX, nQuota, 1, 9999);
//}}AFX_DATA_MAP
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CQuotaManager::OnInitDialog()
{
CDialog::OnInitDialog();
CComboBox cmbSalesmanID, cmbProductID;
cmbSalesmanID.Attach (GetDlgItem(IDC_SALESMANID)->m_hWnd);
cmbProductID.Attach (GetDlgItem(IDC_PRODUCTID)->m_hWnd);
cmbSalesmanID.ResetContent();
cmbProductID.ResetContent();
CRecSalesmanMaster SMRec(&db);
CRecProductMaster PMRec(&db);
TRY
{
// Populate SALESMAN_ID From SALESMAN_MASTER Record Sourec
strSQL = _T("SELECT * FROM SALESMAN_MASTER ORDER BY
TO_NUMBER(SUBSTR(SALESMAN_ID, 3))");

212
SMRec.Open(CRecordset::snapshot, strSQL);
for(SMRec.MoveFirst(); !SMRec.IsEOF(); SMRec.MoveNext())
cmbSalesmanID.AddString (_T(SMRec.m_SALESMAN_ID));
cmbSalesmanID.Detach ();
SMRec.Close();

// Populate PRODUCT_ID From PRODUCT_MASTER Record Sourec


strSQL = _T("SELECT * FROM PRODUCT_MASTER ORDER BY TO_NUMBER(SUBSTR(PRODUCT_ID, 3))");
PMRec.Open(CRecordset::snapshot, strSQL);
for(PMRec.MoveFirst(); !PMRec.IsEOF(); PMRec.MoveNext())
cmbProductID.AddString (_T(PMRec.m_PRODUCT_ID));
cmbProductID.Detach ();
PMRec.Close();

}
CATCH_ALL(e)
{
SMRec.Close();
PMRec.Close();
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL
return TRUE;
}

// Click SAVE Button Save a Record in Record Source


void CQuotaManager::OnOK()
{
if(UpdateData(TRUE))
{
CRecSalesmanQuota SQRec(&db);
db.BeginTrans();
TRY
{
SQRec.m_strFilter = "SALESMAN_ID = '" + strSalesmanID + "' AND PRODUCT_ID = '" +
strProductID + "'";
SQRec.Open();
if(SQRec.IsEOF())
{
SQRec.AddNew();
SQRec.m_SALESMAN_ID = strSalesmanID;
SQRec.m_PRODUCT_ID = strProductID;
}
else
{
SQRec.Edit();
}
SQRec.m_SALESMAN_QUOTA = nQuota;
SQRec.Update();
SQRec.Close();
db.CommitTrans();

213
AfxMessageBox(_T("Succesfull Save."), MB_OK | MB_ICONINFORMATION);
InitiatVariables();
UpdateData(FALSE);
}
CATCH_ALL(e)
{
SQRec.Close();
db.Rollback();
AfxMessageBox(_T("Unable to Add Information"), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL
}
}

// Click CANCEL Button Then It is Called to Close the Interface


void CQuotaManager::OnCancel()
{
db.Close();
CDialog::OnCancel();
}

// Click REFRESH Button Then It is Clear the Dialog Box


void CQuotaManager::OnRefresh()
{
InitiatVariables();
UpdateData(FALSE);
GetDlgItem(IDC_SALESMANID)->SetFocus();
}

// READ Currentaly Selected PRODUCT From ComboBox


void CQuotaManager :: OnSelchangeProductid()
{
GetDlgItemText(IDC_PRODUCTID, strProductID);
CRecProductMaster PMRec(&db);
PMRec.m_strFilter = "PRODUCT_ID = '" + strProductID + "'";
TRY
{
PMRec.Open(CRecordset::snapshot);
strProductName = _T(PMRec.m_PRODUCT_NAME);
PMRec.Close();
UpdateData(FALSE);
FindQuota();
}
CATCH_ALL(e)
{
PMRec.Close();
AfxMessageBox(_T("Unable to Open Record Source. Please try again."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL
}

214
// READ Currentaly Selected SALESMAN From ComboBox
void CQuotaManager :: OnSelchangeSalesmanid()
{
GetDlgItemText(IDC_SALESMANID, strSalesmanID);
CRecSalesmanMaster SMRec(&db);
SMRec.m_strFilter = "SALESMAN_ID = '" + strSalesmanID + "'";
TRY
{
SMRec.Open(CRecordset::snapshot);
strSalesmanName = _T(SMRec.m_SALESMAN_NAME);
SMRec.Close();
UpdateData(FALSE);
GetDlgItem(IDC_PRODUCTID)->SetFocus();
}
CATCH_ALL(e)
{
SMRec.Close();
AfxMessageBox(_T("Unable to Open Record Source. Please try again."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL
}

// FIND QUOTA Currentaly Selected Product AND Salesman


void CQuotaManager :: FindQuota()
{
if(strSalesmanID == "")
{
AfxMessageBox(_T("Please Select Salesman."), MB_OK | MB_ICONINFORMATION);
GetDlgItem(IDC_SALESMANID)->SetFocus();
}
else if(strProductID == "")
{
AfxMessageBox(_T("Please Select Product."), MB_OK | MB_ICONINFORMATION);
GetDlgItem(IDC_PRODUCTID)->SetFocus();
}
else
{
CRecSalesmanQuota SQRec(&db);
SQRec.m_strFilter = "SALESMAN_ID = '" + strSalesmanID + "' AND PRODUCT_ID = '" +
strProductID + "'";
SQRec.Open(CRecordset::snapshot);
if(SQRec.IsEOF())
{
AfxMessageBox(_T("Quota not Defined."), MB_OK | MB_ICONINFORMATION);
nPresentQuota = 0;

}
else
nPresentQuota = SQRec.m_SALESMAN_QUOTA;
SQRec.Close();
GetDlgItem(IDC_QUOTA)->SetFocus();

215
UpdateData(FALSE);
}
}

BEGIN_MESSAGE_MAP(CQuotaManager, CDialog)
//{{AFX_MSG_MAP(CQuotaManager)
ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
ON_CBN_SELCHANGE(IDC_PRODUCTID, OnSelchangeProductid)
ON_CBN_SELCHANGE(IDC_SALESMANID, OnSelchangeSalesmanid)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

216
// THIS FILE IS A RECORD SOURCE OF THE SALESMAN_QUOTA_ASSIGN
// RecSalesmanQuota.h : Interface of the CRecSalesmanQuota class

class CRecSalesmanQuota : public CRecordset


{
DECLARE_DYNAMIC(CRecSalesmanQuota)

public:
// Variable of the SALESMAN_MASTER Data Source Fields
//{{AFX_FIELD (SALESMAN_QUOTA_ASSIGNED)
CString m_SALESMAN_ID;
CString m_PRODUCT_ID;
int m_SALESMAN_QUOTA;
//}}AFX_FIELD

public:
CRecSalesmanQuota(CDatabase* pDatabase = NULL);

//{{AFX_VIRTUAL(CRecCustomerBill)
virtual CString GetDefaultConnect();
virtual CString GetDefaultSQL();
virtual void DoFieldExchange(CFieldExchange* pFX);
//}}AFX_VIRTUAL
};

// RecSalesmanQuota.cpp : implementation of the CRecSalesmanQuota class

#include"StdAfx.h"
#include"RecSalesmanQuota.h"

IMPLEMENT_DYNAMIC(CRecSalesmanQuota, CRecordset)

CRecSalesmanQuota :: CRecSalesmanQuota(CDatabase* pdb) : CRecordset(pdb)


{
//{{AFX_FIELD_INIT (SALESMAN_QUOTA_ASSIGNED)
m_SALESMAN_ID = _T("");
m_PRODUCT_ID = _T("");
m_SALESMAN_QUOTA = 0;
//}}AFX_FIELD_INIT

m_nFields = 3;
m_nDefaultType = snapshot;
}

// Default Connection String


CString CRecSalesmanQuota::GetDefaultConnect()
{
return _T("ODBC;DSN=crm;UID=crm;PWD=crm;");
}

217
// Used to Default SQL for Recordset
CString CRecSalesmanQuota::GetDefaultSQL()
{
return _T("[CRM].[SALESMAN_QUOTA_ASSIGNED]");
}

// To Exchange Data (IN BOTH DIRECTION) Between the Record Source Data Members
// and the Corresponding Record on the Data Variable.
void CRecSalesmanQuota::DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);

//{{AFX_FIELD_MAP(SALESMAN_QUOTA_ASSIGNED)
RFX_Text(pFX, _T("[SALESMAN_ID]"), m_SALESMAN_ID);
RFX_Text(pFX, _T("[PRODUCT_ID]"), m_PRODUCT_ID);
RFX_Int(pFX, _T("[SALESMAN_QUOTA]"), m_SALESMAN_QUOTA);
//}}AFX_FIELD_MAP
}

218
// THIS FILE IS USED FOR UPDATE STOCK
// UpdateStock.h : Interface of the CUpdateStock class

class CUpdateStock : public CDialog


{
public:
CDatabase db;
CString strSQL;

//{{AFX_DATA (CUpdateStock)
enum { IDD = IDD_UPDATESTOCK };
CString strProductID;
CTime tDate;
CString strDate;
UINT nLevel;
UINT nStock;
//}}AFX_DATA

public:
CUpdateStock(CWnd* pParent = NULL); // standard constructor

protected:
//{{AFX_VIRTUAL (CUpdateStock)
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

//{{AFX_MSG (CUpdateStock)
virtual BOOL OnInitDialog();
virtual void OnOK();
virtual void OnCancel();
afx_msg void OnDropdownCombo();
afx_msg void OnSelchangeCombo();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// UpdateStock.cpp : implementation file

#include"StdAfx.h"
#include"RecProductMaster.h"
#include"RecProductInventory.h"
#include"UpdateStock.h"

// Constructer of the CUpdateStock to Initiate the Variables


CUpdateStock :: CUpdateStock(CWnd* pParent) : CDialog(CUpdateStock::IDD, pParent)
{
//{{AFX_DATA_INIT(CUpdateStock)
strProductID = _T("");
tDate = CTime::GetCurrentTime();
strDate = _T("");

219
nLevel = 0;
nStock = 0;
//}}AFX_DATA_INIT
}

void CUpdateStock :: DoDataExchange(CDataExchange* pDX)


{
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP (CUpdateStock)
DDX_Text(pDX, IDC_DATE, strDate);
DDX_Text(pDX, IDC_LEVEL, nLevel);
DDX_Text(pDX, IDC_STOCK, nStock);
DDV_MinMaxUInt(pDX, nStock, 1, 9999);
//}}AFX_DATA_MAP
}

BOOL CUpdateStock::OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}

void CUpdateStock::OnOK()
{
BOOL bTest = TRUE;

// Call This Member to Retrive Data From a DialogBox Using DoDataExchange()


if(UpdateData(TRUE))
{
if(nStock<=0)
{
AfxMessageBox(_T("Please Enter Correct Stock."), MB_OK |
MB_ICONINFORMATION);
GetDlgItem(IDC_STOCK)->SetFocus();
bTest = FALSE;
}
if(bTest)
{
// ERROR Handling in VISUAL C++
TRY
{
db.BeginTrans();
CRecProductInventory PIRec(&db);
PIRec.m_strFilter = "PRODUCT_ID = '" + strProductID + "' ";
PIRec.Open(CRecordset::snapshot);
PIRec.Edit();

// Modify Value in PRODUCT_INVENTORY Record Source.


PIRec.m_PRODUCT_STOCK = nStock;
PIRec.m_PRODUCT_LAST_UPDATE = CTime::GetCurrentTime();

220
strDate = tDate.Format(_T("%d/%m/%Y"));
PIRec.Update();
PIRec.Close();
AfxMessageBox(_T("Record Succesfull Updated."), MB_OK |
MB_ICONINFORMATION);
db.CommitTrans();
UpdateData(FALSE);
}
CATCH_ALL(e)
{
// IF Any Error Process ROLLBACK
db.Rollback();
AfxMessageBox(_T("Unable to Modify Record Source."), MB_OK |
MB_ICONERROR);
}
END_CATCH_ALL
}
}
}

// Click CANCEL Button Then It is Called to Close the Interface


void CUpdateStock :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

// ADD PRODUCT_ID in the ComboBox When ComboBox DropDown


void CUpdateStock :: OnDropdownCombo()
{
CComboBox cmbProductID;
cmbProductID.Attach (GetDlgItem (IDC_PRODUCTID)->m_hWnd);
cmbProductID.ResetContent();
CRecProductMaster PMRec(&db);
strSQL = _T("SELECT * FROM PRODUCT_MASTER ORDER BY TO_NUMBER(SUBSTR(PRODUCT_ID,
3))");
if(PMRec.Open(CRecordset::snapshot, strSQL))
for(PMRec.MoveFirst(); !PMRec.IsEOF(); PMRec.MoveNext())
cmbProductID.AddString (_T (PMRec.m_PRODUCT_ID));
else
AfxMessageBox(_T("Unable to Open Product Master."), MB_OK | MB_ICONERROR);
PMRec.Close();
cmbProductID.Detach ();
}

// READ Currentaly Selected PRODUCT ITEM From ComboBox


void CUpdateStock :: OnSelchangeCombo()
{
CComboBox *wndProductID;
wndProductID = (CComboBox*)GetDlgItem(IDC_PRODUCTID);
wndProductID->GetLBText(wndProductID->GetCurSel(), strProductID);

221
CRecProductInventory PIRec(&db);
TRY
{
PIRec.m_strFilter = "PRODUCT_ID = '" + strProductID + "' ";
PIRec.Open(CRecordset::snapshot);
strDate = PIRec.m_PRODUCT_LAST_UPDATE.Format(_T("%d/%m/%Y"));
nLevel = PIRec.m_PRODUCT_REORDER_LEVEL;
nStock = PIRec.m_PRODUCT_STOCK;
PIRec.Close();
UpdateData(FALSE);
}
CATCH_ALL(e)
{
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK | MB_ICONERROR);
PIRec.Close();
}
END_CATCH_ALL
}

BEGIN_MESSAGE_MAP(CUpdateStock, CDialog)
//{{AFX_MSG_MAP (CUpdateStock)
ON_CBN_DROPDOWN(IDC_PRODUCTID, OnDropdownCombo)
ON_CBN_SELCHANGE(IDC_PRODUCTID, OnSelchangeCombo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

222
// THIS FILE IS USED FOR VIEW ALL STOCK INFORMATION
// ViewStock.h : Interface of the CViewStock class

#define IDC_GRID 100

class CViewStock : public CDialog


{
public:
enum { IDD = IDD_VIEW };
CWnd wndGrid;
CString strSQL;
CDatabase db;
IVSFlexGridPtr VSGrid;

public:
CViewStock(CWnd* pParent = NULL);
void GridFormating();

protected:
//{{AFX_VIRTUAL (CViewStock)
virtual afx_msg void OnCancel();
virtual BOOL OnInitDialog();
//}}AFX_VIRTUAL

//{{AFX_MAP (CViewStock)
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MAP

DECLARE_MESSAGE_MAP()
};

// ViewStock.cpp : Implementation of the CViewStock class

#include"StdAfx.h"
#include"ViewStock.h"
#include"RecProductMaster.h"
#include"RecProductInventory.h"

// Construction of the CViewStock class


CViewStock :: CViewStock(CWnd* pParent) : CDialog(CViewStock::IDD, pParent)
{
}

//This Function is Call Immediately Before the Dialog Box is Displayed


BOOL CViewStock :: OnInitDialog()
{
CDialog::OnInitDialog();

RECT rc;
GetClientRect(&rc);

223
InflateRect(&rc, 0, -50);
rc.top = 0;

// This Member Function to Create an ActiveX Control


wndGrid.CreateControl("VSFlexGrid8.VSFlexGridL.1", NULL, WS_VISIBLE, rc, this, IDC_GRID);

// Retrieve a Pointer to an Unknown OLE Control


VSGrid = wndGrid.GetControlUnknown();
VSGrid->put_Rows(1);
SetWindowText(_T("Stock Information"));

CRecProductMaster PMRec(&db);
CRecProductInventory PIRec(&db);
TRY
{
strSQL = _T("SELECT * FROM PRODUCT_INVENTORY ORDER BY
TO_NUMBER(SUBSTR(PRODUCT_ID, 3))");
PIRec.Open(CRecordset::snapshot, strSQL);
if(!PIRec.IsEOF())
{
int nRW = 0;
CString strRW, strDate;

// Display the HEADER on the Grid


VSGrid->put_Cols(PIRec.m_nResultCols + 2);
VSGrid->PutTextMatrix(nRW, 0, _T("Seq."));
VSGrid->PutTextMatrix(nRW, 1, _T("Product ID"));
VSGrid->PutTextMatrix(nRW, 2, _T("Product Name"));
VSGrid->PutTextMatrix(nRW, 3, _T("Record Level"));
VSGrid->PutTextMatrix(nRW, 4, _T("Stock"));
VSGrid->PutTextMatrix(nRW, 5, _T("Modify Date"));
for(PIRec.MoveFirst(); !PIRec.IsEOF(); PIRec.MoveNext())
{
nRW++;
strRW.Format(_T("%d"), nRW);
VSGrid->put_Rows(VSGrid->GetRows() + 1);

// Display the Values in the Grid


VSGrid->PutTextMatrix(nRW, 0, _bstr_t(strRW));
VSGrid->PutTextMatrix(nRW, 1, _bstr_t(PIRec.m_PRODUCT_ID));

// Find PRODUCT_NAME From PRODUCT_MASTER Record Source


PMRec.m_strFilter = _T("PRODUCT_ID = '" + _T(PIRec.m_PRODUCT_ID) +
"'");
PMRec.Open(CRecordset::snapshot);
VSGrid->PutTextMatrix(nRW, 2, _bstr_t(PMRec.m_PRODUCT_NAME));
PMRec.Close();

VSGrid->PutTextMatrix(nRW, 3,
_bstr_t(PIRec.m_PRODUCT_REORDER_LEVEL));
VSGrid->PutTextMatrix(nRW, 4, _bstr_t(PIRec.m_PRODUCT_STOCK));

224
strDate = PIRec.m_PRODUCT_LAST_UPDATE.Format(_T("%d/%m/%Y"));
VSGrid->PutTextMatrix(nRW, 5, _bstr_t(strDate));
}
}
else
{
AfxMessageBox(_T("Record(s) are not present."), MB_OK |
MB_ICONINFORMATION);
PIRec.Close();
CDialog::OnCancel();
}
}
CATCH_ALL(e)
{
PIRec.Close();
AfxMessageBox(_T("Unable to Open Record Source."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL

// Set the PROPERTY of the Grid


VSGrid->ExplorerBar = (ExplorerBarSettings)(flexExMoveRows | flexExSortShowAndMove);
VSGrid->AllowUserResizing = (AllowUserResizeSettings)(flexResizeColumns);
VSGrid->AllowUserFreezing = (AllowUserFreezeSettings) (flexFreezeBoth);
VSGrid->BackColorFrozen = RGB(200, 200, 255);
VSGrid->AutoSize(0, (VSGrid->GetCols() -1 ), vtMissing, 300 );
VSGrid->AutoSearch = (AutoSearchSettings) (flexSearchFromTop);
VSGrid->SelectionMode = flexSelectionListBox;
VSGrid->put_BackColorSel(RGB(153, 172, 145));
GridFormating();
return TRUE;
}

// This Fuction is Called When DialogBox is Resized.


void CViewStock :: OnSize(UINT nType, int cx, int cy)
{
if (!m_hWnd || !wndGrid.m_hWnd) return;
RECT rc;
GetClientRect(&rc);

// Resize the GRID Control


InflateRect(&rc, 0, - 50);
rc.top = 0;
CWnd *wndGrid = GetDlgItem(IDC_GRID);
wndGrid->MoveWindow(&rc);

// Move the BUTTON Control


CWnd *wndButton = GetDlgItem(IDCANCEL);
rc.left = rc.right - 100;
rc.top = rc.bottom + 10;
rc.right = rc.right - 12;
rc.bottom = rc.bottom + 40;

225
wndButton->MoveWindow(&rc);
GridFormating();
}

// This Fuction is Used to Format Grid


void CViewStock :: GridFormating()
{
VSGrid->PutCell(flexcpFontBold, 0, 0, 0, (VSGrid->GetCols() - 1), 1L);
VSGrid->PutCell(flexcpFontBold, 0, 0, (VSGrid->GetRows() - 1), 0, 1L);
}

// Click CANCEL Button Then Close the Interface.


void CViewStock :: OnCancel()
{
db.Close();
CDialog::OnCancel();
}

BEGIN_MESSAGE_MAP(CViewStock, CDialog)
//{{AFX_MSG_MAP(CViewStock)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

226
// THIS FILE IS RECORD SOURCE OF THE PRODUCT_INVENTORY
// RecProductInventory.h : Interface of the CRecProductInventory class

class CRecProductInventory : public CRecordset


{
DECLARE_DYNAMIC(CRecProductInventory)

public:
CRecProductInventory(CDatabase* pDatabase = NULL);

// Variable of the PRODUCT_INVENTORY Data Source Fields


//{{AFX_FIELD (PRODUCT_INVENTORY)
CString m_PRODUCT_ID;
int m_PRODUCT_STOCK;
int m_PRODUCT_REORDER_LEVEL;
CTime m_PRODUCT_LAST_UPDATE;
//}}AFX_FIELD

public:
//{{AFX_VIRTUAL (CRecProductInventory)
virtual CString GetDefaultConnect();
virtual CString GetDefaultSQL();
virtual void DoFieldExchange(CFieldExchange* pFX);
//}}AFX_VIRTUAL
};

// RecProductInventory.cpp : Implementation of the CRecProductInventory class

#include"StdAfx.h"
#include"RecProductInventory.h"

IMPLEMENT_DYNAMIC(CRecProductInventory, CRecordset)

CRecProductInventory :: CRecProductInventory(CDatabase* pdb) : CRecordset(pdb)


{
//{{AFX_FIELD_INIT(CRecProductInventory)
m_PRODUCT_ID = _T("");
m_PRODUCT_STOCK = 0;
m_PRODUCT_REORDER_LEVEL = 0;
m_PRODUCT_LAST_UPDATE = CTime::GetCurrentTime();
//}}AFX_FIELD_INIT

m_nFields = 4;
m_nDefaultType = snapshot;
}

// Default Connection String


CString CRecProductInventory::GetDefaultConnect()
{
return _T("ODBC;DSN=crm;UID=crm;PWD=crm;");

227
}

// Used to Default SQL for Recordset


CString CRecProductInventory::GetDefaultSQL()
{
return _T("[CRM].[PRODUCT_INVENTORY]");
}

// To Exchange Data (IN BOTH DIRECTION) Between the Record Source Data Members
// and the Corresponding Record on the Data Variable.
void CRecProductInventory::DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);

//{{AFX_FIELD_MAP(CRecProductInventory)
RFX_Text(pFX, _T("[PRODUCT_ID]"), m_PRODUCT_ID);
RFX_Int(pFX, _T("[PRODUCT_STOCK]"), m_PRODUCT_STOCK);
RFX_Int(pFX, _T("[PRODUCT_REORDER_LEVEL]"), m_PRODUCT_REORDER_LEVEL);
RFX_Date(pFX, _T("[PRODUCT_LAST_UPDATE]"), m_PRODUCT_LAST_UPDATE);
//}}AFX_FIELD_MAP
}

228
// THIS FILE IS A RECORD SOURCE OF THE PRODUCT_DISCOUNT
// RecProductDiscount.h : Interface of the CRecProductDiscount class

class CRecProductDiscount : public CRecordset


{
DECLARE_DYNAMIC(CRecProductDiscount)

public:
CRecProductDiscount(CDatabase* pDatabase = NULL);

// Variable of the PRODUCT_DISCOUNT Data Source Fields


//{{AFX_FIELD (PRODUCT_DISCOUNT)
CString m_PRODUCT_ID;
int m_PRODUCT_PURCHASE_PRICE;
int m_PRODUCT_MRP;
int m_PRODUCT_MAX_DISCOUNT;
int m_PRODUCT_MIN_DISCOUNT;
//}}AFX_FIELD

public:
//{{AFX_VIRTUAL(CRecProductDiscount)
virtual CString GetDefaultConnect();
virtual CString GetDefaultSQL();
virtual void DoFieldExchange(CFieldExchange* pFX);
//}}AFX_VIRTUAL
};

// RecProductDiscount.cpp : Implementation of the CRecProductDiscount class

#include"StdAfx.h"
#include"CRMProject.h"
#include"RecProductDiscount.h"

IMPLEMENT_DYNAMIC(CRecProductDiscount, CRecordset)

CRecProductDiscount :: CRecProductDiscount(CDatabase* pdb) : CRecordset(pdb)


{
//{{AFX_FIELD_INIT (PRODUCT_DISCOUNT)
m_PRODUCT_ID = _T("");
m_PRODUCT_PURCHASE_PRICE = 0;
m_PRODUCT_MRP = 0;
m_PRODUCT_MAX_DISCOUNT = 0;
m_PRODUCT_MIN_DISCOUNT = 0;
//}}AFX_FIELD_INIT

m_nFields = 5;
m_nDefaultType = snapshot;
}

229
// Default connection string
CString CRecProductDiscount :: GetDefaultConnect()
{
return _T("ODBC;DSN=crm;UID=crm;PWD=crm;");
}

// Used to Default SQL for Recordset


CString CRecProductDiscount :: GetDefaultSQL()
{
return _T("[CRM].[PRODUCT_DISCOUNT]");
}

// To Exchange Data (IN BOTH DIRECTION) Between the Record Source Data Members
// and the Corresponding Record on the Data Variable.
void CRecProductDiscount :: DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);

//{{AFX_FIELD_MAP (PRODUCT_DISCOUNT)
RFX_Text(pFX, _T("[PRODUCT_ID]"), m_PRODUCT_ID);
RFX_Int(pFX, _T("[PRODUCT_PURCHASE_PRICE]"), m_PRODUCT_PURCHASE_PRICE);
RFX_Int(pFX, _T("[PRODUCT_MRP]"), m_PRODUCT_MRP);
RFX_Int(pFX, _T("[PRODUCT_MAX_DISCOUNT]"), m_PRODUCT_MAX_DISCOUNT);
RFX_Int(pFX, _T("[PRODUCT_MIN_DISCOUNT]"), m_PRODUCT_MIN_DISCOUNT);
//}}AFX_FIELD_MAP
}

230
// THIS FILE DISPLAY ALL CRYSTAL RECORDS
// ReportViewer.h : Interface of the CReportViewer class

//{{AFX_INCLUDES()
#include"CrystalReportViewer10.h"
//}}AFX_INCLUDES

class CReportViewer : public CDialog


{
public:
enum { IDD = IDD_REPORTVIEW };
CString strReportTitle;
CString strReportFileName;
CCrystalReportViewer10 m_Viewer;
IApplicationPtr m_Application;
IReportPtr m_Report;
VARIANT dummy;

public:
CReportViewer(CString strFileName, CString strReportName, CWnd* pParent = NULL);
void HandleError(_com_error &e);
void ResizeViewer(CRect crRect);

protected:
//{{AFX_VIRTUAL (CReportViewer)
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL

//{{AFX_MSG (CReportViewer)
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// ReportViewer.cpp : Implementation of the CReportViewer class

#include"StdAfx.h"
#include"ReportViewer.h"

#define BUFFER_LENGTH 2000

CReportViewer :: CReportViewer(CString strFileName, CString strReportName, CWnd* pParent) :


CDialog(CReportViewer::IDD, pParent)
{
strReportFileName = strFileName;
strReportTitle = strReportName;
try

231
{
// Create instance of Application object
m_Application.CreateInstance("CrystalRuntime.Application.10");
}
catch(_com_error& e)
{
// if errors occur, handle and display errors
HandleError(e);
}
// initialise the m_Report variable to NULL
m_Report = NULL;
}

BOOL CReportViewer::OnInitDialog()
{
CDialog::OnInitDialog();

// A dummy variant
VariantInit (&dummy);
CString strPath;
char lpPath[BUFFER_LENGTH];
CRect rect;

dummy.vt = VT_EMPTY;
::GetCurrentDirectory(BUFFER_LENGTH, lpPath);
strPath.Format(_T("%s"), lpPath);

// Specify the Path to the REPORT You Want to PRINT


strPath = strPath + strReportFileName;

_bstr_t ReportPath(strPath);
_variant_t vtEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);

//Open the Report using the OpenReport method


m_Report = m_Application->OpenReport(ReportPath, dummy);

// Display Report TITLE


SetWindowText(_T(strReportTitle));

//Print the Resize Report to Window


GetClientRect(&rect);
ResizeViewer(rect);
m_Viewer.SetReportSource(m_Report);
m_Viewer.ViewReport();

return TRUE;
}

void CReportViewer :: DoDataExchange(CDataExchange* pDX)


{
CDialog::DoDataExchange(pDX);

232
//{{AFX_DATA_MAP(CReportViewer)
DDX_Control(pDX, IDC_VIEWER, m_Viewer);
//}}AFX_DATA_MAP
}

// Fired When Dialog is RESIZED


void CReportViewer :: OnSize(UINT nType, int cx, int cy)
{
// test to see if the viewer has been drawn yet or not...
if( !::IsWindow(m_Viewer.m_hWnd ) )
{
return;
}
try
{
// move and redraw the viewer's window
CRect rect(0, 0, cx, cy);
ResizeViewer(rect);
}
catch (_com_error& e)
{
HandleError(e);
}
}

// RESIZE the CRYSTAL VIEWER


void CReportViewer :: ResizeViewer(CRect crRect)
{
m_Viewer.MoveWindow(crRect);
m_Viewer.Invalidate();
m_Viewer.UpdateWindow();
}

// A Utility COM error handler...


void CReportViewer :: HandleError(_com_error &e)
{
IErrorInfo* pErrorInfo = e.ErrorInfo();
HRESULT hr = e.Error();
if (pErrorInfo)
{
BSTR bsDesc = NULL;
pErrorInfo->GetDescription( &bsDesc );
_bstr_t sDesc( bsDesc, false );
::MessageBox(0, sDesc.operator LPCTSTR(), "", MB_OK );
pErrorInfo->Release();
}
}

BEGIN_MESSAGE_MAP(CReportViewer, CDialog)
//{{AFX_MSG_MAP(CReportViewer)
ON_WM_SIZE()

233
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

234
// THIS FILE IS USED FOR DISPLAY CLOCK ON STATUS BAR
// StatusBar.h : Interface of the CMyStatusBar class

class CMyStatusBar : public CStatusBar


{
DECLARE_DYNCREATE(CMyStatusBar)

private:
CString m_strClockFormat;

public:
CMyStatusBar();
~CMyStatusBar();

void SetClockFormat(LPCTSTR strClockFormat);

//{{AFX_MSG
afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );
afx_msg void OnDestroy();
afx_msg void OnUpdateIndicatorTime(CCmdUI* pCmdUI);
afx_msg void OnTimer(UINT n);
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

// StatusBar.cpp : Implementation of the CMyStatusBar class

#include"StdAfx.h"
#include"StatusBar.h"

IMPLEMENT_DYNCREATE(CMyStatusBar, CStatusBar)

// Constructer of CMyStatusBar class


CMyStatusBar::CMyStatusBar() : CStatusBar() , m_strClockFormat("%H:%M:%S")
{
}

// Destructer of CMyStatusBar class


CMyStatusBar ::~CMyStatusBar()
{
}

int CMyStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)


{
// make sure time gets updated every second, even when idle
CStatusBar::OnCreate(lpCreateStruct);
SetTimer(ID_PANE_FOUR,1000,NULL);

235
return 0;
}

void CMyStatusBar::SetClockFormat(LPCTSTR strClockFormat)


{
m_strClockFormat = strClockFormat;
}

void CMyStatusBar ::OnTimer(UINT n)


{
CTime t;
int hh, mm, ss;
t = CTime::GetCurrentTime();
hh = t.GetHour()%12;
mm = t.GetMinute();
ss = t.GetSecond();
char str[30];
if(t.GetHour() >= 12)
sprintf(str, "Time: %0.2d:%0.2d:%0.2d PM", hh, mm, ss);
else
sprintf(str, "Time: %0.2d:%0.2d:%0.2d AM", hh, mm, ss);
SetPaneText (1, str, TRUE);

void CMyStatusBar ::OnUpdateIndicatorTime(CCmdUI* pCmdUI)


{
pCmdUI->Enable(true);
pCmdUI->SetText(CTime::GetCurrentTime().Format(m_strClockFormat));
}

void CMyStatusBar::OnDestroy()
{
KillTimer(ID_PANE_FOUR);
// ProgressDestroy();
CStatusBar::OnDestroy();
}

BEGIN_MESSAGE_MAP(CMyStatusBar, CStatusBar)
ON_WM_CREATE()
ON_WM_DESTROY()
// ON_WM_TIMER()
ON_UPDATE_COMMAND_UI(ID_PANE_FOUR, OnUpdateIndicatorTime )
END_MESSAGE_MAP()

236
// THIS FILE DISPLAY SPLASH SCREEN
// SplashWnd.h : Interface of CSplashWnd Class

class CSplashWnd : public CWnd


{
protected:
static CSplashWnd* m_pSplashWnd;
CBitmap m_bitmap;

//{{AFX_MSG(CSplashWnd)
virtual void PostNcDestroy();
afx_msg void OnPaint();
//}}AFX_MSG

public:
// Constructs a CSplashWnd object.
CSplashWnd();

virtual ~CSplashWnd();

static BOOL ShowSplashScreen(UINT uBitmapID, CWnd* pParentWnd = NULL);


void HideSplashScreen();

DECLARE_MESSAGE_MAP()
};

// SplashWnd.cpp : Implementation of the CSplashWnd class

#include "stdafx.h"
#include "SplashWnd.h"

CSplashWnd* CSplashWnd::m_pSplashWnd;

// Counstructer of CSplashWnd class


CSplashWnd::CSplashWnd()
{
}

// Destructer of CSplashWnd class


CSplashWnd::~CSplashWnd()
{
ASSERT(m_pSplashWnd == this);
m_pSplashWnd = NULL;
}

// This Member Function is Called to Create and Display the Splash Screen Window.
BOOL CSplashWnd::ShowSplashScreen(UINT uBitmapID, CWnd* pParentWnd /*= NULL*/)
{
ASSERT(uBitmapID);

237
if (m_pSplashWnd != NULL)
{
return FALSE;
}

// Allocate a new splash screen, and create the window.


m_pSplashWnd = new CSplashWnd;

if (!m_pSplashWnd->m_bitmap.LoadBitmap(uBitmapID)) {
return FALSE;
}

BITMAP bm;
m_pSplashWnd->m_bitmap.GetBitmap(&bm);
CString strWndClass = AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW));
if (!m_pSplashWnd->CreateEx(0, strWndClass, NULL, WS_POPUP | WS_VISIBLE,
0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL))
{
TRACE0("Failed to create splash screen.\n");
delete m_pSplashWnd;
return FALSE;
}

// Center the window.


m_pSplashWnd->CenterWindow();
m_pSplashWnd->UpdateWindow();

return TRUE;
}

// This Member Function is Used to Destroy the Splash Window Once the Timer Has Run Out.
void CSplashWnd::HideSplashScreen()
{
// Destroy the window, and update the mainframe.
DestroyWindow();
AfxGetMainWnd()->UpdateWindow();
}

void CSplashWnd::OnPaint()
{
CPaintDC dc(this);
CDC dcImage;
if (dcImage.CreateCompatibleDC(&dc))
{
BITMAP bm;
m_bitmap.GetBitmap(&bm);
CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
dcImage.SelectObject(pOldBitmap);
}
}

238
void CSplashWnd::PostNcDestroy()
{
delete this;
}

BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()

239
// MyValidation.h : Some Validation Functions

// THis Fuction has a TEMPLATE Which Return a MAX_NO on a Record Set


template <class T>
CString Max_ID(T & Rec, CString & sFile, CString & sField)
{
CString Max_ID;
int nId;

// Open RECORDSET of the <sFile> Table


CString strSQL = "SELECT * FROM ";
strSQL += sFile;
strSQL += " ORDER BY TO_NUMBER(SUBSTR(";
strSQL += sField;
strSQL += ",3))";
TRY
{
Rec.Open(CRecordset::snapshot, _T(strSQL));
if(Rec.GetRecordCount())
{
// MOVE on LAST Record in Recordset
Rec.MoveLast();

// Getting value of the field


Rec.GetFieldValue(sField, Max_ID);
Max_ID = Max_ID.Right(Max_ID.GetLength()-2);
}
else
{
Max_ID = _T("0");
}
// CLOSE the Recordset
Rec.Close();

// Converting CString to integer type value


sscanf(Max_ID, "%d", &nId);
nId += 1;

// Converting integer to CString type value


Max_ID.Format("%d", nId);
}
CATCH_ALL(e)
{
Rec.Close();
Max_ID = _T("");
AfxMessageBox(_T("Unable to Find Unique ID."), MB_OK | MB_ICONERROR);
}
END_CATCH_ALL
return Max_ID;
}

240
// THis Fuction Is Check Given String Has a NUMBER or Not
BOOL isNumber(CString str)
{
int i;
char ch;
for(i=0; i<=str.GetLength(); i++)
{
ch=str.GetAt(i);
if(ch=='0' || ch=='1' || ch=='2' || ch=='3' || ch=='4' ||
ch=='5' || ch=='6' || ch=='7' || ch=='8' || ch=='9')
{
}
else
return FALSE;
}
return TRUE;
}

241
// Stdafx.h : Include File for Standard System Include Files,

#include<afxwin.h> // MFC core and standard components


#include<Afxdb.h> // MFC ODBC database class
#include<afxext.h> // MFC extensions
#include<afxdisp.h> // MFC Automation classes
#include<afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#include<afxcmn.h> // MFC support for Windows Common Controls
#include <afxdb.h>

#include"Resource.h"
#include"MyValidation.h"

#import"vsFlex8l.ocx" no_namespace
#import"craxdrt.dll" no_namespace

242

You might also like