コード例 #1
0
ファイル: FormRegistro.cs プロジェクト: vdiazh/homecinema
        private void btnRegistrase_Click(object sender, EventArgs e)
        {
            if (this.txtUsuario.Text.Trim() != String.Empty && this.txtNombre.Text.Trim() != String.Empty &&
                this.txtPass.Text.Trim() != String.Empty && this.txtTarjeta.Text.Trim() != String.Empty)
            {
                using (myNetStream = myClient.GetStream())
                {
                    myBinaryWriter = new BinaryWriter(myNetStream);
                    myBinaryWriter.Write("REGISTRO");
                    myBinaryWriter.Write(txtUsuario.Text);
                    myBinaryWriter.Flush();

                    myBinaryReader = new BinaryReader(myNetStream);
                    String answer = myBinaryReader.ReadString();
                    if (answer.Equals("OK"))
                    {
                        myDataSet = (DataSet)myFormatter.Deserialize(myNetStream);
                        newUser   = new Usuario(this.txtNombre.Text, this.txtUsuario.Text, this.txtPass.Text, Convert.ToInt64(this.txtTarjeta.Text));
                        myFormatter.Serialize(myNetStream, newUser);
                    }
                    else if (answer.Equals("Cancel"))
                    {
                        this.myClient.Close();
                        MessageBox.Show("Esté usuario ya existe, utilice otro.");
                    }
                }
            }
            else
            {
                MessageBox.Show("Todos los campos son obligatorios");
            }

            FormPelicula frmMovie = new FormPelicula(myClient, myDataSet);

            this.Hide();
            frmMovie.Show();
        }
コード例 #2
0
        private void btnEntrar_Click(object sender, EventArgs e)
        {
            if (this.txtUser.Text.Trim() != string.Empty && this.txtPass.Text.Trim() != string.Empty)
            {
                using (myNetStream = myClient.GetStream()) {
                    myBinaryWriter = new BinaryWriter(myNetStream);
                    myBinaryWriter.Write("INGRESO");
                    myBinaryWriter.Write(this.txtUser.Text);
                    myBinaryWriter.Write(this.txtPass.Text);
                    myBinaryWriter.Flush();

                    myBinaryReader = new BinaryReader(myNetStream);
                    string answer = myBinaryReader.ReadString();

                    if (answer.Equals("OK"))
                    {
                        myDataSet = (DataSet)myFormatter.Deserialize(myNetStream);
                        FormPelicula frmMovie = new FormPelicula(this.myClient, myDataSet);
                        this.Hide();
                        frmMovie.Show();
                    }
                    else if (answer.Equals("Cancel"))
                    {
                        this.myClient.Close();
                        MessageBox.Show("Usuario o Contraseña incorrectos.");
                        this.txtUser.Clear();
                        this.txtPass.Clear();
                        this.myClient = new TcpClient("localhost", 1111);
                    }
                }
            }
            else
            {
                MessageBox.Show("Debe ingresar su usuario y su contraseña");
            }
        }