public ConfigObject CreateNewConfigObject(ConfigObject parentObject, int objType) { try { //检查最大个数限制 //if (!CheckChildObjectMaxinum(parentItem, objType)) { return; } ConfigGroup parentGroup; ResourceTypeParam typeParam = ListAllTypeParams.FirstOrDefault(t => t.TypeID == objType); if (typeParam == null) { return(null); } int parentType = typeParam.ParentID; List <ConfigObject> listConfigObject = ListAllConfigObjects.Where(o => o.ObjectType == objType).OrderBy(o => o.ObjectID).ToList(); long objID = objType * (long)Math.Pow(10, 16) + 1; string strMasterSlaver = "1"; //Key是资源在整个系统中的序号(从零开始),而ID是同一父对象下资源的序号(从零开始) //确定ObjID for (int i = 0; i < listConfigObject.Count; i++) { //如果被占用,递增1 ConfigObject temp = listConfigObject[i]; if (objID == temp.ObjectID) { objID++; } var prop = temp.ListProperties.FirstOrDefault(p => p.PropertyID == S1110Consts.PROPERTYID_MASTERSLAVER); if (prop != null) { if (prop.Value == "1") { strMasterSlaver = "2"; } } } //Key实际上就是ObjID的尾数 int key = (int)(objID - (objType * (long)Math.Pow(10, 16) + 1)); //确定ID int id = 0; //如果类型的父级类型为0,则他的ID与Key一致 if (parentType == 0) { id = key; } else { listConfigObject = parentObject.ListChildObjects.Where(o => o.ObjectType == objType).OrderBy(o => o.ID).ToList(); //遍历同一父对象下该类型的资源 for (int i = 0; i < listConfigObject.Count; i++) { ConfigObject temp = listConfigObject[i]; if (id == temp.ID) { //如果被占用,递增1 id++; } } } ConfigObject configObject = ConfigObject.CreateObject(objType); configObject.ObjectID = objID; configObject.CurrentApp = CurrentApp; configObject.Icon = typeParam.Icon; configObject.TypeParam = typeParam; configObject.ListAllTypeParams = ListAllTypeParams; configObject.ListAllObjects = ListAllConfigObjects; configObject.ListAllBasicInfos = ListAllBasicInfos; List <ObjectPropertyInfo> listPropertyInfos = ListAllPropertyInfos.Where(p => p.ObjType == objType).ToList(); for (int i = 0; i < listPropertyInfos.Count; i++) { ObjectPropertyInfo info = listPropertyInfos[i]; int propertyID = info.PropertyID; ResourceProperty propertyValue = new ResourceProperty(); propertyValue.ObjID = configObject.ObjectID; propertyValue.ObjType = configObject.ObjectType; propertyValue.PropertyID = info.PropertyID; propertyValue.Value = info.DefaultValue; propertyValue.EncryptMode = info.EncryptMode; propertyValue.MultiValueMode = info.MultiValueMode; if (propertyID == S1110Consts.PROPERTYID_KEY) { propertyValue.Value = key.ToString(); } if (propertyID == S1110Consts.PROPERTYID_ID) { propertyValue.Value = id.ToString(); } if (typeParam.ParentID != 0) { if (propertyID == S1110Consts.PROPERTYID_PARENTOBJID) { propertyValue.Value = parentObject.ObjectID.ToString(); } } if (typeParam.IsMasterSlaver) { if (propertyID == S1110Consts.PROPERTYID_MASTERSLAVER) { propertyValue.Value = strMasterSlaver; } } configObject.ListProperties.Add(propertyValue); ListAllPropertyValues.Add(propertyValue); } configObject.GetBasicPropertyValues(); ListAllConfigObjects.Add(configObject); parentObject.ListChildObjects.Add(configObject); #region 写操作日志 //var optID = string.Format("1110{0}06", configObject.ObjectType); //string strOptLog = string.Format("{0}({1})", configObject.Name, // Utils.FormatOptLogString(string.Format("OBJ{0}", configObject.ObjectType))); //App.WriteOperationLog(optID, ConstValue.OPT_RESULT_SUCCESS, strOptLog); #endregion return(configObject); } catch (Exception ex) { CurrentApp.ShowExceptionMessage(ex.Message); return(null); } }
private void AddChannels() { try { if (TxtCount.Value == null) { return; } int intCount = (int)TxtCount.Value; string strExtension = TxtExt.Text; int intExtenstion; int.TryParse(strExtension, out intExtenstion); var baseExtension = ComboBaseExt.SelectedItem as ConfigObject; int objType = S1110Consts.RESOURCE_SCREENCHANNEL; if (ListResourceTypeParams == null) { return; } ResourceTypeParam typeParam = ListResourceTypeParams.FirstOrDefault(t => t.TypeID == objType); if (typeParam == null) { return; } if (ListPropertyInfos == null) { return; } List <ObjectPropertyInfo> listPropertyInfos = ListPropertyInfos.Where(p => p.ObjType == objType).OrderBy(p => p.PropertyID).ToList(); if (ListConfigObjects == null) { return; } if (mParentObject == null) { return; } long parentObjID = mParentObject.ObjectID; //逐一添加 for (int i = 0; i < intCount; i++) { //获取当前所有已经存在的通道 List <ConfigObject> channels = ListConfigObjects.Where(o => o.ObjectType == objType) .OrderBy(o => o.ObjectID) .ToList(); //确定ObjID long objID = objType * (long)Math.Pow(10, 16) + 1; for (int k = 0; k < channels.Count; k++) { if (objID == channels[k].ObjectID) { objID++; } } //确定Key,Key就是ObjID的尾数 int key = (int)(objID - (objType * (long)Math.Pow(10, 16) + 1)); //确定ID //获取当前ScreenServer下的所有通道 List <ConfigObject> channelsInScreen = mParentObject.ListChildObjects.Where(o => o.ObjectType == objType) .OrderBy(o => o.ID) .ToList(); int id = 0; for (int k = 0; k < channelsInScreen.Count; k++) { if (id == channelsInScreen[k].ID) { id++; } } foreach (var channel in channelsInScreen) { if (id == channel.ID) { id++; } } //分机号 string strExt = strExtension; if (intExtenstion > 0) { strExt = (intExtenstion + i).ToString(); } ConfigObject configObject = ConfigObject.CreateObject(objType); configObject.CurrentApp = CurrentApp; configObject.ObjectID = objID; configObject.Icon = typeParam.Icon; configObject.TypeParam = typeParam; configObject.ListAllObjects = ListConfigObjects; configObject.ListAllTypeParams = ListResourceTypeParams; configObject.ListAllBasicInfos = ListAllBasicInfos; for (int j = 0; j < listPropertyInfos.Count; j++) { ObjectPropertyInfo info = listPropertyInfos[j]; int propertyID = info.PropertyID; ResourceProperty propertyValue = new ResourceProperty(); propertyValue.ObjID = configObject.ObjectID; propertyValue.ObjType = configObject.ObjectType; propertyValue.PropertyID = info.PropertyID; //先使用默认属性填充 propertyValue.Value = info.DefaultValue; propertyValue.EncryptMode = info.EncryptMode; //拷贝属性 if (baseExtension != null) { ResourceProperty temp = baseExtension.ListProperties.FirstOrDefault(p => p.PropertyID == propertyID); if (temp != null) { propertyValue.Value = temp.Value; } } //特别的属性重新赋值 if (propertyID == S1110Consts.PROPERTYID_KEY) { propertyValue.Value = key.ToString(); } if (propertyID == S1110Consts.PROPERTYID_ID) { propertyValue.Value = id.ToString(); } if (propertyID == S1110Consts.PROPERTYID_PARENTOBJID) { propertyValue.Value = parentObjID.ToString(); } if (propertyID == 12) { propertyValue.Value = strExt; } configObject.ListProperties.Add(propertyValue); if (ListPropertyValues != null) { ListPropertyValues.Add(propertyValue); } } configObject.Name = string.Format("[{0}] {1}", id.ToString("000"), strExt); configObject.Description = string.Format("[{0}] {1}", id.ToString("000"), strExt); configObject.GetBasicPropertyValues(); mParentObject.ListChildObjects.Add(configObject); ListConfigObjects.Add(configObject); if (MainPage != null) { MainPage.CreateNewChannelConfigObjectItem(ParentItem, configObject); } } #region 写操作日志 var optID = string.Format("1110{0}06", objType); string strOptLog = string.Format("{0}:{1}", Utils.FormatOptLogString("1110202"), intCount); CurrentApp.WriteOperationLog(optID, ConstValue.OPT_RESULT_SUCCESS, strOptLog); #endregion if (MainPage != null) { MainPage.CreateChildObjectList(); } var parent = Parent as PopupPanel; if (parent != null) { parent.IsOpen = false; } } catch (Exception ex) { ShowException(ex.Message); } }
private void LoadChildObjects() { try { mListChildObjects.Clear(); if (ListConfigObjects == null) { return; } if (ObjectItem == null) { return; } ConfigGroup configGroup = ObjectItem.Data as ConfigGroup; if (configGroup == null) { return; } ConfigObject = configGroup.ConfigObject; if (ConfigObject == null) { return; } int childType = configGroup.ChildType; long parentID = 0; if (ListResourceTypeParams != null) { ResourceTypeParam typeParam = ListResourceTypeParams.FirstOrDefault(t => t.TypeID == childType); if (typeParam != null) { if (typeParam.ParentID > 0) { parentID = ConfigObject.ObjectID; } } } List <ConfigObject> listChildObjects; if (parentID != 0) { listChildObjects = ListConfigObjects.Where(o => o.ObjectType == configGroup.ChildType && o.ParentID == parentID) .ToList(); } else { listChildObjects = ListConfigObjects.Where(o => o.ObjectType == configGroup.ChildType) .ToList(); } for (int i = 0; i < listChildObjects.Count; i++) { ConfigObject child = listChildObjects[i]; ChildObjectItem item = new ChildObjectItem(); item.ObjID = child.ObjectID; item.Key = child.ID; item.Name = child.Name; item.Description = child.Description; item.Icon = string.Format("Images/{0}", child.Icon); item.ConfigObject = child; if ((i % 2) == 1) { item.Background = Brushes.LightGray; } mListChildObjects.Add(item); } } catch (Exception ex) { App.ShowExceptionMessage(ex.Message); } }