| 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.IO;
|
|---|
| 9 |
|
|---|
| 10 | namespace Baza_Reklam
|
|---|
| 11 | {
|
|---|
| 12 | public partial class LogaKlientowForm : Form
|
|---|
| 13 | {
|
|---|
| 14 |
|
|---|
| 15 | #region Fields (1)
|
|---|
| 16 |
|
|---|
| 17 | private int customerId;
|
|---|
| 18 |
|
|---|
| 19 | #endregion Fields
|
|---|
| 20 |
|
|---|
| 21 | #region Constructors (1)
|
|---|
| 22 |
|
|---|
| 23 | public LogaKlientowForm(int customerId)
|
|---|
| 24 | {
|
|---|
| 25 | InitializeComponent();
|
|---|
| 26 | this.customerId = customerId;
|
|---|
| 27 |
|
|---|
| 28 | this.kLIENCI_INTERNET_LOGOTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | #endregion Constructors
|
|---|
| 32 |
|
|---|
| 33 | #region Methods (5)
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | // Private Methods (5)
|
|---|
| 37 |
|
|---|
| 38 | private bool CheckImageSize()
|
|---|
| 39 | {
|
|---|
| 40 | Image image = Image.FromFile(openFileDialog1.FileName);
|
|---|
| 41 | if (image.Size.Height > 75 || image.Size.Width > 150)
|
|---|
| 42 | {
|
|---|
| 43 | MessageBox.Show("Logo ma nieodpowiednie wymiary (150 x 75)");
|
|---|
| 44 | return false;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | return true;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | private void DodajLogoToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 51 | {
|
|---|
| 52 | if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
|---|
| 53 | {
|
|---|
| 54 |
|
|---|
| 55 | if (!CheckImageSize())
|
|---|
| 56 | {
|
|---|
| 57 | return;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | kLIENCI_INTERNET_LOGOTableAdapter.Insert(customerId,openFileDialog1.SafeFileName,"",ImageToBytes(openFileDialog1.FileName));
|
|---|
| 61 |
|
|---|
| 62 | this.kLIENCI_INTERNET_LOGOTableAdapter.FillBy(this.bAZA_REKLAMDataSet.KLIENCI_INTERNET_LOGO, customerId);
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | private byte[] ImageToBytes(string fileName)
|
|---|
| 67 | {
|
|---|
| 68 | FileInfo fInfo = new FileInfo(fileName);
|
|---|
| 69 |
|
|---|
| 70 | long bytesNumber = fInfo.Length;
|
|---|
| 71 |
|
|---|
| 72 | FileStream stream = new FileStream(fileName, FileMode.Open,FileAccess.Read);
|
|---|
| 73 | BinaryReader reader = new BinaryReader(stream);
|
|---|
| 74 |
|
|---|
| 75 | byte[] byteArray = reader.ReadBytes((int)bytesNumber);
|
|---|
| 76 |
|
|---|
| 77 | reader.Close();
|
|---|
| 78 | stream.Close();
|
|---|
| 79 |
|
|---|
| 80 | return byteArray;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | private void LogaKlientowForm_Load(object sender, EventArgs e)
|
|---|
| 84 | {
|
|---|
| 85 | this.kLIENCI_INTERNET_LOGOTableAdapter.FillBy(this.bAZA_REKLAMDataSet.KLIENCI_INTERNET_LOGO,customerId);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | private void UsunLogoToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 89 | {
|
|---|
| 90 | if (kLIENCI_INTERNET_LOGOBindingSource.Current != null)
|
|---|
| 91 | {
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | if (Utils.logoByloWykorzystane(Convert.ToInt32(((DataRowView)kLIENCI_INTERNET_LOGOBindingSource.Current)["ID"])))
|
|---|
| 96 | {
|
|---|
| 97 | kLIENCI_INTERNET_LOGOBindingSource.RemoveCurrent();
|
|---|
| 98 | kLIENCI_INTERNET_LOGOTableAdapter.Update(bAZA_REKLAMDataSet.KLIENCI_INTERNET_LOGO);
|
|---|
| 99 | }
|
|---|
| 100 | else
|
|---|
| 101 | {
|
|---|
| 102 | MessageBox.Show("Logo jest przypisane do reklamy.");
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | #endregion Methods
|
|---|
| 109 |
|
|---|
| 110 | }
|
|---|
| 111 | } |
|---|