frmOssManage.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. namespace LYFZ.Software.MainBusiness.SystemSettings
  7. {
  8. public class frmOssManage : LYFZ.Software.UI.frmOssManage
  9. {
  10. /// <summary>
  11. /// 图片集合
  12. /// </summary>
  13. System.Windows.Forms.ImageList imageList = new System.Windows.Forms.ImageList();
  14. BLL.OssCloudDiskSDK.UploadOssCloudDisk uploadOss ;
  15. public frmOssManage()
  16. {
  17. btnOK.Click += btnOK_Click;
  18. btnDelete.Click += btnDelete_Click;
  19. this.Shown += FrmOssManage_Shown;
  20. this.dgvData.CellContentClick += dgvData_CellContentClick;
  21. this.btnRefresh.Click += BtnRefresh_Click;
  22. }
  23. private void BtnRefresh_Click(object sender, EventArgs e)
  24. {
  25. FrmOssManage_Shown(null,null);
  26. }
  27. private void FrmOssManage_Shown(object sender, EventArgs e)
  28. {
  29. this.dgvData.Rows.Clear();
  30. LYFZ.BLL.OssCloudDiskSDK.OSSReturnData returnData = null;
  31. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
  32. {
  33. try
  34. {
  35. backgroundWorker.ReportProgress(0, "正在连接云盘...");
  36. uploadOss = new BLL.OssCloudDiskSDK.UploadOssCloudDisk();
  37. if (uploadOss.InitializationStatus)
  38. {
  39. if (uploadOss.OssDiskInfo.State)
  40. {
  41. backgroundWorker.ReportProgress(0, "正在加载云盘文件...");
  42. returnData = uploadOss.GetOssFileData();
  43. }
  44. }
  45. }
  46. catch { }
  47. });
  48. tb_EnterpriseID.Text = uploadOss.AppInterface.AppEnId;
  49. tb_VerificationCode.Text = uploadOss.AppInterface.Ecode;
  50. pbDiskSizeBar.bshowText = true;
  51. if (uploadOss.InitializationStatus)
  52. {
  53. if (uploadOss.OssDiskInfo.State)
  54. {
  55. pbDiskSizeBar.Maximum = Convert.ToInt32(uploadOss.OssDiskInfo.CapacitySize * 1024);
  56. pbDiskSizeBar.Minimum = 0;
  57. if (uploadOss.OssDiskInfo.GB_AlreadyExistsFileSize() * 1024 > pbDiskSizeBar.Maximum)
  58. {
  59. pbDiskSizeBar.Value = pbDiskSizeBar.Maximum;
  60. }
  61. else
  62. {
  63. pbDiskSizeBar.Value = Convert.ToInt32(uploadOss.OssDiskInfo.GB_AlreadyExistsFileSize() * 1024);
  64. }
  65. this.lbInfo.Text =
  66. "共计: "+ returnData.OssFileList.Count + "个文件 已用磁盘:" + uploadOss.OssDiskInfo.GB_AlreadyExistsFileSize().ToString("0.0000") +
  67. "GB 剩余容量:" + (uploadOss.OssDiskInfo.CapacitySize - uploadOss.OssDiskInfo.GB_AlreadyExistsFileSize()).ToString("0.0000") +
  68. "GB 总容量:" + uploadOss.OssDiskInfo.CapacitySize + "GB ";
  69. pbDiskSizeBar.Refresh();
  70. System.Windows.Forms.DataGridViewRow gridRow;
  71. for (int i = 0; i < returnData.OssFileList.Count; i++)
  72. {
  73. Aliyun.OSS.OssObjectSummary fileMod = returnData.OssFileList[i];
  74. if (fileMod.Size > 0)
  75. {
  76. decimal decSize = (Convert.ToDecimal(fileMod.Size) / 1024m / 1024m);
  77. gridRow = new System.Windows.Forms.DataGridViewRow();
  78. gridRow.Cells.Add(new System.Windows.Forms.DataGridViewTextBoxCell() { Value = fileMod.Key });
  79. gridRow.Cells.Add(new System.Windows.Forms.DataGridViewTextBoxCell() { Value = decSize.ToString("0.0000") + "MB" });
  80. System.Windows.Forms.DataGridViewButtonCell buttonCell = new System.Windows.Forms.DataGridViewButtonCell();
  81. buttonCell.Value = "打开";
  82. gridRow.Cells.Add(buttonCell);
  83. this.dgvData.Rows.Add(gridRow);
  84. }
  85. }
  86. }
  87. else
  88. {
  89. MessageBoxCustom.Show(String.Format("授权失败\r\n{0}", uploadOss.ErrorMsg));
  90. return;
  91. }
  92. }
  93. else
  94. {
  95. MessageBoxCustom.Show(String.Format("初始化\r\n{0}", uploadOss.ErrorMsg));
  96. return;
  97. }
  98. }
  99. void dgvData_CellContentClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
  100. {
  101. if(e.ColumnIndex==2)
  102. {
  103. string filePath = LYFZ.BLL.OssCloudDiskSDK.UploadOssCloudDisk.GetOssKeyToWebUrl(dgvData.Rows[e.RowIndex].Cells["文件路径"].Value.ToString());
  104. System.Diagnostics.Process.Start(filePath);
  105. }
  106. }
  107. void btnDelete_Click(object sender, EventArgs e)
  108. {
  109. if (LYFZ.BLL.BLL_ErpUser.IsAdministrator())
  110. {
  111. if (MessageBoxCustom.Show("是否确认删除当前数据?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
  112. {
  113. var gridRows = dgvData.SelectedRows;
  114. List<string> delList = new List<string>();
  115. for (int i = 0; i < gridRows.Count; i++)
  116. {
  117. delList.Add(gridRows[i].Cells["文件路径"].Value.ToString());
  118. }
  119. bool delState = true;
  120. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
  121. {
  122. try
  123. {
  124. backgroundWorker.ReportProgress(0, "正在连接云盘...");
  125. foreach (string keyValue in delList)
  126. {
  127. LYFZ.BLL.OssCloudDiskSDK.OSSUpdateReturnData resultData = uploadOss.DeleteFile(keyValue);
  128. if (!resultData.State)
  129. {
  130. delState = false;
  131. MessageBoxCustom.Show("删除失败:" + resultData.Description);
  132. break;
  133. }
  134. }
  135. }
  136. catch (Exception ex){
  137. MessageBoxCustom.Show("删除出错:" + ex.Message);
  138. delState = false;
  139. }
  140. });
  141. if (delState)
  142. {
  143. FrmOssManage_Shown(null, null);
  144. }
  145. }
  146. }
  147. else
  148. {
  149. MessageBoxCustom.Show("当前数据只能通过管理员删除!");
  150. }
  151. }
  152. /// <summary>
  153. /// 企业信息确定
  154. /// </summary>
  155. /// <param name="sender"></param>
  156. /// <param name="e"></param>
  157. void btnOK_Click(object sender, EventArgs e)
  158. {
  159. if (LYFZ.BLL.BLL_ErpUser.IsAdministrator())
  160. {
  161. if (uploadOss.sysConfigBll.UpdateAPPInterface(uploadOss.AppInterface.AppUrlPath, tb_EnterpriseID.Text.Trim(), tb_VerificationCode.Text.Trim()))
  162. {
  163. MessageBoxCustom.Show("保存成功!");
  164. FrmOssManage_Shown(null,null);
  165. }
  166. else {
  167. MessageBoxCustom.Show("保存失败!");
  168. }
  169. }
  170. else {
  171. MessageBoxCustom.Show("需要“admin”帐号才能管理云盘帐号");
  172. }
  173. }
  174. }
  175. }