随笔 - 13, 文章 - 0, 评论 - 1, 引用 - 0
数据加载中……

2013年6月3日

加密解密

using System;
using System.Collections.Generic;
using System.Web;
using System.Security.Cryptography;
using System.Text;
using System.IO;

/// <summary>
///Encrypt 的摘要说明
/// </summary>
public class Encrypt
{


    //cookies加密密钥  
    public static string DES_Key = "12345678";

    #region DESEnCode DES加密
    /// <summary>
    /// 加密
    /// </summary>
    /// <param name="pToEncrypt"></param>
    /// <returns></returns>
    public static string DESEnCode(string pToEncrypt)
    {
        pToEncrypt = HttpContext.Current.Server.UrlEncode(pToEncrypt);
        DESCryptoServiceProvider des = new DESCryptoServiceProvider();
        byte[] inputByteArray = Encoding.GetEncoding("UTF-8").GetBytes(pToEncrypt);


        des.Key = ASCIIEncoding.ASCII.GetBytes(DES_Key);
        des.IV = ASCIIEncoding.ASCII.GetBytes(DES_Key);
        MemoryStream ms = new MemoryStream();
        CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);

        cs.Write(inputByteArray, 0, inputByteArray.Length);
        cs.FlushFinalBlock();

        StringBuilder ret = new StringBuilder();
        foreach (byte b in ms.ToArray())
        {
            ret.AppendFormat("{0:X2}", b);
        }
        ret.ToString();
        return ret.ToString();
    }
    #endregion

    #region DESDeCode DES解密
    /// <summary>
    /// 解密
    /// </summary>
    /// <param name="pToDecrypt"></param>
    /// <returns></returns>
    public static string DESDeCode(string pToDecrypt)
    {
        try
        {
            //    HttpContext.Current.Response.Write(pToDecrypt + "<br>" + sKey);  
            //    HttpContext.Current.Response.End();  
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();

            byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
            for (int x = 0; x < pToDecrypt.Length / 2; x++)
            {
                int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
                inputByteArray[x] = (byte)i;
            }

            des.Key = ASCIIEncoding.ASCII.GetBytes(DES_Key);
            des.IV = ASCIIEncoding.ASCII.GetBytes(DES_Key);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();

            StringBuilder ret = new StringBuilder();

            return HttpContext.Current.Server.UrlDecode(System.Text.Encoding.Default.GetString(ms.ToArray()));
        }
        catch (Exception)
        {

            return "";
        }

    }
    #endregion

 

 

 

 

 

}

posted @ 2013-06-03 11:33 李鑫 阅读(364) | 评论 (0)编辑 收藏

2013年5月20日

判断txet.Text是否为数字

private bool IsAccept()   
{       
    try
    {
        Decimal.Parse(txt1.Text);
        return true; <---这里要加一句
    }
    catch
    {
        MessageBox.Show("必须为数字!");  
        return false;
    }
}

posted @ 2013-05-20 08:54 李鑫 阅读(102) | 评论 (0)编辑 收藏

2013年2月4日

创建编码(保证不重复创建)

CREATE OR REPLACE Function GetFtpSeqNO(riqi    in Varchar2,
                                       JiaoYLX in Varchar2) return Varchar2 is
  pragma autonomous_transaction;
  MaxBianH Varchar2(50);
begin
  Lock Table MTJY_BianHTable In Exclusive Mode;
  select MAX(ShangPBH)
    into MaxBianH
    from MTJY_BianHTable
   where substr(Charshj, 1, 10) = riqi
     and leix = JiaoYLX;

  if MaxBianH is null then
    case
      when JiaoYLX = 'N' then
        MaxBianH := 'CONT' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
      when JiaoYLX = 'S' then
        MaxBianH := 'SETT' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
      when JiaoYLX = 'C' then
        MaxBianH := 'COMP' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
      when JiaoYLX = 'X' then
        MaxBianH := 'ORDER' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
      when JiaoYLX = 'Y' then
        MaxBianH := 'FLWUP' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
      when JiaoYLX = 'HBHK' then
        MaxBianH := 'HBHK' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
      when JiaoYLX = 'YJFL' then
        MaxBianH := 'YJFL' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
      when JiaoYLX = 'TB' then
        MaxBianH := 'TB' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
      when JiaoYLX = 'QR' then
        MaxBianH := 'QR' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
      when JiaoYLX = 'PZ' then
        MaxBianH := 'PZ' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
      when JiaoYLX = 'ZJMMXG' then
        MaxBianH := 'ZJMMXG' ||
                    to_char(to_date(riqi, 'yyyy-MM-dd'), 'yyyyMMdd') ||
                    '00001';
    end case;else
    case
      when JiaoYLX = 'N' then
        MaxBianH := 'CONT' ||
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  5,
                                                  13)) + 1,
                                 '0000000000000'));
      when JiaoYLX = 'S' then
        MaxBianH := 'SETT' ||
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  5,
                                                  13)) + 1,
                                 '0000000000000'));
      when JiaoYLX = 'C' then
        MaxBianH := 'COMP' ||
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  5,
                                                  13)) + 1,
                                 '0000000000000'));
      when JiaoYLX = 'X' then
        MaxBianH := 'ORDER' ||
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  6,
                                                  13)) + 1,
                                 '0000000000000'));
      when JiaoYLX = 'Y' then
        MaxBianH := 'FLWUP' ||
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  6,
                                                  13)) + 1,
                                 '0000000000000'));
      when JiaoYLX = 'HBHK' then
        MaxBianH := 'HBHK' ||
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  5,
                                                  13)) + 1,
                                 '0000000000000'));
      when JiaoYLX = 'YJFL' then
        MaxBianH := 'YJFL' ||
                  
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  5,
                                                  13)) + 1,
                                 '0000000000000'));
      when JiaoYLX = 'TB' then
        MaxBianH := 'TB' ||
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  3,
                                                  13)) + 1,
                                 '0000000000000'));
      when JiaoYLX = 'QR' then
        MaxBianH := 'QR' ||
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  3,
                                                  13)) + 1,
                                 '0000000000000'));
      when JiaoYLX = 'PZ' then
        MaxBianH := 'PZ' ||
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  3,
                                                  13)) + 1,
                                 '0000000000000'));
      when JiaoYLX = 'ZJMMXG' then
        MaxBianH := 'ZJMMXG' ||
                    trim(to_char(to_Number(substr(MaxBianH,
                                                  7,
                                                  13)) + 1,
                                 '0000000000000'));
    end case; end if;

  insert into MTJY_BianHTable
    (shangpbh, Charshj, Leix)
  values
    (MaxBianH, riqi || TO_char(sysdate, ' hh24:mi:ss'), JiaoYLX);

  commit;
  return MaxBianH;
exception
  when others then
    rollback;
    return MaxBianH;
end GetFtpSeqNO;


SYSID NUMBER 编号;SHANGPBH VARCHAR2(50) 商品编号;CHARSHJ  VARCHAR2(50) 插入时间;  LEIX VARCHAR2(50)类型 ;

posted @ 2013-02-04 08:46 李鑫 阅读(183) | 评论 (0)编辑 收藏

拼音码转换2

CREATE OR REPLACE FUNCTION PUB_GET_STRING_PY(strs varchar2)
return varchar2
is
/***********************************
过程名称:PUB_GET_STRING_PY
功能:生成汉字字符串的拼音首字符
开发者:贺佳利
联系方式:
最后修改时间:2009.09.09
说明:
修改记录:
      2009.09.09 贺佳利 创建
**********************************/
v_length number;
v_char varchar2(2);
v_charlength number;
v_charPY varchar2(2);
i int:=1;
myresult varchar2(500):='';
begin
--获取字符串长度
v_length:=length(strs);
while i<=v_length
loop
   --按顺序取得字符
   v_char:=substr(strs,i,1);
   v_charlength:=lengthb(rtrim(v_char));
   v_charPY:=rtrim(v_char);
   --判断是否是汉字
   if v_charlength=2 then
     v_charPY:=pub_get_py(rtrim(v_char));
   end if;
   --将拼音进行连接
   myresult:=myresult || v_charPY;
   i:=i+1;
end loop;
return myresult;
end PUB_GET_STRING_PY;

posted @ 2013-02-04 08:40 李鑫 阅读(162) | 评论 (0)编辑 收藏

拼音码转换1

CREATE OR REPLACE FUNCTION PUB_GET_PY(p_汉字 CHAR DEFAULT '%')
       RETURN CHAR
IS
/********************************************************************
过程名称:PUB_GET_PY
功能:生成汉字拼音的首字符
开发者:葛长伟(dba123.com)
联系方式:
最后修改时间:2004.02.14
说明:
修改记录:
      2004.02.14 葛长伟 创建
********************************************************************/
v_汉字内码      NUMBER(8);
v_拼音          CHAR(1);
BEGIN
v_汉字内码 := ASCII(p_汉字);
IF v_汉字内码 BETWEEN 45217 AND 45252 THEN
    v_拼音 := 'A';
ELSIF v_汉字内码 BETWEEN 45253 AND 45760 THEN
    v_拼音 := 'B';
ELSIF v_汉字内码 BETWEEN 45761 AND 46317 THEN
    v_拼音 := 'C';
ELSIF v_汉字内码 BETWEEN 46318 AND 46825 THEN
    v_拼音 := 'D';
ELSIF v_汉字内码 BETWEEN 46826 AND 47009 THEN
    v_拼音 := 'E';
ELSIF v_汉字内码 BETWEEN 47010 AND 47296 THEN
    v_拼音 := 'F';
ELSIF v_汉字内码 BETWEEN 47297 AND 47613 THEN
    v_拼音 := 'G';
ELSIF v_汉字内码 BETWEEN 47614 AND 48116 THEN
    v_拼音 := 'H';
ELSIF v_汉字内码 BETWEEN 48117 AND 49061 THEN
    v_拼音 := 'J';
ELSIF v_汉字内码 BETWEEN 49062 AND 49323 THEN
    v_拼音 := 'K';
ELSIF v_汉字内码 BETWEEN 49324 AND 49895 THEN
    v_拼音 := 'L';
ELSIF v_汉字内码 BETWEEN 49896 AND 50370 THEN
    v_拼音 := 'M';
ELSIF v_汉字内码 BETWEEN 50371 AND 50613 THEN
    v_拼音 := 'N';
ELSIF v_汉字内码 BETWEEN 50614 AND 50621 THEN
    v_拼音 := 'O';
ELSIF v_汉字内码 BETWEEN 50622 AND 50925 THEN
    v_拼音 := 'P';
ELSIF v_汉字内码 BETWEEN 50926 AND 51386 THEN
    v_拼音 := 'Q';
ELSIF v_汉字内码 BETWEEN 51387 AND 51445 THEN
    v_拼音 := 'R';
ELSIF v_汉字内码 BETWEEN 51446 AND 52217 THEN
    v_拼音 := 'S';
ELSIF v_汉字内码 BETWEEN 52218 AND 52697 THEN
    v_拼音 := 'T';
ELSIF v_汉字内码 BETWEEN 52698 AND 52979 THEN
    v_拼音 := 'W';
ELSIF v_汉字内码 BETWEEN 52980 AND 53640 THEN
    v_拼音 := 'X';
ELSIF v_汉字内码 BETWEEN 53641 AND 54480 THEN
    v_拼音 := 'Y';
ELSIF v_汉字内码 BETWEEN 54481 AND 55289 THEN
    v_拼音 := 'Z';
ELSE
    v_拼音 := NULL;
END IF;
RETURN v_拼音;
END PUB_GET_PY;

posted @ 2013-02-04 08:40 李鑫 阅读(176) | 评论 (0)编辑 收藏

金额转换

CREATE OR REPLACE FUNCTION money_to_chinese (money IN VARCHAR2)
   RETURN VARCHAR2
IS
   c_money    VARCHAR2 (12);
   m_string   VARCHAR2 (60) := '分角圆拾佰仟万拾佰仟亿';
   n_string   VARCHAR2 (40) := '壹贰叁肆伍陆柒捌玖';
   b_string   VARCHAR2 (80);
   n          CHAR;
   len        NUMBER (3);
   i          NUMBER (3);
   tmp        NUMBER (12);
   is_zero    BOOLEAN;
   z_count    NUMBER (3);
   l_money    NUMBER;
   l_sign     VARCHAR2 (10);
BEGIN
   l_money := ABS (money);

   IF money < 0
   THEN
      l_sign := '负';
   ELSE
      l_sign := '';
   END IF;

   tmp := ROUND (l_money, 2) * 100;
   c_money := RTRIM (LTRIM (TO_CHAR (tmp, '999999999999')));
   len := LENGTH (c_money);
   is_zero := TRUE;
   z_count := 0;
   i := 0;

   WHILE i < len
   LOOP
      i := i + 1;
      n := SUBSTR (c_money,
                   i,
                   1
                  );

      IF n = '0'
      THEN
         IF len - i = 6 OR len - i = 2 OR len = i
         THEN
            IF is_zero
            THEN
               b_string := SUBSTR (b_string,
                                   1,
                                   LENGTH (b_string) - 1
                                  );
               is_zero := FALSE;
            END IF;

            IF len - i = 6
            THEN
               b_string := b_string || '万';
            END IF;

            IF len - i = 2
            THEN
               b_string := b_string || '元';
            END IF;

            IF len = i
            THEN
               b_string := b_string || '整';
            END IF;

            z_count := 0;
         ELSE
            IF z_count = 0
            THEN
               b_string := b_string || '零';
               is_zero := TRUE;
            END IF;

            z_count := z_count + 1;
         END IF;
      ELSE
         b_string :=
               b_string
            || SUBSTR (n_string,
                       TO_NUMBER (n),
                       1
                      )
            || SUBSTR (m_string,
                       len - i + 1,
                       1
                      );
         z_count := 0;
         is_zero := FALSE;
      END IF;
   END LOOP;

   b_string := l_sign || b_string;
   RETURN b_string;
EXCEPTION
   WHEN OTHERS
   THEN
      RETURN (SQLERRM);
END;

posted @ 2013-02-04 08:39 李鑫 阅读(169) | 评论 (0)编辑 收藏

window 服务安装卸载

在VS2008命令控制台下,执行installitil.exe

1. 注册Windows服务

C:"WINDOWS"Microsoft.NET"Framework"v2.0.50727>installutil @fileName

2. 卸载Windows服务

C:"WINDOWS"Microsoft.NET"Framework"v2.0.50727>installutil /u @fileName

@fileName是Winfows服务文件路径和文件名如:c:\MyService.exe



或者在VS2008命令行提示行下直接输入installutil.exe命令

posted @ 2013-02-04 08:36 李鑫 阅读(175) | 评论 (0)编辑 收藏

2011年2月16日

C#中获取当前路径的几种方法

//获取应用程序的当前工作目录。  

02 String path1=System.IO.Directory.GetCurrentDirectory();  

03 MessageBox.Show("获取应用程序的当前工作目录:"+path1);  

04   

05 //获取程序的基目录。  

06 String path2=System.AppDomain.CurrentDomain.BaseDirectory;  

07 MessageBox.Show("获取程序的基目录:"+path2);  

08   

09 //获取和设置包括该应用程序的目录的名称。  

10 String path3=System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;  

11 MessageBox.Show("获取和设置包括该应用程序的目录的名称:"+path3);  

12   

13 //获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。  

14 String path4=System.Windows.Forms.Application.StartupPath;  

15 MessageBox.Show("获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称:"+path4);  

16   

17 //获取启动了应用程序的可执行文件的路径及文件名  

18 String path5=System.Windows.Forms.Application.ExecutablePath;  

19 MessageBox.Show("获取启动了应用程序的可执行文件的路径及文件名:"+path5);


 

posted @ 2011-02-16 09:30 李鑫 阅读(1355) | 评论 (0)编辑 收藏

C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中

01 /// <summary>  

02         /// 去掉字符串中的数字  

03         /// </summary>  

04         /// <param name="key"></param>  

05         /// <returns></returns>  

06         public static string RemoveNumber(string key)  

07         {  

08             return Regex.Replace(key, @"\d", "");  

09         }        /// <summary>  

10         /// 去掉字符串中的非数字  

11         /// </summary>  

12         /// <param name="key"></param>  

13         /// <returns></returns>  

14         public static string RemoveNotNumber(string key)  

15         {  

16             return Regex.Replace(key, @"[^\d]*", "");  

17         }


 效果:输入"High:4"
第一个函数,输出结果是"High:"
第二个函数,输出结果是"4"

posted @ 2011-02-16 09:28 李鑫 阅读(935) | 评论 (1)编辑 收藏

2011年1月21日

silverlight 中0 第三方组建定义

xmlns:sys="clr-namespace:System;assembly=mscorlib"

 xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"

posted @ 2011-01-21 17:14 李鑫 阅读(179) | 评论 (0)编辑 收藏