我想将一些信息加入到数据库表中去,下面是两个函数,
我感觉好像没问题,但当我输入正确的值时,系统却提示我
CHECKIN 只读,我怎么改,谢谢各位!急--在线等
void CCheckInDlg::OnConfirm() 
{
// TODO: Add your control notification handler code here
//签到用户确认信息
CEdit *pEditFirst=(CEdit*)GetDlgItem(IDC_EDIT_EPLOYEEID);
CEdit *pEditSecond=(CEdit*)GetDlgItem(IDC_EDIT_EMPLOYEEIDAGAIN); this->UpdateData(TRUE);
CCheckRecordset rsCheck;
CConfigRecordset rsConfig;
CEmployeeRecordset rsEmployee; //获取时间
CTime CheckInTime = CTime::GetCurrentTime();
CTime TodayTime = CTime::GetCurrentTime();

//判断输入框是否为空
if (m_strEmployeeID == "")
{
MessageBox("第一个员工输入框不能为空!","提示",MB_ICONINFORMATION);
pEditFirst->SetFocus();
return;
}
else if (m_strEmployeeIDAgain == "")
{
MessageBox("第二个员工输入框不能为空!","提示",MB_ICONINFORMATION);
pEditSecond->SetFocus();
return;
}
else
{
//判断输入的员工号是否正确
if (m_strEmployeeID==m_strEmployeeIDAgain)
{
if (rsEmployee.IsValidEmployee(m_strEmployeeIDAgain))
{
if (rsCheck.IsTodayChecked(TodayTime,m_strEmployeeID))
{
MessageBox("今天这个员工已经签到!","提示",MB_ICONINFORMATION);
}
else
{
//从系统表中取出公司规定的上班时间
CTime RegularTime;
if (!(rsConfig.GetRegularTime(RegularTime)))
{
MessageBox("签到失败!","签到错误",MB_ICONINFORMATION);
}
//根据签到时间和tbConfig表中获取的公司上班时间
//以及浮动时间来计算
int State = this->GetCheckState(CheckInTime,RegularTime);
//将员工签到记录增加到tbCheckIn表中
if (rsCheck.AddCheckRecord(m_strEmployeeID,CheckInTime,State))
{
MessageBox("签到成功!","提示",MB_ICONINFORMATION);
}
else
{
MessageBox("签到失败!","提示",MB_ICONINFORMATION);
}
}
}
else//输入员工号不正确
{
::MessageBox(NULL,"输入员工号不正确,请重新输入!","提示"
,MB_ICONINFORMATION);
}
}
else//第一次和第二次输入不同
{
::MessageBox(NULL,"两次输入的员工号不相同,请重新输入!","提示"
,MB_ICONINFORMATION);
}
pEditFirst->SetWindowText("");
pEditSecond->SetWindowText("");
pEditFirst->SetFocus();
}
}bool CCheckRecordset::AddCheckRecord(CString EmployID, CTime &CheckTime, int state)
{
try
{
if (!this->IsOpen())
{
this->Open();
}
}
catch(CDBException *e)
{
AfxMessageBox(e->m_strError);
return false;
} try
{
//利用CRecordset 的RFX机制实现记录字段的赋值
//当CRecordset::Update()函数被调用后,
//CCheckRecordset::DoFieldExchange()函数被调用
//记录字段和类成员变量的值进行交换
this->AddNew();
this->m_EmployeeID = EmployID;
this->m_CheckInTime = CheckTime;
this->m_State = state;
this->Update();
return true;
}
catch(CDBException *e)
{
AfxMessageBox(e->m_strError);
return false;
}
}

解决方案 »

  1.   

    对不起,刚才着急代码很乱,位置稍改了一下,麻烦了
    void CCheckInDlg::OnConfirm() 
    {
    // TODO: Add your control notification handler code here
    //签到用户确认信息
    CEdit *pEditFirst=(CEdit*)GetDlgItem(IDC_EDIT_EPLOYEEID);
    CEdit *pEditSecond=(CEdit*)GetDlgItem(IDC_EDIT_EMPLOYEEIDAGAIN); this->UpdateData(TRUE);
    CCheckRecordset rsCheck;
    CConfigRecordset rsConfig;
    CEmployeeRecordset rsEmployee; //获取时间
    CTime CheckInTime = CTime::GetCurrentTime();
    CTime TodayTime = CTime::GetCurrentTime();

    //判断输入框是否为空
    if (m_strEmployeeID == "")
    {
    MessageBox("第一个员工输入框不能为空!","提示",MB_ICONINFORMATION);
    pEditFirst->SetFocus();
    return;
    }
    else if (m_strEmployeeIDAgain == "")
    {
    MessageBox("第二个员工输入框不能为空!","提示",MB_ICONINFORMATION);
    pEditSecond->SetFocus();
    return;
    }
    else
    {
    //判断输入的员工号是否正确
    if (m_strEmployeeID==m_strEmployeeIDAgain)
    {
    if (rsEmployee.IsValidEmployee(m_strEmployeeIDAgain))
    {
    if (rsCheck.IsTodayChecke(TodayTime,m_strEmployeeID))
    {
    MessageBox("今天这个员工已
                                                     经!","提",MB_ICONINFORMATION);
    }
    else
    {
    //从系统表中取出公司规定的上班时间
    CTime RegularTime;
    if (!(rsConfig.GetRegularTime(RegularTime)))
    {
    MessageBox("签到失败!","签到错          
                                                             误",MB_ICONINFORMATION);
    }
    //根据签到时间和tbConfig表中获取的公司上班时间
    //以及浮动时间来计算
    int State = this->GetCheckState
                                                                (CheckInTime,RegularTime);
    //将员工签到记录增加到tbCheckIn表中
    if (rsCheck.AddCheckRecord
                                                        (m_strEmployeeID,CheckInTime,State))
    {
    MessageBox("签到成功!","提
                                                                      示",MB_ICONINFORMATION);
    }
    else
    {
    MessageBox("签到失败!","提
                                                                     示",MB_ICONINFORMATION);
    }
    }
    }
    else//输入员工号不正确
    {
    ::MessageBox(NULL,"输入员工号不正确,请重新输入!","提示"
    ,MB_ICONINFORMATION);
    }
    }
    else//第一次和第二次输入不同
    {
    ::MessageBox(NULL,"两次输入的员工号不相同,请重新输入!","提示"
    ,MB_ICONINFORMATION);
    }
    pEditFirst->SetWindowText("");
    pEditSecond->SetWindowText("");
    pEditFirst->SetFocus();
    }
    }bool CCheckRecordset::AddCheckRecord(CString EmployID, CTime &CheckTime, int state)
    {
    try
    {
    if (!this->IsOpen())
    {
    this->Open();
    }
    }
    catch(CDBException *e)
    {
    AfxMessageBox(e->m_strError);
    return false;
    } try
    {
    //利用CRecordset 的RFX机制实现记录字段的赋值
    //当CRecordset::Update()函数被调用后,
    //CCheckRecordset::DoFieldExchange()函数被调用
    //记录字段和类成员变量的值进行交换
    this->AddNew();
    this->m_EmployeeID = EmployID;
    this->m_CheckInTime = CheckTime;
    this->m_State = state;
    this->Update();
    return true;
    }
    catch(CDBException *e)
    {
    AfxMessageBox(e->m_strError);
    return false;
    }
    }
      

  2.   

    我觉得是在CCheckRecordset::AddCheckRecord(CString EmployID, CTime &CheckTime, int state)
    这个函数里出的问题
      

  3.   

    this->Open();//如果是两个表就是只读的
      

  4.   

    EmployeeID
    CheckInTime
    这两个字段是组合主键