如何在Datetimepicker中提取从给定日期到当前日期的数据

本文关键字:日期 当前日期 数据 Datetimepicker 提取 | 更新日期: 2023-09-27 17:58:02

我有很多文件夹,有很多日期不同的数据文件。现在,如果我从DatePicker中选择日期,我的代码会提取数据并提取日期,并将日期作为名称保存到一个txt文件(例如YYYYMMDD.txt20110131.txt)中,我从DatePixer中选择了日期。

我在这些文件中有超过2年的数据。每次我选择提取数据的日期,我都很难做到这一点。

如果我从DatePickers中选择从开始日期到当前日期,那么数据将从开始日期提取到当前日期为止,并将文件名保存为每个日期。

有什么建议吗?

这是我的代码:

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
    DateTime dt = dateTimePicker1.Value;
    txtSelectedDate.Text = dt.ToString("yyyyMMdd");
    selectedDate = txtSelectedDate.Text;
}

private void button2_Click(object sender, EventArgs e)
{
    string DayBgSpot = "E:''Folder";
    string DayBgSpotDestination = "E:''Folder1";
    int DT = int.Parse(txtSelectedDate.Text);
    FileReader Reader = new FileReader();
    FileReader Reader1 = new FileReader();
    Reader.OpenDirectory(DayBgSpot);
    Reader.ReadNaster();
    string path = DayBgSpotDestination + "''" + txtSelectedDate.Text + ".txt";
    StreamWriter Strwriter = new StreamWriter(path);
    try
    {
        while (Reader.iMaRecordsLeft > 0)
        {
            string SecName = Reader.sMaSecName;
            string Symbol = Reader.sMaSecSymbol;
            Symbol = prefix + Symbol;
            int abc = 0;
            Reader.OpenSecurityByName(Reader.sMaSecName);
            if (Reader.iSeRecords > 0)
            {
                while (Reader.iSeRecordsLeft > 0)
                {
                    Reader.ReadDay();
                    float O = Reader.dSeo;
                    float H = Reader.dSeh;
                    float L = Reader.dSel;
                    float C = Reader.dSec;
                    double V = Reader.dSeV;
                    double OI = Reader.dSrest;
                    string T = Reader.iSeTime.ToString();
                    string D = Reader.iSeDate.ToString();
                    if (int.Parse(D) == DT)
                    {
                        string a = string.Concat(SecName, ",", Symbol, ",", D, ",", T, ",", O, ",", H, ",",  L, ",", C, ",", V, ",", OI);
                        if (SecName != "" && V != 0)
                        {
                            Strwriter.WriteLine(a);
                        }
                    }
                }
            }

            abc++;

            Reader.ReadNaster();
        }
        Reader.CloseDirectory();
        Strwriter.Close();
        Strwriter.Dispose();

    }
    catch
    {
    }

}

如何在Datetimepicker中提取从给定日期到当前日期的数据

这是逻辑。比方说,您已经将日期时间选择器作为开始日期,并生成截止日期的报告。

用户在按钮中循环2_点击代码

DateTime stdate = Datetimepicker1.value;
while (stdate <= DateTime.Now)
{
    txtSelectedDate.Text = stdate.ToString("yyyyMMdd");
    selectedDate = txtSelectedDate.Text;
/* Here use your existing code as it is */
............
.........

stdate = stdate.AddDays (1); // It will get next date till present
}