123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- // FileManage2.cpp : implementation file
- //
- #include "stdafx.h"
- //#include "ZLSoftC.h"
- #include "YLGL.h"
- #include "FileManage2.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // FileManage2 dialog
- FileManage2::FileManage2(CWnd* pParent /*=NULL*/)
- : CDialog(FileManage2::IDD, pParent)
- {
- //{{AFX_DATA_INIT(FileManage2)
- m_text = _T("");
- //}}AFX_DATA_INIT
- }
- void FileManage2::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(FileManage2)
- DDX_Control(pDX, IDC_TREE1, m_mytree);
- DDX_Text(pDX, IDC_EDIT1, m_text);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(FileManage2, CDialog)
- //{{AFX_MSG_MAP(FileManage2)
- ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
- ON_BN_CLICKED(IDC_BUTAddP, OnBUTAddP)
- ON_BN_CLICKED(IDC_BUTAddC, OnBUTAddC)
- ON_BN_CLICKED(IDC_BUTrename, OnBUTrename)
- ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // FileManage2 message handlers
- BOOL FileManage2::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // SetDlgFont( this );
- // TODO: Add extra initialization here
- GetDlgItem(IDC_BUTrename)->EnableWindow(IsHasRights2new(49));
- GetDlgItem(IDC_BUTdel)->EnableWindow(IsHasRights2new(49));
- HICON icon[2];
- icon[0]=AfxGetApp()->LoadIcon (IDI_ICON12);
- icon[1]=AfxGetApp()->LoadIcon (IDI_ICON13);
- CImageList *m_imagelist=new CImageList;
- m_imagelist->Create(16,16,0,7,7);
- m_imagelist->SetBkColor (RGB(255,255,255));
- for(int n=0;n<2;n++)
- {
- m_imagelist->Add(icon[n]); //把图标载入图像列表控件
- }
- m_mytree.SetImageList(m_imagelist,TVSIL_NORMAL);
- GetData();
- CenterWindow();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void FileManage2::GetData()
- {
- g_sendhead.bsql=0;
- g_sendhead.code[0]=232;
- g_sendhead.tabcount=1;
- g_pMainWnd->ProcessChatMessageRequest2(1);
- if(g_bSendOK==0)return;
- DataToArray(&m_List1array);
- m_mytree.DeleteAllItems();
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(m_List1array.ElementAt(i).ElementAt(1)=="")
- {
- AddChild(m_List1array.ElementAt(i).ElementAt(0), NULL);
- }
- }
- }
- void FileManage2::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- // TODO: Add your control notification handler code here
- HTREEITEM hSelectedItem = m_mytree.GetSelectedItem();
- if(hSelectedItem==NULL)
- {
- //m_curposition="";UpdateData(0);m_curid=-1;
- CString str;
- str.Format ("当前柜:%s", "");
- SetDlgItemText(IDC_STATIC2, str);
- return;
- } CString str,m_curposition;
- GetCurSelID(m_curposition);
- str.Format ("当前柜:%s", m_curposition);
- SetDlgItemText(IDC_STATIC2, str);
- *pResult = 0;
- }
- void FileManage2::AddChild(CString curid, HTREEITEM hParent)
- {
- HTREEITEM hChild;
- if(hParent==NULL)
- hChild=m_mytree.InsertItem(GetName(curid),0,1,TVI_ROOT,TVI_LAST);
- else
- hChild=m_mytree.InsertItem(GetName(curid),0,1,hParent,TVI_LAST);
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(m_List1array.ElementAt(i).ElementAt(1)==curid)
- {
- AddChild(m_List1array.ElementAt(i).ElementAt(0), hChild);
- }
- }
- }
- CString FileManage2::GetName(CString id)
- {
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(m_List1array.ElementAt(i).ElementAt(0)==id)
- {
- return m_List1array.ElementAt(i).ElementAt(2);
- }
- }
- }
- CString FileManage2::GetCurSelID(CString &path)
- {
- HTREEITEM hSelectedItem = m_mytree.GetSelectedItem();
- if(hSelectedItem==NULL)
- {
- return "";
- }
- CString m_strSelect;
- while(hSelectedItem)
- {
- m_strSelect="\\"+m_mytree.GetItemText(hSelectedItem)+m_strSelect;
- hSelectedItem=m_mytree.GetParentItem(hSelectedItem);
- }
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(m_List1array.ElementAt(i).ElementAt(1)!="")continue;//不是主则继续
- CString m_strSelect2;
- CString curid=m_List1array.ElementAt(i).ElementAt(0);
- m_strSelect2+="\\"+GetName(curid);
- CStringArray array;
- array.Add(m_strSelect2); array.Add(curid);
- GetChildId(m_strSelect2, curid, &array);
- for(int aa=0; aa<array.GetSize(); aa+=2)
- {
- if(m_strSelect==array.ElementAt(aa))
- {
- path=m_strSelect;
- return array.ElementAt(aa+1);
- }
- }
- continue;
- }
- return "";
- }
- BOOL FileManage2::CheckExist(CString m_strSelect)
- {
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(m_List1array.ElementAt(i).ElementAt(1)!="")continue;//不是主则继续
- CString m_strSelect2;
- CString curid=m_List1array.ElementAt(i).ElementAt(0);
- m_strSelect2+="\\"+GetName(curid);
- CStringArray array;
- array.Add(m_strSelect2); array.Add(curid);
- GetChildId(m_strSelect2, curid, &array);
- for(int aa=0; aa<array.GetSize(); aa+=2)
- {
- if(m_strSelect==array.ElementAt(aa))
- {
- return 1;
- }
- }
- }
- return 0;
- }
- void FileManage2::GetChildId(CString oldstr, CString curid, CStringArray *pArray)
- {
- CString oldstrbak=oldstr;
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- oldstr=oldstrbak;
- if(m_List1array.ElementAt(i).ElementAt(1)==curid)
- {
- CString curid=m_List1array.ElementAt(i).ElementAt(0);
- oldstr+="\\"+GetName(curid);
- GetChildId(oldstr, curid, pArray);
- pArray->Add(oldstr); pArray->Add(curid);
- }
- }
- }
- void FileManage2::OnBUTAddP()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- m_text.TrimLeft();
- m_text.TrimRight();
- if( m_text=="" )return;
- if(m_text.Find("\\")!=-1 || m_text.Find("(")!=-1 || m_text.Find(")")!=-1)
- {
- AfxMessageBox("请不要包含\\,(,)字符", MB_ICONINFORMATION);
- return;
- }
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(m_List1array.ElementAt(i).ElementAt(1)=="")
- {
- if(m_text==m_List1array.ElementAt(i).ElementAt(2))
- {
- AfxMessageBox("已存在该项目!", MB_ICONINFORMATION);
- return;
- }
- }
- }
- CString sql;
- sql.Format("insert into [filemanage]([parent],[name])values('%s','%s')", "", m_text);
- g_sendhead.bsql=1;
- g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
- AfxMessageBox("保存成功!", MB_ICONINFORMATION);
- GetData();
- }
- void FileManage2::OnBUTAddC()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- m_text.TrimLeft();
- m_text.TrimRight();
- if( m_text=="" )return;
- if(m_text.Find("\\")!=-1 || m_text.Find("(")!=-1 || m_text.Find(")")!=-1)
- {
- AfxMessageBox("请不要包含\\,(,)字符", MB_ICONINFORMATION);
- return;
- }
- int pos;
- CString str;
- HTREEITEM hSelectedItem = m_mytree.GetSelectedItem();
- if(hSelectedItem==NULL)
- {
- AfxMessageBox("请先选中上级项目!", MB_ICONINFORMATION);
- return;
- }
- CString path;
- CString parent=GetCurSelID(path);
- if(parent=="")
- {
- AfxMessageBox("出错了!", MB_ICONINFORMATION);
- return;
- }
- path+="\\"+m_text;
- if(CheckExist(path))
- {
- AfxMessageBox("已存在此名称的项目,请重新命名!", MB_ICONINFORMATION);
- return;
- }
- CString sql;
- sql.Format("insert into [filemanage]([parent],[name])values('%s','%s')", parent, m_text);
- g_sendhead.bsql=1;
- g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
- AfxMessageBox("保存成功!", MB_ICONINFORMATION);
- GetData();
- }
- void FileManage2::OnBUTrename()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- m_text.TrimLeft();
- m_text.TrimRight();
- if( m_text=="" )return;
- if(m_text.Find("\\")!=-1 || m_text.Find("(")!=-1 || m_text.Find(")")!=-1)
- {
- AfxMessageBox("请不要包含\\,(,)字符", MB_ICONINFORMATION);
- return;
- }
- CString str;
- HTREEITEM hSelectedItem = m_mytree.GetSelectedItem();
- if(hSelectedItem==NULL)
- {
- AfxMessageBox("请先选中您要改名的项目!", MB_ICONINFORMATION);
- return;
- }
- CString path;
- CString parent=GetCurSelID(path);
- if(parent=="")
- {
- AfxMessageBox("出错了!", MB_ICONINFORMATION);
- return;
- }
- int pos=path.ReverseFind('\\');
- if(pos!=-1)
- path=path.Left(pos+1)+m_text;
- if(CheckExist(path))
- {
- AfxMessageBox("已存在此名称的项目,请重新命名!", MB_ICONINFORMATION);
- return;
- }
- str=m_mytree.GetItemText(hSelectedItem);
- if(AfxMessageBox("是否将'"+str+"'改名为'"+m_text+"'?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
- CString sql;
- sql.Format("update [filemanage] set [name]='%s' where [autoid]=%s",m_text, parent);
- g_sendhead.bsql=1;
- g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
- AfxMessageBox("保存成功!", MB_ICONINFORMATION);
- GetData();
- }
- void FileManage2::GetChildIds(CString curid, CStringArray *pArray)
- {
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(m_List1array.ElementAt(i).ElementAt(1)==curid)
- {
- CString curid=m_List1array.ElementAt(i).ElementAt(0);
- GetChildIds(curid, pArray);
- pArray->Add(curid);
- }
- }
- }
- void FileManage2::OnBUTdel() // 删除;
- {
- // TODO: Add your control notification handler code here
- CString str;
- HTREEITEM hSelectedItem = m_mytree.GetSelectedItem();
- if(hSelectedItem==NULL)
- {
- AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
- return;
- }
- CString path;
- CString parent=GetCurSelID(path);
- if(parent=="")
- {
- AfxMessageBox("出错了!", MB_ICONINFORMATION);
- return;
- }
- str=m_mytree.GetItemText(hSelectedItem);
- if(AfxMessageBox("警告:此操作将删除文件柜'"+str+"'包含其子柜中全部文件,是否继续?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
- CString id=parent;
- CStringArray array;
- array.Add(id);
- GetChildIds(id, &array);
- CString filter,filter2;
- for(int aa=0; aa<array.GetSize(); aa++)
- {
- str.Format(" [autoid]=%s or", array.ElementAt(aa));
- filter+=str;
- str.Format(" [parent]='%s' or", array.ElementAt(aa));
- filter2+=str;
- }
- filter.TrimRight("or");
- filter2.TrimRight("or");
- if(filter.GetLength()>4096)
- {
- AfxMessageBox("一次请删除少一点的项目!", MB_ICONINFORMATION);
- return;
- }
- CString sql;
- sql.Format("delete from [filemanage] where %s***delete from [filemanage2] where %s", filter, filter2);
- g_sendhead.bsql=1;
- g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
- AfxMessageBox("保存成功!", MB_ICONINFORMATION);
- GetData();
- }
|