protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["ref"] != null) { List <Contact> destin = ContactService.getContacts(); id_destinataire.Items.Clear(); id_destinataire.Items.AddRange(destin.Select(ex => new ListItem() { Text = ex.getNom(), Value = ex.getId() + "" }).ToArray()); List <Unite> l = UniteService.getUnites(); unit.Items.Clear(); unit.Items.Add(new ListItem() { Text = "Choisissez une unité", Value = "0" }); unit.Items.AddRange(l.Select(u => new ListItem() { Text = u.getNom(), Value = u.getId() + "" }).ToArray()); unit_copie.Items.Clear(); unit_copie.Items.AddRange(l.Select(u => new ListItem() { Text = u.getNom(), Value = u.getId() + "" }).ToArray()); CourrierArriveInterne c = CourrierService.getCourrierByRef(Request.QueryString["ref"]); cour = c; if (c != null) { ref_cour.Text = c.getReference(); reference.Text = c.getReference(); type.Text = c.getTypecr(); nature.Text = c.getNature(); datecrea.Text = c.getDate_creation().ToString().Substring(0, 10); objet.Text = c.getObjet(); agentua.Text = c.getAgentUA().getNom() + " " + c.getAgentUA().getPrenom(); uniteua.Text = c.getAgentUA().getUnite().getNom(); reponse.Text = c.getReponse() ? "Oui" : "Non"; courrier_reponse.Text = (c.getCourrier_Reponse() != null) ? c.getCourrier_Reponse().getReference() : "Pas de réponse"; ref_dos.Text = (c.getDossier() != null) ? c.getDossier().getReference() : "Sans dossier"; datecour.Text = c.getDate_Courrier().ToString().Substring(0, 10); datearr.Text = c.getDate_Arrivee().ToString().Substring(0, 10); expediteur.Text = c.getExpediteur().getNom(); if (c is Facture) { facture.Text = ""; device.Text = ((Facture)c).getDevice(); montant.Text = ((Facture)c).getMontant().ToString(); } else { facture.Text = "Non"; device.Text = " - "; montant.Text = " - "; } etat.Text = c.getEtat(); } } }
public static Boolean ajouterCourrier(CourrierArriveInterne c) { try { SqlConnection cnx = new SqlConnection(ConfigurationManager.AppSettings["cnx"].ToString()); cnx.Open(); SqlTransaction tran = cnx.BeginTransaction("ajout"); string requete1 = String.Format("Insert into courrier values('{0}','{1}','{2}','{3}','{4}','Cree',{5},{6},{7},null,{8})", c.getReference(), c.getTypecr(), c.getNature(), c.getDate_creation(), c.getObjet(), c.getAgentBO().getId(), c.getAgentUA().getId(), c.getReponse() ? 1 : 0, (c.getDossier() != null) ? "'" + c.getDossier().getReference() + "'" : "null"); //, (c.getDossier()!=null)?c.getDossier().getReference():null Console.WriteLine(requete1); SqlCommand cmd = new SqlCommand(requete1, cnx); cmd.Transaction = tran; int n = cmd.ExecuteNonQuery(); if (n != 0) { cmd = new SqlCommand(String.Format("Insert into courrier_arrive_interne values('{0}','{1}','{2}','{3}',(select id_contact from contacts where nom='{4}'))", c.getReference(), c.getDate_Courrier(), c.getDate_Arrivee(), c.getType(), c.getExpediteur().getNom()), cnx); cmd.Transaction = tran; n = cmd.ExecuteNonQuery(); if (n != 0 && (c is Facture)) { cmd = new SqlCommand(String.Format("Insert into facture values ('{0}','{1}',{2})", c.getReference(), ((Facture)c).getDevice(), (((Facture)c).getMontant() + "").Replace(",", ".")), cnx); cmd.Transaction = tran; n = cmd.ExecuteNonQuery(); if (n != 0) { tran.Commit(); return(true); } else { tran.Rollback(); return(false); } } else if (n != 0) { tran.Commit(); return(true); } else { tran.Rollback(); return(false); } } else { tran.Rollback(); return(false); } }catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }