示例#1
0
 /// <summary>
 /// Gets a service by its numeric id.
 /// </summary>
 /// <returns>The service.</returns>
 /// <param name="serviceID">Service ID</param>
 protected Service GetServiceById(int serviceID)
 {
     if (ModelLookup.ContainsKey(serviceID))
     {
         if (ModelLookup [serviceID].GetSettings() == null)
         {
             throw new ControlException(ControlException.Cause.Uninitialized, serviceID.ToString());
         }
         else
         {
             return(ModelLookup [serviceID]);
         }
     }
     else
     {
         throw new ControlException(ControlException.Cause.NoService, serviceID.ToString());
     }
 }
示例#2
0
        protected void BindModelDdl(string make, string model, string other)
        {
            List <ModelLookup> models = ModelLookup.GetAllModelsLookup(make);

            DdlModel.DataSource = models;
            DdlModel.DataBind();
            if (model != "")
            {
                if (models.Select(m => m.Model).ToString() == model)
                {
                    DdlModel.SelectedValue = model;
                }
                if (model == "Other")
                {
                    RfvModelOther.Enabled = true;
                    RfvModelOther.Visible = true;
                    TxtModelOther.Enabled = true;
                    TxtModelOther.Visible = true;
                    TxtModelOther.Text    = other;
                }
            }
        }
示例#3
0
        /// <summary>
        /// 构建模块树
        /// </summary>
        /// <param name="instanceKey"></param>
        /// <param name="models"></param>
        /// <returns></returns>
        private static ModelLookup CreateModelTree(string instanceKey, IList <Model> models)
        {
            if (models.Count == 0)
            {
                return(null);
            }

            var lookup = new ModelLookup {
                InstanceKey = instanceKey
            };

            foreach (var model in models)
            {
                model.Childs.Clear();
                lookup.ModelDictionary.Add(model.Key, model);
            }

            foreach (var model in models)
            {
                //如果是根模块
                if (model.ParentKey == -1)
                {
                    lookup.Root = model;
                }
                else
                {
                    var parent = lookup.ModelDictionary.TryGetValue(model.ParentKey);
                    if (parent != null)
                    {
                        model.ParentKey = parent.ParentKey;
                        int childCount = parent.Childs.Count;
                        if (childCount == 0)
                        {
                            parent.Childs.Add(model);
                        }
                        if (childCount == 1)
                        {
                            if (model.SortNumber < parent.Childs[0].SortNumber)
                            {
                                parent.Childs.Insert(0, model);
                            }
                            else
                            {
                                parent.Childs.Add(model);
                            }
                        }

                        for (int i = 1; i < childCount; i++)
                        {
                            if (model.SortNumber < parent.Childs[0].SortNumber)
                            {
                                parent.Childs.Insert(0, model);
                                break;
                            }
                            if (model.SortNumber > parent.Childs[childCount - 1].SortNumber)
                            {
                                parent.Childs.Add(model);
                                break;
                            }
                            if (parent.Childs[i - 1].SortNumber <= model.SortNumber &&
                                parent.Childs[i].SortNumber > model.SortNumber)
                            {
                                parent.Childs.Insert(i, model);
                                break;
                            }
                        }
                    }
                }
            }
            return(lookup);
        }