23
2013
08

C#winform批量给图片加水印代码

//文件下载,里面有exe可直接运行

http://download.csdn.net/detail/pukuimin1226/6001759

22
2013
08

.net mvc中上传图片生成缩略图

Code:

        #region CreateThumbnail
        /// <summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="uploadObject">上传的HttpPostedFile或图片物理路径</param>
        /// <param name="uploaddir">上传文件夹相对路径</param>
        /// <param name="ext">后缀(如:.jpg)</param>
        /// <param name="t_width">缩略图宽</param>
        /// <param name="t_height">缩略图高</param>
        /// <param name="filename">文件夹,不含路径和后缀</param>
        /// <param name="tm">枚举类-缩略图的样式</param>
        /// <returns>返回生成图片的路径</returns>
        public static string CreateThumbnail(object uploadObject, string uploaddir, string ext, int t_width, int t_height, string filename, ThumbModel tm)
        {
            System.Drawing.Image thumbnail_image = null;
            System.Drawing.Image original_image = null;
            System.Drawing.Bitmap final_image = null;
            System.Drawing.Graphics graphic = null;
            MemoryStream ms = null;


09
2013
08

谈.net mvc开发中gzip压缩的应用


压缩view的内容,可加过滤器

    public class GzipFilter : ActionFilterAttribute
    {
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            string acceptEncoding = filterContext.HttpContext.Request.Headers["Accept-Encoding"];
            if (String.IsNullOrEmpty(acceptEncoding)) return;
            var response = filterContext.HttpContext.Response;
            acceptEncoding = acceptEncoding.ToUpperInvariant();
            if (acceptEncoding.Contains("GZIP"))
            {
                response.AppendHeader("Content-Encoding", "gzip");
                response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
            }
            else if (acceptEncoding.Contains("DEFLATE"))
            {
                response.AppendHeader("Content-Encoding", "deflate");
                response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
            }
        }
    }


01
2013
08

学习并使用了两种linq to entity 的实现sql关键字in的查询方法

//构造Lambda语句

       private static Expression<Func<TElement, bool>> BuildWhereInExpression<TElement, TValue>(Expression<Func<TElement, TValue>> propertySelector, IEnumerable<TValue> values)
        {
            ParameterExpression p = propertySelector.Parameters.Single();
            if (!values.Any())
                return e => false;
            var equals = values.Select(value => (Expression)Expression.Equal(propertySelector.Body, Expression.Constant(value, typeof(TValue))));
            var body = equals.Aggregate<Expression>((accumulate, equal) => Expression.Or(accumulate, equal));
            return Expression.Lambda<Func<TElement, bool>>(body, p);
        }


24
2013
07

js与flash交互操作1


//flash里传送值


'<param name="flashvars" value="' + this.getFlashVars() + '" />'

//flash里获取值

this.uploadURL=root.loaderinfo.parameters.uploadURL


SWFUpload.prototype.getFlashVars = function () {

24
2013
07

flash 上传文件的actionscript

import flash.net.FileReference;
import flash.net.URLRequest;
import flash.net.FileFilter;
import flash.display.Sprite;
import flash.events.*;



var fileRef = new FileReference();
var fileListener = new Object();
var totalBytes:Number = 0;
var uploadedBytes:Number = 0;

20
2013
07

C#中npoi操作Excel[版本2.0.1读写2003、2007格式]

 2.0.1npoi的dll文件下载:NPOI2.0.1.zip


       public static void test1()
       {
           NpoiHelper np = new NpoiHelper();
           DataTable dt1 = np.ReadExcel(AppDomain.CurrentDomain.BaseDirectory + "1测试数据.xls", 2).Tables[0];//读2003格式数据
           DataSet ds1 = new DataSet();
           ds1.Tables.Add(dt1.Copy());
           ds1.AcceptChanges();
           string SaveFileName = "output1.xls";
           np.CreateExcel2003(SaveFileName, "sheet001", ds1, 0);//写2003格式数据

16
2013
07

子窗体与父窗体传值操作的js示例

//返回值给父窗体
function returnParent(value) {//获取子窗体返回值
   var parent = window.dialogArguments; //获取父页面
   //parent.location.reload(); //刷新父页面
   if (parent != null && parent != "undefined") {
       window.returnValue = value; //返回值

16
2013
07

js控制滚动条示例

function runToTop(){
currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
currentPosition-=10;
if(currentPosition>0)
{
window.scrollTo(0,currentPosition);
}


14
2013
07

使用LitJSON.dll处理json格式的数据示例

using LitJson;
       //可到 http://sourceforge.net/projects/litjson/?source=dlp  下载
       protected void Page_Load(object sender, EventArgs e)
       {
           String str = "{'name':'j1','id':1,'items':[{'itemid':1001,'itemname':'it1'},{'itemid':1002,'itemname':'it2'}]}";
           //*** 读取JSON字符串中的数据 *******************************            
           JsonData jd = JsonMapper.ToObject(str);
           String name = (String)jd["name"];
           int id = (int)(jd["id"]);
           Response.Write(string.Format("name:{0},id:{1}<br/>",name,id));
           JsonData jdItems = jd["items"];

}