private void btnEdit_Click(object sender, EventArgs e) { int nIncidentId = 0; int nIllnessId = 0; int result = 0; for (int i = 0; i < gvIncidents.Rows.Count; i++) { //nIncidentId = int.Parse(gvIncidents["Incident_Id", i]?.Value?.ToString()) if (int.TryParse(gvIncidents["Incident_Id", i]?.Value?.ToString(), NumberStyles.Number, new CultureInfo("en-US"), out result)) { nIncidentId = result; } if (int.TryParse(gvIncidents["Illness_Id", i]?.Value?.ToString(), NumberStyles.Number, new CultureInfo("en-US"), out result)) { nIllnessId = result; } } if (nIncidentId != 0 && nIllnessId != 0) { frmIncidentCreationPage frm = new frmIncidentCreationPage(); frm.strIncidentId = nIncidentId.ToString(); frm.strCaseId = CaseId; frm.strIndividualId = IndividualId; frm.nLoggedInId = nLoggedInId; frm.mode = frmIncidentCreationPage.IncidentMode.Edit; //frm.ShowDialog(); DialogResult dlgEditIncident = frm.ShowDialog(); //if (dlgEditIncident == DialogResult.OK) //{ // Close(); //} //if (dlgEditIncident == DialogResult.OK) //{ //} //String strSqlQueryForIncident = "select [dbo].[tbl_incident].[Case_id], [dbo].[tbl_incident].[Illness_Id], [dbo].[tbl_program].[ProgramName], [dbo].[tbl_program].[CreateDate], " + // "[dbo].[tbl_program].[ModifiDate], [dbo].[tbl_program].[IncidentNote] from [dbo].[tbl_program] " + // "inner join [dbo].[tbl_program] on [dbo].[tbl__incident].[Program_id] = [dbo].[tbl_program].[Program_Id] " + // "where [dbo].[tbl_incident].[Incident_id] = @IncidentId and [dbo].[tbl_incident].[Individual_id] = @IndividualId"; //SqlCommand cmdQueryForIncident = new SqlCommand(strSqlQueryForIncident, connRNDB); //cmdQueryForIncident.CommandType = CommandType.Text; //cmdQueryForIncident.Parameters.AddWithValue("@IncidentId", nIncidentId); //cmdQueryForIncident.Parameters.AddWithValue("@IndividualId", IndividualId); //connRNDB.Open(); //SqlDataReader rdrIncident = cmdQueryForIncident.ExecuteReader(); //if (rdrIncident.HasRows) //{ // rdrIncident.Read(); // //if (!rdrIncident.IsDBNull(0)) //} } }
private void btnAddNew_Click(object sender, EventArgs e) { frmIncidentCreationPage frmIncidentCreation = new frmIncidentCreationPage(); frmIncidentCreation.strIndividualId = IndividualId; frmIncidentCreation.strCaseId = CaseId; frmIncidentCreation.strIllnessId = IllnessId; frmIncidentCreation.nLoggedInId = nLoggedInId; frmIncidentCreation.mode = frmIncidentCreationPage.IncidentMode.AddNew; if (frmIncidentCreation.ShowDialog(this) == DialogResult.OK) { // Do when an incident is created successfully //String strSqlQueryForIncident = "select [dbo].[tbl_incident].[incident_id], [dbo].[tbl_incident].[individual_id], [dbo].[tbl_incident].[Case_id], [dbo].[tbl_incident].[Illness_id], " + // "[dbo].[tbl_incident].[CreateDate], [dbo].[tbl_incident].[Program_id], [dbo].[tbl_incident].[IncidentNote] " + // "from ([dbo].[tbl_incident] inner join [dbo].[tbl_illness] on [dbo].[tbl_incident].[Illness_id] = [dbo].[tbl_illness].[Illness_Id]) " + // "where [dbo].[tbl_incident].[individual_id] = @IndividualId and " + // "[dbo].[tbl_incident].[Case_id] = @CaseId and " + // "[dbo].[tbl_illness].[ICD_10_Id] = @ICD10Code"; String strSqlQueryForIncident = "select [dbo].[tbl_incident].[incident_id], [dbo].[tbl_incident].[individual_id], [dbo].[tbl_incident].[Case_id], [dbo].[tbl_incident].[Illness_id], " + "[dbo].[tbl_incident].[CreateDate], [dbo].[tbl_program].[ProgramName], [dbo].[tbl_incident].[IncidentNote] " + "from ([dbo].[tbl_incident] inner join [dbo].[tbl_illness] on [dbo].[tbl_incident].[Illness_id] = [dbo].[tbl_illness].[Illness_Id]) " + "inner join [dbo].[tbl_program] on [dbo].[tbl_incident].[Program_id] = [dbo].[tbl_program].[Program_Id] " + "where [dbo].[tbl_incident].[individual_id] = @IndividualId and " + "[dbo].[tbl_incident].[Case_id] = @CaseId and " + "[dbo].[tbl_illness].[ICD_10_Id] = @ICD10Code and " + "[dbo].[tbl_incident].[IsDeleted] = 0 " + "order by [dbo].[tbl_incident].[incident_id]"; SqlCommand cmdQueryForIncident = new SqlCommand(strSqlQueryForIncident, connRNDB); cmdQueryForIncident.CommandType = CommandType.Text; cmdQueryForIncident.CommandText = strSqlQueryForIncident; cmdQueryForIncident.Parameters.AddWithValue("@IndividualId", IndividualId); cmdQueryForIncident.Parameters.AddWithValue("@CaseId", CaseId); cmdQueryForIncident.Parameters.AddWithValue("@ICD10Code", ICD10Code); //SqlDependency dependencyIncident = new SqlDependency(cmdQueryForIncident); //dependencyIncident.OnChange += new OnChangeEventHandler(OnIncidentListChange); if (connRNDB.State == ConnectionState.Open) { connRNDB.Close(); connRNDB.Open(); } else if (connRNDB.State == ConnectionState.Closed) { connRNDB.Open(); } SqlDataReader rdrIncidents = cmdQueryForIncident.ExecuteReader(); gvIncidents.Rows.Clear(); if (rdrIncidents.HasRows) { while (rdrIncidents.Read()) { DataGridViewRow row = new DataGridViewRow(); row.Cells.Add(new DataGridViewCheckBoxCell { Value = false }); row.Cells.Add(new DataGridViewTextBoxCell { Value = rdrIncidents.GetInt32(0) }); row.Cells.Add(new DataGridViewTextBoxCell { Value = rdrIncidents.GetInt32(3) }); row.Cells.Add(new DataGridViewTextBoxCell { Value = rdrIncidents.GetDateTime(4) }); row.Cells.Add(new DataGridViewTextBoxCell { Value = rdrIncidents.GetString(5) }); row.Cells.Add(new DataGridViewTextBoxCell { Value = rdrIncidents.GetString(6) }); gvIncidents.Rows.Add(row); } } if (connRNDB.State == ConnectionState.Open) { connRNDB.Close(); } } }