private void btnAdd_Click(object sender, System.EventArgs e) { Diagnosis diagnosis = new Diagnosis(); diagnosis.DiagnosisNumber = txtNumber.Text; diagnosis.DiagnosisText = txtDescription.Text; try { database.Add(diagnosis); MessageBox.Show("Diagnosnumret lades till i databasen", "Uppdateringen av databasen lyckades"); txtNumber.ResetText(); txtDescription.ResetText(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Fel vid uppdateringen av databasen"); } }
private void UpdateSelectedDiagnosis() { System.Windows.Forms.CurrencyManager cm = (CurrencyManager)BindingContext[dgDiagnosis.DataSource,dgDiagnosis.DataMember]; DataView dv = (DataView) cm.List; selectedDiagnosis = new Diagnosis(); selectedDiagnosis.Id = (int) dv[dgDiagnosis.CurrentRowIndex]["id"]; selectedDiagnosis.DiagnosisText = (string) dv[dgDiagnosis.CurrentRowIndex]["diagnosistext"]; selectedDiagnosis.DiagnosisNumber = (string) dv[dgDiagnosis.CurrentRowIndex]["diagnosisnumber"]; }
private bool IsAlreadyExsisting(Diagnosis diagnosis) { DataView dv = new DataView(); dv.Table = dsMaster.Tables["Diagnosis"]; dv.RowFilter = "diagnosisnumber = '" + diagnosis.DiagnosisNumber + "'"; if (dv.Count > 0) return true; else return false; }
public Diagnosis CreateDiagnosis(System.Data.DataRow dr) { Diagnosis diagnosis = new Diagnosis(); if (!dr.HasErrors && dr != null) { object o = dr["diagnosisnumber"]; if (o == System.DBNull.Value) { diagnosis = null; } diagnosis.Id = (int) dr["diagnosisid"]; diagnosis.DiagnosisText = (string) dr["diagnosistext"]; diagnosis.DiagnosisNumber = (string) dr["diagnosisnumber"]; } return diagnosis; }
public void Add(Diagnosis diagnosis) { //TODO; Take care of the exception if (IsAlreadyExsisting(diagnosis)) throw new Exception("En diagnos med samma diagnosnummer finns redan inlagd i database"); System.Data.DataRow dr = dsMaster.Tables["Diagnosis"].NewRow(); dr["diagnosisnumber"] = diagnosis.DiagnosisNumber; dr["diagnosistext"] = diagnosis.DiagnosisText; dsMaster.Tables["Diagnosis"].Rows.Add(dr); daDiagnosis.Update(dsMaster, "Diagnosis"); }
private void UpdateSelectedDiagnosis() { System.Windows.Forms.CurrencyManager cm = (CurrencyManager)BindingContext[dgDiagnosis.DataSource,dgDiagnosis.DataMember]; DataView dv = (DataView) cm.List; selectedDiagnosis = database.CreateDiagnosis(dv[dgDiagnosis.CurrentRowIndex].Row); //Check if the null value is selected //TODO: Fix so that diagnosisfield is null if no diagnosis is selected Debug.WriteLine("Current diagnosis: " + selectedDiagnosis.Id.ToString() + ", " + selectedDiagnosis.DiagnosisNumber + ", " + selectedDiagnosis.DiagnosisText); }