工作笔记2

1、js的$('#form1').serialize()方法可以把表单中的元素转成一串参数

2、数据库有三种锁机制:共享锁、排它锁(其他进程不能读也不能改)、更新锁(其他进程可以读不能改,将来会升级为排它锁)和意向锁(作为标志,告诉其他进行表中有记录被锁,需等待)
1)一个资源上不能同时共存共享锁和排它锁,但可以共存两个共享锁;
2)T1:
begin tran
update table set column1='hello' where id=10

T2:
begin tran
update table set column1='world' where id=20
如果Id是主键,则上述的两个事务不会产生死锁,他们会根据索引直接定位到该记录然后加排它锁
如果Id不是主键没有索引,则会产生死锁,因为T1执行时会给Id=10的记录加排它锁,T2再执行会首
先进行全表扫描试图找到Id=20的记录,因为表中有了排它锁,所以全表扫描进行不下去就会等待

3、为了解决死锁,引入了更新锁:
更新锁的意思是:“我现在只想读,你们别人也可以读,但我将来可能会做更新操作,我已经获取了从共享锁(用来读)到排他锁(用来更新)的资格”。一个事务只能有一个更新锁获此资格。

4、arguments包含所有参数,可以点出来具体的参数

5、用MVC自带的Attribute验证太麻烦(比较两个字段的大小就不好判断了),前台绑定必须是强类型视图TextBoxFor(m=>m.value),此时不能对value字段进行类型转换,因为模板的字段仅用于展示

6、后退事件:history.go(-1);

7、图片刷新需要加个随机参数 Math.random()

<img id="image" src="/Content/images/statistic/LineChart.jpeg?r=0.48441014741547406">

8、把枚举转换成字典:
ViewData["resultlist"] = typeof(ServiceConfig.SERVICE_RESULT).ToDictionary().Select(s => new
SelectListItem() { Text = s.Key,Value = s.Value}).ToList<SelectListItem>()

9、a标签的href属性需要指定http:,若未指定则默认是http://localhost(中文的标点符号":"无法识别,会当做未指定协议名称来处理)

10、<a href="data:image/jpg;base64,code"/>64位编码显示图片流,高版本浏览器支持

11、代码配置开启目录浏览

<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>

12、js计算时间差

    function checkDate() {
        var date1 = Date.parse(new Date($("#staTime").val().replace(/-/g, "/")));  //开始时间
        var date2 = Date.parse(new Date($("#endTime").val().replace(/-/g, "/"))); //结束时间
        var date3 = date2 - date1;  //时间差的毫秒数

        //计算出相差天数
        var days = Math.floor(date3 / (24 * 3600 * 1000));
        if (days>2) {
            $.growl.warning({ message: "日期间隔超过两天,请重新选择", title: '提示' });
            return false;
        }
        return true;
    }

 13、decimal类型的数据初始化:decimal price=0m;

14、数据库可以修改自增长的id

  SET IDENTITY_INSERT notice on
  insert into notice(id,title) values(17,'淘宝订单自动发货说明')
  SET IDENTITY_INSERT notice off

15、查看EF报错的具体信息:

  System.Data.Entity.Validation.DbEntityValidationException,最简单的就是

try
{
// 写数据库
}
catch (DbEntityValidationException dbEx)
{

}
16、设置默认选中
  select标签 $('#select').val(['select1','select2'])
  radio标签 $(':radio').val(['radio1','radio2'])
  checkbox标签 $(':checkbox').val(['checkbox1','checkbox2'])
17、金额转成大写
    //金额转成大写
    function ConvertDX(num) {
        var strOutput = "";
        var strUnit = '仟佰拾亿仟佰拾万仟佰拾元角分';
        num += "00";
        var intPos = num.indexOf('.');
        if (intPos >= 0)
            num = num.substring(0, intPos) + num.substr(intPos + 1, 2);
        strUnit = strUnit.substr(strUnit.length - num.length);
        for (var i = 0; i < num.length; i++)
            strOutput += '零壹贰叁肆伍陆柒捌玖'.substr(num.substr(i, 1), 1) + strUnit.substr(i, 1);
        return strOutput.replace(/零角零分$/, '').replace(/零[仟佰拾]/g, '').replace(/零{2,}/g, '').replace(/零([亿|万])/g, '$1').replace(/零+元/, '').replace(/亿零{0,3}万/, '亿').replace(/^元/, "零元");
    };
18、Code First模式创建数据库:

  1、Install-Package EntityFramework

  2、Enable-Migrations -Force

  3、Add-Migration actionName

  4、Update-Database -Force

  注意:1) Enable-Migrations -StartUpProjectName ProjectName (如果在“Package Manager Console”中选择了默认项目可以不设置“-StartUpProjectName”参数;如果多次执行此命令可以添加-Force参数。)
     2)Update-Database -TargetMigration 201404240917497_SetDateCreatedToNullable (复原到指定版本201404240917497_SetDateCreatedToNullable)
       3) Get-Migrations 获取Migration的记录

  参考:http://www.cnblogs.com/libingql/p/3330880.html http://www.bkjia.com/Asp_Netjc/1007458.html

 19、ActiveX控件打印

<script>
    var printer;
    $(function () {
        if (request("p") != "true") {
            if (document.all.print_ocx.object != null) {
                try {
                    printer = document.getElementById("print_ocx");
                    printer.SET_LICENSES("上海商为电子商务有限公司", "E6F8119E6EE17DEFD00A1ECF1E83CA26", "", "");
                } catch (e) {
                    alert("没有安装打印控件");
                    window.open("http://www.lodop.net/uploads/file/sample/install_lodop32.zip");
                }
            }
        }
    })
    function printView() {
        printer.PRINT_INIT("12");
        printer.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
        printer.ADD_PRINT_URL(10, 10, 765, 270, 'http://' + window.location.host + "/PayOrderNew/DetailsPrint/@Model.id");
        printer.PREVIEW();
    }
    function print() {
        printer.PRINT_INIT("12");
        printer.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
        printer.ADD_PRINT_URL(10, 10, 765, 270, 'http://' + window.location.host + "/PayOrderNew/DetailsPrint/@Model.id");
        printer.print();
    }


</script>
<object id="print_ocx" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width="0" height="0"></object>

20、winform的DateTimePicker设置成选择时分秒:  当DateTimePicker控件被拖到界面时,它默认显示的是年月日,需要更改它的两个属性, dateTimePicker1.Format = DateTimePickerFormat.Time; dateTimePicker1.ShowUpDown = true; 第一个属性指定时间显示格式是hh:MM:ss; 第二个属性指定显示数字显示框,而不是显示下拉日历; 这样就可以选择小时分钟秒了。

21、播放视频:<embed src="http://cloud.video.taobao.com/play/u/1981672156/p/1/e/1/t/1/38199875.swf" allowfullscreen="true" flashvars="" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" ></embed>

22、开启进程,调用.exe并穿入参数

Process myprocess = new Process();
                ProcessStartInfo startInfo = new ProcessStartInfo(@"LoginBaidu.exe", baiduData);
                myprocess.StartInfo = startInfo;
                myprocess.StartInfo.UseShellExecute = false;

                myprocess.StartInfo.RedirectStandardOutput = true;
                myprocess.StartInfo.UseShellExecute = false;
                myprocess.StartInfo.CreateNoWindow = true;
                myprocess.Start();

                myprocess.WaitForExit();
                string cookies = myprocess.StandardOutput.ReadToEnd();

 

23、js创建对象的两种方式,其中函数名用大写表示是构造函数,不需要返回值(return)

        //第一种:
        var Person = function () {
            this.name = "宁";
            this.age = 18;
            this.gender = "男";
        }
        var p = new Person();
        console.log(p.name);
        //第二种:
        var person = {
            'name':"宁",
            'age':"18",
            'gender':"男"
        };
        console.log(p.name);
    //第二种用Json格式创建的对象不能复用,第一种可以:var p1 = new Person(); p2 = new Person();

 

posted @ 2015-08-24 19:03  望峰游云  阅读(257)  评论(0编辑  收藏  举报