摘要: 接着昨天的博客 零代码配置xml维护单表 ,今天上午上班啥事没做也没啥事做,一心想接着昨天的文章搞一个简单版的demo,然后就整理出了这么个阉割版本的demo,在这个版本中,去掉了分层和自定义控件扩展,sql操作代码也放在了页面中,有兴趣的可以看昨天那篇文章自行扩展。 demo结构目录如下: crud操作在于三个页面commonAdd.aspx(添加页),commonEdit.aspx(编辑查看页...阅读全文
posted @ 2010-01-22 11:20 记忆的森林 阅读(532) 评论(4) 编辑
摘要: 小弟关注cnblogs有一段时间了,每天上班第一件事是打开博客园关注里面的最新博客(当然开会或其它特殊情况就例外了,哈哈),这段时间工作不忙,刚刚申请开通了属于自己的blog,没想到cnblogs的管理员办事效率如此之高(真是令人倍感兴奋!),从提交申请到审核通过只等待了31分钟,在此先谢过啦。这是我的第一篇blog,希望各位帅哥美女不要扔太多砖头鸡蛋(小弟害怕太暴力哦!),写得不好的地方,也希望...阅读全文
posted @ 2010-01-21 13:27 记忆的森林 阅读(289) 评论(8) 编辑

   前段时间看见别人写的一篇 c#调用网络摄像头的,正好搬到的新的地方,这地儿洗脸的地方木有镜子用,每天起床,头发总是很乱,也不想专门去超市买个镜子,又正好笔记本上有个摄像头,平时也木有MM跟偶视频聊天,纯粹的浪费了一个多好的功能,突发"奇想",视频不就是实时的吗,何不写个客户端程序,把摄像头当镜子用呢,想到此处,所以把别人的代码copy过来以定制偶整理头发的镜子,不过发现copy过来的代码偶尔不工作,重新修改了下,基本当个镜子木有问题了(当然木有镜子清晰!),只是有一个问题至今还木解决,视频源窗口偶尔会弹出来,不知道哪个筒子能解决,如下图(左),另外一张就是偶的镜子程序,刚下班回来,头发还不乱,稍加整理了下,截个了屏 #_#

 刚下班,所以人有点累,废话不多话,直接上代码,如下,希望对这个有兴趣的筒子也可以借鉴下,大家相互借鉴,相信总是可以做得更好 :)

 

namespace webcam
{
    
using System;
    
using System.Runtime.InteropServices;
    
using System.Windows.Forms;

    
/// <summary>
    
/// Leon's webcam mirror
    
/// </summary>
    public partial class WebCam : Form
    {
        
/// <summary>
        
/// Webcam handle. 
        
/// </summary>
        private int hHwnd;

        
public WebCam()
        {
            InitializeComponent();
        }

        
public struct videohdr_tag
        {
            
public byte[] lpData;
            
public int dwBufferLength;
            
public int dwBytesUsed;
            
public int dwTimeCaptured;
            
public int dwUser;
            
public int dwFlags;
            
public int[] dwReserved;
        }

        
#region P/Invoke

        [DllImport(
"avicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        
public static extern int capCreateCaptureWindowA([MarshalAs(UnmanagedType.VBByRefStr)]   ref   string lpszWindowName, int dwStyle, int x, int y, int nWidth, short nHeight, int hWndParent, int nID);
        [DllImport(
"avicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        
public static extern bool capGetDriverDescriptionA(short wDriver, [MarshalAs(UnmanagedType.VBByRefStr)]   ref   string lpszName, int cbName, [MarshalAs(UnmanagedType.VBByRefStr)]   ref   string lpszVer, int cbVer);
        [DllImport(
"user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        
public static extern bool DestroyWindow(int hndw);
        [DllImport(
"user32", EntryPoint = "SendMessageA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        
public static extern int SendMessage(int hwnd, int wMsg, int wParam, [MarshalAs(UnmanagedType.AsAny)]   object lParam);
        [DllImport(
"user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        
public static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
        [DllImport(
"vfw32.dll")]
        
public static extern string capVideoStreamCallback(int hwnd, videohdr_tag videohdr_tag);
        [DllImport(
"vicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        
public static extern bool capSetCallbackOnFrame(int hwnd, string s);

        
#endregion

        
/// <summary>
        
/// Initialize webcam and display the video in a panel.
        
/// </summary>
        
/// <returns></returns>
        private bool InitializeWebcam()
        {
            
bool ok = false;

            
int intWidth = this.panel1.Width;
            
int intHeight = this.panel1.Height;
            
int intDevice = 0;
            
string refDevice = intDevice.ToString();

            
//Create vedio and get the window handle.
            hHwnd = WebCam.capCreateCaptureWindowA(ref refDevice, 134217728000640480this.panel1.Handle.ToInt32(), 0);
           
            
if (WebCam.SendMessage(hHwnd, 0x40a, intDevice, 0> 0)
            {
                WebCam.SendMessage(
this.hHwnd, 0x435-10);
                WebCam.SendMessage(
this.hHwnd, 0x4340x420);
                WebCam.SendMessage(
this.hHwnd, 0x432-10);
                WebCam.SetWindowPos(
this.hHwnd, 100, intWidth, intHeight, 6);

                ok 
= true;
            }
            
else
            {
                WebCam.DestroyWindow(
this.hHwnd);
            }

            
return ok;
        }
        
/// <summary>
        
/// App run, then invoke the webcam till successfully.
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>
        private void WebCam_Load(object sender, EventArgs e)
        {
            
bool ok = false;

            
while (!ok)
            {
                ok 
= this.InitializeWebcam();
                System.Threading.Thread.Sleep(
100);
            }
        }
        
private void CloseWebcam()
        {
            
if (this.hHwnd > 0)
            {
                WebCam.SendMessage(
this.hHwnd, 0x40b00);
                WebCam.DestroyWindow(
this.hHwnd);
            }
        }
        
/// <summary>
        
/// when close window, destroy the webcam window.
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>
        private void WebCam_FormClosed(object sender, FormClosedEventArgs e)
        {
            CloseWebcam();
        }
        
/// <summary>
        
/// when window size changed, resize webcam pic.
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>
        private void WebCam_SizeChanged(object sender, EventArgs e)
        {
            WebCam.SetWindowPos(
this.hHwnd, 100,this.Width,this.Height, 6);
        }
    }
}

 

排列控件的Designer代码就不贴了,就一个panel控件,相信大家一看就懂的:) , 实现这个“镜子”的代码,所花的时间还真的比去超市的买个镜子花的时间少哈,而且还变废为宝,c#真不愧是快餐语言,够快,够方便的 :)

posted @ 2011-08-12 19:54 记忆的森林 阅读(1115) 评论(7) 编辑
摘要: 好久没有做web了,JSON目前比较流行,闲得没事,所以动手试试将对象序列化为JSON字符(尽管DotNet Framework已经有现成的库,也有比较好的第三方开源库),而且只是实现了处理简单的类型,并且DateTime处理的也不专业,有兴趣的筒子可以扩展,代码比较简单,反序列化木有实现:( ,直接贴代码吧,都有注释了,所以废话不多说 :)测试类///<summary>///NestedclassofPerson.///</summary>publicclassHouse{publicstringName{get;set;}publicdoublePrice{get;阅读全文
posted @ 2011-08-12 17:15 记忆的森林 阅读(2887) 评论(13) 编辑

   接着昨天的博客 零代码配置xml维护单表 ,今天上午上班啥事没做也没啥事做,一心想接着昨天的文章搞一个简单版的demo,然后就整理出了这么个阉割版本的demo,在这个版本中,去掉了分层和自定义控件扩展,sql操作代码也放在了页面中,有兴趣的可以看昨天那篇文章自行扩展。

   demo结构目录如下:

 

  crud操作在于三个页面commonAdd.aspx(添加页),commonEdit.aspx(编辑查看页),commonQuery.aspx(列表页),另外加一个配置文件config.xml

,config.xml文件对应了数据库建立的表配置,另外app_code/t_column.cs是对xml表配置实体的一个封装,每个配置信息代表什么意思,里面都已经注释了

     数据库放在app_data里面,自己还原

   下面对demo作简单介绍:

   1.建立数据库:(偷个懒,列直接用中文了)

配置xml

 

 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <root>
 3   <table id="1" key="id" name="t_demo" cnname="测试演示" order="addtime desc">
 4     <column name="id" cnname="编号" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="n" regex="" tip="" type="key"></column>
 5     <column name="姓名" cnname="姓名" ftable="" fvalue="" ftext="" isfilter="y" visible="y" allownull="n" regex="" tip="姓名必须填写哦!" type="textbox"></column>
 6     <column name="性别" cnname="性别" ftable="t_sex" fvalue="id" ftext="name" isfilter="n" visible="y" allownull="n" regex="" tip="" type="dropdownlist"></column>
 7     <column name="年龄" cnname="年龄" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="n" regex="^\d+$" tip="" type="textbox"></column>
 8     <column name="出生日期" cnname="出生日期" ftable="" fvalue="" ftext="" isfilter="n" visible="n" allownull="y" regex="^\d{4}-\d{1,2}-\d{1,2}$" tip="" type="textbox"></column>
 9     <column name="个人简介" cnname="个人简介" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="y" regex="" tip="" type="mtextbox"></column>
10     <column name="技能描述" cnname="技能描述" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="y" regex="" tip="" type="mtextbox"></column>
11     <column name="语言" cnname="语言" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="y" regex="" tip="" type="textbox"></column>
12     <column name="国家" cnname="国家" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="y" regex="" tip="" type="textbox"></column>
13     <column name="省" cnname="省" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="y" regex="" tip="" type="textbox"></column>
14     <column name="市" cnname="市" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="y" regex="" tip="" type="textbox"></column>
15     <column name="家庭地址" cnname="家庭地址" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="y" regex="" tip="" type="textbox"></column>
16     <column name="兴趣爱好" cnname="兴趣爱好" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="y" regex="" tip="" type="mtextbox"></column>
17     <column name="qq" cnname="qq" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="y" regex="" tip="" type="textbox"></column>
18     <column name="msn" cnname="msn" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="y" regex="" tip="" type="textbox"></column>
19     <column name="addtime" cnname="时间" ftable="" fvalue="" ftext="" isfilter="n" visible="y" allownull="n" regex="" tip="" type="autodatetime"></column>
20   </table>
21 </root>

 

 

运行default.aspx,直接跳转到commonquery.aspx?id=1

 

 

点击添加按钮

 

 

点击编辑按钮

 

 

点击删除按钮

 

 

点击查看链接

 

 

 demo.rar

/Files/leonwang/db.rar 

 

posted @ 2010-01-22 11:20 记忆的森林 阅读(532) 评论(4) 编辑
摘要: 小弟关注cnblogs有一段时间了,每天上班第一件事是打开博客园关注里面的最新博客(当然开会或其它特殊情况就例外了,哈哈),这段时间工作不忙,刚刚申请开通了属于自己的blog,没想到cnblogs的管理员办事效率如此之高(真是令人倍感兴奋!),从提交申请到审核通过只等待了31分钟,在此先谢过啦。这是我的第一篇blog,希望各位帅哥美女不要扔太多砖头鸡蛋(小弟害怕太暴力哦!),写得不好的地方,也希望...阅读全文
posted @ 2010-01-21 13:27 记忆的森林 阅读(289) 评论(8) 编辑