private bool BuildServicesRendusTable(int idconsultation) { tlpValidationFacture.Controls.Clear(); tlpValidationFacture.RowCount = 1; tlpValidationFacture.Controls.Add(new Label() { Text = "Type MedEasy" }, 0, 0); tlpValidationFacture.Controls.Add(new Label() { Text = "Description" }, 1, 0); tlpValidationFacture.Controls.Add(new Label() { Text = "Durée (minutes)" }, 2, 0); tlpValidationFacture.Controls.Add(new Label() { Text = "Prix à facturer" }, 3, 0); try { Database_Manager db = new Database_Manager(); SQLiteDataReader reader = db.SqlRequest("SELECT SR.*, ST.SET_Chf_Minute, ST.SET_Nom FROM Service_Rendu SR INNER JOIN Service_Type ST ON SR.SER_SET_ID = ST.SET_ID WHERE SR.SER_CON_FID IS " + idconsultation); while (reader.Read()) { tlpValidationFacture.RowCount = tlpValidationFacture.RowCount + 1; tlpValidationFacture.Controls.Add(new Label() { Text = reader.GetValue(6).ToString() }, 0, tlpValidationFacture.RowCount - 1); tlpValidationFacture.Controls.Add(new Label() { Text = reader.GetValue(2).ToString() }, 1, tlpValidationFacture.RowCount - 1); tlpValidationFacture.Controls.Add(new Label() { Text = reader.GetValue(1).ToString() }, 2, tlpValidationFacture.RowCount - 1); float duree = Convert.ToSingle(reader.GetValue(1).ToString()); float prixpm = Convert.ToSingle(reader.GetValue(5).ToString()); float res = duree * prixpm; tlpValidationFacture.Controls.Add(new Label() { Text = Convert.ToString(res) }, 3, tlpValidationFacture.RowCount - 1); } reader.Close(); return(true); } catch (Exception e) { Exception_Manager.NewException(e, "Erreur lors du calcul de la facture", false); //PanelManager("ListeRendezVous"); return(false); } }
/* * Méthode SQLREQUEST * Execute la requête SQLite passée en entrée * * RETOURNE : le résultat de la requête */ public SQLiteDataReader SqlRequest(string Request) { if (Request == null) { throw new ArgumentNullException(nameof(Request)); } // Initialise la commande dans une nouvelle instance de l'objet SQLiteCommand //SQLiteCommand command = new SQLiteCommand(Request, Connexion()); try { SQLiteConnection dbConnexion = Connexion(); //dbConnexion.Open(); SQLiteCommand cmd = new SQLiteCommand(Request, dbConnexion); SQLiteDataReader reader = cmd.ExecuteReader(); // Retourne le résultat de la requête return(reader); } catch (Exception e) { // Exectute ce code en cas d'erreur : // Passe l'exception à Exception_Manager Exception_Manager.NewException(e, "Requête incorrecte", false); // Ne retourne rien return(null); } }
/* * METHODE CONNEXION * Cette méthode crée et gère la connexion vers le fichier de base de données * Elle génère la base de données si elle est inexistante * * RETOURNE : La connexion à la base de donnée */ public SQLiteConnection Connexion() { // Vérifie si le fichier de base de données existe if (!System.IO.File.Exists("M:\\DB.sqlite")) { // Si le fichier n'existe pas, éxectute ce code : //Connexion à la base SQLite : Code adapté de https://www.connectionstrings.com/sqlite/ // Le fichier est crée try { SQLiteConnection.CreateFile("M:\\DB.sqlite"); // La connexion est initialisée dans une instance de l'objet SQLiteConnection SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source= M:\\DB.sqlite"); // La connexion est ouverte m_dbConnection.Open(); // Une instance de l'objet SQLiteCommand est créée, contenant le script de création de la base SQLiteCommand command = new SQLiteCommand("CREATE TABLE 'Patient'( 'PAT_ID' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'PAT_Nom' VARCHAR(30) NOT NULL, 'PAT_Prenom' VARCHAR(30) NOT NULL, 'PAT_Date_Naissance' DATETIME NOT NULL, 'PAT_Titre' VARCHAR(6), 'PAT_Etat_Civil' VARCHAR(10), 'PAT_Origine' VARCHAR(25), 'PAT_Adresse' VARCHAR(45), 'PAT_Ville' VARCHAR(25), 'PAT_Code_Postal' VARCHAR(4), 'PAT_Canton' VARCHAR(20), 'PAT_Telephone_Mobile' VARCHAR(14), 'PAT_Telephone_Professionnel' VARCHAR(14), 'PAT_Telephone_Urgence' VARCHAR(14), 'PAT_Email' VARCHAR(14), 'PAT_Emp_Titre' VARCHAR(45), 'PAT_Emp_Adresse' VARCHAR(45), 'PAT_Emp_Canton' VARCHAR(20), 'PAT_Emp_Ville' VARCHAR(25), 'PAT_Emp_Code_Postal' VARCHAR(4), 'PAT_Emp_Pays' VARCHAR(20), 'PAT_Ass_Numero_Avs' VARCHAR(13), 'PAT_Ass_Numero_Carte' VARCHAR(20), 'PAT_Ass_Numero_OFSP' VARCHAR(45), 'PAT_Ass_Institution' VARCHAR(15), 'PAT_Ass_Police' VARCHAR(20), CONSTRAINT 'IDPatient_UNIQUE' UNIQUE('PAT_ID')); INSERT INTO 'Patient'('PAT_NOM', 'PAT_Prenom', 'PAT_Date_Naissance') VALUES('Adelle', 'Morte', '2018-03-15');CREATE TABLE 'Consultation'( 'CON_ID' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'CON_Visite_Routine' BOOL NOT NULL, 'CON_Date_Heure' DATETIME NOT NULL, 'CON_PAT_FID' INTEGER NOT NULL, 'CON_Premiere_Consultation' BOOL NOT NULL, 'CON_Notes' LONGTEXT, 'CON_Facture_Validee' BOOL NOT NULL, 'CON_Facture_Payee' BOOL NOT NULL, 'CON_Facture_Pdf' BLOB, 'CON_Visite_Effectuee' BOOL NOT NULL, CONSTRAINT 'CON_ID_Consultation_UNIQUE' UNIQUE('CON_ID'), CONSTRAINT 'fk_Consultation_Patient' FOREIGN KEY('CON_PAT_FID') REFERENCES 'Patient'('PAT_ID')); INSERT INTO 'Consultation'(CON_Visite_Routine, CON_Premiere_Consultation, CON_Date_Heure, CON_PAT_FID, CON_Facture_Validee, CON_FACTURE_PAYEE, CON_Visite_Effectuee) VALUES('false', 'false', '1900-01-01 00:00:00', '1', 'false', 'false', 'false'); CREATE INDEX 'Consultation.fk_Consultation_Patient' ON 'Consultation' ('CON_PAT_FID');CREATE TABLE 'CIM10'( 'CIM_ID' INTEGER PRIMARY KEY NOT NULL, 'CIM_Description' LONGTEXT, CONSTRAINT 'CIM_ID_UNIQUE' UNIQUE('CIM_ID'));CREATE TABLE 'Service_Type'( 'SET_ID' INTEGER PRIMARY KEY NOT NULL, 'SET_Nom' VARCHAR(15), 'SET_Chf_Minute' FLOAT); INSERT INTO Service_Type('SET_Nom', 'SET_Chf_Minute') VALUES ('Entretien', '1'), ('Examen Physique', '2'), ('Examen Complémentaire', '3'), ('Vaccination', '4'), ('Chirurgie', '5'); CREATE TABLE 'Utilisateurs'( 'USR_ID' VARCHAR(25) PRIMARY KEY NOT NULL, 'USR_Password' VARCHAR(45) NOT NULL, 'USR_Nom' VARCHAR(35), 'USR_Prenom' VARCHAR(25), 'USR_EstAdmin' BOOL NOT NULL, CONSTRAINT 'USR_ID_UNIQUE' UNIQUE('USR_ID'));INSERT INTO 'Utilisateurs'('USR_ID','USR_Password','USR_Nom','USR_Prenom','USR_EstAdmin') VALUES('admin', 'pass', 'Bon', 'Jean', 1); CREATE TABLE 'Probleme'( 'PRB_ID' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'PRB_Titre' VARCHAR(35) NOT NULL, 'PRB_Type' VARCHAR(15) NOT NULL, 'PRB_Description' LONGTEXT, 'PRB_Date_Debut' DATE, 'PRB_Date_Fin' DATE, 'PRB_Occurence' VARCHAR(20), 'PRB_PAT_FID' INTEGER NOT NULL, CONSTRAINT 'PRB_ID_UNIQUE' UNIQUE('PRB_ID'), CONSTRAINT 'fk_Probleme_Patient1' FOREIGN KEY('PRB_PAT_FID') REFERENCES 'Patient'('PAT_ID'));CREATE INDEX 'Probleme.fk_Probleme_Patient' ON 'Probleme' ('PRB_PAT_FID');CREATE TABLE 'Consultation_Problemes'( 'COPB_CON_ID' INTEGER NOT NULL, 'Probleme_PRB_ID' INTEGER NOT NULL, PRIMARY KEY('COPB_CON_ID','Probleme_PRB_ID'), CONSTRAINT 'fk_Consultations_Problemes_Consultation1' FOREIGN KEY('COPB_CON_ID') REFERENCES 'Consultation'('CON_ID'), CONSTRAINT 'fk_Consultations_Problemes_Probleme1' FOREIGN KEY('Probleme_PRB_ID') REFERENCES 'Probleme'('PRB_ID'));CREATE INDEX 'Consultation_Problemes.fk_COPB_Consultation' ON 'Consultation_Problemes' ('COPB_CON_ID');CREATE INDEX 'Consultation_Problemes.fk_COPB_Probleme' ON 'Consultation_Problemes' ('Probleme_PRB_ID');CREATE TABLE 'Service_Rendu'( 'SER_ID' INTEGER NOT NULL, 'SER_Duree' INTEGER NOT NULL, 'SER_Description' LONGTEXT, 'SER_CON_FID' INTEGER NOT NULL, 'SER_SET_ID' INTEGER NOT NULL, PRIMARY KEY('SER_ID','SER_SET_ID'), CONSTRAINT 'SER_ID_UNIQUE' UNIQUE('SER_ID'), CONSTRAINT 'fk_Service_Rendu_Consultation1' FOREIGN KEY('SER_CON_FID') REFERENCES 'Consultation'('CON_ID'), CONSTRAINT 'fk_Service_Rendu_Service_Type1' FOREIGN KEY('SER_SET_ID') REFERENCES 'Service_Type'('SET_ID'));CREATE INDEX 'Service_Rendu.fk_Service_Rendu_Consultation1_idx' ON 'Service_Rendu' ('SER_CON_FID');CREATE INDEX 'Service_Rendu.fk_Service_Rendu_Service_Type1_idx' ON 'Service_Rendu' ('SER_SET_ID');CREATE TABLE 'Probleme_CIM10'( 'PBCI_PRB_ID' INTEGER NOT NULL, 'PBCI_CIM_ID' INTEGER PRIMARY KEY NOT NULL, CONSTRAINT 'fk_Probleme_CIM10_Probleme1' FOREIGN KEY('PBCI_PRB_ID') REFERENCES 'Probleme'('PRB_ID'), CONSTRAINT 'fk_Probleme_CIM10_CIM101' FOREIGN KEY('PBCI_CIM_ID') REFERENCES 'CIM10'('CIM_ID'));CREATE INDEX 'Probleme_CIM10.fk_Probleme_CIM10_Probleme1_idx' ON 'Probleme_CIM10' ('PBCI_PRB_ID');CREATE INDEX 'Probleme_CIM10.fk_Probleme_CIM10_CIM101_idx' ON 'Probleme_CIM10' ('PBCI_CIM_ID');", m_dbConnection); // La commande est executée sans demander de retour command.ExecuteNonQuery(); // La connexion est retournée et la méthode stoppée return(m_dbConnection); } catch (Exception e) { Exception_Manager.NewException(e, "La base de données n'a pas pu être créée : Vérifiez la disponibilité du partage M:", true); return(null); } } else { // Si le fichier existe, éxecute ce code : try { // Connexion à la base SQLite : Code adapté de https://www.connectionstrings.com/sqlite/ // La connexion est initialisée dans une instance de l'objet SQLiteConnection SQLiteConnection dbConnection = new SQLiteConnection("Data Source=M:\\DB.sqlite"); // La connexion est ouverte dbConnection.Open(); // La connexion est retournée et la méthode stoppée return(dbConnection); } catch (Exception e) { // Exectute ce code en cas d'erreur : // Passe l'erreur à l'Exception_Manager Exception_Manager.NewException(e, "La base de données n'a pas pu être trouvée - Veuillez contacter le support technique ", true); // Ne retourne rien return(null); } } }
private void btnRdvConfirmer_Click(object sender, EventArgs e) { bool checkedradiobutton = false; foreach (Control c in pnlRendezVous.Controls) { if (c is GroupBox) { GroupBox groupBox = c as GroupBox; ttpARemplir.Hide(this); groupBox.BackColor = DefaultBackColor; foreach (RadioButton rdb in groupBox.Controls.OfType <RadioButton>()) { if (rdb.Checked) { checkedradiobutton = true; break; } else { checkedradiobutton = false; } } if (checkedradiobutton == false) { ttpARemplir.Show("Veuillez choisir une option", groupBox); groupBox.BackColor = Color.Red; break; } } } if (checkedradiobutton) { try { Data_Handler.CreateRendezVousConsultation(CurrentPatient.Id, rdbRdvPremiereConsultOui.Checked, rdbRdvPremiereConsultOui.Checked, dtpRdvDate.Value, rtbRdvNotes.ToString(), false); PanelManager("ListeRendezVous"); } catch (Exception ex) { Exception_Manager.NewException(ex, "Le rendez-vous n'a pas pu être créé", false); } } }
private void BuildVisiteForm(bool modifier) { if (modifier) { } else { rdbVstRdvNon.Checked = true; lblVstPatientActif.Text = CurrentPatient.Prenom + CurrentPatient.Nom; try { Database_Manager db = new Database_Manager(); SQLiteDataReader results = db.SqlRequest("SELECT CON_ID, CON_Date_Heure FROM Consultation WHERE CON_PAT_FID IS '" + CurrentPatient.Id + "';"); while (results.Read()) { cbxVstListeRdv.Items.Add("Rendez-vous " + results.GetValue(0) + " pour le " + results.GetValue(1).ToString()); } results.Close(); tlpVstServicesRendus.RowCount = 1; tlpVstServicesRendus.Controls.Add(new Label { Text = "Type MedEasy" }, 0, 1); tlpVstServicesRendus.Controls.Add(new Label { Text = "Description" }, 1, 1); tlpVstServicesRendus.Controls.Add(new Label { Text = "Durée (min)" }, 2, 1); } catch (Exception e) { Exception_Manager.NewException(e, "", false); } cbxVstListeRdv.Enabled = false; } }
private void btnConfirmerNvPat_Click(object sender, EventArgs e) { int emptyfieldcount = 0; foreach (Control c in pnlNouveauPatient.Controls) { if (c is TextBox) { TextBox textBox = c as TextBox; if (textBox.Text == string.Empty && (textBox.Name == txtNom.Name || textBox.Name == txtPrenom.Name || textBox.Name == txtAdresse.Name || textBox.Name == txtCP.Name || textBox.Name == txtOrigine.Name)) { emptyfieldcount++; textBox.Focus(); textBox.BackColor = Color.Red; if (emptyfieldcount <= 1) { ttpARemplir.Show("Veuillez remplir ce champ", textBox); } } else { textBox.BackColor = DefaultBackColor; } } if (c is ComboBox) { ComboBox comboBox = c as ComboBox; if (comboBox.SelectedItem == null && comboBox.Name != cbxEmpCanton.Name) { emptyfieldcount++; comboBox.Focus(); comboBox.BackColor = Color.Red; if (emptyfieldcount <= 1) { ttpARemplir.Show("Veuillez remplir ce champ", comboBox); } } else { comboBox.BackColor = DefaultBackColor; } } } if (emptyfieldcount > 1) { MessageBox.Show("Veuillez remplir tous les champs en rouge"); } else if (emptyfieldcount == 0) { if (txtTelDomicile.Text != string.Empty && !UInt64.TryParse(txtTelDomicile.Text.Trim(), out UInt64 trash)) { ttpARemplir.Show("Veuillez rentrer un numéro valide", txtTelDomicile); txtTelDomicile.BackColor = Color.Red; return; } else { txtTelDomicile.BackColor = TextBox.DefaultBackColor; } if (txtTelMobile.Text != string.Empty && !UInt64.TryParse(txtTelMobile.Text.Trim(), out trash)) { ttpARemplir.Show("Veuillez rentrer un numéro valide", txtTelMobile); txtTelMobile.BackColor = Color.Red; return; } else { txtTelMobile.BackColor = TextBox.DefaultBackColor; } if (txtTelPro.Text != string.Empty && !UInt64.TryParse(txtTelPro.Text.Trim(), out trash)) { ttpARemplir.Show("Veuillez rentrer un numéro valide", txtTelPro); txtTelPro.BackColor = Color.Red; return; } else { txtTelPro.BackColor = TextBox.DefaultBackColor; } if (txtTelUrgence.Text != string.Empty && !UInt64.TryParse(txtTelUrgence.Text.Trim(), out trash)) { ttpARemplir.Show("Veuillez rentrer un numéro valide", txtTelUrgence); txtTelUrgence.BackColor = Color.Red; return; } else { txtTelUrgence.BackColor = TextBox.DefaultBackColor; } if (txtCP.Text != string.Empty) { if (!Regex.IsMatch(txtCP.Text, "[0-9][0-9][0-9][0-9]$")) { ttpARemplir.Show("Veuillez entrer un Code Postal valide", txtCP); txtCP.BackColor = Color.Red; return; } } else { txtCP.BackColor = TextBox.DefaultBackColor; } if (txtEmpCP.Text != string.Empty) { if (!Regex.IsMatch(txtEmpCP.Text, "[0-9][0-9][0-9][0-9]$")) { ttpARemplir.Show("Veuillez entrer un Code Postal valide", txtEmpCP); txtEmpCP.BackColor = Color.Red; return; } } else { txtEmpCP.BackColor = TextBox.DefaultBackColor; } if (txtEmail.Text != string.Empty) { try { new System.Net.Mail.MailAddress(txtEmail.Text); } catch { ttpARemplir.Show("Veuillez rentrer une adresse email valide", txtTelPro); txtEmail.BackColor = Color.Red; return; } } else { txtEmail.BackColor = TextBox.DefaultBackColor; } string canton; string titre; string etatCivil; string cantonEmployeur; try { canton = cbxCanton.SelectedItem.ToString(); } catch { canton = string.Empty; } try { titre = cbxTitre.SelectedItem.ToString(); } catch { titre = string.Empty; } try { etatCivil = cbxEtatCivil.SelectedItem.ToString(); } catch { etatCivil = string.Empty; } try { cantonEmployeur = cbxEmpCanton.SelectedItem.ToString(); } catch { cantonEmployeur = string.Empty; } try { Data_Handler.CreatePatient(txtNom.Text.Trim(), txtPrenom.Text.Trim() + "" + txtPrenom2.Text.Trim(), dtpNaissance.Value.Date, titre, etatCivil, txtOrigine.Text.Trim(), txtAdresse.Text.Trim(), txtVille.Text.Trim(), txtCP.Text.Trim(), canton, txtTelMobile.Text.Trim(), txtTelPro.Text.Trim(), txtTelUrgence.Text.Trim(), txtEmail.Text.Trim(), txtEmpNom.Text.Trim(), txtEmpAdresse.Text.Trim(), cantonEmployeur, txtEmpVille.Text.Trim(), txtEmpCP.Text.Trim(), txtEmpPays.Text.Trim(), txtNumAvs.Text.Trim(), txtNumCarte.Text.Trim(), txtNumOFSP.Text.Trim(), txtInstitution.Text.Trim(), txtNumPolice.Text.Trim()); } catch (Exception e2) { Exception_Manager.NewException(e2, "Une erreur est survenue durant la création du patient", false); } finally { PanelManager("ListePatients"); } } }
private void btnActions_Click(object sender, EventArgs e) { Button btn = (Button)sender; if (Regex.IsMatch(btn.Name, "btnSelectionnerPatient*")) { try { Database_Manager db = new Database_Manager(); SQLiteDataReader results = db.SqlRequest("SELECT PAT_Nom, PAT_Prenom, PAT_Date_Naissance FROM Patient WHERE PAT_ID IS " + Regex.Match(btn.Name, @"\d+$").Value); if (results.Read()) { int age = 0; age = DateTime.Now.Year - Convert.ToDateTime(results.GetValue(2)).Year; if (DateTime.Now.DayOfYear < Convert.ToDateTime(results.GetValue(2)).DayOfYear) { age--; } CurrentPatient.Id = Convert.ToInt32(Regex.Match(btn.Name, @"\d+$").Value); lblPatientactif.Text = (CurrentPatient.Prenom = results.GetValue(1).ToString()) + " " + (CurrentPatient.Nom = results.GetValue(0).ToString()); lblPatientactifage.Text = Convert.ToString(CurrentPatient.Age = age); } results.Close(); } catch (Exception ex) { Exception_Manager.NewException(ex, "Le patient sélectionné n'a pas pu être trouvé", false); } } else if (Regex.IsMatch(btn.Name, "btnModifierPatient*")) { MessageBox.Show("Fonctionalitlé en cours de création"); } else if (Regex.IsMatch(btn.Name, "btnSupprimmerPatient*")) { try { Data_Handler.DeletePatient(Convert.ToInt16(Regex.Match(btn.Name, @"\d+$").Value)); PanelManager("ListePatients"); } catch (Exception ex) { Exception_Manager.NewException(ex, "Le patient sélectionné n'a pas pu être supprimmé", false); } } else if (Regex.IsMatch(btn.Name, "btnModifierRendezVous*")) { MessageBox.Show("Fonctionalitlé en cours de création"); } else if (Regex.IsMatch(btn.Name, "btnSupprimmerRendezVous*")) { try { Data_Handler.DeleteConsultationRendezVous(Convert.ToInt16(Regex.Match(btn.Name, @"\d+$").Value)); PanelManager("RendezVous"); } catch (Exception ex) { Exception_Manager.NewException(ex, "Le Rendez-Vous sélectionné n'a pas pu être supprimmé", false); } } else { Exception_Manager.NewException(new Exception("NoMatchBtnName:" + btn.Name), "L'élément sélectionné n'a pas pu être trouvé", false); } }