private void GetUser() { menuStrip1.Invoke(new Action(() => menuStrip1.Enabled = false)); buttonSignIn.Invoke(new Action(() => buttonSignIn.Enabled = false)); textBoxLogin.Invoke(new Action(() => textBoxLogin.Enabled = false)); textBoxPassword.Invoke(new Action(() => textBoxPassword.Enabled = false)); DALServerDB.Data Data = new DALServerDB.Data(); Data.Login = textBoxLogin.Text; Data.Password = textBoxPassword.Text; string localAddr = textBoxHostName.Text; int port = int.Parse(textBoxPortNumber.Text); try { client = new TcpClient(localAddr, port); using (NetworkStream stream = client.GetStream()) { //using (var ms = new MemoryStream()) //{ // new BinaryFormatter().Serialize(ms, Data); // buffer = ms.ToArray(); //} // отправка сообщения //stream.Write(buffer, 0, buffer.Length); new BinaryFormatter().Serialize(client.GetStream(), Data); // получаем ответ Data = (DALServerDB.Data) new BinaryFormatter().Deserialize(stream); if (Data.Token == null) { MessageBox.Show(Environment.NewLine + "user not found!!!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); EnabledComponent(); return; } else { this.Invoke(new Action(() => { FormClientMain form = new FormClientMain(Data, stream, client); form.Owner = this; this.Hide(); form.ShowDialog(); })); } } } catch (Exception ex) { EnabledComponent(); MessageBox.Show(Environment.NewLine + ex.Message + Environment.NewLine, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } //catch { EnabledComponent(); } }
public FormClientMain(DALServerDB.Data data, NetworkStream stream, TcpClient client) { InitializeComponent(); this.data = data; this.stream = stream; this.client = client; labelSelected.Text = string.Empty; labelFLName.Text = data.FName + " " + data.LName; FillComboBoxGroupName(data.Groups); SplitContainerDGSplitterDistance(panelPassTests.Height); }
private void GetResponce() { try { new BinaryFormatter().Serialize(client.GetStream(), data); data = (DALServerDB.Data) new BinaryFormatter().Deserialize(stream); } //catch (Exception ex) //{ // MessageBox.Show(Environment.NewLine + ex.Message + Environment.NewLine, this.Text, // MessageBoxButtons.OK, MessageBoxIcon.Error); //} catch { } }