// 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. ipcalcIP地址计算

    ipcalc命令是一个简单的ip地址计算器,可以完成简单的IP地址计算任务. 语法 ipcalc(选项) 选项 -b:由给定的IP地址和网络掩码计算出广播地址: -h:显示给定UP地址所对应的主机名: ...

  2. postgresql 不同数据库不同模式下的数据迁移

    编写不容易,转载请注明出处谢谢, 数据迁移 因为之前爬虫的时候,一部分数据并没有上传到服务器,在本地.本来用的就是postgresql,也没用多久,数据迁移的时候,也遇到了很多问题,第一次使pg_du ...

  3. Summary Day32

    1 . 文件管理 1.1 标C文件处理和UC文件处理函数的比較: 标C文件处理函数比UC的文件处理函数速度快.由于标C内部独立输入输出缓冲区, 会积累一定数量之后再写入文件,因此读写效率比較高 使用t ...

  4. centos7 Another app is currently holding the yum lock; waiting for it to exit...

    解决方法:rm -rf /var/run/yum.pid 来强行解除锁定,然后你的yum就可以运行了

  5. IntelliJ IDEA 启动tomcat 报错: idea Unable to open debugger port (127.0.0.1:58233): java.net.SocketException "socket closed"

    debug启动项目弹出提示 Error running omp: Unable to open debugger port (127.0.0.1:50812): java.net.SocketExce ...

  6. [转]Accept-Encoding

    原文地址:https://blog.csdn.net/sqzhao/article/details/49499471 HTTP Header中Accept-Encoding 是浏览器发给服务器,声明浏 ...

  7. CF-833B The Bakery(线段树优化Dp)

      Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredie ...

  8. 内核中的宏定义__init、__initdata和__exit、__exitdata

    __init.__initdata和__exit.__exitdata的定义位于<kernel/include/linux/init.h> /* These are for everybo ...

  9. 洛谷——P1781 宇宙总统

    https://www.luogu.org/problem/show?pid=1781 题目背景 宇宙总统竞选 题目描述 地球历公元6036年,全宇宙准备竞选一个最贤能的人当总统,共有n个非凡拔尖的人 ...

  10. [Node] Stateful Session Management for login, logout and signup

    Stateful session management: Store session which associate with user, and store in the menory on ser ...