예제 #1
0
        private void btnDownload1_Click(object sender, EventArgs e)
        {
            try
            {
                DataGridViewSelectedRowCollection selectedRows = this.gvData.SelectedRows;
                if (selectedRows.Count == 0)
                {
                    MessageBox.Show("请选择!");
                    return;
                }
                else if (selectedRows.Count > 1)
                {
                    MessageBox.Show("只能选择一行!");
                    return;
                }
                String type = Util.Util.ConvertObjToString(selectedRows[0].Cells[objTypeStr].Value);
                if (type.Equals(this.directoryType))
                {
                    MessageBox.Show("选择的是文件夹!");
                    return;
                }
                String         bosUri             = Util.Util.ConvertObjToString(selectedRows[0].Cells[this.keyStr].Value);
                String         fileName           = Util.Util.ConvertObjToString(selectedRows[0].Cells[this.objNameStr].Value);
                long           size               = long.Parse(selectedRows[0].Cells["s2"].Value.ToString());
                String         selectedBucketName = lbSelectedBucket.Text.Replace("选中的Bucket:", "");
                BosUtil        bosUtil            = new BosUtil();
                String         uriPath            = bosUtil.getFileUrl(selectedBucketName, bosUri);
                DownloadUtil   downloadUtil       = new DownloadUtil();
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.FileName = fileName;
                DialogResult result = sfd.ShowDialog();
                String       path   = sfd.FileName;

                if (result.Equals(DialogResult.OK))
                {
                    DateTime startTime = DateTime.Now;
                    String   start     = startTime.ToString();
                    this.toolStripStatusLabel2.Text = "开始时间:" + start + "|";
                    bosUtil.Download1(selectedBucketName, bosUri, fileName, path);
                    DateTime endTime = DateTime.Now;
                    String   end     = endTime.ToString();
                    this.toolStripStatusLabel3.Text = "结束时间:" + end + "|";
                    TimeSpan tsStart        = new TimeSpan(startTime.Ticks);
                    TimeSpan tsEnd          = new TimeSpan(endTime.Ticks);
                    TimeSpan ts             = tsEnd.Subtract(tsStart).Duration();
                    int      dateDiffSecond = ts.Days * 24 * 60 * 60 + ts.Hours * 60 * 60 + ts.Minutes * 60 + ts.Seconds;
                    this.toolStripStatusLabel4.Text = "耗时:" + dateDiffSecond.ToString() + "|";
                    //两个时间的秒差
                    long speed = size / 1024 / dateDiffSecond;
                    this.toolStripStatusLabel5.Text = "速度:" + speed.ToString() + "M/s";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
 private void btnDownload_Click(object sender, EventArgs e)
 {
     try
     {
         DataGridViewSelectedRowCollection selectedRows = this.gvData.SelectedRows;
         if (selectedRows.Count == 0)
         {
             MessageBox.Show("请选择!");
             return;
         }
         else if (selectedRows.Count > 1)
         {
             MessageBox.Show("只能选择一行!");
             return;
         }
         String type = Util.Util.ConvertObjToString(selectedRows[0].Cells[objTypeStr].Value);
         if (type.Equals(this.directoryType))
         {
             MessageBox.Show("选择的是文件夹!");
             return;
         }
         String         bosUri             = Util.Util.ConvertObjToString(selectedRows[0].Cells[this.keyStr].Value);
         String         fileName           = Util.Util.ConvertObjToString(selectedRows[0].Cells[this.objNameStr].Value);
         String         selectedBucketName = lbSelectedBucket.Text.Replace("选中的Bucket:", "");
         BosUtil        bosUtil            = new BosUtil();
         String         uriPath            = bosUtil.getFileUrl(selectedBucketName, bosUri);
         DownloadUtil   downloadUtil       = new DownloadUtil();
         SaveFileDialog sfd = new SaveFileDialog();
         sfd.FileName = fileName;
         DialogResult result = sfd.ShowDialog();
         String       path   = sfd.FileName;
         if (result.Equals(DialogResult.OK))
         {
             downloadUtil.DownloadFile(uriPath, path, pbProcess);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }