📄 gspmange.cpp
字号:
// GspMange.cpp : 实现文件
//
#include "stdafx.h"
#include "MedicineSaleManages.h"
#include "GspMange.h"
#include ".\gspmange.h"
#define ChunkSize 1024
// CGspMange 对话框
IMPLEMENT_DYNAMIC(CGspMange, CDialog)
CGspMange::CGspMange(CWnd* pParent /*=NULL*/)
: CDialog(CGspMange::IDD, pParent)
{
}
CGspMange::~CGspMange()
{
}
void CGspMange::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_PROGRESS1, m_progress1);
DDX_Control(pDX, IDC_LIST1, m_list1);
}
BEGIN_MESSAGE_MAP(CGspMange, CDialog)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
ON_BN_CLICKED(IDC_WRITETEMPLATE, OnBnClickedWritetemplate)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnNMDblclkList1)
END_MESSAGE_MAP()
// CGspMange 消息处理程序
void CGspMange::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
OnOK();
}
void CGspMange::OnBnClickedCancel()
{
// TODO: 在此添加控件通知处理程序代码
OnCancel();
}
BOOL CGspMange::OnInitDialog()
{
CDialog::OnInitDialog();
m_tooltip.Create(this,TTS_ALWAYSTIP);
m_tooltip.Activate(TRUE);
m_tooltip.AddTool(GetDlgItem(IDC_WRITETEMPLATE),IDS_WRITETEMPLATE);
m_tooltip.AddTool(GetDlgItem(IDC_PROGRESS1),IDS_SETPROGRESS1);
m_tooltip.AddTool(GetDlgItem(IDC_LIST1),IDS_GSPLIST1);
DWORD style;
style=(LVS_EX_GRIDLINES|LVS_OWNERDRAWFIXED) ; //style/|LVS_EX_CHECKBOXES|设置样式LVS_EX_FULLROWSELECT|
m_list1.SetExtendedStyle(style); //应用样式
CRect rect;
m_list1.GetWindowRect(rect);
m_list1.InsertColumn(0,"GSP文件列表",LVCFMT_LEFT,rect.Width()-4);
NewView();
return TRUE;
}
BOOL CGspMange::PreTranslateMessage(MSG* pMsg)
{
m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
void CGspMange::OnBnClickedWritetemplate()
{
CTreeFileView dlg;
dlg.FileExName=_T("");
if(dlg.DoModal()==IDOK && !(dlg.str_pathname.IsEmpty()))
{
CString message=_T("将写入 ");
message+=dlg.str_pathname;
message+=_T(" 目录下的所有文件,但不包括子目录?\r\n\r\n注意:该操作将会删除所有原始模板文件!!!\r\n\r\n是否继续???");
if(AfxMessageBox(message,MB_YESNO|MB_ICONQUESTION)==IDYES)
{
CStringArray sheet_name;
int file_number=0;
CString str;
str=dlg.str_pathname;
str+=_T("*.*");
CFileFind file;
BOOL bContinue = file.FindFile(str);
while(bContinue)
{
bContinue = file.FindNextFile();
if(!file.IsDirectory() && !file.IsDots())
{
sheet_name.Add(file.GetFilePath());
file_number++;
}
}
theApp.BeginWaitCursor();
m_progress1.SetRange(0,file_number+1);
m_progress1.SetStep(1);
CString strSQL=_T("");
CString error=_T("");
m_progress1.StepIt();
strSQL="drop table Template";
(((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="CREATE TABLE Template (name char(250) NOT NULL,table_xls image NOT NULL)";
(((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1)->Execute((_bstr_t)strSQL,NULL,adCmdText);
for(int i=0;i<file_number;i++)
{
CFileFind find;
BOOL bFound = find.FindFile(sheet_name[i]);
if(bFound)
{
LZARI Lzari;
Lzari.Compress(sheet_name[i],sheet_name[i]+_T("1"));
theApp.FileToDb("Template","name","table_xls",sheet_name[i].Right(sheet_name[i].GetLength()-sheet_name[i].ReverseFind('\\')-1),sheet_name[i]+_T("1"));
}
else
{
error+=sheet_name[i];
error+="\r\n";
}
m_progress1.StepIt();
find.Close();
}
sheet_name.RemoveAll();
theApp.EndWaitCursor();
NewView();
if(error.IsEmpty())
AfxMessageBox("模板文件写入完毕!");
else
AfxMessageBox(error+"\r\n以上文件未能写入,请检查后重新执行该操作!");
m_progress1.SetPos(0);
theApp.m_pConn1->Close();
theApp.m_pConn1=NULL;
theApp.CompressDatabase();
theApp.makeaccessdatabase();
}
}
else
AfxMessageBox("用户取消了选择,未能写放任何模板文件!");
}
void CGspMange::NewView(void)
{
m_list1.DeleteAllItems();
m_pRecordset.CreateInstance(__uuidof(Recordset));
CString str;
CString strSQL="SELECT * FROM Template";
m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
while(!(m_pRecordset->adoEOF))
{
str=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("name"));
if(!str.IsEmpty())
m_list1.InsertItem(m_list1.GetItemCount(),str.Left(str.ReverseFind('.')));
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
m_pRecordset=NULL;
}
void CGspMange::WinHelp(DWORD dwData, UINT nCmd)
{
}
void CGspMange::OnNMDblclkList1(NMHDR *pNMHDR, LRESULT *pResult)//打开对应GSP文件
{
POSITION pos=m_list1.GetFirstSelectedItemPosition();
int r=m_list1.GetItemCount();
if(pos && r>=1)
{
int n=m_list1.GetNextSelectedItem(pos);
m_list1.SetItemColor(n,(DWORD)RGB(0,0,255));
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -