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;

namespace BazaZamowien
{
    public partial class UserAddFormZamowienia : Form
    {
        public UserAddFormZamowienia(int id)
        {
            InitializeComponent();

            dzialyTableAdapter.Connection.ConnectionString = ConnString.getConnString().ZamowieniaConnStr;
            grupyRoboczeTableAdapter.Connection.ConnectionString = ConnString.getConnString().ZamowieniaConnStr;
            usersTableAdapter.Connection.ConnectionString = ConnString.getConnString().ZamowieniaConnStr;

            this.dzialyTableAdapter.FillByAll(this.zamowieniaDataSet.Dzialy);
            this.grupyRoboczeTableAdapter.Fill(this.zamowieniaDataSet.GrupyRobocze);



            if (id == 0)
            {
                DataView table = (DataView)usersBindingSource.List;
                DataRowView row = table.AddNew();

                usersBindingSource.MoveLast();
                usersBindingSource.EndEdit();         
            }
            else
            {
                usersTableAdapter.FillByIDE(this.zamowieniaDataSet.Users,id);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.usersBindingSource.EndEdit();
            this.usersTableAdapter.Update(this.zamowieniaDataSet.Users);
            MessageBox.Show("Zmiany zostały zapisane");
            this.DialogResult = DialogResult.OK;
        }

    }
}