Exemple #1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                string CardName = txtSearch.Text.ToLower();
                Game   mygame   = proxy.Games[gameindex];

                // Search for Card
                Guid     card = Guid.Empty;
                string[] cond = new string[1];
                cond[0] = "name = '" + CardName.Trim().Replace("'", "''") + "'";       // Equals
                string[] cond2 = new string[1];
                cond2[0] = "name like '%" + CardName.Trim().Replace("'", "''") + "%'"; // Contains
                List <CardModel> SetsWhereCardAppear = new List <CardModel>();
                SetsWhereCardAppear.AddRange(mygame.SelectCardModels(cond));
                if (SetsWhereCardAppear.Count < 1)
                {
                    // If incorrectly typed name try a "name contains" statement
                    SetsWhereCardAppear.AddRange(mygame.SelectCardModels(cond2));
                    if (SetsWhereCardAppear.Count > 0)
                    {
                        CardSelection cardForm = new CardSelection();
                        cardForm.CardList = new string[SetsWhereCardAppear.Count];
                        for (int i = 0; i < SetsWhereCardAppear.Count; i++)
                        {
                            cardForm.CardList[i] = SetsWhereCardAppear[i].Name;
                        }
                        cardForm.ShowDialog();
                        string[] fixedSearch = new string[1];
                        fixedSearch[0] = "name = '" + cardForm.CardName.Trim().Replace("'", "''") + "'"; // Equals
                        SetsWhereCardAppear.Clear();
                        SetsWhereCardAppear.AddRange(mygame.SelectCardModels(fixedSearch));
                        txtSearch.Text = cardForm.CardName;
                    }
                    else
                    {
                        MessageBox.Show("Could not find any matching cards for search term: " + txtSearch.Text);
                        txtSearch.Focus();
                        txtSearch.SelectAll();
                    }
                }
                // If multiple cards returned.
                if (SetsWhereCardAppear.Count > 1)
                {
                    Chooser chooser = new Chooser();
                    chooser.SetList   = new List <CardModel>();
                    chooser.SetList   = SetsWhereCardAppear;
                    chooser.CardName  = CardName;
                    chooser.GameIndex = gameindex;
                    chooser.ShowDialog();
                    card = chooser.selectedCard;
                }
                else
                {
                    if (SetsWhereCardAppear.Count == 1)
                    {
                        card = SetsWhereCardAppear[0].Id;
                    }
                }
                if (SetsWhereCardAppear.Count != 0)
                {
                    // Retrieve Card Image
                    BitmapImage img = new BitmapImage();
                    System.Windows.Controls.Image CardImage = new System.Windows.Controls.Image();
                    Uri picture = CardModel.GetPictureUri(mygame, mygame.GetCardById(card).Set.Id,
                                                          mygame.GetCardById(card).ImageUri) ?? mygame.GetCardBackUri();
                    pictureBox1.Image = SourceConvert.BitmapFromUri(picture);
                    Uri alternate = new Uri(picture.ToString().Replace(".jpg", ".b.jpg"));
                    try
                    {
                        pictureBox2.Image = SourceConvert.BitmapFromUri(alternate);
                    }
                    catch
                    {
                        pictureBox2.Image = SourceConvert.BitmapFromUri(mygame.GetCardBackUri());
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
            txtSearch.Focus();
            txtSearch.SelectAll();
            pictureBox1.Visible = true;
            pictureBox2.Visible = false;
        }
Exemple #2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                string CardName = txtSearch.Text.ToLower();
                Game mygame = proxy.Games[gameindex];

                // Search for Card
                Guid card = Guid.Empty;
                string[] cond = new string[1];
                cond[0] = "name = '" + CardName.Trim().Replace("'", "''") + "'"; // Equals
                string[] cond2 = new string[1];
                cond2[0] = "name like '%" + CardName.Trim().Replace("'", "''") + "%'"; // Contains
                List<CardModel> SetsWhereCardAppear = new List<CardModel>();
                SetsWhereCardAppear.AddRange(mygame.SelectCardModels(cond));
                if (SetsWhereCardAppear.Count < 1)
                {
                    // If incorrectly typed name try a "name contains" statement
                    SetsWhereCardAppear.AddRange(mygame.SelectCardModels(cond2));
                    if (SetsWhereCardAppear.Count > 0)
                    {
                        CardSelection cardForm = new CardSelection();
                        cardForm.CardList = new string[SetsWhereCardAppear.Count];
                        for (int i = 0; i < SetsWhereCardAppear.Count; i++)
                        {
                            cardForm.CardList[i] = SetsWhereCardAppear[i].Name;
                        }
                        cardForm.ShowDialog();
                        string[] fixedSearch = new string[1];
                        fixedSearch[0] = "name = '" + cardForm.CardName.Trim().Replace("'", "''") + "'"; // Equals
                        SetsWhereCardAppear.Clear();
                        SetsWhereCardAppear.AddRange(mygame.SelectCardModels(fixedSearch));
                        txtSearch.Text = cardForm.CardName;
                    }
                    else
                    {
                        MessageBox.Show("Could not find any matching cards for search term: " + txtSearch.Text);
                        txtSearch.Focus();
                        txtSearch.SelectAll();
                    }
                }
                // If multiple cards returned.
                if (SetsWhereCardAppear.Count > 1)
                {
                    Chooser chooser = new Chooser();
                    chooser.SetList = new List<CardModel>();
                    chooser.SetList = SetsWhereCardAppear;
                    chooser.CardName = CardName;
                    chooser.GameIndex = gameindex;
                    chooser.ShowDialog();
                    card = chooser.selectedCard;
                }
                else
                {
                    if (SetsWhereCardAppear.Count == 1) { card = SetsWhereCardAppear[0].Id; }
                }
                if (SetsWhereCardAppear.Count != 0)
                {
                    // Retrieve Card Image
                    BitmapImage img = new BitmapImage();
                    System.Windows.Controls.Image CardImage = new System.Windows.Controls.Image();
                    Uri picture = CardModel.GetPictureUri(mygame, mygame.GetCardById(card).Set.Id,
                        mygame.GetCardById(card).ImageUri) ?? mygame.GetCardBackUri();
                    pictureBox1.Image = SourceConvert.BitmapFromUri(picture);
                    Uri alternate = new Uri(picture.ToString().Replace(".jpg", ".b.jpg"));
                    try
                    {
                        pictureBox2.Image = SourceConvert.BitmapFromUri(alternate);
                    }
                    catch
                    {
                        pictureBox2.Image = SourceConvert.BitmapFromUri(mygame.GetCardBackUri());
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
            txtSearch.Focus();
            txtSearch.SelectAll();
            pictureBox1.Visible = true;
            pictureBox2.Visible = false;
        }