123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540 |
- // TXSPDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ylgl.h"
- #include "TXSPDlg.h"
- #include "MyMdi.H"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- IMPLEMENT_DYNCREATE(TXSPDlg, MyFormView)
- TXSPDlg::TXSPDlg(): MyFormView(TXSPDlg::IDD)
- {
- m_taoxiid = _T("");
- m_taoxijiage = _T("");
- m_zs = _T("");
- }
- TXSPDlg::~TXSPDlg()
- {
- }
- void TXSPDlg::DoDataExchange(CDataExchange* pDX)
- {
- MyFormView::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_LIST2, m_List2);
- DDX_Control(pDX, IDC_LIST1, m_List1);
- DDX_Control(pDX, IDC_STATIC1, m_static1);
- DDX_Control(pDX, IDC_COMBOtaoxiname, m_combotaoxiname);
- DDX_Text(pDX, IDC_EDITtaoxiid, m_taoxiid);
- DDX_Text(pDX, IDC_EDITtaoxijiage, m_taoxijiage);
- DDX_Text(pDX, IDC_EDITzs, m_zs);
- DDX_Control(pDX, CB_KINDS, m_cbKinds);
- }
- BEGIN_MESSAGE_MAP(TXSPDlg, MyFormView)
- ON_BN_CLICKED(IDC_BUTsave, OnBUTsave)
- ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
- ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
- ON_CBN_SELCHANGE(IDC_COMBOtaoxiname, OnSelchangeCOMBOtaoxiname)
- ON_BN_CLICKED(IDC_BUTspbox, OnBUTspbox)
- ON_WM_TIMER()
- ON_BN_CLICKED(IDC_BUTsave2, OnBUTsave2)
- ON_BN_CLICKED(IDC_BUTdel2, OnBUTdel2)
- ON_BN_CLICKED(IDC_BUTspbox2, OnBUTspbox2)
- ON_BN_CLICKED(IDC_BUTclose2, OnBUTclose2)
- ON_CBN_SELCHANGE(CB_KINDS, OnCbnSelchangeKinds)
- ON_WM_SIZE()
- END_MESSAGE_MAP()
- #ifdef _DEBUG
- void TXSPDlg::AssertValid() const
- {
- MyFormView::AssertValid();
- }
- void TXSPDlg::Dump(CDumpContext& dc) const
- {
- MyFormView::Dump(dc);
- }
- #endif
- void TXSPDlg::OnInitialUpdate()
- {
- MyFormView::OnInitialUpdate();
- CMyMdi Mdi;
- Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
- CRect rc1, rc2;
- GetWindowRect(rc1);
- rc2 = rc1;
- rc1 = g_rc;
- ScreenToClient(&rc1);
- ::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
- EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc, 0);
- m_combotaoxiname.GetWindowRect(rc2);
- ScreenToClient(rc2);
- rc2.bottom += 200;
- m_combotaoxiname.MoveWindow(rc2);
- m_static1.SetFont(&g_titlefont);
- g_sendhead.bsql = 0;
- g_sendhead.code[0] = 6;
- g_sendhead.code[1] = 7;
- g_sendhead.code[2] = 10;
- g_sendhead.code[3] = 4;
- g_sendhead.tabcount = 4;
- g_pMainWnd->ProcessChatMessageRequest2(6);
- if (g_bSendOK == 0)return;
- DataToArray(&m_List1array, &m_List2array, &m_List3array, &m_sparray);
- for (int i = 0; i < m_List1array.GetSize(); i++)
- m_combotaoxiname.AddString(m_List1array.ElementAt(i).ElementAt(1));
- m_List1.InitStyle();
- m_List1.InsertColumn(0, _T("编号"), LVCFMT_LEFT, 80);
- m_List1.InsertColumn(1, _T("商品名称"), LVCFMT_LEFT, 200);
- m_List1.InsertColumn(2, _T("数量"), LVCFMT_LEFT, 60);
- m_List2.InitStyle();
- m_List2.InsertColumn(0, _T("编号"), LVCFMT_LEFT, 80);
- m_List2.InsertColumn(1, _T("商品名称"), LVCFMT_LEFT, 200);
- m_List2.InsertColumn(2, _T("数量"), LVCFMT_LEFT, 60);
- }
- void TXSPDlg::OnSelchangeCOMBOtaoxiname()
- {
- int pos = m_combotaoxiname.GetCurSel();
- if (pos == -1)return;
- m_taoxiid = m_List1array.ElementAt(pos).ElementAt(0);
- m_taoxijiage = m_List1array.ElementAt(pos).ElementAt(2);
- m_zs = m_List1array.ElementAt(pos).ElementAt(3);
- UpdateData(false);
- FillGrid();
- }
- void TXSPDlg::FillGrid()
- {
- m_List1.DeleteAllItems();
- int pos = 0;
- int i = 0;
- for ( i = 0; i < m_List2array.GetSize(); i++)
- {
- if (m_List2array.ElementAt(i).ElementAt(0) != m_taoxiid)continue;
- m_List1.InsertItem(pos, m_List2array.ElementAt(i).ElementAt(1));
- m_List1.SetItemText(pos, 1, GetSPNameFromId(m_List2array.ElementAt(i).ElementAt(1)));
- m_List1.SetItemText(pos, 2, m_List2array.ElementAt(i).ElementAt(2));
- pos++;
- }
- //#ifndef MODERN_VERSION
- #if 0
- for( i=0; i<m_List3array.GetSize (); i++)
- {
- if(m_List3array.ElementAt (i).ElementAt (0)!=m_taoxiid)continue;
- m_List1.InsertItem(pos, m_List3array.ElementAt (i).ElementAt (1));
- m_List1.SetItemText(pos,1, GetSPNameFromId(m_List3array.ElementAt (i).ElementAt (1)));
- m_List1.SetItemText(pos,2, m_List3array.ElementAt (i).ElementAt (2));
- pos++;
- }
- #else
- m_List2.DeleteAllItems();
- pos = 0;
- for (i = 0; i < m_List3array.GetSize(); i++)
- {
- if (m_List3array.ElementAt(i).ElementAt(0) != m_taoxiid)continue;
- m_List2.InsertItem(pos, m_List3array.ElementAt(i).ElementAt(1));
- m_List2.SetItemText(pos, 1, GetSPNameFromId(m_List3array.ElementAt(i).ElementAt(1)));
- m_List2.SetItemText(pos, 2, m_List3array.ElementAt(i).ElementAt(2));
- pos++;
- }
- #endif
- }
- CString TXSPDlg::GetSPNameFromId(CString id)
- {
- int i = 0;
- for ( i = 0; i < m_sparray.GetSize(); i++)
- {
- if (id == m_sparray.ElementAt(i).ElementAt(0))
- return m_sparray.ElementAt(i).ElementAt(1);
- }
- id.TrimLeft("0");
- for (i = 0; i < m_sparray.GetSize(); i++)
- {
- if (id == m_sparray.ElementAt(i).ElementAt(0))
- return m_sparray.ElementAt(i).ElementAt(1);
- }
- return "";
- }
- BOOL TXSPDlg::PreTranslateMessage(MSG* pMsg)
- {
- if (pMsg->message == WM_KEYDOWN)
- {
- switch (pMsg->wParam)
- {
- case 0x43: // copy
- if ((GetKeyState(VK_CONTROL) & 0x80))
- {
- GetFocus()->SendMessage(WM_COPY);
- return TRUE;
- }
- break;
- case 0x56: //Ctrl + V:
- if ((GetKeyState(VK_CONTROL) & 0x80))
- {
- GetFocus()->SendMessage(WM_PASTE);
- return TRUE;
- }
- break;
- case 0x58: // cut
- if ((GetKeyState(VK_CONTROL) & 0x80))
- {
- GetFocus()->SendMessage(WM_CUT);
- return TRUE;
- }
- break;
- case 0x5A: //undo
- case 0x59: //redo
- if ((GetKeyState(VK_CONTROL) & 0x80))
- {
- GetFocus()->SendMessage(WM_UNDO);
- return TRUE;
- }
- break;
- }
- }
- else if (pMsg->message == WM_LBUTTONDBLCLK)
- {
- if (0)
- {//list1
- CPoint pt;
- CRect rc, rc2;
- ::GetCursorPos(&pt);
- m_List1.GetWindowRect(rc2);
- if (rc2.PtInRect(pt) == 0) return MyFormView::PreTranslateMessage(pMsg);
- pt.x -= rc2.left;
- pt.y -= rc2.top;
- POSITION pos;
- pos = m_List1.GetFirstSelectedItemPosition();
- if (pos == NULL)return 1;
- int iItem = m_List1.GetNextSelectedItem(pos);
- m_List1.GetSubItemRect(iItem, 2, LVIR_BOUNDS, rc);
- if (rc.PtInRect(pt))
- return MyFormView::PreTranslateMessage(pMsg);
- else
- return 1;
- }
- }
- return MyFormView::PreTranslateMessage(pMsg);
- }
- void TXSPDlg::SetSPName1()
- {
- for (int i = 0; i < m_List1.GetItemCount(); i++)
- {
- m_List1.SetItemText(i, 1, GetSPNameFromId(m_List1.GetItemText(i, 0)));
- }
- }
- void TXSPDlg::SetSPName2()
- {
- for (int i = 0; i < m_List2.GetItemCount(); i++)
- {
- m_List2.SetItemText(i, 1, GetSPNameFromId(m_List2.GetItemText(i, 0)));
- }
- }
- void TXSPDlg::OnTimer(UINT nIDEvent)
- {
- if (nIDEvent == 1)
- {
- KillTimer(nIDEvent);
- SetSPName1();
- }
- else if (nIDEvent == 2)
- {
- KillTimer(nIDEvent);
- SetSPName2();
- }
- }
- void TXSPDlg::OnBUTsave()
- {
- int pos = m_combotaoxiname.GetCurSel();
- if (pos == -1)return;
- CArray<CStringArray, CStringArray>sparray;
- sparray.SetSize(m_List1.GetItemCount());
- int realcount = 0;
- for (int i = 0; i < m_List1.GetItemCount(); i++)
- {
- if (m_List1.GetItemText(i, 0).IsEmpty())continue;
- sparray.ElementAt(realcount).Add(m_List1array.ElementAt(pos).ElementAt(0));
- sparray.ElementAt(realcount).Add(m_List1.GetItemText(i, 0));
- sparray.ElementAt(realcount).Add(m_List1.GetItemText(i, 2));
- realcount++;
- }
- sparray.SetSize(realcount);
- if (realcount == 0)
- {
- sparray.SetSize(1);
- sparray.ElementAt(0).Add(m_List1array.ElementAt(pos).ElementAt(0));
- }
- CMemFile memfile;
- CArchive ar(&memfile, CArchive::store);
- for (int ii = 0; ii < sparray.GetSize(); ii++)
- {
- sparray.ElementAt(ii).Serialize(ar);
- }
- ar.Close();
- int length = memfile.GetLength();
- BYTE *pData = memfile.Detach();
- int size = sparray.GetSize();
- BYTE *pData2 = new BYTE[length + sizeof(int)];
- memcpy(pData2, pData, length);
- memcpy(pData2 + length, &size, sizeof(int));
- delete[]pData;
- length += sizeof(int);
- g_nSendCode = 1;
- g_pMainWnd->ProcessChatMessageRequest2(pData2, length);
- g_nSendCode = 0;
- delete[]pData2;
- if (g_bSendOK == 0)return;
- g_sendhead.bsql = 0;
- g_sendhead.code[0] = 7;
- g_sendhead.code[1] = 10;
- g_sendhead.tabcount = 2;
- g_pMainWnd->ProcessChatMessageRequest2(7); if (g_bSendOK == 0)return;
- DataToArray(&m_List2array, &m_List3array);
- AfxMessageBox("保存成功!", MB_ICONINFORMATION);
- }
- void TXSPDlg::OnBUTdel()
- {
- POSITION pos;
- pos = m_List1.GetFirstSelectedItemPosition();
- if (pos == NULL)
- {
- AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
- return;
- }
- int iItem = m_List1.GetNextSelectedItem(pos);
- m_List1.DeleteItem(iItem);
- int count = m_List1.GetItemCount();
- if (count == 0)return;
- if (iItem == count)
- iItem = 0;
- m_List1.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
- }
- void TXSPDlg::OnBUTspbox()
- {
- SPBox dlg;
- if (dlg.DoModal() != IDOK)return;
- for (int a = 0; a < dlg.m_spidarray.GetSize(); a++)
- {
- dlg.m_spid = dlg.m_spidarray.ElementAt(a);
- dlg.m_spname = dlg.m_spnamearray.ElementAt(a);
- dlg.m_lb = dlg.m_lbarray.ElementAt(a);
- int pos = m_List1.GetItemCount();
- if (pos)
- {
- if (m_List1.GetItemText(pos - 1, 0).IsEmpty() && m_List1.GetItemText(pos - 1, 1).IsEmpty() && m_List1.GetItemText(pos - 1, 2).IsEmpty())
- {
- pos--;
- m_List1.SetItemText(pos, 0, dlg.m_spid);
- m_List1.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
- }
- else
- {
- m_List1.InsertItem(pos, dlg.m_spid);
- m_List1.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
- m_List1.SetItemText(pos, 2, "1");
- }
- }
- else
- {
- m_List1.InsertItem(pos, dlg.m_spid);
- m_List1.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
- m_List1.SetItemText(pos, 2, "1");
- }
- }
- }
- void TXSPDlg::OnBUTclose()
- {
- GetParent()->SendMessage(WM_CLOSE);
- }
- void TXSPDlg::OnBUTsave2()
- {
- int pos = m_combotaoxiname.GetCurSel();
- if (pos == -1)return;
- CArray<CStringArray, CStringArray>sparray;
- sparray.SetSize(m_List2.GetItemCount());
- int realcount = 0;
- for (int i = 0; i < m_List2.GetItemCount(); i++)
- {
- if (m_List2.GetItemText(i, 0).IsEmpty())continue;
- sparray.ElementAt(realcount).Add(m_List1array.ElementAt(pos).ElementAt(0));
- sparray.ElementAt(realcount).Add(m_List2.GetItemText(i, 0));
- sparray.ElementAt(realcount).Add(m_List2.GetItemText(i, 2));
- realcount++;
- }
- sparray.SetSize(realcount);
- if (realcount == 0)
- {
- sparray.SetSize(1);
- sparray.ElementAt(0).Add(m_List1array.ElementAt(pos).ElementAt(0));
- }
- CMemFile memfile;
- CArchive ar(&memfile, CArchive::store);
- for (int ii = 0; ii < sparray.GetSize(); ii++)
- {
- sparray.ElementAt(ii).Serialize(ar);
- }
- ar.Close();
- int length = memfile.GetLength();
- BYTE *pData = memfile.Detach();
- int size = sparray.GetSize();
- BYTE *pData2 = new BYTE[length + sizeof(int)];
- memcpy(pData2, pData, length);
- memcpy(pData2 + length, &size, sizeof(int));
- delete[]pData;
- length += sizeof(int);
- g_nSendCode = 2;
- g_pMainWnd->ProcessChatMessageRequest2(pData2, length);
- g_nSendCode = 0;
- delete[]pData2;
- if (g_bSendOK == 0)return;
- g_sendhead.bsql = 0;
- g_sendhead.code[0] = 7;
- g_sendhead.code[1] = 10;
- g_sendhead.tabcount = 2;
- g_pMainWnd->ProcessChatMessageRequest2(7); if (g_bSendOK == 0)return;
- DataToArray(&m_List2array, &m_List3array);
- AfxMessageBox("保存成功!", MB_ICONINFORMATION);
- }
- void TXSPDlg::OnBUTdel2()
- {
- POSITION pos;
- pos = m_List2.GetFirstSelectedItemPosition();
- if (pos == NULL)
- {
- AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
- return;
- }
- int iItem = m_List2.GetNextSelectedItem(pos);
- m_List2.DeleteItem(iItem);
- int count = m_List2.GetItemCount();
- if (count == 0)return;
- if (iItem == count)
- iItem = 0;
- m_List2.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
- }
- void TXSPDlg::OnBUTspbox2()
- {
- SPBox dlg;
- dlg.m_mode = 1;
- if (dlg.DoModal() != IDOK)return;
- for (int a = 0; a < dlg.m_spidarray.GetSize(); a++)
- {
- dlg.m_spid = dlg.m_spidarray.ElementAt(a);
- dlg.m_spname = dlg.m_spnamearray.ElementAt(a);
- dlg.m_lb = dlg.m_lbarray.ElementAt(a);
- int pos = m_List2.GetItemCount();
- if (pos)
- {
- if (m_List2.GetItemText(pos - 1, 0).IsEmpty() && m_List2.GetItemText(pos - 1, 1).IsEmpty() && m_List2.GetItemText(pos - 1, 2).IsEmpty())
- {
- pos--;
- m_List2.SetItemText(pos, 0, dlg.m_spid);
- m_List2.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
- m_List2.SetItemText(pos, 2, "1");
- }
- else
- {
- m_List2.InsertItem(pos, dlg.m_spid);
- m_List2.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
- m_List2.SetItemText(pos, 2, "1");
- }
- }
- else
- {
- m_List2.InsertItem(pos, dlg.m_spid);
- m_List2.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
- m_List2.SetItemText(pos, 2, "1");
- }
- }
- }
- void TXSPDlg::OnBUTclose2()
- {
- GetParent()->SendMessage(WM_CLOSE);
- }
- void TXSPDlg::OnCbnSelchangeKinds()
- {
- }
- BOOL CALLBACK TXSPDlg::EnumChildProc1(HWND hwnd, LPARAM lParam)
- {
- CSize sz = (CSize)lParam;
- CRect rtCtrl, rtWnd; // 子窗口,父窗口;
- if (hwnd)
- {
- ::GetWindowRect(hwnd, &rtCtrl); // 获取控件大小;
- ::GetWindowRect(::GetParent(hwnd), &rtWnd); // 获取父窗口大小;
- ((CWnd*)hwnd)->ScreenToClient(rtCtrl);
- rtCtrl.left += g_rc.left;
- rtCtrl.top += g_rc.top;
- rtCtrl.right += sz.cx;
- rtCtrl.bottom += sz.cy;
- ::MoveWindow(hwnd, rtCtrl.left, rtCtrl.top, rtCtrl.Width(), rtCtrl.Height(), TRUE);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- // 从OnSize中可以获取两个坐标:1.原始的, 2.最后的;
- // 1.原始的:第一次的Get cx,cy;
- // 2.最后的:最后一次Get cx,cy;
- void TXSPDlg::OnSize(UINT nType, int cx, int cy)
- {
- MyFormView::OnSize(nType, cx, cy);
- static BOOL bDeal = FALSE;
- static CRect FirstRect(g_rc.left, g_rc.top, g_rc.left + cx, g_rc.top + cy); // 移动到g_rc后的原始屏幕坐标;
- static CRect LastWindowRect( g_rc.left, g_rc.top, g_rc.right, g_rc.bottom );
- if ( bDeal == FALSE)
- {
- m_rcOld = FirstRect;
- bDeal = TRUE;
- }
- }
|