Example #1
0
        private void Tb_ExemplarID_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                #region Buchcode parsen
                if (tb_ExemplarID.Text.Length == 8)
                {
                    string seven = tb_ExemplarID.Text.Substring(0, 7);
                    string eight = tb_ExemplarID.Text.Substring(7, 1);
                    if (ParseBuchcode(seven).ToString().Equals(eight))
                    {
                        tb_ExemplarID.Text = int.Parse(seven).ToString();
                    }
                }
                #endregion

                if (tb_ExemplarID.Text != "")
                {
                    try
                    {
                        Copy copy = new Copy(int.Parse(tb_ExemplarID.Text));
                        if (copy.CopyActivated)
                        {
                            lb_selected.Text            = "ausgewählte Bücher:";
                            returnHelper.Copy           = copy;
                            returnHelper.StartCondition = copy.Condition;
                            returnHelper.EndCondition   = copy.Condition;
                            if (selectedBuecher.Columns.Count < 2)
                            {
                                selectedBuecher.Columns.Add("ID");
                                selectedBuecher.Columns.Add("Vorheriger Zustand");
                                selectedBuecher.Columns.Add("Titel");
                            }
                            if (!copy.IsAvailable())
                            {
                                DataGridViewRow Buchrow = new DataGridViewRow();
                                if (GetIndexInLeihBuecher() != -1)
                                {
                                    Buchrow = gv_suggested.Rows[GetIndexInLeihBuecher()];
                                    if (!returnHelper.CheckRueckList())
                                    {
                                        SelectExemplar();
                                        Buchrow.DefaultCellStyle.BackColor = Color.LimeGreen;
                                        Buchrow.DefaultCellStyle.ForeColor = Color.Black;
                                    }
                                    else
                                    {
                                        UnSelectExemplar();
                                        Buchrow.DefaultCellStyle.BackColor = default;
                                        Buchrow.DefaultCellStyle.ForeColor = default;
                                    }
                                }
                                else
                                {
                                    DialogResult dialogResult = MetroMessageBox.Show(this, "Dieses Buch wurde nicht von diesem Kunden ausgeliehen!", "Achtung", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                            }
                            else
                            {
                                MetroMessageBox.Show(this, "Dieses Buch wurde nicht verliehen. Es kann nicht zur Buchrückgabeliste hinzugefügt werden.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            gv_selected.DataSource = selectedBuecher;
                            gv_selected.Refresh();
                            if (gv_selected.Columns.Contains("cbzustand"))
                            {
                                gv_selected.Columns.Remove("cbzustand");
                            }
                            DataGridViewComboBoxColumn combobox = new DataGridViewComboBoxColumn();
                            combobox = conditionHelper.FillDataGridViewComboBox();
                            gv_selected.Columns.Add(combobox);
                            gv_selected.Columns["cbzustand"].DisplayIndex = 2;
                            gv_selected.Columns["cbzustand"].HeaderText   = "aktueller Ist-Zustand";
                            for (int i = 0; i < gv_selected.RowCount; i++)
                            {
                                DataGridViewComboBoxCell comboValue = (DataGridViewComboBoxCell)(gv_selected.Rows[i].Cells["cbzustand"]);
                                //comboValue.Value = 0;
                                string    valueMember = gv_selected.Rows[i].Cells[1].Value.ToString();
                                Condition condition   = new Condition(conditionHelper.FindIdByName(valueMember));
                                valueMember = condition.ConditionId.ToString();
                                gv_selected.Rows[i].Cells[3].Value = int.Parse(valueMember);
                            }
                            gv_selected.ClearSelection();
                            tb_ExemplarID.Focus();
                            tb_ExemplarID.SelectAll();
                            combobox.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
                        }
                        else
                        {
                            tb_ExemplarID.Focus();
                            tb_ExemplarID.SelectAll();
                            MetroMessageBox.Show(this, "Dieser Buchcode existiert nicht.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    catch (Exception ex)
                    {
                        MetroMessageBox.Show(this, "Dieser Buchcode existiert nicht.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }