123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- namespace LYFZ.Software.MainBusiness.SystemSettings
- {
- public class frmOssManage : LYFZ.Software.UI.frmOssManage
- {
- /// <summary>
- /// 图片集合
- /// </summary>
- System.Windows.Forms.ImageList imageList = new System.Windows.Forms.ImageList();
- BLL.OssCloudDiskSDK.UploadOssCloudDisk uploadOss ;
- public frmOssManage()
- {
- btnOK.Click += btnOK_Click;
- btnDelete.Click += btnDelete_Click;
- this.Shown += FrmOssManage_Shown;
- this.dgvData.CellContentClick += dgvData_CellContentClick;
- this.btnRefresh.Click += BtnRefresh_Click;
- }
- private void BtnRefresh_Click(object sender, EventArgs e)
- {
- FrmOssManage_Shown(null,null);
- }
- private void FrmOssManage_Shown(object sender, EventArgs e)
- {
- this.dgvData.Rows.Clear();
- LYFZ.BLL.OssCloudDiskSDK.OSSReturnData returnData = null;
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
- {
- try
- {
- backgroundWorker.ReportProgress(0, "正在连接云盘...");
- uploadOss = new BLL.OssCloudDiskSDK.UploadOssCloudDisk();
- if (uploadOss.InitializationStatus)
- {
- if (uploadOss.OssDiskInfo.State)
- {
- backgroundWorker.ReportProgress(0, "正在加载云盘文件...");
- returnData = uploadOss.GetOssFileData();
- }
- }
- }
- catch { }
- });
- tb_EnterpriseID.Text = uploadOss.AppInterface.AppEnId;
- tb_VerificationCode.Text = uploadOss.AppInterface.Ecode;
- pbDiskSizeBar.bshowText = true;
- if (uploadOss.InitializationStatus)
- {
- if (uploadOss.OssDiskInfo.State)
- {
- pbDiskSizeBar.Maximum = Convert.ToInt32(uploadOss.OssDiskInfo.CapacitySize * 1024);
- pbDiskSizeBar.Minimum = 0;
- if (uploadOss.OssDiskInfo.GB_AlreadyExistsFileSize() * 1024 > pbDiskSizeBar.Maximum)
- {
- pbDiskSizeBar.Value = pbDiskSizeBar.Maximum;
- }
- else
- {
- pbDiskSizeBar.Value = Convert.ToInt32(uploadOss.OssDiskInfo.GB_AlreadyExistsFileSize() * 1024);
- }
- this.lbInfo.Text =
- "共计: "+ returnData.OssFileList.Count + "个文件 已用磁盘:" + uploadOss.OssDiskInfo.GB_AlreadyExistsFileSize().ToString("0.0000") +
- "GB 剩余容量:" + (uploadOss.OssDiskInfo.CapacitySize - uploadOss.OssDiskInfo.GB_AlreadyExistsFileSize()).ToString("0.0000") +
- "GB 总容量:" + uploadOss.OssDiskInfo.CapacitySize + "GB ";
- pbDiskSizeBar.Refresh();
-
- System.Windows.Forms.DataGridViewRow gridRow;
- for (int i = 0; i < returnData.OssFileList.Count; i++)
- {
- Aliyun.OSS.OssObjectSummary fileMod = returnData.OssFileList[i];
- if (fileMod.Size > 0)
- {
- decimal decSize = (Convert.ToDecimal(fileMod.Size) / 1024m / 1024m);
- gridRow = new System.Windows.Forms.DataGridViewRow();
- gridRow.Cells.Add(new System.Windows.Forms.DataGridViewTextBoxCell() { Value = fileMod.Key });
- gridRow.Cells.Add(new System.Windows.Forms.DataGridViewTextBoxCell() { Value = decSize.ToString("0.0000") + "MB" });
- System.Windows.Forms.DataGridViewButtonCell buttonCell = new System.Windows.Forms.DataGridViewButtonCell();
- buttonCell.Value = "打开";
- gridRow.Cells.Add(buttonCell);
- this.dgvData.Rows.Add(gridRow);
- }
- }
- }
- else
- {
- MessageBoxCustom.Show(String.Format("授权失败\r\n{0}", uploadOss.ErrorMsg));
- return;
- }
- }
- else
- {
- MessageBoxCustom.Show(String.Format("初始化\r\n{0}", uploadOss.ErrorMsg));
- return;
- }
- }
- void dgvData_CellContentClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
- {
- if(e.ColumnIndex==2)
- {
- string filePath = LYFZ.BLL.OssCloudDiskSDK.UploadOssCloudDisk.GetOssKeyToWebUrl(dgvData.Rows[e.RowIndex].Cells["文件路径"].Value.ToString());
- System.Diagnostics.Process.Start(filePath);
- }
- }
- void btnDelete_Click(object sender, EventArgs e)
- {
- if (LYFZ.BLL.BLL_ErpUser.IsAdministrator())
- {
- if (MessageBoxCustom.Show("是否确认删除当前数据?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
- {
- var gridRows = dgvData.SelectedRows;
- List<string> delList = new List<string>();
-
- for (int i = 0; i < gridRows.Count; i++)
- {
- delList.Add(gridRows[i].Cells["文件路径"].Value.ToString());
-
- }
- bool delState = true;
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
- {
- try
- {
- backgroundWorker.ReportProgress(0, "正在连接云盘...");
- foreach (string keyValue in delList)
- {
- LYFZ.BLL.OssCloudDiskSDK.OSSUpdateReturnData resultData = uploadOss.DeleteFile(keyValue);
- if (!resultData.State)
- {
- delState = false;
- MessageBoxCustom.Show("删除失败:" + resultData.Description);
- break;
- }
- }
- }
- catch (Exception ex){
- MessageBoxCustom.Show("删除出错:" + ex.Message);
- delState = false;
- }
- });
- if (delState)
- {
- FrmOssManage_Shown(null, null);
- }
-
- }
- }
- else
- {
- MessageBoxCustom.Show("当前数据只能通过管理员删除!");
- }
- }
- /// <summary>
- /// 企业信息确定
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnOK_Click(object sender, EventArgs e)
- {
- if (LYFZ.BLL.BLL_ErpUser.IsAdministrator())
- {
- if (uploadOss.sysConfigBll.UpdateAPPInterface(uploadOss.AppInterface.AppUrlPath, tb_EnterpriseID.Text.Trim(), tb_VerificationCode.Text.Trim()))
- {
- MessageBoxCustom.Show("保存成功!");
- FrmOssManage_Shown(null,null);
- }
- else {
- MessageBoxCustom.Show("保存失败!");
- }
- }
- else {
- MessageBoxCustom.Show("需要“admin”帐号才能管理云盘帐号");
- }
- }
- }
- }
|