ORACEL上传BLOB,深度遍历文件夹
// 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,深度遍历文件夹的更多相关文章
- win 10 用户上传头像保存的文件夹路径
win 10 用户上传头像保存的文件夹路径 C:\Users\Administrator(用户名)\AppData\Roaming\Microsoft\Windows\AccountPictures
- 将文件夹上传到FTP服务器,遍历上传,,,文件夹不能直接上传到FTP服务器上。。。
<? $ftp_ip = "FTP"; $ftp_user = "user"; $ftp_pwd = "password"; $con ...
- File类_深度遍历文件夹_练习
遍历指定目录下的所有文件和文件夹 import java.io.File; public class FileTest { public static void main(String[] args) ...
- C#实现多文件上传,写到文件夹中,获取文件信息以及下载文件和删除文件
前台:.js //上传附件 function uploadAttachment() { if ($("#Tipbind").attr('checked')) { var ip = ...
- 往github上传代码忽略node_modules文件夹
首先必须在你初始化 git 仓库的那个文件夹建立 .gitigonre 文件,在这个文件夹里面写入下面代码 node_modules npm-debug.log package-lock.json ...
- ftp上传文件不能上传到指定的文件夹
首先是,使用ftp创建连接,这一点没有错误,但是在切换目录创建文件夹的时候出现了问题. 指定创建的文件夹,总是创建失败,切换目录同样失败.最后查看文件夹的权限才知道,没有权限的问题: 然后给img文件 ...
- java 深度遍历文件夹中的所有文件
看标题就知道是什么意思了吧,所以就不多说了,直接贴代码: import java.io.*; public class files { private static void iterateFile( ...
- Java深度遍历文件夹(递归实现)
package FileDemo; import java.io.File; public class DeepSearchDir { /** * @param args */ public stat ...
- Java解压上传zip或rar文件,并解压遍历文件中的html的路径
1.本文只提供了一个功能的代码 public String addFreeMarker() throws Exception { HttpSession session = request.getSe ...
随机推荐
- Exercise : Softmax Regression
Step 0: Initialize constants and parameters Step 1: Load data Step 2: Implement softmaxCost Implemen ...
- C# WPF开源控件库MaterialDesign介绍
介绍 1.由于前端时间萌发开发一个基础架构得WPF框架得想法, 然后考虑到一些界面层元素统一, 然后就无意间在GitHub上发现一个开源WPF UI, 于是下载下来了感觉不错. 官网地址:http:/ ...
- ios UITextView 提示文本
定义两个UITextView,一个用于输入文本,一个用于显示提示信息,当输入文本为空时显示提示信息,否则不显示提示信息. //6.3.1文字内容提示 _contentTextViewTip = [[U ...
- BASH 文本模版的简单实现 micro_template_compile
详细代码 ############################### # # Funciton: micro_template_compile # # Parameter: # [1] => ...
- 类名引用static变量好处
不仅强调了变量static的结构,而且在有些情况下他还为编译器进行优化提供了更好的机会.
- 关于Sleep函数介绍
函数名: Sleep 功 能: 执行挂起一段时间 用 法: void Sleep(DWORD dwMilliseconds); 在VC中使用带上头文件 #include <windows.h&g ...
- golang sync.Once
package main import ( "fmt" "sync" "time" ) func main() { var once syn ...
- IIS发布asp.net mvc项目(asp.net core也是一样)
因为之前都是利用其他的工具在linux上面进行发布,导致现在忘记了在IIS上面怎么发布,现在就记录下来,以防不时之需吧 第一步: 在vs里面进行项目发布:指定好发布的位置,点击发布就好了 第二步:右击 ...
- Vue Cli 打包之后静态资源路径不对的解决方法
cli2版本: 将 config/index.js 里的 assetsPublicPath 的值改为 './' . build: { ... assetsPublicPath: './', ... } ...
- Android: 分页浏览的利器 android View Pager
最近有一个项目需求,水平滑动实现视图切换(分页显示效果) 最先想到的是ImageSwitcher + ViewFilpper 来实现,这效果做出来我自己都不想用,更不用说客户的感觉了:滑动效果生硬,只 ...