SmsManager/DLG_Corp_Extension.cpp
2025-01-14 10:46:18 +08:00

180 lines
4.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// DLG_Corp_Extension.cpp: 实现文件
//
#include "stdafx.h"
#include "SmsManager.h"
#include "afxdialogex.h"
#include "DLG_Corp_Extension.h"
// DLG_Corp_Extension 对话框
IMPLEMENT_DYNAMIC(DLG_Corp_Extension, CDialogEx)
DLG_Corp_Extension::DLG_Corp_Extension(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_CORP_EXTENSION, pParent)
, m_strCorpName(_T(""))
, m_strDuration(_T(""))
, m_strExpiry(_T(""))
, m_S1(_T(""))
, m_strYWY(_T(""))
, m_tNewExpiry(COleDateTime::GetCurrentTime())
, m_strBZ(_T(""))
, m_strCorpID(_T(""))
{
m_tOvrTime = { 0 };
m_tNewOvrTime = { 0 };
m_lType=0;
m_lCorpID = 0;
}
DLG_Corp_Extension::~DLG_Corp_Extension()
{
}
void DLG_Corp_Extension::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_CORP_EXTENSION_CORPNAME, m_strCorpName);
DDX_CBString(pDX, IDC_CORP_EXTENSION_DURATION, m_strDuration);
DDX_Text(pDX, IDC_CORP_EXTENSION_EXPRIY, m_strExpiry);
DDX_Text(pDX, IDC_CORP_EXTENSION_S1, m_S1);
DDX_Text(pDX, IDC_CORP_EXTENSION_YWY, m_strYWY);
DDX_DateTimeCtrl(pDX, IDC_CORP_EXTENSION_NEWEXPIRY, m_tNewExpiry);
DDX_Control(pDX, IDC_CORP_EXTENSION_DURATION, m_L_Duration);
DDX_Text(pDX, IDC_CORP_HSSMS_BZ, m_strBZ);
DDV_MaxChars(pDX, m_strBZ, 160);
DDX_Text(pDX, IDC_CORP_EXTENSION_CORPID, m_strCorpID);
}
BEGIN_MESSAGE_MAP(DLG_Corp_Extension, CDialogEx)
ON_BN_CLICKED(IDOK, &DLG_Corp_Extension::OnBnClickedOk)
ON_CBN_SELCHANGE(IDC_CORP_EXTENSION_DURATION, &DLG_Corp_Extension::OnSelchangeCorpExtensionDuration)
END_MESSAGE_MAP()
// DLG_Corp_Extension 消息处理程序
void DLG_Corp_Extension::SetData(long lCorpID,CString strCorpName, CString strYWYName, SYSTEMTIME tOvrTime, long lType)
{
m_lCorpID = lCorpID;
m_strCorpName2 = strCorpName;
m_strYWYName2 = strYWYName;
m_tOvrTime = tOvrTime;
m_lType = lType;
}
BOOL DLG_Corp_Extension::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
m_strCorpID.Format(_T("%d"), m_lCorpID);
m_strCorpName = m_strCorpName2;
m_strYWY = m_strYWYName2;
m_strExpiry.Format(_T("%04d.%02d.%02d"), m_tOvrTime.wYear, m_tOvrTime.wMonth, m_tOvrTime.wDay);
if (m_lType == 1)
{
m_S1 = _T("代理商延期");
GetDlgItem(IDC_CORP_EXTENSION_CORPID_S)->SetWindowText(_T("代理商ID"));
}
UpdateData(false);
m_L_Duration.SetCurSel(0);
OnSelchangeCorpExtensionDuration();
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
SYSTEMTIME DLG_Corp_Extension::GetData()
{
return SYSTEMTIME(m_tNewOvrTime);
}
void DLG_Corp_Extension::OnBnClickedOk()
{
if (!UpdateData(true))
return;
m_tNewExpiry.SetDateTime(m_tNewExpiry.GetYear(), m_tNewExpiry.GetMonth(), m_tNewExpiry.GetDay(),23, 59, 59);
if (m_tNewExpiry < COleDateTime::GetCurrentTime())
{
MessageBox(_T("延期后新过期时间不能小于当前日期!"), _T("错误"), MB_ICONWARNING);
return;
}
if (m_tNewExpiry > COleDateTime::GetCurrentTime() + COleDateTimeSpan(366))
{
MessageBox(_T("延期后新过期时间不能超过1年"), _T("错误"), MB_ICONWARNING);
return;
}
m_tNewExpiry.GetAsSystemTime(m_tNewOvrTime);
if (m_strBZ.GetLength() < 4)
{
MessageBox(_T("请录入延期原因!"), _T("错误"), MB_ICONWARNING);
GetDlgItem(IDC_CORP_HSSMS_BZ)->SetFocus();
return;
}
CDialogEx::OnOK();
}
void DLG_Corp_Extension::OnSelchangeCorpExtensionDuration()
{
//计算延期时间
long lDuration = m_L_Duration.GetCurSel();
UpdateData(true);
//1星期;1个月;2个月;3个月;6个月;1年;其它日期;
SYSTEMTIME tNow = { 0 };
tNow = m_tOvrTime;
if (COleDateTime(tNow).GetStatus() == COleDateTime::invalid)
{
GetLocalTime(&tNow);
}
COleDateTime tNewExpiry=COleDateTime(tNow);
WORD wMon = 0;
BOOL bEnable = false;
switch(lDuration)
{
case 0: //1星期
default:
tNewExpiry = tNewExpiry + COleDateTimeSpan(7, 0, 0, 0);
break;
case 1: //1月
case 2: //2月
case 3: //3月
case 4: //6月
if (lDuration == 4)
wMon = 6;
else
wMon = lDuration;
tNow.wYear = tNow.wYear + (tNow.wMonth + wMon) / 12;
tNow.wMonth = (tNow.wMonth + wMon) % 12;
tNewExpiry = COleDateTime(tNow);
break;
case 5: //1年
tNow.wYear = tNow.wYear + 1;
tNewExpiry = COleDateTime(tNow);
break;
case 6: //其它日期
tNewExpiry = tNewExpiry + COleDateTimeSpan(7, 0, 0, 0);
bEnable = true;
break;
}
m_tNewExpiry = tNewExpiry;
tNewExpiry.SetTime(23, 59, 59);
GetDlgItem(IDC_CORP_EXTENSION_NEWEXPIRY)->EnableWindow(bEnable);
UpdateData(false);
}