?? searchproductinputform.cpp
字號:
// SearchProductInputForm.cpp : implementation file
//
#include "stdafx.h"
#include "Store.h"
#include "SearchProductInputForm.h"
#include "ProductInputForm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSearchProductInputForm dialog
CSearchProductInputForm::CSearchProductInputForm(CWnd* pParent /*=NULL*/)
: CDialog(CSearchProductInputForm::IDD, pParent)
{
//{{AFX_DATA_INIT(CSearchProductInputForm)
m_formDateBegin = COleDateTime::GetCurrentTime();
m_formDateEnd = COleDateTime::GetCurrentTime();
m_productInputFormID = _T("");
m_storeHouseIn = _T("");
m_produceDepartment = _T("");
m_productName = _T("");
m_dealer = _T("");
//}}AFX_DATA_INIT
}
void CSearchProductInputForm::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSearchProductInputForm)
DDX_Control(pDX, IDC_dealer, m_dealerCombo);
DDX_Control(pDX, IDC_productName, m_productNameCombo);
DDX_Control(pDX, IDC_produceDepartment, m_produceDepartmentCombo);
DDX_Control(pDX, IDC_storeHouse, m_storeHouseInCombo);
DDX_Control(pDX, IDC_productInputFormID, m_productInputFormIDCombo);
DDX_Control(pDX, IDC_LIST2, m_productList);
DDX_Control(pDX, IDC_LIST1, m_formList);
DDX_DateTimeCtrl(pDX, IDC_formDateBegin, m_formDateBegin);
DDX_DateTimeCtrl(pDX, IDC_formDateEnd, m_formDateEnd);
DDX_CBString(pDX, IDC_productInputFormID, m_productInputFormID);
DDX_CBString(pDX, IDC_storeHouse, m_storeHouseIn);
DDX_CBString(pDX, IDC_produceDepartment, m_produceDepartment);
DDX_CBString(pDX, IDC_productName, m_productName);
DDX_CBString(pDX, IDC_dealer, m_dealer);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSearchProductInputForm, CDialog)
//{{AFX_MSG_MAP(CSearchProductInputForm)
ON_BN_CLICKED(IDC_search, OnSearch)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSearchProductInputForm message handlers
void CSearchProductInputForm::OnSearch()
{
UpdateData(true);
HRESULT hTRes;
CString strSQL;
int flag=0;
m_formList.DeleteAllItems();
strSQL="select * from productInputFormView";
if(((CStoreApp*)AfxGetApp())->ToStringCTime(m_formDateBegin)!="")
{
strSQL=strSQL+" where formDate>='"+((CStoreApp*)AfxGetApp())->ToStringCTime(m_formDateBegin)+"'";
flag=1;
}
if(((CStoreApp*)AfxGetApp())->ToStringCTime(m_formDateEnd)!="")
{
strSQL=strSQL+" and formDate<'"+((CStoreApp*)AfxGetApp())->ToStringCTime(m_formDateEnd)+"'";
}
if(m_productInputFormID!=""&&flag==1)
{
strSQL=strSQL+" and productInputFormID='"+m_productInputFormID+"'";
}
else if(m_productInputFormID!=""&&flag==0)
{
strSQL=strSQL+" where productInputFormID='"+m_productInputFormID+"'";
flag=1;
}
if(m_storeHouseIn!=""&&flag==1)
{
strSQL=strSQL+" and storeHouse='"+m_storeHouseIn+"'";
}
else if(m_storeHouseIn!=""&&flag==0)
{
strSQL=strSQL+" where storeHouse='"+m_storeHouseIn+"'";
flag=1;
}
if(m_produceDepartment!=""&&flag==1)
{
strSQL=strSQL+" and produceDepartment='"+m_produceDepartment+"'";
}
else if(m_produceDepartment!=""&&flag==0)
{
strSQL=strSQL+" where produceDepartment='"+m_produceDepartment+"'";
}
if(m_productName!=""&&flag==1)
{
strSQL=strSQL+" and productName='"+m_productName+"'";
}
else if(m_productName!=""&&flag==0)
{
strSQL=strSQL+" where productName='"+m_productName+"'";
flag=1;
}
if(m_dealer!=""&&flag==1)
{
strSQL=strSQL+" and dealer='"+m_dealer+"'";
}
else if(m_dealer!=""&&flag==0)
{
strSQL=strSQL+" where dealer='"+m_dealer+"'";
}
// AfxMessageBox(strSQL);
_RecordsetPtr m_pRecordset;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
//----------------------------------------------------
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
int i=0;
m_formList.DeleteAllItems();
while(!(m_pRecordset->adoEOF))
{
m_formList.InsertItem(i,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("productInputFormID")));
m_formList.SetItemText(i,1,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("formDate")));
m_formList.SetItemText(i,2,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("storeHouse")));
m_formList.SetItemText(i,3,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("produceDepartment")));
m_formList.SetItemText(i,4,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("dealer")));
m_formList.SetItemText(i,5,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("houseInType")));
m_formList.SetItemText(i,6,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("remark")));
m_pRecordset->MoveNext();
i++;
}
}
}
m_pRecordset->Close();
UpdateData(false);
}
BOOL CSearchProductInputForm::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD style;
style=m_formList.GetExStyle();
style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
m_formList.SetExtendedStyle(style);
m_formList.InsertColumn(0,"產品入庫單號",LVCFMT_LEFT,100);
m_formList.InsertColumn(1,"生產日期",LVCFMT_LEFT,100);
m_formList.InsertColumn(2,"倉庫名稱",LVCFMT_LEFT,100);
m_formList.InsertColumn(3,"生產部門",LVCFMT_LEFT,100);
m_formList.InsertColumn(4,"經辦人",LVCFMT_LEFT,100);
m_formList.InsertColumn(5,"入庫類別",LVCFMT_LEFT,100);
m_formList.InsertColumn(6,"備注",LVCFMT_LEFT,100);
style=m_productList.GetExStyle();
style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
m_productList.SetExtendedStyle(style);
m_productList.InsertColumn(0,"產品編號",LVCFMT_LEFT,100);
m_productList.InsertColumn(1,"產品名稱",LVCFMT_LEFT,100);
m_productList.InsertColumn(2,"產品單位",LVCFMT_LEFT,100);
m_productList.InsertColumn(3,"產品型號",LVCFMT_LEFT,100);
m_productList.InsertColumn(5,"數量",LVCFMT_LEFT,100);
m_productList.InsertColumn(4,"單價",LVCFMT_LEFT,100);
m_productList.InsertColumn(6,"金額",LVCFMT_LEFT,100);
CString strSQL;
HRESULT hTRes;
_RecordsetPtr m_pRecordset;
strSQL="select distinct productInputFormID from productInputForm";
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
//----------------------------------------------------
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
while(!(m_pRecordset->adoEOF))
{
m_productInputFormIDCombo.AddString(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("productInputFormID")));
m_pRecordset->MoveNext();
}
}
}
m_pRecordset->Close();
strSQL="select distinct storeHouse from productInputForm";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
while(!(m_pRecordset->adoEOF))
{
m_storeHouseInCombo.AddString(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("storeHouse")));
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
strSQL="select distinct produceDepartment from productInputForm";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
while(!(m_pRecordset->adoEOF))
{
m_produceDepartmentCombo.AddString(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("produceDepartment")));
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
strSQL="select distinct productName from productInputFormView";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
while(!(m_pRecordset->adoEOF))
{
m_productNameCombo.AddString(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("productName")));
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
strSQL="select distinct dealer from productInputForm";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
while(!(m_pRecordset->adoEOF))
{
m_dealerCombo.AddString(((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("dealer")));
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSearchProductInputForm::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
HRESULT hTRes;
CString strSQL;
CString str;
int flag=0;
POSITION pos = m_formList.GetFirstSelectedItemPosition();
if(pos)
{
int nFirstSelItem = m_formList.GetNextSelectedItem(pos);
str=m_formList.GetItemText(nFirstSelItem,0);
}
strSQL="select * from productInputFormView where productInputFormID='";
strSQL=strSQL+str+"'";
_RecordsetPtr m_pRecordset;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
//----------------------------------------------------
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
int i=0;
m_productList.DeleteAllItems();
while(!(m_pRecordset->adoEOF))
{
m_productList.InsertItem(i,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("productID")));
m_productList.SetItemText(i,1,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("productName")));
m_productList.SetItemText(i,2,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("unit")));
m_productList.SetItemText(i,3,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("model")));
m_productList.SetItemText(i,4,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("price")));
m_productList.SetItemText(i,5,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("num")));
m_productList.SetItemText(i,6,((CStoreApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("total")));
m_pRecordset->MoveNext();
i++;
}
}
}
*pResult = 0;
}
void CSearchProductInputForm::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
CString str;
int flag=0;
POSITION pos = m_formList.GetFirstSelectedItemPosition();
if(pos)
{
int nFirstSelItem = m_formList.GetNextSelectedItem(pos);
str=m_formList.GetItemText(nFirstSelItem,0);
}
CProductInputForm dlg;
dlg.m_productInputFormID=str;
dlg.is_search=1;
dlg.DoModal();
*pResult = 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -