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 { /// /// 图片集合 /// 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 delList = new List(); 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("当前数据只能通过管理员删除!"); } } /// /// 企业信息确定 /// /// /// 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”帐号才能管理云盘帐号"); } } } }