// 图片处理Dlg.cpp : 实现文件
//
#include "stdafx.h"
#include "图片处理.h"
#include "图片处理Dlg.h"
#include "MyWrapperAdo.h"
void C图片处理Dlg::OnBnClickedButton1()
{
//TODO: 在此添加控件通知处理程序代码
CString count1,count2;
intzongshu1,zongshu2;
inti;
intj;
CString oldpath1,oldpath2;
CString newpath1,newpath2;
CString strOrderNO;
CString strTime =strOrderNO.Mid(4,8);
CString strQuery1= "";
CString strQuery2= "";
longnTemplateID =0 ;
longnOrderNum = 0;
longnProductID = 0;
longnOrderProductID = 0;
longnPhotoID = 0;
longnOrderPhotoID = 0;
longnPhotoNum = 0 ;
longnIsjq = 0 ;
longnIsgm = 0 ;
longnIstl = 0 ;
CString strPhotoPath = "";
CString strDisk = "";
CString strPhotoName = "";
CString strProductName = "";
CString strProductType = "";
CString strIsjq = "";
CString strIsgm = "";
CString strIstl = "";
CString strRename1 = "";
CString strRename2 = "";
CString strTemplateTitle = "";
CString strPhotoInfo = _T("");
CString strNewOrOld = _T("");
CString strUserId = _T("");
CString strTmp2 = "";
intnPos = 0;
intnPhotoFlag = 0;
//连接数据库
CMyWrapperAdo *mydb = new CMyWrapperAdo(CBasicAdo::GetBasicInstance());
//设置路径
CString connectlujing;
connectlujing="Provider = OraOLEDB.Oracle.1;Persist SecurityInfo=True;Data Source =o****;User Id=*******;Password=******* ";
//连接数据库
mydb->ConnectiontoDB(connectlujing,ADODB::adOpenUnspecified);
//获得未处理图片数量
//对照片处理
CString select1;
CString select11;
select1="selectcount(a.orderno) as tatol from ordersa,orderproducts b where a.orderno =b.orderno and b.producttype='尺寸' anda.status='未冲印'";
select11="select a.orderno fromorders a,orderproducts b where a.orderno = b.orderno and b.producttype='尺寸' anda.status='未冲印'";
mydb->Open(select1);
mydb->GetCollect("tatol",count1);
//强制类型转换
zongshu1=atoi(count1);
mydb->Open(select11);//得到订单号
//对图片重命名移动
for(i=1;i<=zongshu1;i++)
{
mydb->GetCollect("orderno", strOrderNO);
//获得图片全部信息
strQuery1.Format("selectphotos.photopath,photos.disk,photos.photoname,photos.photoid,orderphotos.photonum,products.productname,products.ordernum,\
products.productid,products.producttype,products.orderproductid,orderphotos.isjq,orderphotos.isgm,orderphotos.istl,orderphotos.orderphotoid \
from orderproducts products, orderphotos,photos where products.orderproductid = orderphotos.orderproductid\
and photos.photoid = orderphotos.photoid andproducts.producttype='尺寸' and products.orderno='%s'",strOrderNO);
mydb->Open(strQuery1);
if(mydb->IsEOF()== false)//是否为空
{//路径
mydb->GetCollect("disk",strDisk);
mydb->GetCollect("photopath",strPhotoPath);
mydb->GetCollect("photoname",strPhotoName);
mydb->GetCollect("ordernum",nOrderNum);
mydb->GetCollect("productid",nProductID);
mydb->GetCollect("orderproductid",nOrderProductID);
mydb->GetCollect("photoid",nPhotoID);
mydb->GetCollect("photonum",nPhotoNum);
mydb->GetCollect("isjq",nIsjq);
mydb->GetCollect("isgm",nIsgm);
mydb->GetCollect("istl",nIstl);
mydb->GetCollect("productname",strProductName);
mydb->GetCollect("orderphotoid",nOrderPhotoID);
oldpath1.Format("%s%s%s",strDisk,strPhotoPath,strPhotoName);
//重命名
CString strTmp = _T("");
strTmp =strPhotoName.Left( strPhotoName.GetLength()-4 );
switch (nIsgm)
{
case 1:
strIsgm = _T("光面");
break;
case 2:
strIsgm = _T("麻面");
break;
}
switch (nIstl)
{
case 1:
// strIstl ="";
break;
case 2:
strIstl = _T("调亮");
break;
case 3:
strIstl = _T("不调亮");
break;
}
switch (nIsjq)
{
case 1:
//strIsjq = "";
break;
case 2:
strIsjq = _T("裁切");
break;
case 3:
strIsjq = _T("留白");
break;
}
strRename1.Format("%s/%s/%s_%d张_%d_%d_%s_%s_%s_%sa.jpg",strTime,strOrderNO,strProductName,nPhotoNum,nOrderProductID,\
nOrderPhotoID,strTmp, strIsjq, strIstl, strIsgm);
newpath1.Format("Y:/%s%s",strPhotoPath,strRename1);
//路径拆分
CString lift;
lift=strPhotoPath.Left(9);
//创建文件夹(根据路径)
//一级路径
CString yiji;
yiji.Format("Y:/%s",lift);
DWORD dwAttr =GetFileAttributes(strPhotoPath);
if (dwAttr == 0xFFFFFFFF)
{
//不存在
CreateDirectory(yiji,NULL);
CreateDirectory(strPhotoPath,NULL);
//复制文件
CopyFile(oldpath1,newpath1,3);
//改字段
CString ziduan1;
ziduan1.Format("updata orders SET status='已上传' whereorderno='%s'",strOrderNO);
mydb->Open(ziduan1);
mydb->MoveNext();
}
else
{
//存在
CopyFile(oldpath1,newpath1,3);
//改字段
CString ziduan1;
ziduan1.Format("updata orders SET status='已上传' whereorderno='%s'",strOrderNO);
mydb->Open(ziduan1);
mydb->MoveNext();
}
}
}
//对增值产品的操作
CString select2;
CString select22;
select2="selectcount(a.orderno) as tatol from ordersa,orderproducts b where a.orderno =b.orderno and b.producttype='增值' anda.status='未冲印'";
select22="select a.orderno fromorders a,orderproducts b where a.orderno = b.orderno and b.producttype='增值' anda.status='未冲印'";
mydb->Open(select2);
mydb->GetCollect("tatol",count2);
//强制类型转换
zongshu2=atoi(count2);
mydb->Open(select22);//得到订单号
for(j=1;j<=zongshu2;j++)
{
mydb->GetCollect("orderno", strOrderNO);
strQuery2.Format("selectphotos.photopath,photos.disk,photos.photoname,photos.photoid,orderphotos.photonum,\
products.productname,products.ordernum, products.productid,products.producttype,\
products.orderproductid,title.title,title.neworold,orderphotos.orderphotoid,orderphotos.info\
from orderproductsproducts,orderphotos,photos,template_title title \
whereproducts.orderproductid=orderphotos.orderproductid\
and photos.photoid = orderphotos.photoid andproducts.producttype='增值'\
and products.template_id = title.title_id(+)and products.orderno='%s'",strOrderNO);
mydb->Open(strQuery2);
if(mydb->IsEOF()== false)
{//加载信息
mydb->GetCollect("ordernum",nOrderNum);
mydb->GetCollect("productid",nProductID);
mydb->GetCollect("orderproductid",nOrderProductID);
mydb->GetCollect("orderphotoid",nOrderPhotoID);
mydb->GetCollect("photonum",nPhotoNum);
mydb->GetCollect("photoname",strPhotoName);
mydb->GetCollect("photopath",strPhotoPath) ;
mydb->GetCollect("productname",strProductName);
mydb->GetCollect("title",strTemplateTitle);
mydb->GetCollect("info",strPhotoInfo);
mydb->GetCollect("disk",strDisk);
mydb->GetCollect("neworold",strNewOrOld);
oldpath2.Format("%s%s%s",strDisk,strPhotoPath,strPhotoName);
//重命名
if (strTemplateTitle == "")
{
strTemplateTitle="不使用模板";
}
strRename2.Format("%s/%s/%s_%d张_%d_%s_%s_%d_%s_%s",strTime,strOrderNO,strProductName,nOrderNum,nOrderProductID,
strNewOrOld,strTemplateTitle,nOrderPhotoID,strPhotoInfo,strPhotoName);
newpath2.Format("Y:/%s%s",strPhotoPath,strRename2);
//路径拆分
CString lift2;
lift2=strPhotoPath.Left(9);
CString yiji2;
yiji2.Format("Y:/%s",lift2);
//创建文件夹(根据路径)
DWORD dwAttr =GetFileAttributes(strPhotoPath);
if (dwAttr == 0xFFFFFFFF)
{
CreateDirectory(yiji2,NULL);
CreateDirectory(strPhotoPath,NULL);
//复制文件
CopyFile(oldpath2,newpath2,3);
//改字段
CString ziduan2;
ziduan2.Format("updata orders SET status='已上传' whereorderno='%s'",strOrderNO);
mydb->Open(ziduan2);
mydb->MoveNext();
}
else
{
//复制文件
CopyFile(oldpath2,newpath2,3);
//改字段
CString ziduan2;
ziduan2.Format("updata orders SET status='已上传' whereorderno='%s'",strOrderNO);
mydb->Open(ziduan2);
mydb->MoveNext();
}
}
}
}