public Window_AddEditContact(Object parent, Object contact, List<string> listGroup) // for printer
        {
            InitializeComponent();
            currentMode = MODE_PRINTER;
            this.parent = parent;
            listGroupName = listGroup;

            if (contact == null)
            {
                this.Title = CMLibrary.Properties.Resources.add_contact;
            }
            else
            {
                this.Title = CMLibrary.Properties.Resources.edit_contact;

                if (contact is ContactDB)
                {
                    contactDB = (ContactDB)contact;
                }
                else if (contact is ContactPrinter)
                {
                    contactPrinter = (ContactPrinter)contact;
                }
            }
        }
示例#2
0
        public static List<Object> CloneContactList(List<Object> list)
        {
            List<Object> listContact = new List<Object>();

            if (list != null && list.Count() > 0)
            {
                foreach (Object contact in list)
                {
                    if (contact is ContactDB)
                    {
                        ContactDB cloneContact = new ContactDB();
                        cloneContact.Clone((ContactDB)contact);
                        listContact.Add(cloneContact);
                    }
                    else if (contact is ContactPrinter)
                    {
                        ContactPrinter cloneContact = new ContactPrinter();
                        cloneContact.Clone((ContactPrinter)contact);
                        listContact.Add(cloneContact);
                    }
                }
            }

            return listContact;
        }
示例#3
0
 public void Clone(ContactPrinter contactPrinter)
 {
     if (contactPrinter != null)
     {
         contactAction = contactPrinter.ContactAction;
         id = contactPrinter.Id;
         name = contactPrinter.Name;
         email = contactPrinter.Email;
         fax = contactPrinter.Fax;
         fromPrinter = contactPrinter.FromPrinter;
         groupName = contactPrinter.GroupName;
         nameOrder = contactPrinter.NameOrder;
     }
 }
示例#4
0
        public static List<ContactPrinter> ParseContactsFromJson(Printer printer, string json)
        {
            List<ContactPrinter> list = new List<ContactPrinter>();
            JToken token = JObject.Parse(json);
            JToken contacts = token.SelectToken("contacts");
            foreach (JToken data in contacts)
            {
                ContactPrinter contact = new ContactPrinter();
                contact.ParseContactFromJToken(data);
                contact.fromPrinter = printer;
                contact.NameOrder = ContactDB.NAME_ORDER_FIRST_MID_LAST;
                list.Add(contact);
            }

            return list;
        }
示例#5
0
 public ContactPrinter(ContactPrinter contactPrinter)
 {
     Printer printer = new Printer();
     printer.IpAddress = contactPrinter.FromPrinter.IpAddress;
     printer.MaxContact = contactPrinter.FromPrinter.MaxContact;
     printer.MaxGroup = contactPrinter.FromPrinter.MaxGroup;
     printer.Name = contactPrinter.FromPrinter.Name;
     this.id = contactPrinter.id;
     this.contactAction = contactPrinter.contactAction;
     this.email = contactPrinter.email;
     this.fax = contactPrinter.fax;
     this.groupName = contactPrinter.groupName;
     this.name = contactPrinter.name;
     this.nameOrder = contactPrinter.nameOrder;
     this.fromPrinter = printer;
 }
示例#6
0
        public void notifyResult(string resultJson)
        {
            if (listener != null)
            {
                contactPrinter = new ContactPrinter();
                if (contactPrinter.IsGetContactFromPrinter(resultJson))
                {
                    DataManager.Instance.IsSendPrinter = true;
                    List<ContactPrinter> list = ContactPrinter.ParseContactsFromJson(printer, resultJson);
                    listener.notifyPrinterContactList(list);
                    SetContactLocalFromPrinter(list);
                }
                else
                {
                    DataManager.Instance.IsSendPrinter = false;
                    var errorPrinter = ErrorPrinter.ParseErrorFromJson(resultJson);
                    listener.notifyError(errorPrinter);
                }

            }
        }
示例#7
0
        public static List<Printer> ParsePrintsFromJson(string json)
        {
            List<Printer> listPrint = new List<Printer>();
            List<ContactPrinter> listContactPrinter = new List<ContactPrinter>();

            var list = JsonParser.ToArrayOject<Printer>(json);

            //JToken token = JObject.Parse(json);
            //JToken contacts = token.SelectToken("contacts");
            foreach (var item in list)
            {
                ContactPrinter contactPrint = new ContactPrinter();
                contactPrint.Name = "name 1";
                contactPrint.NameOrder = "oder name";
                listContactPrinter.Add(contactPrint);
                Printer print = new Printer();
                print.IpAddress = item.ipAddress;
                print.MaxContact = item.MaxContact;
                print.MaxContact = item.MaxContact;
                
                listPrint.Add(print);
            }
            return listPrint;
        }
示例#8
0
        private bool CheckContactSendToPrinter()
        {
            ContactPrinter contactPrinter = new ContactPrinter();
            var listContactsInLocal = contactPrinter.GetListContactSendToPrinterInLocal();
            if (listContactsInLocal.Any())
                return true;
            return false;

        }
示例#9
0
        public ContactPrinter ConvertObjToContactPrinter(Object contactObj, string action)
        {
            int id = -1;
            string name = "";
            string email = "";
            string fax = "";
            string groupName = "";
            string location = "";
            Printer printer = new Printer();

            if (contactObj is ContactDB)
            {
                ContactDB contactDB = ((ContactDB)contactObj);
                id = contactDB.Id;
                name = contactDB.Name;
                groupName = contactDB.GroupName;
                location = contactDB.AccountName;
                email = contactDB.ListEmail.Count() > 0 ? contactDB.ListEmail[0].Value : "";
                fax = contactDB.ListFax.Count() > 0 ? contactDB.ListFax[0].Value : "";
            }
            else if (contactObj is ContactPrinter)
            {
                ContactPrinter contactPrinter = ((ContactPrinter)contactObj);
                id = contactPrinter.Id;
                name = contactPrinter.Name;
                groupName = contactPrinter.GroupName;
                location = contactPrinter.FromPrinter.Name;
                email = contactPrinter.Email;
                fax = contactPrinter.Fax;
                printer = contactPrinter.FromPrinter;
            }

            ContactPrinter contact = new ContactPrinter();
            contact.Id = id;
            contact.Name = name;
            contact.Email = email;
            contact.Fax = fax;
            contact.GroupName = groupName;
            contact.FromPrinter = printer;
            contact.ContactAction = action;
            return contact;
        }
        private void btn_save_Click(object sender, RoutedEventArgs e)
        {
            int currentLimitContact = ContactDB.MAX_CONTACT;
            int currentLimitGroup = GroupDB.MAX_GROUP;
            int newContactCount = UC_AddressBook.AllContactCount + 1;
            int newGroupCount;
            string group = MyUtils.RemoveSpaces(tbox_group.Text);
            string firstName = MyUtils.RemoveSpaces(tbox_firstname.Text);
            string middleName = MyUtils.RemoveSpaces(tbox_middlename.Text);
            string lastName = MyUtils.RemoveSpaces(tbox_lastname.Text);
            if (String.IsNullOrEmpty(firstName + middleName + lastName))
            {
                NotifyUser(CMLibrary.Properties.Resources.name_no_empty, NotifyType.ErrorMessage);
                return;
            }

            string email = tbox_email.Text.Trim();
            string fax = MyUtils.RemoveSpaces(tbox_fax.Text);
            string contact_id = tbox_contact_id.Text.Trim();
            if (String.IsNullOrEmpty(email))
            {
                if (String.IsNullOrEmpty(fax))
                {
                    NotifyUser(CMLibrary.Properties.Resources.enter_value_for_email_or_fax, NotifyType.ErrorMessage);
                    return;
                }
            }
            else if (!MyUtils.IsEmailValid(email))
            {
                NotifyUser(CMLibrary.Properties.Resources.email_invalid, NotifyType.ErrorMessage);
                return;
            }

            if (CheckLimitGroupInLocal(group) > 0)
            {
                newGroupCount = UC_AddressBook.AllGroupCount + CheckLimitGroupInLocal(group);
            }
            else
            {
                newGroupCount = UC_AddressBook.AllGroupCount;
            }

            DuplicateContactMode mode;
            if (radio_btn_allow_duplicate.IsChecked == true)
            {
                mode = DuplicateContactMode.ALLOW_ADD_NEW;
            }
            else if (radio_btn_replace_with_new.IsChecked == true)
            {
                mode = DuplicateContactMode.REPLACE_WITH_NEW_ITEM;
            }
            else
            {
                mode = DuplicateContactMode.DO_NOT_IMPORT;
            }
            dbController.UpdateDuplicateContactMode(mode);

            if (currentMode == MODE_LOCAL)
            {
                int res = 0;
                List<int> listBelongGroupId = new List<int>();
                List<int> listContactIdDuplicated = new List<int>();
                bool isValidateContactLimit;
                if (contactId <= 0) // add new
                {
                    isValidateContactLimit = validate_contact_limit(currentLimitContact, currentLimitGroup, newContactCount, newGroupCount);
                    if (isValidateContactLimit)
                    {
                        listContactId = dbController.SelfAddContact(firstName, middleName, lastName, email, fax);
                    }
                    else {
                        this.Close();
                    }
                }
                else
                {
                    int updRes = 0;
                    // list email
                    List<EmailDB> lEmail = new List<EmailDB>();
                    EmailDB emailDB = new EmailDB();
                    emailDB.Value = email;
                    lEmail.Add(emailDB);
                    // list fax
                    List<FaxDB> lFax = new List<FaxDB>();
                    FaxDB faxDB = new FaxDB();
                    faxDB.Value = fax;
                    lFax.Add(faxDB);

                    List<ContactDB> listContactDB = new List<ContactDB>();
                    ContactDB contactDB = new ContactDB();
                    contactDB.Id = contactId;
                    contactDB.FirstName = firstName;
                    contactDB.LastName = lastName;
                    contactDB.MiddleName = middleName;
                    contactDB.ListEmail = lEmail;
                    contactDB.ListFax = lFax;
                    listContactDB.Add(contactDB);
                    listContactIdDuplicated = dbController.GetContactIdDuplicated(listContactDB);
                    if (mode == DuplicateContactMode.DO_NOT_IMPORT)
                    {
                        if (listContactIdDuplicated.Any())
                        {
                            this.Close();
                            return;
                        }
                        else
                        {
                            isValidateContactLimit = validate_contact_limit(ContactDB.MAX_LIMITATION, currentLimitGroup, 0, newGroupCount);
                            if (isValidateContactLimit)
                            {
                                updRes = dbController.UpdateContact(contactId, firstName, middleName, lastName, email, fax);
                            }
                            else
                            {
                                return;
                            }

                        }
                    }
                    else if (mode == DuplicateContactMode.REPLACE_WITH_NEW_ITEM)
                    {
                        isValidateContactLimit = validate_contact_limit(ContactDB.MAX_LIMITATION, currentLimitGroup, 0, newGroupCount);
                        if (isValidateContactLimit)
                        {
                            updRes = dbController.UpdateContact(contactId, firstName, middleName, lastName, email, fax);
                            dbController.UpdateContactDuplicate(contactId, listContactIdDuplicated);
                        }
                        else { return; }

                    }
                    else
                    {
                        isValidateContactLimit = validate_contact_limit(ContactDB.MAX_LIMITATION, currentLimitGroup, 0, newGroupCount);
                        if (isValidateContactLimit)
                        {
                            updRes = dbController.UpdateContact(contactId, firstName, middleName, lastName, email, fax);
                        }
                        else
                        {
                            return;
                        }
                    }
                    if (updRes <= 0)
                    {
                        NotifyUser(CMLibrary.Properties.Resources.database_failure, NotifyType.ErrorMessage);
                        return;
                    }
                    else
                    {
                        if (parent is Page_LocalContacts)
                        {
                            ((Page_LocalContacts)parent).clearPreviousState();
                            //((Page_LocalContacts)parent).Reload();
                        }
                    }
                }
                //List<int> contactIds = new List<int>();
                //contactIds.Add(contactId);
                //List<int> currentBelongGroupIds = dbController.GetGroupIdListByCheckedContactIdList(contactIds);

                if (isValidateContactLimit == true)
                {
                    listBelongGroupId = GetListGroupId();
                    if (listBelongGroupId == null)
                    {
                        return;
                    }
                }

                if (listContactId.Count != 0)
                {
                    foreach (var Id in listContactId)
                    {
                        res = dbController.UpdateContactBelongToGroupList(Id, listBelongGroupId);
                    }
                }
                else
                {
                    res = dbController.UpdateContactBelongToGroupList(contactId, listBelongGroupId);
                }
                // update all contacts if option choose replace duplicate
                if (listContactIdDuplicated.Any() && mode != DuplicateContactMode.ALLOW_ADD_NEW)
                {
                    foreach (var Id in listContactIdDuplicated)
                    {
                        res = dbController.UpdateContactBelongToGroupList(Id, listBelongGroupId);
                    }
                }

                if (res > 0)
                {
                    if (parent is Page_LocalContacts)
                    {
                        Page_LocalContacts page = (Page_LocalContacts)parent;
                        page.NotifyNewGroupAndContactAdded();
                        page.RefreshContactCount();
                    }
                    this.Close();
                }
                else
                {
                    NotifyUser(CMLibrary.Properties.Resources.database_failure, NotifyType.ErrorMessage);
                }
            }
            else if (currentMode == MODE_PRINTER)
            {
                Page_PrinterContacts uc_parent = null;
                if (parent is Page_PrinterContacts)
                {
                    uc_parent = (Page_PrinterContacts)parent;
                }
                string listGroupStr = tbox_group.Text.TrimStart().TrimEnd();
                List<string> listGroupSplits = GetListGroupString(listGroupStr);
                int len = listGroupSplits.Count;
                if (len > GroupDB.MAX_GROUP)
                {
                    NotifyUser(CMLibrary.Properties.Resources.exceed_group_limit, NotifyType.ErrorMessage);
                    return;
                }

                string groupName = "";
                for (int i = 0; i < len; i++)
                {
                    groupName += listGroupSplits[i];
                    if (i < len - 1)
                    {
                        groupName += GroupDB.SEPARATE_TOKEN;
                    }
                }
                var listContactPrinter = DataManager.Instance.ListSentToPrinter;
                if (contactDB == null && contactPrinter == null) // Add new
                {
                    int contactPrinter_Id = 1;
                    if (listContactPrinter.Any())
                    {
                        contactPrinter_Id = listContactPrinter.Cast<ContactPrinter>().ToList().OrderBy(c => c.Id).ToList().Last().Id + 1;
                    }
                    contactPrinter = new ContactPrinter();
                    contactPrinter.Id = contactPrinter_Id;
                    string name = ContactDB.GetFullNameFromFirstMidLast(firstName, middleName, lastName, contactPrinter.NameOrder);
                    contactPrinter.FirstName = firstName;
                    contactPrinter.LastName = lastName;
                    contactPrinter.MiddleName = middleName;
                    contactPrinter.Name = name;
                    contactPrinter.Email = email;
                    contactPrinter.Fax = fax;
                    contactPrinter.GroupName = groupName;
                    contactPrinter.ContactAction = ContactAB.PRINTER_ADD;
                    Printer printer = new Printer("", AccountDB.SELF_ACCOUNT_NAME);
                    contactPrinter.FromPrinter = printer;

                    List<ContactPrinter> list = new List<ContactPrinter>();
                    list.Add(contactPrinter);
                    if (uc_parent != null)
                    {
                        uc_parent.AddMoreContacts(list);
                    }
                }
                else // edit
                {
                    if (contactDB != null)
                    {
                        contactDB.FirstName = firstName;
                        contactDB.MiddleName = middleName;
                        contactDB.LastName = lastName;
                        contactDB.SelfUpdateName();

                        List<EmailDB> listEmail = contactDB.ListEmail;
                        if (listEmail.Count > 0)
                        {
                            listEmail[0].Value = email;
                        }
                        else
                        {
                            EmailDB emailDB = new EmailDB();
                            emailDB.Value = email;
                            listEmail.Add(emailDB);
                        }

                        List<FaxDB> listFax = contactDB.ListFax;
                        if (listFax.Count > 0)
                        {
                            listFax[0].Value = fax;
                        }
                        else
                        {
                            FaxDB faxlDB = new FaxDB();
                            faxlDB.Value = fax;
                            listFax.Add(faxlDB);
                        }
                        var isDuplicate = uc_parent.FindDuplicateContact123(contactDB);

                        if (uc_parent.CheckLimitGroupWhenChange(groupName))
                        {
                            NotifyUser(CMLibrary.Properties.Resources.group_limitation_printer, NotifyType.ErrorMessage);
                            return;
                        }
                        switch (mode)
                        {
                            case DuplicateContactMode.REPLACE_WITH_NEW_ITEM:
                                contactDB.GroupName = groupName;
                                break;
                            case DuplicateContactMode.ALLOW_ADD_NEW:
                                contactDB.GroupName = groupName;
                                break;
                            case DuplicateContactMode.DO_NOT_IMPORT:
                                if (!isDuplicate.Any())
                                {
                                    contactDB.GroupName = groupName;
                                }
                                break;
                            default:
                                break;
                        }

                        if (uc_parent != null)
                        {
                            uc_parent.UpdateContact(contactDB, false);
                        }
                    }
                    else if (contactPrinter != null)
                    {
                        var isDuplicate = uc_parent.FindDuplicateContact123(contactPrinter);
                        string name = ContactDB.GetFullNameFromFirstMidLast(firstName, middleName, lastName, ContactDB.NAME_ORDER_FIRST_LAST_MID);
                        contactPrinter.FirstName = firstName;
                        contactPrinter.LastName = lastName;
                        contactPrinter.MiddleName = middleName;
                        contactPrinter.Name = name;
                        contactPrinter.Email = email;
                        contactPrinter.Fax = fax;
                        if (uc_parent.CheckLimitGroupWhenChange(groupName))
                        {
                            NotifyUser(CMLibrary.Properties.Resources.group_limitation_printer, NotifyType.ErrorMessage);
                            return;
                        }
                        switch (mode)
                        {
                            case DuplicateContactMode.REPLACE_WITH_NEW_ITEM:
                                contactPrinter.GroupName = groupName;
                                break;
                            case DuplicateContactMode.ALLOW_ADD_NEW:
                                contactPrinter.GroupName = groupName;
                                break;
                            case DuplicateContactMode.DO_NOT_IMPORT:
                                if (!isDuplicate.Any())
                                {
                                    contactPrinter.GroupName = groupName;
                                }
                                break;
                            default:
                                break;
                        }
                        
                        if (contactPrinter.IsLocal(int.Parse(contact_id)))
                        {
                            contactPrinter.ContactAction = ContactAB.PRINTER_UPDATE;
                        }
                        if (uc_parent != null)
                        {
                            uc_parent.UpdateContact(contactPrinter, false);
                        }
                    }
                }
                this.Close();
            }
        }
        private void btn_save_Click(object sender, RoutedEventArgs e)
        {
            string firstName = tbox_firstname.Text.Trim();
            string middleName = tbox_middlename.Text.Trim();
            string lastName = tbox_lastname.Text.Trim();
            if (String.IsNullOrEmpty(firstName + middleName + lastName))
            {
                MessageBox.Show(CMLibrary.Properties.Resources.name_no_empty);
                return;
            }

            string email = tbox_email.Text.Trim();
            string fax = tbox_fax.Text.Trim();

            if (String.IsNullOrEmpty(email))
            {
                if (String.IsNullOrEmpty(fax))
                {
                    MessageBox.Show(CMLibrary.Properties.Resources.enter_value_for_email_or_fax);
                    return;
                }
            }
            else if (!MyUtils.IsEmailValid(email))
            {
                MessageBox.Show(CMLibrary.Properties.Resources.wrong_email_format);
                return;
            }


            DuplicateContactMode mode;
            if (radio_btn_allow_duplicate.IsChecked == true)
            {
                mode = DuplicateContactMode.ALLOW_ADD_NEW;
            }
            else if (radio_btn_replace_with_new.IsChecked == true)
            {
                mode = DuplicateContactMode.REPLACE_WITH_NEW_ITEM;
            }
            else
            {
                mode = DuplicateContactMode.DO_NOT_IMPORT;
            }
            dbController.UpdateDuplicateContactMode(mode);

            if (currentMode == MODE_LOCAL)
            {
                if (contactId <= 0) // add new
                {
                    contactId = dbController.SelfAddContact(firstName, middleName, lastName, email, fax);
                }
                else
                {
                    int updRes = dbController.UpdateContact(contactId, firstName, middleName, lastName, email, fax);
                    if (updRes <= 0)
                    {
                        MessageBox.Show(CMLibrary.Properties.Resources.database_failure);
                        return;
                    }
                }

                List<int> listBelongGroupId = GetListGroupId();
                if (listBelongGroupId == null)
                {
                    return;
                }
                int res = dbController.UpdateContactBelongToGroupList(contactId, listBelongGroupId);
                if (res > 0)
                {
                    if (parent is Page_LocalContacts)
                    {
                        Page_LocalContacts page = (Page_LocalContacts)parent;
                        page.NotifyNewGroupAndContactAdded();
                    }
                    this.Close();
                }
                else
                {
                    MessageBox.Show(CMLibrary.Properties.Resources.database_failure);
                }
            }
            else if (currentMode == MODE_PRINTER)
            {
                Page_PrinterContacts uc_parent = null;
                if (parent is Page_PrinterContacts)
                {
                    uc_parent = (Page_PrinterContacts)parent;
                }
                string listGroupStr = tbox_group.Text.TrimStart().TrimEnd();
                List<string> listGroupSplits = GetListGroupString(listGroupStr);
                int len = listGroupSplits.Count;
                if (len > GroupDB.MAX_GROUP)
                {
                    MessageBox.Show(CMLibrary.Properties.Resources.exceed_group_limit);
                    return;
                }

                string groupName = "";
                for (int i = 0; i < len; i++)
                {
                    groupName += listGroupSplits[i];
                    if (i < len - 1)
                    {
                        groupName += GroupDB.SEPARATE_TOKEN;
                    }
                }

                if (contactDB == null && contactPrinter == null) // Add new
                {
                    contactPrinter = new ContactPrinter();
                    string name = ContactDB.GetFullNameFromFirstMidLast(firstName, middleName, lastName, contactPrinter.NameOrder);
                    contactPrinter.Name = name;
                    contactPrinter.Email = email;
                    contactPrinter.Fax = fax;
                    contactPrinter.GroupName = groupName;
                    Printer printer = new Printer("", AccountDB.SELF_ACCOUNT_NAME);
                    contactPrinter.FromPrinter = printer;

                    List<ContactPrinter> list = new List<ContactPrinter>();
                    list.Add(contactPrinter);

                    if (uc_parent != null)
                    {
                        uc_parent.AddMoreContacts(list);
                    }
                }
                else // edit
                {
                    if (contactDB != null)
                    {
                        contactDB.FirstName = firstName;
                        contactDB.MiddleName = middleName;
                        contactDB.LastName = lastName;
                        contactDB.SelfUpdateName();

                        List<EmailDB> listEmail = contactDB.ListEmail;
                        if (listEmail.Count > 0)
                        {
                            listEmail[0].Value = email;
                        }
                        else
                        {
                            EmailDB emailDB = new EmailDB();
                            emailDB.Value = email;
                            listEmail.Add(emailDB);
                        }

                        List<FaxDB> listFax = contactDB.ListFax;
                        if (listFax.Count > 0)
                        {
                            listFax[0].Value = fax;
                        }
                        else
                        {
                            FaxDB faxlDB = new FaxDB();
                            faxlDB.Value = fax;
                            listFax.Add(faxlDB);
                        }

                        contactDB.GroupName = groupName;
                        if (uc_parent != null)
                        {
                            uc_parent.UpdateContact(contactDB);
                        }
                    }
                    else if (contactPrinter != null)
                    {
                        string name = ContactDB.GetFullNameFromFirstMidLast(firstName, middleName, lastName, ContactDB.NAME_ORDER_FIRST_LAST_MID);
                        contactPrinter.Name = name;
                        contactPrinter.Email = email;
                        contactPrinter.Fax = fax;
                        contactPrinter.GroupName = groupName;
                        if (uc_parent != null)
                        {
                            uc_parent.UpdateContact(contactPrinter);
                        }
                    }
                }

                this.Close();
            }
        }
        private void btn_ok_Click(object sender, RoutedEventArgs e)
        {
            if (currentMode == MODE_LOCAL)
            {
                //phtkiet
                if (!checkLimit())
                {
                    return;
                }
                //phtkiet

                List<int> listGroupId = GetListGroupId();
                if (listGroupId == null)
                {
                    return;
                }
                List<int> listContactId = new List<int>();
                foreach (ContactDB contact in listContact)
                {
                    listContactId.Add(contact.Id);
                }
                List<int> currentBelongGroupIds = dbController.GetGroupIdListByCheckedContactIdList(listContactId);
                if (parent is Page_LocalContacts)
                {
                    ((Page_LocalContacts)parent).NotifyNewGroupAdded();
                }
                int res = 0;

                //if (checkLimit())
                //{
                res = dbController.UpdateContactsOfGroups(listGroupId, listContactId, listGroupDuplicateIdOld, isSelectedMultiple);
                List<int> deleteGroupIds = new List<int>();
                foreach (var groupId in currentBelongGroupIds)
                {
                    int contactCount = dbController.GetGroupContactIdList(groupId).Count;
                    if (contactCount == 0)
                    {
                        deleteGroupIds.Add(groupId);
                    }
                }
                if (deleteGroupIds.Any())
                {
                    MessageBoxResult dialogResGroup = MessageBox.Show(CMLibrary.Properties.Resources.delete_last_contact_in_group,
                CMLibrary.Properties.Resources.warning,
                MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    if (dialogResGroup == MessageBoxResult.Yes)
                    {
                        dbController.DeleteGroupList(deleteGroupIds);
                        UC_AddressBook.AllGroupCount = dbController.GetAllGroups().Count;
                    }
                }
                //}
                ////Not Add
                //else
                //{
                //    return;
                //}

                if (res > 0)
                {
                    if (parent is Page_LocalContacts)
                    {
                        ((Page_LocalContacts)parent).clearPreviousState();
                        ((Page_LocalContacts)parent).Reload();

                    }

                    this.Close();
                }
                else
                {
                    NotifyUser(CMLibrary.Properties.Resources.database_failure, NotifyType.ErrorMessage);
                }
            }
            else if (currentMode == MODE_PRINTER)
            {
                string listGroupStr = tbox_group.Text.TrimStart().TrimEnd();

                List<string> listGroupSplits = GetListGroupString(listGroupStr);
                int count = listGroupSplits.Count();
                if (count > GroupDB.MAX_GROUP)
                {
                    NotifyUser(CMLibrary.Properties.Resources.exceed_group_limit, NotifyType.ErrorMessage);
                    return;
                }

                listGroupStr = "";
                for (int i = 0; i < count; i++)
                {
                    listGroupStr += listGroupSplits[i];
                    if (i < count - 1)
                    {
                        listGroupStr += GroupDB.SEPARATE_TOKEN;
                    }
                }

                if (parent is Page_PrinterContacts)
                {
                    bool isLimitGroupPrinter = ((Page_PrinterContacts)parent).CheckLimitGroupWhenChange(listGroupStr);
                    if (isLimitGroupPrinter)
                    {
                        NotifyUser(CMLibrary.Properties.Resources.group_limitation_printer, NotifyType.ErrorMessage);
                        return;
                    }
                }

                if (listPrinterContact.Count() >= 2)
                {
                    // Update action for printer.
                    foreach (Object contactObj in listPrinterContact)
                    {
                        if (contactObj is ContactAB)
                        {
                            if (String.Compare(((ContactAB)contactObj).GroupName, listGroupStr) != 0)
                            {
                                var contactPrinter = new ContactPrinter();
                                if (contactPrinter.IsLocal(((ContactAB)contactObj).Id))
                                {
                                    ((ContactAB)contactObj).ContactAction = ContactAB.PRINTER_UPDATE;
                                }
                            }
                        }
                    }
                    // Remove/Update select multiple contacts have duplicate.
                    if (listGroupPrinterDuplicateOld.Any())
                    {
                        RemoveGroupDuplicateOld();
                    }
                    // Update group after checked duplicate history
                    foreach (Object contactObj in listPrinterContact)
                    {
                        if (contactObj is ContactAB)
                        {
                            ContactAB contactAB = (ContactAB)contactObj;
                            string groupStr = "";
                            string currentGroupStr = contactAB.GroupName;
                            string groupStrPrinter = UpdateGroupPrinter(contactObj, listGroupStr);
                            if (currentGroupStr != "")
                            {
                                groupStr = currentGroupStr + ";" + groupStrPrinter;
                            }
                            else
                            {
                                groupStr = groupStrPrinter;
                            }
                            contactAB.GroupName = groupStr.TrimEnd(';');
                        }
                    }
                }
                else
                {
                    foreach (Object contactObj in listPrinterContact)
                    {
                        if (contactObj is ContactAB)
                        {
                            if (String.Compare(((ContactAB)contactObj).GroupName, listGroupStr) != 0)
                            {
                                var contactPrinter = new ContactPrinter();
                                if (contactPrinter.IsLocal(((ContactAB)contactObj).Id))
                                {
                                    ((ContactAB)contactObj).ContactAction = ContactAB.PRINTER_UPDATE;
                                }
                            }
                            ((ContactAB)contactObj).GroupName = listGroupStr;
                        }
                    }
                }

                if (parent is Page_PrinterContacts)
                {
                    ((Page_PrinterContacts)parent).UpdateListGroupNameAndReload(listPrinterContact);
                }
                this.Close();
            }
        }