public static int Save(Applicant applicant) { int applicantId; using (OracleConnection oraDbConn = new OracleConnection( ConnStringFactory.getConnString( ConnStringFactory.ConnStringType.Oracle))) { oraDbConn.Open(); using (OracleTransaction oraTrans = oraDbConn.BeginTransaction(IsolationLevel.ReadCommitted)) { try { applicantId = ApplicantDB.Save(applicant, oraDbConn, oraTrans); foreach (Loan loan in applicant.Loans) { loan.ApplicantId = applicantId; LoanManager.Save(loan, oraDbConn, oraTrans); } applicant.Id = applicantId; oraTrans.Commit(); } catch (OracleException oraEx) { oraTrans.Rollback(); throw oraEx; } } } return applicantId; }
private void btnSubmit_Click(object sender, EventArgs e) { Loan loan = new Loan(); Decimal loanAmount; Decimal.TryParse(txtLoanAmount.Text, out loanAmount); loan.Amount = loanAmount; loan.Type = (LoanType)cmbLoanType.SelectedIndex; Applicant applicant = new Applicant(); applicant.Name = txtName.Text; applicant.SSN = txtSSN.Text; applicant.Gender = (GenderType)cmbGender.SelectedIndex; applicant.Loans.Add(loan); try { ApplicantManager.Save(applicant); } catch(OracleException oraEx){ string errorMessage = oraEx.Message; errorMessage = errorMessage.Substring(0, errorMessage.IndexOf("\n")); errorMessage = errorMessage.Substring(errorMessage.IndexOf(":") + 1); errorMessage = errorMessage.Trim(); MessageBox.Show(errorMessage); } BindDataGrid(); }
public static int Save(Applicant applicant, OracleConnection oraDbConn, OracleTransaction oraTrans) { if (applicant.Id == null) { return Insert(applicant, oraDbConn, oraTrans); } else { return Update(applicant); } }
private static Applicant FillDataRecord(IDataRecord myDataRecord) { Applicant applicant = new Applicant(); applicant.Id = myDataRecord.GetInt32(myDataRecord.GetOrdinal("Id")); applicant.Name = myDataRecord.GetString(myDataRecord.GetOrdinal("Name")); applicant.SSN = myDataRecord.GetString(myDataRecord.GetOrdinal("SSN")); applicant.Gender = (GenderType)myDataRecord.GetInt32(myDataRecord.GetOrdinal("Gender")); return applicant; }
private static int Update(Applicant applicant) { throw new NotImplementedException(); }
private static int Insert(Applicant applicant, OracleConnection oraDbConn, OracleTransaction oraTrans) { int applicantId = 0; using (OracleCommand insertApplicantCommand = new OracleCommand()) { insertApplicantCommand.CommandType = CommandType.StoredProcedure; insertApplicantCommand.CommandText = "ApplicantsPKG.insertApplicant"; insertApplicantCommand.Connection = oraDbConn; insertApplicantCommand.Transaction = oraTrans; insertApplicantCommand.Parameters.AddWithValue("AppName", applicant.Name); insertApplicantCommand.Parameters.AddWithValue("AppSsn", applicant.SSN); insertApplicantCommand.Parameters.AddWithValue("AppGender", (int)applicant.Gender); OracleParameter outputAppId = new OracleParameter("AppId", OracleType.Number); outputAppId.Direction = ParameterDirection.Output; insertApplicantCommand.Parameters.Add(outputAppId); insertApplicantCommand.ExecuteNonQuery(); applicantId = Convert.ToInt32(outputAppId.Value); } return applicantId; }