window.showModalDialog模态对话框 & 值回传 & TreeView无刷新
摘要:要求: 点击父页面的text,弹出子页面,将在子页面TreeView选择的值传回,其中子页面树选中叶子节点应有颜色变化(显示选中),且页面不刷新。实现: 使用window.showModalDialog弹出子页面,设置页面返回值window.returnValue。---------------------------------------------------------------------------------------------------------------------------------------------父页面中只有一个text, 部分代码如下:<s
阅读全文
posted @
2011-09-25 23:30
PeterZhang
阅读(2698)
推荐(3)
读《程序设计实践》之二 算法与数据结构
摘要:1. 检索顺序检索。逐个查看每个数据元素是不是要找的那一个。顺序检索非常简单,但是它的工作量与被检索数据的数目成正比。这种检索也成为线性检索。二分检索。做检索的表格本身必须是排好序的,程序还必须知道表格的长度。算法复杂度:log(n)。 // lookup: binary search for value in arr; returen it's index int lookup(int arr[], int length, int val) { int index = -1; int low = 0; int high = length...
阅读全文
posted @
2011-09-18 10:39
PeterZhang
阅读(1512)
推荐(3)
读《程序设计实践》之一 风格
摘要:1. 名字 名字应该是非形式的、简练的、容易记忆的,如果可能的话,最好是能拼读的。 1.1 全局变量使用具有说明性的名字,局部变量用短名字。 1.2 保持一致性。相关的东西应该给以相关的名字,以说明它们的关系和差异。 1.3 函数采用动作性的名字。函数名应当用动作性的动词,后面可以跟着名字。 1.4 要准确。名字不仅是个标记,它还携带着给读程序人的信息。误用的名字可能引起奇怪的程序错误。 2. 表达式和语句 2.1 用缩行显示程序的结构。 2.2 使用表达式的自然形式。表达式应该写得你能大声念出来。含有否定运算的条件表达式比较难理解。 2.3 用加括号的方式排出二义性。 2...
阅读全文
posted @
2011-09-18 09:29
PeterZhang
阅读(1366)
推荐(1)
Winform Execute (executable) File and Display Result On the UI
摘要:Execute the executable file and display the result on the UI in WinForm.Note:Process, ProcessStartInfo => running executable file andpassingthe parameters(Method: RunCommand)Thread, ParameterizedThreadStart =>createa thread to executeRunCommand;otherwise the UI will be locked when executing th
阅读全文
posted @
2011-09-17 22:35
PeterZhang
阅读(699)
推荐(0)
WinForm UI 多线程 (线程间操作无效)
摘要:一个简单的Form, 按钮btnTest是enabled=false。在btnEnable的Click事件中 创建线程,在线程中尝试设置btnTest.Enabled = true; 发生异常:线程间操作无效: 从不是创建控件“btnTest”的线程访问它。代码如下: 1 using System; 2 using System.Threading; 3 using System.Windows.Forms; 4 5 namespace TestingUIThread 6 { 7 public partial class Form1 : Form 8 { 9 ...
阅读全文
posted @
2011-09-17 22:34
PeterZhang
阅读(25043)
推荐(6)
C#中执行PowerShell 脚本
摘要:在C#中调用powershell脚本,需要引用的namespace如下:using System.Management.Automation;using System.Management.Automation.Runspaces;添加System.Management.Automation.dll的引用,需要使用浏览,如果不知道位置,可以先在本机查找下。代码如下: 1 //RunPowershell(@".\x.ps1", ""); 2 private Collection<PSObject> RunPowershell(string fi
阅读全文
posted @
2011-09-17 21:33
PeterZhang
阅读(6417)
推荐(2)
Powershell 实现 Hyper-V 虚拟机 管理
摘要:本文包括使用powershell启动、关闭Hyper-V虚拟机,及获得虚拟机状态、虚拟机快照、根据快照回滚虚拟机。1. 启动 1 param 2 ( 3 [string]$hostServer = $(throw "param -host server is required."), 4 [string]$vmName = $(throw "param -virtual machine name is required.") 5 ) 6 7 function GetImageState 8 { 9 param10 (11 [string]...
阅读全文
posted @
2011-09-17 17:15
PeterZhang
阅读(5582)
推荐(1)
C# 实现 Hyper-V 虚拟机 管理
摘要:Hyper-V WMI Provider工具类如下:using System;using System.Collections.Generic;using System.Management;namespace MyNamespace{ #region Return Value of RequestStateChange Method of the Msvm_ComputerSystem Class //Return Value of RequestStateChange Method of the Msvm_ComputerSystem Class //This meth...
阅读全文
posted @
2011-09-17 15:04
PeterZhang
阅读(4963)
推荐(1)
Get the Type of the OS(Windows)
摘要:Get the operating system info by using the classes from namespace System.Management. OS: Windows XP, Vista, Win7, Windows Server 2008 and so on. 1 using System; 2 using System.Management; 3 4 namespace GetOSInfo_Peter 5 { 6 class Program 7 { 8 static void Main(string[] args) 9 ...
阅读全文
posted @
2011-09-17 13:38
PeterZhang
阅读(787)
推荐(2)
WinForm MDI
摘要:MDI,全称是多文档界面(Multiple Document Interface),主要应用于基于图形用户界面的系统中。其目的是同时打开和显示多个文档,便于参考和编辑资料。 下面是一个WinForm MDI小例子。 1 using System; 2 using System.Windows.Forms; 3 4 namespace WinFormMDI 5 { 6 public partial class FrmMain : Form 7 { 8 public FrmMain() 9 {10 InitializeCo...
阅读全文
posted @
2011-09-17 12:43
PeterZhang
阅读(8025)
推荐(2)
使用WebClient 获得网页内容或提交请求
摘要:WebClient 提供的向 URI 标识的资源发送数据和从 URI 标识的资源接收数据的公共方法。使用时需要将捕捉到的Http头部放入Headers中。(捕获http可以使用HttpWatch)WebClient wc = new WebClient();wc.Credentials = new NetworkCredential(username, password); //对于需要登录的网站设置验证信息wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");string
阅读全文
posted @
2011-09-17 12:33
PeterZhang
阅读(1175)
推荐(1)
HTTP 错误 404.13 - Not Found 请求筛选模块被配置为拒绝超过请求内容长度的请求。
摘要:问题:HTTP 错误 404.13 - Not Found 请求筛选模块被配置为拒绝超过请求内容长度的请求。原因:Web 服务器上的请求筛选被配置为拒绝该请求,因为内容长度超过配置的值(IIS 7 默认文件上传大小时30M)。解决:更改asp.net文件上传大小限制1. 修改IIS的applicationhost.config 文件位置: %windir%/system32/inetsrv/config/applicationhost.config 找到<requestFiltering>节点,该节点下默认没有 <requestLimits maxAllowedContent
阅读全文
posted @
2011-09-17 11:39
PeterZhang
阅读(18352)
推荐(4)
导入Excel和CSV文件
摘要:读取excel或csv文件中的数据暂时保存在DataTable中, 代码如下: public static DataTable ReadDataFromFile(string file, string sheet) { string strConn = ""; string extension = Path.GetExtension(file); string sqlStr = string.Empty; if (extension == ".csv") { strConn = stri...
阅读全文
posted @
2011-09-12 21:37
PeterZhang
阅读(1609)
推荐(1)