Advancing a timestamp by a day when an exception is encountered [closed]
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;
}
}
精彩评论