123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- // ShowEarlyWarning.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ylgl.h"
- #include "ShowEarlyWarning.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // ShowEarlyWarning dialog
- ShowEarlyWarning::ShowEarlyWarning(CWnd* pParent /*=NULL*/)
- : CDialog(ShowEarlyWarning::IDD, pParent)
- {
- //{{AFX_DATA_INIT(ShowEarlyWarning)
- // NOTE: the ClassWizard will add member initialization here
- m_dtdays=0;
- m_mode=0;
- m_nRet=0;
- m_nCheckPos=0;
- //}}AFX_DATA_INIT
- }
- void ShowEarlyWarning::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(ShowEarlyWarning)
- DDX_Control(pDX, IDC_LIST2, m_List1);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(ShowEarlyWarning, CDialog)
- //{{AFX_MSG_MAP(ShowEarlyWarning)
- ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST2, OnCustomdrawList)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // ShowEarlyWarning message handlers
- BOOL ShowEarlyWarning::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_List1.SetHeadings("编号,100;名称,100;数量,60;已售,60;客人,100;电话,100;数量,60;取件日,100;还件日,100;经手人,100;日期,100");
- m_List1.m_bSortSupport =0;
- g_sendhead.bsql=0;
- g_sendhead.code[0]=222;
- g_sendhead.tabcount=1;
- g_pMainWnd->ProcessChatMessageRequest2("(hireorsale<>'售' or hireorsale is null) and (isreturn<>'已还' or isreturn is null) and no='"+m_no+"'");
- if(g_bSendOK==0)
- {
- CDialog::OnOK();
- return 1;
- }
- CArray<CStringArray, CStringArray>m_List1array;
- DataToArray(&m_List1array);
- if(m_List1array.GetSize()==0)
- {
- m_List1array.SetSize(1, 1);
- m_List1array.ElementAt(0).Add(m_no);
- m_List1array.ElementAt(0).Add(m_name);
- m_List1array.ElementAt(0).Add(m_cot1);
- m_List1array.ElementAt(0).Add(m_cot2);
- m_List1array.ElementAt(0).Add("当前");
- m_List1array.ElementAt(0).Add("..");
- m_List1array.ElementAt(0).Add(m_cot3);
- m_List1array.ElementAt(0).Add(m_date1);
- m_List1array.ElementAt(0).Add("..");
- m_List1array.ElementAt(0).Add("..");
- m_List1array.ElementAt(0).Add("..");
- m_nCheckPos=0;
- }
- else
- {
- int size=m_List1array.GetSize();
- m_List1array.SetSize(size+1, 1);
- BOOL bInsert=0;
- for(int i=0; i<size; i++)
- {
- if(m_List1array.ElementAt(i).ElementAt(7)>m_date1)
- {
- for(int j=size; j>i; j--)
- {
- m_List1array.ElementAt(j).Copy(m_List1array.ElementAt(j-1));
- }
- m_nCheckPos=i;
- m_List1array.ElementAt(i).RemoveAll();
- m_List1array.ElementAt(i).Add("");
- m_List1array.ElementAt(i).Add("..");
- m_List1array.ElementAt(i).Add("..");
- m_List1array.ElementAt(i).Add("..");
- m_List1array.ElementAt(i).Add("当前");
- m_List1array.ElementAt(i).Add("..");
- m_List1array.ElementAt(i).Add(m_cot3);
- m_List1array.ElementAt(i).Add(m_date1);
- m_List1array.ElementAt(i).Add(m_date2);
- m_List1array.ElementAt(i).Add("..");
- m_List1array.ElementAt(i).Add("..");
- if(i==0)
- {
- m_List1array.ElementAt(i).SetAt(0, m_List1array.ElementAt(i+1).ElementAt(0));
- m_List1array.ElementAt(i).SetAt(1, m_List1array.ElementAt(i+1).ElementAt(1));
- m_List1array.ElementAt(i).SetAt(2, m_List1array.ElementAt(i+1).ElementAt(2));
- m_List1array.ElementAt(i).SetAt(3, m_List1array.ElementAt(i+1).ElementAt(3));
- m_List1array.ElementAt(i+1).SetAt(0, "");
- m_List1array.ElementAt(i+1).SetAt(1, "");
- m_List1array.ElementAt(i+1).SetAt(2, "");
- m_List1array.ElementAt(i+1).SetAt(3, "");
- }
- bInsert=1;break;
-
- }
- }
- if(bInsert==0)
- {
- m_List1array.ElementAt(size).Add("");
- m_List1array.ElementAt(size).Add("..");
- m_List1array.ElementAt(size).Add("..");
- m_List1array.ElementAt(size).Add("..");
- m_List1array.ElementAt(size).Add("当前");
- m_List1array.ElementAt(size).Add("..");
- m_List1array.ElementAt(size).Add(m_cot3);
- m_List1array.ElementAt(size).Add(m_date1);
- m_List1array.ElementAt(size).Add(m_date2);
- m_List1array.ElementAt(size).Add("..");
- m_List1array.ElementAt(size).Add("..");
- m_nCheckPos=size;
- }
- }
- m_dtdays=AfxGetApp()->GetProfileInt (LYFZVERSION, "dtdays", 2);
-
- m_List1.DeleteAllItems2 ();
- int ii=0;
- m_List1.m_arLabels.SetSize( m_List1array.GetSize (), 1 );
- int count=0;
- for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
- {
- m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
- }
- m_List1.m_arLabels.SetSize(count, 1);
- ii=count;
- m_List1.m_LabelCount=ii;
- m_List1.SetItemCountEx (ii);
-
- int pos=count-1;
-
- int posbase=pos;
- while(m_List1.m_arLabels.ElementAt (posbase).ElementAt (0).IsEmpty ())
- {
- posbase--;
- if(posbase<1)break;
- }
- int cot=atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (2))-atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (3));
- if(posbase==pos)
- {
- if(atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (6))>cot)
- {
- if(m_mode)
- {
- if(pos==m_List1.GetItemCount()-1)
- {
- m_nRet=1;
- }
- }
- }
- else
- {
- if(m_mode)
- {
- if(pos==m_List1.GetItemCount()-1)
- {
- CDialog::OnOK();return 1;
- }
- }
- }
-
- }
- else
- {
- CTimeSpan dt(m_dtdays, 0, 0, 0);
- CString time1=m_List1.m_arLabels.ElementAt (pos).ElementAt (7);
- CTime taketm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0); //取衣日
- CTime todaytm(atoi(g_date.Mid (0,4)),atoi(g_date.Mid (5,2)),atoi(g_date.Mid (8,2)),0,0,0);
- todaytm+=dt;
-
- for(int i=posbase; i<pos; i++)
- {
- time1=m_List1.m_arLabels.ElementAt (i).ElementAt (8);
- CTime returntm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0);
-
- if(returntm+dt>=taketm)
- cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
- // else if(returntm<=todaytm)
- // cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
- }
- int sign1=0;
- int sign2=0;
- if(cot>=atoi(m_List1.m_arLabels.ElementAt (pos).ElementAt (6)))
- {
- if(m_mode)
- {
- if(pos==m_nCheckPos)
- {
- sign1=1;
- //CDialog::OnOK();return 1;
- }
- if(pos==m_nCheckPos+1)
- {
- sign2=1;
- }
- }
- }
- else
- {
-
- if(m_mode)
- {
- if(pos==m_nCheckPos)
- {
- sign1=2;
- // m_nRet=1;
- }
- if(pos==m_nCheckPos+1)
- {
- sign2=2;
- }
- }
- }
- if(m_mode)
- {
- if(m_nCheckPos<m_List1.GetItemCount()-1)
- {
- if(sign1==1 && sign2==1)
- {
- CDialog::OnOK();return 1;
- }
- if(sign1==2 || sign2==2)
- {
- m_nRet=1;
- }
- else
- {
- CDialog::OnOK();return 1;
- }
- }
- else
- {
- if(sign1==1)
- {
- CDialog::OnOK();return 1;
- }
- if(sign1==2)
- {
- m_nRet=1;
- }
- }
- }
-
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void ShowEarlyWarning::OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult )
- {
- NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
- // Take the default processing unless we set this to something else below.
- *pResult = 0;
- // First thing - check the draw stage. If it's the control's prepaint
- // stage, then tell Windows we want messages for every item.
- if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
- {
- *pResult = CDRF_NOTIFYITEMDRAW;
- }
- else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
- {
- // This is the prepaint stage for an item. Here's where we set the
- // item's text color. Our return value will tell Windows to draw the
- // item itself, but it will use the new color we set here.
- // We'll cycle the colors through red, green, and light blue.
- COLORREF crText;
- int pos=pLVCD->nmcd.dwItemSpec;
- if(pos%2)
- pLVCD->clrTextBk = g_gridcol1;
- else
- pLVCD->clrTextBk = g_gridcol2;
- int posbase=pos;
- while(m_List1.m_arLabels.ElementAt (posbase).ElementAt (0).IsEmpty ())
- {
- posbase--;
- if(posbase<1)break;
- }
- int cot=atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (2))-atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (3));
- BOOL bNeedReturn=0;
- CTimeSpan dt(m_dtdays, 0, 0, 0);
- CTime todaytm(atoi(g_date.Mid (0,4)),atoi(g_date.Mid (5,2)),atoi(g_date.Mid (8,2)),0,0,0);
- todaytm+=dt;
-
- if(posbase==pos)
- {
- if(atoi(m_List1.m_arLabels.ElementAt (posbase).ElementAt (6))>cot)
- crText = RGB(220,0,0);
- else
- crText = RGB(20,133,20);
- pLVCD->clrText = crText;
- }
- else
- {
- CTimeSpan dt(m_dtdays, 0, 0, 0);
- CString time1=m_List1.m_arLabels.ElementAt (pos).ElementAt (7);
- CTime taketm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0); //取衣日
-
- for(int i=posbase; i<pos; i++)
- {
- time1=m_List1.m_arLabels.ElementAt (i).ElementAt (8);
- CTime returntm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0);
-
- if(returntm+dt>=taketm)
- cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
- // else if(returntm<=todaytm)
- // cot-=atoi(m_List1.m_arLabels.ElementAt (i).ElementAt (6));
- }
- if(cot>=atoi(m_List1.m_arLabels.ElementAt (pos).ElementAt (6)))
- {
- crText = RGB(20,133,20);
-
- }
- else
- {
- crText = RGB(220,0,0);
-
- }
- pLVCD->clrText = crText;
- }
- CString time1=m_List1.m_arLabels.ElementAt (pos).ElementAt (8);
- if(time1.GetLength()>5)
- {
- CTime returntm(atoi(time1.Mid (0,4)),atoi(time1.Mid (5,2)),atoi(time1.Mid (8,2)),0,0,0);
- bNeedReturn=0;
- if(returntm<=todaytm)
- bNeedReturn=1;
- if(bNeedReturn)
- {
- crText = RGB(220,0,0);pLVCD->clrText = crText;
- }}
- // Store the color back in the NMLVCUSTOMDRAW struct.
-
- // Tell Windows to paint the control itself.
- *pResult = CDRF_DODEFAULT;
- }
- }
|