示例#1
0
        private void search_Click_1(object sender, EventArgs e)
        {
            try
            {
                Error.Text = "";
                if (searchID.Text.Length == 0 && searchName.Text.Length == 0)
                {
                    searchError.Text = CommonFunctions.ReturnString("empty");
                }
                else
                {
                    if (searchID.Text.Length != 0 && searchName.Text.Length == 0)
                    {
                        var    id = int.Parse(searchID.Text.Trim());
                        byte[] img;
                        if (_musicBook.GetById(id, "MusicBook").Rows[0][8].ToString() != "NULL")
                        {
                            img = (byte[])(_musicBook.GetById(id, "MusicBook").Rows[0][8]);
                            if (img == null)
                            {
                                productPicture.Image = null;
                            }
                            else
                            {
                                var ms = new MemoryStream(img);
                                productPicture.Image = Image.FromStream(ms);
                            }
                        }
                        CommonFunctions.GetMusicBookById(dataGridView1, id, tID, tName, tPrice, tPiece, tDate, tAuthor, tProducer);
                    }

                    else if (searchID.Text.Length == 0 && searchName.Text.Length != 0)
                    {
                        var name = searchName.Text.Trim();
                        CommonFunctions.GetMusicBookByName(dataGridView1, name, tID, tName, tPrice, tPiece, tDate, tAuthor, tProducer);
                    }

                    else
                    {
                        searchError.Text = CommonFunctions.ReturnString("one");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (cb.SelectedIndex == 0)
     {
         if (searchID.Text.Trim() == "" && searchName.Text.Trim() == "")
         {
             searchError.Text = "Parameters can not be empty.";
         }
         else
         {
             if (searchID.Text.Trim() != "" && searchName.Text.Trim() == "")
             {
                 dataGridView1.DataSource = comp.GetById(int.Parse(searchID.Text.Trim()), "Computers");
             }
             else if (searchID.Text.Trim() == "" && searchName.Text.Trim() != "")
             {
                 dataGridView1.DataSource = comp.GetByName(searchName.Text.Trim(), "Computers");
             }
             else
             {
                 searchError.Text = "You can only search with only one parameter";
             }
         }
     }
     else if (cb.SelectedIndex == 1)
     {
         if (searchID.Text.Trim() == "" && searchName.Text.Trim() == "")
         {
             searchError.Text = "Parameters can not be empty.";
         }
         else
         {
             if (searchID.Text.Trim() != "" && searchName.Text.Trim() == "")
             {
                 dataGridView1.DataSource = SmartPhones.GetById(int.Parse(searchID.Text.Trim()), "SmartPhones");
             }
             else if (searchID.Text.Trim() == "" && searchName.Text.Trim() != "")
             {
                 dataGridView1.DataSource = SmartPhones.GetByName(searchName.Text.Trim(), "SmartPhones");
             }
             else
             {
                 searchError.Text = "You can only search with only one parameter";
             }
         }
     }
     else if (cb.SelectedIndex == 2)
     {
         if (searchID.Text.Trim() == "" && searchName.Text.Trim() == "")
         {
             searchError.Text = "Parameters can not be empty.";
         }
         else
         {
             if (searchID.Text.Trim() != "" && searchName.Text.Trim() == "")
             {
                 dataGridView1.DataSource = MusicBook.GetById(int.Parse(searchID.Text.Trim()), "MusicBook");
             }
             else if (searchID.Text.Trim() == "" && searchName.Text.Trim() != "")
             {
                 dataGridView1.DataSource = MusicBook.GetByName(searchName.Text.Trim(), "MusicBook");
             }
             else
             {
                 searchError.Text = "You can only search with only one parameter";
             }
         }
     }
     else
     {
         searchError.Text = "Please select a category.";
     }
 }