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 PaymentForm : Form
    {
        
        private int reklamaId;

        public PaymentForm(int rekId)
        {
            InitializeComponent();
            reklamaId = rekId;
        }

        private void PaymentForm_Load(object sender, EventArgs e)
        {
            rEKLAMATableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
            fAKTURYTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;

            this.rEKLAMATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, reklamaId);


            if (rEKLAMABindingSource.Current != null)
            {
                DataRowView row = (DataRowView)rEKLAMABindingSource.Current;

                if (row["DATA ZAPŁATY"] == DBNull.Value)
                {
                    dATA_ZAPŁATYDateTimePicker.Value = DateTime.Today;
                }

                if ((row["FAKTURA WYSTAWIONO"] != DBNull.Value) && (Convert.ToBoolean(row["FAKTURA WYSTAWIONO"]) == true))
                {
                    int id_faktury = Convert.ToInt32(row["ID_FAKTURY"]);

                    this.fAKTURYTableAdapter.FillByIdFaktury(this.rEKLAMADataSet.FAKTURY, id_faktury);
                }
            }
        }

        private void dodajButton_Click(object sender, EventArgs e)
        {
            if (zAPŁACONOCheckBox.Checked)
            {
                if ((sYMBOL_POTWIERDZENIATextBox.Text == "") | (rODZAJ_POTWIERDZENIAComboBox.SelectedIndex == -1))
                {
                    MessageBox.Show("Uzupełnij wszystkie pola");
                    return;
                }
            }
            else
            {
                DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
                row["DATA ZAPŁATY"] = DBNull.Value;
                row["sYMBOL POTWIERDZENIA"] = DBNull.Value;
                row["rODZAJ POTWIERDZENIA"] = DBNull.Value;                
            }

            this.Validate();
            this.rEKLAMABindingSource.EndEdit();
            this.rEKLAMATableAdapter.Update(this.rEKLAMADataSet.REKLAMA);
            this.DialogResult = DialogResult.OK;
      
        }

        private void anulujButton_Click(object sender, EventArgs e)
        {
            rEKLAMABindingSource.CancelEdit();
        }
       
    }
}