Exemplo n.º 1
0
        public static List <Employe> All()
        {
            List <Employe> employeList = new List <Employe>();
            Connecteur     ct          = new Connecteur();

            try
            {
                SqlDataAdapter dap = new SqlDataAdapter(EmployeDAL.selectAllEmploye, ct.Connection);

                DataTable dt = new DataTable("Employe");

                ct.Connection.Open();
                dap.Fill(dt);

                Employe e;
                foreach (DataRow dr in dt.Rows)
                {
                    e = new Employe();
                    EmployeDAL.Hydrate(e, dr);
                    employeList.Add(e);
                }

                return(employeList);
            }
            catch (SqlException ex)
            {
                throw new Exception("Error: " + ex.Message + " - Code: " + ex.Number + " - Couche(DAL)");
            }
            finally
            {
                ct.Connection.Close();
            }
        }
Exemplo n.º 2
0
        public static Employe TrouverEmploye(string code)
        {
            Employe    e  = new Employe();
            Connecteur ct = new Connecteur();

            try
            {
                SqlDataAdapter dae = new SqlDataAdapter(EmployeDAL.selectOneEmploye, ct.Connection);
                dae.SelectCommand.Parameters.AddWithValue("@CodeEmploye", code);


                DataTable dt = new DataTable("Employe");

                ct.Connection.Open();
                dae.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    EmployeDAL.Hydrate(e, dr);
                }

                return(e);
            }
            catch (SqlException ex)
            {
                throw new Exception("Error: " + ex.Message + " - Code: " + ex.Number + " - Couche(DAL)");
            }
            finally
            {
                ct.Connection.Close();
            }
        }
Exemplo n.º 3
0
        public static void Insert(Employe emp, StatutCarriere stc)
        {
            Connecteur ct = new Connecteur();


            if (ct.Connection.State == ConnectionState.Closed)
            {
                ct.Connection.Open();
            }

            //----Begin Transaction---
            SqlTransaction trans = ct.Connection.BeginTransaction();

            try
            {
                //Proceed Database Command-------------------------------------
                SqlCommand employeCmd =
                    new SqlCommand(EmployeDAL.insertEmploye, ct.Connection, trans);

                SqlCommand carriereCmd =
                    new SqlCommand(StatutCarriereDAL.InsertStatutCarriere, ct.Connection, trans);

                //1 - INSERT Employe
                //Employe Params - Insert
                EmployeDAL.setEmployeParameters(employeCmd.Parameters, emp);
                employeCmd.ExecuteNonQuery();

                //2 - INSERT StatutCarriere
                //StatutCarriere Params  - Insert
                StatutCarriereDAL.setStatutCarriereParameters(carriereCmd.Parameters, stc);
                carriereCmd.ExecuteNonQuery();

                //Commit Transaction
                trans.Commit();

                //-------------------------------------------------------------
            }
            catch (SqlException ex)
            {
                trans.Rollback();
                throw new Exception("Error: " + ex.Message + " - Code: " + ex.Number + " - Couche(DAL)");
            }
            finally
            {
                ct.Connection.Close();
            }
        }