IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

application d'envoi SMS en C#


Sujet :

C#

  1. #1
    Membre actif
    Inscrit en
    Octobre 2006
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 73
    Par défaut application d'envoi SMS en C#
    bonjour tous le monde je développe une application en c# d'envoi sms par telephone connecte au port usb de pc en utilisant les commandes at voila mon code de la form SMS
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
     
        using System.IO.Ports;
    namespace SMS
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                loadPorts();
            }
            private void loadPorts()
            {
                string[] ports = SerialPort.GetPortNames();
                foreach (string port in ports)
                {
                    cboPorts.Items.Add(port);
                }
            }
            private void btnSend_Click(object sender, EventArgs e)
            {
                SmsClass sm = new SmsClass(cboPorts.Text);
                sm.Opens();
                sm.sendSms(txtPhone.Text, txtMessage.Text);
                sm.Closes();
                MessageBox.Show("Message Sent!");
            }
     
            private void cboPorts_SelectedIndexChanged(object sender, EventArgs e)
            {
     
            }
     
            private void txtPhone_TextChanged(object sender, EventArgs e)
            {
     
            }
     
            private void txtMessage_TextChanged(object sender, EventArgs e)
            {
     
            }
     
     
     
     
        }
    }
    et voila le code de program.cs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;
     
    namespace WindowsFormsApplication5
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    }
    j'utilise la class smsclass pour communiquer avec le port et envoyer les commandes at
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;
    using System.IO.Ports;
    using System.Windows.Forms;
    namespace SMS
    {
        class SmsClass
        {
            SerialPort serialPort;
            public SmsClass(string comPort)
            {
                this.serialPort = new SerialPort();
                this.serialPort.PortName = comPort;
                this.serialPort.BaudRate = 9600;
                this.serialPort.Parity = Parity.None;
                this.serialPort.DataBits = 8;
                this.serialPort.StopBits = StopBits.One;
                this.serialPort.Handshake = Handshake.RequestToSend;
                this.serialPort.DtrEnable = true;
                this.serialPort.RtsEnable = true;
                this.serialPort.NewLine = System.Environment.NewLine;
            }
            public bool sendSms(string cellNo, string sms)
            {
                string messages = null;
                messages = sms;
                if (this.serialPort.IsOpen == true)
                {
                    try
                    {
                        this.serialPort.WriteLine("AT" + (char)(13));
                        Thread.Sleep(4);
                        this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
                        Thread.Sleep(5);
                        this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\"");
                        Thread.Sleep(10);
                        this.serialPort.WriteLine(">" + messages + (char)(26));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Source);
                    }
                    return true;
                }
                else
                    return false;
            }
     
            public void Opens()
            {
                if (this.serialPort.IsOpen == false)
                {
                    this.serialPort.Open();
                }
            }
            public void Closes()
            {
                if (this.serialPort.IsOpen == true)
                {
                    this.serialPort.Close();
                }
            }
        }
    }
    mon probleme c'est quand j'execute le programe il ma'affiche une ereur dans le code de program.cs :
    Error 1 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?) D:\Program.cs 18 33 WindowsFormsApplication5
    merci de m'aider svp

  2. #2
    Rédacteur
    Avatar de Nathanael Marchand
    Homme Profil pro
    Expert .Net So@t
    Inscrit en
    Octobre 2008
    Messages
    3 615
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Expert .Net So@t
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2008
    Messages : 3 615
    Par défaut
    il manque
    dans program.cs

  3. #3
    Membre actif
    Inscrit en
    Octobre 2006
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 73
    Par défaut
    le même problème persiste

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Application d'envoi de SMS
    Par skywalker70 dans le forum Android
    Réponses: 2
    Dernier message: 20/11/2012, 13h14
  2. Réponses: 3
    Dernier message: 28/05/2012, 22h08
  3. [Débutant] application de gestion d’élèves et envoi SMS aux parent
    Par belakhdarbts10 dans le forum VB.NET
    Réponses: 4
    Dernier message: 07/12/2011, 22h38
  4. application d'envoi de sms
    Par teleinfo dans le forum JDBC
    Réponses: 0
    Dernier message: 26/10/2009, 17h21
  5. recherche d'application d'envoi de sms sur ubuntu
    Par le_perse dans le forum Applications et environnements graphiques
    Réponses: 0
    Dernier message: 21/09/2007, 16h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo