コード例 #1
0
        protected override void OnDelete(Entity item, out string message, ref Action <Entity> afterConfirm)
        {
            if (afterConfirm == null)
            {
                throw new ArgumentNullException(nameof(afterConfirm));
            }

            message = ((Person)item).Name.Fullname;

            afterConfirm = currentItem =>
            {
                try
                {
                    var deletedItem = (Person)currentItem;


                    deletedItem.RowStatus = RecordStatus.DeletedRecord;

                    var dataWriter = new PersonDataWriter(App.CurrentUser.User.Username, deletedItem);
                    dataWriter.SaveChanges();

                    ItemDataCollection.Remove((Person)currentItem);

                    App.LogAction("Contacts", "Deleted Contact: " + ((Person)currentItem).Name.Fullname);
                }
                catch (Exception ex)
                {
                    MessageDialog.ShowError(ex, this);
                }
            };
        }
コード例 #2
0
        public bool FileSave()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (!DataIsValid())
                {
                    return(false);
                }

                ItemData.Name.Lastname      = txtLastname.Text.Trim();
                ItemData.Name.Firstname     = txtFirstname.Text.Trim();
                ItemData.Name.Middlename    = txtMiddlename.Text.Trim();
                ItemData.Name.MiddleInitial = txtMi.Text.Trim();
                ItemData.Name.NameExtension = cboNameExtension.Text;


                ItemData.Name.MaidenMiddlename = txtMaidenMiddlename.Enabled ? txtMaidenMiddlename.Text : "";

                ItemData.Gender    = cboGender.Text.ToLower() == "male" ? GenderType.Male : GenderType.Female;
                ItemData.BirthDate = dtBirthdate.Value;

                ItemData.BirthProvince = cboProvince.Text;
                ItemData.BirthTown     = cboTown.Text;
                ItemData.BirthCountry  = cboCountry.Text;

                ItemData.CameraCounter = txtImageFile.Text;


                //Write Mobile Numbers;
                if (lstContacts.Items.Any())
                {
                    foreach (ListBoxItem listItem in lstContacts.Items)
                    {
                        var m = (MobileNumber)listItem.Tag;

                        if (!listItem.Visible)
                        {
                            m.RowStatus = RecordStatus.DeletedRecord;
                        }
                        else
                        {
                            if (m.Id == 0)
                            {
                                ItemData.MobileNumbers.Add(m);
                            }
                        }
                    }
                }


                var dataWriter = new PersonDataWriter(App.CurrentUser.User.Username, ItemData);

                var ret = dataWriter.SaveChanges();


                for (var c = lstContacts.Items.Count - 1; c >= 0; c--)
                {
                    if (!((ListBoxItem)lstContacts.Items[c]).Visible)
                    {
                        lstContacts.Items.Remove(lstContacts.Items[c]);
                    }
                }


                App.LogAction("Contacts", "Updated Contacts");

                DialogResult = DialogResult.OK;
                DirtyStatus.Clear();
                return(true);
            }
            catch (Exception ex)
            {
                MessageDialog.ShowError(ex, this);
                return(false);
            }
        }