private void InitializeComboBoxes()
        {
            using (var context = new DataClasses2DataContext())
            {
                var users = context.uzytkownicy.Select(x => new ComboboxModel
                {
                    DisplayMember = x.imie + x.nazwisko, Id = x.id_uzytkownika
                }).ToArray();
                var categories = context.kategoria.Where(x => x.id_nadkategoria == null).Select(x => new ComboboxModel
                {
                    DisplayMember = x.nazwa, Id = x.id_kategoria
                }).ToArray();
                var operationForms = context.forma_platnosci.Select(x => new ComboboxModel
                {
                    DisplayMember = x.nazwa, Id = x.id_forma_platnosci
                }).ToArray();

                comboBoxUsers.Items.AddRange(users);
                comboBoxCategory.Items.AddRange(categories);
                comboBoxOperationForm.Items.AddRange(operationForms);
            }
            comboBoxUsers.DisplayMember = "DisplayMember";
            comboBoxUsers.ValueMember   = "Id";

            comboBoxCategory.DisplayMember = "DisplayMember";
            comboBoxCategory.ValueMember   = "Id";

            comboBoxSubcategory.DisplayMember = "DisplayMember";
            comboBoxSubcategory.ValueMember   = "Id";

            comboBoxOperationForm.DisplayMember = "DisplayMember";
            comboBoxOperationForm.ValueMember   = "Id";

            wczytaj_kategorie();
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            using (var context = new DataClasses2DataContext())
            {
                var userId = comboBoxUsers.SelectedIndex != -1
                    ? ((ComboboxModel)comboBoxUsers.Items[comboBoxUsers.SelectedIndex]).Id
                    : 0;
                var categoryId = comboBoxCategory.SelectedIndex != -1
                    ? ((ComboboxModel)comboBoxCategory.Items[comboBoxCategory.SelectedIndex]).Id
                    : 0;
                var subcategoryId = comboBoxSubcategory.SelectedIndex != -1
                    ? ((ComboboxModel)comboBoxSubcategory.Items[comboBoxSubcategory.SelectedIndex]).Id
                    : 0;
                var operationFormId = comboBoxOperationForm.SelectedIndex != -1
                    ? ((ComboboxModel)comboBoxOperationForm.Items[comboBoxOperationForm.SelectedIndex]).Id
                    : 0;

                if (Walidacja() == true)
                {
                    return;
                }

                if (Walidacja() == false)
                {
                    if (IsEditMode)
                    {
                        var operation = context.operacje.FirstOrDefault(x => x.id_operacji == OperationDto.Id);
                        if (operation != null)
                        {
                            operation.data               = dateTimePickerDate.Value;
                            operation.kwota              = TryParse(textBoxPrice.Text, out var price) ? price : 0;
                            operation.id_uzytkownika     = userId;
                            operation.id_kategoria       = subcategoryId;
                            operation.id_forma_platnosci = operationFormId;
                            operation.opis               = richTextBoxDescription.Text;
                        }
                    }
                    else
                    {
                        context.operacje.InsertOnSubmit(new operacje()
                        {
                            data               = dateTimePickerDate.Value,
                            kwota              = TryParse(textBoxPrice.Text, out var price) ? price : 0,
                            id_uzytkownika     = userId,
                            id_kategoria       = subcategoryId,
                            id_forma_platnosci = operationFormId,
                            opis               = richTextBoxDescription.Text
                        });
 void wyswietlUzytkownikow()
 {
     using (var context = new DataClasses2DataContext())
     {
         var query = from u in context.uzytkownicy
                     select new
         {
             uzytkownik = u.imie + " " + u.nazwisko,
             id         = u.id_uzytkownika
         };
         foreach (var r in query)
         {
             tW_users.Nodes.Add(r.id.ToString(), r.uzytkownik);
         }
     }
 }
        private void dodajToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var text = string.Empty;

            if (tW_kategorie.SelectedNode != null)
            {
                int id;
                using (var context = new DataClasses2DataContext())
                {
                    if (tW_kategorie.SelectedNode.Level == 0)
                    {
                        id = -1;
                        if (tW_kategorie.SelectedNode.Name == "wydatek")
                        {
                            text = "wydatek";
                        }
                        else
                        {
                            text = "przychod";
                        }
                    }

                    else if (tW_kategorie.SelectedNode.Level == 1) // dodaj kat jak kliknie na nadkategorie
                    {
                        var query = context.kategoria.Where(t => t.nazwa == tW_kategorie.SelectedNode.Text);
                        id = query.FirstOrDefault().id_kategoria;
                    }
                    else
                    {
                        var query = context.kategoria.Where(t => t.nazwa == tW_kategorie.SelectedNode.Parent.Text);
                        id = query.FirstOrDefault().id_kategoria;
                    }
                }
                var uDK = new uc_dodaj_kategorię(this, 0, id, text)
                {
                    Size     = new Size(121, 90),
                    Location = new Point(3, 250)
                };
                this.Controls.Add(uDK);
                uDK.BringToFront();
            }
        }
        private void ReadEditedOperation()
        {
            using (var context = new DataClasses2DataContext())
            {
                var operation = context.operacje.FirstOrDefault(x => x.id_operacji == EditedId);
                if (operation == null)
                {
                    throw new ArgumentException("No operation with given id in the database");
                }

                OperationDto = new OperationDto()
                {
                    Id            = operation.id_operacji,
                    Data          = operation.data,
                    Price         = operation.kwota,
                    CategoryId    = operation.id_kategoria,
                    UserId        = operation.id_uzytkownika,
                    PaymentFormId = operation.id_forma_platnosci,
                    Description   = operation.opis,
                };
            }
            SetEditedOperationData();
        }
        private bool Walidacja()
        {
            using (var context = new DataClasses2DataContext())
            {
                bool Check = false;

                if (comboBoxUsers.SelectedIndex == -1)
                {
                    labelWybierzUzytkownika.Visible = true;
                    pictureBox1.Visible             = true;
                    Check = true;
                }
                else
                {
                    labelWybierzUzytkownika.Visible = false;
                    pictureBox1.Visible             = false;
                }

                if (comboBoxOperationForm.SelectedIndex == -1)
                {
                    labelWybierzPłatność.Visible = true;
                    pictureBox2.Visible          = true;
                    Check = true;
                }
                else
                {
                    labelWybierzPłatność.Visible = false;
                    pictureBox2.Visible          = false;
                }

                if (comboBoxCategory.SelectedIndex == -1)
                {
                    labelWybierzKategorie.Visible = true;
                    pictureBox3.Visible           = true;
                    Check = true;
                }
                else
                {
                    labelWybierzKategorie.Visible = false;
                    pictureBox3.Visible           = false;
                }

                if (comboBoxSubcategory.SelectedIndex == -1)
                {
                    labelWybierzPodkategorie.Visible = true;
                    pictureBox4.Visible = true;
                    Check = true;
                }
                else
                {
                    labelWybierzPodkategorie.Visible = false;
                    pictureBox4.Visible = false;
                }

                if (textBoxPrice.Text == "")
                {
                    labelWpiszKwote.Visible = true;
                    pictureBox5.Visible     = true;
                    Check = true;
                }
                else
                {
                    labelWpiszKwote.Visible = false;
                    pictureBox5.Visible     = false;
                }

                int parsedValue;
                if (!int.TryParse(textBoxPrice.Text, out parsedValue))
                {
                    labelWpiszLiczby.Visible = true;
                    pictureBox5.Visible      = true;
                    Check = true;
                }
                else
                {
                    labelWpiszLiczby.Visible = false;
                    pictureBox5.Visible      = false;
                }

                return(Check);
            }
        }