【发布时间】:2017-01-19 21:34:36
【问题描述】:
目前我有两个按钮。创建一个 Patient 对象并向其添加费用详细信息,并将继续为每次单击添加这些详细信息的其他副本,然后将这些副本添加到 Patientlist。
第二个按钮应该创建 Patient 对象的一个新实例,以便它也可以执行上述相同的过程。
问题在于,当按下第二个按钮时,它会创建 Patient 对象的新实例,但列表会丢失之前的患者对象。
我觉得我在这里遗漏了一些非常明显的东西,并且已经回顾了复数视频、youtube 教程以及关于 SO 本身的很多问题。
static List<Patient> PatientsList()
{
List<Patient> patientList = new List<Patient>();
return patientList;
}
private void AddAddOn_Click(object sender, EventArgs e)
{
// Set the data on the patient, name etc.
patient.PatientFirstName = PatientFirstNameInput.Text;
patient.PatientLastName = PatientLastNameInput.Text;
patient.PatientCopay = Convert.ToDecimal(PatientCopayInput.Text);
patient.BillId = BillIdInput.Text;
Charge charge;
// Does the patient already have a Charge in their list?
if (patient.ChargeList.Count == 0)
{
// - if not, add a new charge
charge = new Charge();
patient.ChargeList.Add(charge);
}
else
{
// - if that's the case, use the existing charge but update info
charge = patient.ChargeList.First();
}
// Add a charge to the patient's list of charges
charge.DateofService = DateofServiceInput.Value.ToString("yyyyMMdd");
charge.PrimaryProcedureCode = PrimaryProcedureInput.Text;
charge.PrimaryChargeCost = Convert.ToDecimal(PrimaryChargeInput.Text);
charge.PrimaryChargeContractualAdjustment = Convert.ToDecimal(PrimaryAdjustmentInput.Text);
charge.PrimaryPaymentAmount = Convert.ToDecimal(PrimaryPaidInput.Text);
// Set the name of the Patient
// Create a new Charge
// Create an add-on charge and add it to the Charge
AddonCharge newAddonCharge = new AddonCharge();
newAddonCharge.AddonProcedureCode = AddonProcedureInput.Text;
newAddonCharge.AddonChargeCost = Convert.ToDecimal(AddonChargeInput.Text);
newAddonCharge.AddonContractualAdjustment = Convert.ToDecimal(AddonAdjustmentInput.Text);
newAddonCharge.AddonPaymentAmount = Convert.ToDecimal(AddonPaidInput.Text);
charge.AddonChargeList.Add(newAddonCharge);
List<Patient> patientList = PatientsList();
patientList.Add(patient);
//newCharge.AddonChargeList.Add(newAddonCharge);
}
private void AddtoListButton_Click(object sender, EventArgs e)
{
//return a new patient with null details
Patient patient = new Patient();
List<Patient> patientlist = PatientsList();
// Show a messagebox with the string
//MessageBox.Show(EDIToString());
}
【问题讨论】:
-
PatientsList()每次都会创建一个新列表。
标签: c# winforms list static-methods