private void btnHistory_Click(object sender, EventArgs e) { MarikinaOpticalEntities dbContext = new MarikinaOpticalEntities(); Forms.FormPatientRecords formPatientRecords = new Forms.FormPatientRecords(); formPatientRecords.txtName.Text = lblPatientName.Text; formPatientRecords.txtAddress.Text = lblHouseNo.Text + " " + lblStreet.Text + " " + lblBarangay.Text + " " + lblCity.Text; formPatientRecords.txtMobile.Text = lblMobileNo.Text; formPatientRecords.txtTelephone.Text = lblTelephoneNo.Text; formPatientRecords.txtBirthdate.Text = dtpBirthday.Value.Date.ToShortDateString(); formPatientRecords.txtGender.Text = lblGender.Text; var countOpticalLens = dbContext.CountPatientOpticalLens(Convert.ToInt32(lblPatientId.Text)); foreach (var countPatientOpticalLens in countOpticalLens) { count[0] = (int)countPatientOpticalLens; } formPatientRecords.lblCountOptical.Text = count[0].ToString(); var countContactLens = dbContext.CountPatientContactLens(Convert.ToInt32(lblPatientId.Text)); foreach (var countPatientContactLens in countContactLens) { count[0] = (int)countPatientContactLens; } formPatientRecords.lblCountContact.Text = count[0].ToString(); var getPatientLastCheckUpDateOptical = dbContext.GetLastCheckUpDateOpticalLens(Convert.ToInt32(lblPatientId.Text)); foreach (var patientLastCheckUpDateOptical in getPatientLastCheckUpDateOptical) { date[0] = patientLastCheckUpDateOptical.ToString(); } formPatientRecords.lblLastCheckUpDateOptical.Text = date[0].ToString(); var getPatientLastCheckUpDatContact = dbContext.GetLastCheckUpDateContactLens(Convert.ToInt32(lblPatientId.Text)); foreach (var patientLastCheckUpDateContact in getPatientLastCheckUpDatContact) { date[0] = patientLastCheckUpDateContact.ToString(); } formPatientRecords.lblLastCheckUpDateContact.Text = date[0].ToString(); formPatientRecords.dgvPatientOpticalLens.DataSource = dbContext.GetPatientOpticalLens(Convert.ToInt32(lblPatientId.Text)); formPatientRecords.dgvPatientContactLens.DataSource = dbContext.GetPatientContactLens(Convert.ToInt32(lblPatientId.Text)); formPatientRecords.ShowDialog(); }