public void UpdateMethodOK() { clsReportsCollection AllReports = new clsReportsCollection(); //create the item of test data clsReports TestItem = new clsReports(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.ProfitOrLoss = true; TestItem.EmployeeId = 2; TestItem.DateAdded = DateTime.Now.Date; TestItem.EmployeeName = "Akshay"; TestItem.Expenses = 200; TestItem.Total = 1000; //set ThisReport to the test data AllReports.ThisReport = TestItem; //add the record PrimaryKey = AllReports.Add(); //set the primary key of the test data TestItem.EmployeeId = PrimaryKey; //modify the test data TestItem.ProfitOrLoss = false; TestItem.EmployeeId = 3; TestItem.DateAdded = DateTime.Now.Date; TestItem.EmployeeName = "Lax"; TestItem.Expenses = 500; TestItem.Total = 5000; //set the record based on the new test data AllReports.ThisReport = TestItem; //update the record AllReports.Update(); //find the record AllReports.ThisReport.Find(PrimaryKey); //test to see ThisReport matched the test data Assert.AreEqual(AllReports.ThisReport, TestItem); }
protected void btnOK_Click(object sender, EventArgs e) { clsReports AReport = new clsReports(); //capture employeeName string EmployeeName = txtEmployeeName.Text; //capture DateAdded string DateAdded = txtDateAdded.Text; //capture Total string Total = txtTotal.Text; //capture Expenses string Expenses = txtExpenses.Text; //variable to store any error messages string Error = ""; //validate the data Error = AReport.Valid(EmployeeName, Total, Expenses, DateAdded); if (Error == "") { //Capture the employee id AReport.EmployeeId = EmployeeId; //Capture EmployeeName AReport.EmployeeName = EmployeeName; //capture DateAdded AReport.DateAdded = Convert.ToDateTime(DateAdded); //capture Total AReport.Total = Convert.ToInt32(Total); //capture Expenses AReport.Expenses = Convert.ToInt32(Expenses); //capture Profit AReport.ProfitOrLoss = chkProfit.Checked; //capture Loss AReport.ProfitOrLoss = chkLoss.Checked; //create a new instance of the reports collection clsReportsCollection ReportList = new clsReportsCollection(); //if this is a new record i.e. EmployeeId = -1 then add the data if (EmployeeId == -1) { //set the ThisReport property ReportList.ThisReport = AReport; //add the new record ReportList.Add(); } else { //find the record to update ReportList.ThisReport.Find(EmployeeId); //set the ThisReport property ReportList.ThisReport = AReport; //update the record ReportList.Update(); } //redirect back to the listpage Response.Redirect("5ReportsList.aspx"); } else { //display the error message lblError.Text = Error; } }