?? lqexportdlg.cpp
字號:
// lqexportDlg.cpp : implementation file
//
#include "stdafx.h"
#include "lqexport.h"
#include "lqexportDlg.h"
#include "MyODBC.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLqexportDlg dialog
extern CLqexportApp theApp;
CLqexportDlg::CLqexportDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLqexportDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLqexportDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CLqexportDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLqexportDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLqexportDlg, CDialog)
//{{AFX_MSG_MAP(CLqexportDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLqexportDlg message handlers
BOOL CLqexportDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
if(OnButton1())
// AfxMessageBox("售電數據已傳送到MIS系統");
WriteLog();
this->OnOK();
return TRUE; // return TRUE unless you set the focus to a control
}
void CLqexportDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CLqexportDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CLqexportDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CLqexportDlg::OnButton1()
{
// TODO: Add your control notification handler code here
_variant_t sql,Holder;
CString strTemp,SequenceNo,SaleMoney,SaleOperatorID,ID,SaleDate,UserName,jsyf, tagid,version;
CString datetime;
CTime tmSaleDate;
CTime tm = CTime::GetCurrentTime();
CTimeSpan tspan(7,0,0,0);//7天
CTime tt=tm-tspan;
datetime = tt.Format("%Y-%m-%d");
CMyODBC db;
if(!db.ConnectDB("psmis","wsjk", "wsjk")) //臨朐連接數據庫
{
return false;
}
//export data to oracle
sql=" select a.SequenceNo,a.SaleMoney,a.SaleOperatorID,a.SaleDate,b.ID,b.AreaName from\
PrePayment a,\
[user] b,\
ICCard c\
where a.SaleDate>'"+datetime+"'\
and b.ID=c.User_ID and c.ID=a.ICCard_ID";
theApp.ADOExecute(theApp.m_pADOSet,sql);
if(!theApp.m_pADOSet->EndOfFile)
theApp.m_pADOSet->MoveFirst();
while (!theApp.m_pADOSet->EndOfFile)
{
Holder=theApp.m_pADOSet->GetCollect("SequenceNo");
SequenceNo=VariantToCString(Holder);
SequenceNo.TrimLeft();
SequenceNo.TrimRight();
SequenceNo ="hnd"+SequenceNo;
tagid="11"+SequenceNo.Right(10);
Holder=theApp.m_pADOSet->GetCollect("ID");
ID=VariantToCString(Holder);
ID.TrimRight();
ID.TrimLeft();
Holder=theApp.m_pADOSet->GetCollect("AreaName");
UserName=VariantToCString(Holder);
UserName.TrimLeft();
UserName.TrimRight();
Holder=theApp.m_pADOSet->GetCollect("SaleMoney");
SaleMoney=VariantToCString(Holder);
SaleMoney.TrimRight();
SaleMoney.TrimLeft();
Holder=theApp.m_pADOSet->GetCollect("SaleOperatorID");
SaleOperatorID=VariantToCString(Holder);
SaleOperatorID.TrimLeft();
SaleOperatorID.TrimRight();
Holder=theApp.m_pADOSet->GetCollect("SaleDate");
SaleDate=VariantToCString(Holder);
SaleDate.TrimRight();
SaleDate.TrimLeft();
ConvertJSYF(SaleDate,jsyf);
version="0";
CString strSql;
strSql.Format("delete from fc_precharge where CHARGEFLOWNO='%s'",SequenceNo);
db.ExeSqlDirect(strSql);//執行sql語句
strSql.Format("insert into fc_precharge values(%s,%s,'%s','%s',null,'%s','%s',%s,null,null,null,null,null,'%s',null,'已入庫',to_date('%s', 'dd-mm-yyyy hh24:mi:ss'))",tagid,version,SequenceNo,ID,UserName,jsyf,SaleMoney,SaleOperatorID,SaleDate);
db.ExeSqlDirect(strSql);//執行sql語句
theApp.m_pADOSet->MoveNext();
}
db.DisConnect();//斷開連接
return true;
}
CString CLqexportDlg::VariantToCString(const _variant_t &var)
{
CString strValue;
switch (var.vt)
{
case VT_BSTR://字符串
case VT_LPSTR:
case VT_LPWSTR:
strValue = (LPCTSTR)(_bstr_t)var;
break;
case VT_I1://無符號字符
case VT_UI1:
strValue.Format("%d", var.bVal);
break;
case VT_I2://短整型
strValue.Format("%d", var.iVal);
break;
case VT_UI2://無符號短整型
strValue.Format("%d", var.uiVal);
break;
case VT_INT://整型
strValue.Format("%d", var.intVal);
break;
case VT_I4: //整型
case VT_I8: //長整型
strValue.Format("%d", var.lVal);
break;
case VT_UINT://無符號整型
strValue.Format("%d", var.uintVal);
break;
case VT_UI4: //無符號整型
case VT_UI8: //無符號長整型
strValue.Format("%d", var.ulVal);
break;
case VT_VOID:
strValue.Format("%8x", var.byref);
break;
case VT_R4://浮點型
strValue.Format("%.4f", var.fltVal);
break;
case VT_R8://雙精度型
strValue.Format("%.8f", var.dblVal);
break;
case VT_DECIMAL: //小數
strValue.Format("%.8f", (double)var);
break;
case VT_CY:
{
COleCurrency cy = var.cyVal;
strValue = cy.Format();
}
break;
case VT_BLOB:
case VT_BLOB_OBJECT:
case 0x2011:
strValue = "[BLOB]";
break;
case VT_BOOL://布爾型
strValue = var.boolVal ? "TRUE" : "FALSE";
break;
case VT_DATE: //日期型
{
DATE dt = var.date;
COleDateTime da = COleDateTime(dt);
strValue = da.Format("%d-%m-%y %H:%M:%S");
}
break;
case VT_NULL://NULL值
case VT_EMPTY://空
strValue = "";
break;
case VT_UNKNOWN://未知類型
default:
strValue = "UN_KNOW";
break;
}
return strValue;
}
void CLqexportDlg::CStringtoCtime(CString str,CTime & tm)
{
int year,month,day,hour,minite,second;
sscanf(str,"%d-%d-%d %d:%d:%d",&year,&month,&day,&hour,&minite,&second);
CTime time(year,month,day,hour,minite,second);
tm=time;
}
void CLqexportDlg::WriteLog()
{
CStdioFile f1;
char* pFileName = "log.txt";
CString tm;
CTime t = CTime::GetCurrentTime();
tm="\n";
tm+=t.Format("%Y-%m-%d %H:%M:%S");
tm=tm+"售電數據已傳送到MIS系統";
f1.Open( pFileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite| CFile::typeText );
f1.SeekToEnd();
f1.WriteString(tm);
f1.Close();
}
void CLqexportDlg::ConvertJSYF(CString strTemp, CString & jsyf)
{
int day;
int month;
day=atoi(strTemp.Mid(0,2));
month=atoi(strTemp.Mid(3,2));
if(day<11)
{
month--;
if(month==0)
month=12;
}
jsyf.Format("%d",month);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -