Ejemplo n.º 1
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                Produs p = produse.ElementAt(dataGridView1.CurrentCell.RowIndex);

                if (p.State == "Expired")
                {
                    MessageBox.Show("This offer expired!");
                }
                else
                {
                    BidOnOffer dialog = new BidOnOffer(p.Current_price);
                    dialog.ShowDialog();
                    if (dialog.DialogResult == DialogResult.OK)
                    {
                        String packet = "bid$" + p.Name + "$" + dialog.tb_bid.Text + "$" + username + "$";
                        p = null;
                        SendPacket(packet);
                    }
                }
            }
            catch
            {
                dataGridView1.ClearSelection();
            }
        }
Ejemplo n.º 2
0
        private void DoWorkOnPacket(string[] packet)
        {
            switch (packet[0])
            {
            case "update_produs":



                produse.Clear();
                my_offers.Clear();

                String owner, name, state;
                int    starting_price, current_price, parser = 2;

                int x = Int32.Parse(packet[1]);

                for (int j = 1; j <= x; j++)
                {
                    name = packet[parser];
                    parser++;
                    owner = packet[parser];
                    parser++;
                    starting_price = Int32.Parse(packet[parser]);
                    parser++;
                    current_price = Int32.Parse(packet[parser]);
                    parser++;
                    state = packet[parser];
                    parser++;
                    Produs p = new Produs(name, owner, starting_price, current_price, state);



                    if (owner == username)
                    {
                        my_offers.Add(p);
                    }
                    else
                    {
                        produse.Add(p);
                    }
                }



                dataGridView1.Invoke(
                    new MethodInvoker(delegate()
                {
                    dataGridView1.ClearSelection();
                    dataGridView1.DataSource = null;
                    dataGridView1.DataSource = produse;
                    dataGridView1.ClearSelection();
                    foreach (DataGridViewRow r in  dataGridView1.Rows)
                    {
                        if (produse.ElementAt(r.Index).State == "Active")
                        {
                            r.DefaultCellStyle.ForeColor = Color.Green;
                        }
                        else
                        {
                            r.DefaultCellStyle.ForeColor = Color.Red;
                        }
                    }
                }));

                dataGridView2.Invoke(
                    new MethodInvoker(delegate()
                {
                    dataGridView2.ClearSelection();
                    dataGridView2.DataSource = null;
                    dataGridView2.DataSource = my_offers;
                    dataGridView2.ClearSelection();
                }));



                break;

            case "notification":
                MessageBox.Show(packet[1]);
                break;
            }
        }