private DataTable getPaidHistory() { DataTable retVal = new DataTable(); try { DataColumn dcYearPaid = new DataColumn("YearPaid", System.Type.GetType("System.Int32")); DataColumn dcMembershipYear = new DataColumn("MembershipYear", System.Type.GetType("System.String")); DataColumn dcDeleted = new DataColumn("Deleted", System.Type.GetType("System.Boolean")); DataColumn dcNewRec = new DataColumn("NewRec", System.Type.GetType("System.Boolean")); DataColumn dcPaymentType = new DataColumn("PaymentType", System.Type.GetType("System.Int32")); DataColumn dcPaymentName = new DataColumn("PaymentName", System.Type.GetType("System.String")); DataRow dr; retVal.Columns.Add(dcYearPaid); retVal.Columns.Add(dcMembershipYear); retVal.Columns.Add(dcDeleted); retVal.Columns.Add(dcNewRec); retVal.Columns.Add(dcPaymentType); retVal.Columns.Add(dcPaymentName); MembershipTableAdapters.PaidTableAdapter daPaid = new PFGA_Membership.MembershipTableAdapters.PaidTableAdapter(); Membership.PaidDataTable dtPaid = new Membership.PaidDataTable(); DataView dvPaid; daPaid.Fill(dtPaid); dvPaid = new DataView(dtPaid); dvPaid.RowFilter = String.Format("MemberID = {0}", ID); foreach (DataRowView row in dvPaid) { int paymentType = -1; if (int.TryParse(row["PaymentType"].ToString(), out paymentType) == false) { paymentType = -1; } dr = retVal.NewRow(); dr["YearPaid"] = int.Parse(row["YearPaid"].ToString()); dr["MembershipYear"] = row["MembershipYear"].ToString(); dr["Deleted"] = false; dr["NewRec"] = false; dr["PaymentType"] = paymentType; retVal.Rows.Add(dr); } } catch (Exception ex) { ErrorLogger.Log("Error getting Paid Records from the database", ex, true); } return(retVal); }
private void savePaidHistory() { DataRow[] search; int retVal = 0; try { search = _paidHistory.Select("Deleted = True OR NewRec = True"); if (search.Length > 0) { MembershipTableAdapters.PaidTableAdapter daPaid = new PFGA_Membership.MembershipTableAdapters.PaidTableAdapter(); foreach (DataRow row in search) { int test; int?paymentType = null; if (int.TryParse(row["PaymentType"].ToString(), out test)) { paymentType = test; } if (bool.Parse(row["Deleted"].ToString()) == true) { retVal = daPaid.Delete(_ID, 0, row["MembershipYear"].ToString(), int.Parse(row["YearPaid"].ToString()), paymentType, null); } else if (bool.Parse(row["NewRec"].ToString()) == true) { retVal = daPaid.Insert(_ID, 0, row["MembershipYear"].ToString(), int.Parse(row["YearPaid"].ToString()), paymentType, DateTime.Today); } } } } catch (Exception ex) { ErrorLogger.Log("Error saving Paid History", ex, true); } }