2012年5月4日

js中时间比较最简洁的方法

想必大家也为js中时间比较所烦恼;

发现一个简单的方法,高手勿喷哦。

本人菜鸟 嘿嘿

代码:

1             var d1 = new Date("2012-12-12 12:12:12".replace(/-/g, "/"));
 2 
 3             var d2 = new Date();
 4 
 5             if (Date.parse(d1) - Date.parse(d2) < 0) {
 6                 alert("d1小于d2");
 7             }
 8             if (Date.parse(d1) - Date.parse(d2) = 0) {
 9                 alert("d1等于d2");
10             }
11             if (Date.parse(d1) - Date.parse(d2) > 0) {
12                 alert("d1大于d2");
13             }

posted @ 2012-05-04 18:53 强哥咋了 阅读(20) 评论(0) 编辑

2012年5月3日

控制台程序“模拟”WEB请求 Post方式

1.“模拟”WEB请求 主要用的命名空间 System.Net。

2.用到的类 HttpWebRequest  其中Create方法创建个实例。

3.如图:

private static string HttpWebRequest_Post(string strURL, string strParams)
        {
            string returnContent = string.Empty;
            try
            {
                Encoding myEncoding = Encoding.GetEncoding("UTF-8");
                Uri myUri = new Uri(strURL);
                byte[] paramBytes = myEncoding.GetBytes(strParams);
                HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
                myWebRequest.ContentType = "application/x-www-form-urlencoded";
                myWebRequest.AllowAutoRedirect = true;
                myWebRequest.Method = "POST";
                myWebRequest.Timeout = 120000;
                myWebRequest.ContentLength = paramBytes.Length;

                //发送
                Stream requestStream = myWebRequest.GetRequestStream();
                requestStream.Write(paramBytes, 0, paramBytes.Length);
                requestStream.Close();

                //返回
                HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
                StreamReader myStreamReader = new StreamReader(myWebResponse.GetResponseStream(), myEncoding);
                returnContent = myStreamReader.ReadToEnd();
                myStreamReader.Close();
            }
            catch (Exception ex)
            {
                return string.Empty;
            }
            return returnContent;
        }

PS:有一些网站有漏洞(后台没有验证等),可以用此方法模拟请求绕过客户端的验证,进行“瞎搞”。

posted @ 2012-05-03 18:44 强哥咋了 阅读(26) 评论(0) 编辑

2012年4月24日

WPF中MVVM

简单对 WPF中的MVVM的理解:

MVVM模式主要是可以分工明确,美工专做界面,代码专门给程序员,分工明确,效率高。

一个View至少对应一个ViewModel,主要是要熟悉Binding和Command 个人觉得事件很重要哦。

上图:可以简单的理解一下。

posted @ 2012-04-24 12:08 强哥咋了 阅读(28) 评论(0) 编辑

2012年4月23日

初识WPF

 

初始WPF,感觉还不错,可能因为WEB有关系,现在是做web项目突然想写点WPF的程序玩玩,结果自我感觉不太难 嘿嘿上代码。

在网上找了个简单的例子,试着做了做。

有些乱 见谅。嘿嘿


<Window x:Class="WPF1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <ListView Name="listview1" Grid.Row="0" MinWidth="280">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="70" Header="ID" DisplayMemberBinding="{Binding Path=ID}"></GridViewColumn>
                    <GridViewColumn Width="70" Header="Name" DisplayMemberBinding="{Binding Path=Name}"></GridViewColumn>
                    <GridViewColumn Width="70" Header="Gender" DisplayMemberBinding="{Binding Path=Gender}"></GridViewColumn>
                    <GridViewColumn Width="70" Header="Age" DisplayMemberBinding="{Binding Path=Age}"></GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        <WrapPanel Grid.Row="1" Orientation="Horizontal" DataContext="{Binding ElementName=listview1,Path=SelectedItem}">
            <StackPanel Orientation="Horizontal" Margin="5,2,5,2">
                <TextBlock Text="ID:"></TextBlock>
                <TextBox MinWidth="100" Text="{Binding Path=ID}"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="5,2,5,2">
                <TextBlock Text="Name:"></TextBlock>
                <TextBox MinWidth="100" Text="{Binding Path=Name}"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="5,2,5,2">
                <TextBlock Text="Gender:"></TextBlock>
                <TextBox MinWidth="100" Text="{Binding Path=Gender}"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="5,2,5,2">
                <TextBlock Text="Age:"></TextBlock>
                <TextBox MinWidth="100" Text="{Binding Path=Age}"/>
            </StackPanel>
        </WrapPanel>
    </Grid>
</Window>


界面:


后台代码:

Model:

public class Person
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public bool Gender { get; set; }
        public int Age { get; set; }
    }

DAL:

public class PersonDAL     {        

private static List<Person> _listPerson;

        public PersonDAL()        

{           

  _listPerson = new List<Person>();       

  }

        public void AddPerson(Person p)       

  {

            _listPerson.Add(p);        

}

        public List<Person> GetAllPerson()        

{

            return _listPerson;      

   }   

  }

BLL:

 public class PersonBLL     {        

private PersonDAL PD;

   public PersonBLL()   {    

    PD = new PersonDAL();          

   PD.AddPerson(new Person() { ID = 1, Name = "s1", Gender = true, Age = 10 });          

   PD.AddPerson(new Person() { ID = 2, Name = "s2", Gender = true, Age = 20 });         

   PD.AddPerson(new Person() { ID = 3, Name = "s3", Gender = true, Age = 30 });          

   PD.AddPerson(new Person() { ID = 4, Name = "s4", Gender = true, Age = 40 });          

   PD.AddPerson(new Person() { ID = 5, Name = "s5", Gender = true, Age = 50 });      

   }

        public List<Person> GetAllPerson()     

   { 

return PD.GetAllPerson();

    }   

  }

前台的后台代码:

public partial class MainWindow : Window     {     

    public MainWindow()         {        

     InitializeComponent();         

    this.Loaded += new RoutedEventHandler(MainWindow_Loaded);    

     }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)       

  {        

     this.listview1.ItemsSource = new PersonBLL().GetAllPerson();    

     }   

  }

 

 

posted @ 2012-04-23 12:16 强哥咋了 阅读(466) 评论(2) 编辑

2012年2月17日

Windows Phone 7 命名空间介绍

  Microsoft.Devices:包含与Windows Phone 7手机相关的硬件设备的类型,如摄像头(Camera),手机设备的环境信息(Environment),音乐与视频的信息(MediaHistory),手机相机拍照(PhotoCamera),手机震动功能等等。

  Microsoft.Devices.Radio:想必大家看到这个名字就多少能猜到,这是跟收音机有关的,那么它包含的的却是无线电设备的控制功能。

  Microsoft.Devices.Sensors:与传感器相关的信息,比如应用程序设备的加速,类似于罗盘的传感器,陀螺仪传感器,手机设备的方位和运动信息的控制等。

  Microsoft.Phone:包含了图片与背景图片的解码器。

  Microsoft.Phone.Controls:包含了PhoneApplicationPage(普通页面),Panorama(大屏幕内被拆分多个子块的页面),Pivot(选项卡式界面),WebBrowser(浏览器控件)。

  Microsoft.Phone.Controls.Maps:包含在Bing Map中使用的公共类型的许多Windows Phone控件。

  Microsoft.Phone.Controls.Maps.AutomationPeers:包含一些用于自动化测试的类。

  Microsoft.Phone.Controls.Maps.Core:包含许多核心控制的类,可以帮助我们更自由化的自己定制地图模式或地图。

  Microsoft.Phone.Controls.Maps.Design:包含一些主要用于转换功能的Converter类型。大多都是将一个对象转换成某个类型。

  Microsoft.Phone.Controls.Maps.Overlays:包含一些包装类型,比如Logo,ZoomBar这种放大缩小的辅助类型等等。

  Microsoft.Phone.Controls.Maps.Platform:包含几个关于图形操作的类型。

  Microsoft.Phone.Controls.Primitives:包含一些Windows Phone独有的控件模型,可供开发者进行自我扩展。

  Microsoft.Phone.Info:包含检索设备相关信息的类型。

  Microsoft.Phone.Marketplace:提供对程序访问检索权限信息的类型。

  Microsoft.Phone.Net.NetworkInformation:提供了一些网络互操作的类型。

  Microsoft.Phone.Notification:提供用于接收通知,从微软推送通知服务的一些类型。

  Microsoft.Phone.Reactive:提供了多线程,异常,事件,释放等操作的类型。

  Microsoft.Phone.Shell:包含了ApplicationBar(托盘)等类型。

  Microsoft.Phone.Tasks:包含了许多任务的功能,如调用打电话,邮件,短信,等等。

posted @ 2012-02-17 12:03 强哥咋了 阅读(43) 评论(0) 编辑

2012年2月8日

wp7之路开始

摘要: 最近开始关注wp7的开发,不知道晚不晚。在网上找了各种资料关于wp7开发的资料,咱们博客园资料还是不少的哦,哈哈....买了一本《Windows Phone 7 应用开发指南》 还没有到手里,不知道怎样,应该不会很差吧。在网上看到也有人说wp7将来肯定失败! 我想对你说,无论成功失败,我经历了这就是我的财富。谢谢阅读全文

posted @ 2012-02-08 16:42 强哥咋了 阅读(24) 评论(0) 编辑

2011年3月29日

MyPetShop

摘要: 最近 自己在写Microsoft的petshop项目,很经典的项目。(待续)以下是我对petshop的肤浅(可以说是相当肤浅)理解:可以分为以下几步1,商品的呈现2,购物车3,缓存4,订单其中几张结构图让我颇有提高:阅读全文

posted @ 2011-03-29 14:50 强哥咋了 阅读(113) 评论(0) 编辑