HOH
posts - 20,comments - 7,trackbacks - 0
     摘要: 窗体的基类:1/**//*=========================================================================2Copyright(C)2008.Allrightsreserved3CLR版本:2.0.50727.14334Createdby王端奎/HOHat2008-05-3118:27:435====================... 阅读全文
posted @ 2008-06-01 00:29 HOH 阅读(177) | 评论 (0)编辑
     方法很简单,看代码:

 1using System;
 2using System.IO;
 3using System.Runtime.Serialization.Formatters.Binary;
 4using System.Runtime.Serialization;
 5
 6namespace HOH
 7{
 8    /// <summary>
 9    /// Test 的摘要说明。
10    /// </summary>
11    /// 

12    [System.Serializable]
13    public class Test
14    {
15        private string _Name = string.Empty;
16        public string Name
17        {
18            get
19            {
20                return this._Name;
21            }

22            set
23            {
24                this._Name = value;
25            }

26        }

27        public Test()
28        {
29            //
30            // TODO: 在此处添加构造函数逻辑
31            //
32        }

33        public virtual Test Clone()
34        {
35            using(Stream stream = new MemoryStream())
36            {
37                Test test = new Test();
38                IFormatter formatter = new BinaryFormatter();
39                formatter.Serialize(stream,test);
40                stream.Position = 0;
41                return (Test)formatter.Deserialize(stream);
42            }

43        }

44    }

45}

46
posted @ 2007-11-23 10:14 HOH 阅读(70) | 评论 (0)编辑
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
            
internal struct TokPriv1Luid
        
{
            
public int Count;
            
public long Luid;
            
public int Attr;
        }


        [DllImport(
"kernel32.dll", ExactSpelling = true)]
        
internal static extern IntPtr GetCurrentProcess();

        [DllImport(
"advapi32.dll", ExactSpelling = true, SetLastError = true)]
        
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);

        [DllImport(
"advapi32.dll", SetLastError = true)]
        
internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);

        [DllImport(
"advapi32.dll", ExactSpelling = true, SetLastError = true)]
        
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
            
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);

        [DllImport(
"user32.dll", ExactSpelling = true, SetLastError = true)]
        
internal static extern bool ExitWindowsEx(int DoFlag, int rea);

        
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
        
internal const int TOKEN_QUERY = 0x00000008;
        
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
        
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
        
internal const int EWX_LOGOFF = 0x00000000;
        
internal const int EWX_SHUTDOWN = 0x00000001;
        
internal const int EWX_REBOOT = 0x00000002;
        
internal const int EWX_FORCE = 0x00000004;
        
internal const int EWX_POWEROFF = 0x00000008;
        
internal const int EWX_FORCEIFHUNG = 0x00000010;

        
private static bool DoExitWin(int DoFlag)
        
{
            
bool ok;
            TokPriv1Luid tp;
            IntPtr hproc 
= GetCurrentProcess();
            IntPtr htok 
= IntPtr.Zero;
            ok 
= OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
            tp.Count 
= 1;
            tp.Luid 
= 0;
            tp.Attr 
= SE_PRIVILEGE_ENABLED;
            ok 
= LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid);
            ok 
= AdjustTokenPrivileges(htok, falseref tp, 0, IntPtr.Zero, IntPtr.Zero);
            ok 
= ExitWindowsEx(DoFlag, 0);
            
return ok;
        }


        
/// <summary>
        
/// 重新启动
        
/// </summary>

        public static bool Reboot()
        
{
            
return DoExitWin(EWX_FORCE | EWX_REBOOT);
        }


        
/// <summary>
        
/// 关机
        
/// </summary>

        public static bool PowerOff()
        
{
            
return DoExitWin(EWX_FORCE | EWX_POWEROFF);
        }


        
/// <summary>
        
/// 注销
        
/// </summary>

        public static bool LogOff()
        
{
            
return DoExitWin(EWX_FORCE | EWX_LOGOFF);
        }
posted @ 2007-07-02 17:53 HOH 阅读(217) | 评论 (0)编辑
     摘要: .NET自带的ComboBox控件没有添加图片的功能,我们可以自己进行扩展,下面就是扩展类的代码:ComboBoxEx.csusingSystem;usingSystem.Windows.Forms;usingSystem.Windows.Forms.Design;usingSystem.Drawing;namespaceMengxianhui.ComboBoxEx{classComboBoxEx... 阅读全文
posted @ 2007-07-02 17:51 HOH 阅读(266) | 评论 (0)编辑
     摘要: 以下代码拷贝后可以直接运行1usingSystem;2usingSystem.Drawing;3usingSystem.Collections;4usingSystem.ComponentModel;5usingSystem.Windows.Forms;6usingSystem.Data;78namespaceWindowsApplication429{10/**////<summary&g... 阅读全文
posted @ 2007-07-02 17:47 HOH 阅读(569) | 评论 (0)编辑

                                                                                                           插入排序

        插入排序的核心思想是维持第I个元素左边的一组元素是有序的。

 1    private void CR(double[] list)
 2        {
 3            for(int i=1;i<list.Length;i++)
 4            {
 5                double t=list[i];
 6                int j=i;
 7                while((j>0)&&(list[j-1]>t))
 8                {
 9                    list[j]=list[j-1];
10                    --j;
11                }

12                list[j]=t;
13            }

14        }
posted @ 2007-07-02 16:47 HOH 阅读(55) | 评论 (0)编辑

选择排序


选择排序 的核心是每遍历一次集合,只记录下最大元素或者最小元素的位置,然后根据你的需要把这个最大或者最小元素的位置跟第一个或者第二个元素进行交换,第二次遍历就从第二个元素开始,直到最后一个元素结束。如下:
 1
 2        private void XZ(double[] array)
 3        {
 4            double y;//中转值
 5            for(int i=0;i<array.Length;i++)
 6            {
 7                int x = i ;//用来记录最小数的位置
 8                for(int j=i;j<array.Length;j++)
 9                {
10                    if(array[x]>array[j])
11                    {
12                        x = j;
13                    }

14                    if(j == array.Length-1)
15                    {
16                        y = array[i];
17                        array[i] = array[x];
18                        array[x] = y;
19                    }

20                }

21            }

22        }
posted @ 2007-07-02 13:58 HOH 阅读(56) | 评论 (0)编辑

冒泡排序

         冒泡排序 的核心知道思想是顺序的把相邻的两个元素来比较,根据你的需要,把大的或者是小的放在前面或者后面,也就是相互交换位置,直到最后相邻的两个元素都是前面的元素大于后面或者是小于后面的元素为止。请看下面的例子。
 1        private void MP(double[] array)
 2        {
 3            double x ;
 4            for(int i=0;i<array.Length;i++)
 5            {
 6                for(int j=0;j<array.Length-i-1;j++)
 7                {
 8                    if(array[j]>array[j+1])
 9                    {
10                        x = array[j];
11                        array[j] = array[j+1];
12                        array[j+1= x;
13                    }

14                }

15            }

16        }
posted @ 2007-07-01 16:59 HOH 阅读(123) | 评论 (0)编辑

 

--更改某个表 
exec sp_changeobjectowner 'tablename','dbo' 
--存储更改全部表 
CREATE PROCEDURE dbo.User_ChangeObjectOwnerBatch 
@OldOwner as NVARCHAR(128), 
@NewOwner as NVARCHAR(128
AS 

DECLARE @Name as NVARCHAR(128
DECLARE @Owner as NVARCHAR(128
DECLARE @OwnerName as NVARCHAR(128

DECLARE curObject CURSOR FOR 
select 'Name' = name, 
'Owner' = user_name(uid) 
from sysobjects 
where user_name(uid)=@OldOwner 
order by name 

OPEN curObject 
FETCH NEXT FROM curObject INTO @Name@Owner 
WHILE(@@FETCH_STATUS=0
BEGIN 
if @Owner=@OldOwner 
begin 
set @OwnerName = @OldOwner + '.' + rtrim(@Name
exec sp_changeobjectowner @OwnerName@NewOwner 
end 
-- select @name,@NewOwner,@OldOwner 

FETCH NEXT FROM curObject INTO @Name@Owner 
END 

close curObject 
deallocate curObject 
posted @ 2007-06-27 13:20 HOH 阅读(48) | 评论 (0)编辑
今天遇到个怪问题
用SqlDataReader 从一个数据库中取数据插入到另外一个数据库的时候,竟然总是少插入了许多的记录
加了个排序就好了
搞不懂是为什么
posted @ 2007-06-27 13:17 HOH 阅读(24) | 评论 (0)编辑