コード例 #1
0
 public static NmsInfo GetInstance()
 {
     if (instance == null)
     {
         instance = new NmsInfo();
     }
     return(instance);
 }
コード例 #2
0
 public int GetNewLocation()
 {
     try
     {
         Location = NmsInfo.GetInstance().serverList.Max(x => x.Location) + 1;
     }
     catch
     {
         Location = 0;
     }
     return(Location);
 }
コード例 #3
0
        public static List <Group> GetGroupList()
        {
            DataTable dt    = new DataTable();
            string    query = "SELECT G.* FROM grp G ORDER BY G.create_time";

            using (MySqlConnection conn = new MySqlConnection(DatabaseManager.getInstance().ConnectionString))
            {
                conn.Open();

                /*
                 * MySqlCommand cmd = new MySqlCommand(query, conn);
                 * cmd.Prepare();
                 */
                MySqlDataAdapter adpt = new MySqlDataAdapter(query, conn);
                adpt.Fill(dt);
            }

            List <Group> groups = dt.AsEnumerable().Select(row => new Group
            {
                Id   = row.Field <string>("id"),
                Name = row.Field <string>("name")
            }).ToList();

            foreach (Group g in groups)
            {
                if (g.Servers == null)
                {
                    g.Servers = new ObservableCollection <Server>();
                }
            }

            foreach (Server s in NmsInfo.GetInstance().serverList)
            {
                foreach (Group g in groups)
                {
                    if (s.Gid == g.Id)
                    {
                        g.Servers.Add(s);
                    }
                }
            }

            return(groups);
        }