大家好!遇到这么一个问题!
我想在填写了一张定单后通知所有的跟单人员。我现在一个listbox上选择接受的用户,然后添加到一个datagrid中,最后,我想按一个按钮,然后将这个信息(“定单一已完成!”)发送到网络内的选定人员的机器上(datagrid中的用户)。该如何实现啊??谢谢!最好是有代码!

解决方案 »

  1.   

    B/S 还是C/S?
    定时刷新最好了,要是自己用SOCKET进行连接的话,好累
      

  2.   

    如果你的整个系统用OO的方式的话,我觉得使用访问者模式会比较好。具体的你可以参照一下设计模式。至于你所说的发送信息到选定人员的机器上,我觉得这种做法欠妥,不如发邮件给选中的人员。发送邮件可以选择JMail组件。所以在你的用户数据中应该有他们的EMail地址属性,就算你想用Net Send这种方式发送给他们,也需要有他们IP地址的属性。你按下一个按钮之后,激发事件,这个事件内遍历被你选中的用户,然后分别对他们发送。当然发送这个过程最好采用多线程,不然速度会比较慢。
      

  3.   

    正好,前几天看这设计模式,你可以使用观察者模式。或者使用代理,和事件。例子:
    /*=====================================================================
      File:      Chat.cs  Summary:   Demonstrates how to use delegates and events.---------------------------------------------------------------------
      This file is part of the Microsoft .NET Framework SDK Code Samples.  Copyright (C) Microsoft Corporation.  All rights reserved.This source code is intended only as a supplement to Microsoft
    Development Tools and/or on-line documentation.  See these other
    materials for detailed information regarding Microsoft code samples.THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
    KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    PARTICULAR PURPOSE.
    =====================================================================*/// Add the classes in the following namespaces to our namespace
    using System;
    ///////////////////////////////////////////////////////////////////////////////
    class DChatServer {
        // Declare a multicast delegate type
        public delegate void OnMsgArrived(String message);    // Declare a reference to an OnGetString delegate
        private static OnMsgArrived onMsgArrived;    // Private to prevent instances of this type from being instantiated.
        private DChatServer() {}    // This function is necessary because we are not using an event
        public static void ClientConnect(OnMsgArrived onMsgArrived) {
            DChatServer.onMsgArrived = (OnMsgArrived)
                Delegate.Combine(DChatServer.onMsgArrived, onMsgArrived);
        }    // This function is necessary because we are not using an event
        public static void ClientDisconnect(OnMsgArrived onMsgArrived) {
            DChatServer.onMsgArrived = (OnMsgArrived)
                Delegate.Remove(DChatServer.onMsgArrived, onMsgArrived);
        }    public static void SendMsg(String msg) {
            // Send message to ALL clients
            SendMsg(msg, null);
        }    public static void SendMsg(String msg, Object excludeClient) {
            // Send message to all clients except 'excludeClient'
            if (excludeClient == null) {
                onMsgArrived(msg);
            } else {
                Delegate[] DelegateList = onMsgArrived.GetInvocationList();
                for (int i = 0; i < DelegateList.Length; i++) {
                    if (DelegateList[i].Target != excludeClient) {
                        ((OnMsgArrived) DelegateList[i])(msg);
                    }
                }            
            }        
        }    
    }
    ///////////////////////////////////////////////////////////////////////////////
    class DChatClient {
        private void onMsgArrived(String msg) {
            Console.WriteLine("Msg arrived (Client {0}): {1}", clientName, msg);
        }    private String clientName;    public DChatClient(String clientName) {
            this.clientName = clientName;
            DChatServer.ClientConnect(new DChatServer.OnMsgArrived(onMsgArrived));
        }    public void Dispose() {
            DChatServer.ClientDisconnect(new DChatServer.OnMsgArrived(onMsgArrived));
            GC.SuppressFinalize(this);
        }    ~DChatClient() {
            Dispose();        
        }
    }
    ///////////////////////////////////////////////////////////////////////////////
    class EChatServer {
        // Declare a multicast (because return type is void) delegate type
        public delegate void OnMsgArrived(String message);    // Declaring an event causes the compiler to generate a PRIVATE field 
        // (onMsgArrived) that references the tail of an OnMsgArrived delegate 
        // linked-list. The compiler also generates two PUBLIC methods, 
        // add_onMsgArrived and remove_onMsgArrived which are called when the 
        // += and -= operators are applied to the event's delegate.
        public static event OnMsgArrived onMsgArrived;    // Private to prevent instances of this type from being instantiated.
        private EChatServer() {}    public static void SendMsg(String msg) {
            // Send message to ALL clients
            SendMsg(msg, null);
        }    public static void SendMsg(String msg, Object excludeClient) {
            // Send message to all clients except 'excludeClient'
            if (excludeClient == null) {
                onMsgArrived(msg);
            } else {
                Delegate[] DelegateList = onMsgArrived.GetInvocationList();
                for (int i = 0; i < DelegateList.Length; i++) {
                    if (DelegateList[i].Target != excludeClient) {
                        ((OnMsgArrived) DelegateList[i])(msg);
                    }
                }            
            }        
        }    
    }
    ///////////////////////////////////////////////////////////////////////////////
    class EChatClient {
        private void onMsgArrived(String msg) {
            Console.WriteLine("Msg arrived (Client {0}): {1}", clientName, msg);
        }    private String clientName;    public EChatClient(String clientName) {
            this.clientName = clientName;
            EChatServer.onMsgArrived += new EChatServer.OnMsgArrived(onMsgArrived);
        }    public void Dispose() {
            EChatServer.onMsgArrived -= new EChatServer.OnMsgArrived(onMsgArrived);
            GC.SuppressFinalize(this);
        }    ~EChatClient() {
            Dispose();        
        }
    }
    ///////////////////////////////////////////////////////////////////////////////
    class Application {
        private static void DelegateChatServerDemo() {
            Console.WriteLine("Demo start: Delegate Chat Server.");        DChatClient cc1 = new DChatClient("1");
            DChatClient cc2 = new DChatClient("2");
            DChatClient cc3 = new DChatClient("3");        DChatServer.SendMsg("Hi to all clients");
            DChatServer.SendMsg("Hi to all clients except client 2", cc2);        // Explicitly disconnect the clients from the chat server.
            // If we didn't do this, the clients' memory could not be 
            // reclaimed until the server is collected (app shutdown time).
            cc1.Dispose();
            cc2.Dispose();
            cc3.Dispose();
            Console.WriteLine("Demo stop: Delegate Chat Server.");
        }    private static void EventChatServerDemo() {
            Console.WriteLine("\n\nDemo start: Event Chat Server.");
            EChatClient cc1 = new EChatClient("1");
            EChatClient cc2 = new EChatClient("2");
            EChatClient cc3 = new EChatClient("3");        EChatServer.SendMsg("Hi to all clients");
            EChatServer.SendMsg("Hi to all clients except client 2", cc2);        // Explicitly disconnect the clients from the chat server.
            // If we didn't do this, the clients' memory could not be 
            // reclaimed until the server is collected (app shutdown time).
            cc1.Dispose();
            cc2.Dispose();
            cc3.Dispose();
            Console.WriteLine("Demo stop: Event Chat Server.");
        }    public static void Main() {
            DelegateChatServerDemo();
            EventChatServerDemo();
        }
    }
      

  4.   

    是c/s模式的。我使用sockets连接,可行吗,广播可以实现这个效果吗?希望大家继续给些提示!谢谢!