public static void ReloadPinYinFile() { try { pinyinList = ReadPinYin(); } catch (Exception ex) { LogText.LogWrite("重新加载拼音文件出错,错误信息:" + ex.Message, "PinYinErr"); } }
//通过汉字编码取得汉字 public static string GetHanZi(byte[] ChineseBuf) { string tmpbuf = ""; try { for (int i = 0; i < ChineseBuf.Length; i++) { if (tmpbuf == "") { tmpbuf = GetStringFromByte(ChineseBuf[i]); } else { tmpbuf += " " + GetStringFromByte(ChineseBuf[i]); } } if (pinyinList == null) { pinyinList = ReadPinYin(); } //先从汉字配置文件中查找是否存在,如果不存在则继续下面的流程 string tmpstr = ""; for (int i = 0; i < pinyinList.Count; i++) { tmpstr = pinyinList[i]; if (tmpstr.ToUpper().IndexOf(tmpbuf) != -1) { string[] sl = tmpstr.Split(new char[1] { ' ' }); return(sl[0]); } } } catch (Exception ex) { LogText.LogWrite("汉字编码转换成对应汉字,错误信息:" + ex.Message, "PinYinErr"); } return(""); }
/// <summary> /// 根据汉字获取汉字拼音及汉字编码 /// </summary> /// <param name="chrstr">汉字</param> /// <param name="ChineseBuf">汉字编码</param> /// <returns>汉字的拼音</returns> public static string convert(string chrstr, out byte[] ChineseBuf) { byte[] array = new byte[2]; string returnstr = ""; int chrasc = 0; int i1 = 0; int i2 = 0; ChineseBuf = null; try { if (pinyinList == null) { pinyinList = ReadPinYin(); } //先从汉字配置文件中查找是否存在,如果不存在则继续下面的流程 string tmpstr = ""; for (int i = 0; i < pinyinList.Count; i++) { tmpstr = pinyinList[i]; if (tmpstr.IndexOf(chrstr) != -1) { string[] sl = tmpstr.Trim().Split(new char[1] { ' ' }); int count = 0; string strReturn = ""; for (int j = 0; j < sl.Length; j++) { if (sl[j].Trim() == "") { continue; } switch (count) { //汉字 case 0: break; //拼音 case 1: strReturn = sl[j]; break; } count++; if (sl.Length == 4) { if (ChineseBuf == null) { ChineseBuf = new byte[2]; } ChineseBuf[0] = GetByteFromString(sl[2]); ChineseBuf[1] = GetByteFromString(sl[3]); } else if (sl.Length > 4) { if (ChineseBuf == null) { ChineseBuf = new byte[4]; } ChineseBuf[0] = GetByteFromString(sl[2]); ChineseBuf[1] = GetByteFromString(sl[3]); ChineseBuf[2] = GetByteFromString(sl[4]); ChineseBuf[3] = GetByteFromString(sl[5]); } } return(strReturn); } } char[] nowchar = chrstr.ToCharArray(); for (int j = 0; j < nowchar.Length; j++) { array = System.Text.Encoding.Default.GetBytes(nowchar[j].ToString()); i1 = (short)(array[0]); i2 = (short)(array[1]); chrasc = i1 * 256 + i2 - 65536; if (chrasc > 0 && chrasc < 160) { returnstr += nowchar[j]; } else { for (int i = (pyvalue.Length - 1); i >= 0; i--) { if (pyvalue[i] <= chrasc) { returnstr += pystr[i]; break; } } } } } catch (Exception ex) { LogText.LogWrite("根据汉字获取汉字拼音及汉字编码,错误信息:" + ex.Message, "PinYinErr"); } return(returnstr); }
/// <summary> /// 记录一个实体中的所有基本数据 key=value /// </summary> /// <param name="strDesc">实体说明</param> /// <param name="model">实体对象</param> /// <param name="dir">子目录 没有可为空</param> public static string LogWrite(string strDesc, T model, string dir) { StringBuilder sbLog = new StringBuilder(); try { sbLog.AppendFormat("【时间:{0}】=======================================================\r\n", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); if (!string.IsNullOrEmpty(strDesc)) { sbLog.AppendFormat("\r\n{0}:\r\n", strDesc); } List <string> PropertyList = new List <string>(); Type t = model.GetType(); if (t.FullName == "System.Data.DataTable") { DataTable table = model as DataTable; if (table != null && table.Rows.Count > 0) { DataRowCollection rcs = table.Rows; DataColumnCollection dcs = table.Columns; int i = 0; foreach (DataRow dr in rcs) { i++; PropertyList.Add("表名:" + table.TableName + "" + "第" + i + "行数据:\r\n"); StringBuilder sbRowData = new StringBuilder(); object obj = null; foreach (DataColumn dc in dcs) { obj = dr[dc.ColumnName] == DBNull.Value ? "null" : dr[dc.ColumnName].ToString(); sbRowData.Append(dc.ColumnName + "=" + obj + "\r\n"); } PropertyList.Add(sbRowData.ToString()); } } } else if (t.FullName == "System.Data.DataSet") { DataSet ds = model as DataSet; if (ds != null && ds.Tables.Count > 0) { foreach (DataTable table in ds.Tables) { if (table != null && table.Rows.Count > 0) { DataRowCollection rcs = table.Rows; DataColumnCollection dcs = table.Columns; int i = 0; foreach (DataRow dr in rcs) { i++; PropertyList.Add("表名:" + table.TableName + "" + "第" + i + "行数据:\r\n"); StringBuilder sbRowData = new StringBuilder(); object obj = null; foreach (DataColumn dc in dcs) { obj = dr[dc.ColumnName] == DBNull.Value ? "null" : dr[dc.ColumnName].ToString(); sbRowData.Append(dc.ColumnName + "=" + obj + "\r\n"); } PropertyList.Add(sbRowData.ToString()); } } } } } else { PropertyInfo[] properties = t.GetProperties(BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetProperty); object obj = null; foreach (PropertyInfo p in properties) { obj = p.GetValue(model, null); PropertyList.Add(p.Name + "=" + (obj == null ? "null" : obj)); } } if (PropertyList.Count > 0) { sbLog.Append(string.Join("\r\n", PropertyList.ToArray())); } sbLog.Append("结束=======================================================\r\n"); //记录日志 LogText.LogWrite(sbLog.ToString(), dir); } catch (Exception) { } finally { } return(sbLog.ToString()); }