获取,设置,存储和检索日期 [英] Getting, setting, storing and retrieving dates

查看:56
本文介绍了获取,设置,存储和检索日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再次卡住...:-<我创建了一个COleDateTime变量和一个CString变量,我使用了.Format函数将我的COleDateTime转换为CString.我有一个CStringArray存储我所有的cstring并将它们全部保存到磁盘,但是当我尝试填充表单时,除日期外,所有字符串均显示.我的磁盘文件显示了日期以及所有cstrings.

对此应该如何工作感到非常困惑.

什么是处理日期的适当技术?


[NEW]

这只是我正在使用的代码的一部分,我想将OnBnClickedOrderButton()中的日期设置为具有当前日期的表单(编辑控件),但是当我这样做时,我会得到一个断言错误.我应该在哪里以及如何将日期正确插入数组中?我知道这很模糊,但是我不知道如何创建日期逻辑.

PS:我倾向于考虑问题,这可能很容易解决,但我却难以捉摸.

I stuck...again :-< I created an COleDateTime variable and a CString variable, I used the .Format function to convert my COleDateTime to CString. I have a CStringArray storing all my cstrings and saving them all to disk, but when I try to populate my form all strings show except the date. My disk file shows the date along with all of cstrings.

Very confused about how this should work.

What are the proper techniques for dealing with dates?


[NEW]

Here is just a portion of the code I''m working with, I would like to set the date in my OnBnClickedOrderButton()to the form (EDIT CONTROL) with the current date, but when I do this I get an assertion error. Where and how should I properly insert the date into my array? I know this is vague, but I don''t know how to create the date logic.

PS: I tend to over think things, this is probably very simple to solve, but it eludes me.

//CSpecialOrdersView Construction/Destruction

CSpecialOrdersView::CSpecialOrdersView()
	:CFormView(CSpecialOrdersView::IDD)
	, m_oleDateTime(COleDateTime::GetCurrentTime())
	, m_sOrderDate(_T(""))

void CSpecialOrdersView::OnBnClickedOrderButton()
{
    myDataArray& dataMembers = GetData();
    CEdit* pCtl = &m_wndFirstName;
    CmyData order;
    dataMembers.Add(order);
    m_nDataMember = dataMembers.GetCount() - 1;
    PopulateOrder();
    pCtl->SetFocus();
}

void CSpecialOrdersView::PopulateOrder(void)
{
    myDataArray& dataMembers = GetData();

    m_bSettingData = TRUE;
    
    if(dataMembers.GetCount() > 0)
    {
        m_wndOrderDate.SetWindowTextW(dataMembers[m_nDataMember].m_sOrderDate);
        m_wndOrderDate.EnableWindow(TRUE);
        ....
        ....
        ....

推荐答案

如果希望获得帮助,请发布一些相关代码,并明确指出不起作用的地方.
If you expect help, please post some relevant code and clearly indicate the place where it doesn''t work.


您正在使用统一数据.也许您想这样做(我无法从您的代码部分中确切知道):

You are using unitialized data. Maybe you want to do it this way (I can''t know exactly from your code portions):

// Uninitialized data
CmyData order;
// Initiliaze data
COleDateTime dt(COleDateTime::GetCurrentTime);
order.m_sOrderDate = dt.Format();
// Add data to array
dataMembers.Add(order);
// Get index of added data
m_nDataMember = dataMembers.GetCount() - 1;
// Access just added data
PopulateOrder();


我可能在VS2010中遇到了一个错误.当我试图弄清楚日期逻辑时,我决定看看是否只键入日期,看看它是否可以那样工作,但是不起作用!如此,我删除了编辑框,删除了所有变量,pDX,控件,序列化,类日期成员……与我的设置有关的所有内容,然后重新创建了所有内容.完成此操作后,它就可以正常工作,不确定到底是什么引起了这种行为. STRANGE!?!?

感谢您的输入:-)

DrB
I may have run into a bug in VS2010. As I was trying to figure out my date logic I decided to see if I just type in the date to see if it would work that way, it did not work! Soooo, I removed my edit box deleted all variables, pDX, controls, serialization, class date member...anything to do with my setup and then recreated everything. It works just fine after doing this, not sure exactly what might have caused this kind of behavior. STRANGE!?!?

Thanks for your input :-)

DrB


这篇关于获取,设置,存储和检索日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆