ProviderDlg.cpp 7.8 KB

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