示例#1
0
        private void btnSuchen_Click(object sender, EventArgs e) // Button Suchen
        {
            if (tbKundenNr.Text != "")
            {
                rData.openReadConnection();
                MySqlDataReader reader = rData.getDataReader("kundendaten", "KundenNr", tbKundenNr.Text.Trim());
                if (reader.Read())
                {
                    recordNr = Convert.ToInt32(reader[0].ToString());

                    PerformDataFill(ref reader);
                }

                reader.Close();
                rData.closeReadConnection();
            }
            else if (tbKundenName.Text != "")
            {
                int found = rData.getCount("kundendaten", "KundenName", tbKundenName.Text.Trim());
                if (found == 1)
                {
                    rData.openReadConnection();
                    MySqlDataReader reader = rData.getDataReader("kundendaten", "KundenName", tbKundenName.Text.Trim());
                    if (reader.Read())
                    {
                        recordNr = Convert.ToInt32(reader[0].ToString());
                        PerformDataFill(ref reader);
                    }
                    reader.Close();
                    rData.closeReadConnection();
                }
                else if (found > 1)
                {
                    // Complete string match where more items have same name
                    listView1.Visible = true;
                    rData.openReadConnection();
                    MySqlDataReader reader = rData.getDataReader("kundendaten", "KundenName", tbKundenName.Text.Trim());
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            ListViewItem item = new ListViewItem(reader["KundenNr"].ToString());
                            item.SubItems.Add(reader["KundenName"].ToString());
                            item.SubItems.Add(reader["idKundendaten"].ToString());
                            listView1.Items.Add(item);
                        }
                    }
                    reader.Close();
                    rData.closeReadConnection();
                    MessageBox.Show("Mehere daten gefunden wählen sie aus der liste");
                }
                else
                {
                    // not full matching found match String segments
                    rData.openReadConnection();
                    MySqlDataReader reader = rData.searchDaten("kundendaten", "KundenName", "%" + tbKundenName.Text.Trim() + "%");
                    listView1.Visible = true;
                    if (reader.HasRows)
                    {
                        MessageBox.Show("Mehere daten gefunden wählen sie aus der liste");
                        while (reader.Read())
                        {
                            ListViewItem item = new ListViewItem(reader["KundenNr"].ToString());

                            item.SubItems.Add(reader["KundenName"].ToString());
                            item.SubItems.Add(reader["idKundendaten"].ToString());
                            listView1.Items.Add(item);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Daten nicht gefunden");
                    }
                    reader.Close();
                    rData.closeReadConnection();
                }
            }
            else
            {
                MessageBox.Show("Für Suchen Bitte geben sie Kunden Nummer oder Kunden Name ein");
            }
        }
示例#2
0
        private void SearchRecord()
        {
            // Code from KundenDaten
            NeuKunde = DialogResult.No;
            if (tbTelefon.Text != "" && tbTelefon.Focused) //if telefon is not empty and telefone is focused
            {
                int found = rData.getCount("kundendaten", "KundenNr", tbTelefon.Text.Trim());

                if (found == 1) // One Record Found
                {
                    rData.openReadConnection();
                    MySqlDataReader readerKunde = rData.getDataReader("kundendaten", "KundenNr", tbTelefon.Text.Trim());
                    if (readerKunde.Read())
                    {
                        PerformDataFill(readerKunde);
                        tbKNr.Enabled = false;
                    }
                    readerKunde.Close();
                    rData.closeReadConnection();
                }
                else if (found > 1) // More than One records found
                {
                    // Complete string match where more items have same name
                    rData.openReadConnection();
                    MySqlDataReader readerKunde = rData.getDataReader("kundendaten", "KundenNr", tbTelefon.Text.Trim());
                    if (readerKunde.HasRows)
                    {
                        while (readerKunde.Read())
                        {
                            ListViewItem item = new ListViewItem(readerKunde["KundenNr"].ToString());
                            item.SubItems.Add(readerKunde["KundenName"].ToString());
                            item.SubItems.Add(readerKunde["idKundendaten"].ToString());
                            item.SubItems.Add(readerKunde["Strasse"].ToString() + "." + readerKunde["strno"].ToString());
                            lwKundenDaten.Items.Add(item);
                        }
                        lwKundenDaten.Visible = true;
                        lwKundenDaten.Enabled = true;
                    }
                    readerKunde.Close();
                    rData.closeReadConnection();
                }
                else
                {
                    // not full matching found match String segments
                    rData.openReadConnection();
                    MySqlDataReader readerKunde = rData.searchDaten("kundendaten", "KundenNr", tbTelefon.Text.Trim() + " % ");

                    if (readerKunde.HasRows)
                    {
                        while (readerKunde.Read())
                        {
                            ListViewItem item = new ListViewItem(readerKunde["KundenNr"].ToString());
                            item.SubItems.Add(readerKunde["KundenName"].ToString());
                            item.SubItems.Add(readerKunde["idKundendaten"].ToString());
                            item.SubItems.Add(readerKunde["Strasse"].ToString() + "." + readerKunde["strno"].ToString());
                            lwKundenDaten.Items.Add(item);
                        }

                        lwKundenDaten.Visible = true;
                        lwKundenDaten.Enabled = true;
                    }
                    else
                    {
                        NeuKunde = MessageBox.Show("Daten Nicht gefunden. Soll Neu Kunde eingefügt werden", "?", MessageBoxButtons.YesNo);
                        if (NeuKunde == DialogResult.Yes)
                        {
                            tbName.Focus();
                            tbKNr.Enabled     = false;
                            btnWeiter.Enabled = true;
                        }
                        lwKundenDaten.Visible = false;
                    }
                    readerKunde.Close();
                    rData.closeReadConnection();
                }
            }
            else if (tbKNr.Text != "" && tbKNr.Focused) // Kunden Nummer Search
            {
                rData.openReadConnection();
                MySqlDataReader readerKunde = rData.getDataReader("kundendaten", "idkundendaten", tbKNr.Text);
                if (readerKunde.Read())
                {
                    PerformDataFill(readerKunde);
                }
                readerKunde.Close();
                rData.closeReadConnection();
            }
            else if (tbName.Text != "" && tbName.Focused) // Name Search
            {
                int found = rData.getCount("kundendaten", "KundenName", tbName.Text.Trim());

                if (found == 1) // One Name Found
                {
                    rData.openReadConnection();
                    MySqlDataReader readerKunde = rData.getDataReader("kundendaten", "KundenName", tbName.Text.Trim());

                    if (readerKunde.Read())
                    {
                        PerformDataFill(readerKunde);
                        tbKNr.Enabled = false;
                    }
                    readerKunde.Close();
                    rData.closeReadConnection();
                }
                else if (found > 1)
                {
                    // Complete string match where more items have same name
                    rData.openReadConnection();
                    MySqlDataReader readerKunde = rData.getDataReader("kundendaten", "KundenName", tbName.Text.Trim());

                    if (readerKunde.HasRows)
                    {
                        while (readerKunde.Read())
                        {
                            ListViewItem item = new ListViewItem(readerKunde["KundenNr"].ToString());
                            item.SubItems.Add(readerKunde["KundenName"].ToString());
                            item.SubItems.Add(readerKunde["idKundendaten"].ToString());
                            item.SubItems.Add(readerKunde["Strasse"].ToString() + "." + readerKunde["strno"].ToString());
                            lwKundenDaten.Items.Add(item);
                        }
                        lwKundenDaten.Visible = true;
                        lwKundenDaten.Enabled = true;
                        //listView1.Visible = false;
                    }
                    readerKunde.Close();
                    rData.closeReadConnection();
                }
                else
                {
                    // not full matching found match String segments
                    rData.openReadConnection();
                    MySqlDataReader readerKunde = rData.searchDaten("kundendaten", "KundenName", tbName.Text.Trim() + "%");
                    if (readerKunde.HasRows)
                    {
                        while (readerKunde.Read())
                        {
                            ListViewItem item = new ListViewItem(readerKunde["KundenNr"].ToString());
                            item.SubItems.Add(readerKunde["KundenName"].ToString());
                            item.SubItems.Add(readerKunde["idKundendaten"].ToString());
                            item.SubItems.Add(readerKunde["Strasse"].ToString() + "." + readerKunde["strno"].ToString());
                            lwKundenDaten.Items.Add(item);
                        }

                        lwKundenDaten.Visible = true;
                        lwKundenDaten.Enabled = true;
                    }
                    else
                    {
                        NeuKunde = MessageBox.Show("Daten Nicht gefunden. Soll Neu Kunde eingefügt werden", "?", MessageBoxButtons.YesNo);
                        if (NeuKunde == DialogResult.Yes)
                        {
                            tbTelefon.Focus();
                            tbKNr.Enabled     = false;
                            btnWeiter.Enabled = true;
                        }
                        lwKundenDaten.Visible = false;
                        //listView1.Visible = true;
                    }
                    readerKunde.Close();
                    rData.closeReadConnection();
                }
            }
            else if (tbName.Focused)
            {
                MessageBox.Show("Für Suchen Bitte geben sie Name ein");
            }
            else if (tbTelefon.Focused)
            {
                MessageBox.Show("Für Suchen Bitte geben sie Anfangsziffern ein");
            }
        }