using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BazaZamowien.Classes;
using BazaZamowien.PREMIEDataSetTableAdapters;

namespace BazaZamowien
{
    public partial class UserAddFormPremie : Form
    {
        GrupyTableAdapter grupyTableAdapter = new GrupyTableAdapter();

        public UserAddFormPremie(int id)
        {
            InitializeComponent();

            grupyTableAdapter.Connection.ConnectionString = ConnString.getConnString().PremieConnStr;
            usersTableAdapter.Connection.ConnectionString = ConnString.getConnString().PremieConnStr;

            interface_Pracownicy2TableAdapter.Connection.ConnectionString = ConnString.getConnString().PremieConnStr;
            this.interface_Pracownicy2TableAdapter.Fill(this.pREMIEDataSet.Interface_Pracownicy2);

            iDEGrupaComboBox.DataSource = grupyTableAdapter.GetData();
            iDEGrupaComboBox.DisplayMember = "NazwaGrupy";
            iDEGrupaComboBox.ValueMember = "IDE";
            
            if (id == 0)
            {
                DataView table = (DataView)usersBindingSource.List;
                DataRowView row = table.AddNew();

                usersBindingSource.MoveLast();
                usersBindingSource.EndEdit();
            }
            else
            {
                usersTableAdapter.FillByIDEPracownik(this.pREMIEDataSet.Users, id);
            }         
        }
  
        private void anulujButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void zapiszButton_Click(object sender, EventArgs e)
        {
            this.usersBindingSource.EndEdit();
            this.usersTableAdapter.Update(this.pREMIEDataSet.Users);
            MessageBox.Show("Zmiany zostały zapisane");
            this.DialogResult = DialogResult.OK;            
        }

    }
}