// ShowHisSalary.cpp : implementation file
//

#include "stdafx.h"
#include "ylgl.h"
#include "ShowHisSalary.h"

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

/////////////////////////////////////////////////////////////////////////////
// ShowHisSalary dialog


ShowHisSalary::ShowHisSalary(CWnd* pParent /*=NULL*/)
	: CDialog(ShowHisSalary::IDD, pParent)
{
	//{{AFX_DATA_INIT(ShowHisSalary)
	m_filter = _T("");
	m_year = atoi(g_date.Mid(0, 4));
	m_month = atoi(g_date.Mid(5, 2));
	m_bInit = 0;
	//}}AFX_DATA_INIT
}

void ShowHisSalary::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(ShowHisSalary)
	DDX_Control(pDX, IDC_SPIN2, m_spinmonth);
	DDX_Control(pDX, IDC_SPIN1, m_spinyear);
	DDX_Control(pDX, IDC_LIST1, m_List1);
	DDX_Text(pDX, IDC_EDIT1, m_filter);
	DDX_Text(pDX, IDC_EDITyear, m_year);
	DDV_MinMaxUInt(pDX, m_year, 1900, 3000);
	DDX_Text(pDX, IDC_EDITmonth, m_month);
	DDV_MinMaxUInt(pDX, m_month, 1, 12);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(ShowHisSalary, CDialog)
	//{{AFX_MSG_MAP(ShowHisSalary)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_EN_CHANGE(IDC_EDITyear, OnChangeEDITyear)
	ON_EN_CHANGE(IDC_EDITmonth, OnChangeEDITmonth)
	ON_BN_CLICKED(IDC_BUTclear1, OnBUTclear1)
	ON_BN_CLICKED(IDC_BUTclear2, OnBUTclear2)
	ON_BN_CLICKED(IDC_BUTclear3, OnBUTclear3)
	ON_BN_CLICKED(IDC_BUTclear4, OnBUTclear4)
	ON_BN_CLICKED(IDC_BUTclear5, OnBUTclear5)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// ShowHisSalary message handlers

BOOL ShowHisSalary::OnInitDialog()
{
	CDialog::OnInitDialog();
	// TODO: Add extra initialization here
	if (IsHasRights2new(25) == 0)
	{
		GetDlgItem(IDC_BUTclear1)->EnableWindow(0);
		GetDlgItem(IDC_BUTclear2)->EnableWindow(0);
		GetDlgItem(IDC_BUTclear3)->EnableWindow(0);
		GetDlgItem(IDC_BUTclear4)->EnableWindow(0);
		GetDlgItem(IDC_BUTclear5)->EnableWindow(0);
	}

#ifdef CHILD_VERSION
	m_List1.SetHeadings("������,100;�ҳ�����,100;��������,120;��Ӱ���,120;��ױ���,120;�������,120;�������,120;������,100");
#else
	m_List1.SetHeadings("������,100;�б�����,100;Ů������,120;��Ӱ���,120;��ױ���,120;�������,120;�������,120;������,100" );
#endif
	m_List1.LoadColumnInfo(140);
	m_spinyear.SetRange(1900, 3000);
	m_spinmonth.SetRange(1, 12);
	m_bInit = 1;
	GetData();

	CRect rc2;
	GetWindowRect(rc2);
	::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
	GetClientRect(rc2);
	rc2.top += 40 * g_fscaley;
	m_List1.MoveWindow(rc2);
	int right = rc2.right - 5;
	GetDlgItem(IDC_BUTclear5)->GetWindowRect(rc2);
	int wid = rc2.Width();
	ScreenToClient(rc2);
	rc2.left = right - wid * 1;
	rc2.right = rc2.left + wid;
	GetDlgItem(IDC_BUTclear5)->MoveWindow(rc2);
	rc2.left = right - wid * 2;
	rc2.right = rc2.left + wid;
	GetDlgItem(IDC_BUTclear4)->MoveWindow(rc2);
	rc2.left = right - wid * 3;
	rc2.right = rc2.left + wid;
	GetDlgItem(IDC_BUTclear3)->MoveWindow(rc2);
	rc2.left = right - wid * 4;
	rc2.right = rc2.left + wid;
	GetDlgItem(IDC_BUTclear2)->MoveWindow(rc2);
	rc2.left = right - wid * 5;
	rc2.right = rc2.left + wid;
	GetDlgItem(IDC_BUTclear1)->MoveWindow(rc2);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void ShowHisSalary::FillGrid()
{
	if (m_bInit == 0)return;
	UpdateData();
	CString strdate;
	strdate.Format("%d-%02d", m_year, m_month);
	m_List1.DeleteAllItems2();
	int ii = 0;
	m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
	int count = 0;
	if (m_filter.IsEmpty())
	{
		for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
		{
			if (m_List1array.ElementAt(ii).ElementAt(3).Find(strdate) != -1 || \
				m_List1array.ElementAt(ii).ElementAt(4).Find(strdate) != -1 || \
				m_List1array.ElementAt(ii).ElementAt(5).Find(strdate) != -1 || \
				m_List1array.ElementAt(ii).ElementAt(6).Find(strdate) != -1 || \
				m_List1array.ElementAt(ii).ElementAt(7).Find(strdate) != -1)
				m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
		}
	}
	else
	{
		int type = GetType(m_filter);
		if (type == 1)//�绰
		{
			for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
			{
				if (m_List1array.ElementAt(ii).ElementAt(8).Find(m_filter) != -1 || \
					m_List1array.ElementAt(ii).ElementAt(9).Find(m_filter) != -1)
				{
					if (m_List1array.ElementAt(ii).ElementAt(3).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(4).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(5).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(6).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(7).Find(strdate) != -1)
						m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
				}
			}
		}
		else if (type == 2)//ƴ��
		{
			m_filter.MakeUpper();
			for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
			{
				if (m_List1array.ElementAt(ii).ElementAt(10).Find(m_filter) != -1 || \
					m_List1array.ElementAt(ii).ElementAt(11).Find(m_filter) != -1)
				{
					if (m_List1array.ElementAt(ii).ElementAt(3).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(4).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(5).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(6).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(7).Find(strdate) != -1)
						m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
				}
			}
		}
		else
		{
			for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
			{
				if (m_List1array.ElementAt(ii).ElementAt(0).Find(m_filter) != -1 || \
					m_List1array.ElementAt(ii).ElementAt(1).Find(m_filter) != -1 || \
					m_List1array.ElementAt(ii).ElementAt(2).Find(m_filter) != -1)
				{
					if (m_List1array.ElementAt(ii).ElementAt(3).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(4).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(5).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(6).Find(strdate) != -1 || \
						m_List1array.ElementAt(ii).ElementAt(7).Find(strdate) != -1)
						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);
}

void ShowHisSalary::OnButton1()
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_filter.TrimLeft();
	m_filter.TrimRight();
	FillGrid();
}

void ShowHisSalary::OnChangeEDITyear()
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	FillGrid();
	// TODO: Add your control notification handler code here

}

void ShowHisSalary::OnChangeEDITmonth()
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	FillGrid();
	// TODO: Add your control notification handler code here

}

void ShowHisSalary::OnBUTclear1()
{
	// TODO: Add your control notification handler code here
	Clear(1);
}

void ShowHisSalary::OnBUTclear2()
{
	// TODO: Add your control notification handler code here
	Clear(2);
}

void ShowHisSalary::OnBUTclear3()
{
	// TODO: Add your control notification handler code here
	Clear(3);
}

void ShowHisSalary::OnBUTclear4()
{
	// TODO: Add your control notification handler code here
	Clear(4);
}

void ShowHisSalary::OnBUTclear5()
{
	// TODO: Add your control notification handler code here
	Clear(5);
}

void ShowHisSalary::Clear(int selpos)
{
	if (IsHasRights2new(25) == 0)return;
	POSITION pos;
	pos = m_List1.GetFirstSelectedItemPosition();
	if (pos == NULL)
	{
		AfxMessageBox("����ѡ����Ҫ����Ķ���!", MB_ICONINFORMATION);
		return;
	}
	int iItem;
	CStringArray array;
	while (pos)
	{
		iItem = m_List1.GetNextSelectedItem(pos);
		array.Add(m_List1.GetItemText(iItem, 0));
	}
	CString sql, temp;
	for (int i = 0; i < array.GetSize(); i++)
	{
		if (selpos == 1)
			temp = "***update dindan set [tichenren1]='' where [id]='" + array.ElementAt(i) + "'";
		else if (selpos == 2)
			temp = "***update dindan set [tichenren2]='' where [id]='" + array.ElementAt(i) + "'";
		else if (selpos == 3)
			temp = "***update dindan set [tichenren3]='' where [id]='" + array.ElementAt(i) + "'";
		else if (selpos == 4)
			temp = "***update dindan set [tichenren4]='' where [id]='" + array.ElementAt(i) + "'";
		else if (selpos == 5)
			temp = "***update dindan set [tichenren5]='' where [id]='" + array.ElementAt(i) + "'";
		sql += temp;
	}
	sql.TrimLeft("***");
	g_sendhead.bsql = 1;
	g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
	AfxMessageBox("����ɹ�!");
	GetData();
}

void ShowHisSalary::GetData()
{

	CString filter = "[tichenren1]<>'' or [tichenren2]<>'' or [tichenren3]<>'' or [tichenren4]<>'' or [tichenren5]<>''";
	g_sendhead.code[0] = 86;
	g_sendhead.tabcount = 1;
	g_sendhead.bsql = 0;
	g_pMainWnd->ProcessChatMessageRequest2(filter);
	if (g_bSendOK == 0)
	{
		return;
	}
	DataToArray(&m_List1array);
	FillGrid();
}