node.js读写文件例子

Continue Read..

fs的open,read,write

直接看代码

var fs = require('fs');

var filepath = './1.jpg';
var filepath2 = './2.jpg';
fs.open(filepath, 'r', '0777', function(err,fd){
	fs.stat(filepath,function(err, stats){
		var filesize = stats.size;
		//console.log(stats);

		var buffer = new Buffer(filesize);
		var offset = 0;
		var length = filesize;
		var position = null;
		fs.read(fd, buffer, offset, length, position, function(err, bytesRead){
			console.log(buffer.length);
			console.log(bytesRead +':'+buffer);

			fs.open(filepath2, 'w+', '0777', function(err,fd2){
				fs.write(fd2, buffer, offset, length, position,function(err, written){
					console.log(written);	
				});
				fs.close(fd);
				fs.close(fd2);
			});
			
		});
	});
});

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【PHP】修改图片大小

Continue Read..
function chImageSize ($img,$max_w,$max_h) 
$size = @getimagesize($img); 
$w = $size[0]; 
$h = $size[1]; 
//计算缩放比例 
@$w_ratio = $max_w / $w; 
@$h_ratio = $max_h / $h; 
//决定处理后的图片宽和高 
if( ($w <= $max_w) && ($h <= $max_h) ) 
$tn['w'] = $w; 
$tn['h'] = $h; 
else if(($w_ratio * $h) < $max_h) 
$tn['h'] = ceil($w_ratio * $h); 
$tn['w'] = $max_w; 
else 
$tn['w'] = ceil($h_ratio * $w); 
$tn['h'] = $max_h; 
$tn['rc_w'] = $w; 
$tn['rc_h'] = $h; 
return $tn ; 
}

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

C# DropDownList数据绑定 enum类型

Continue Read..

点击查看原图

<asp:DropDownList ID="DDLType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DDLType_SelectedIndexChanged" style="width:135px;"></asp:DropDownList>

1.绑定数据

(1)方法一:

//药柜类型

            foreach (ChestType co in Enum.GetValues(typeof(ChestType)))

            {

                string _val = co.ToString();

                string _v = ((Int32)Enum.Parse(typeof(ChestType), _val)).ToString();

                string _key = GetEnumDesc(typeof(ChestType), co);

                DDLType.Items.Add(new ListItem(_key, _v));

            }

///
    /// 获得Enum类型description
    /// 创建人:Porschev
    /// 创建时间:2011-7-19
    ///
    ///枚举的类型
    ///枚举值
    ///string
    public static string GetEnumDesc(Type enumType, object val)
    {
        string enumvalue = System.Enum.GetName(enumType, val);
        if (string.IsNullOrEmpty(enumvalue))
        {
            return "";
        }
        System.Reflection.FieldInfo finfo = enumType.GetField(enumvalue);
        object[] enumAttr = finfo.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), true);
        if (enumAttr.Length > 0)
        {
            System.ComponentModel.DescriptionAttribute desc = enumAttr[0] as System.ComponentModel.DescriptionAttribute;
            if (desc != null)
            {
                return desc.Description;
            }
        }
        return enumvalue;
    }

(2)方法二:

BindEnumList(DDLState, typeof(ItemState), new ListItem("请选择", "-1"));
        DDLState.SelectedValue = "1";

 

/// <summary>
    /// Mr.Tom 下拉列表框绑定枚举
    /// </summary>
    /// <param name="droplist">DropDownList名称</param>
    /// <param name="enumType">要绑定的枚举类型</param>

    /// <param name="li">第一项要显示的.eg:--请选择--</param>
    /// <returns></returns>
    public static void BindEnumList(DropDownList droplist, Type enumType, ListItem li)
    {
        droplist.Items.Clear();
        if (enumType.IsEnum == false)
        {
            return;
        }
        droplist.Items.Add(li);

        Type typeDescription = typeof(DescriptionAttribute);
        System.Reflection.FieldInfo[] fields = enumType.GetFields();
        string strText = string.Empty;
        string strValue = string.Empty;
        foreach (FieldInfo field in fields)
        {
            if (field.IsSpecialName) continue;
            strValue = field.GetRawConstantValue().ToString();

            object[] arr = field.GetCustomAttributes(typeDescription, true);
            if (arr.Length > 0)
            {
                strText = (arr[0] as DescriptionAttribute).Description;
            }
            else
            {
                strText = field.Name;
            }

            droplist.Items.Add(new ListItem(strText, strValue));
        }
    }

 

2.获取数据

DDLType.SelectedValue = chestInfo.ChestType.GetHashCode().ToString();

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权