| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.ComponentModel;
|
|---|
| 4 | using System.Data;
|
|---|
| 5 | using System.Drawing;
|
|---|
| 6 | using System.Text;
|
|---|
| 7 | using System.Windows.Forms;
|
|---|
| 8 | using System.Net;
|
|---|
| 9 | using System.Net.Mail;
|
|---|
| 10 | using System.Text.RegularExpressions;
|
|---|
| 11 | using System.IO;
|
|---|
| 12 |
|
|---|
| 13 | namespace Baza_Reklam
|
|---|
| 14 | {
|
|---|
| 15 | public partial class MailForm : Form
|
|---|
| 16 | {
|
|---|
| 17 | public MailForm(int custID,string temat, string zalacznik)
|
|---|
| 18 | {
|
|---|
| 19 | InitializeComponent();
|
|---|
| 20 |
|
|---|
| 21 | kLIENCI_OSOBY_DO_KONTAKTUTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 22 |
|
|---|
| 23 | sZal1TextBox.Text = zalacznik;
|
|---|
| 24 | openFileDialog1.FileName = zalacznik;
|
|---|
| 25 |
|
|---|
| 26 | tematTextBox.Text = temat;
|
|---|
| 27 |
|
|---|
| 28 | this.kLIENCI_OSOBY_DO_KONTAKTUTableAdapter.FillByCustomerId(this.rEKLAMADataSet.KLIENCI_OSOBY_DO_KONTAKTU,custID);
|
|---|
| 29 |
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | public MailForm(int custID, string temat, string zalacznik, string tresc)
|
|---|
| 33 | {
|
|---|
| 34 | InitializeComponent();
|
|---|
| 35 |
|
|---|
| 36 | // kLIENCI_OSOBY_DO_KONTAKTUTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 37 |
|
|---|
| 38 | sZal1TextBox.Text = zalacznik;
|
|---|
| 39 | openFileDialog1.FileName = zalacznik;
|
|---|
| 40 | trescTextBox.Text = tresc;
|
|---|
| 41 | tematTextBox.Text = temat;
|
|---|
| 42 | // doComboBox.Text = Utils.mailKlienta(custID);
|
|---|
| 43 | string mailKlienta = Utils.mailKlienta(custID);
|
|---|
| 44 | doEmailTextBox.Text = mailKlienta;
|
|---|
| 45 |
|
|---|
| 46 | // this.kLIENCI_OSOBY_DO_KONTAKTUTableAdapter.FillByCustomerId(this.rEKLAMADataSet.KLIENCI_OSOBY_DO_KONTAKTU, custID);
|
|---|
| 47 |
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | private void MailForm_Load(object sender, EventArgs e)
|
|---|
| 53 | {
|
|---|
| 54 | odTextBox.Text = User.getUser().Imie + " " + User.getUser().Nazwisko;
|
|---|
| 55 | odEmailTextBox.Text = User.getUser().Email;
|
|---|
| 56 | doWiadomosciTextBox.Text = User.getUser().Email;
|
|---|
| 57 | doComboBox.Text = "";
|
|---|
| 58 |
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | private void WylijButton_Click(object sender, EventArgs e)
|
|---|
| 62 | {
|
|---|
| 63 | //walidacja maili
|
|---|
| 64 |
|
|---|
| 65 | Regex r = new Regex("^[a-zA-Z0-9_\\.\\-]+@[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-\\.]+$");
|
|---|
| 66 |
|
|---|
| 67 | if (!r.IsMatch(odEmailTextBox.Text))
|
|---|
| 68 | {
|
|---|
| 69 | MessageBox.Show("Niepoprawny adres mailowy nadawcy");
|
|---|
| 70 | return;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | if (!r.IsMatch(doEmailTextBox.Text))
|
|---|
| 74 | {
|
|---|
| 75 | MessageBox.Show("Nieporawny adres mailowy odbiorcy");
|
|---|
| 76 | return;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | if (!r.IsMatch(doWiadomosciTextBox.Text))
|
|---|
| 80 | {
|
|---|
| 81 | MessageBox.Show("Nieporawny adres mailowy 'do wiadomoci'");
|
|---|
| 82 | return;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | this.Cursor = Cursors.WaitCursor;
|
|---|
| 86 |
|
|---|
| 87 | MailAddress adresOD = new MailAddress(odEmailTextBox.Text, odTextBox.Text);
|
|---|
| 88 | MailAddress adresDO = new MailAddress(doEmailTextBox.Text, doComboBox.Text);
|
|---|
| 89 | MailMessage message = new MailMessage(adresOD, adresDO);
|
|---|
| 90 |
|
|---|
| 91 | message.CC.Add(doWiadomosciTextBox.Text);
|
|---|
| 92 | message.Subject = tematTextBox.Text;
|
|---|
| 93 | message.Body = trescTextBox.Text;
|
|---|
| 94 |
|
|---|
| 95 | if (File.Exists(sZal1TextBox.Text))
|
|---|
| 96 | {
|
|---|
| 97 | message.Attachments.Add(new Attachment(sZal1TextBox.Text));
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | if (File.Exists(sZal2TextBox.Text))
|
|---|
| 101 | {
|
|---|
| 102 | message.Attachments.Add(new Attachment(sZal2TextBox.Text));
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | if (File.Exists(sZal3TextBox.Text))
|
|---|
| 106 | {
|
|---|
| 107 | message.Attachments.Add(new Attachment(sZal3TextBox.Text));
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | if (File.Exists(dZal1TextBox.Text))
|
|---|
| 111 | {
|
|---|
| 112 | message.Attachments.Add(new Attachment(dZal1TextBox.Text));
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | if (File.Exists(dZal2TextBox.Text))
|
|---|
| 116 | {
|
|---|
| 117 | message.Attachments.Add(new Attachment(dZal2TextBox.Text));
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | if (File.Exists(dZal3TextBox.Text))
|
|---|
| 121 | {
|
|---|
| 122 | message.Attachments.Add(new Attachment(dZal3TextBox.Text));
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | SmtpClient klientSMTP = new SmtpClient("poczta.ct.com.pl");
|
|---|
| 126 | klientSMTP.Timeout = 1000000;
|
|---|
| 127 | //klientSMTP.EnableSsl = false;
|
|---|
| 128 | //klientSMTP.Credentials = new System.Net.NetworkCredential(User.getUser().Email, User.getUser().Password);
|
|---|
| 129 | //MessageBox.Show(User.getUser().Email + User.getUser().Password);
|
|---|
| 130 |
|
|---|
| 131 | try
|
|---|
| 132 | {
|
|---|
| 133 | klientSMTP.Send(message);
|
|---|
| 134 | MessageBox.Show("Wiadomoæ zosta³a wys³ana");
|
|---|
| 135 | }
|
|---|
| 136 | catch (Exception e2)
|
|---|
| 137 | {
|
|---|
| 138 | MessageBox.Show(e2.Message);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | this.Cursor = Cursors.Default;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | private void dodajSZal1Button_Click(object sender, EventArgs e)
|
|---|
| 145 | {
|
|---|
| 146 | if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
|---|
| 147 | {
|
|---|
| 148 | sZal1TextBox.Text = openFileDialog1.FileName;
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | private void dodajSZal2Button_Click(object sender, EventArgs e)
|
|---|
| 153 | {
|
|---|
| 154 | if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
|---|
| 155 | {
|
|---|
| 156 | sZal2TextBox.Text = openFileDialog1.FileName;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | private void dodajSZal3Button_Click(object sender, EventArgs e)
|
|---|
| 162 | {
|
|---|
| 163 | if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
|---|
| 164 | {
|
|---|
| 165 | sZal3TextBox.Text = openFileDialog1.FileName;
|
|---|
| 166 | }
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | private void dodajDZal1Button_Click(object sender, EventArgs e)
|
|---|
| 170 | {
|
|---|
| 171 | if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
|---|
| 172 | {
|
|---|
| 173 | dZal1TextBox.Text = openFileDialog1.FileName;
|
|---|
| 174 | }
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | private void dodajDZal2Button_Click(object sender, EventArgs e)
|
|---|
| 178 | {
|
|---|
| 179 | if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
|---|
| 180 | {
|
|---|
| 181 | dZal2TextBox.Text = openFileDialog1.FileName;
|
|---|
| 182 | }
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | private void dodajDZal3Button_Click(object sender, EventArgs e)
|
|---|
| 186 | {
|
|---|
| 187 | if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
|---|
| 188 | {
|
|---|
| 189 | dZal3TextBox.Text = openFileDialog1.FileName;
|
|---|
| 190 | }
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | private void otworzSZal1Button_Click(object sender, EventArgs e)
|
|---|
| 194 | {
|
|---|
| 195 | if (File.Exists(sZal1TextBox.Text))
|
|---|
| 196 | {
|
|---|
| 197 | System.Diagnostics.Process.Start(sZal1TextBox.Text);
|
|---|
| 198 | }
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | private void otworzSZal2Button_Click(object sender, EventArgs e)
|
|---|
| 202 | {
|
|---|
| 203 | if (File.Exists(sZal2TextBox.Text))
|
|---|
| 204 | {
|
|---|
| 205 | System.Diagnostics.Process.Start(sZal2TextBox.Text);
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | private void otworzSZal3Button_Click(object sender, EventArgs e)
|
|---|
| 210 | {
|
|---|
| 211 | if (File.Exists(sZal3TextBox.Text))
|
|---|
| 212 | {
|
|---|
| 213 | System.Diagnostics.Process.Start(sZal3TextBox.Text);
|
|---|
| 214 | }
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | private void otworzDZal1Button_Click(object sender, EventArgs e)
|
|---|
| 218 | {
|
|---|
| 219 | if (File.Exists(dZal1TextBox.Text))
|
|---|
| 220 | {
|
|---|
| 221 | System.Diagnostics.Process.Start(dZal1TextBox.Text);
|
|---|
| 222 | }
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | private void otworzDZal2Button_Click(object sender, EventArgs e)
|
|---|
| 226 | {
|
|---|
| 227 | if (File.Exists(dZal2TextBox.Text))
|
|---|
| 228 | {
|
|---|
| 229 | System.Diagnostics.Process.Start(dZal2TextBox.Text);
|
|---|
| 230 | }
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | private void otworzDZal3Button_Click(object sender, EventArgs e)
|
|---|
| 234 | {
|
|---|
| 235 | if (File.Exists(dZal3TextBox.Text))
|
|---|
| 236 | {
|
|---|
| 237 | System.Diagnostics.Process.Start(dZal3TextBox.Text);
|
|---|
| 238 | }
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | private void doComboBox_SelectedValueChanged(object sender, EventArgs e)
|
|---|
| 242 | {
|
|---|
| 243 | if (doComboBox.SelectedValue != null)
|
|---|
| 244 | {
|
|---|
| 245 | if (kLIENCIOSOBYDOKONTAKTUBindingSource.Current != null)
|
|---|
| 246 | {
|
|---|
| 247 | doEmailTextBox.Text = doComboBox.SelectedValue.ToString();
|
|---|
| 248 | }
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | }
|
|---|
| 253 | } |
|---|