Beispiel #1
0
        private static void FromXmlElement(XmlElement elem, XmlTelephoneItem telephoneItem)
        {
            if (elem == null)
            {
                return;
            }
            telephoneItem.Date          = elem.GetAttribute("Date");
            telephoneItem.DateActivated = elem.GetAttribute("DateActivated");
            telephoneItem.Comment       = elem.GetAttribute("Comment");
            telephoneItem.GroupName     = elem.GetAttribute("GroupName");
            telephoneItem.Telephone     = XmlWrapperHelper.ResolvePhoneNumber(elem.InnerText);

            if (telephoneItem.GroupName == String.Empty)
            {
                telephoneItem.GroupName = XmlWrapperHelper.ResolvePhoneGroupName(telephoneItem.Telephone);
            }
        }
        /// <summary>
        /// Add new phone number in database.
        /// </summary>
        /// <param name="phone">New telephone number.</param>
        /// <param name="dateInput">Date of input.</param>
        /// <param name="dateActivated">Date of activation.</param>
        /// <param name="commentary">Comment.</param>
        /// <returns>True if the current number already existed in database.</returns>
        private bool AddNewTelephone(string phone, string dateInput = null, string dateActivated = null, string commentary = null)
        {
            var culture = Application.CurrentCulture;

            if (phone.Length < 6)
            {
                var warningInvalidFormatText = String.Format(ResourceManagerProvider.GetLocalizedString("MSG_NUMBER_INVALID_FORMAT", culture), phone);
                if (MessageBox.Show(warningInvalidFormatText,
                                    ResourceManagerProvider.GetLocalizedString("MSG_WARNING_TITLE", culture),
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    return(true);
                }
                return(false);
            }

            phone = XmlWrapperHelper.ResolvePhoneNumber(phone);
            if (_xmlWrapper.TelephoneItems.All(x => x.Telephone != phone))
            {
                var groupName = XmlWrapperHelper.ResolvePhoneGroupName(phone);
                if (string.IsNullOrEmpty(groupName))
                {
                    groupName = cbGroupFilter.Items[cbGroupFilter.SelectedIndex].ToString();
                }
                var phoneItem = String.IsNullOrEmpty(dateInput) ? new XmlTelephoneItem(phone, groupName, DateTime.Now) : new XmlTelephoneItem(phone, groupName, dateInput, dateActivated, commentary);
                _xmlWrapper.TelephoneItems.Add(phoneItem);
                listTelephones.AddTelephone(phoneItem);
                return(true);
            }

            var warningDuplicatedText = String.Format(ResourceManagerProvider.GetLocalizedString("MSG_NUMBER_DUPLICATED", culture), phone);

            if (MessageBox.Show(warningDuplicatedText, ResourceManagerProvider.GetLocalizedString("MSG_WARNING_TITLE", culture),
                                MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                return(true);
            }
            return(false);
        }