DlgScanBarCode.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. // DlgScanBarCode.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "YLGL.h"
  5. #include "DlgScanBarCode.h"
  6. #include <Imm.h>
  7. #pragma comment(lib, "Imm32.lib")
  8. // CDlgScanBarCode 对话框
  9. //////////////////////////////////////////////////////////////////////////
  10. IMPLEMENT_DYNAMIC(CEnEdit, CEdit)
  11. CEnEdit::CEnEdit()
  12. {
  13. m_DefaultHKL = GetDefaultKbdLayout();
  14. m_Save_KbdLayout = 0;
  15. m_pParent = NULL;
  16. m_nLines = 0;
  17. m_bLockKbdLayout = TRUE;
  18. }
  19. CEnEdit::~CEnEdit()
  20. {
  21. }
  22. BEGIN_MESSAGE_MAP(CEnEdit, CEdit)
  23. //{{AFX_MSG_MAP(CEditEx)
  24. //}}AFX_MSG_MAP
  25. ON_CONTROL_REFLECT(EN_KILLFOCUS, OnEnKillfocus)
  26. ON_CONTROL_REFLECT(EN_SETFOCUS, OnEnSetfocus)
  27. //ON_WM_CHAR()
  28. ON_WM_CHAR()
  29. END_MESSAGE_MAP()
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CEditEx message handlers
  32. void CEnEdit::OnEnKillfocus()
  33. {
  34. if(m_Save_KbdLayout) //恢复输入法;
  35. {
  36. printf("恢复输入法\n");
  37. if(ActivateKeyboardLayout(m_Save_KbdLayout, 0) == 0)
  38. printf( _T("Restore ActivateKeyboardLayout Err=%d"), GetLastError());
  39. m_Save_KbdLayout = 0;
  40. }
  41. }
  42. void CEnEdit::OnEnSetfocus()
  43. {
  44. if(m_DefaultHKL)
  45. {
  46. HKL CurKbdLayout = GetKeyboardLayout(0);
  47. if(CurKbdLayout != m_DefaultHKL)
  48. {
  49. m_Save_KbdLayout = CurKbdLayout; //保存输入法 ;
  50. if(ActivateKeyboardLayout(m_DefaultHKL, 0) == 0) //设置为默认输入法 ;
  51. {
  52. printf( _T("Set ActivateKeyboardLayout Err=%d"), GetLastError());
  53. }
  54. }
  55. }
  56. }
  57. HKL CEnEdit::GetDefaultKbdLayout()
  58. {
  59. HKL HKL_Ret= 0;
  60. int nSize = GetKeyboardLayoutList(0 , 0);
  61. if(nSize != 0)
  62. {
  63. printf("输入法数量:%d\n", nSize);
  64. HKL FAR * lpList = (HKL FAR *)new HKL[nSize];
  65. ZeroMemory(lpList, sizeof(HKL) * nSize);
  66. if(GetKeyboardLayoutList(nSize, lpList) == nSize)
  67. {
  68. for(int i=0; i<nSize; i++)
  69. {
  70. HKL Val = lpList[i];
  71. if(HIWORD(Val) == LOWORD(Val))
  72. HKL_Ret = Val;
  73. printf( _T("0x%08X/n"), Val);
  74. }
  75. }
  76. delete []lpList;
  77. }
  78. return HKL_Ret;
  79. }
  80. LRESULT CEnEdit::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  81. {
  82. //if(WM_INPUTLANGCHANGEREQUEST == message) //输入法改变;
  83. //printf("==%d,%d,%d\n", message, wParam, lParam);
  84. if ( WM_INPUTLANGCHANGE == message || WM_INPUTLANGCHANGEREQUEST == message)
  85. {
  86. printf("输入法改变\n");
  87. if(m_DefaultHKL)
  88. {
  89. HKL CurKbdLayout = GetKeyboardLayout(0);
  90. if(CurKbdLayout != m_DefaultHKL)
  91. {
  92. printf("设置输入法\n");
  93. m_Save_KbdLayout = CurKbdLayout; //保存输入法 ;
  94. if(ActivateKeyboardLayout(m_DefaultHKL, 0) == 0) //设置为默认输入法 ;
  95. {
  96. printf( _T("Set ActivateKeyboardLayout Err=%d"), GetLastError());
  97. }
  98. }
  99. }
  100. }
  101. /*
  102. if ( message == WM_KEYDOWN && VK_RETURN == wParam)
  103. {
  104. printf("\t回车键\n");
  105. }
  106. */
  107. if ( WM_LBUTTONUP == message )
  108. {// 光标一直在最后;
  109. SetSel(-1);
  110. }
  111. return CEdit::WindowProc(message, wParam, lParam);
  112. }
  113. /*
  114. void CEnEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  115. {
  116. // TODO: 在此添加消息处理程序代码和/或调用默认值
  117. printf("\t键值:%d\n", nChar);
  118. if ( nChar == 13 )
  119. {
  120. ((CDlgScanBarCode*)m_pParent)->DealScanBarCode(m_nLines);
  121. m_nLines++;
  122. }
  123. CEdit::OnChar(nChar, nRepCnt, nFlags);
  124. }
  125. */
  126. //////////////////////////////////////////////////////////////////////////
  127. IMPLEMENT_DYNAMIC(CDlgScanBarCode, CDialog)
  128. CDlgScanBarCode::CDlgScanBarCode(CWnd* pParent /*=NULL*/)
  129. : CDialog(CDlgScanBarCode::IDD, pParent)
  130. {
  131. m_nScanMode = 0;
  132. }
  133. CDlgScanBarCode::~CDlgScanBarCode()
  134. {
  135. }
  136. void CDlgScanBarCode::DoDataExchange(CDataExchange* pDX)
  137. {
  138. CDialog::DoDataExchange(pDX);
  139. DDX_Control(pDX, ET_BARCODE, m_EtBarCode);
  140. DDX_Control(pDX, IDC_LIST1, m_ScanResult);
  141. }
  142. BEGIN_MESSAGE_MAP(CDlgScanBarCode, CDialog)
  143. END_MESSAGE_MAP()
  144. // CDlgScanBarCode 消息处理程序
  145. BOOL CDlgScanBarCode::OnInitDialog()
  146. {
  147. CDialog::OnInitDialog();
  148. // TODO: 在此添加额外的初始化
  149. if ( m_nScanMode == 0 )
  150. {
  151. SetWindowText(_T("请使用条码枪扫描条码来完成回件!"));
  152. }
  153. else
  154. {
  155. SetWindowText(_T("请使用条码枪扫描条码来完成取件!"));
  156. }
  157. // 获取未取件的dindanspview;同时获取shangpin;gongyingshang;dindan;dindansp;
  158. g_sendhead.code[0] = 239;
  159. g_sendhead.code[1] = 240;
  160. g_sendhead.tabcount = 2;
  161. g_sendhead.bsql = 0;
  162. g_pMainWnd->ProcessChatMessageRequest2("");
  163. if ( g_bSendOK == FALSE)
  164. return FALSE;
  165. DataToArray(&m_AryOrderItems, &m_AryOutWarehouse);
  166. m_EtBarCode.m_pParent = this;
  167. m_EtBarCode.SetFocus();
  168. SetWindowPos(&wndTopMost, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
  169. CenterWindow();
  170. InitSortList();
  171. return TRUE; // return TRUE unless you set the focus to a control
  172. // 异常: OCX 属性页应返回 FALSE
  173. }
  174. void CDlgScanBarCode::InitSortList()
  175. {
  176. //m_ScanResult.m_bSortSupport = TRUE;//是否启用列头重新排序;
  177. if ( !m_nScanMode )
  178. m_ScanResult.SetHeadings(CString("回件结果,100;扫描条码,100;订单号,100;商品类别,100;商品名,100;商品数量,100;完成数量,100;取件数量,100;"));
  179. else
  180. m_ScanResult.SetHeadings(CString("取件结果,100;扫描条码,100;订单号,100;商品类别,100;商品名,100;商品数量,100;完成数量,100;取件数量,100;"));
  181. m_ScanResult.LoadColumnInfo(1003);
  182. }
  183. void CDlgScanBarCode::OnOK()
  184. {
  185. // TODO: 在此添加专用代码和/或调用基类
  186. printf("\tOK触发\n");
  187. if (ET_BARCODE == GetFocus()->GetDlgCtrlID() )
  188. {
  189. printf("\t条码回车触发\n");
  190. DealScanBarCode(0);
  191. }
  192. //CDialog::OnOK();
  193. }
  194. void CDlgScanBarCode::DealScanBarCode(const int& nlines)
  195. {
  196. CString strText = _T("");
  197. UpdateData();
  198. #if 0
  199. //GetDlgItemText(ET_BARCODE, strText);
  200. //SetDlgItemText(ET_BARCODE,"");
  201. TCHAR szBuff[1024] = {0};
  202. m_EtBarCode.GetLine(nlines, (LPTSTR)szBuff, 1024);
  203. strText = szBuff;
  204. UpdateData();
  205. #else
  206. GetDlgItemText(ET_BARCODE, strText);
  207. SetDlgItemText(ET_BARCODE, _T(""));
  208. #endif
  209. int i = 0;
  210. CString strAutoId; // 商品的AutoId;
  211. CString strOrder; // 订单号;
  212. CString strSPID; // 商品ID;
  213. CString strPSName; // 商品名称;
  214. CString strSQL, strSQL2;
  215. CString strBackCot;
  216. int nSPCount = 0; // 商品数量;
  217. int nBackCot = 0; // 回件数量;
  218. int nPickupCot = 0; // 取件数量;
  219. int nIndex = -1; // #位置;
  220. int nIndex2 = -1; // \r\n位置;
  221. //CString strTemp;
  222. strText.TrimLeft(_T("#"));
  223. strText.TrimRight(_T("\r"));
  224. // 包含在#和\r\n之间的符号,才是条形码;
  225. OrderItems tagItems;
  226. OrderItems tagOldItem;
  227. OutWarehouse tagOutWarehouse;
  228. OutWarehouse tagOldOutWarehouse;
  229. CTime tm = CTime::GetCurrentTime();
  230. printf("商品AutoId = %s\n", strText);
  231. BOOL bGet = FALSE;
  232. int nListRow = 0;
  233. BOOL bFind = FALSE;
  234. for ( i = 0; i < m_AryOrderItems.GetSize(); i++ )
  235. {
  236. if ( strText.CompareNoCase(m_AryOrderItems.ElementAt(i).ElementAt(1)) == 0 )
  237. { // 找出订单号和商品ID、商品名称;
  238. strOrder = m_AryOrderItems.ElementAt(i).ElementAt(0);
  239. strSPID = m_AryOrderItems.ElementAt(i).ElementAt(2);
  240. strPSName = m_AryOrderItems.ElementAt(i).ElementAt(3);
  241. tagItems.nIndex = i;
  242. tagItems.strOrder = m_AryOrderItems.ElementAt(i).ElementAt(0);
  243. tagItems.strAutoId = m_AryOrderItems.ElementAt(i).ElementAt(1);
  244. tagItems.strSPId = m_AryOrderItems.ElementAt(i).ElementAt(2);
  245. tagItems.strSPName = m_AryOrderItems.ElementAt(i).ElementAt(3);
  246. tagItems.strSPLb = m_AryOrderItems.ElementAt(i).ElementAt(4);
  247. tagItems.strBackStatus = m_AryOrderItems.ElementAt(i).ElementAt(5);
  248. tagItems.strPickupStatus = m_AryOrderItems.ElementAt(i).ElementAt(6);
  249. tagItems.strShuliang = m_AryOrderItems.ElementAt(i).ElementAt(7);
  250. tagItems.strBackCot = m_AryOrderItems.ElementAt(i).ElementAt(8);
  251. tagItems.strPickupCot = m_AryOrderItems.ElementAt(i).ElementAt(9);
  252. tagOldItem = tagItems;
  253. bFind = TRUE;
  254. break;
  255. }
  256. }
  257. if ( !bFind )
  258. {// 没找到产品;
  259. bGet = FALSE;
  260. for ( i = 0; i < m_AryWithOut.GetSize(); i++ )
  261. {
  262. if ( strText.CompareNoCase(m_AryWithOut.ElementAt(i)) == 0 )
  263. {
  264. bGet = TRUE;
  265. break;
  266. }
  267. }
  268. if ( !bGet )
  269. {
  270. m_AryWithOut.Add(strText);
  271. m_ScanResult.AddItem(_T("未找到该产品条码"),strText, "", "", "", "", "","" );
  272. }
  273. return;
  274. }
  275. bGet = FALSE;
  276. int nCurItemIndex = 0;
  277. if ( m_nScanMode == 0 )
  278. {// 扫描回件;
  279. // 登记完成状态;
  280. for ( i = 0; i < m_AryOrderItems.GetSize(); i++ )
  281. {
  282. if ( strText.CompareNoCase(m_AryOrderItems.ElementAt(i).ElementAt(1)) == 0 )
  283. {
  284. if ( m_AryOrderItems.ElementAt(i).ElementAt(5).CompareNoCase("OK") != 0 )
  285. {
  286. tagItems.nIndex = i;
  287. tagOldItem.nIndex = i;
  288. // 完成数量 + 1 == 商品数量 ==> 更新完成状态;
  289. if ( (atoi(m_AryOrderItems.ElementAt(i).ElementAt(7)) - atoi(m_AryOrderItems.ElementAt(i).ElementAt(8))) == 1)
  290. {
  291. strSQL.Format(_T("update dindansp set status1 = 'OK', [name3] = '%s', [date3] = '%s', [BackItemsCot] = '%s' where autoid = %s "), g_user.name, tm.Format("%Y-%m-%d"), m_AryOrderItems.ElementAt(i).ElementAt(7), strText);
  292. m_AryOrderItems.ElementAt(i).SetAt(8, m_AryOrderItems.ElementAt(i).ElementAt(7));
  293. m_AryOrderItems.ElementAt(i).SetAt(5, "OK");
  294. tagItems.strBackCot = m_AryOrderItems.ElementAt(i).ElementAt(7);
  295. tagItems.strBackStatus = _T("OK");
  296. }
  297. else if ( atoi(m_AryOrderItems.ElementAt(i).ElementAt(7)) > atoi(m_AryOrderItems.ElementAt(i).ElementAt(8)) )
  298. {
  299. strSQL.Format(_T("update dindansp set [name3] = '%s', [date3] = '%s', [BackItemsCot] = '%d' where autoid = %s "), g_user.name, tm.Format("%Y-%m-%d"), atoi(m_AryOrderItems.ElementAt(i).ElementAt(8)) + 1, strText);
  300. strBackCot.Format(_T("%d"), atoi(m_AryOrderItems.ElementAt(i).ElementAt(8)) + 1);
  301. m_AryOrderItems.ElementAt(i).SetAt(8, strBackCot);
  302. tagItems.strBackCot = strBackCot;
  303. }
  304. vector<WithIn>::iterator it = m_vtWithIn.begin();
  305. for ( ; it != m_vtWithIn.end(); it++ )
  306. {
  307. if ( strText.CompareNoCase(it->strBarCode) == 0 )
  308. {
  309. bGet = TRUE;
  310. break;
  311. }
  312. }
  313. if ( !bGet )
  314. {
  315. WithIn tagWithIn;
  316. tagWithIn.strBarCode = strText;
  317. tagWithIn.nIndex = m_ScanResult.AddItem(tagItems.strBackStatus, strText, tagItems.strOrder, tagItems.strSPLb, tagItems.strSPName, tagItems.strShuliang, tagItems.strBackCot, tagItems.strPickupCot );
  318. nCurItemIndex = tagWithIn.nIndex;
  319. //tagItems.nIndex = nCurItemIndex;
  320. //tagOldItem.nIndex = nCurItemIndex;
  321. m_vtWithIn.push_back(tagWithIn);
  322. }
  323. else
  324. {
  325. nCurItemIndex = it->nIndex;
  326. //tagItems.nIndex = nCurItemIndex;
  327. //tagOldItem.nIndex = nCurItemIndex;
  328. m_ScanResult.SetItemText(it->nIndex, 0, tagItems.strBackStatus); // 回件状态;
  329. m_ScanResult.SetItemText(it->nIndex, 6, tagItems.strBackCot); // 完成数量;
  330. }
  331. //////////////////////////////////////////////////////////////////////////
  332. // 是否要出库;
  333. if ( atoi(g_cominfoarray.ElementAt(0).ElementAt(99)) == 0 )
  334. {
  335. nSPCount = 0;
  336. //BOOL bHasOutWarehouse = FALSE;
  337. for ( i = 0; i < m_AryOrderItems.GetSize(); i++ )
  338. {// 查找该商品在订单目录下的数量;
  339. if ( m_AryOrderItems.ElementAt(i).ElementAt(0).CompareNoCase(strOrder) == 0 && m_AryOrderItems.ElementAt(i).ElementAt(2).CompareNoCase(strSPID) == 0 )
  340. {
  341. nSPCount += atoi(m_AryOrderItems.ElementAt(i).ElementAt(7)); // 商品数量;
  342. nBackCot += atoi(m_AryOrderItems.ElementAt(i).ElementAt(8)); // 完成数量;
  343. nPickupCot += atoi(m_AryOrderItems.ElementAt(i).ElementAt(9)); // 取件数量;
  344. }
  345. }// for;
  346. // 获取出库数量;
  347. int nOutWarehouseCount = 0;
  348. for ( i = 0; i < m_AryOutWarehouse.GetSize(); i++ )
  349. {
  350. if ( m_AryOutWarehouse.ElementAt(i).ElementAt(0).CompareNoCase(strOrder + _T("(订单使用)")) == 0 && m_AryOutWarehouse.ElementAt(i).ElementAt(2).CompareNoCase(strPSName) == 0 )
  351. {
  352. //bHasOutWarehouse = TRUE;
  353. nOutWarehouseCount += atoi(m_AryOutWarehouse.ElementAt(i).ElementAt(3));
  354. tagOutWarehouse.nIndex = i;
  355. tagOutWarehouse.strOrder = m_AryOutWarehouse.ElementAt(i).ElementAt(0);
  356. tagOutWarehouse.strSPLB = m_AryOutWarehouse.ElementAt(i).ElementAt(1);
  357. tagOutWarehouse.strSPName = m_AryOutWarehouse.ElementAt(i).ElementAt(2);
  358. tagOutWarehouse.strCount = m_AryOutWarehouse.ElementAt(i).ElementAt(3);
  359. tagOutWarehouse.strDate = m_AryOutWarehouse.ElementAt(i).ElementAt(4);
  360. tagOutWarehouse.strClerk = m_AryOutWarehouse.ElementAt(i).ElementAt(5);
  361. tagOutWarehouse.strRemark = m_AryOutWarehouse.ElementAt(i).ElementAt(6);
  362. tagOldOutWarehouse = tagOutWarehouse;
  363. break;
  364. }
  365. }// for;
  366. if ( nOutWarehouseCount == 0 )
  367. {
  368. strSQL2.Format(_T("insert into storeinfo2([id],[type],[name],[count],[date],[clerk])values('%s','%s','%s','%s','%s','%s')"),
  369. strOrder + _T("(订单使用)"),
  370. tagItems.strSPLb,
  371. tagItems.strSPName,
  372. "1",
  373. tm.Format("%Y-%m-%d"),
  374. g_user.name);
  375. strSQL += _T("***") + strSQL2;
  376. // 添加记录;
  377. int nSize = m_AryOutWarehouse.GetSize() + 1;
  378. m_AryOutWarehouse.SetSize(nSize, 1);
  379. m_AryOutWarehouse.ElementAt(nSize - 1).Add(strOrder+_T("(订单使用)"));
  380. m_AryOutWarehouse.ElementAt(nSize - 1).Add(tagItems.strSPLb);
  381. m_AryOutWarehouse.ElementAt(nSize - 1).Add(tagItems.strSPName);
  382. m_AryOutWarehouse.ElementAt(nSize - 1).Add("1");
  383. m_AryOutWarehouse.ElementAt(nSize - 1).Add(tm.Format("%Y-%m-%d"));
  384. m_AryOutWarehouse.ElementAt(nSize - 1).Add(g_user.name);
  385. tagOutWarehouse.nIndex = -1;
  386. tagOutWarehouse.strOrder = strOrder+_T("(订单使用)");
  387. tagOutWarehouse.strSPLB = tagItems.strSPLb;
  388. tagOutWarehouse.strSPName = tagItems.strSPName;
  389. tagOutWarehouse.strCount = "1";
  390. tagOutWarehouse.strDate = tm.Format("%Y-%m-%d");
  391. tagOutWarehouse.strClerk = g_user.name;
  392. tagOutWarehouse.strRemark = _T("");
  393. }
  394. else if ( nOutWarehouseCount < ( nBackCot >= nPickupCot ? nBackCot : nPickupCot) )
  395. {
  396. strBackCot.Format(_T("%d"), ( nBackCot >= nPickupCot ? nBackCot : nPickupCot));
  397. strSQL2.Format(_T("update storeinfo2 set [count] = '%s',[date] = '%s', [clerk] = '%s' where id = '%s' and name = '%s'"),
  398. strBackCot,
  399. tm.Format("%Y-%m-%d"),
  400. g_user.name,
  401. strOrder + _T("(订单使用)"),
  402. strPSName
  403. );
  404. //tagOutWarehouse.strOrder = strOrder+_T("(订单使用)");
  405. //tagOutWarehouse.strSPLB = tagItems.strSPLb;
  406. //tagOutWarehouse.strSPName = tagItems.strSPName;
  407. tagOutWarehouse.strCount = strBackCot;
  408. tagOutWarehouse.strDate = tm.Format("%Y-%m-%d");
  409. tagOutWarehouse.strClerk = g_user.name;
  410. //tagOutWarehouse.strRemark = _T("");
  411. printf("m_AryOutWarehouse = %d\n", m_AryOutWarehouse.GetSize());
  412. m_AryOutWarehouse.ElementAt(i).SetAt(3, strBackCot);
  413. strSQL += _T("***") + strSQL2;
  414. }
  415. break;
  416. }
  417. }
  418. }
  419. } // for;
  420. }
  421. else
  422. {// 扫描取件;
  423. // 登记取件状态;
  424. for ( i = 0; i < m_AryOrderItems.GetSize(); i++ )
  425. {
  426. if ( strText.CompareNoCase(m_AryOrderItems.ElementAt(i).ElementAt(1)) == 0 )
  427. {
  428. if ( m_AryOrderItems.ElementAt(i).ElementAt(6).CompareNoCase("OK") != 0 )
  429. {
  430. tagItems.nIndex = i;
  431. tagOldItem.nIndex = i;
  432. // 取件数量 + 1 == 商品数量 ==> 更新完成状态;
  433. if ( (atoi(m_AryOrderItems.ElementAt(i).ElementAt(7)) - atoi(m_AryOrderItems.ElementAt(i).ElementAt(9))) == 1)
  434. {
  435. strSQL.Format(_T("update dindansp set status2 = 'OK', [name4] = '%s', [date4] = '%s', [PickupItemsCot] = '%s' where autoid = %s "), g_user.name, tm.Format("%Y-%m-%d"), m_AryOrderItems.ElementAt(i).ElementAt(7), strText);
  436. m_AryOrderItems.ElementAt(i).SetAt(9, m_AryOrderItems.ElementAt(i).ElementAt(7));
  437. m_AryOrderItems.ElementAt(i).SetAt(6, "OK");
  438. tagItems.strPickupCot = m_AryOrderItems.ElementAt(i).ElementAt(7);
  439. tagItems.strPickupStatus = _T("OK");
  440. }
  441. else if (atoi(m_AryOrderItems.ElementAt(i).ElementAt(7)) > atoi(m_AryOrderItems.ElementAt(i).ElementAt(9)))
  442. {
  443. strSQL.Format(_T("update dindansp set [name4] = '%s', [date4] = '%s', [PickupItemsCot] = '%d' where autoid = %s "), g_user.name, tm.Format("%Y-%m-%d"), atoi(m_AryOrderItems.ElementAt(i).ElementAt(9)) + 1, strText);
  444. strBackCot.Format(_T("%d"), atoi(m_AryOrderItems.ElementAt(i).ElementAt(9)) + 1);
  445. m_AryOrderItems.ElementAt(i).SetAt(9, strBackCot);
  446. tagItems.strPickupCot = strBackCot;
  447. }
  448. vector<WithIn>::iterator it = m_vtWithIn.begin();
  449. for ( ; it != m_vtWithIn.end(); it++ )
  450. {
  451. if ( strText.CompareNoCase(it->strBarCode) == 0 )
  452. {
  453. bGet = TRUE;
  454. break;
  455. }
  456. }
  457. if ( !bGet )
  458. {
  459. WithIn tagWithIn;
  460. tagWithIn.strBarCode = strText;
  461. tagWithIn.nIndex = m_ScanResult.AddItem(tagItems.strPickupStatus, strText, tagItems.strOrder, tagItems.strSPLb, tagItems.strSPName, tagItems.strShuliang, tagItems.strBackCot, tagItems.strPickupCot );
  462. nCurItemIndex = tagWithIn.nIndex;
  463. //tagItems.nIndex = nCurItemIndex;
  464. //tagOldItem.nIndex = nCurItemIndex;
  465. m_vtWithIn.push_back(tagWithIn);
  466. }
  467. else
  468. {
  469. nCurItemIndex = it->nIndex;
  470. //tagItems.nIndex = nCurItemIndex;
  471. //tagOldItem.nIndex = nCurItemIndex;
  472. m_ScanResult.SetItemText(it->nIndex, 0, tagItems.strPickupStatus); // 取件状态;
  473. m_ScanResult.SetItemText(it->nIndex, 7, tagItems.strPickupCot); // 取件数量;
  474. }
  475. //////////////////////////////////////////////////////////////////////////
  476. // 全部取走,更新订单取件状态;
  477. BOOL bPickupAll = TRUE;
  478. for ( i = 0; i < m_AryOrderItems.GetSize(); i++ )
  479. {
  480. if ( strOrder == m_AryOrderItems.ElementAt(i).ElementAt(0) )
  481. {
  482. if ( m_AryOrderItems.ElementAt(i).ElementAt(6) != "OK")
  483. {
  484. bPickupAll = FALSE;
  485. break;
  486. }
  487. }
  488. }
  489. if ( bPickupAll )
  490. {
  491. strSQL2.Format(_T("update dindan set status3='OK', time5='%s', datetime5 = '%s' where id = '%s'"),tm.Format("%Y-%m-%d"), tm.Format("%H:%M"), strOrder);
  492. strSQL += _T("***") + strSQL2;
  493. }
  494. //////////////////////////////////////////////////////////////////////////
  495. // 是否要出库;
  496. if ( atoi(g_cominfoarray.ElementAt(0).ElementAt(99)) == 0 )
  497. {
  498. nSPCount = 0;
  499. for ( i = 0; i < m_AryOrderItems.GetSize(); i++ )
  500. {// 查找该商品在订单目录下的数量;
  501. if ( m_AryOrderItems.ElementAt(i).ElementAt(0).CompareNoCase(strOrder) == 0 && m_AryOrderItems.ElementAt(i).ElementAt(2).CompareNoCase(strSPID) == 0 )
  502. {
  503. nSPCount += atoi(m_AryOrderItems.ElementAt(i).ElementAt(7)); // 商品数量;
  504. nBackCot += atoi(m_AryOrderItems.ElementAt(i).ElementAt(8)); // 完成数量;
  505. nPickupCot += atoi(m_AryOrderItems.ElementAt(i).ElementAt(9)); // 取件数量;
  506. }
  507. }// for;
  508. // 获取出库数量;
  509. int nOutWarehouseCount = 0;
  510. for ( i = 0; i < m_AryOutWarehouse.GetSize(); i++ )
  511. {
  512. if ( m_AryOutWarehouse.ElementAt(i).ElementAt(0).CompareNoCase(strOrder + _T("(订单使用)")) == 0 && m_AryOutWarehouse.ElementAt(i).ElementAt(2).CompareNoCase(strPSName) == 0 )
  513. {
  514. nOutWarehouseCount += atoi(m_AryOutWarehouse.ElementAt(i).ElementAt(3));
  515. tagOutWarehouse.nIndex = i;
  516. tagOutWarehouse.strOrder = m_AryOutWarehouse.ElementAt(i).ElementAt(0);
  517. tagOutWarehouse.strSPLB = m_AryOutWarehouse.ElementAt(i).ElementAt(1);
  518. tagOutWarehouse.strSPName = m_AryOutWarehouse.ElementAt(i).ElementAt(2);
  519. tagOutWarehouse.strCount = m_AryOutWarehouse.ElementAt(i).ElementAt(3);
  520. tagOutWarehouse.strDate = m_AryOutWarehouse.ElementAt(i).ElementAt(4);
  521. tagOutWarehouse.strClerk = m_AryOutWarehouse.ElementAt(i).ElementAt(5);
  522. tagOutWarehouse.strRemark = m_AryOutWarehouse.ElementAt(i).ElementAt(6);
  523. tagOldOutWarehouse = tagOutWarehouse;
  524. break;
  525. }
  526. }// for;
  527. if ( nOutWarehouseCount == 0 )
  528. {
  529. strSQL2.Format(_T("insert into storeinfo2([id],[type],[name],[count],[date],[clerk])values('%s','%s','%s','%s','%s','%s')"),
  530. strOrder + _T("(订单使用)"),
  531. tagItems.strSPLb,
  532. tagItems.strSPName,
  533. "1",
  534. tm.Format("%Y-%m-%d"),
  535. g_user.name);
  536. strSQL += _T("***") + strSQL2;
  537. // 添加记录;
  538. int nSize = m_AryOutWarehouse.GetSize() + 1;
  539. m_AryOutWarehouse.SetSize(nSize, 1);
  540. m_AryOutWarehouse.ElementAt(nSize - 1).Add(strOrder+_T("(订单使用)"));
  541. m_AryOutWarehouse.ElementAt(nSize - 1).Add(tagItems.strSPLb);
  542. m_AryOutWarehouse.ElementAt(nSize - 1).Add(tagItems.strSPName);
  543. m_AryOutWarehouse.ElementAt(nSize - 1).Add("1");
  544. m_AryOutWarehouse.ElementAt(nSize - 1).Add(tm.Format("%Y-%m-%d"));
  545. m_AryOutWarehouse.ElementAt(nSize - 1).Add(g_user.name);
  546. tagOutWarehouse.nIndex = -1;
  547. tagOutWarehouse.strOrder = strOrder+_T("(订单使用)");
  548. tagOutWarehouse.strSPLB = tagItems.strSPLb;
  549. tagOutWarehouse.strSPName = tagItems.strSPName;
  550. tagOutWarehouse.strCount = "1";
  551. tagOutWarehouse.strDate = tm.Format("%Y-%m-%d");
  552. tagOutWarehouse.strClerk = g_user.name;
  553. tagOutWarehouse.strRemark = _T("");
  554. }
  555. else if ( nOutWarehouseCount < ( nBackCot >= nPickupCot ? nBackCot : nPickupCot) )
  556. {
  557. strBackCot.Format(_T("%d"), ( nBackCot >= nPickupCot ? nBackCot : nPickupCot));
  558. strSQL2.Format(_T("update storeinfo2 set [count] = '%s',[date] = '%s', [clerk] = '%s' where id = '%s' and name = '%s'"),
  559. strBackCot,
  560. tm.Format("%Y-%m-%d"),
  561. g_user.name,
  562. strOrder + _T("(订单使用)"),
  563. strPSName
  564. );
  565. strSQL += _T("***") + strSQL2;
  566. m_AryOutWarehouse.ElementAt(i).SetAt(3, strBackCot);
  567. //tagOutWarehouse.strOrder = strOrder+_T("(订单使用)");
  568. //tagOutWarehouse.strSPLB = tagItems.strSPLb;
  569. //tagOutWarehouse.strSPName = tagItems.strSPName;
  570. tagOutWarehouse.strCount = strBackCot;
  571. tagOutWarehouse.strDate = tm.Format("%Y-%m-%d");
  572. tagOutWarehouse.strClerk = g_user.name;
  573. //tagOutWarehouse.strRemark = _T("");
  574. }
  575. break;
  576. }
  577. }
  578. }
  579. }
  580. }
  581. if ( !strSQL.IsEmpty() )
  582. {
  583. g_sendhead.bsql = 1;
  584. g_pMainWnd->ProcessChatMessageRequest2(strSQL);
  585. if ( !g_bSendOK )
  586. {// 更新失败;
  587. if ( m_nScanMode )
  588. {
  589. m_ScanResult.SetItemText(nCurItemIndex, 0, _T("更新取件失败"));
  590. m_ScanResult.SetItemText(nCurItemIndex, 7, tagOldItem.strPickupCot);
  591. // 是否要出库;
  592. if ( atoi(g_cominfoarray.ElementAt(0).ElementAt(99)) == 0 )
  593. {
  594. if ( tagOutWarehouse.nIndex == -1 && !tagOutWarehouse.strOrder.IsEmpty() )
  595. {// 新元素;
  596. m_AryOutWarehouse.RemoveAt(m_AryOutWarehouse.GetSize() - 1);
  597. }
  598. else
  599. {
  600. m_AryOutWarehouse.ElementAt(tagOutWarehouse.nIndex).SetAt(3, tagOldOutWarehouse.strCount);
  601. m_AryOutWarehouse.ElementAt(tagOutWarehouse.nIndex).SetAt(4, tagOldOutWarehouse.strDate);
  602. m_AryOutWarehouse.ElementAt(tagOutWarehouse.nIndex).SetAt(5, tagOldOutWarehouse.strClerk);
  603. }
  604. }
  605. m_AryOrderItems.ElementAt(tagOldItem.nIndex).SetAt(6, tagOldItem.strPickupStatus); // 取件状态;
  606. m_AryOrderItems.ElementAt(tagOldItem.nIndex).SetAt(9, tagOldItem.strPickupCot); // 取件数量;
  607. }
  608. else
  609. {
  610. m_ScanResult.SetItemText(nCurItemIndex, 0, _T("更新回件失败"));
  611. m_ScanResult.SetItemText(nCurItemIndex, 6, tagOldItem.strBackCot);
  612. // 是否要出库;
  613. if ( atoi(g_cominfoarray.ElementAt(0).ElementAt(99)) == 0 )
  614. {
  615. if ( tagOutWarehouse.nIndex == -1 && !tagOutWarehouse.strOrder.IsEmpty() )
  616. {// 新元素;
  617. m_AryOutWarehouse.RemoveAt(m_AryOutWarehouse.GetSize() - 1);
  618. }
  619. else
  620. {
  621. m_AryOutWarehouse.ElementAt(tagOutWarehouse.nIndex).SetAt(3, tagOldOutWarehouse.strCount);
  622. m_AryOutWarehouse.ElementAt(tagOutWarehouse.nIndex).SetAt(4, tagOldOutWarehouse.strDate);
  623. m_AryOutWarehouse.ElementAt(tagOutWarehouse.nIndex).SetAt(5, tagOldOutWarehouse.strClerk);
  624. }
  625. }
  626. m_AryOrderItems.ElementAt(tagOldItem.nIndex).SetAt(5, tagOldItem.strBackStatus); // 回件状态;
  627. m_AryOrderItems.ElementAt(tagOldItem.nIndex).SetAt(8, tagOldItem.strBackCot); // 回件数量;
  628. }
  629. }
  630. printf("SQL:%s\n", strSQL);
  631. }
  632. }
  633. void CDlgScanBarCode::OnCancel()
  634. {
  635. // 退出扫描时,进行出入库及订单商品状态更新;
  636. CDialog::OnCancel();
  637. }