Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

VLQ 是 Variable-length quantity 的缩写,是一种通用的,使用任意位数的二进制来表示一个任意大的数字的一种编码方式。这个编码方式是在 MIDI 文件格式中定义的,用来节省空间

线编码解码的网站:http://murzwin.com/base64vlq.html ,
开源库相关实现:
https://github.com/mozilla/source-map/blob/master/lib/source-map/base64-vlq.js,

首先我们先来了解下 VLQ 是什么,VLQ 是 Variable-length quantity 的缩写,是一种通用的,使用任意位数的二进制来表示一个任意大的数字的一种编码方式。这个编码方式是在 MIDI 文件格式中定义的,用来节省空间。在其他地方也有很多类似这样的编码格式,比如在 Google’s protocol buffers 中,还有我们马上要讨论到的 BASE64 VLQ 中。想了解的更多,请参考wikipedia

我们先来看看 MIDI 中的 VLQ 编码是如何编码 137 这个数字的吧:(摘抄自 wikipedia)

  • 先把 137 转换成二进制:10001001
  • 7 bit 一组,把二进制分开,不足的补 0 ,变成 0000001 0001001
  • 把最低的7位拿出来,在最高位补0表示最后一位,变成 0000 1001,这个作为最低位,放在最后边。
  • 在其他组的最高位补 1 ,表示没有结束,后面跟着还有数据。在这里就是 1000 0001
  • 拼在一起,就变成了 1000 0001 0000 1001 .

这就是 VLQ 的变化过程。

那么什么是 Base64 VLQ 呢?和上面的变换过程有什么区别呢?

我们可以先来参考我博客的另外一篇文章,先来回顾下 Base64 编码:BASE64 编码规则

我们可以看到 Base64 是一种可以把二进制数据编码成用 ASCII 表示的一种编码规则,但是受限于 Base64 采用的字符集,一个 Base64 字符只能表示 6bit 的数据。所以上面的 VLQ 中 7 bit 一组的分组方式,在这里就要变成 5 bit 一组的分组了。

另外,Base64 VLQ 需要能够表示负数,于是规定了需要先把数字变成无符号数,用最后一位来作为符号标志位。我们直接来做一个变换吧,这样理解的最快。在例子中可以看到和上面的 VLQ 编码还是有一定差别的。

不妨还拿 137 来做示例吧。

  • 先把 137 转换成二进制:10001001
  • 由于 137 是正数,所以在最低位补0 变成 100010010
  • 按照 5bit 一组的方式分组,变成 01000 10010
  • 按照从低位到高位的顺序,以 5bit 一组为单位,依次拿出数据做转换。
  • 先拿出第一组 10010 , 因为后面还有数据,所以需要在高位补 1,变成 110010 ,编码成 Base64: y
  • 再拿出第二组,也是我们这里的最后一组,01000 , 由于是最后一组,所以在高位补 0 变成 001000,编码成 Base64: I
  • 按照从低位到高位的顺序把这些 ASCII 字符拼接起来,变成 yI

可以看到在 VLQ 中,编码顺序是从高位到低位,在 Base64 VLQ 中,编码顺序是从低位到高位。

那么如何解码呢?相信了解了编码过程后,解码过程就不必再讲解了。

参考:http://blog.allenm.me/2012/12/base64-vlq-encoding/
http://www.ruanyifeng.com/blog/2013/01/javascript_source_map.html


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

公司每天EMS包裹单有很多,人工查效率不高且易出错,想用程序上传包裹单查询,考察了市面上的程序,kuaidi100不错,经沟通,并不支持EMS,他们是免费的,EMS开放的话服务器会抗不住,自己写!
实现过程:
1,利用AspriseOCR进行验证码识别。
2,将获取的验证码构造Post数据上传。
3,对于反应的包裹消息源页面,用Winista.HtmlParser分析出包裹信息。
4,源码:enjoytools/…


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication38
{
    public class LevenshteinDistance
    {

        private static LevenshteinDistance _instance=null;
        public static LevenshteinDistance Instance
        {
            get
            {
                if (_instance == null)
                {
                    return new LevenshteinDistance();
                }
                return _instance;
            }
        }
    

        /// <summary>
        /// 取最小的一位数
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <param name="third"></param>
        /// <returns></returns>
        public int LowerOfThree(int first, int second, int third)
        {
            int min = first;
            if (second < min)
                min = second;
            if (third < min)
                min = third;
            return min;
        }

        public int Levenshtein_Distance(string str1, string str2)
        {
            int[,] Matrix;
            int n=str1.Length;
            int m=str2.Length;

            int temp = 0;
            char ch1;
            char ch2;
            int i = 0;
            int j = 0;
            if (n ==0)
            {
                return m;
            }
            if (m == 0)
            {

                return n;
            }
            Matrix=new int[n+1,m+1];

            for (i = 0; i <= n; i++)
            {
                //初始化第一列
                Matrix[i,0] = i;
            }

            for (j = 0; j <= m; j++)
            {
                //初始化第一行
                Matrix[0, j] = j;
            }

            for (i = 1; i <= n; i++)
            {
                ch1 = str1[i-1];
                for (j = 1; j <= m; j++)
                {
                    ch2 = str2[j-1];
                    if (ch1.Equals(ch2))
                    {
                        temp = 0;
                    }
                    else
                    {
                        temp = 1;
                    }
                    Matrix[i,j] = LowerOfThree(Matrix[i - 1,j] + 1, Matrix[i,j - 1] + 1, Matrix[i - 1,j - 1] + temp);


                }
            }

            for (i = 0; i <= n; i++)
            {
                for (j = 0; j <= m; j++)
                {
                    Console.Write(" {0} ", Matrix[i, j]);
                }
                Console.WriteLine("");
            }
            return Matrix[n, m];

        }

        /// <summary>
        /// 计算字符串相似度
        /// </summary>
        /// <param name="str1"></param>
        /// <param name="str2"></param>
        /// <returns></returns>
        public decimal LevenshteinDistancePercent(string str1,string str2)
        {
            int maxLenth = str1.Length > str2.Length ? str1.Length : str2.Length;
            int val = Levenshtein_Distance(str1, str2);
            return 1 - (decimal)val / maxLenth;
        }
    }

    class Program
    {


        static void Main(string[] args)
        {
            string str1 = "你好蒂蒂";
            string str2="你好蒂芬";
            Console.WriteLine("字符串1 {0}", str1);

            Console.WriteLine("字符串2 {0}", str2);

            Console.WriteLine("相似度 {0} %", LevenshteinDistance.Instance.LevenshteinDistancePercent(str1, str2)*100);
            Console.ReadLine();
        }
    }



}


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed += new FileSystemEventHandler(OnChanged);
        watcher.Created += new FileSystemEventHandler(OnChanged);
        watcher.Deleted += new FileSystemEventHandler(OnChanged);
        watcher.Renamed += new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \'q\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: " +  e.FullPath + " " + e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
莱恩戴尔算法
调用方式:
 SymmetricMethod smd = new SymmetricMethod();
 string encode = smd.Encrypto("18620023427"); //JyHPgvA0lDTzgEKGYeCvxw==
 string decode = smd.Decrypto(encode);
可用DotNETReactor混淆加密提升安全
参考:http://www.cnblogs.com/freelyflight/archive/2005/08/19/218139.aspx


  /// <summary>
    /// 对称加密算法类
    /// </summary>
    public class SymmetricMethod
    {

        private SymmetricAlgorithm mobjCryptoService;
        private string Key;
        /// <summary>
        /// 对称加密类的构造函数
        /// </summary>
        public SymmetricMethod()
        {
            mobjCryptoService = new RijndaelManaged();
            Key = "LifeIsGood@lvshou";
        }
        /// <summary>
        /// 获得密钥
        /// </summary>
        /// <returns>密钥</returns>
        private byte[] GetLegalKey()
        {
            string sTemp = Key;
            mobjCryptoService.GenerateKey();
            byte[] bytTemp = mobjCryptoService.Key;
            int KeyLength = bytTemp.Length;
            if (sTemp.Length > KeyLength)
                sTemp = sTemp.Substring(0, KeyLength);
            else if (sTemp.Length < KeyLength)
                sTemp = sTemp.PadRight(KeyLength, ' ');
            return ASCIIEncoding.ASCII.GetBytes(sTemp);
        }
        /// <summary>
        /// 获得初始向量IV
        /// </summary>
        /// <returns>初试向量IV</returns>
        private byte[] GetLegalIV()
        {
            //string sTemp = "E4ghj*Ghg7!rNIfb&95GUY86GfghUb#er57HBh(u%g6HJ($jhWk7&!hg4ui%$hjk";
            string sTemp = Key;
            mobjCryptoService.GenerateIV();
            byte[] bytTemp = mobjCryptoService.IV;
            int IVLength = bytTemp.Length;
            if (sTemp.Length > IVLength)
                sTemp = sTemp.Substring(0, IVLength);
            else if (sTemp.Length < IVLength)
                sTemp = sTemp.PadRight(IVLength, ' ');
            return ASCIIEncoding.ASCII.GetBytes(sTemp);
        }
        /// <summary>
        /// 加密方法
        /// </summary>
        /// <param name="Source">待加密的串</param>
        /// <returns>经过加密的串</returns>
        public string Encrypto(string Source)
        {
            byte[] bytIn = UTF8Encoding.UTF8.GetBytes(Source);
            MemoryStream ms = new MemoryStream();
            mobjCryptoService.Key = GetLegalKey();
            mobjCryptoService.IV = GetLegalIV();
            ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor();
            CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
            cs.Write(bytIn, 0, bytIn.Length);
            cs.FlushFinalBlock();
            ms.Close();
            byte[] bytOut = ms.ToArray();
            return Convert.ToBase64String(bytOut);
        }
        /// <summary>
        /// 解密方法
        /// </summary>
        /// <param name="Source">待解密的串</param>
        /// <returns>经过解密的串</returns>
        public string Decrypto(string Source)
        {
            byte[] bytIn = Convert.FromBase64String(Source);
            MemoryStream ms = new MemoryStream(bytIn, 0, bytIn.Length);
            mobjCryptoService.Key = GetLegalKey();
            mobjCryptoService.IV = GetLegalIV();
            ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor();
            CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read);
            StreamReader sr = new StreamReader(cs);
            return sr.ReadToEnd();
        }
    }


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
1,生成图片类:
using System;
using System.Configuration;
using Share.Data;
using System.Data.SqlClient;
using System.Text;
using System.Data;
using Share.Utility;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace Web.Class.Constant
{
    /// <summary>
    /// Summary description for HelpConstant.
    /// </summary>
    public class VerifyCode : System.Web.UI.Page
    {
        private static string codenum;
        public static string CodeNum
        {
            get { return codenum; }
            set { codenum = value; }
        }
        public static string strRandom(int Ia, int Ib)
        {
            Random rd = new Random(unchecked((int)DateTime.Now.Ticks));
            object i = rd.Next(Ia, Ib);
            return i.ToString();
        }
        public static byte[] GetCode(int Ia, int Ib)
        {
            CodeNum = strRandom(Ia,Ib);
            Bitmap bm = new Bitmap(50, 15, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Font f = new Font("Lucida Sans Unicode", 9, FontStyle.Bold);
            Graphics g = Graphics.FromImage(bm);
            Rectangle newRect = new Rectangle(0, 0, 50, 16);
            g.FillRectangle(new SolidBrush(Color.WhiteSmoke), newRect);
            g.DrawString(codenum, f, new SolidBrush(Color.Red), 1, -1);
            MemoryStream mStream = new MemoryStream();
            bm.Save(mStream, ImageFormat.Gif);
            g.Dispose();
            bm.Dispose();
            
            return mStream != null?mStream.ToArray():null;

        }

    }
}

2,输出:
        Response.ClearContent();
        Response.ContentType = "image/GIF";
        Response.BinaryWrite(VerifyCode.GetCode(10000, 99999));
        Response.End();
3,前台引用:
4,前台录入的与VerifyCode.CodeNum比较即可


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
数组:0 1 2 3 4 5
取数据:
方法1:取出一个删除一个,但删除很费时,性能并不高
方法2:取出一个,用数组最后一位填充,相当于将最后一位前移,同时将最后一排除在下次取数据之外即可。
&lt;a href="http://www.cnblogs.com/eaglet/archive/2011/01/17/1937083.html"&gt;不重复随机数列生成算法&lt;/a&gt;

新方法:

下面的时间复杂度很小
public static int[] GetRandomSequence2(int total)

{

int[] sequence = new int[total];

int[] output = new int[total];

for (int i = 0; i &amp;lt; total; i++)

{

sequence[i] = i;

}

Random random = new Random();

int end = total - 1;

for (int i = 0; i &amp;lt; total; i++)

{

int num = random.Next(0, end + 1);

output[i] = sequence[num];

sequence[num] = sequence[end];

end--;&nbsp; //缩小范围,将最后一位前移,并排除最后一位。

}

return output;

}

老方法:时间复杂度为n2
public static int[] GetRandomSequence0(int total)

{

int[] hashtable = new int[total];

int[] output = new int[total];

Random random = new Random();

for (int i = 0; i &amp;lt; total; i++)

{

int num = random.Next(0, total);

while (hashtable[num] &amp;gt; 0)

{

num = random.Next(0, total);

}

output[i] = num;

hashtable[num] = 1;

}

return output;

}


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

主要是用organid字段 ,在数据表中表示好树形结构。
1,数据形式:
category organid
保健家居用品类 01
内衣 0101
其他 0102
保健器械类 02
丰胸美乳 0201
减肥瘦身 0202
身体保健 0203
其他 0204
保健食品类 03
品牌 0301
贝力美 030101
高颗丽挺 030102
零点1号 030103
零点2号 030104

2,取数据:
SELECT STUFF(a.Category,1,0,REPLICATE(‘-‘,LEN(a.OrganID)-2))
FROM mdCategory a(NOLOCK)
ORDER BY a.OrganID

效果:
保健家居用品类
–内衣
–其他
保健器械类
–丰胸美乳
–减肥瘦身
–身体保健
–其他
保健食品类
–品牌
—-贝力美
—-高颗丽挺


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

1,IE自带的打印方法繁琐,利用控件,
目前有:QWPrint、Lodop,JaTools。
Lodop:功能最强大,可拖曳式布局打印界面,免费版直接打印时带有版权信息。
JaToos:功能一般,不过价格比较贵一些。
QWPrint:功能简单一些,不过是完全免费,封装一下也能解决目前的打印问题。

2,QWPrint打印的是当前页面,若想打印指定内容,需要进行封装一下,思路:在指定的内容传到一新窗口中打印,然后关闭窗口。
方法:

//vinfo:指定要打印的元素名称,model:默认为预览,为1时为直接打印
function OutTo(vinfo,model){
var content = document.getElementById(vinfo);
if ( content == undefined )
{
alert(‘请指定打印的内容!’);
return;
}
var wprint = window.open();
wprint.moveTo(-500,-500); //隐藏窗口
//指定打印内容
wprint.document.writeln(content.innerHTML);
wprint.document.body.style.cssText=”margin:0px;”;
//打印控件
wprint.document.writeln(“


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

comm100
注册一个编号,可以新建多个客服。支持文本和语音聊天,客服转接和加入对话 ,监控访客动态,主动抓住客户等。还开以开论坛、知识库,关键是开源,免费的。
效果如下:
客户界面(可定制):
客户界面

信息来时提醒:
信息来时的提醒界面

客服界面:
客服界面


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
从小到大排序

1,冒泡:
当前元素是a[i],在a[0]到a[i-1]之间依次比对
若a[j]> a[i],a[j]与a[i]进行交换,(小值向上浮动,保证每次循环后a[0]获得最小值,a[1]二小)
因要与左侧元素比对,故循环从a[1]开始直到数据尾a[n-1]

2,选择:
当前元素是a[i],在a[i+1]与a[n-1]之间依次比对,取出最小值与a[i]进行交换。
以保证:第一次:比较n个元素,取出最小的放在第一个位置(进行交换)
        第二次:比较剩下的n-1个元素,取出第二小的放在第二个位置
         ...
因要与右侧元素比对,故循环从a[0]开始到a[n-2]结束

3,插入:
当前元素是a[i],在a[0]到a[i-1]之间依次比对,
若a[j] > a[i],a[j]右移到a[j+1]
否则,说明当前位置的前一个位置正是要插入的位置,跳出循环,将a[i]的值放到a[j+1]处即可
(保证每次的a[i]都放在恰当的位置)
因要与左侧元素比对,故循环从a[1]开始直到数据尾a[n-1]
注:
(1)若n较小,可采用直接插入或直接选择排序。
但当记录规模较大时,因为直接选择移动的记录数少于直接插人,所以宜用选直接选择排序。
冒泡:    比较次数,频繁的交换操作
直接插入:比较次数,频繁的移位操作
选择:    比较次数,更少的交换操作

4,归并排序:递归拆分与合并。将数组拆分成左右数组,进行合并。

5  ,快速排序:
      1)性质: 若一组数已经排好序,那么对于此组数每一个元素来说,每一个元素的左边都比它小,右边都比它大。
应用此性质:将当前元素放到恰好位置,让左区的元素都比它小,右区的元素都比它大,然后递归,
直到区细分到单个元素为止。
过程:对于数组第一个元素进行排序,循环:将左区元素第一个比当前元素大的与右区第一个比当前元素小的进行交换,
直到左区的都比当前元素小,右区的都比当前元素大。然后递归左区与右区。
     2)快速排序也是使用了分治法的思路,不需要合并,快速排序和归并排序都是分治法,它们的区别在于,快速排序不需
要合并,快速排序的平均运行时间为Θ(n log n)

6,希尔排序,将整个无序列分割成若干小的子序列分别进行插入排序的方法,
是插入排序的一种高效稳定的改进版本。
先取一个正整数d1

快速排序
快速排序

算法的实现:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication31
{
    class Program
    {
        public delegate void Sort(int[] arr);
        static void Main(string[] args)
        {
            int[] arr = { 9,8,7,6,5,4,3,2,1};
            //BubbleSorter(arr);
            //Printf("BubbleSorter", arr);

            //SelectSorter(arr);
            //Printf("SelectSorter", arr);

            InsertSorter(arr);
            Printf("InsertSorter", arr);

           
            //Printf("QuickSort", arr, QuickSort);
            //QuickSort(arr,0,arr.Length-1);
            //Printf("QuickSort",arr);
            Console.Read();
        }

        public static void Printf(string type,int[] arr) {
            Console.WriteLine(string.Format("-------------------{0}-------------------",type));
            DateTime DateTime = DateTime.Now;
            //System.Threading.Thread.Sleep(1000);
            //sort(arr);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < arr.Length; i++) {
                sb.Append(","+arr[i].ToString() );
            }
            Console.WriteLine(sb.ToString().Substring(1,sb.Length-1));
            string timespent = (DateTime.Now.Subtract(DateTime)).TotalMilliseconds.ToString();
            Console.WriteLine(string.Format("-------------------{0}:{1}s----------------", type, timespent));
           
        }


        //冒泡法,每次将元素放到合适的位置,
        //保持当前元素之前的元素处在有序状态,然后将当前元素与之前的有序元素进行对比交换
        //复杂度:1+2+..(n-1) = (n-1)*n/2,比上边的复杂度少了一半。
        //冒泡:即相邻数据的交换
        private static int[] BubbleSorter(int[] arr)
        {
            int key = 0;
            int tmp = 0;
            for (int i = 1; i < arr.Length; i++) {
                key = arr[i];
                for (int j = i - 1; j >= 0; j--) {
                    if (arr[j] > key) {
                        tmp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = tmp;
                    }
                }
            }
            return arr;
        }

        //选择排序:
        //第一次:比较n个元素,取出最小的放在第一个位置(进行交换)
        //第二次:比较剩下的n-1个元素,取出第二小的放在第二个位置
        // ......
        //(n-1)*n/2加少量交换,而冒泡是(n-1)*n/2加多次交换
        private static void SelectSorter(int[] arr)
        {
            int key = 0;
            int k = 0;
            for (int i = 0; i < arr.Length-1; i++)
            {
                k = i;
                for (int j = i + 1; j < arr.Length; j++)
                {
                    if (arr[j] < arr[k] )
                    {
                        k = j;
                    }
                }
                key = arr[i];
                arr[i] = arr[k];
                arr[k] = key;
            }
           
        }



        /*
        插入法,每次将元素放到最合适的位置,
        保持当前元素之前的元素处在有序状态,然后将当前元素与之前的有序元素进行对比
        若对比的元素大于当前元素,则将此对比的元素右移一位,若对比元素小于当前元素,说明此对比元素位置之后的那个
        位置正是要插入的位置,插入即可
        注:1,与增强版冒泡排序相同的一点是保持当前元素之前的元素处于有序状态,
              然后逐个比较,满足条件的元素进行右移操作而不是交换。
            2,参考打牌,拾起一张牌,放已排好顺序的牌堆中进行插入,右移每张牌直到找到比它小的,然后插入到之前即可。
           //(n-1)*n/2加少量移位,比选择好一些
        */
        private static void InsertSorter(int[] arr)
        {
            int key = 0;
            int j = 0;
            for (int i = 1; i < arr.Length; i++)
            {
                key = arr[i];
                for (j=i-1; j >= 0; j--)
                {
                    if (arr[j] > key)
                    {
                        arr[j + 1] = arr[j];
                    }
                    else { break; }
                }
                arr[j+1] = key;
            }
           
        }

        ///快速排序:利用的性质,若一个数组排好顺序,那么对于每一个元素来说,它左边的都比此元素小,右边的都比此元素大。
        ///过程,对于数组第一个元素进行排序,循环:将左区元素第一个比当前元素大的与右区第一个比当前元素小的进行交换,
        ///直到左区的都比当前元素小,右区的都比当前元素大。然后递归左区与右区。
        ///(若左区或右区进入对方区域,则说明循环完毕,跳出即可。)
        ///保证得到的结果是:它左边的元素都比此元素小,右边的元素都比此元素大
        ///然后分别从此元素左侧、若侧元素进行快速排序
        private static void QuickSort(int[] arr, int left,int right) {
            if (left >= right) { return; }
            int i=left;
            int j=right+1;
            while (true)
            {
                while (i < arr.Length-1 && arr[++i] < arr[left]) ;
                while (j >= 0 && arr[--j] > arr[left]) ;
                if (i >= j) { break; }
                else {
                    swap(ref arr[i], ref arr[j]);
                }
            }
            swap(ref arr[left], ref arr[j]);
            QuickSort(arr, left, j - 1);
            QuickSort(arr, j + 1, right);
        }
        //交换两个数
        static void swap( ref int left,ref int right) {
            int tmp = left;
            left = right;
            right = tmp;
        }

        /// 
        /// 归并排序:递归拆分与合并。将数组拆分成左右数组,进行合并。
        int[] MeargeSort(int[] data)
        {
            //取数组中间下标
            int middle = data.Length / 2;
            //初始化临时数组let,right,并定义result作为最终有序数组
            int[] left = new int[middle], right = new int[middle], result = new int[data.Length];
            if (data.Length % 2 != 0)//若数组元素奇数个,重新初始化右临时数组
            {
                right = new int[middle + 1];
            }
            if (data.Length <= 1)//只剩下1 or 0个元数,返回,不排序
            {
                return data;
            }
            int i = 0, j = 0;
            foreach (int x in data)//开始排序
            {
                if (i < middle)//填充左数组
                {
                    left[i] = x;
                    i++;
                }
                else//填充右数组
                {
                    right[j] = x;
                    j++;
                }
            }
            left = MeargeSort(left);//递归左数组
            right = MeargeSort(right);//递归右数组
            result = Merge(left, right);//开始排序
            //this.Write(result);//输出排序
            return result;
        }
        /// 
        /// 归并排序之并:排序在这一步
        /// 
        /// 左数组
        /// 右数组
        /// 合并左右数组排序后返回
        int[] Merge(int[] a, int[] b)
        {
            //定义结果数组,用来存储最终结果
            int[] result = new int[a.Length + b.Length];
            int i = 0, j = 0, k = 0;
            while (i < a.Length && j < b.Length)
            {
                if (a[i] < b[j])//左数组中元素小于右数组中元素
                {
                    result[k++] = a[i++];//将小的那个放到结果数组
                }
                else//左数组中元素大于右数组中元素
                {
                    result[k++] = b[j++];//将小的那个放到结果数组
                }
            }
            while (i < a.Length)//这里其实是还有左元素,但没有右元素
            {
                result[k++] = a[i++];
            }
            while (j < b.Length)//右右元素,无左元素
            {
                result[k++] = b[j++];
            }
            return result;//返回结果数组
        }
    }
}


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

克拉默法则
克拉默法则


应用:
设有未知数x1、x2、x3、x4,满足以下条件:
x1 + 3*x2 -2*x3 + x4 = 1
2*x1 + 5*x2 -3*x3 + 2*x4 = 3
-3*x1+ 4*x2 + 8*x3 -2*x4 = 4
6*x1 -x2 - 6*x3 + 4*x4 =2
用克拉默法则求出x1、x2、x3、x4的值。

解题方法:

我们在(A1:E4)单元格分别输入系数和等号右边的数值
1    3    -2    1    1
2    5    -3    2    3
-3    4    8    -2    4
6    -1    -6    4    2

在单元格A5输入公式:
=MDETERM(A1:D4)    注意这里是(A1:D4),而不是(A1:E4)

MDETERM

返回一个数组的矩阵行列式的值。

语法

MDETERM(array)

Array    行数和列数相等的数值数组
MDETERM(A1:C3) 等于
A1*(B2*C3-B3*C2) + A2*(B3*C1-B1*C3) + A3*(B1*C2-B2*C1)

选中(E1:E4)这一列单元格,复制:按Ctrl + c,
然后点中A1单元,粘贴:按Ctrl +  v,
A5单元格变成了 -34 ,于是得 D1 = -34

取消:按Ctrl + z,A5单元格仍变回17。点中B1单元格,粘贴:按Ctrl +  v,
A5单元格变成了 0 ,于是得 D2 = 0

取消:按Ctrl + z,A5单元格仍变回17。点中C1单元格,粘贴:按Ctrl +  v,
A5单元格变成了 17,于是得 D3 = 17

取消:按Ctrl + z,A5单元格仍变回17。点中D1单元格,粘贴:按Ctrl +  v,
A5单元格变成了 85,于是得 D4 = 85

根据克拉默法则:

x1 = D1 / D = -34 / 17 = -2
x2 = D2 / D =    0 / 17 = 0
x3 = D3 / D =  17 / 17 = 1


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

1. 用最简单的方法判断一个LONG整形的数A是2^n(2的n次方)

* 若一个数是2^n,那么此数的二进制形式应为: 100000…,在所有的数位中,只有一个是1,其它都为0
* 当用此数减1时,就会变成: 01111111….,在所有数位为1,对应数位为0,那么二者相与,就会为0
* 故:当此数与比他小一的数相与若为0,则此数是2的n次方,算法为:判断 i&(i-1) 是否为0,若为0,则此数是2的n次方

2. 扩展:判断一个LONG整形的数是否是2^n – 1

* 设:x为一个2^n -1数, 那么x+1= 2^n = (x+1)&x
* 即:用x&(x+1)若为0,则是2^n – 1数

3.? (A|B|C) & A = A
令:X = A|B|C, 因为进行的是或运算, 那么在A中位数为1的数位上,对应的X数位也为1,这些为1的数位与A进行与操作,结果为1.?????? 在X的其它数位上,因A在这些数位上为0,故X的其它数位与A相与为0,总和二者知:结果为A
扩展:权限设计,每个权限给予一个数字,每个人的权限值即为这些权限的或操作结果,那么判断此人是否拥有A权限,即用此人总的权限值与A进行与操作即可,若结果为A,则说明拥有此权限。


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

001
012
111
据int 构造字符串
(’00’ + i)从右边取三位即是,这种方法就不用再判断i的位数加不同的‘0’的个数来实现


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
  public static  string encode(string str)
        {
            string htext = "";

            for (int i = 0; i < str.Length; i++)
            {
                htext = htext + (char)(str[i] + 10 - 1 * 2);
            }
            return htext;
        }

        public static string decode(string str)
        {
            string dtext = "";

            for (int i = 0; i < str.Length; i++)
            {
                dtext = dtext + (char)(str[i] - 10 + 1 * 2);
            }
            return dtext;
        }


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
public class DataBaseUntity
    {
        //获取数据库数据:据数据库的表字段为实体类相同名称属性赋值
        public static IList SetEntityFromDB(DataTable dt)
        {
            IList list = new List();
            Type type = typeof(T);
            System.Reflection.PropertyInfo[] properties = type.GetProperties();
            foreach (DataRow dr in dt.Rows)
            {
                T t = Activator.CreateInstance();  
                for (int i = 0; i < properties.Length; i++)
                {
                    if (dt.Columns.Contains(properties[i].Name))
                    {
                        properties[i].SetValue(t, dr[properties[i].Name], null);
                    }
                }
                list.Add(t);
            }

            return list;
        }

        //向数据库传参:据实体构造参数
        public static ArrayList GetParamsFromEntity(T t) {
            Type type = typeof(T);
                      
            System.Reflection.PropertyInfo[] properties = type.GetProperties();
            //SqlParameter[] sps = new SqlParameter[properties.Length-1];
            ArrayList args = new ArrayList();
            SqlParameter sp;
            for (int i = 0; i < properties.Length; i++) {
                args.Add(new SqlParameter(string.Format("@{0}",properties[i].Name),properties[i].GetValue(t,null)));
            }

            return args;
        }

    }


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
 

注:要放到网站下面,不然图片显示不出来


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
 //IE
window.onbeforeunload=function(){
if(event.clientX>document.body.clientWidth && event.clientY < 0 || event.altKey){
    if(winHref.indexOf("lvshou66")<0){
    window.external.addFavorite("http://"+location.hostname,"绿瘦首页收藏!");
    }
}
}
//FF
window.onunload=function(){
    if(window.sidebar){
        if(document.body.clientWidth==0){    
            if(winHref.indexOf("lvshou66")<0){
                window.sidebar.addPanel("绿瘦首页收藏!","http://"+location.hostname, "");
            }
        }
    }
}


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

SELECT money GROUP BY CONVERT(varchar, in_date, 111) 日期为日,时,分,这样只按日分组


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;

using System.Globalization;

namespace FtpTest1
{

    public class FtpWeb
    {
        string ftpServerIP;
        string ftpRemotePath;
        string ftpUserID;
        string ftpPassword;
        string ftpURI;

        /// 
        /// 连接FTP
        /// 
        /// FTP连接地址
        /// 指定FTP连接成功后的当前目录, 如果不指定即默认为根目录
        /// 用户名
        /// 密码
        public FtpWeb(string FtpServerIP, string FtpRemotePath, string FtpUserID, string FtpPassword)
        {
            ftpServerIP = FtpServerIP;
            ftpRemotePath = FtpRemotePath;
            ftpUserID = FtpUserID;
            ftpPassword = FtpPassword;
            ftpURI = "ftp://" + ftpServerIP + "/" ;
        }


        static void Main() {
            //string file = "c:\\aq3.gifa";
            //FileInfo fileInf = new FileInfo(file);
            //if (!fileInf.Exists)
            //{
            //    Console.WriteLine(file + " no exists");
            //}
            //else {
            //    Console.WriteLine("yes");
            //}
            //Console.ReadLine();
            FtpWeb fw = new FtpWeb("121.11.65.10", "", "aa1", "aa");
            string[] filePaths = { "c:\\aq3.gif1", "c:\\aq2.gif1", "c:\\bsmain_runtime.log" };
            Console.WriteLine(fw.UploadFile(filePaths));
            Console.ReadLine();
        }

        //上传文件
        public string UploadFile( string[] filePaths ) {
            StringBuilder sb = new StringBuilder();
            if ( filePaths != null && filePaths.Length > 0 ){
                foreach( var file in filePaths ){
                    sb.Append(Upload( file ));
                    
                }
            }
            return sb.ToString();
        }

         /// 
        /// 上传文件
        /// 
        /// 
        private string Upload(string filename)
        {
            FileInfo fileInf = new FileInfo(filename);
            if ( !fileInf.Exists ){
                return filename + " 不存在!\n";
            }

            string uri = ftpURI + fileInf.Name;
            FtpWebRequest reqFTP;
            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
            
            reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
            reqFTP.KeepAlive = false;
            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
            reqFTP.UseBinary = true;
            reqFTP.UsePassive = false;  //选择主动还是被动模式
            //Entering Passive Mode
            reqFTP.ContentLength = fileInf.Length;
            int buffLength = 2048;
            byte[] buff = new byte[buffLength];
            int contentLen;
            FileStream fs = fileInf.OpenRead();
            try
            {
                Stream strm = reqFTP.GetRequestStream();
                contentLen = fs.Read(buff, 0, buffLength);
                while (contentLen != 0)
                {
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);
                }
                strm.Close();
                fs.Close();
            }
            catch (Exception ex)
            {
                return "同步 "+filename+"时连接不上服务器!\n";
                //Insert_Standard_ErrorLog.Insert("FtpWeb", "Upload Error --> " + ex.Message);
            }
            return "";
        }


        /// 
        /// 下载
        /// 
        /// 
        /// 
        public void Download(string filePath, string fileName)
        {
            FtpWebRequest reqFTP;
            try
            {
                FileStream outputStream = new FileStream(filePath + "\\" + fileName, FileMode.Create);

                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + fileName));
                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();
                long cl = response.ContentLength;
                int bufferSize = 2048;
                int readCount;
                byte[] buffer = new byte[bufferSize];

                readCount = ftpStream.Read(buffer, 0, bufferSize);
                while (readCount > 0)
                {
                    outputStream.Write(buffer, 0, readCount);
                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                }

                ftpStream.Close();
                outputStream.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                Insert_Standard_ErrorLog.Insert("FtpWeb", "Download Error --> " + ex.Message);
            }
        }

        /// 
        /// 删除文件
        /// 
        /// 
        public void Delete(string fileName)
        {
            try
            {
                string uri = ftpURI + fileName;
                FtpWebRequest reqFTP;
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));

                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                reqFTP.KeepAlive = false;
                reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;

                string result = String.Empty;
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                long size = response.ContentLength;
                Stream datastream = response.GetResponseStream();
                StreamReader sr = new StreamReader(datastream);
                result = sr.ReadToEnd();
                sr.Close();
                datastream.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                Insert_Standard_ErrorLog.Insert("FtpWeb", "Delete Error --> " + ex.Message + "  文件名:" + fileName);
            }
        }

        /// 
        /// 获取当前目录下明细(包含文件和文件夹)
        /// 
        /// 
        public string[] GetFilesDetailList()
        {
            string[] downloadFiles;
            try
            {
                StringBuilder result = new StringBuilder();
                FtpWebRequest ftp;
                ftp = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI));
                ftp.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                WebResponse response = ftp.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string line = reader.ReadLine();
                line = reader.ReadLine();
                line = reader.ReadLine();
                while (line != null)
                {
                    result.Append(line);
                    result.Append("\n");
                    line = reader.ReadLine();
                }
                result.Remove(result.ToString().LastIndexOf("\n"), 1);
                reader.Close();
                response.Close();
                return result.ToString().Split('\n');
            }
            catch (Exception ex)
            {
                downloadFiles = null;
                Insert_Standard_ErrorLog.Insert("FtpWeb", "GetFilesDetailList Error --> " + ex.Message);
                return downloadFiles;
            }
        }

        /// 
        /// 获取当前目录下文件列表(仅文件)
        /// 
        /// 
        public string[] GetFileList(string mask)
        {
            string[] downloadFiles;
            StringBuilder result = new StringBuilder();
            FtpWebRequest reqFTP;
            try
            {
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI));
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
                WebResponse response = reqFTP.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());

                string line = reader.ReadLine();
                while (line != null)
                {
                    if (mask.Trim() != string.Empty && mask.Trim() != "*.*")
                    {
                        string mask_ = mask.Substring(0, mask.IndexOf("*"));
                        if (line.Substring(0, mask_.Length) == mask_)
                        {
                            result.Append(line);
                            result.Append("\n");
                        }
                    }
                    else
                    {
                        result.Append(line);
                        result.Append("\n");
                    }
                    line = reader.ReadLine();
                }
                result.Remove(result.ToString().LastIndexOf('\n'), 1);
                reader.Close();
                response.Close();
                return result.ToString().Split('\n');
            }
            catch (Exception ex)
            {
                downloadFiles = null;
                if (ex.Message.Trim() != "远程服务器返回错误: (550) 文件不可用(例如,未找到文件,无法访问文件)。")
                {
                    Insert_Standard_ErrorLog.Insert("FtpWeb", "GetFileList Error --> " + ex.Message.ToString());
                }
                return downloadFiles;
            }
        }

        /// 
        /// 获取当前目录下所有的文件夹列表(仅文件夹)
        /// 
        /// 
        public string[] GetDirectoryList()
        {
            string[] drectory = GetFilesDetailList();
            string m = string.Empty;
            foreach (string str in drectory)
            {
                if (str.Trim().Substring(0, 1).ToUpper() == "D")
                {
                    m += str.Substring(54).Trim() + "\n";
                }
            }

            char[] n = new char[] { '\n' };
            return m.Split(n);
        }

        /// 
        /// 判断当前目录下指定的子目录是否存在
        /// 
        /// 指定的目录名
        public bool DirectoryExist(string RemoteDirectoryName)
        {
            string[] dirList = GetDirectoryList();
            foreach (string str in dirList)
            {
                if (str.Trim() == RemoteDirectoryName.Trim())
                {
                    return true;
                }
            }
            return false;
        }

        /// 
        /// 判断当前目录下指定的文件是否存在
        /// 
        /// 远程文件名
        public bool FileExist(string RemoteFileName)
        {
            string[] fileList = GetFileList("*.*");
            foreach (string str in fileList)
            {
                if (str.Trim() == RemoteFileName.Trim())
                {
                    return true;
                }
            }
            return false;
        }

        /// 
        /// 创建文件夹
        /// 
        /// 
        public void MakeDir(string dirName)
        {
            FtpWebRequest reqFTP;
            try
            {
                // dirName = name of the directory to create.
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + dirName));
                reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();

                ftpStream.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                Insert_Standard_ErrorLog.Insert("FtpWeb", "MakeDir Error --> " + ex.Message);
            }
        }

        /// 
        /// 获取指定文件大小
        /// 
        /// 
        /// 
        public long GetFileSize(string filename)
        {
            FtpWebRequest reqFTP;
            long fileSize = 0;
            try
            {
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + filename));
                reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();
                fileSize = response.ContentLength;

                ftpStream.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                Insert_Standard_ErrorLog.Insert("FtpWeb", "GetFileSize Error --> " + ex.Message);
            }
            return fileSize;
        }

        /// 
        /// 改名
        /// 
        /// 
        /// 
        public void ReName(string currentFilename, string newFilename)
        {
            FtpWebRequest reqFTP;
            try
            {
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + currentFilename));
                reqFTP.Method = WebRequestMethods.Ftp.Rename;
                reqFTP.RenameTo = newFilename;
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();

                ftpStream.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                Insert_Standard_ErrorLog.Insert("FtpWeb", "ReName Error --> " + ex.Message);
            }
        }

        /// 
        /// 移动文件
        /// 
        /// 
        /// 
        public void MovieFile(string currentFilename, string newDirectory)
        {
            ReName(currentFilename, newDirectory);
        }