必赢网上注册-亚洲必赢官方登录

认清文件是不是被占用,RMB大写转化

日期:2019-10-04编辑作者:必赢网上注册
using System;namespace Common{ public class RMB { #region 人民币大写转化 /// <summary> /// 转换人民币大小金额 /// </summary> /// <param name="num">金额</param> /// <returns>返回大写形式</returns> public static string CmycurD(decimal num) { string str1 = "零壹贰叁肆伍陆柒捌玖"; //0-9所对应的汉字 string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"; //数字位所对应的汉字 string str3 = ""; //从原num值中取出的值 string str4 = ""; //数字的字符串形式 string str5 = ""; //人民币大写金额形式 int i; //循环变量 int j; //num的值乘以100的字符串长度 string ch1 = ""; //数字的汉语读法 string ch2 = ""; //数字位的汉字读法 int nzero = 0; //用来计算连续的零值是几个 int temp; //从原num值中取出的值 num = Math.Round(Math.Abs; //将num取绝对值并四舍五入取2位小数 str4 = (num * 100)).ToString(); //将num乘100并转换成字符串形式 j = str4.Length; //找出最高位 if (j > 15) { return "溢出"; } str2 = str2.Substring; //取出对应位数的str2的值。如:200.55,j为5所以str2=佰拾元角分 //循环取出每一位需要转换的值 for (i = 0; i < j; i++) { str3 = str4.Substring; //取出需转换的某一位的值 temp = Convert.ToInt32; //转换为数字 if (i !=  && i !=  && i !=  && i !=  { //当所取位数不为元、万、亿、万亿上的数字时 if (str3 == "0") { ch1 = ""; ch2 = ""; nzero = nzero + 1; } else { if (str3 != "0" && nzero != 0) { ch1 = "零" + str1.Substring(temp * 1, 1); ch2 = str2.Substring; nzero = 0; } else { ch1 = str1.Substring(temp * 1, 1); ch2 = str2.Substring; nzero = 0; } } } else { //该位是万亿,亿,万,元位等关键位 if (str3 != "0" && nzero != 0) { ch1 = "零" + str1.Substring(temp * 1, 1); ch2 = str2.Substring; nzero = 0; } else { if (str3 != "0" && nzero == 0) { ch1 = str1.Substring(temp * 1, 1); ch2 = str2.Substring; nzero = 0; } else { if (str3 == "0" && nzero >= 3) { ch1 = ""; ch2 = ""; nzero = nzero + 1; } else { if (j >= 11) { ch1 = ""; nzero = nzero + 1; } else { ch1 = ""; ch2 = str2.Substring; nzero = nzero + 1; } } } } } if (i ==  || i ==  { //如果该位是亿位或元位,则必须写上 ch2 = str2.Substring; } str5 = str5 + ch1 + ch2; if (i == j - 1 && str3 == "0") { //最后一位为0时,加上“整” str5 = str5 + '整'; } } if  { str5 = "零元整"; } return str5; } /**/ /// <summary> /// 一个重载,将字符串先转换成数字在调用CmycurD(decimal num) /// </summary> /// <param name="num">用户输入的金额,字符串形式未转成decimal</param> /// <returns></returns> public static string CmycurD(string numstr) { try { decimal num = Convert.ToDecimal; return CmycurD; } catch { return "非数字形式!"; } } #endregion }}
using System;using System.Net;namespace Common{ public class IP { /// <summary> /// 获取客户端ip地址 /// </summary> /// <returns></returns> public static string GetClientIPv4Address() { string ipv4 = String.Empty; foreach (IPAddress ip in Dns.GetHostAddresses(GetClientIP { if (ip.AddressFamily.ToString() == "InterNetwork") { ipv4 = ip.ToString(); break; } } if (ipv4 != String.Empty) { return ipv4; } // 利用 Dns.GetHostEntry 方法,由获取的 IPv6 位址反查 DNS 纪录, // 再逐一判断何者为 IPv4 协议,即可转为 IPv4 位址。 foreach (IPAddress ip in Dns.GetHostEntry(GetClientIP.AddressList) //foreach (IPAddress ip in Dns.GetHostAddresses(Dns.GetHostName { if (ip.AddressFamily.ToString() == "InterNetwork") { ipv4 = ip.ToString(); break; } } return ipv4; } private static string GetClientIP() { if (null == System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) { if (null == System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"]) { return System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } else { return ""; } } else { return System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } } }}
 #region 判断文件是否被占用 /// <summary> /// 判断文件是否被占用 /// </summary> /// <param name="fileName">文件地址</param> /// <returns>true表示正在使用,false没有使用</returns> public static bool IsFileInUse(string fileName) { bool inUse = true; FileStream fs = null; try { fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None); inUse = false; } catch { } finally { if (fs != null) fs.Close(); } return inUse; } #endregion
using System;using System.IO;using System.Net;using System.Text;namespace Common{ public class Http { #region Get请求 /// <summary> /// HTTP GET方式请求数据. /// </summary> /// <param name="url">URL.</param> /// <returns></returns> public static string HttpGet(string url) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create; request.Method = "GET"; request.Accept = "*/*"; request.Timeout = 15000; request.AllowAutoRedirect = false; WebResponse response = null; string responseStr = null; try { response = request.GetResponse(); if (response != null) { StreamReader reader =new StreamReader(response.GetResponseStream(), Encoding.UTF8); responseStr = reader.ReadToEnd(); reader.Close(); } } catch (Exception) { throw; } finally { request = null; response = null; } return responseStr; } #endregion #region POST请求 /// <summary> /// HTTP POST方式请求数据 /// </summary> /// <param name="url">URL.</param> /// <returns></returns> public static string HttpPost(string url) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "*/*"; request.Timeout = 15000; request.AllowAutoRedirect = false; WebResponse response = null; string responseStr = null; try { response = request.GetResponse(); if (response != null) { StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); responseStr = reader.ReadToEnd(); reader.Close(); } } catch (Exception) { throw; } finally { request = null; response = null; } return responseStr; } /// <summary> /// HTTP POST方式请求数据 /// </summary> /// <param name="url">URL.</param> /// <param name="Data">POST的数据</param> /// <returns></returns> public static string HttpPost(string url, string Data) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; //request.ContentType = "application/json"; request.Accept = "*/*"; request.Timeout = 15000; request.AllowAutoRedirect = false; StreamWriter requestStream = null; WebResponse response = null; string responseStr = null; try { requestStream = new StreamWriter(request.GetRequestStream(), Encoding.UTF8); requestStream.Write; requestStream.Close(); response = request.GetResponse(); if (response != null) { StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); responseStr = reader.ReadToEnd(); // File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath("~//weixin/Weixin/") + @"test.txt", responseStr); reader.Close(); } } catch (Exception) { throw; } finally { request = null; requestStream = null; response = null; } return responseStr; } /// <summary> /// HTTP POST方式请求数据 /// </summary> /// <param name="url">URL.</param> /// <param name="Data">POST的数据</param> /// <param name="type">请求类型(json,xml,param)</param> /// <returns></returns> public static string HttpPost(string url, string Data, string type) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create; request.Method = "POST"; switch  { case "xml": request.ContentType = "text/xml; Charset=utf-8"; break; case "json": request.ContentType = "application/json"; break; default: request.ContentType = "application/x-www-form-urlencoded"; break; } request.Headers.Add("Accept-Language: zh-CN"); request.Accept = "*/*"; request.Timeout = 15000; request.AllowAutoRedirect = false; StreamWriter requestStream = null; WebResponse response = null; string responseStr = null; try { requestStream = new StreamWriter(request.GetRequestStream(), Encoding.UTF8); requestStream.Write; requestStream.Close(); response = request.GetResponse(); if (response != null) { StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); responseStr = reader.ReadToEnd(); reader.Close(); } } catch (Exception) { throw; } finally { request = null; requestStream = null; response = null; } return responseStr; } #endregion }}
using System.IO;using System.Net;using System.Text;namespace Common{ public class Crawler { //爬虫类 /// <summary> /// 根据url爬取网页数据 /// </summary> /// <param name="url"></param> /// <returns></returns> public static string WebTextUrl(string url) { WebRequest request = WebRequest.Create; WebResponse response = request.GetResponse(); //定义一个流来保存获得的内容 Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream, Encoding.UTF8); string text = reader.ReadToEnd(); return text; } }}

本文由必赢网上注册发布于必赢网上注册,转载请注明出处:认清文件是不是被占用,RMB大写转化

关键词: