private void RefreshMainAttribute(int addLevel) { RoleInfo roleInfo = HeroStrengthenProxy.instance.StrengthenHeroInfo; TransformUtil.ClearChildren(heroAttributeViewRoot, true); //List<RoleAttribute> mainAttriList = HeroUtil.CalcHeroMainAttributesByHeroType(heroInfo); //HeroInfo nextTemp = new HeroInfo(0,heroInfo.heroData.id,heroInfo.breakthroughLevel,heroInfo.strengthenLevel+addLevel,heroInfo.advanceLevel,heroInfo.level); List <RoleAttribute> mainAttriList = RoleUtil.CalcRoleMainAttributesList(roleInfo); RoleInfo nextTemp = null; if ((roleInfo as HeroInfo) != null) { nextTemp = new HeroInfo(roleInfo.instanceID, roleInfo.modelDataId, roleInfo.breakthroughLevel, roleInfo.strengthenLevel + addLevel, roleInfo.advanceLevel, roleInfo.level); } else if ((roleInfo as PlayerInfo) != null) { nextTemp = new PlayerInfo(0, (uint)roleInfo.modelDataId, 0, 0, 0, 0, ""); nextTemp.breakthroughLevel = roleInfo.breakthroughLevel; nextTemp.strengthenLevel = roleInfo.strengthenLevel + addLevel; nextTemp.advanceLevel = roleInfo.advanceLevel; nextTemp.level = roleInfo.level; } bool isMaxLevel = HeroStrengthenNeedData.IsMaxLevel(roleInfo.strengthenLevel); List <RoleAttribute> nextMainAttriList = RoleUtil.CalcRoleMainAttributesList(nextTemp); heroAttributeViewPrefab.gameObject.SetActive(true); for (int i = 0, count = mainAttriList.Count; i < count; i++) { AttributeView view = Instantiate <AttributeView>(heroAttributeViewPrefab); Transform tran = view.transform; tran.SetParent(heroAttributeViewRoot, false); if (isMaxLevel) { view.Set(mainAttriList[i]); } else { view.Set(mainAttriList[i], (int)(nextMainAttriList[i].value - mainAttriList[i].value)); } } heroAttributeViewPrefab.gameObject.SetActive(false); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var dm = values[0] as Datamodel.Datamodel; if (dm == null) { return(null); } var path = (string)values[1]; if (path == String.Empty) { return(null); } object current; if (path.StartsWith("//")) { current = dm.Root; path = path.Remove(0, 2); } else { throw new NotImplementedException(); } foreach (var part in path.Split('/').Where(p => p.Length > 0)) { var attr = current as AttributeView; if (attr != null && attr.Value is Element) { current = attr.Value; attr = null; } var elem = current as Element; if (elem == null) { break; } var name = part; var index = -1; if (!elem.ContainsKey(part)) { var indexer_pos = part.LastIndexOf('['); if (indexer_pos != -1) { name = part.Substring(0, indexer_pos); index = Int32.Parse(part.Substring(indexer_pos + 1, part.Length - indexer_pos - 2)); } } if (!elem.ContainsKey(name)) { return(null); } current = attr = new AttributeView(elem, name, index); } return(current); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var dm = values[0] as Datamodel.Datamodel; if (dm == null) return null; var path = (string)values[1]; if (path == String.Empty) return null; object current; if (path.StartsWith("//")) { current = dm.Root; path = path.Remove(0, 2); } else throw new NotImplementedException(); foreach (var part in path.Split('/').Where(p => p.Length > 0)) { var attr = current as AttributeView; if (attr != null && attr.Value is Element) { current = attr.Value; attr = null; } var elem = current as Element; if (elem == null) break; var name = part; var index = -1; if (!elem.ContainsKey(part)) { var indexer_pos = part.LastIndexOf('['); if (indexer_pos != -1) { name = part.Substring(0, indexer_pos); index = Int32.Parse(part.Substring(indexer_pos + 1, part.Length - indexer_pos - 2)); } } if (!elem.ContainsKey(name)) return null; current = attr = new AttributeView(elem, name, index); } return current; }
/// <summary> /// 查询属性集合 /// </summary> /// <param name="search">查询条件</param> /// <returns>属性数据集合</returns> public List <AttributeView> QueryAttrId(SearchCondition search) { List <AttributeView> result = new List <AttributeView>(); MySqlConnection connection = Connection.GetConnection(); MySqlCommand cmd = new MySqlCommand(); StringBuilder sql = new StringBuilder(); sql.Append("SELECT a.Id AS AttrId,a.`Name`,b.Id AS ValueId,b.`Value` FROM Himall_Attributes a "); sql.Append("INNER JOIN Himall_AttributeValues b on a.Id=b.AttributeId "); sql.Append("INNER JOIN (SELECT DISTINCT _pa.AttributeId,_pa.ValueId FROM Himall_Products _p "); sql.Append("INNER JOIN Himall_ProductAttributes _pa on _p.Id = _pa.ProductId "); sql.Append("WHERE _p.IsDeleted=0 AND _p.AuditStatus=2 AND _p.SaleStatus=1 "); #region 店铺过滤 if (search.shopId > 0) { sql.Append(" AND _p.ShopId=@ShopId "); cmd.Parameters.AddWithValue("@ShopId", search.shopId); } #endregion #region 品牌过滤 if (search.BrandId > 0) { sql.Append(" AND _p.BrandId=@BrandId "); cmd.Parameters.AddWithValue("@BrandId", search.BrandId); } #endregion #region 分类过滤 if (search.CategoryId > 0) { if (search.shopId > 0) { sql.Append(" AND _p.Id IN (SELECT DISTINCT ProductId FROM Himall_ProductShopCategories WHERE ShopCategoryId = @ShopCategoryId)"); cmd.Parameters.AddWithValue("@ShopCategoryId", search.ShopCategoryId); } else { sql.AppendFormat("AND _p.CategoryId IN (SELECT Id FROM Himall_Categories WHERE CONCAT('|',Path,'|') LIKE '%|{0}|%')", search.CategoryId); } } #endregion #region 属性过滤 if (search.AttrIds.Count > 0) { string sqlAttrWhere = string.Empty; for (int i = 0; i < search.AttrIds.Count; i++) { if (search.AttrIds[i].Contains("_")) { string attrId = search.AttrIds[i].Split(new char[] { '_' })[0]; string valId = search.AttrIds[i].Split(new char[] { '_' })[1]; sqlAttrWhere += string.Format("(AttributeId=@AttrId{0} AND ValueId=@ValId{0}) OR", i.ToString()); cmd.Parameters.AddWithValue(string.Format("@AttrId{0}", i.ToString()), attrId); cmd.Parameters.AddWithValue(string.Format("@ValId{0}", i.ToString()), valId); } } if (!string.IsNullOrEmpty(sqlAttrWhere)) { sqlAttrWhere = sqlAttrWhere.Substring(0, sqlAttrWhere.Length - 3); sql.AppendFormat(" AND _p.Id IN (SELECT DISTINCT ProductId FROM Himall_ProductAttributes WHERE {0}) ", sqlAttrWhere); } } #endregion #region 价格区间 if (search.StartPrice > 0) { sql.Append(" AND _p.MinSalePrice>=@StartPrice "); cmd.Parameters.AddWithValue("@StartPrice", search.StartPrice); } if (search.EndPrice > 0 && search.EndPrice >= search.StartPrice) { sql.Append(" AND _p.MinSalePrice <= @EndPrice "); cmd.Parameters.AddWithValue("@EndPrice", search.EndPrice); } #endregion #region 关键词处理 if (!string.IsNullOrEmpty(search.Keyword)) { //分隔关键词 List <string> words = new List <string>(); List <string> ws = _segment.DoSegment(search.Keyword); foreach (string s in ws) { if (!words.Contains(s)) { words.Add(s); } } if (search.Ex_Keyword != null && !string.IsNullOrEmpty(search.Ex_Keyword.Trim()) && search.Ex_Keyword.Trim().Length <= 5) { words.Add(search.Ex_Keyword.Trim()); } else { if (!string.IsNullOrEmpty(search.Ex_Keyword)) { ws = _segment.DoSegment(search.Ex_Keyword); foreach (string s in ws) { if (!words.Contains(s)) { words.Add(s); } } } } //分词搜索 if (words.Count > 0) { MySqlCommand IdCmd = new MySqlCommand(); string sqlWhere = "SELECT Id FROM Himall_Products WHERE ProductName=@ProductName UNION ALL SELECT a.ProductId FROM Himall_ProductWords a INNER JOIN Himall_SegmentWords b ON a.WordId=b.Id WHERE b.Word IN (SELECT WORD FROM ({0}) AS _WordTable) OR MATCH(b.Word) AGAINST(@WordList IN BOOLEAN MODE)"; string wordList = string.Empty; string wordInList = string.Empty; string IdList = string.Empty; for (int i = 0; i < words.Count; i++) { wordList += words[i] + "*,"; wordInList += string.Format("SELECT @word{0} AS WORD {1} ", i.ToString(), (i == words.Count - 1 ? string.Empty : " UNION ALL ")); IdCmd.Parameters.AddWithValue(string.Format("@word{0}", i.ToString()), words[i]); } IdCmd.Parameters.AddWithValue("@WordList", wordList.TrimEnd(new char[] { ',' })); IdCmd.Parameters.AddWithValue("@ProductName", search.Keyword.Trim()); IdCmd.CommandText = string.Format(sqlWhere, wordInList); IdCmd.Connection = connection; if (IdCmd.Connection.State != ConnectionState.Open) { connection.Open(); } MySqlDataReader IdReader = IdCmd.ExecuteReader(); while (IdReader.Read()) { IdList += IdReader["Id"].ToString() + ","; } IdReader.Dispose(); sql.AppendFormat(" AND _p.Id IN ({0})", string.IsNullOrEmpty(IdList) ? "0" : IdList.TrimEnd(new char[] { ',' })); } } #endregion sql.Append(") AS _r ON b.AttributeId=_r.AttributeId AND b.Id=_r.ValueId "); cmd.Connection = connection; if (cmd.Connection.State != ConnectionState.Open) { connection.Open(); } cmd.CommandText = sql.ToString(); MySqlDataReader reader = cmd.ExecuteReader(); AttributeView attr; while (reader.Read()) { bool isfind = true; attr = result.Find(t => t.AttrId == long.Parse(reader["AttrId"].ToString())); if (attr == null)//新属性构造 { isfind = false; attr = new AttributeView(); attr.AttrId = long.Parse(reader["AttrId"].ToString()); attr.Name = reader["Name"].ToString(); } //属性下的值构造 AttributeValue v = new AttributeValue(); v.Id = long.Parse(reader["ValueId"].ToString()); v.Name = reader["Value"].ToString(); if (attr.AttrValues.Find(t => t.Id == v.Id && t.Name == v.Name) == null) { attr.AttrValues.Add(v); } if (!isfind) { result.Add(attr); } } reader.Dispose(); connection.Close(); connection.Dispose(); return(result); }