| 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 AgentAddForm : Form
|
|---|
| 12 | {
|
|---|
| 13 |
|
|---|
| 14 | // bool nowyRekord;
|
|---|
| 15 |
|
|---|
| 16 | string starySymbol = string.Empty;
|
|---|
| 17 |
|
|---|
| 18 | public AgentAddForm(int idAgenta, int IdAgencji)
|
|---|
| 19 | {
|
|---|
| 20 | InitializeComponent();
|
|---|
| 21 |
|
|---|
| 22 | this.aGENCITableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 23 | this.pLANY_PROWIZJITableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 24 | this.pLANY_PROWIZJITableAdapter.Fill(this.sLOWNIKDataSet.PLANY_PROWIZJI);
|
|---|
| 25 |
|
|---|
| 26 | if (idAgenta == 0)
|
|---|
| 27 | {
|
|---|
| 28 | DataView table = (DataView)aGENCIBindingSource.List;
|
|---|
| 29 | DataRowView row = table.AddNew();
|
|---|
| 30 | row["id_agencji"] = IdAgencji;
|
|---|
| 31 | // row["f_ROZ"] = "K";
|
|---|
| 32 | aGENCIBindingSource.EndEdit();
|
|---|
| 33 |
|
|---|
| 34 | // nowyRekord = true;
|
|---|
| 35 | }
|
|---|
| 36 | else
|
|---|
| 37 | {
|
|---|
| 38 | this.aGENCITableAdapter.FillByIdAgenta(this.sLOWNIKDataSet.AGENCI, idAgenta);
|
|---|
| 39 |
|
|---|
| 40 | starySymbol = this.sLOWNIKDataSet.AGENCI[0].Symbol;
|
|---|
| 41 |
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | private void ZapiszButton_Click(object sender, EventArgs e)
|
|---|
| 46 | {
|
|---|
| 47 | //raise f_ROZTextBox.Validating;
|
|---|
| 48 |
|
|---|
| 49 | f_ROZTextBox.Focus();
|
|---|
| 50 |
|
|---|
| 51 | if (Validate())
|
|---|
| 52 | {
|
|---|
| 53 | this.aGENCIBindingSource.EndEdit();
|
|---|
| 54 | this.aGENCITableAdapter.Update(this.sLOWNIKDataSet.AGENCI);
|
|---|
| 55 | MessageBox.Show("Zmiany zosta³y zapisane");
|
|---|
| 56 | this.DialogResult = DialogResult.OK;
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | private void AnulujButton_Click(object sender, EventArgs e)
|
|---|
| 62 | {
|
|---|
| 63 | this.Close();
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | ErrorProvider errProvider = new ErrorProvider();
|
|---|
| 67 |
|
|---|
| 68 | private void f_ROZTextBox_Validating(object sender, CancelEventArgs e)
|
|---|
| 69 | {
|
|---|
| 70 | DataRowView row = (DataRowView)aGENCIBindingSource.Current;
|
|---|
| 71 |
|
|---|
| 72 | if (f_ROZTextBox.Text.Length != 3)
|
|---|
| 73 | {
|
|---|
| 74 | e.Cancel = true;
|
|---|
| 75 |
|
|---|
| 76 | errProvider.SetError((Control)sender, "Kod powienien mieæ 3 znaki.");
|
|---|
| 77 | return;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | if (starySymbol != string.Empty)
|
|---|
| 81 | {
|
|---|
| 82 | if (!Utils.tagAgentaUnikalny(f_ROZTextBox.Text, starySymbol))
|
|---|
| 83 | {
|
|---|
| 84 | e.Cancel = true;
|
|---|
| 85 |
|
|---|
| 86 | errProvider.SetError((Control)sender, "Kod powienien byæ unikalny.");
|
|---|
| 87 | return;
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 | else
|
|---|
| 91 | {
|
|---|
| 92 | if (!Utils.tagAgentaUnikalny(f_ROZTextBox.Text, symbolTextBox1.Text))
|
|---|
| 93 | {
|
|---|
| 94 | e.Cancel = true;
|
|---|
| 95 |
|
|---|
| 96 | errProvider.SetError((Control)sender, "Kod powienien byæ unikalny.");
|
|---|
| 97 | return;
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | errProvider.SetError((Control)sender, "");
|
|---|
| 102 |
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | private void AgentAddForm_Load(object sender, EventArgs e)
|
|---|
| 106 | {
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | }
|
|---|
| 110 | } |
|---|