コード例 #1
0
 public void addPret(ServiceSocial pret)
 {
     if (pret != null)
     {
         MyPret.Add(pret);
         MoneyToken += pret.getPrix();
         if (!(pret is Dons))
         {
             Debt += pret.getRestAPyer();
         }
     }
 }
コード例 #2
0
        public static void AddPret(ServiceSocial serviceSocial)
        {
            SqlConnection sqlConnection = new SqlConnection(constr);

            sqlConnection.Open();
            String Command = "INSERT INTO " + table + " VALUES (@Id , @Emp , @service ," +
                             "@pv , @somme , @remb1 , @date1 , @remb2 , @date2 , @remb3 , @date3" +
                             ", @remb4 , @date4 , @remb5 , @date5" +
                             ", @remb6 , @date6 , @remb7 , @date7 , @remb8 , @date8" +
                             ", @remb9 , @date9 , @remb10 , @date10 ,@observation ,@type ) ; ";
            SqlCommand sqlCommand = new SqlCommand(Command, sqlConnection);

            using (sqlCommand)
            {
                sqlCommand.CommandType = CommandType.Text;
                sqlCommand.Parameters.AddWithValue("@Id", serviceSocial.getid());
                sqlCommand.Parameters.AddWithValue("@Emp", serviceSocial.getEmployer());
                if (serviceSocial is PretSociale)
                {
                    sqlCommand.Parameters.AddWithValue("@service", 1);
                }
                else if (serviceSocial is Dons)
                {
                    sqlCommand.Parameters.AddWithValue("@service", 2);
                }
                else // Credit Electromenager
                {
                    sqlCommand.Parameters.AddWithValue("@service", 3);
                }
                sqlCommand.Parameters.AddWithValue("@pv", serviceSocial.getPV().getId());
                sqlCommand.Parameters.AddWithValue("@somme", serviceSocial.getPrix());

                int j;
                for (int i = 0; i < serviceSocial.getprelevements().Count; i++)
                {
                    j = i + 1;
                    String str = "@remb" + j;
                    sqlCommand.Parameters.AddWithValue(str, serviceSocial.getprelevement(i));
                }
                for (int i = 0; i < serviceSocial.getDates().Count; i++)
                {
                    j = i + 1;
                    String str = "@date" + j;
                    sqlCommand.Parameters.AddWithValue(str, serviceSocial.getDate(i));
                }
                for (int i = serviceSocial.getDates().Count; i < 10; i++)
                {
                    j = i + 1;
                    String str = "@date" + j;
                    sqlCommand.Parameters.AddWithValue(str, DBNull.Value);
                }
                if (String.IsNullOrEmpty(serviceSocial.getobservation()))
                {
                    sqlCommand.Parameters.AddWithValue("@observation", DBNull.Value);
                }
                else
                {
                    sqlCommand.Parameters.AddWithValue("@observation", serviceSocial.getobservation());
                }
                if (serviceSocial is Pret)
                {
                    TypePret type = ((Pret)serviceSocial).getTypePret();
                    sqlCommand.Parameters.AddWithValue("@type", type.Id);
                }
                else
                {
                    sqlCommand.Parameters.AddWithValue("@type", DBNull.Value);
                }

                sqlCommand.ExecuteNonQuery();
            }
            sqlCommand.Dispose();
            sqlConnection.Close();
            try
            {
                if (serviceSocial is Electromenager)
                {
                    ConnectionBonCmd.AddBonCmd(((Electromenager)serviceSocial).GetBon_Cmd());
                    ConnectionFacture.AddFacture(((Electromenager)serviceSocial).GetFacture());
                }
            }
            catch { }
        }