开发者

How to extract the data from Given date to Currentdate in Datetimepicker

I have many folders and there are many data files with different dates. Now if I select the date from my DatePicker, my code extracts the data and extracts the date also and save the date as the name to a txt file (eg. YYYYMMDD.txt, 20110131.txt), which I selcted the date from my DatePicker.

I have more then 2 years data in those files. Each time I select the date to extract the data, it is very hard for me to do that.

If i select the beginning date to current date from my DatePickers, then the data will be extracted from the beginning date until the current date, and save the file name as each date.

Any suggestions?

Here is my code:

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
    {
    }


}


Here is the logic. Lets say, you have taken the datetimepicker for begining date and generate report till date.

User a loop in button2_click code

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

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜