protected override void save_Click(object sender, EventArgs e) { if (valid) { if (combobox.Name == ComboboxesImproved.names.room.ToString()) { var room = queries.addRoom(nameT.Text); combobox.Items.Add(room); combobox.SelectedItem = room; } else if (combobox.Name == ComboboxesImproved.names.wardrobe.ToString()) { var room = ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.room).SelectedItem as Room; var wardrobe = queries.addWardrobe(nameT.Text, room.id_room); combobox.Items.Add(wardrobe); combobox.SelectedItem = wardrobe; } else if (combobox.Name == ComboboxesImproved.names.status.ToString()) { var status = queries.addStatus(nameT.Text); combobox.Items.Add(status); combobox.SelectedItem = status; } Close(); } else { MessageBox.Show(Utils.GetEnumDescription(Messages.errors.SAVE), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void fillForm() { var textbox = TextboxesNames.getTextBoxByName(TextboxesNames.names.name); textbox.Text = (item != null) ? item.name : null; setTextboxesErrors(textbox); textbox = TextboxesNames.getTextBoxByName(TextboxesNames.names.description); textbox.Text = (item != null) ? item.description : null; var combo = ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.category); combo.SelectedItem = (item != null) ? queries.getCategoryById(item.id_category) : null; setComboboxesErrors(combo); combo = ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.room); combo.SelectedItem = (item != null) ? queries.getRoomByShelfId(item.id_shelf) : null; setComboboxesErrors(combo); combo = ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.wardrobe); combo.SelectedItem = (item != null) ? queries.getWardrobeByShelfId(item.id_shelf) : null; setComboboxesErrors(combo); combo = ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.shelf); combo.SelectedItem = (item != null) ? queries.getShelfById(item.id_shelf) : null; setComboboxesErrors(combo); combo = ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.status); combo.SelectedItem = (item != null) ? queries.getStatusById(item.id_status) : null; setComboboxesErrors(combo); var trackbar = TrackbarImproved.getTrackbar(); trackbar.Value = (item != null) ? item.size : 0; setTrackbarErrors(trackbar); if (item != null && item.image != null) { pictureBox1.Image = Classes.ImageConverter.dbImgaeToImage(item.image); oryginalImage = (Bitmap)pictureBox1.Image; var button = ButtonsImproved.getList().Find(x => x.Name == ButtonsImproved.names.image_delete.ToString()); button.Enabled = true; } else { var button = ButtonsImproved.getList().Find(x => x.Name == ButtonsImproved.names.image_delete.ToString()); button.Enabled = false; pictureBox1.Image = null; oryginalImage = null; } fillHistoryGrid(historyDataGridView); //this.checkBox1.Checked = item.deleted ? false : true; }
private void InitializeComboboxes() { var k = 0; var comboboxes = new ComboboxesImproved(); foreach (var item in comboboxes.getComboboxImprovedList()) { item.Location = new System.Drawing.Point(250, 225 + 60 * k); Controls.Add(item); k++; item.SelectedIndexChanged += comboBoxSelectionChangeCommitted; setComboboxesErrors(item); } }
private void setTrackbarErrors(TrackBar something) { switch (something.Name) { case "size": if (something.Value < 1) { errorProviders[6].Icon = Properties.Resources.ERR; errorProviders[6].SetError(TrackbarImproved.getTrackbar(), "Nie wybrałeś warości"); errors[6] = false; } else { errorProviders[6].Icon = Properties.Resources.OK; errorProviders[6].SetError(TrackbarImproved.getTrackbar(), "OK"); errors[6] = true; } break; } try { int itemSize = 0; try { itemSize = queries.getItemById(item.id_item).size; } catch { } var shelfCurrentSize = queries.getShelfOccupancyByShelfId((ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.shelf).SelectedItem as Shelf).id_shelf); var capacity = (ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.shelf).SelectedItem as Shelf).capacity; int size = 0; try { size = TrackbarImproved.getTrackbar().Value; } catch { } if ((shelfCurrentSize + size - itemSize) > capacity) { errorProviders[3].Icon = Properties.Resources.ERR; errorProviders[3].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.shelf), "Rozmiar rzeczy jest za duży"); errors[3] = false; } else { errorProviders[3].Icon = Properties.Resources.OK; errors[3] = true; } } catch { } }
protected override void save_Click(object sender, EventArgs e) { if (valid[0] && valid[1]) { var wardrobe = ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.wardrobe).SelectedItem as Wardrobe; var shelf = queries.addShelf(Int32.Parse(locationT.Text), Int32.Parse(capacityT.Text), wardrobe.id_wardrobe); combobox.Items.Add(shelf); combobox.SelectedItem = shelf; Close(); } else { MessageBox.Show(Utils.GetEnumDescription(Messages.errors.SAVE), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void save_Click(object sender, EventArgs e) { AddItem addItem; if (item != null) { addItem = new AddItem(item); } else { addItem = new AddItem(); } if (checkIfSave()) { addItem.setActive(false); addItem.setName(TextboxesNames.getTextBoxByName(TextboxesNames.names.name).Text); addItem.setStatus(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.status).SelectedItem as Status); addItem.setShelf(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.shelf).SelectedItem as Shelf); addItem.setCategory(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.category).SelectedItem as Category); addItem.setSize(TrackbarImproved.getTrackbar().Value); addItem.setImage(oryginalImage); var desc = TextboxesNames.getTextBoxByName(TextboxesNames.names.description).Text; if (desc != null) { addItem.setDescription(desc); } item = addItem.save(); fillForm(); } else { MessageBox.Show(Utils.GetEnumDescription(Messages.errors.SAVE), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void setComboboxesErrors(ComboBox something) { switch (something.Name) { case "room": if (something.SelectedItem == null || something.SelectedItem.ToString() == Utils.GetEnumDescription(ComboboxNew.actions.add)) { errorProviders[1].Icon = Properties.Resources.ERR; errorProviders[1].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.room), "Nie wybrałeś pokoju"); errors[1] = false; } else { errorProviders[1].Icon = Properties.Resources.OK; errorProviders[1].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.room), "OK"); errors[1] = true; } break; case "wardrobe": if (something.SelectedItem == null || something.SelectedItem.ToString() == Utils.GetEnumDescription(ComboboxNew.actions.add)) { errorProviders[2].Icon = Properties.Resources.ERR; errorProviders[2].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.wardrobe), "Nie wybrałeś szafy"); errors[2] = false; } else { errorProviders[2].Icon = Properties.Resources.OK; errorProviders[2].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.wardrobe), "OK"); errors[2] = true; } break; case "shelf": if (something.SelectedItem == null || something.SelectedItem.ToString() == Utils.GetEnumDescription(ComboboxNew.actions.add)) { errorProviders[3].Icon = Properties.Resources.ERR; errorProviders[3].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.shelf), "Nie wybrałeś półki"); errors[3] = false; } else { int itemSize = 0; try { itemSize = queries.getItemById(item.id_item).size; } catch { } var shelfCurrentSize = queries.getShelfOccupancyByShelfId((ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.shelf).SelectedItem as Shelf).id_shelf); var capacity = (ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.shelf).SelectedItem as Shelf).capacity; int size = 0; try { size = TrackbarImproved.getTrackbar().Value; } catch { } if ((shelfCurrentSize + size - itemSize) > capacity) { errorProviders[3].Icon = Properties.Resources.ERR; errorProviders[3].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.shelf), "Rozmiar rzeczy jest za duży"); errors[3] = false; } else { errorProviders[3].Icon = Properties.Resources.OK; errorProviders[3].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.shelf), "OK"); errors[3] = true; } } break; case "status": if (something.SelectedItem == null || something.SelectedItem.ToString() == Utils.GetEnumDescription(ComboboxNew.actions.add)) { errorProviders[4].Icon = Properties.Resources.ERR; errorProviders[4].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.status), "Nie wybrałeś statusu"); errors[4] = false; } else { errorProviders[4].Icon = Properties.Resources.OK; errorProviders[4].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.status), "OK"); errors[4] = true; } break; case "category": if (something.SelectedItem == null || something.SelectedItem.ToString() == Utils.GetEnumDescription(ComboboxNew.actions.add)) { errorProviders[5].Icon = Properties.Resources.ERR; errorProviders[5].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.category), "Nie wybrałeś kategorii"); errors[5] = false; } else { errorProviders[5].Icon = Properties.Resources.OK; errorProviders[5].SetError(ComboboxesImproved.getComboboxByName(ComboboxesImproved.names.category), "OK"); errors[5] = true; } break; } }