public void ComboBoxSyncSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // get the combo box
            ComboBox cb = sender as ComboBox;

            // get xpath source property
            var sourcexpath = cb.GetValue(SourceXPathProperty) as string;

            if (null == sourcexpath || 0 == sourcexpath.Length)
            {
                sourcexpath = "*[1]/@value";
            }

            // get data context
            Object dc = Utils.GetDataContext(cb);
            IEnumerable <XmlNode> contextNodes = Utils.GetXmlDataContext(dc);

            if (null == contextNodes)
            {
                return;
            }

            // get code value
            XmlNode valueNode       = contextNodes.First().SelectSingleNode(sourcexpath);
            string  valueNodeString = String.Empty;

            if (null != valueNode)
            {
                valueNodeString = valueNode.Value;
            }

            // check sync status
            XmlAttribute syncAtt = GetSyncAtt(cb);

            if (null == syncAtt)
            {
                return;
            }

            // handle sync status
            bool isSynced = "true".Equals(syncAtt.Value, StringComparison.InvariantCultureIgnoreCase);

            // get cached value
            if (!_syncItems.ContainsKey(cb))
            {
                return;
            }

            SyncTag cache = _syncItems[cb];

            if (null != cache && valueNode != null)
            {
                bool modified = (null != cache.tagValue) && (cache.tagValue != valueNode.Value);

                // get sync
                if (isSynced && modified)
                {
                    syncAtt.Value = "FALSE";
                }
                else if (cache.syncValue && !modified)
                {
                    syncAtt.Value = "TRUE";
                }
            }
        }
        /// <summary>
        /// Test if the code in the metadata doesn't match a code in the codelist.
        /// If such a value exists, then present that value at the top of the pick list
        ///
        /// Also check the @Sync attribute and change its value to FALSE if another item is selected in the combo box
        ///
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void PostProcessComboBoxValues(object sender, EventArgs e)
        {
            // get the combo box
            ComboBox cb = sender as ComboBox;

            // get xpath source property
            var sourcexpath = cb.GetValue(SourceXPathProperty) as string;

            if (null == sourcexpath || 0 == sourcexpath.Length)
            {
                sourcexpath = "*[1]/@value";
            }

            // get data context
            Object dc = Utils.GetDataContext(cb);
            IEnumerable <XmlNode> contextNodes = Utils.GetXmlDataContext(dc);

            if (null == contextNodes)
            {
                return;
            }

            // get code value
            XmlNode valueNode       = contextNodes.First().SelectSingleNode(sourcexpath);
            string  valueNodeString = String.Empty;

            if (null != valueNode)
            {
                valueNodeString = valueNode.Value;
            }

            // check sync status
            XmlAttribute syncAtt = GetSyncAtt(cb);

            // handle sync
            if (null != syncAtt)
            {
                bool isSynced = "true".Equals(syncAtt.Value, StringComparison.InvariantCultureIgnoreCase);

                // add to hash for later retrieval
                if (_syncItems.ContainsKey(cb))
                {
                    _syncItems.Remove(cb);
                }
                SyncTag item = new SyncTag(valueNodeString, isSynced);
                _syncItems.Add(cb, item);
            }

            // get combox values
            XmlNodeList nodes         = cb.ItemsSource as XmlNodeList;
            object      selectedValue = cb.SelectedValue;

            if (!String.IsNullOrEmpty(valueNodeString))
            {
                if (null == selectedValue)
                {
                    try
                    {
                        // get first node in codelist
                        XmlNode firstNode = nodes[0];

                        // exit if alread added this node
                        if (null == firstNode.Attributes.GetNamedItem("added"))
                        {
                            XmlNode clone = firstNode.CloneNode(true);

                            clone.InnerText = Internal.Metadata.Properties.Resources.CMB_UNRECOGNIZED_VALUE + valueNodeString;
                            clone.Attributes.GetNamedItem("value").Value = valueNodeString;

                            XmlAttribute att = firstNode.OwnerDocument.CreateAttribute("added");
                            att.Value = "True";
                            clone.Attributes.SetNamedItem(att);

                            // insert temporary value
                            firstNode.ParentNode.InsertBefore(clone, firstNode);

                            // give the combobox a new list, reselect
                            cb.ItemsSource = firstNode.SelectNodes("../*");

                            // and a new value
                            cb.SelectedValue = valueNodeString;
                        }
                    }
                    catch (Exception)
                    {
                        // NO-OP
                    }
                }
            }
            else
            {
                //cb.SelectedValue = valueNodeString;
            }
        }
Example #3
0
        /// <summary>
        /// 同步标签 (无租户验证版本)
        /// </summary>
        /// <param name="wx_dept"></param>
        /// <returns>更新的本地Id</returns>
        public void MatchQYTagWithoutTenant(SyncTag wx_tag, int?tenant_id)
        {
            if (wx_tag != null)
            {
                using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
                {
                    if (wx_tag.ChangeType == "update_tag")
                    {
                        _logger.Info("update : " + wx_tag.AddUserItems + " del : " + wx_tag.DelUserItems);
                        var local_role = _roleRepository.FirstOrDefault(r => r.WxTagId == wx_tag.TagId && r.TenantId == tenant_id);
                        int role_id    = 0;
                        if (local_role == null)
                        {
                            var tag_name = _weChatManager.GetTagNameById(wx_tag.TagId.Value, tenant_id.Value);
                            local_role = new Role
                            {
                                WxTagId        = wx_tag.TagId,
                                IsDefault      = false,
                                NormalizedName = "WX_" + tag_name,
                                DisplayName    = "WX_" + tag_name,
                                Name           = "WX_" + tag_name,
                                TenantId       = tenant_id
                            };
                            role_id = _roleRepository.InsertAndGetId(local_role);
                            CurrentUnitOfWork.SaveChanges();
                        }
                        else
                        {
                            role_id = local_role.Id;
                        }

                        if (!string.IsNullOrEmpty(wx_tag.DelUserItems))
                        {
                            var del_users = wx_tag.DelUserItems.Split(',');
                            var del_list  = _userLoginRepository.GetAll().Where(x => del_users.Contains(x.ProviderKey) && x.LoginProvider == "Wechat" && x.TenantId == tenant_id).ToList();
                            if (del_list?.Count > 0)
                            {
                                _userRoleRepository.Delete(x => x.RoleId == role_id && del_list.Any(d => d.UserId == x.UserId));
                                CurrentUnitOfWork.SaveChanges();
                            }
                        }

                        if (!string.IsNullOrEmpty(wx_tag.AddUserItems))
                        {
                            var add_users = wx_tag.AddUserItems.Split(',');
                            var add_list  = _userLoginRepository.GetAll().Where(x => add_users.Contains(x.ProviderKey) && x.LoginProvider == "Wechat" && x.TenantId == tenant_id).ToList();
                            if (add_list?.Count > 0)
                            {
                                foreach (var item in add_list)
                                {
                                    if (!_userRoleRepository.GetAll().Any(x => x.RoleId == role_id && x.TenantId == tenant_id && x.UserId == item.UserId))
                                    {
                                        _userRoleRepository.Insert(new UserRole
                                        {
                                            RoleId   = role_id,
                                            TenantId = tenant_id,
                                            UserId   = item.UserId
                                        });
                                    }
                                }
                                CurrentUnitOfWork.SaveChanges();
                            }
                        }
                    }
                }
            }
        }