Skip to content

Instantly share code, notes, and snippets.

View greatcodeeer's full-sized avatar

codeeer greatcodeeer

View GitHub Profile
@greatcodeeer
greatcodeeer / gist:3fe5b7334702ca885054
Created January 30, 2015 18:01
Android 获取网络状态
/**
* 网络工具类
*/
public class NetworkUtil {
public static String NETWORK_TYPE_WIFI = "WIFI";
public static String NETWORK_TYPE_MOBILE = "MOBILE";
public static String NETWORK_TYPE_ERROR = "ERROR";
/**
* 返回网络是否可用
@greatcodeeer
greatcodeeer / ChinaDate.class
Last active September 14, 2023 14:52
C# 计算农历日期
public static class ChinaDate
{
private static ChineseLunisolarCalendar china = new ChineseLunisolarCalendar();
private static Hashtable gHoliday = new Hashtable();
private static Hashtable nHoliday = new Hashtable();
private static string[] JQ = { "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至" };
private static int[] JQData = { 0, 21208, 43467, 63836, 85337, 107014, 128867, 150921, 173149, 195551, 218072, 240693, 263343, 285989, 308563, 331033, 353350, 375494, 397447, 419210, 440795, 462224, 483532, 504758 };
static ChinaDate()
{
@greatcodeeer
greatcodeeer / gist:2d5f699c87b4b2bbcaae
Last active August 16, 2020 09:55
C# 操作配置文件 app.config
//工程里添加对system.configuration.dll程序集的引用
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
cfa.AppSettings.Settings.Add("key", "Name");//添加节点
cfa.AppSettings.Settings["key"].Value = "name";//设置节点(如果节点为空,会抛出异常)
cfa.Save(); //关键的一步!保存修改。
string ConString = System.Configuration.ConfigurationSettings.AppSettings["key"];//读取节点
@greatcodeeer
greatcodeeer / gist:342b0e7f9d063b37cfd9
Last active August 16, 2020 09:56
C# GUID的使用
Guid.NewGuid().ToString("N") //结果为:38bddf48f43c48588e0d78761eaa1ce6
Guid.NewGuid().ToString("D") //结果为:57d99d89-caab-482a-a0e9-a0a803eed3ba
Guid.NewGuid().ToString("B") //结果为:{09f140d5-af72-44ba-a763-c861304b46f8}
Guid.NewGuid().ToString("P") //结果为:(778406c2-efff-4262-ab03-70a77d09c2b5)
@greatcodeeer
greatcodeeer / Class
Last active August 16, 2020 09:56
C# 遍历目录
public class FileDirectoryEnumerator : System.Collections.IEnumerator
{
#region 表示对象当前状态的数据和属性
/// <summary>
/// 当前对象
/// </summary>
private object objCurrentObject = null;
@greatcodeeer
greatcodeeer / gist:3affd8d88192dff54fe3
Last active August 16, 2020 09:56
C# 通过资源管理器(explorer)打开文件并定位
//FilePath 为文件路径
Process.Start("explorer.exe ", @"/select,""" + FilePath + @"""");
@greatcodeeer
greatcodeeer / 获取网页源码
Last active August 16, 2020 09:57
C# 获取网页源码
/// <summary>
/// 获取网页源码
/// </summary>
/// <param name="Url">链接</param>
/// <param name="CharSet">编码</param>
/// <returns></returns>
public static string GetSource(string Url, string CharSet = "GB2312")
{
using (WebClient myWebClient = new WebClient())
{
@greatcodeeer
greatcodeeer / 多线程
Last active August 16, 2020 09:57
C# 多线程 线程池
/*
* Go_TEST为测试样例
* Go_Core为线程核心执行代码
*
* 正在运行的线程数量:RunningThreadNumbers
* 暂停线程:Thread_Statu_Pause = checkBox1.Checked;
* 暂停取消:Thread_Statu_Exit = true;
* 提取线程(标识符GUID为[textBox2.Text]值)返回值
* for (int i = 0; i < ThreadNodeS_Pool.Count; i++)
{
@greatcodeeer
greatcodeeer / 热键 Alt
Last active August 16, 2020 09:57
C# 绑定仅程序内有效的热键
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if ((Keys.Alt & keyData) == Keys.Alt) MessageBox.Show("1");
return base.ProcessCmdKey(ref msg, keyData);
}
@greatcodeeer
greatcodeeer / gist:d2c41173e0e580adbbb4
Last active August 16, 2020 09:57
C# 检测是否已经安装Winrar
static public bool ExistsWINRAR()
{
try
{
RegistryKey the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Win11RAR.exe");
return !string.IsNullOrEmpty(the_Reg.GetValue("").ToString());
}
catch
{
return false;