FileManage2.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. // FileManage2.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. //#include "ZLSoftC.h"
  5. #include "YLGL.h"
  6. #include "FileManage2.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // FileManage2 dialog
  14. FileManage2::FileManage2(CWnd* pParent /*=NULL*/)
  15. : CDialog(FileManage2::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(FileManage2)
  18. m_text = _T("");
  19. //}}AFX_DATA_INIT
  20. }
  21. void FileManage2::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(FileManage2)
  25. DDX_Control(pDX, IDC_TREE1, m_mytree);
  26. DDX_Text(pDX, IDC_EDIT1, m_text);
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(FileManage2, CDialog)
  30. //{{AFX_MSG_MAP(FileManage2)
  31. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
  32. ON_BN_CLICKED(IDC_BUTAddP, OnBUTAddP)
  33. ON_BN_CLICKED(IDC_BUTAddC, OnBUTAddC)
  34. ON_BN_CLICKED(IDC_BUTrename, OnBUTrename)
  35. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // FileManage2 message handlers
  40. BOOL FileManage2::OnInitDialog()
  41. {
  42. CDialog::OnInitDialog();
  43. // SetDlgFont( this );
  44. // TODO: Add extra initialization here
  45. GetDlgItem(IDC_BUTrename)->EnableWindow(IsHasRights2new(49));
  46. GetDlgItem(IDC_BUTdel)->EnableWindow(IsHasRights2new(49));
  47. HICON icon[2];
  48. icon[0]=AfxGetApp()->LoadIcon (IDI_ICON12);
  49. icon[1]=AfxGetApp()->LoadIcon (IDI_ICON13);
  50. CImageList *m_imagelist=new CImageList;
  51. m_imagelist->Create(16,16,0,7,7);
  52. m_imagelist->SetBkColor (RGB(255,255,255));
  53. for(int n=0;n<2;n++)
  54. {
  55. m_imagelist->Add(icon[n]); //把图标载入图像列表控件
  56. }
  57. m_mytree.SetImageList(m_imagelist,TVSIL_NORMAL);
  58. GetData();
  59. CenterWindow();
  60. return TRUE; // return TRUE unless you set the focus to a control
  61. // EXCEPTION: OCX Property Pages should return FALSE
  62. }
  63. void FileManage2::GetData()
  64. {
  65. g_sendhead.bsql=0;
  66. g_sendhead.code[0]=232;
  67. g_sendhead.tabcount=1;
  68. g_pMainWnd->ProcessChatMessageRequest2(1);
  69. if(g_bSendOK==0)return;
  70. DataToArray(&m_List1array);
  71. m_mytree.DeleteAllItems();
  72. for(int i=0; i<m_List1array.GetSize(); i++)
  73. {
  74. if(m_List1array.ElementAt(i).ElementAt(1)=="")
  75. {
  76. AddChild(m_List1array.ElementAt(i).ElementAt(0), NULL);
  77. }
  78. }
  79. }
  80. void FileManage2::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
  81. {
  82. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  83. // TODO: Add your control notification handler code here
  84. HTREEITEM hSelectedItem = m_mytree.GetSelectedItem();
  85. if(hSelectedItem==NULL)
  86. {
  87. //m_curposition="";UpdateData(0);m_curid=-1;
  88. CString str;
  89. str.Format ("当前柜:%s", "");
  90. SetDlgItemText(IDC_STATIC2, str);
  91. return;
  92. } CString str,m_curposition;
  93. GetCurSelID(m_curposition);
  94. str.Format ("当前柜:%s", m_curposition);
  95. SetDlgItemText(IDC_STATIC2, str);
  96. *pResult = 0;
  97. }
  98. void FileManage2::AddChild(CString curid, HTREEITEM hParent)
  99. {
  100. HTREEITEM hChild;
  101. if(hParent==NULL)
  102. hChild=m_mytree.InsertItem(GetName(curid),0,1,TVI_ROOT,TVI_LAST);
  103. else
  104. hChild=m_mytree.InsertItem(GetName(curid),0,1,hParent,TVI_LAST);
  105. for(int i=0; i<m_List1array.GetSize(); i++)
  106. {
  107. if(m_List1array.ElementAt(i).ElementAt(1)==curid)
  108. {
  109. AddChild(m_List1array.ElementAt(i).ElementAt(0), hChild);
  110. }
  111. }
  112. }
  113. CString FileManage2::GetName(CString id)
  114. {
  115. for(int i=0; i<m_List1array.GetSize(); i++)
  116. {
  117. if(m_List1array.ElementAt(i).ElementAt(0)==id)
  118. {
  119. return m_List1array.ElementAt(i).ElementAt(2);
  120. }
  121. }
  122. }
  123. CString FileManage2::GetCurSelID(CString &path)
  124. {
  125. HTREEITEM hSelectedItem = m_mytree.GetSelectedItem();
  126. if(hSelectedItem==NULL)
  127. {
  128. return "";
  129. }
  130. CString m_strSelect;
  131. while(hSelectedItem)
  132. {
  133. m_strSelect="\\"+m_mytree.GetItemText(hSelectedItem)+m_strSelect;
  134. hSelectedItem=m_mytree.GetParentItem(hSelectedItem);
  135. }
  136. for(int i=0; i<m_List1array.GetSize(); i++)
  137. {
  138. if(m_List1array.ElementAt(i).ElementAt(1)!="")continue;//不是主则继续
  139. CString m_strSelect2;
  140. CString curid=m_List1array.ElementAt(i).ElementAt(0);
  141. m_strSelect2+="\\"+GetName(curid);
  142. CStringArray array;
  143. array.Add(m_strSelect2); array.Add(curid);
  144. GetChildId(m_strSelect2, curid, &array);
  145. for(int aa=0; aa<array.GetSize(); aa+=2)
  146. {
  147. if(m_strSelect==array.ElementAt(aa))
  148. {
  149. path=m_strSelect;
  150. return array.ElementAt(aa+1);
  151. }
  152. }
  153. continue;
  154. }
  155. return "";
  156. }
  157. BOOL FileManage2::CheckExist(CString m_strSelect)
  158. {
  159. for(int i=0; i<m_List1array.GetSize(); i++)
  160. {
  161. if(m_List1array.ElementAt(i).ElementAt(1)!="")continue;//不是主则继续
  162. CString m_strSelect2;
  163. CString curid=m_List1array.ElementAt(i).ElementAt(0);
  164. m_strSelect2+="\\"+GetName(curid);
  165. CStringArray array;
  166. array.Add(m_strSelect2); array.Add(curid);
  167. GetChildId(m_strSelect2, curid, &array);
  168. for(int aa=0; aa<array.GetSize(); aa+=2)
  169. {
  170. if(m_strSelect==array.ElementAt(aa))
  171. {
  172. return 1;
  173. }
  174. }
  175. }
  176. return 0;
  177. }
  178. void FileManage2::GetChildId(CString oldstr, CString curid, CStringArray *pArray)
  179. {
  180. CString oldstrbak=oldstr;
  181. for(int i=0; i<m_List1array.GetSize(); i++)
  182. {
  183. oldstr=oldstrbak;
  184. if(m_List1array.ElementAt(i).ElementAt(1)==curid)
  185. {
  186. CString curid=m_List1array.ElementAt(i).ElementAt(0);
  187. oldstr+="\\"+GetName(curid);
  188. GetChildId(oldstr, curid, pArray);
  189. pArray->Add(oldstr); pArray->Add(curid);
  190. }
  191. }
  192. }
  193. void FileManage2::OnBUTAddP()
  194. {
  195. // TODO: Add your control notification handler code here
  196. UpdateData();
  197. m_text.TrimLeft();
  198. m_text.TrimRight();
  199. if( m_text=="" )return;
  200. if(m_text.Find("\\")!=-1 || m_text.Find("(")!=-1 || m_text.Find(")")!=-1)
  201. {
  202. AfxMessageBox("请不要包含\\,(,)字符", MB_ICONINFORMATION);
  203. return;
  204. }
  205. for(int i=0; i<m_List1array.GetSize(); i++)
  206. {
  207. if(m_List1array.ElementAt(i).ElementAt(1)=="")
  208. {
  209. if(m_text==m_List1array.ElementAt(i).ElementAt(2))
  210. {
  211. AfxMessageBox("已存在该项目!", MB_ICONINFORMATION);
  212. return;
  213. }
  214. }
  215. }
  216. CString sql;
  217. sql.Format("insert into [filemanage]([parent],[name])values('%s','%s')", "", m_text);
  218. g_sendhead.bsql=1;
  219. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  220. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  221. GetData();
  222. }
  223. void FileManage2::OnBUTAddC()
  224. {
  225. // TODO: Add your control notification handler code here
  226. UpdateData();
  227. m_text.TrimLeft();
  228. m_text.TrimRight();
  229. if( m_text=="" )return;
  230. if(m_text.Find("\\")!=-1 || m_text.Find("(")!=-1 || m_text.Find(")")!=-1)
  231. {
  232. AfxMessageBox("请不要包含\\,(,)字符", MB_ICONINFORMATION);
  233. return;
  234. }
  235. int pos;
  236. CString str;
  237. HTREEITEM hSelectedItem = m_mytree.GetSelectedItem();
  238. if(hSelectedItem==NULL)
  239. {
  240. AfxMessageBox("请先选中上级项目!", MB_ICONINFORMATION);
  241. return;
  242. }
  243. CString path;
  244. CString parent=GetCurSelID(path);
  245. if(parent=="")
  246. {
  247. AfxMessageBox("出错了!", MB_ICONINFORMATION);
  248. return;
  249. }
  250. path+="\\"+m_text;
  251. if(CheckExist(path))
  252. {
  253. AfxMessageBox("已存在此名称的项目,请重新命名!", MB_ICONINFORMATION);
  254. return;
  255. }
  256. CString sql;
  257. sql.Format("insert into [filemanage]([parent],[name])values('%s','%s')", parent, m_text);
  258. g_sendhead.bsql=1;
  259. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  260. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  261. GetData();
  262. }
  263. void FileManage2::OnBUTrename()
  264. {
  265. // TODO: Add your control notification handler code here
  266. UpdateData();
  267. m_text.TrimLeft();
  268. m_text.TrimRight();
  269. if( m_text=="" )return;
  270. if(m_text.Find("\\")!=-1 || m_text.Find("(")!=-1 || m_text.Find(")")!=-1)
  271. {
  272. AfxMessageBox("请不要包含\\,(,)字符", MB_ICONINFORMATION);
  273. return;
  274. }
  275. CString str;
  276. HTREEITEM hSelectedItem = m_mytree.GetSelectedItem();
  277. if(hSelectedItem==NULL)
  278. {
  279. AfxMessageBox("请先选中您要改名的项目!", MB_ICONINFORMATION);
  280. return;
  281. }
  282. CString path;
  283. CString parent=GetCurSelID(path);
  284. if(parent=="")
  285. {
  286. AfxMessageBox("出错了!", MB_ICONINFORMATION);
  287. return;
  288. }
  289. int pos=path.ReverseFind('\\');
  290. if(pos!=-1)
  291. path=path.Left(pos+1)+m_text;
  292. if(CheckExist(path))
  293. {
  294. AfxMessageBox("已存在此名称的项目,请重新命名!", MB_ICONINFORMATION);
  295. return;
  296. }
  297. str=m_mytree.GetItemText(hSelectedItem);
  298. if(AfxMessageBox("是否将'"+str+"'改名为'"+m_text+"'?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  299. CString sql;
  300. sql.Format("update [filemanage] set [name]='%s' where [autoid]=%s",m_text, parent);
  301. g_sendhead.bsql=1;
  302. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  303. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  304. GetData();
  305. }
  306. void FileManage2::GetChildIds(CString curid, CStringArray *pArray)
  307. {
  308. for(int i=0; i<m_List1array.GetSize(); i++)
  309. {
  310. if(m_List1array.ElementAt(i).ElementAt(1)==curid)
  311. {
  312. CString curid=m_List1array.ElementAt(i).ElementAt(0);
  313. GetChildIds(curid, pArray);
  314. pArray->Add(curid);
  315. }
  316. }
  317. }
  318. void FileManage2::OnBUTdel() // 删除;
  319. {
  320. // TODO: Add your control notification handler code here
  321. CString str;
  322. HTREEITEM hSelectedItem = m_mytree.GetSelectedItem();
  323. if(hSelectedItem==NULL)
  324. {
  325. AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
  326. return;
  327. }
  328. CString path;
  329. CString parent=GetCurSelID(path);
  330. if(parent=="")
  331. {
  332. AfxMessageBox("出错了!", MB_ICONINFORMATION);
  333. return;
  334. }
  335. str=m_mytree.GetItemText(hSelectedItem);
  336. if(AfxMessageBox("警告:此操作将删除文件柜'"+str+"'包含其子柜中全部文件,是否继续?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  337. CString id=parent;
  338. CStringArray array;
  339. array.Add(id);
  340. GetChildIds(id, &array);
  341. CString filter,filter2;
  342. for(int aa=0; aa<array.GetSize(); aa++)
  343. {
  344. str.Format(" [autoid]=%s or", array.ElementAt(aa));
  345. filter+=str;
  346. str.Format(" [parent]='%s' or", array.ElementAt(aa));
  347. filter2+=str;
  348. }
  349. filter.TrimRight("or");
  350. filter2.TrimRight("or");
  351. if(filter.GetLength()>4096)
  352. {
  353. AfxMessageBox("一次请删除少一点的项目!", MB_ICONINFORMATION);
  354. return;
  355. }
  356. CString sql;
  357. sql.Format("delete from [filemanage] where %s***delete from [filemanage2] where %s", filter, filter2);
  358. g_sendhead.bsql=1;
  359. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  360. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  361. GetData();
  362. }