private void RefreshDictionary_Click(object sender, EventArgs e) { //запрос из сети if (m_IsConnectedToServer) { m_tcpModule.SendData(null, ProtocolOfExchange.AskDictionary); } }
private void SendReqest(ProtocolOfExchange req, NetworkTransferObjects obj, TcpModule tcp) { if (m_IsConnectedToServer || req == ProtocolOfExchange.CheckConnection) { // m_tcpModule.Receive += Tcp_Receive; tcp.SendData(obj, req); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { try { _tcpmodule.CloseSocket(); c = true; int i = list1.SelectedIndex; _tcpmodule.ConnectClient(ip[i, 1]); Thread t = new Thread(() => _tcpmodule.SendData(ip[i, 0])); t.Start(); } catch (Exception m) { if (m.Message == "Индекс находился вне границ массива.") { System.Windows.MessageBox.Show("Выберите адресата"); } else { System.Windows.MessageBox.Show("Не удалось отправить файл\n" + "Ошибка: " + m.Message); } } }
private static void _tcpMod_Receive(object sender, DataBase.ReceiveEventArgs e) { TcpModule tcp = (TcpModule)sender; if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.CheckConnection) { Thread.Sleep(10); tcp.SendData(null, ProtocolOfExchange.CheckConnectionOK); } if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.AskDictionary) { Dictionary di = new Dictionary(); di.ReadFromIni(); NetworkTransferObjects obj = new NetworkTransferObjects(); obj.Dictionary = di; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.AskDictionaryOk); } if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.AskDbCollection) { NetworkTransferObjects obj = new NetworkTransferObjects(); obj.DataBaseCollection = m_DbCollection; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.AskDbCollectionOk); } if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.AddBase) { NetworkTransferObjects obj = new NetworkTransferObjects(); DataBase.DataBase addDb = (DataBase.DataBase)e.NetDataObj.DataBase; if (addDb != null) { if (m_DbCollection.AddDataBase(addDb)) { Functions.SaveConfig(m_DbCollection, "DataBase.qrdb"); obj.DataBaseCollection = m_DbCollection; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.AddBaseOk); } else { Thread.Sleep(10); tcp.SendData(null, ProtocolOfExchange.AddBaseFail); } } } if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.DelBase) { DataBase.DataBase addDb = (DataBase.DataBase)e.NetDataObj.DataBase; if (addDb != null) { if (m_DbCollection.DeleteDataBase(addDb)) { NetworkTransferObjects obj = new NetworkTransferObjects(); obj.DataBaseCollection = m_DbCollection; Functions.SaveConfig(m_DbCollection, "DataBase.qrdb"); Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.DelBaseOk); } } } //ADDQRITEMINBASE if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.AddQrItemInBase) { QrCodeData qrcode = (QrCodeData)e.NetDataObj.QrCodeData; if (qrcode != null) { if (m_DbCollection.AddQrCodeToDataBases(qrcode)) { Functions.SaveConfig(m_DbCollection, "DataBase.qrdb"); NetworkTransferObjects obj = new NetworkTransferObjects(); obj.DataBaseCollection = m_DbCollection; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.AddQrItemInBaseOk); } else { Thread.Sleep(10); tcp.SendData(null, ProtocolOfExchange.AddQrItemInBaseFail); } } } //ADDQRITEMSINBASE if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.AddQrItemSInBase) { QrCodeData[] qrcode = (QrCodeData[])e.NetDataObj.QrCodeDataArray; if (qrcode != null) { if (m_DbCollection.AddQrCodeSerialToDataBases(qrcode)) { Functions.SaveConfig(m_DbCollection, "DataBase.qrdb"); NetworkTransferObjects obj = new NetworkTransferObjects(); obj.DataBaseCollection = m_DbCollection; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.AddQrItemSInBaseOk); } else { Thread.Sleep(10); tcp.SendData(null, ProtocolOfExchange.AddQrItemSInBaseFail); } } } if (e.SendInfo.ProtocolMsg == ProtocolOfExchange.DelDbItems) { int db_index = e.NetDataObj.DbIndex; if (db_index != -1) { if (m_DbCollection.DeleteItemsFromDb((List <DataBaseItem>)e.NetDataObj.DataBaseItemsList, db_index)) { Functions.SaveConfig(m_DbCollection, "DataBase.qrdb"); NetworkTransferObjects obj = new NetworkTransferObjects(); obj.DataBaseCollection = m_DbCollection; Thread.Sleep(10); tcp.SendData(obj, ProtocolOfExchange.DelDbItemsOK); } else { Thread.Sleep(10); tcp.SendData(null, ProtocolOfExchange.DelDbItemsFail); } } } }