コード例 #1
0
ファイル: LoginForm.cs プロジェクト: treejames/P2PHomework
 private void LoginButton_Click(object sender, EventArgs e)
 {
     try
     {
         userinfo.UserName = userNameInput.Text;
         userinfo.Password = PasswordInput.Text;
         IPHostEntry ipe = Dns.GetHostEntry(Dns.GetHostName());
         string ipaddress = "219.245.98.140";//here we need modify
         string port = PortInput.Text;
         userinfo.Port = port;
         userinfo.IpAddress = ipaddress;
         PostData Require = new PostData();
         Require.InData = "action=login" +
                         "&&username="******"&&password="******"&&ipaddress=" + ipaddress +
                         "&&port=" + port;
         string response = Require.postPackge();
         if (response.Equals("SUCCESS"))
         {
             MessageBox.Show("登录成功!");
             this.DialogResult = DialogResult.OK;
             return;
         }
         if (response.Equals("WRONG") || response.Equals("NOTEXIST"))
         {
             MessageBox.Show("错误的用户名或密码!");
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Error");
     }
 }
コード例 #2
0
ファイル: HomeForm.cs プロジェクト: treejames/P2PHomework
 private void GetDownLoadThread()
 {
     if (ResourceGridView.SelectedRows.Count != 0)
     {
         string requierFilename = ResourceGridView.CurrentRow.Cells[0].Value.ToString();
         string requireUser = ResourceGridView.CurrentRow.Cells[2].Value.ToString();
         PostData Require = new PostData();
         Require.InData = "action=download" +
                         "&&username="******"&&password="******"&&requireuser="******"&&filename=" + requierFilename;
         string response = Require.postPackge();
         string[] tmp = response.Split('&');
         GetFile getFile = new GetFile();
         getFile.IpAddress = tmp[0];
         getFile.Port = tmp[1];
         getFile.FileName = tmp[2];
         getFile.FilePath = tmp[3];
         byte[] outputb = Convert.FromBase64String(getFile.FilePath);
         getFile.FilePath = Encoding.Default.GetString(outputb);
         MessageBox.Show(getFile.FilePath);
         if (getFile.DownloadFile())
         {
             MessageBox.Show(requierFilename + "已经下载完成!");
         }
         else
         {
             MessageBox.Show(requierFilename + "下载失败!");
         }
     }
 }
コード例 #3
0
ファイル: HomeForm.cs プロジェクト: treejames/P2PHomework
 private void CancelShareButton_Click(object sender, EventArgs e)
 {
     if (UploadGridView.SelectedRows.Count != 0)
     {
         string filename = UploadGridView.CurrentRow.Cells[0].Value.ToString();
         PostData Require = new PostData();
         Require.InData = "action=canclesharefile" +
                         "&&username="******"&&password="******"&&filename=" + filename;
         string response = Require.postPackge();
         if (response.Equals("SUCCESS"))
         {
             MessageBox.Show("取消分享" + filename + "成功!");
             getUpload();
             return;
         }
     }
 }
コード例 #4
0
ファイル: RegistForm.cs プロジェクト: treejames/P2PHomework
        private void RegistUserButton_Click(object sender, EventArgs e)
        {
            try
            {
                userInfo.UserName = RegistNameInput.Text;
                userInfo.Password = RegistPasswordInput.Text;
                string configPassword = ConfigPasswordInput.Text;
                if (userInfo.UserName.Equals("")
                    || userInfo.Password.Equals("")
                    || configPassword.Equals(""))
                {
                    MessageBox.Show("输入不能为空");
                }
                else if (!userInfo.Password.Equals(configPassword))
                {
                    MessageBox.Show("密码和确认密码必须一致!");
                }
                else
                {
                    PostData Require = new PostData();
                    Require.InData = "action=regist" +
                                     "&&username="******"&&password="******"SUCCESS"))
                    {
                        MessageBox.Show("注册成功!");
                        this.DialogResult = DialogResult.OK;
                        return;
                    }
                    else if (respose.Equals("EXIST"))
                    {
                        MessageBox.Show("用户名已经存在!");
                    }
                }

            }
            catch (Exception)
            {
                MessageBox.Show("Error!");
                this.DialogResult = DialogResult.Abort;
            }
        }
コード例 #5
0
ファイル: HomeForm.cs プロジェクト: treejames/P2PHomework
 private void getUpload()
 {
     PostData Require = new PostData();
     Require.InData = "action=upload" +
                     "&&username="******"&&password=" + userinfo.Password;
     string response = Require.postPackge();
     //ResourceGridView.Dispose();
     string[] tmp = response.Split('#');
     int len = tmp.Length - 1;
     string[,] info = new string[len, 1];
     UploadGridView.ColumnCount = 1;
     UploadGridView.RowCount = len;
     for (int i = 0; i < UploadGridView.RowCount; i++)
     {
         string[] buff = tmp[i].Split('&');
         for (int j = 0; j < UploadGridView.ColumnCount; j++)
         {
             info[i, j] = buff[j];
         }
     }
     for (int i = 0; i < UploadGridView.RowCount; i++)
     {
         for (int j = 0; j < UploadGridView.ColumnCount; j++)
         {
             UploadGridView.Rows[i].Cells[j].Value = info[i, j];
         }
     }
     UploadGridView.Show();
 }
コード例 #6
0
ファイル: HomeForm.cs プロジェクト: treejames/P2PHomework
 private void ShareButton_Click(object sender, EventArgs e)
 {
     DialogResult openFileResult = openFileDialog.ShowDialog();
     if (openFileResult == DialogResult.OK)
     {
         string filepath = openFileDialog.FileName;
         byte[] bytes = Encoding.Default.GetBytes(filepath);
         filepath = Convert.ToBase64String(bytes);
         FileInfo fileinfo = new FileInfo(openFileDialog.FileName);
         string filesize = fileinfo.Length / 1024 + "KB";
         string filename = openFileDialog.SafeFileName;
         PostData Require = new PostData();
         Require.InData = "action=sharefile" +
                         "&&username="******"&&password="******"&&filename=" + filename +
                         "&&filesize=" + filesize +
                         "&&filepath=" + filepath;
         string response = Require.postPackge();
         if (response.Equals("SUCCESS"))
         {
             MessageBox.Show("分享成功!");
             getUpload();
             return;
         }
         if (response.Equals("EXIST"))
         {
             MessageBox.Show("文件已经存在!");
             return;
         }
     }
 }
コード例 #7
0
ファイル: HomeForm.cs プロジェクト: treejames/P2PHomework
 private void SearchButton_Click(object sender, EventArgs e)
 {
     PostData Require = new PostData();
     Require.InData = "action=search" +
                     "&&username="******"&&password="******"&&filename=" + SearchInput.Text;
     string response = Require.postPackge();
     //ResourceGridView.Dispose();
     string[] tmp = response.Split('#');
     int len = tmp.Length - 1;
     string[,] info = new string[len, 4];
     ResourceGridView.ColumnCount = 4;
     ResourceGridView.RowCount = len;
     for (int i = 0; i < ResourceGridView.RowCount; i++)
     {
         string[] buff = tmp[i].Split('&');
         for (int j = 0; j < ResourceGridView.ColumnCount; j++)
         {
             info[i, j] = buff[j];
         }
     }
     for (int i = 0; i < ResourceGridView.RowCount; i++)
     {
         for (int j = 0; j < ResourceGridView.ColumnCount; j++)
         {
             ResourceGridView.Rows[i].Cells[j].Value = info[i, j];
         }
     }
     ResourceGridView.Show();
 }
コード例 #8
0
ファイル: HomeForm.cs プロジェクト: treejames/P2PHomework
 private void HomeForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     PostData Require = new PostData();
     Require.InData = "action=logoff" +
                     "&&username="******"&&password="******"SUCCESS"))
     {
         MessageBox.Show("下线成功!");
         return;
     }
     newListenThread.Abort();
 }