示例#1
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                searchError.Text = string.Empty;
                lberror.Text     = string.Empty;
                if (searchID.Text.Length == 0 && searchName.Text.Trim().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 (_comp.GetById(id, "Computers").Rows[0][12].ToString() != "NULL")
                        {
                            img = (byte[])(_comp.GetById(id, "Computers").Rows[0][12]);
                            if (img == null)
                            {
                                productPicture.Image = null;
                            }
                            else
                            {
                                var ms = new MemoryStream(img);
                                productPicture.Image = Image.FromStream(ms);
                            }
                        }


                        CommonFunctions.GetComputerById(id, "Computers", dataGridView1, tID, tName, tPrice, tPiece, tDate, tBrand, tGPU, tCPU, tRAM, tSS, tOS);
                    }
                    else if (searchID.Text.Length == 0 && searchName.Text.Length != 0)
                    {
                        var productName = searchName.Text.Trim();
                        CommonFunctions.GetComputerByName(productName, "Computers", dataGridView1, tID, tName, tPrice, tPiece, tDate, tBrand, tGPU, tCPU, tRAM, tSS, tOS);
                    }
                    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.";
     }
 }