root/Baza Reklam 2 - Faktury/SMSform.cs @ 366

Wersja 65, 2.7 KB (wprowadzona przez dorota, 17 years temu)
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.Net;
9using System.IO;
10using System.Web;
11using System.Text.RegularExpressions;
12
13namespace Baza_Reklam
14{
15    public partial class SMSform : Form
16    {
17        private int customerId;
18
19        public SMSform(string nrTel, int custID)
20        {
21            InitializeComponent();
22            ntTelTextBox.Text = nrTel;
23            this.customerId = custID;
24
25            this.kontaktyTableAdapter1.Connection.ConnectionString = ConnString.getConnString().Value;
26        }
27
28        private void button1_Click(object sender, EventArgs e)
29        {
30            if (ntTelTextBox.Text == "")
31            {
32                MessageBox.Show("Podaj nr telefonu");
33                return;
34            }
35
36            if (trescTextBox.Text == "")
37            {
38                MessageBox.Show("Podaj treœæ sms-a");
39                return;
40            }
41           
42            ASCIIEncoding encoding = new ASCIIEncoding();
43
44            string postData = "login=" + HttpUtility.UrlEncode("CT_CTRAVEL") + "&pass=" + HttpUtility.UrlEncode("jacek@ct.") +
45                "&MSISDN=" + HttpUtility.UrlEncode(ntTelTextBox.Text) + "&body="
46                + HttpUtility.UrlEncode(trescTextBox.Text);
47            byte[] pom1 = encoding.GetBytes(postData);
48
49            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.wapster.pl/smssender.asp");
50            req.Method = "POST";
51            req.ContentType = "application/x-www-form-urlencoded";
52            req.ContentLength = pom1.Length;
53           
54            Stream reqStream = req.GetRequestStream();
55            reqStream.Write(pom1, 0, pom1.Length);
56            reqStream.Close();
57           
58            Stream stream = req.GetResponse().GetResponseStream();
59            StreamReader sr = new StreamReader(stream);
60            string stronka = sr.ReadToEnd();
61            if (stronka.Contains("<response><value>1</value></response>"))
62            {           
63                MessageBox.Show("Wiadomoœæ zosta³a wys³ana.");
64                dodajDoKontaktow();
65            }
66            else
67            {
68                MessageBox.Show("Wyst¹pi³ b³¹d. Wiadomoœæ nie zosta³a wys³ana.");
69            }
70
71            sr.Close();
72            stream.Close();
73            this.Close();
74        }
75
76        private void dodajDoKontaktow()
77        {
78            kontaktyTableAdapter1.Insert(this.customerId, User.getUser().Login, DateTime.Now, "SMS", ntTelTextBox.Text + " \n " + trescTextBox.Text);
79        }
80
81        private void SMSform_Load(object sender, EventArgs e)
82        {
83
84        }
85    }
86}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.