示例#1
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();
            }
        }
        public static void AjouterStatut(StatutCarriere stc)
        {
            Connecteur ct = new Connecteur();

            //Proceed Database Command-------------------------------------
            if (ct.Connection.State == ConnectionState.Closed)
            {
                ct.Connection.Open();
            }

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

            SqlCommand ancienCarriereCmd =
                new SqlCommand(StatutCarriereDAL.updateAncienStatut, ct.Connection, trans);

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

            try
            {
                //1 - Update FinStatut de l'Ancien Statut
                //Employe Params - Insert
                ancienCarriereCmd.Parameters.AddWithValue("@CodeEmploye", stc.CodeEmploye);
                ancienCarriereCmd.Parameters.AddWithValue("@FinStatut", stc.Debut);
                ancienCarriereCmd.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();
            }
        }