⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lqexportdlg.cpp

📁 这是一个odbc数据库接口程序
💻 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 + -