| 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 |
|
|---|
| 9 | namespace Baza_Reklam
|
|---|
| 10 | {
|
|---|
| 11 | public partial class AddZamowienieForm : Form
|
|---|
| 12 | {
|
|---|
| 13 | private REKLAMADataSetTableAdapters.KLIENCITableAdapter klienciTableAdapter =
|
|---|
| 14 | new Baza_Reklam.REKLAMADataSetTableAdapters.KLIENCITableAdapter();
|
|---|
| 15 |
|
|---|
| 16 | public REKLAMADataSet.zamowieniaDataTable Zamowienia
|
|---|
| 17 | {
|
|---|
| 18 | get
|
|---|
| 19 | {
|
|---|
| 20 | return this.rEKLAMADataSet.zamowienia;
|
|---|
| 21 | }
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | public AddZamowienieForm(int idZam, int idKlienta)
|
|---|
| 25 | {
|
|---|
| 26 | InitializeComponent();
|
|---|
| 27 |
|
|---|
| 28 | this.zamowieniaTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 29 | this.kONTATableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 30 | this.aGENCITableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 31 | this.klienciTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 32 |
|
|---|
| 33 | List<BoundItem> list = new List<BoundItem>();
|
|---|
| 34 | list.Add(new BoundItem(7,"7 dni"));
|
|---|
| 35 | list.Add(new BoundItem(14,"14 dni"));
|
|---|
| 36 | list.Add(new BoundItem(30,"30 dni"));
|
|---|
| 37 | czasPlatnosciListBox.DisplayMember = "DisplayValue";
|
|---|
| 38 | czasPlatnosciListBox.ValueMember = "IDEvalue1";
|
|---|
| 39 | czasPlatnosciListBox.DataSource = list;
|
|---|
| 40 |
|
|---|
| 41 | procentProwizjiTextBox.DataBindings[0].Format += new ConvertEventHandler(DecimalToProcent);
|
|---|
| 42 | procentProwizjiTextBox.DataBindings[0].Parse += new ConvertEventHandler(ProcentToDecimal);
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | REKLAMADataSet.zamowieniaRow row;
|
|---|
| 46 | if (idZam == 0)
|
|---|
| 47 | {
|
|---|
| 48 | DataView table = (DataView)zamowieniaBindingSource.List;
|
|---|
| 49 | DataRowView r = table.AddNew();
|
|---|
| 50 | row = (REKLAMADataSet.zamowieniaRow)r.Row;
|
|---|
| 51 |
|
|---|
| 52 | row.nrZamowienia = Utils.numerNowegoZamowienia(idKlienta, DateTime.Today.Year);
|
|---|
| 53 | row.rokZamowienia = DateTime.Today.Year;
|
|---|
| 54 | row.kodAgenta = User.getUser().Kod_agenta;
|
|---|
| 55 | row.idKlienta = idKlienta;
|
|---|
| 56 |
|
|---|
| 57 | row.EndEdit();
|
|---|
| 58 | this.zamowieniaBindingSource.EndEdit();
|
|---|
| 59 | }
|
|---|
| 60 | else
|
|---|
| 61 | {
|
|---|
| 62 | this.zamowieniaTableAdapter.FillByIdZamowienia(this.rEKLAMADataSet.zamowienia, idZam);
|
|---|
| 63 | row = this.rEKLAMADataSet.zamowienia[0];
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | REKLAMADataSet.KLIENCIRow k = (REKLAMADataSet.KLIENCIRow)klienciTableAdapter.GetDataByCustomerId(row.idKlienta)[0];
|
|---|
| 67 | numerZamowieniaLabel1.Text = k.kodKlienta + "/" + row.rokZamowienia + "/" + row.kodAgenta + "/" + row.nrZamowienia;
|
|---|
| 68 |
|
|---|
| 69 | kierownikGroupBox.Enabled = User.getUser().St_kierownik;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | private void AddZamowienieForm_Load(object sender, EventArgs e)
|
|---|
| 73 | {
|
|---|
| 74 | string agent = ((DataRowView)zamowieniaBindingSource.Current)["kodAgenta"].ToString();
|
|---|
| 75 | int idAgencji = Utils.idAgencji(agent);
|
|---|
| 76 |
|
|---|
| 77 | this.kONTATableAdapter.FillByIdAgencji(this.sLOWNIKDataSet.KONTA, idAgencji);
|
|---|
| 78 | this.aGENCITableAdapter.FillByAktywny(this.sLOWNIKDataSet.AGENCI);
|
|---|
| 79 |
|
|---|
| 80 | this.zamowieniaBindingSource.ResetBindings(false);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | private void anulujButton_Click(object sender, EventArgs e)
|
|---|
| 84 | {
|
|---|
| 85 |
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | private void button3_Click(object sender, EventArgs e)
|
|---|
| 89 | {
|
|---|
| 90 | if (kONTABindingSource.Current != null)
|
|---|
| 91 | {
|
|---|
| 92 | DataRowView row = (DataRowView)kONTABindingSource.Current;
|
|---|
| 93 | MessageBox.Show(row["konto"].ToString());
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | private void zapiszButton_Click(object sender, EventArgs e)
|
|---|
| 98 | {
|
|---|
| 99 | this.zamowieniaBindingSource.EndEdit();
|
|---|
| 100 | zamowieniaTableAdapter.Update(this.rEKLAMADataSet.zamowienia);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | /// <summary>
|
|---|
| 104 | /// formatowanie do decimal -> %
|
|---|
| 105 | /// </summary>
|
|---|
| 106 | private void DecimalToProcent(object sender, ConvertEventArgs cevent)
|
|---|
| 107 | {
|
|---|
| 108 | if (Convert.ToDecimal(cevent.Value) > 1)
|
|---|
| 109 | {
|
|---|
| 110 | // cevent.Value = Convert.ToDecimal(cevent.Value) / 100;
|
|---|
| 111 | }
|
|---|
| 112 | cevent.Value = String.Format("{0:P}", cevent.Value);
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | /// <summary>
|
|---|
| 116 | /// formatowanie do % -> decimal
|
|---|
| 117 | /// </summary>
|
|---|
| 118 | private void ProcentToDecimal(object sender, ConvertEventArgs cevent)
|
|---|
| 119 | {
|
|---|
| 120 | string pom = cevent.Value.ToString();
|
|---|
| 121 | if (cevent.Value.ToString().EndsWith("%"))
|
|---|
| 122 | {
|
|---|
| 123 | pom = cevent.Value.ToString().Substring(0, cevent.Value.ToString().Length - 1);
|
|---|
| 124 | }
|
|---|
| 125 | decimal p = Decimal.Parse(pom) / 100;
|
|---|
| 126 | cevent.Value = p.ToString();
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 | } |
|---|