zoukankan      html  css  js  c++  java
  • 是否联网以及热点问题

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Net.NetworkInformation;
    using System.Runtime.InteropServices;
    using Microsoft.Win32;

    namespace DCWriterTasks
    {
    public partial class Form1 : Form
    {
    #region Initionalization
    public Form1()
    {
    InitializeComponent();
    }
    #endregion

    #region Methods
    //使用System.Net.NetworkInformation下的Ping以及PingReply判断网络
    /// <summary>
    /// 判断是否有网络
    /// </summary>
    /// <returns></returns>
    public bool OnlineOrNot()
    {
    bool resultoOnlineOrNot = false;
    Ping ping = new Ping();
    PingReply pingReply;
    //向百度ping看看,能否ping通,通了有网络,否则无网络
    //pingReply = ping.Send("202.108.22.5");
    pingReply = ping.Send("www.baidu.com");
    //pingReply = ping.Send("http://www.dcwriter.cn/html/Template/DCWriter.html");
    if (pingReply.Status == IPStatus.Success)
    {
    resultoOnlineOrNot = true;
    return resultoOnlineOrNot;
    }
    return resultoOnlineOrNot;

    }

    //使用System.Runtime.InteropServices调用wininet中的 InternetGetConnectedState API判断网络
    //判断internet的网络连接状态
    [DllImport("wininet", EntryPoint = "InternetGetConnectedState")]
    private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);

    /// <summary>
    /// 判断是否有网络
    /// </summary>
    /// <returns></returns>
    public bool OnlineOrNot1()
    {

    bool resultoOnlineOrNot = false;
    int i = 0;
    if (InternetGetConnectedState(out i, 0))
    {
    resultoOnlineOrNot = true;
    return resultoOnlineOrNot;
    }
    return resultoOnlineOrNot;
    }

    /// <summary>
    /// 访问Access 数据库
    /// </summary>
    /// <param name="access"></param>
    /// <returns></returns>
    public bool AccessExistOrNot(string access)
    {
    using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SoftwareMicrosoftWindowsCurrentVersionUninstall", false))
    {
    if (key != null)//判断对象存在
    {
    foreach (string keyName in key.GetSubKeyNames())//遍历子项名称的字符串数组
    {
    using (RegistryKey key2 = key.OpenSubKey(keyName, false))//遍历子项节点
    {
    if (key2 != null)
    {
    string softwareName = key2.GetValue("DisplayName", "").ToString();//获取软件名
    if (softwareName.IndexOf(access) > -1)
    {
    //string installLocation = key2.GetValue("InstallLocation", "").ToString();//获取安装路径
    return true;
    }
    }
    }
    }
    }
    }
    return false;
    }

    #endregion

    #region Events
    /// <summary>
    /// 打开模板浏览器
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void tsbModeBroser_Click(object sender, EventArgs e)
    {
    bool onlineOrNot = false;
    onlineOrNot = OnlineOrNot1();
    if (onlineOrNot)
    {
    myWebBrowser.Navigate("http://www.dcwriter.cn/html/Template/DCWriter.html");
    }
    else
    {
    myWebBrowser.Navigate("about:blank");
    }
    }

    /// <summary>
    /// 打开地图热点
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void tsbMapHot_Click(object sender, EventArgs e)
    {
    bool onlineOrNot = false;
    onlineOrNot = OnlineOrNot1();
    if (onlineOrNot)
    {
    myWebBrowser.Navigate("http://www.dcwriter.cn/CustomerCase/DCWriterCustomerCase.HTML");
    }
    else
    {
    if (MessageBox.Show("对不起无网络!是否使用本地文件?", "友情提示:", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
    {
    myWebBrowser.Navigate(System.IO.Path.Combine(Application.StartupPath, "本地地图.png"));
    }
    else
    {
    myWebBrowser.Navigate("about:blank");
    }
    }
    }

    private void tsbAccessClient_Click(object sender, EventArgs e)
    {
    //System.Net.WebClient myWebClient = new System.Net.WebClient();
    ////Uri uri = new Uri("ftp://ygdy8:ygdy8@y219.dydytt.net:9066/[阳光电影www.ygdy8.com].叶问3.BD.720p.国粤双语中字.mkv");
    //Uri uri = new Uri("http://192.168.0.100:8080");
    //myWebClient.DownloadFileAsync(uri, System.IO.Path.Combine(Application.StartupPath, "哈哈"));
    bool accessExistOrNot = AccessExistOrNot("Access");
    if (accessExistOrNot)
    {
    //访问Access 数据库
    //if (MessageBox.Show("Access 数据库不存在,是否访问本地文件?", "信息提示:", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
    //{
    //}
    }
    else
    {
    //访问本地文件
    }
    }
    #endregion

    }
    }

  • 相关阅读:
    死磕 java线程系列之自己动手写一个线程池(续)
    Spring Boot (十): Spring Boot Admin 监控 Spring Boot 应用
    opencv之为图像添加边界
    协作,才能更好的中断线程
    Java并发——线程池Executor框架
    神经网络dropout
    xgboost
    物体检测-毕业设计项目回顾
    计算机网络-TCP连接
    gbdt推导和代码
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/5292673.html
Copyright © 2011-2022 走看看