diff --git a/插件库/Lskj.Control/Model/MyControl.cs b/插件库/Lskj.Control/Model/MyControl.cs index caf3b9f..e4372f1 100644 --- a/插件库/Lskj.Control/Model/MyControl.cs +++ b/插件库/Lskj.Control/Model/MyControl.cs @@ -2970,63 +2970,73 @@ namespace Lskj.Control.Model if (isTip) MessageUtil.Show(ResourceKeys.SaveSuccess); #endregion #region 保存成功后上传附件 - string idValue = primaryValue; - if (SystemModel != null && !string.IsNullOrWhiteSpace(SystemModel.AttachmentAssociated)) + try { - idValue = GetControlValue(SystemModel.AttachmentAssociated); - } - List uploadModels = ControlModels.Where(n => n.FileUploadControl).ToList(); - foreach (ControlModel uploadModel in uploadModels) - { - BaseUserControl uploadControl = FindControl(uploadModel); - if (uploadControl != null && uploadControl is LabelRemarkEdit labelRemarkEdit && !string.IsNullOrEmpty(labelRemarkEdit.filepath) && File.Exists(labelRemarkEdit.filepath)) + string idValue = primaryValue; + if (SystemModel != null && !string.IsNullOrWhiteSpace(SystemModel.AttachmentAssociated)) { - string filePath = labelRemarkEdit.filepath; - string token = UploadFileUtil.Login(SystemInfo.Instance.OAUrl); - if (!string.IsNullOrEmpty(token)) + idValue = GetControlValue(SystemModel.AttachmentAssociated); + } + ControlModel uploadModel = ControlModels.Where(n => n.FileUploadControl).FirstOrDefault(); + if (uploadModel != null) + { + BaseUserControl uploadControl = FindControl(uploadModel); + if (uploadControl != null && uploadControl is LabelRemarkEdit labelRemarkEdit && !string.IsNullOrEmpty(labelRemarkEdit.filepath) && File.Exists(labelRemarkEdit.filepath)) { - string speciesno = "010106"; - GetFileCodeInfo(Path.GetFileNameWithoutExtension(filePath), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC); - byte[] fileBytes = UploadFileUtil.ConvertFileToBytes(filePath); - string fileStream = Convert.ToBase64String(fileBytes); - string selectSql = $"select * from P_fm_FileTab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{idValue}' and dllcoid = '{Model.ModuleCode}') and speciesno = '{speciesno}' and sname like '{sourceCode}%'"; - DataTable deleteTable = BaseImpl.GetDataTableResult(selectSql); - if (deleteTable != null && deleteTable.Rows.Count > 0) + string filePath = labelRemarkEdit.filepath; + string token = UploadFileUtil.Login(SystemInfo.Instance.OAUrl); + if (!string.IsNullOrEmpty(token)) { - foreach (DataRow deleteRow in deleteTable.Rows) + string speciesno = "010106"; + GetFileCodeInfo(Path.GetFileNameWithoutExtension(filePath), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC); + byte[] fileBytes = UploadFileUtil.ConvertFileToBytes(filePath); + string fileStream = Convert.ToBase64String(fileBytes); + string selectSql = $"select * from P_fm_FileTab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{idValue}' and dllcoid = '{Model.ModuleCode}') and speciesno = '{speciesno}' and sname like '{sourceCode}%'"; + DataTable deleteTable = BaseImpl.GetDataTableResult(selectSql); + if (deleteTable != null && deleteTable.Rows.Count > 0) { - string field = HttpUtility.UrlEncode(deleteRow["fileId"] + ""); - string webpath = HttpUtility.UrlEncode(deleteRow["webpath"] + ""); - //删除文件 - string deleteUrl = "{0}Api/FileUploadApi.ashx?fileId={1}&filename={2}&method={3}"; - deleteUrl = string.Format(deleteUrl, SystemInfo.Instance.OAUrl, field, webpath, "DoDelete"); - HttpHelper.Setting("application/x-www-form-urlencoded", null, null); - Dictionary deleteHeaderDic = new Dictionary(); - deleteHeaderDic.Add("Authorization", $"Bearer {token}"); - HttpHelper.Post(deleteUrl, fileStream, null, deleteHeaderDic, out string deleteResult); + foreach (DataRow deleteRow in deleteTable.Rows) + { + string field = HttpUtility.UrlEncode(deleteRow["fileId"] + ""); + string webpath = HttpUtility.UrlEncode(deleteRow["webpath"] + ""); + //删除文件 + string deleteUrl = "{0}Api/FileUploadApi.ashx?fileId={1}&filename={2}&method={3}"; + deleteUrl = string.Format(deleteUrl, SystemInfo.Instance.OAUrl, field, webpath, "DoDelete"); + HttpHelper.Setting("application/x-www-form-urlencoded", null, null); + Dictionary deleteHeaderDic = new Dictionary(); + deleteHeaderDic.Add("Authorization", $"Bearer {token}"); + HttpHelper.Post(deleteUrl, fileStream, null, deleteHeaderDic, out string deleteResult); + } + } + string postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&speciesno={8}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}&confirm=1"; + postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, Model.ModuleCode, HttpUtility.UrlEncode(idValue), "file", fileBytes.Length, 0, HttpUtility.UrlEncode(Path.GetFileName(filePath)), "DoWebUpload", speciesno); + bool isUpload = UploadFileUtil.UploadFile(token, postUrl, fileStream, out string fileId, out string rtnMsg); + if (!isUpload) + { + throw new Exception($"自动上传失败\r\n{rtnMsg}"); + } + else + { + string updateSql = $"update QMS_wenjiangenggaitab set fileId = '{fileId}' where qms_wjgg_billdocument_id = '{primaryValue}'"; + SqlHelper.ExecuteNonQuery(updateSql); } - } - string postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&speciesno={8}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}&confirm=1"; - postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, Model.ModuleCode, HttpUtility.UrlEncode(idValue), "file", fileBytes.Length, 0, HttpUtility.UrlEncode(Path.GetFileName(filePath)), "DoWebUpload", speciesno); - bool isUpload = UploadFileUtil.UploadFile(token, postUrl, fileStream, out string fileId, out string rtnMsg); - if (!isUpload) - { - MessageUtil.Show($"自动上传失败\r\n{rtnMsg}"); - return false; } else { - string updateSql = $"update {SystemModel.MenuTable} set fileId = '{fileId}' where {SystemModel.ParmaryKey} = '{primaryValue}'"; - BaseImpl.ExecSqlValue(updateSql); + throw new Exception($"登录失败,自动上传失败"); } } - else - { - MessageUtil.Show($"登录失败,自动上传失败"); - return false; - } } } + catch (Exception ex) + { + MessageUtil.Show(ex.Message); + if (isAdd) + { + BaseImpl.ExecSqlValue($"delete QMS_wenjiangenggaitab where qms_wjgg_billdocument_Id = '{primaryValue}'"); + } + return false; + } #endregion #region 保存后执行某个右键 if (SystemModel != null && !string.IsNullOrEmpty(SystemModel.AfterSaveExec)) @@ -4593,14 +4603,14 @@ namespace Lskj.Control.Model baseControl.EditText = dataRow["sname"] + ""; VerControl.EditText = dataRow["Ver"] + ""; fileidControl.EditText = dataRow["fileid"] + ""; - string IsLatest=dataRow["IsLatest"] + ""; + string IsLatest = dataRow["IsLatest"] + ""; if (IsLatest.Equals("False")) { MessageUtil.Show("当前变更的版本低于历史版本,请检查!"); labelRemarkEdit.EditText = string.Empty; } } - + // 手动触发关联,有可能单据打开后直接点击新增按钮此时文本框值未改变,不会触发关联和计算 this.SetUnionAncCalcControl(labelRemarkEdit); } @@ -5957,30 +5967,4 @@ namespace Lskj.Control.Model LabelDateEdit dateEdit = controlObj as LabelDateEdit; value = dateEdit.TextEdit.EditValue == null ? dateEdit.EditText : dateEdit.TextEdit.DateTime.ToString("yyyy-MM-dd"); } - else if (controlObj is LabelCheckEdit) - { - LabelCheckEdit checkEdit = controlObj as LabelCheckEdit; - value = checkEdit.EditText; - } - else if (controlObj is LabelComboxEdit) - { - LabelComboxEdit autoEdit = controlObj as LabelComboxEdit; - value = autoEdit.EditValue; - } - else if (controlObj is LabelTextEdit) - { - LabelTextEdit textIntEdit = controlObj as LabelTextEdit; - if (textIntEdit != null) value = string.IsNullOrEmpty(textIntEdit.EditText) ? "0" : textIntEdit.EditText; - } - - defaultValue = defaultValue.Replace(item, value); - } - - } - } - return defaultValue; - } - - - } -} \ No newline at end of file + else if \ No newline at end of file