Exemple #1
0
        /// <summary>
        /// 加载远程桌面配置
        /// </summary>
        private void LoadHostConfig()
        {
            SetWait(true);
            panelBody.Controls.Clear(); //清空原有

            #region 1.0 获取数据
            RemoteHost[] hosts;
            using (var conn = new SQLiteConnection(Common.ConnectionString))
            {
                const string sqlCmd = @"SELECT a.FId,a.FName,a.FConectId,a.FParentId,a.FSort,b.FId,b.FIpAddress,b.FIpPort,b.FLoginUser,b.FPassword,b.FFullUrl
                                    FROM RemoteHost a 
                                    LEFT JOIN ConnectLib b ON a.FConectId=b.FId 
                                    ORDER BY a.FSort ASC,a.FId DESC";
                hosts = conn.Query <RemoteHost, IpAddress, RemoteHost>(sqlCmd, (host, ip) =>
                {
                    host.IpAddress = ip;
                    return(host);
                }, null, null, false, "FId", null, null).ToArray();
            }
            #endregion

            #region 2.0 加载配置信息
            var group = hosts.Where(x => x.FParentId == 0).OrderByDescending(x => x.FSort).ToArray();
            foreach (var hostGroup in group)
            {
                //建立分组
                var hostBox = new WHostGroupBox {
                    Dock = DockStyle.Top, Height = 100, Text = hostGroup.FName
                };
                panelBody.Controls.Add(hostBox); //分组Box
                //填充分组内容
                foreach (var host in hosts.Where(x => x.FParentId == hostGroup.FId).OrderBy(x => x.FSort))
                {
                    var ipInfo = host.IpAddress; //IP地址信息
                    if (ipInfo == null)
                    {
                        continue;
                    }

                    var title = new MetroTile
                    {
                        Name                    = "title",
                        ActiveControl           = null,
                        Height                  = 60,
                        Text                    = string.Format("{0}\r\n  {1}", host.FName, ipInfo.FFullUrl),
                        UseSelectable           = true,
                        UseVisualStyleBackColor = true,
                        Tag              = host,
                        AutoSize         = true,
                        ContextMenuStrip = menuTitle,
                        StyleManager     = metroStyleManager
                    };
                    title.Click     += ConnectRemoteHost;
                    title.MouseDown += menuTitle_Show;
                    hostBox.AddControl(title);
                }
            }
            #endregion

            SetWait(false);
        }
        /// <summary>
        /// 加载远程桌面配置
        /// </summary>
        private void LoadHostConfig()
        {
            SetWait(true);
            panelBody.Controls.Clear(); //清空原有

            #region 1.0 获取数据
            RemoteHost[] hosts;
            using (var conn = new SQLiteConnection(Common.ConnectionString))
            {
                const string sqlCmd = @"SELECT a.FId,a.FName,a.FConectId,a.FParentId,a.FSort,b.FId,b.FIpAddress,b.FIpPort,b.FLoginUser,b.FPassword,b.FFullUrl
                                    FROM RemoteHost a
                                    LEFT JOIN ConnectLib b ON a.FConectId=b.FId
                                    ORDER BY a.FSort ASC,a.FId DESC";
                hosts = conn.Query<RemoteHost, IpAddress, RemoteHost>(sqlCmd, (host, ip) =>
                   {
                       host.IpAddress = ip;
                       return host;
                   }, null, null, false, "FId", null, null).ToArray();
            }
            #endregion

            #region 2.0 加载配置信息
            var group = hosts.Where(x => x.FParentId == 0).OrderByDescending(x => x.FSort).ToArray();
            foreach (var hostGroup in group)
            {
                //建立分组
                var hostBox = new WHostGroupBox { Dock = DockStyle.Top, Height = 100, Text = hostGroup.FName };
                panelBody.Controls.Add(hostBox); //分组Box
                //填充分组内容
                foreach (var host in hosts.Where(x => x.FParentId == hostGroup.FId).OrderBy(x => x.FSort))
                {
                    var ipInfo = host.IpAddress; //IP地址信息
                    if (ipInfo == null) continue;

                    var title = new MetroTile
                    {
                        Name = "title",
                        ActiveControl = null,
                        Height = 60,
                        Text = string.Format("{0}\r\n  {1}", host.FName, ipInfo.FFullUrl),
                        UseSelectable = true,
                        UseVisualStyleBackColor = true,
                        Tag = host,
                        AutoSize = true,
                        ContextMenuStrip = menuTitle,
                        StyleManager = metroStyleManager
                    };
                    title.Click += ConnectRemoteHost;
                    title.MouseDown += menuTitle_Show;
                    hostBox.AddControl(title);
                }
            }
            #endregion

            SetWait(false);
        }