ProviderDlg.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. // ProviderDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "LYFZIPManage.h"
  5. #include "ProviderDlg.h"
  6. #include "MyMdi.H"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // ProviderDlg
  14. IMPLEMENT_DYNCREATE(ProviderDlg, CFormView)
  15. ProviderDlg::ProviderDlg()
  16. : CFormView(ProviderDlg::IDD)
  17. {
  18. //{{AFX_DATA_INIT(ProviderDlg)
  19. m_id = _T("");
  20. m_name = _T("");
  21. m_address = _T("");
  22. m_phone = _T("");
  23. m_fax = _T("");
  24. m_netaddress = _T("");
  25. m_bz = _T("");
  26. //}}AFX_DATA_INIT
  27. }
  28. ProviderDlg::~ProviderDlg()
  29. {
  30. }
  31. void ProviderDlg::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CFormView::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(ProviderDlg)
  35. DDX_Control(pDX, IDC_LIST2, m_List1);
  36. DDX_Control(pDX, IDC_STATIC1, m_static1);
  37. DDX_Text(pDX, IDC_EDITaddress, m_address);
  38. DDX_Text(pDX, IDC_EDITbz, m_bz);
  39. DDX_Text(pDX, IDC_EDITfax, m_fax);
  40. DDX_Text(pDX, IDC_EDITid, m_id);
  41. DDX_Text(pDX, IDC_EDITname, m_name);
  42. DDX_Text(pDX, IDC_EDITnetaddress, m_netaddress);
  43. DDX_Text(pDX, IDC_EDITphone, m_phone);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(ProviderDlg, CFormView)
  47. //{{AFX_MSG_MAP(ProviderDlg)
  48. ON_BN_CLICKED(IDC_BUTsave, OnBUTsave)
  49. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  50. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  51. ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
  52. ON_BN_CLICKED(IDC_BUTadd, OnBUTadd)
  53. //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // ProviderDlg diagnostics
  57. #ifdef _DEBUG
  58. void ProviderDlg::AssertValid() const
  59. {
  60. CFormView::AssertValid();
  61. }
  62. void ProviderDlg::Dump(CDumpContext& dc) const
  63. {
  64. CFormView::Dump(dc);
  65. }
  66. #endif //_DEBUG
  67. /////////////////////////////////////////////////////////////////////////////
  68. // ProviderDlg message handlers
  69. void ProviderDlg::OnInitialUpdate()
  70. {
  71. CFormView::OnInitialUpdate();
  72. // TODO: Add your specialized code here and/or call the base class
  73. CMyMdi Mdi;
  74. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  75. // Here we create the outbar control using the splitter as its parent
  76. // and setting its id to the first pane.
  77. CRect rc2;
  78. GetWindowRect(rc2);
  79. ::MoveWindow(m_hWnd,g_rc.left,g_rc.top,g_rc.Width(),g_rc.Height(),TRUE);
  80. EnumChildWindows(m_hWnd,(WNDENUMPROC)EnumChildProc,0);
  81. m_static1.SetFont (&g_titlefont);
  82. m_List1.SetHeadings( "供应商编号, 60;供应商名称, 60;地址, 60;电话, 60;传真, 60;网址, 60" );
  83. m_List1.LoadColumnInfo (104);
  84. GetData();
  85. }
  86. void ProviderDlg::FillGrid()
  87. {
  88. m_List1.DeleteAllItems2 ();
  89. int ii=0;
  90. m_List1.m_arLabels.SetSize( m_List1array.GetSize (), 1 );
  91. int count=0;
  92. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  93. {
  94. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  95. }
  96. m_List1.m_arLabels.SetSize(count, 1);
  97. ii=count;
  98. m_List1.m_LabelCount=ii;
  99. m_List1.SetItemCountEx (ii);
  100. OnBUTadd() ;
  101. }
  102. void ProviderDlg::OnBUTclose()
  103. {
  104. // TODO: Add your control notification handler code here
  105. GetParent()->SendMessage(WM_CLOSE);
  106. }
  107. void ProviderDlg::ClearCtrl()
  108. {
  109. m_address = _T("");
  110. m_bz = _T("");
  111. m_fax = _T("");
  112. m_id = _T("");
  113. m_name = _T("");
  114. m_netaddress = _T("");
  115. m_phone = _T("");
  116. UpdateData(false);
  117. }
  118. void ProviderDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  119. {
  120. // TODO: Add your control notification handler code here
  121. ListSelChange();
  122. *pResult = 0;
  123. }
  124. void ProviderDlg::ListSelChange()
  125. {
  126. POSITION pos;
  127. pos=m_List1.GetFirstSelectedItemPosition();
  128. if(pos==NULL)
  129. {OnBUTadd() ;
  130. return;
  131. }
  132. int iItem=m_List1.GetNextSelectedItem(pos);
  133. m_oldid=m_List1.GetItemText (iItem, 0);
  134. m_oldname=m_List1.GetItemText (iItem, 1);
  135. for(int ii=0; ii<m_List1array.GetSize (); ii++)
  136. {
  137. if(m_List1array.ElementAt (ii).ElementAt (0)==m_oldid)
  138. {
  139. m_id = m_List1array.ElementAt (ii).ElementAt (0);
  140. m_name = m_List1array.ElementAt (ii).ElementAt (1);
  141. m_address = m_List1array.ElementAt (ii).ElementAt (2);
  142. m_phone = m_List1array.ElementAt (ii).ElementAt (3);
  143. m_fax = m_List1array.ElementAt (ii).ElementAt (4);
  144. m_netaddress = m_List1array.ElementAt (ii).ElementAt (5);
  145. m_bz = m_List1array.ElementAt (ii).ElementAt (6);
  146. UpdateData(false);
  147. return;
  148. }
  149. }
  150. }
  151. void ProviderDlg::OnBUTadd()
  152. {
  153. // TODO: Add your control notification handler code here
  154. m_oldid.Empty ();
  155. m_oldname.Empty ();
  156. ClearCtrl();
  157. }
  158. void ProviderDlg::OnBUTsave()
  159. {
  160. // TODO: Add your control notification handler code here
  161. UpdateData();
  162. if(m_id.IsEmpty () || m_name.IsEmpty () )
  163. {
  164. AfxMessageBox("资料不全!", MB_ICONINFORMATION);return;
  165. }
  166. CString sql;
  167. if(m_oldid.IsEmpty ())//新增
  168. {
  169. if(IsExist())
  170. {
  171. AfxMessageBox("已有此编号或名称的供应商,请重新输入!", MB_ICONINFORMATION);
  172. return;
  173. }
  174. sql.Format ("insert into gongyingshang(gyid,gyname,addr,tel,fax,netaddress,bz)\
  175. values('%s','%s','%s','%s','%s','%s','%s')", m_id,m_name,m_address,m_phone,m_fax,m_netaddress,m_bz);
  176. sql+=GYS_REF;
  177. g_sendhead.bsql=1;
  178. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  179. GetData();
  180. }
  181. else//修改
  182. {
  183. if(m_oldid!=m_id)
  184. {
  185. if(IsExistID())
  186. {
  187. AfxMessageBox("已有此编号的供应商,请重新输入!", MB_ICONINFORMATION);
  188. return;
  189. }
  190. }
  191. if(m_oldname!=m_name)
  192. {
  193. if(IsExistName())
  194. {
  195. AfxMessageBox("已有此名称的供应商,请重新输入!", MB_ICONINFORMATION);
  196. return;
  197. }
  198. }
  199. sql.Format ("update gongyingshang set gyid='%s',gyname='%s',addr='%s',tel='%s',fax='%s',netaddress='%s',bz='%s' where gyid='%s' ", m_id,m_name,m_address,m_phone,m_fax,m_netaddress,m_bz, m_oldid);
  200. sql+=GYS_REF;
  201. g_sendhead.bsql=1;
  202. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  203. GetData();
  204. }
  205. }
  206. void ProviderDlg::OnBUTdel()
  207. {
  208. // TODO: Add your control notification handler code here
  209. POSITION pos;
  210. pos=m_List1.GetFirstSelectedItemPosition();
  211. if(pos==NULL)
  212. {
  213. return;
  214. }
  215. if(AfxMessageBox("确认删除吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  216. int iItem=m_List1.GetNextSelectedItem(pos);
  217. CString id=m_List1.GetItemText (iItem, 0);
  218. CString sql;
  219. sql.Format ("delete from gongyingshang where gyid='%s' ", id);
  220. sql+=GYS_REF;
  221. g_sendhead.bsql=1;
  222. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  223. GetData();
  224. }
  225. void ProviderDlg::GetData()
  226. {
  227. g_sendhead.bsql=0;
  228. g_sendhead.code[0]=9;
  229. g_sendhead.tabcount=1;
  230. g_pMainWnd->ProcessChatMessageRequest2(9);if(g_bSendOK==0)return;
  231. DataToArray(&m_List1array);
  232. FillGrid();
  233. }
  234. BOOL ProviderDlg::IsExist()
  235. {
  236. for(int i=0; i<m_List1array.GetSize (); i++)
  237. {
  238. if(m_id==m_List1array.ElementAt (i).ElementAt (0))return 1;
  239. if(m_name==m_List1array.ElementAt (i).ElementAt (1))return 1;
  240. }
  241. return 0;
  242. }
  243. BOOL ProviderDlg::IsExistID()
  244. {
  245. for(int i=0; i<m_List1array.GetSize (); i++)
  246. {
  247. if(m_id==m_List1array.ElementAt (i).ElementAt (0))return 1;
  248. }
  249. return 0;
  250. }
  251. BOOL ProviderDlg::IsExistName()
  252. {
  253. for(int i=0; i<m_List1array.GetSize (); i++)
  254. {
  255. if(m_name==m_List1array.ElementAt (i).ElementAt (1))return 1;
  256. }
  257. return 0;
  258. }
  259. BOOL ProviderDlg::PreTranslateMessage(MSG* pMsg)
  260. {
  261. // TODO: Add your specialized code here and/or call the base class
  262. try
  263. {
  264. if(pMsg->message==WM_KEYDOWN)
  265. {
  266. switch (pMsg->wParam)
  267. {
  268. case 0x43: // copy
  269. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  270. {
  271. GetFocus()->SendMessage(WM_COPY);
  272. return TRUE;
  273. }
  274. break;
  275. case 0x56: //Ctrl + V:
  276. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  277. {
  278. GetFocus()->SendMessage(WM_PASTE);
  279. return TRUE;
  280. }
  281. break;
  282. case 0x58: // cut
  283. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  284. {
  285. GetFocus()->SendMessage(WM_CUT);
  286. return TRUE;
  287. }
  288. break;
  289. case 0x5A: //undo
  290. case 0x59: //redo
  291. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  292. {
  293. GetFocus()->SendMessage(WM_UNDO);
  294. return TRUE;
  295. }
  296. break;
  297. }
  298. }
  299. return CFormView::PreTranslateMessage(pMsg);
  300. }
  301. catch(...)
  302. {
  303. }
  304. }