示例#1
0
 private DTO.employee ParseEmploye(SqlDataReader reader)
 {
     DTO.employee e = new DTO.employee();
     if (!reader.IsDBNull(0)) e.emp_id = (string)reader[0];
     if (!reader.IsDBNull(1)) e.fname = (string)reader[1];
     if (!reader.IsDBNull(2)) e.minit = (string)reader[2];
     if (!reader.IsDBNull(3)) e.lname = (string)reader[3];
     if (!reader.IsDBNull(4)) e.job_id = (short)reader[4];
     e.job_lvl = (System.Nullable<byte>)reader[5];
     if (!reader.IsDBNull(6)) e.pub_id = (string)reader[6];
     if (!reader.IsDBNull(7)) e.hire_date = (DateTime)reader[7];
     return e;
 }
示例#2
0
        public static void execute()
        {
            char exec = '-';
            if (exec == '+') {
                Console.WriteLine("Exemple d'utilisation ADO SELECT:\r\n");
                Console.WriteLine();
                DateTime bc = DateTime.Now;
                DateTime ac;
                string cstr = ConfigurationManager.ConnectionStrings["Pubs"].ConnectionString;
                using (SqlConnection con = new SqlConnection(cstr)) {

                    con.Open();
                    ac = DateTime.Now;
                    var bll = new BLL(con);

                    {
                        // Le filtrage where ci-dessous ce fait après un SQL SELECT ALL puis une selection LINQ sur entitées
                        foreach (var e in bll.employee.GetAll(null).Where((x) => x.fname.CompareTo("M") > 0))
                            Console.WriteLine(e.emp_id + " " + e.fname + " " + e.lname);
                        Console.WriteLine();
                    }

                    {
                        SqlTransaction trans = con.BeginTransaction();
                        DTO.employee em = new DTO.employee();
                        em.fname = "Thierry";
                        bll.employee.Add(em, trans);
                        DTO.employee e = bll.employee.GetByName("Thierry", trans);
                        if (e != null)
                            Console.WriteLine(e.emp_id + " " + e.fname + " " + e.lname);
                        else
                            Console.WriteLine("Introuvable");
                        Console.WriteLine();
                        trans.Rollback();
                    }

                    { // bll.employee.Add
                        bool cont;
                        //SqlTransaction trans = con.BeginTransaction(); // Ne pas metre dans la boucle do sinon on imbrique plusieures transactions
                        SqlTransaction trans = null; // ci on descide de ne gerer la transaction au niveau application la Bll s'en chargera
                        do {
                            try {
                                DTO.employee e = new DTO.employee();
                                Console.Write("Entrez un nom:");
                                e.fname = Console.ReadLine();
                                bll.employee.Add(e, trans);
                                //trans.Rollback();
                                cont = false;
                            }
                            catch (AppException ex) {
                                Console.WriteLine(ex.Message);
                                cont = true;
                            }
                            catch (SqlException ex) {
                                Console.WriteLine(ex.Message);
                                cont = true;
                            }
                        }
                        while (cont);
                    }

                }
                DateTime ad = DateTime.Now;
                Console.WriteLine();
                Console.WriteLine("Durée Connexion:" + (ac - bc).TotalMilliseconds);
                Console.WriteLine("Durée Requette.:" + (ad - ac).TotalMilliseconds);
                Console.WriteLine("\r\n");
            }
        }