Esempio n. 1
0
        // change data in selected item
        private void editAttendee(ListViewItem lvi)
        {
            using (DataEntryForm data = new DataEntryForm())
            {
                DataRow[] updateRow = AttendeeDT.Select("GUEST_ID = " + lvi.SubItems[2].Text.ToString());
                if (updateRow.Length > 0)
                {
                    data.FirstName = updateRow[0]["FIRST_NAME"].ToString();
                    data.LastName = updateRow[0]["LAST_NAME"].ToString();
                    data.RSVP = updateRow[0]["RSVP"].ToString();
                    data.FoodAllergy = updateRow[0]["FOOD_ALLERGY"].ToString();
                    data.Comments = updateRow[0]["COMMENTS"].ToString();
                }
   

                if (data.ShowDialog(this) == DialogResult.OK)
                {
                    if (updateRow.Length > 0)
                    {
                        updateRow[0]["FIRST_NAME"] = data.FirstName;
                        updateRow[0]["LAST_NAME"] = data.LastName;
                        updateRow[0]["RSVP"] = data.RSVP;
                        updateRow[0]["FOOD_ALLERGY"] = data.FoodAllergy;
                        updateRow[0]["COMMENTS"] = data.Comments;
                        //AttendeeDT.AcceptChanges();
                        if (updateRow[0]["RSVP"].ToString() != "Accept")
                        {
                            updateRow[0]["TABLE_ID"] = DBNull.Value;
                            updateRow[0]["SEAT_NUM"] = DBNull.Value;
                        }

                        lvi.Text = data.LastName + ", " + data.FirstName;
                        lvi.SubItems[1].Text = data.RSVP;
                        lvi.SubItems[2].Text = data.FoodAllergy;
                        lvi.SubItems[3].Text = data.Comments;

                        //LoadListView();
                    }
                }
            }
        }
Esempio n. 2
0
        // add item
        private void addAttendee()
        {
            bool equal = false;
            //Create edit entry window for data population
            //  Pull data form form rather than passing through
            using (DataEntryForm data = new DataEntryForm())
            {
                if (data.ShowDialog(this) == DialogResult.OK)
                {

                    string name = data.LastName + ", " + data.FirstName;
                    string rsvp = data.RSVP;
                    string allergy = data.FoodAllergy;
                    string comment = data.Comments;


                    foreach (ListViewItem lvi in lvwAttendee.Items)
                    {
                        //if names are equal, do not add and break from search
                        if (name.Equals(lvi.SubItems[0].Text))
                        {
                            equal = true;
                            break;
                        }
                    }

                    if (!equal)
                    {
                        //add new row to DataTable
                        DataRow newRow = AttendeeDT.NewRow();
                        newRow["FIRST_NAME"] = data.FirstName;
                        newRow["LAST_NAME"] = data.LastName;
                        if (data.RSVP.ToString() == "")
                            newRow["RSVP"] = "Unknown";
                        else
                            newRow["RSVP"] = data.RSVP;
                        if (AttendeeDT.Rows.Count == 0)
                            newRow["GUEST_ID"] = 1;
                        else
                            newRow["GUEST_ID"] = Convert.ToInt32(AttendeeDT.Compute("max(GUEST_ID)", string.Empty)) + 1;
                        newRow["WED_ID"] = wedID;
                        newRow["FOOD_ALLERGY"] = allergy;
                        if (comment == "")
                        {
                            newRow["COMMENTS"] = DBNull.Value;
                        }
                        else
                        {
                            newRow["COMMENTS"] = comment;
                        }
                        AttendeeDT.Rows.Add(newRow);

                        updateGuestCount();
                    }
                    else
                    {
                        MessageBox.Show(name + " already is listed as a guest", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    //ListViewItem [0] = NAME
                    //ListViewItem [1] = RSVP
                    //ListViewItem [2] = GUEST_ID
                    //ListViewItem [3] = FOOD_ALLERGY
                    //ListViewItem [4] = COMMENTS
                    //ListViewItem newGuest = new ListViewItem(new string[] { name, rsvp, newRow["GUEST_ID"].ToString(), newRow["FOOD_ALLERGY"].ToString(), newRow["COMMENTS"].ToString() });
                    //newGuest.ImageIndex = 0;
                    //newGuest.Group = lvwAttendee.Groups[0];
                    //lvwAttendee.Items.Add(newGuest);
                }
            }

            CheckGuestCount();
        }