예제 #1
0
        //处理socket接收的数据(且反序列化解码)
        private void DataArrival(byte[] Data, IPAddress Ip, int Port) //当有数据到达后的主要逻辑处理函数(的进程)
        {
            try
            {
                ClassMsg msg = new ClassSerializers().DeSerializeBinary((new System.IO.MemoryStream(Data))) as ClassMsg;

                switch (msg.msgCommand)
                {
                case MsgCommand.Registered:    //注册成功
                    DialogResult = DialogResult.OK;
                    WritePrivateProfileString("MyDTS", "UID", serID, PubClass.Get_windows() + "\\Server.ini");
                    WritePrivateProfileString("MyDTS", "Port", PubClass.GetServerPort().Trim(), PubClass.Get_windows() + "\\Server.ini");
                    WritePrivateProfileString("MyDTS", "Name", text_regist_name.Text.Trim(), PubClass.Get_windows() + "\\Server.ini");
                    WritePrivateProfileString("MyDTS-Client", "C-UID", PubClass.getMacAddr_Local(0).Trim(), PubClass.Get_windows() + "\\Server.ini");
                    WritePrivateProfileString("MyDTS-Client", "C-Port", this.udpSocket1.LocalPort.ToString(), PubClass.Get_windows() + "\\Server.ini");
                    WritePrivateProfileString("MyDTS-Client", "C-MacAddr", PubClass.getMacAddr_Local(1).Trim(), PubClass.Get_windows() + "\\Server.ini");

                    break;
                }
            }
            catch { }
        }
예제 #2
0
        /// <summary>
        /// 保存
        /// </summary>
        private void dbconn_save_Click(object sender, EventArgs e)
        {
            Int32  pro_tmp    = 1;
            DB_Map db_pro_tmp = null;

            //全局变量重构//
            //if (PublicValue.mydics.llDictionary.Count > 0)
            if (SuperMessage.mydics.llDictionary.Count > 0)
            {
                if (PublicValue.old_dbname != null)
                {
                    db_pro_tmp             = getKeyExistsDics(PublicValue.old_dbname);
                    PublicValue.old_dbname = "";
                }
                else
                {
                    db_pro_tmp = getKeyExistsDics(dbconn_comb.Text.Trim());
                }
                if (db_pro_tmp == null)
                {
                    pro_tmp = 0;
                }
                else
                {
                    pro_tmp = 0;
                    //bug  ing
                    //MessageBox.Show("       名字冲突,请重新填写一个连接名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //return;
                }
            }
            DB_Map dbconn_save = new DB_Map(dbconn_comb.Text.Trim(), dbconn_username.Text.Trim(), dbconn_password.Text.Trim(),
                                            dbconn_ipaddr.Text.Trim(), Convert.ToInt32(dbconn_port.Text.Trim()), pro_tmp, "否", Publec_Class.UserName);

            byte[]   dbconn_saveData = new ClassSerializers().SerializeBinary(dbconn_save).ToArray();
            ClassMsg msg             = new ClassMsg();

            msg.sendKind   = SendKind.SendCommand;
            msg.msgCommand = MsgCommand.DBSave;
            msg.SPort      = this.udpSocket1.LocalPort.ToString();
            msg.SIP        = PubClass.getMacAddr_Local(0);
            msg.Data       = dbconn_saveData;

            udpSocket1.Send(IPAddress.Parse(PubClass.GetServerIp().Trim()), Convert.ToInt32(PubClass.GetServerPort().Trim()), new ClassSerializers().SerializeBinary(msg).ToArray());
        }