// uploadingDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "uploading.h"
#include "uploadingDlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CuploadingDlg 对话框

CuploadingDlg::CuploadingDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CuploadingDlg::IDD, pParent)
, m_OpTypeString(_T(""))
, m_usernameString(_T(""))
, m_passwordString(_T(""))
, m_dataBaseString(_T(""))
, m_hostString(_T(""))
, m_IpAddressString(_T(""))
, m_InnoString(_T(""))
, m_szFilepPathString(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CuploadingDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT5, m_OpType);
DDX_Text(pDX, IDC_EDIT5, m_OpTypeString);
DDX_Control(pDX, IDC_EDIT1, m_username);
DDX_Text(pDX, IDC_EDIT1, m_usernameString);
DDX_Control(pDX, IDC_EDIT2, m_password);
DDX_Text(pDX, IDC_EDIT2, m_passwordString);
DDX_Control(pDX, IDC_EDIT3, m_dataBase);
DDX_Text(pDX, IDC_EDIT3, m_dataBaseString);
DDX_Control(pDX, IDC_EDIT4, m_host);
DDX_Text(pDX, IDC_EDIT4, m_hostString);
DDX_Control(pDX, IDC_EDIT6, m_IpAddress);
DDX_Text(pDX, IDC_EDIT6, m_IpAddressString);
DDX_Control(pDX, IDC_INNO, m_Inno);
DDX_Text(pDX, IDC_INNO, m_InnoString);
DDX_Control(pDX, IDC_EDIT7, m_szFilepPath);
DDX_Text(pDX, IDC_EDIT7, m_szFilepPathString);
}

BEGIN_MESSAGE_MAP(CuploadingDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDOK, &CuploadingDlg::OnBnClickedOk)
ON_BN_CLICKED(IDC_BUTTON1, &CuploadingDlg::OnBnClickedButton1)
END_MESSAGE_MAP()

// CuploadingDlg 消息处理程序

BOOL CuploadingDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标

// TODO: 在此添加额外的初始化代码

m_IpAddress.SetWindowTextA("127.0.0.1");
m_host.SetWindowTextA("1521");
m_OpType.SetWindowTextA("jpg");
m_dataBase.SetWindowTextA("orcl");

return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}

// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。

void CuploadingDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// 使图标在工作区矩形中居中
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;

// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CuploadingDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}

UINT Send(LPVOID lParam)
{
CuploadingDlg *pthis = (CuploadingDlg*)lParam;
int i=0;
int errorcount = 0;
for ( i=0;i<pthis->v.size();++i)
{
if(pthis->SendPhoto(pthis->v[i]) != 0 )
{
errorcount++;
continue;
}
CString temp;
temp.Format("正在处理第%d条",i+1);
pthis->m_Inno.SetWindowTextA(temp);
pthis->GetDlgItem(IDOK)->EnableWindow(FALSE);
}

CString temp;
temp.Format("处理完成,共有%d条数据,正确处理%d条,错误数据%d条",pthis->v.size(),pthis->v.size() - errorcount,errorcount);
pthis->m_Inno.SetWindowTextA(temp);
pthis->GetDlgItem(IDOK)->EnableWindow(TRUE);

if (pthis->pRect)
{
pthis->pRect->Close();
pthis->pRect = NULL;
}
if (pthis->pConn)
{
pthis->pConn->Close();
pthis->pConn = NULL;
}

}

void CuploadingDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
//CDialogEx::OnOK();
UpdateData(TRUE);
if (m_usernameString.IsEmpty() || m_passwordString.IsEmpty() || m_IpAddressString.IsEmpty() || m_hostString.IsEmpty() || m_dataBaseString.IsEmpty() || m_OpTypeString.IsEmpty() || m_szFilepPathString.IsEmpty())
{
return ;
}
std::vector<CString>().swap(v);
TraverseDir(m_szFilepPathString, v);

if(OpenDataBase() != 0 )return ;
CWinThread *IninThread = AfxBeginThread(Send,this);

}

void CuploadingDlg::TraverseDir(CString& dir,std::vector<CString>& vec)//深度遍历文件夹
{
CFileFind ff;
if (dir.Right(1) != "\\")
{
dir += "\\";
}
dir += "*.*";

BOOL ret = ff.FindFile(dir);
while (ret)
{
ret = ff.FindNextFileA();
if (ff.IsDirectory() && !ff.IsDots())
{
CString path = ff.GetFilePath();
TraverseDir(path,vec);
}
if (!ff.IsDirectory() && !ff.IsDots())
{
CString name = ff.GetFileName();
CString path = ff.GetFilePath();
int dotpos = name.ReverseFind('.');
CString fileExt = name.Right(name.GetLength() - dotpos-1);
m_OpTypeString = "";
m_OpType.GetWindowTextA(m_OpTypeString);
m_OpTypeString.MakeLower();
if (fileExt == m_OpTypeString)
{
vec.push_back(path);
}
}
}
ff.Close();
}

int CuploadingDlg::SendPhoto(CString photoPath)
{
CStdioFile file;
if (file.Open(photoPath,CFile::modeRead|CFile::typeBinary) == FALSE)
{
Writelog("打开文件失败:%s",photoPath);
return -1;
}
long filelen = file.GetLength();
byte *fielBuffer = new byte[filelen+1];
byte *oldfieldBuffer = fielBuffer;
file.Read(fielBuffer,filelen);
file.Close();

SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = filelen;

SAFEARRAY *safeArray;
safeArray = SafeArrayCreate(VT_UI1,1,rgsabound);
for (long i=0;i< filelen;i++)
{
SafeArrayPutElement(safeArray,&i,fielBuffer++);
}

VARIANT varBLOB;
varBLOB.vt = VT_ARRAY | VT_UI1;
varBLOB.parray = safeArray;

if (fielBuffer)
{
delete[] oldfieldBuffer;
fielBuffer = NULL;
}

CString str;
try
{

CString Index;
str.Format("select faceid from (select * from userface order by faceid desc) where rownum=1");
_variant_t vt;
pRect = pConn->Execute(_bstr_t(str),&vt,adCmdText);
if (vt.lVal < 1)
{
Index = "0";
}else
{
Index = LPSTR(_bstr_t(pRect->GetCollect("faceid")));
}
CString filename;
int dotpos = photoPath.ReverseFind('.');
filename = photoPath.Mid(0,dotpos);
dotpos = filename.ReverseFind('\\');
filename = filename.Right(filename.GetLength() - dotpos-1);

str.Format("insert into userface(faceid,USERID,FEATURE) values(%d,'%s','000')",atoi(Index)+1,filename);
pRect = pConn->Execute(_bstr_t(str),&vt,adCmdText);
if (vt.lVal < 1)
{
Writelog("插入数据失败:%s",str);
SafeArrayDestroy(safeArray);
if (pRect)
{
pRect->Close();
pRect = NULL;
}
if (pConn)
{
pConn->Close();
pConn = NULL;
}

return -1;
}
str.Format("select * from userface where faceid = %d",atoi(Index) +1);
HRESULT hr;
hr = pRect->Open(str.GetBuffer(0),(IDispatch*)pConn,adOpenDynamic,adLockOptimistic,adCmdText);
hr = pRect->GetFields()->GetItem("IMAGE")->AppendChunk(varBLOB);
if (hr == S_OK)
{
pRect->Update();
pRect->Requery(0);
}
SafeArrayDestroy(safeArray);
if (pRect)
{
pRect->Close();
pRect = NULL;
}
}
catch (_com_error &e)
{
Writelog("SendCommand捕获异常:%s",e.ErrorMessage());
if (pRect)
{
pRect->Close();
pRect = NULL;
}
if (pConn)
{
pConn->Close();
pConn = NULL;
}
return -1;
}
return 0;
}

int CuploadingDlg::OpenDataBase(void)
{
pConn.CreateInstance(__uuidof(Connection));//连接对像
pRect.CreateInstance(__uuidof(Recordset));//记录集对象

CString strConn;

strConn.Format("Provider=OraOLEDB.Oracle.1;User ID=%s;Password=%s;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=%s)(PORT=%s))(CONNECT_DATA=(SERVICE_NAME=%s)))",m_usernameString,m_passwordString,m_IpAddressString,m_hostString,m_dataBaseString);
HRESULT rValue = pConn->Open(_bstr_t(strConn),"","",adModeUnknown);
if (rValue == S_FALSE)
{
MessageBox(_T("打开失败"));
return -1;
}
return 0;
}

void CuploadingDlg::Writelog(char* buf,...)
{
try
{
CString sdlog;
m_szFilepPath.GetWindowTextA(m_szFilepPathString);
if (m_szFilepPathString.IsEmpty())
{
sdlog =" C:\\Send";

}else
{
sdlog = m_szFilepPathString;
}
sdlog += "\\log\\";
CreateDirectory(sdlog, NULL);
long i=0;
char tmp[32],tmpfile[256];
//char tmpPrint[4096]={0};

char buffer[1524]={0};
char Data[1024]={0};
FILE *fp;

SYSTEMTIME SystemTimeStruct;
::GetLocalTime(&SystemTimeStruct);

sprintf(tmp,"%04d%02d%02d ",SystemTimeStruct.wYear,SystemTimeStruct.wMonth,
SystemTimeStruct.wDay);

sprintf(tmpfile,"%s%s.log",sdlog,tmp);

fp=fopen(tmpfile,"at");
if (fp == NULL)
{
return;
}

va_list arglist;

va_start(arglist, buf);
vsprintf(&Data[strlen(Data)], buf, arglist);
va_end(arglist);
sprintf(buffer,"%02d:%02d:%02d %s",SystemTimeStruct.wHour,SystemTimeStruct.wMinute,
SystemTimeStruct.wSecond,Data);

fputs(buffer,fp);
fputs("\n",fp);

fclose(fp);
}
catch(...)
{

return;
}
}

void CuploadingDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
char szPath[MAX_PATH];

ZeroMemory(szPath,sizeof(szPath));

BROWSEINFO bi;
bi.hwndOwner = m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szPath;
bi.lpszTitle = "请选择文件夹";
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;

LPITEMIDLIST lp = SHBrowseForFolder(&bi);

if (lp && SHGetPathFromIDList(lp,szPath))
{
m_szFilepPathString.Format("%s",szPath);
m_szFilepPath.SetWindowTextA(m_szFilepPathString);
}
}

ORACEL上传BLOB,深度遍历文件夹的更多相关文章

  1. win 10 用户上传头像保存的文件夹路径

    win 10 用户上传头像保存的文件夹路径 C:\Users\Administrator(用户名)\AppData\Roaming\Microsoft\Windows\AccountPictures

  2. 将文件夹上传到FTP服务器,遍历上传,,,文件夹不能直接上传到FTP服务器上。。。

    <? $ftp_ip = "FTP"; $ftp_user = "user"; $ftp_pwd = "password"; $con ...

  3. File类_深度遍历文件夹_练习

    遍历指定目录下的所有文件和文件夹 import java.io.File; public class FileTest { public static void main(String[] args) ...

  4. C#实现多文件上传,写到文件夹中,获取文件信息以及下载文件和删除文件

    前台:.js //上传附件 function uploadAttachment() { if ($("#Tipbind").attr('checked')) { var ip = ...

  5. 往github上传代码忽略node_modules文件夹

    首先必须在你初始化  git 仓库的那个文件夹建立 .gitigonre 文件,在这个文件夹里面写入下面代码 node_modules npm-debug.log package-lock.json ...

  6. ftp上传文件不能上传到指定的文件夹

    首先是,使用ftp创建连接,这一点没有错误,但是在切换目录创建文件夹的时候出现了问题. 指定创建的文件夹,总是创建失败,切换目录同样失败.最后查看文件夹的权限才知道,没有权限的问题: 然后给img文件 ...

  7. java 深度遍历文件夹中的所有文件

    看标题就知道是什么意思了吧,所以就不多说了,直接贴代码: import java.io.*; public class files { private static void iterateFile( ...

  8. Java深度遍历文件夹(递归实现)

    package FileDemo; import java.io.File; public class DeepSearchDir { /** * @param args */ public stat ...

  9. Java解压上传zip或rar文件,并解压遍历文件中的html的路径

    1.本文只提供了一个功能的代码 public String addFreeMarker() throws Exception { HttpSession session = request.getSe ...

随机推荐

  1. JMS基础知识

    JMS规范: jms的基本构件:  连接工厂(connectionFactory):客户用来创建连接的对象.比如:activeMQ提供的ActiveMQConnectionFactory. 连接(co ...

  2. [NOI.AC#40]Erlang

    链接 题解 显然,最多抽2个集合 如果一直抽一个,前提是该集合有重复的,答案是不同元素的个数+1 如果抽两个,那么最坏情况下,在一个集合中抽到某一个数的次数是这个集合不同元素的个数(因为抽不到重复的) ...

  3. 带你一分钟理解闭包--js面向对象编程(转载他人)

    什么是闭包? 先看一段代码: function a(){ var n = 0; function inc() { n++; console.log(n); } inc(); inc(); } a(); ...

  4. prettyJson V7.1 使用

    头文件 #include "document.h" #include "prettywriter.h" #include "filereadstrea ...

  5. 洛谷 P2694 接金币

    P2694 接金币 题目描述 在二维坐标系里,有N个金币,编号0至N-1.初始时,第i个金币的坐标是(Xi,Yi).所有的金币每秒向下垂直下降一个单位高度,例如有个金币当前坐标是(xf, yf),那么 ...

  6. 阻止事件冒泡js jquery

    jQuery之防止冒泡事件 冒泡事件就是点击子节点,会向上触发父节点.祖先节点的点击事件. 以下是html代码部分: <body> <div id="content&quo ...

  7. 【SSH学习笔记】—从配置Struts1环境到简单实例

    以下我将从一个简单点的计算器实例,介绍struts1的环境配置,以及其重要的两个核心类:ActionForm和Action  简单计算器实现思路: 1.提供一个输入界面,输入两个数字和运算符(+.-. ...

  8. 本地 oracle 安装文件夹满触发 ORA-7445 [_memmove()+64] 导致Instance Crashed 的事故

    近期处理了一个问题,原因是因为命中ORA-600 [kole_t2u], [34] - description, bugs 导致 在udump 文件夹下大量转储 出cdmp 文件, 然后这些 cdmp ...

  9. 2.写给设计师看的HTML&CSS入门指导

    转自:http://www.uisdc.com/html-and-css-guide 整体简介 在开始学习HTML&CSS之前,首先要搞清楚两者的区别.两者在整体上有着很明显的差异. 整体看来 ...

  10. time and datetime

    一.简述 我们在写代码的过程经常遇到时间模块,如果我们以后需要根据时间去筛选信息的话,那用户会更大,所以今天就来讲讲时间的两大模块:time & datetime 二.time模块 1.tim ...