ShowEarlyWarning.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. m_dtdays=AfxGetApp()->GetProfileInt (LYFZVERSION, "dtdays", 2);
  128. m_List1.DeleteAllItems2 ();
  129. int ii=0;
  130. m_List1.m_arLabels.SetSize( m_List1array.GetSize (), 1 );
  131. int count=0;
  132. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  133. {
  134. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  135. }
  136. m_List1.m_arLabels.SetSize(count, 1);
  137. ii=count;
  138. m_List1.m_LabelCount=ii;
  139. m_List1.SetItemCountEx (ii);
  140. int pos=count-1;
  141. int posbase=pos;
  142. while(m_List1.m_arLabels.ElementAt (posbase).ElementAt (0).IsEmpty ())
  143. {
  144. posbase--;
  145. if(posbase<1)break;
  146. }
  147. int cot=atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (2))-atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (3));
  148. if(posbase==pos)
  149. {
  150. if(atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (6))>cot)
  151. {
  152. if(m_mode)
  153. {
  154. if(pos==m_List1.GetItemCount()-1)
  155. {
  156. m_nRet=1;
  157. }
  158. }
  159. }
  160. else
  161. {
  162. if(m_mode)
  163. {
  164. if(pos==m_List1.GetItemCount()-1)
  165. {
  166. CDialog::OnOK();return 1;
  167. }
  168. }
  169. }
  170. }
  171. else
  172. {
  173. CTimeSpan dt(m_dtdays, 0, 0, 0);
  174. CString time1=m_List1.m_arLabels.ElementAt (pos).ElementAt (7);
  175. CTime taketm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0); //取衣日
  176. CTime todaytm(atoi(g_date.Mid (0,4)),atoi(g_date.Mid (5,2)),atoi(g_date.Mid (8,2)),0,0,0);
  177. todaytm+=dt;
  178. for(int i=posbase; i<pos; i++)
  179. {
  180. time1=m_List1.m_arLabels.ElementAt (i).ElementAt (8);
  181. CTime returntm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0);
  182. if(returntm+dt>=taketm)
  183. cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
  184. // else if(returntm<=todaytm)
  185. // cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
  186. }
  187. int sign1=0;
  188. int sign2=0;
  189. if(cot>=atoi(m_List1.m_arLabels.ElementAt (pos).ElementAt (6)))
  190. {
  191. if(m_mode)
  192. {
  193. if(pos==m_nCheckPos)
  194. {
  195. sign1=1;
  196. //CDialog::OnOK();return 1;
  197. }
  198. if(pos==m_nCheckPos+1)
  199. {
  200. sign2=1;
  201. }
  202. }
  203. }
  204. else
  205. {
  206. if(m_mode)
  207. {
  208. if(pos==m_nCheckPos)
  209. {
  210. sign1=2;
  211. // m_nRet=1;
  212. }
  213. if(pos==m_nCheckPos+1)
  214. {
  215. sign2=2;
  216. }
  217. }
  218. }
  219. if(m_mode)
  220. {
  221. if(m_nCheckPos<m_List1.GetItemCount()-1)
  222. {
  223. if(sign1==1 && sign2==1)
  224. {
  225. CDialog::OnOK();return 1;
  226. }
  227. if(sign1==2 || sign2==2)
  228. {
  229. m_nRet=1;
  230. }
  231. else
  232. {
  233. CDialog::OnOK();return 1;
  234. }
  235. }
  236. else
  237. {
  238. if(sign1==1)
  239. {
  240. CDialog::OnOK();return 1;
  241. }
  242. if(sign1==2)
  243. {
  244. m_nRet=1;
  245. }
  246. }
  247. }
  248. }
  249. return TRUE; // return TRUE unless you set the focus to a control
  250. // EXCEPTION: OCX Property Pages should return FALSE
  251. }
  252. void ShowEarlyWarning::OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult )
  253. {
  254. NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
  255. // Take the default processing unless we set this to something else below.
  256. *pResult = 0;
  257. // First thing - check the draw stage. If it's the control's prepaint
  258. // stage, then tell Windows we want messages for every item.
  259. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
  260. {
  261. *pResult = CDRF_NOTIFYITEMDRAW;
  262. }
  263. else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
  264. {
  265. // This is the prepaint stage for an item. Here's where we set the
  266. // item's text color. Our return value will tell Windows to draw the
  267. // item itself, but it will use the new color we set here.
  268. // We'll cycle the colors through red, green, and light blue.
  269. COLORREF crText;
  270. int pos=pLVCD->nmcd.dwItemSpec;
  271. if(pos%2)
  272. pLVCD->clrTextBk = g_gridcol1;
  273. else
  274. pLVCD->clrTextBk = g_gridcol2;
  275. int posbase=pos;
  276. while(m_List1.m_arLabels.ElementAt (posbase).ElementAt (0).IsEmpty ())
  277. {
  278. posbase--;
  279. if(posbase<1)break;
  280. }
  281. int cot=atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (2))-atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (3));
  282. BOOL bNeedReturn=0;
  283. CTimeSpan dt(m_dtdays, 0, 0, 0);
  284. CTime todaytm(atoi(g_date.Mid (0,4)),atoi(g_date.Mid (5,2)),atoi(g_date.Mid (8,2)),0,0,0);
  285. todaytm+=dt;
  286. if(posbase==pos)
  287. {
  288. if(atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (6))>cot)
  289. crText = RGB(220,0,0);
  290. else
  291. crText = RGB(20,133,20);
  292. pLVCD->clrText = crText;
  293. }
  294. else
  295. {
  296. CTimeSpan dt(m_dtdays, 0, 0, 0);
  297. CString time1=m_List1.m_arLabels.ElementAt (pos).ElementAt (7);
  298. CTime taketm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0); //取衣日
  299. for(int i=posbase; i<pos; i++)
  300. {
  301. time1=m_List1.m_arLabels.ElementAt (i).ElementAt (8);
  302. CTime returntm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0);
  303. if(returntm+dt>=taketm)
  304. cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
  305. // else if(returntm<=todaytm)
  306. // cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
  307. }
  308. if(cot>=atoi(m_List1.m_arLabels.ElementAt (pos).ElementAt (6)))
  309. {
  310. crText = RGB(20,133,20);
  311. }
  312. else
  313. {
  314. crText = RGB(220,0,0);
  315. }
  316. pLVCD->clrText = crText;
  317. }
  318. CString time1=m_List1.m_arLabels.ElementAt (pos).ElementAt (8);
  319. if(time1.GetLength()>5)
  320. {
  321. CTime returntm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0);
  322. bNeedReturn=0;
  323. if(returntm<=todaytm)
  324. bNeedReturn=1;
  325. if(bNeedReturn)
  326. {
  327. crText = RGB(220,0,0);pLVCD->clrText = crText;
  328. }}
  329. // Store the color back in the NMLVCUSTOMDRAW struct.
  330. // Tell Windows to paint the control itself.
  331. *pResult = CDRF_DODEFAULT;
  332. }
  333. }