using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Baza_Reklam
{
    public partial class PaymentForm2 : Form
    {
        private int idWplaty;

        public int IdWplaty
        {
            get { return idWplaty; }
            set { idWplaty = value; }
        }
        private int idFaktury;

        public PaymentForm2(int idWplaty, int idFaktury)
        {
            this.idWplaty = idWplaty;
            this.idFaktury = idFaktury;
            InitializeComponent();
        }

        private void PaymentForm_Load(object sender, EventArgs e)
        {

            this.rEKLAMADataSet.Wplaty.Constraints.Remove("FAKTURY_Wplaty");

            wplatyTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
            VIEW_ZESTAWIENIE_FAKTUR_NOWETableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
            zestawienieFakturTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;

            if (idWplaty == 0)
            {
                /*
                DataRowView row = (DataRowView)wplatyBindingSource.AddNew();
                row["idFaktury"] = idFaktury;
                row["idZamowienia"] = this.rEKLAMADataSet.VIEW_ZESTAWIENIE_FAKTUR_NOWE[0].idZamowienia;
                wplatyBindingSource.EndEdit();
                 */
            }
            else
            {
                wplatyTableAdapter.FillByIdWplaty(this.rEKLAMADataSet.Wplaty, idWplaty);
            }

            REKLAMADataSet.WplatyRow wplata = this.rEKLAMADataSet.Wplaty[0];

            if (wplata.IsidZamowieniaNull())
            {
                //stara faktura
                UstawBindowanieDlaStarychFaktur();

                this.zestawienieFakturTableAdapter.FillByIdFaktury(this.rEKLAMADataSet.ZestawienieFaktur, wplata.idFaktury);
            }
            else
            {
                this.VIEW_ZESTAWIENIE_FAKTUR_NOWETableAdapter.FillByIdFaktury(this.rEKLAMADataSet.VIEW_ZESTAWIENIE_FAKTUR_NOWE, idFaktury);
            }
        }

        private void UstawBindowanieDlaStarychFaktur()
        {
            this.VIEW_ZESTAWIENIE_FAKTUR_NOWEBindingSource.DataMember = "ZestawienieFaktur";

            this.iD_REKLAMYTextBox.DataBindings.Clear();
            this.iD_REKLAMYTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.VIEW_ZESTAWIENIE_FAKTUR_NOWEBindingSource, "NR_FK", true));

            this.suma_zaplatTextBox.DataBindings.Clear();
            this.suma_zaplatTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.VIEW_ZESTAWIENIE_FAKTUR_NOWEBindingSource, "suma_zaplat", true, System.Windows.Forms.DataSourceUpdateMode.OnValidation, null, "C2"));

            this.waluta_bruttoTextBox1.DataBindings.Clear();
            this.waluta_bruttoTextBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.VIEW_ZESTAWIENIE_FAKTUR_NOWEBindingSource, "waluta_brutto", true, System.Windows.Forms.DataSourceUpdateMode.OnValidation, null, "N2"));

            this.bRUTTOTextBox.DataBindings.Clear();
            this.bRUTTOTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.VIEW_ZESTAWIENIE_FAKTUR_NOWEBindingSource, "BRUTTO", true, System.Windows.Forms.DataSourceUpdateMode.OnValidation, null, "C2"));
        }

        private void dodajButton_Click(object sender, EventArgs e)
        {
            /*
            if ((sYMBOL_POTWIERDZENIATextBox.Text == "") | (rODZAJ_POTWIERDZENIAComboBox.SelectedIndex == -1))
            {
                MessageBox.Show("Uzupełnij wszystkie pola");
                return;
            }
            
            this.Validate();

            this.wplatyBindingSource.EndEdit();
            this.wplatyTableAdapter.Update(this.rEKLAMADataSet.Wplaty);
            this.idWplaty = rEKLAMADataSet.Wplaty[0].idWplaty;
             */
            this.DialogResult = DialogResult.OK;
        }

        private void anulujButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}