ShowEarlyWarning.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. // ShowEarlyWarning.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ShowEarlyWarning.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // ShowEarlyWarning dialog
  13. ShowEarlyWarning::ShowEarlyWarning(CWnd* pParent /*=NULL*/)
  14. : CDialog(ShowEarlyWarning::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(ShowEarlyWarning)
  17. // NOTE: the ClassWizard will add member initialization here
  18. m_dtdays=0;
  19. m_mode=0;
  20. m_nRet=0;
  21. m_nCheckPos=0;
  22. //}}AFX_DATA_INIT
  23. }
  24. void ShowEarlyWarning::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(ShowEarlyWarning)
  28. DDX_Control(pDX, IDC_LIST2, m_List1);
  29. //}}AFX_DATA_MAP
  30. }
  31. BEGIN_MESSAGE_MAP(ShowEarlyWarning, CDialog)
  32. //{{AFX_MSG_MAP(ShowEarlyWarning)
  33. ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST2, OnCustomdrawList)
  34. //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // ShowEarlyWarning message handlers
  38. BOOL ShowEarlyWarning::OnInitDialog()
  39. {
  40. CDialog::OnInitDialog();
  41. // TODO: Add extra initialization here
  42. m_List1.SetHeadings("编号,100;名称,100;数量,60;已售,60;客人,100;电话,100;数量,60;取件日,100;还件日,100;经手人,100;日期,100");
  43. m_List1.m_bSortSupport =0;
  44. g_sendhead.bsql=0;
  45. g_sendhead.code[0]=222;
  46. g_sendhead.tabcount=1;
  47. g_pMainWnd->ProcessChatMessageRequest2("(hireorsale<>'售' or hireorsale is null) and (isreturn<>'已还' or isreturn is null) and no='"+m_no+"'");
  48. if(g_bSendOK==0)
  49. {
  50. CDialog::OnOK();
  51. return 1;
  52. }
  53. CArray<CStringArray, CStringArray>m_List1array;
  54. DataToArray(&m_List1array);
  55. if(m_List1array.GetSize()==0)
  56. {
  57. m_List1array.SetSize(1, 1);
  58. m_List1array.ElementAt(0).Add(m_no);
  59. m_List1array.ElementAt(0).Add(m_name);
  60. m_List1array.ElementAt(0).Add(m_cot1);
  61. m_List1array.ElementAt(0).Add(m_cot2);
  62. m_List1array.ElementAt(0).Add("当前");
  63. m_List1array.ElementAt(0).Add("..");
  64. m_List1array.ElementAt(0).Add(m_cot3);
  65. m_List1array.ElementAt(0).Add(m_date1);
  66. m_List1array.ElementAt(0).Add("..");
  67. m_List1array.ElementAt(0).Add("..");
  68. m_List1array.ElementAt(0).Add("..");
  69. m_nCheckPos=0;
  70. }
  71. else
  72. {
  73. int size=m_List1array.GetSize();
  74. m_List1array.SetSize(size+1, 1);
  75. BOOL bInsert=0;
  76. for(int i=0; i<size; i++)
  77. {
  78. if(m_List1array.ElementAt(i).ElementAt(7)>m_date1)
  79. {
  80. for(int j=size; j>i; j--)
  81. {
  82. m_List1array.ElementAt(j).Copy(m_List1array.ElementAt(j-1));
  83. }
  84. m_nCheckPos=i;
  85. m_List1array.ElementAt(i).RemoveAll();
  86. m_List1array.ElementAt(i).Add("");
  87. m_List1array.ElementAt(i).Add("..");
  88. m_List1array.ElementAt(i).Add("..");
  89. m_List1array.ElementAt(i).Add("..");
  90. m_List1array.ElementAt(i).Add("当前");
  91. m_List1array.ElementAt(i).Add("..");
  92. m_List1array.ElementAt(i).Add(m_cot3);
  93. m_List1array.ElementAt(i).Add(m_date1);
  94. m_List1array.ElementAt(i).Add(m_date2);
  95. m_List1array.ElementAt(i).Add("..");
  96. m_List1array.ElementAt(i).Add("..");
  97. if(i==0)
  98. {
  99. m_List1array.ElementAt(i).SetAt(0, m_List1array.ElementAt(i+1).ElementAt(0));
  100. m_List1array.ElementAt(i).SetAt(1, m_List1array.ElementAt(i+1).ElementAt(1));
  101. m_List1array.ElementAt(i).SetAt(2, m_List1array.ElementAt(i+1).ElementAt(2));
  102. m_List1array.ElementAt(i).SetAt(3, m_List1array.ElementAt(i+1).ElementAt(3));
  103. m_List1array.ElementAt(i+1).SetAt(0, "");
  104. m_List1array.ElementAt(i+1).SetAt(1, "");
  105. m_List1array.ElementAt(i+1).SetAt(2, "");
  106. m_List1array.ElementAt(i+1).SetAt(3, "");
  107. }
  108. bInsert=1;break;
  109. }
  110. }
  111. if(bInsert==0)
  112. {
  113. m_List1array.ElementAt(size).Add("");
  114. m_List1array.ElementAt(size).Add("..");
  115. m_List1array.ElementAt(size).Add("..");
  116. m_List1array.ElementAt(size).Add("..");
  117. m_List1array.ElementAt(size).Add("当前");
  118. m_List1array.ElementAt(size).Add("..");
  119. m_List1array.ElementAt(size).Add(m_cot3);
  120. m_List1array.ElementAt(size).Add(m_date1);
  121. m_List1array.ElementAt(size).Add(m_date2);
  122. m_List1array.ElementAt(size).Add("..");
  123. m_List1array.ElementAt(size).Add("..");
  124. m_nCheckPos=size;
  125. }
  126. }
  127. CString version = _T ("Version 1.0");
  128. m_dtdays=AfxGetApp()->GetProfileInt (version, "dtdays", 2);
  129. m_List1.DeleteAllItems2 ();
  130. int ii=0;
  131. m_List1.m_arLabels.SetSize( m_List1array.GetSize (), 1 );
  132. int count=0;
  133. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  134. {
  135. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  136. }
  137. m_List1.m_arLabels.SetSize(count, 1);
  138. ii=count;
  139. m_List1.m_LabelCount=ii;
  140. m_List1.SetItemCountEx (ii);
  141. int pos=count-1;
  142. int posbase=pos;
  143. while(m_List1.m_arLabels.ElementAt (posbase).ElementAt (0).IsEmpty ())
  144. {
  145. posbase--;
  146. if(posbase<1)break;
  147. }
  148. int cot=atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (2))-atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (3));
  149. if(posbase==pos)
  150. {
  151. if(atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (6))>cot)
  152. {
  153. if(m_mode)
  154. {
  155. if(pos==m_List1.GetItemCount()-1)
  156. {
  157. m_nRet=1;
  158. }
  159. }
  160. }
  161. else
  162. {
  163. if(m_mode)
  164. {
  165. if(pos==m_List1.GetItemCount()-1)
  166. {
  167. CDialog::OnOK();return 1;
  168. }
  169. }
  170. }
  171. }
  172. else
  173. {
  174. CTimeSpan dt(m_dtdays, 0, 0, 0);
  175. CString time1=m_List1.m_arLabels.ElementAt (pos).ElementAt (7);
  176. CTime taketm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0); //取衣日
  177. CTime todaytm(atoi(g_date.Mid (0,4)),atoi(g_date.Mid (5,2)),atoi(g_date.Mid (8,2)),0,0,0);
  178. todaytm+=dt;
  179. for(int i=posbase; i<pos; i++)
  180. {
  181. time1=m_List1.m_arLabels.ElementAt (i).ElementAt (8);
  182. CTime returntm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0);
  183. if(returntm+dt>=taketm)
  184. cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
  185. // else if(returntm<=todaytm)
  186. // cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
  187. }
  188. int sign1=0;
  189. int sign2=0;
  190. if(cot>=atoi(m_List1.m_arLabels.ElementAt (pos).ElementAt (6)))
  191. {
  192. if(m_mode)
  193. {
  194. if(pos==m_nCheckPos)
  195. {
  196. sign1=1;
  197. //CDialog::OnOK();return 1;
  198. }
  199. if(pos==m_nCheckPos+1)
  200. {
  201. sign2=1;
  202. }
  203. }
  204. }
  205. else
  206. {
  207. if(m_mode)
  208. {
  209. if(pos==m_nCheckPos)
  210. {
  211. sign1=2;
  212. // m_nRet=1;
  213. }
  214. if(pos==m_nCheckPos+1)
  215. {
  216. sign2=2;
  217. }
  218. }
  219. }
  220. if(m_mode)
  221. {
  222. if(m_nCheckPos<m_List1.GetItemCount()-1)
  223. {
  224. if(sign1==1 && sign2==1)
  225. {
  226. CDialog::OnOK();return 1;
  227. }
  228. if(sign1==2 || sign2==2)
  229. {
  230. m_nRet=1;
  231. }
  232. else
  233. {
  234. CDialog::OnOK();return 1;
  235. }
  236. }
  237. else
  238. {
  239. if(sign1==1)
  240. {
  241. CDialog::OnOK();return 1;
  242. }
  243. if(sign1==2)
  244. {
  245. m_nRet=1;
  246. }
  247. }
  248. }
  249. }
  250. return TRUE; // return TRUE unless you set the focus to a control
  251. // EXCEPTION: OCX Property Pages should return FALSE
  252. }
  253. void ShowEarlyWarning::OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult )
  254. {
  255. NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
  256. // Take the default processing unless we set this to something else below.
  257. *pResult = 0;
  258. // First thing - check the draw stage. If it's the control's prepaint
  259. // stage, then tell Windows we want messages for every item.
  260. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
  261. {
  262. *pResult = CDRF_NOTIFYITEMDRAW;
  263. }
  264. else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
  265. {
  266. // This is the prepaint stage for an item. Here's where we set the
  267. // item's text color. Our return value will tell Windows to draw the
  268. // item itself, but it will use the new color we set here.
  269. // We'll cycle the colors through red, green, and light blue.
  270. COLORREF crText;
  271. int pos=pLVCD->nmcd.dwItemSpec;
  272. if(pos%2)
  273. pLVCD->clrTextBk = g_gridcol1;
  274. else
  275. pLVCD->clrTextBk = g_gridcol2;
  276. int posbase=pos;
  277. while(m_List1.m_arLabels.ElementAt (posbase).ElementAt (0).IsEmpty ())
  278. {
  279. posbase--;
  280. if(posbase<1)break;
  281. }
  282. int cot=atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (2))-atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (3));
  283. BOOL bNeedReturn=0;
  284. CTimeSpan dt(m_dtdays, 0, 0, 0);
  285. CTime todaytm(atoi(g_date.Mid (0,4)),atoi(g_date.Mid (5,2)),atoi(g_date.Mid (8,2)),0,0,0);
  286. todaytm+=dt;
  287. if(posbase==pos)
  288. {
  289. if(atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (6))>cot)
  290. crText = RGB(220,0,0);
  291. else
  292. crText = RGB(20,133,20);
  293. pLVCD->clrText = crText;
  294. }
  295. else
  296. {
  297. CTimeSpan dt(m_dtdays, 0, 0, 0);
  298. CString time1=m_List1.m_arLabels.ElementAt (pos).ElementAt (7);
  299. CTime taketm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0); //取衣日
  300. for(int i=posbase; i<pos; i++)
  301. {
  302. time1=m_List1.m_arLabels.ElementAt (i).ElementAt (8);
  303. CTime returntm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0);
  304. if(returntm+dt>=taketm)
  305. cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
  306. // else if(returntm<=todaytm)
  307. // cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
  308. }
  309. if(cot>=atoi(m_List1.m_arLabels.ElementAt (pos).ElementAt (6)))
  310. {
  311. crText = RGB(20,133,20);
  312. }
  313. else
  314. {
  315. crText = RGB(220,0,0);
  316. }
  317. pLVCD->clrText = crText;
  318. }
  319. CString time1=m_List1.m_arLabels.ElementAt (pos).ElementAt (8);
  320. if(time1.GetLength()>5)
  321. {
  322. CTime returntm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0);
  323. bNeedReturn=0;
  324. if(returntm<=todaytm)
  325. bNeedReturn=1;
  326. if(bNeedReturn)
  327. {
  328. crText = RGB(220,0,0);pLVCD->clrText = crText;
  329. }}
  330. // Store the color back in the NMLVCUSTOMDRAW struct.
  331. // Tell Windows to paint the control itself.
  332. *pResult = CDRF_DODEFAULT;
  333. }
  334. }