// Trade_MISView.cpp : implementation of the CTrade_MISView class
//
#include "stdafx.h"
#include "Trade_MIS.h"
#include "Trade_MISDoc.h"
#include "Trade_MISView.h"
#include "ProviderDLG.h"
#include "SearchProviderDLG.h"
#include "CustomerDLG.H"
#include "SearchCustomerDLG.h"
#include "ProductDLG.h"
#include "StockDLG.h"
#include "SearchStockDLG.h"
#include "OrderDLG.h"
#include "SearchOrderDLG.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTrade_MISView
IMPLEMENT_DYNCREATE(CTrade_MISView, CView)
BEGIN_MESSAGE_MAP(CTrade_MISView, CView)
//{{AFX_MSG_MAP(CTrade_MISView)
ON_COMMAND(IDD_MENU_ADDPROVIDER, OnAddProvider)
ON_COMMAND(IDD_MENU_ALTERPROVIDER, OnAlterProvider)
ON_COMMAND(IDD_MENU_DELPROVIDER, OnDelProvider)
ON_COMMAND(IDD_MENU_SEARCHPROVIDER, OnSearchProvider)
ON_WM_CONTEXTMENU()
ON_COMMAND(IDD_MENU_ADDCUSTOMER, OnAddCustomer)
ON_WM_SIZE()
ON_COMMAND(IDD_MENU_ALTERCUSTOMER, OnAlterCustomer)
ON_COMMAND(IDD_MENU_DELCUSTOMER, OnDelCustomer)
ON_COMMAND(IDD_MENU_SEARCHCUSTOMER, OnSearchCustomer)
ON_COMMAND(ID_MENU_ADDPRODUCT, OnAddProduct)
ON_COMMAND(ID_MENU_ALTERPRODUCT, OnuAlterProduct)
ON_COMMAND(ID_MENU_DELPRODUCT, OnDelProduct)
ON_COMMAND(ID_MENU_ADDSTOCK, OnAddStock)
ON_COMMAND(ID_MENU_ALTERSTOCK, OnAlterStock)
ON_COMMAND(ID_MENU_DELSTOCK, OnDelStock)
ON_COMMAND(ID_MENU_SEARCHSTOCK, OnSearchStock)
ON_COMMAND(ID_MENU_ADDORDER, OnAddOrder)
ON_COMMAND(ID_MENU_ALTERORDER, OnAlterOrder)
ON_COMMAND(ID_MENU_DELORDER, OnDelOrder)
ON_COMMAND(ID_MENU_SEARCHORDER, OnSearchOrder)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTrade_MISView construction/destruction
CTrade_MISView::CTrade_MISView()
{
// TODO: add construction code here
m_sCurrentList = "";
}
CTrade_MISView::~CTrade_MISView()
{
}
BOOL CTrade_MISView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTrade_MISView drawing
void CTrade_MISView::OnDraw(CDC* pDC)
{
CTrade_MISDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CTrade_MISView diagnostics
#ifdef _DEBUG
void CTrade_MISView::AssertValid() const
{
CView::AssertValid();
}
void CTrade_MISView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTrade_MISDoc* CTrade_MISView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTrade_MISDoc)));
return (CTrade_MISDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTrade_MISView message handlers
void CTrade_MISView::OnAddProvider()
{
// TODO: Add your command handler code here
CProviderDLG dlg;
dlg.m_bAppend = true;
dlg.DoModal();
}
void CTrade_MISView::RefreshProvider(_variant_t strQuery)
{
if (m_ListCtrl) m_ListCtrl.DestroyWindow();
CreateProvider( strQuery );
m_sCurrentList = _T("供应商信息列表");
m_StaticCtrl.SetWindowText(m_sCurrentList);
}
void CTrade_MISView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
// Create a Static ctrl for tip
CRect rect;
rect.left = rect.top =5;
rect.bottom = 30;
rect.right = 120;
m_StaticCtrl.Create(m_sCurrentList, WS_VISIBLE, rect, this, 1);
}
void CTrade_MISView::CreateProvider(_variant_t strQuery)
{
// Get Client Rect
CRect rect;
GetClientRect(rect);
rect.top += 30;
// Create
m_ListCtrl.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT, rect, this, 1);
// Set Color
m_ListCtrl.SetBkColor(RGB(177, 151, 240));
m_ListCtrl.SetTextColor(RGB(0,0,0));
m_ListCtrl.SetTextBkColor(RGB(177, 151, 240));
// Set EX-Style
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
// Create Header
m_ListCtrl.InsertColumn(0,_T("公司名称"), LVCFMT_LEFT, 100);
m_ListCtrl.InsertColumn(1,_T("联系人姓名"), LVCFMT_LEFT, 100);
m_ListCtrl.InsertColumn(2,_T("联系地址"), LVCFMT_LEFT, 100);
m_ListCtrl.InsertColumn(3,_T("城市名称"), LVCFMT_LEFT, 100);
m_ListCtrl.InsertColumn(4,_T("地区名称"), LVCFMT_LEFT, 100);
m_ListCtrl.InsertColumn(5,_T("邮政编码"), LVCFMT_LEFT, 100);
m_ListCtrl.InsertColumn(6,_T("联系电话"), LVCFMT_LEFT, 100);
m_ListCtrl.InsertColumn(7,_T("传真号码"), LVCFMT_LEFT, 100);
m_ListCtrl.InsertColumn(8,_T("公司主页"), LVCFMT_LEFT, 100);
m_ListCtrl.InsertColumn(9,_T("备注信息"), LVCFMT_LEFT, 100);
// Get all records
_variant_t Holder;
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
int iCount = theApp.m_pADOSet->GetRecordCount();
if ( 0==iCount ) return;
CString str;
COleDateTime time;
theApp.m_pADOSet->MoveFirst();
for(int i=0; i<iCount; i++)
{
// Get CompanyName
Holder = theApp.m_pADOSet->GetCollect("CompanyName");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
m_ListCtrl.InsertItem(i, str);
// Get ContactName
Holder = theApp.m_pADOSet->GetCollect("ContactName");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
m_ListCtrl.SetItemText(i, 1, str);
// Get Address
Holder = theApp.m_pADOSet->GetCollect("Address");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
m_ListCtrl.SetItemText(i, 2, str);
// Get City
Holder = theApp.m_pADOSet->GetCollect("City");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
m_ListCtrl.SetItemText(i, 3, str);
// Get Region
Holder = theApp.m_pADOSet->GetCollect("Region");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
m_ListCtrl.SetItemText(i, 4, str);
// Get PostalCode
Holder = theApp.m_pADOSet->GetCollect("PostalCode");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
m_ListCtrl.SetItemText(i, 5, str);
// Get Phone
Holder = theApp.m_pADOSet->GetCollect("Phone");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
m_ListCtrl.SetItemText(i, 6, str);
// Get Fax
Holder = theApp.m_pADOSet->GetCollect("Fax");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
m_ListCtrl.SetItemText(i, 7, str);
// Get HomePage
Holder = theApp.m_pADOSet->GetCollect("HomePage");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
m_ListCtrl.SetItemText(i, 8, str);
// Get Memo
Holder = theApp.m_pADOSet->GetCollect("SupplierMemo");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
m_ListCtrl.SetItemText(i, 9, str);
theApp.m_pADOSet->MoveNext();
}
}
void CTrade_MISView::OnAlterProvider()
{
// TODO: Add your command handler code here
_variant_t strQuery;
strQuery = "select * from suppliers";
if ( m_ListCtrl && m_sCurrentList!=_T("供应商信息列表") )
{
m_ListCtrl.DestroyWindow();
CreateProvider(strQuery);
m_sCurrentList = _T("供应商信息列表");
m_StaticCtrl.SetWindowText(m_sCurrentList);
return;
}
if ( !m_ListCtrl )
{
CreateProvider(strQuery);
m_sCurrentList = _T("供应商信息列表");
m_StaticCtrl.SetWindowText(m_sCurrentList);
return;
}
//Popup Alter Dialog
POSITION pos = m_ListCtrl.GetFirstSelectedItemPosition();
if (pos == NULL) AfxMessageBox(_T("没有选中的记录!"), MB_ICONEXCLAMATION);
else
{
CProviderDLG dlg;
dlg.m_bAppend = false;
CString str;
int iItem = m_ListCtrl.GetNextSelectedItem(pos);
// Get CompanyName
dlg.m_sCompa