Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //very similar as hashtable
            //sorted list has two arrays behind it, keys and values,  keys is sorted so that values is to
            System.Collections.SortedList table = new System.Collections.SortedList();
            table["Ryan"] = 22;
            table["Mike"] = 25;
            table["Josh"] = 15;

            Console.WriteLine("Ryan is found at index {0}", table.IndexOfKey("Ryan"));
            Console.WriteLine("Mike is found at index {0}", table.IndexOfKey("Mike"));
            Console.WriteLine("Josh is found at index {0}", table.IndexOfKey("Josh"));

            Console.WriteLine("Ryan is {0} years old", table["Ryan"]);
            Console.WriteLine("ContainsKey foo? {0}", table.ContainsKey("foo"));
            Console.WriteLine("ContainsKey Ryan? {0}", table.ContainsKey("Ryan"));
        }
 internal void setDBTag(int _station, int _address, short _datatype, object _value)
 {
     lock ( lockobject )
     {
         int curIdx = allCreatedTags.IndexOfKey(HashIndex(_station, _address, _datatype));
         if (curIdx < 0)
         {
             allCreatedTags.Add
                 (HashIndex(_station, _address, _datatype),
                 _value
                 );
         }
         else
         {
             allCreatedTags.SetByIndex(curIdx, _value);
         }
     }
 }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                string personCode = CurrentUserInfo.Personcode;
                string companyId = CurrentUserInfo.CompanyId;
                string module_Code = this.Request.QueryString["ModuleCode"].ToString();
                ModuleCode.Value = module_Code;
                dt = hrmDepartmentBll.getOrgTree(personCode, companyId, module_Code);
                //=================加載樹=================
                this.UltraWebTreeData.Nodes.Clear();
                System.Collections.SortedList allTreeNodes = new System.Collections.SortedList();
                Color foreColor;
                string strDeleted = "";
                foreach (System.Data.DataRow row in dt.Rows)
                {
                    switch (row["levelcode"].ToString())
                    {
                        case "0":
                            foreColor = Color.Blue;
                            break;
                        case "1":
                            foreColor = Color.Maroon;
                            break;
                        case "2":
                            foreColor = Color.SaddleBrown;
                            break;
                        case "3":
                            foreColor = Color.Red;
                            break;
                        default:
                            foreColor = Color.Black;
                            break;
                    }
                    if (row["Deleted"].ToString() == "Y")
                    {
                        foreColor = Color.DarkGray;
                        strDeleted = "[Disabled]";
                    }
                    else
                    {
                        strDeleted = "";
                    }
                    allTreeNodes.Add(System.Convert.ToString(row["depcode"]), base.CreateNode(System.Convert.ToString(row["depcode"]), System.Convert.ToString(row["depname"]) + "[" + System.Convert.ToString(row["depcode"]) + "]" + strDeleted, false,
                        System.Convert.ToDecimal(dt.Compute("count(depcode)", "parentdepcode='" + row["depcode"] + "'")) == 0, foreColor));

                    if (row["parentdepcode"].ToString().Trim().Length > 0)
                    {
                        if (allTreeNodes.IndexOfKey(row["parentdepcode"]) >= 0)
                        {
                            ((Infragistics.WebUI.UltraWebNavigator.Node)allTreeNodes.GetByIndex(allTreeNodes.IndexOfKey(row["parentdepcode"]))).Nodes.Add((Infragistics.WebUI.UltraWebNavigator.Node)allTreeNodes.GetByIndex(allTreeNodes.IndexOfKey(row["depcode"])));
                        }
                        else
                        {
                            this.UltraWebTreeData.Nodes.Add((Infragistics.WebUI.UltraWebNavigator.Node)allTreeNodes.GetByIndex(allTreeNodes.IndexOfKey(System.Convert.ToString(row["depcode"]))));
                        }
                    }
                    else
                    {
                        this.UltraWebTreeData.Nodes.Add((Infragistics.WebUI.UltraWebNavigator.Node)allTreeNodes.GetByIndex(allTreeNodes.IndexOfKey(System.Convert.ToString(row["depcode"]))));
                    }
                }
                //=================加載完成=================
                foreach (Node node in this.UltraWebTreeData.Nodes)
                {
                    node.Expand(false);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// renew all guids of xmlString
        /// </summary>
        /// <param name="xmlString"></param>
        /// <returns></returns>
        public string RefreshAllGuids(ref string xmlString)
        {
            System.Xml.XmlDocumentFragment fragdoc = xmlDoc.CreateDocumentFragment();
            fragdoc.InnerXml = xmlString;

            System.Collections.IEnumerator ie       = fragdoc.ChildNodes.GetEnumerator();
            System.Collections.SortedList  listGUID = new System.Collections.SortedList();

            string strFirstGUID = null;

            xmlString = "";
            while (ie.MoveNext())
            {
                System.Xml.XmlNode node = (System.Xml.XmlNode)ie.Current;

                string OldGUID    = GetAttributeByName(node, PazDocumentLegacy.TAG_GUID);
                string NewGUID    = Guid.NewGuid().ToString();
                string ParentGUID = GetAttributeByName(node, PazDocumentLegacy.TAG_PARENTGUID);

                if (strFirstGUID == null)
                {
                    strFirstGUID = NewGUID;
                }

                listGUID.Add(OldGUID, NewGUID);

                if (listGUID.Contains(ParentGUID))
                {
                    SetAttributeByName(node, PazDocumentLegacy.TAG_PARENTGUID, (string)listGUID.GetByIndex(listGUID.IndexOfKey(ParentGUID)));
                }

                SetAttributeByName(node, PazDocumentLegacy.TAG_GUID, NewGUID);
                SetAttributeByName(node, PazDocumentLegacy.TAG_TIMESTAMP, DateTime.Now.Ticks.ToString());
                xmlString += node.OuterXml;
            }

            return(strFirstGUID);
        }