// ShowMsg.cpp : implementation file
//

#include "stdafx.h"
#include "ylgl.h"
#include "ShowMsg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// ShowMsg dialog
ShowMsg::ShowMsg(CWnd* pParent /*=NULL*/)
	: CDialog(ShowMsg::IDD, pParent)
{
	//{{AFX_DATA_INIT(ShowMsg)
	m_bz2 = _T("");
	m_receivers = _T("");
	m_pos=0;
	//}}AFX_DATA_INIT
 
}

void ShowMsg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(ShowMsg)
	DDX_Text(pDX, IDC_EDIT1, m_bz2);
	DDV_MaxChars(pDX, m_bz2, 1000);
	DDX_Text(pDX, IDC_EDIT2, m_receivers);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(ShowMsg, CDialog)
	//{{AFX_MSG_MAP(ShowMsg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// ShowMsg message handlers

void ShowMsg::OnOK() 
{
	// TODO: Add extra validation here
	CDialog::OnOK();
}

BOOL ShowMsg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	CString str;
	str="������:"+g_List1array.ElementAt (m_pos).ElementAt (0);
	str+=" ����ʱ��:"+g_List1array.ElementAt (m_pos).ElementAt (2);
	str+=" ��������:";
	GetDlgItem(IDC_STATIC1)->SetWindowText(str);
	m_bz2=g_List1array.ElementAt (m_pos).ElementAt (1);
 	m_receivers=g_List1array.ElementAt (m_pos).ElementAt (3);
	UpdateData(false);
	if(g_List1array.GetSize ()==1)
	{	
		GetDlgItem(IDC_BUTTON1)->ShowWindow(0);
		GetDlgItem(IDC_BUTTON2)->ShowWindow(0);
	}
	MarkRead();
	CenterWindow();
	return false;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void ShowMsg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	m_pos--;
	if(m_pos<0)m_pos=g_List1array.GetSize ()-1;

	CString str;
	str="������:"+g_List1array.ElementAt (m_pos).ElementAt (0);
	str+=" ����ʱ��:"+g_List1array.ElementAt (m_pos).ElementAt (2);
	str+=" ��������:";
	GetDlgItem(IDC_STATIC1)->SetWindowText(str);
	m_bz2=g_List1array.ElementAt (m_pos).ElementAt (1);
 	m_receivers=g_List1array.ElementAt (m_pos).ElementAt (3);
	UpdateData(false);
	MarkRead();
}

void ShowMsg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	m_pos++;
	if(m_pos>=g_List1array.GetSize ())m_pos=0;

	CString str;
	str="������:"+g_List1array.ElementAt (m_pos).ElementAt (0);
	str+=" ����ʱ��:"+g_List1array.ElementAt (m_pos).ElementAt (2);
	str+=" ��������:";
	GetDlgItem(IDC_STATIC1)->SetWindowText(str);
	m_bz2=g_List1array.ElementAt (m_pos).ElementAt (1);
 	m_receivers=g_List1array.ElementAt (m_pos).ElementAt (3);
	UpdateData(false);
	MarkRead();
}

void ShowMsg::MarkRead()
{
	CString receivers2,str;
	str=","+g_user.name+",";
	receivers2=g_List1array.ElementAt (m_pos).ElementAt (4);
	receivers2.TrimLeft(",");
	receivers2.TrimRight(",");
	receivers2=","+receivers2+",";

	if(receivers2.Find(str)==-1)
	{
		receivers2.TrimLeft(",");
		receivers2+=str;
        CString sql="update insidemsg set [receiver2]='"+receivers2+"' where [timestamp]='"+g_List1array.ElementAt (m_pos).ElementAt (2)+"' and [sender]='"+g_List1array.ElementAt (m_pos).ElementAt (0)+"'";
        g_sendhead.bsql=1;
	    g_pMainWnd->ProcessChatMessageRequest2(sql);
		if(g_bSendOK==1) 
		{
			g_List1array.ElementAt (m_pos).SetAt (4, receivers2);
		}
	}
}