开发者

Advancing a timestamp by a day when an exception is encountered [closed]

开发者 https://www.devze.com 2023-03-12 12:39 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

In my code, I am able to delete dated files from a folder.

But the date must appear in certain *.dat files, otherwise nothing happens.

Some days are not included in these files; for example, holidays are skipped.

In this case I am encountering a problem.

So, if I am on one of these days, how can I advance to the next day after failing?

    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);
                w开发者_StackOverflow社区riterdelete1.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();
    }


The problem is in your DeleteSecRecords method.

Google shows no hits for this name, so there is no way to look at it to further analyze the problem.


Edit: Ah, I understand what you are asking for. This will advance to the next day whenever an exception is encountered, until no possible days remain.

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;
    }
}
0

精彩评论

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