基础公用函数(整理中)

来源:互联网 发布:我国域名管理机构 编辑:程序博客网 时间:2024/05/17 09:31

//换行
        public string GetLength(string str)
        {
            string s = "";
            string s2 = "";
            if (str.Length > 40)
            {
                int j = str.Length / 40 + 1;
                int z = str.Length % 40;
                int o = j - 1;
                for (int i = 0; i < j; i++)
                {
                    if (i == j - 1)
                    {
                        s2 = s2 + str.Substring(o * 40, z);

                    }
                    else
                    {
                        int l = i * 40;
                        s = str.Substring(l, 40);
                        s2 = s2 + s + "<br/>";

                    }

                }
                return s2;
            }
            else
            {
                return str;
            }
        }


  /// <summary>
        /// 半角(DBC case)转全角(SBC case)
        /// </summary>
        /// <param name="source">被转换的半角字符串</param>
        /// <returns>转换后的全角字符串</returns>
        static string DBC2SBC(string source)
        {
            //袁晓辉(http://blog.csdn.net/uoyevoli) 整理
            byte[] bytes = Encoding.Unicode.GetBytes(source);
            for (int i = 0; i < bytes.Length; i += 2)
            {
                if (bytes[i + 1] == 0)
                {
                    bytes[i] -= 32;
                    bytes[i + 1] = 255;
                }
            }
            return new string(Encoding.Unicode.GetChars(bytes));
        }

 

// Helper routine that logs SqlException details to the
// Application event log
private void LogException( SqlException sqlex )
{
  EventLog el = new EventLog();
  el.Source = "CustomAppLog";
  string strMessage;
  strMessage = "Exception Number : " + sqlex.Number +
               "(" + sqlex.Message + ") has occurred";
  el.WriteEntry( strMessage );

  foreach (SqlError sqle in sqlex.Errors)
  {
    strMessage = "Message: " + sqle.Message +
                 " Number: " + sqle.Number +
                 " Procedure: " + sqle.Procedure +
                 " Server: " + sqle.Server +
                 " Source: " + sqle.Source +
                 " State: " + sqle.State +
                 " Severity: " + sqle.Class +
                 " LineNumber: " + sqle.LineNumber;
    el.WriteEntry( strMessage );
  }

 

原创粉丝点击