sqlcmd -s 127.0.0.1 -i g:1.sql -U sa -P 123456
posted @ 2008-08-20 10:49 陈旭85 阅读(25) | 评论 (0)编辑
     摘要: [代码][代码] 阅读全文
posted @ 2008-08-09 09:06 陈旭85 阅读(16) | 评论 (0)编辑

 

Code
posted @ 2008-08-09 08:59 陈旭85 阅读(15) | 评论 (0)编辑
Code
posted @ 2008-08-09 08:56 陈旭85 阅读(67) | 评论 (0)编辑

net use \\192.168.1.2 ""  /user:"Administrator"

 

 

 private  string CmdPing(string strIp)
        {

            Process p = new Process();

            p.StartInfo.FileName = "cmd.exe";

            p.StartInfo.UseShellExecute = false;

            p.StartInfo.RedirectStandardInput = true;

            p.StartInfo.RedirectStandardOutput = true;

            p.StartInfo.RedirectStandardError = true;

            p.StartInfo.CreateNoWindow = true;

            string pingrst;

            p.Start();

            p.StandardInput.WriteLine("ping -n 1 " + strIp);

            p.StandardInput.WriteLine("exit");

            string strRst = p.StandardOutput.ReadToEnd();

            if (strRst.IndexOf("(0% loss)") != -1)

                pingrst = "连接";

            else if (strRst.IndexOf("Destination host unreachable.") != -1)

                pingrst = "无法到达目的主机";

            else if (strRst.IndexOf("Request timed out.") != -1)

                pingrst = "超时";

            else if (strRst.IndexOf("Unknown host") != -1)

                pingrst = "无法解析主机";

            else

                pingrst = strRst;

            p.Close();

            return pingrst;

        }

 

 

tcp 发送

public static bool NetworkCommand(string CommandText, string Ip, string Port)
        {
            try
            {
                byte[] bt = System.Text.Encoding.Default.GetBytes(CommandText);

                IPEndPoint ep = new IPEndPoint(IPAddress.Parse(Ip), Convert.ToInt32(Port));
                TcpClient tc = new TcpClient();
                tc.Connect(ep);

                NetworkStream nstream = tc.GetStream();
                nstream.Write(bt, 0, bt.Length);
                tc.Close();

                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return false;
        }

 

 

tcp监听

private void SocketLis()
        {
            Int32 port = Config.SocketPort;
            IPAddress localAddr = IPAddress.Any;//(/*"117.25.162.138"/*"127.0.0.1"*/);
           // IPAddress localAddr = IPAddress.Parse("127.0.0.1");
            tcl = new TcpListener(localAddr, port);
            tcl.Start();
            DrawListView("在" + port.ToString() + "端口启动监听");
            while (true)
            {
               
                TcpClient tc = tcl.AcceptTcpClient();
                DrawListView("收到网络上的信息");
                NetworkStream netstream = tc.GetStream();
                byte[] bt = new byte[256];
                int i;
                string revdate="";
                DateTime dt;
                while ((i = netstream.Read(bt, 0, bt.Length)) != 0)
                {
                    revdate = System.Text.Encoding.Default.GetString(bt, 0, i);
                }
                DrawListView(revdate);
                try
                {
                    dt = DateTime.Parse(revdate);
                    TimeSpan ts = dt - DateTime.Now;
                    if (ts.Ticks > 0)
                    {
                        tr.Change(ts, new TimeSpan(-1));  
                    }
                }
                catch(Exception ex)
                {
                    DrawListView("Socket接收出错:"+ex.Message);
                }
            }
        }

posted @ 2008-07-25 09:45 陈旭85 阅读(22) | 评论 (0)编辑
using System;
using System.Collections.Generic;
using System.Text;

using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace jieshou
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
                Jie();
        }


        
static void Jie()
        
{
            
int i = 0;

             Socket socket 
= new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);//初始化一个Scoket协议

            IPEndPoint iep 
= new IPEndPoint(IPAddress.Any, 3000);//初始化一个侦听局域网内部所有IP和指定端口

            EndPoint ep 
= (EndPoint)iep;

            socket.Bind(iep);
//绑定这个实例

            
while (true)
            
{
                
byte[] buffer = new byte[1024];//设置缓冲数据流

                socket.ReceiveFrom(buffer, 
ref ep);//接收数据,并确把数据设置到缓冲流里面

                Console.WriteLine(Encoding.Unicode.GetString(buffer).TrimEnd(
'\u0000'+ " " + i.ToString());

                i
++;
            }

        }

    }

}




using System;
using System.Collections.Generic;
using System.Text;

using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace guangbo
{
    
class Program
    
{
        
//private Thread trd;
        public int num = 0;

        
static void Main(string[] args)
        
{
            
//Thread trd = new Thread(new ThreadStart(guangbo()));
            
//trd.IsBackground = true;
            
//trd.Start();
            for (int i = 0; i < 10000; i++)
            
{
                Console.WriteLine(i);
                
//Thread.Sleep(10000);
                Guang();
            }

            Console.ReadKey();
        }


        
static  void Guang()
        
{
            Socket sock 
= new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);//初始化一个Scoket实习,采用UDP传输

            IPAddress ip 
= IPAddress.Parse("192.168.111.195");

            
//ip可以用IPAddress.Any来代替全发送。

            IPEndPoint iep 
= new IPEndPoint(ip, 3000);//初始化一个发送广播和指定端口的网络端口实例

            sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 
1);//设置该scoket实例的发送形式


            
string request ="你好,hi";//初始化需要发送而的发送数据

            
byte[] buffer = Encoding.Unicode.GetBytes(request);

            sock.SendTo(buffer, iep);

            sock.Close();            
            
            
//Console.WriteLine("nihao");
        }

    }

}

posted @ 2008-07-21 10:42 陈旭85 阅读(38) | 评论 (0)编辑
 当设计表的时候没有建组合字段唯一约束,以后需要增加这一约束时,却发现表里已经有了很多重复记录了。

        请看看我用的去掉表里组合字段重复的记录方法:

        假设原始表名为source_table,字段名1为field_name1,字段名2为field_name2。

        (当然稍加修改也可以用到三个及以上组合字段重复的情况)

        第一步: 生成组合字段重复的临时表source_dup_simple
        create table source_dup_simple
        nologging
        pctfree 1 pctused 99
        as select field_name1,field_name2,count(0) as num from source_table
        group by field_name1,field_name2 having count(0)>1;

        第二步: 生成组合字段重复的主表里完整记录的临时表source_dup
        create table source_dup
        nologging
        pctfree 1 pctused 99
        as select t1.* from source_table t1,source_dup_simple t2
        where t1.field_name1=t2.field_name1 and t1.field_name2=t2.field_name2;

        第三步: 删去source_dup里的重复记录

        --可选择:保留rowid小的记录
        delete from source_dup a where rowid > (
        select min(rowid) from source_dup b where
        a.field_name1 = b.field_name1 and a.field_name2=b.field_name2);
        commit;

        --可选择:保留rowid大的记录
        delete from source_dup a where rowid < (
        select max(rowid) from source_dup b where
        a.field_name1 = b.field_name1 and a.field_name2=b.field_name2);
        commit;

        注意:如果操作一万条以上的记录最好在source_dup的field_name1和field_name2字段上建索引.

             如果想按别的删除规则,如保留日期最新的记录:

             --可选择:保留时间字段date_field大的记录

             delete from source_dup a where date_field < (
                select max(date_field) from source_dup b where
                a.field_name1 = b.field_name1 and a.field_name2=b.field_name2);
             commit;

             --可选择:保留时间字段date_field小的记录

             delete from source_dup a where date_field > (
                select min(date_field) from source_dup b where
                a.field_name1 = b.field_name1 and a.field_name2=b.field_name2);
             commit;

             如果时间字段上有重复,还需要再次根据rowid来删一次

             delete from source_dup a where rowid < (
                select max(rowid) from source_dup b where
                a.field_name1 = b.field_name1 and a.field_name2=b.field_name2);
             commit;

        第四步: 删去所有重复组合字段原始表里记录
        delete from source_table
        where field_name1||field_name2 in (select field_name1||field_name2 from source_dup_simple);
        commit;

        注意:如果操作一万条以上的记录最好在source_table的field_name1和field_name2字段上建索引.

        第五步: 把剩下的没有重复的记录插回原始表
        insert into source_table select * from source_dup;
        commit;

posted @ 2008-06-11 17:09 陈旭85 阅读(34) | 评论 (0)编辑

 

private void btn_send_Click(object sender, EventArgs e)
        
{
            
byte[] bt = System.Text.Encoding.Default.GetBytes(this.txt_msg.Text);
            TcpClient tc 
= new TcpClient(this.txt_tarip.Text, int.Parse(this.txt_tarport.Text));
            NetworkStream nks 
= tc.GetStream();
            nks.Write(bt, 
0, bt.Length);
            nks.Flush();
        }


        
private void btn_begin_Click(object sender, EventArgs e)
        
{
            Thread t 
= new Thread(Listen);
            t.Start();
        }


        
private void Listen()
        
{
            TcpListener tl 
= new TcpListener(ep);
            tl.Start();
            
while (true)
            
{
                
try
                
{
                    Socket s 
= tl.AcceptSocket();
                    
byte[] bt = new byte[256];
                    
int i = s.Receive(bt);
                    
string msg = System.Text.Encoding.Default.GetString(bt, 0, i);
                    
if (msg.Length != 0)
                    
{
                        
this.txt_accmsg.AppendText(msg + "\r\n");
                    }

                }

                
catch 
                
{ }
            }

        }
posted @ 2008-05-13 15:09 陈旭85 阅读(39) | 评论 (0)编辑

一个用FileStream来复制文件的小程序


相比用File.Copy()方法,我觉得有两个好处
1:可以实时显示文件进度
2:当文件拷贝到一半发生异常时不会造成目标文件不可用,(用FileStream,文件可播放已拷贝部分的片段)


贴上代码:

 1       private void button1_Click(object sender, EventArgs e)
 2        {
 3            FileStream fsr = null;
 4            FileStream fsw = null;
 5            try
 6            {
 7                this.progressBar1.Maximum =100;
 8                fsr = new FileStream(this.textBox1.Text, FileMode.Open);
 9                fsw = new FileStream(this.textBox2.Text, FileMode.Create);
10                byte[] bt = new byte[1024*1024];
11                int rcount = 0;
12                do
13                {
14                    Application.DoEvents();
15                    rcount = fsr.Read(bt, 0, bt.Length);
16                    fsw.Write(bt, 0, rcount);
17                    //this.progressBar1.Value = Convert.ToInt32(fsw.Length);
18                    this.progressBar1.Value = ((int)(((float)fsw.Length / (float)fsr.Length)*100 )) ;
19                    Application.DoEvents();
20                }
 while (rcount != 0);
21                fsr.Close();
22                fsw.Close();
23            }

24            catch (Exception ex)
25            {
26                if (fsr != null)
27                {
28                    fsr.Close();
29                    fsr = null;
30                }

31  &n