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 DzialAddForm : Form
    {
        public DzialAddForm(int id)
        {
            InitializeComponent();

            this.dzialyTableAdapter.Connection.ConnectionString = ConnString.getConnString().ZamowieniaConnStr;

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

                dzialyBindingSource.MoveLast();
                dzialyBindingSource.EndEdit();
            }
            else
            {
               dzialyTableAdapter.FillByIDE(this.zamowieniaDataSet.Dzialy, id);
            }

        }

        private void zapiszButton_Click(object sender, EventArgs e)
        {
            this.dzialyBindingSource.EndEdit();
            this.dzialyTableAdapter.Update(this.zamowieniaDataSet.Dzialy);
            MessageBox.Show("Zmiany zostały zapisane");
            this.DialogResult = DialogResult.OK;
        }

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