Created
September 4, 2013 11:58
-
-
Save DominicFinn/6436010 to your computer and use it in GitHub Desktop.
Bit of code for John
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected void CreateReportButton_Click(object sender, EventArgs e) | |
| { | |
| DateTime startDate, endDate; | |
| if (FormValid(out startDate, out endDate)) | |
| { | |
| this.GenerateReport(startDate, endDate); | |
| } | |
| } | |
| private bool FormValid(out DateTime startDate, out DateTime endDate) | |
| { | |
| //validate the dates and also check that the start is before the end etc... | |
| bool valid = false; | |
| valid = DateTime.TryParse(this.frm_DateStart.Text, out startDate); | |
| valid = DateTime.TryParse(this.frm_DateEnd.Text, out endDate); | |
| valid = startDate <= endDate; | |
| if (!valid) | |
| { | |
| this.feedback1.add(@" | |
| Please ensure you have entered a valid Start and | |
| End date and that the Start date is before the End date | |
| "); | |
| } | |
| return valid; | |
| } | |
| private void GenerateReport(DateTime startDate, DateTime endDate) | |
| { | |
| var outputFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + @"_AdvisorSessionReport" + ".xls"; | |
| var man = ObjectFactory.GetInstance<IReportManagement>(); | |
| // AdvisorSessionReport will be red. That's becuase the method was added to the concrete class | |
| // but not it's interface.... oops! we had better add it or we won't be able to | |
| // a) test the class in the future | |
| // b) nicely swap the class out. | |
| var bytes = man.AdvisorSessionReport(startDate, endDate); | |
| Context.StreamBytes(MimeType.Excel, outputFileName, bytes); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment