在遇到异常的一天推进时间戳

时间:2011-06-12 03:17:18

标签: c#

在我的代码中,我可以从文件夹中删除过时的文件。

但是日期必须出现在某些*.dat文件中,否则不会发生任何事情。

有些日子不包含在这些文件中;例如,跳过假期。

在这种情况下,我遇到了一个问题。

所以,如果我在其中一天,我怎么能在失败后进入第二天?

    private void button1_Click(object sender, EventArgs e)
    {
        string Destinationdead = "C:\\test\\test1";

        string todaysDate;
        todaysDate = dateTimePicker1.Text;
        int FinalDate4 = 0;

        BLWriterClass writerdelete1 = new BLWriterClass();

        writerdelete1.OpenDirectory(Destinationdead);
        writerdelete1.OpenSecurityBySymbol(SecSymbol);
        FinalDate4 = int.Parse(todaysDate);

        {
            try
            {
                writerdelete1.OpenDirectory(Destinationdead);
                writerdelete1.OpenSecurityBySymbol(SecSymbolbol);
                FinalDate4 = int.Parse(todaysDate);

                writerdelete1.OpenDirectory(Destinationdead);
                writerdelete1.OpenSecurityBySymbol(SecSymbol);
                int idate = Convert.ToInt32(dateTimePicker1.Text);
                int itodate = Convert.ToInt32(dateTimePicker2.Text);
                writerdelete1.DeleteSecRecords(idate, itodate);
            }
            catch (Exception)
            {

            }
        }
        writerdelete1.CloseSecurity();
        writerdelete1.CloseDirectory();
    }

1 个答案:

答案 0 :(得分:2)

问题在于您的DeleteSecRecords方法。

Google没有显示此名称的匹配,因此无法查看它以进一步分析问题。


编辑:啊,我理解你的要求。只要遇到异常,这将进入第二天,直到没有可能的天数为止。

int idate = Convert.ToInt32(dateTimePicker1.Text);
int itodate = Convert.ToInt32(dateTimePicker2.Text);

while (idate <= itodate) {
    try
    {
        writerdelete1.OpenDirectory(Destinationdead);
        writerdelete1.OpenSecurityBySymbol(SecSymbolbol);
        FinalDate4 = int.Parse(todaysDate);

        writerdelete1.OpenDirectory(Destinationdead);
        writerdelete1.OpenSecurityBySymbol(SecSymbol);
        writerdelete1.DeleteSecRecords(idate, itodate);

        break;
    }
    catch (Exception)
    {
        idate += 60 * 60 * 24; // advance by one day
        continue;
    }
}