Ejemplo n.º 1
0
        public void AddOrUpdateHistoricItem(Historic h, ListViewItem lvi = null)
        {
            if (lstHistoricsQueries.InvokeRequired)
            {
                AddOrUpdateHistoricItemCallback cb = new AddOrUpdateHistoricItemCallback(AddOrUpdateHistoricItem);
                this.Invoke(cb, new object[] { h, lvi });
            }
            else
            {
                lstHistoricsQueries.BeginUpdate();

                try
                {
                    if (lvi == null)
                    {
                        // No ListViewItem given, try to find a matching row
                        foreach (ListViewItem lvi_candidate in lstHistoricsQueries.Items)
                        {
                            if (h.getHash() == ((Historic)lvi_candidate.Tag).getHash())
                            {
                                lvi = lvi_candidate;
                                break;
                            }
                        }
                    }

                    if (h.isDeleted())
                    {
                        if (lvi != null)
                        {
                            lstHistoricsQueries.Items.Remove(lvi);
                        }
                    }
                    else
                    {
                        if (lvi == null)
                        {
                            // Still not found it, add it
                            lvi = lstHistoricsQueries.Items.Add(h.getName());
                            lvi.SubItems.Add(h.getStatus());
                            lvi.SubItems.Add(h.getProgress().ToString());
                            lvi.SubItems.Add(h.getStartDate().ToString());
                            lvi.SubItems.Add(h.getEndDate().ToString());
                            lvi.SubItems.Add(string.Join(", ", h.getSources().ToArray()));
                        }
                        else
                        {
                            // Already exists, update the pieces
                            lvi.SubItems[0].Text = h.getName();
                            lvi.SubItems[1].Text = h.getStatus();
                            lvi.SubItems[2].Text = h.getProgress().ToString();
                            lvi.SubItems[3].Text = h.getStartDate().ToString();
                            lvi.SubItems[4].Text = h.getEndDate().ToString();
                            lvi.SubItems[5].Text = string.Join(", ", h.getSources().ToArray());
                        }

                        // Store the Historic in the item
                        lvi.Tag = h;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                lstHistoricsQueries.EndUpdate();
            }
        }
        public void AddOrUpdateHistoricItem(Historic h, ListViewItem lvi = null)
        {
            if (lstHistoricsQueries.InvokeRequired)
            {
                AddOrUpdateHistoricItemCallback cb = new AddOrUpdateHistoricItemCallback(AddOrUpdateHistoricItem);
                this.Invoke(cb, new object[] { h, lvi });
            }
            else
            {
                lstHistoricsQueries.BeginUpdate();

                try
                {
                    if (lvi == null)
                    {
                        // No ListViewItem given, try to find a matching row
                        foreach (ListViewItem lvi_candidate in lstHistoricsQueries.Items)
                        {
                            if (h.getHash() == ((Historic)lvi_candidate.Tag).getHash())
                            {
                                lvi = lvi_candidate;
                                break;
                            }
                        }
                    }

                    if (h.isDeleted())
                    {
                        if (lvi != null)
                        {
                            lstHistoricsQueries.Items.Remove(lvi);
                        }
                    }
                    else
                    {
                        if (lvi == null)
                        {
                            // Still not found it, add it
                            lvi = lstHistoricsQueries.Items.Add(h.getName());
                            lvi.SubItems.Add(h.getStatus());
                            lvi.SubItems.Add(h.getProgress().ToString());
                            lvi.SubItems.Add(h.getStartDate().ToString());
                            lvi.SubItems.Add(h.getEndDate().ToString());
                            lvi.SubItems.Add(string.Join(", ", h.getSources().ToArray()));
                        }
                        else
                        {
                            // Already exists, update the pieces
                            lvi.SubItems[0].Text = h.getName();
                            lvi.SubItems[1].Text = h.getStatus();
                            lvi.SubItems[2].Text = h.getProgress().ToString();
                            lvi.SubItems[3].Text = h.getStartDate().ToString();
                            lvi.SubItems[4].Text = h.getEndDate().ToString();
                            lvi.SubItems[5].Text = string.Join(", ", h.getSources().ToArray());
                        }

                        // Store the Historic in the item
                        lvi.Tag = h;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                lstHistoricsQueries.EndUpdate();
            }
        }