根据字段自动生成二维码赋值原创
6人赞赏了该文章
189次浏览
未经作者许可,禁止转载编辑于2024年06月01日 08:42:10
using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Text; using ThoughtWorks.QRCode.Codec; using Kingdee.BOS.App.Data; namespace WRKU.OSDA.K3Cloud.GYL.XSGL.CHCL.FHTZD.ServicePlugIn { [Kingdee.BOS.Util.HotUpdate] [Description("根据字段自动生成二维码赋值")] public class SubmitToOA : AbstractOperationServicePlugIn { /// <summary> /// 操作开始前功能处理 /// </summary> /// <param name="e"></param> public override void BeginOperationTransaction(BeginOperationTransactionArgs e) { base.BeginOperationTransaction(e); { //保存单据时, 将单据编号保存到单据体上备注字段上(FEntryNote) var billNoField = this.BusinessInfo.GetBillNoField(); var entity = this.BusinessInfo.GetEntity("FPOOrderEntry"); foreach (var dataEntity in e.DataEntitys) { var rows = (DynamicObjectCollection)dataEntity[entity.DynamicProperty.Name]; if (rows != null) { foreach (var row in rows) { List<string> result = GetQrCode(row["F_UNW_Text_ewm"].ToString()); int x = DBUtils.Execute(this.Context, result[1]); if (x > 0) { row["F_UNW_Picture_83g"] = result[0]; } } } } } } public static string GetObjectValeByKey(object obj, string key) { DynamicObject dyobj = obj as DynamicObject; return Convert.ToString(dyobj[key]); } /// <summary> /// 生成二维码图片 /// </summary> /// <param name="data"></param> /// <returns></returns> public static List<string> GetQrCode(string data) { List<string> list = new List<string>(); var fille = Guid.NewGuid().ToString().Replace("-", ""); list.Add(fille); var imgFileName = fille + ".png"; var encoder = new QRCodeEncoder(); encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; //编码方法(注意:BYTE能支持中文,ALPHA_NUMERIC扫描出来的都是数字) encoder.QRCodeScale = 4; //大小(值越大生成的二维码图片像素越高) encoder.QRCodeVersion = 0; //版本(注意:设置为0主要是防止编码的字符串太长时发生错误) encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; //错误效验、错误更正(有4个等级) var bp = encoder.Encode(data, Encoding.GetEncoding("UTF-8")); var imgFilePath = AppDomain.CurrentDomain.BaseDirectory + "TempfilePath/" + imgFileName; bp.Save(imgFilePath); string destinationFilePath = ""; // var imgBytes = File.ReadAllBytes(imgFilePath); DateTime currentDateTime = DateTime.Now; int currentYear = currentDateTime.Year; try { // 提取当前年份 // 确保目标目录存在,如果不存在则创建 if (!Directory.Exists("D:\\FILE\\Image\\2024")) { Directory.CreateDirectory("D:\\FILE\\Image\\2024"); } // 构建目标文件的完整路径 destinationFilePath = Path.Combine("D:\\FILE\\Image\\2024", Path.GetFileName(imgFilePath)); // 复制文件,如果目标文件已存在则覆盖 File.Copy(imgFilePath, destinationFilePath, true); } catch (IOException ex) { } // 获取当前日期和时间 // 格式化为指定格式 string formattedTime = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 获取文件大小 long fileSizeInBytes = new FileInfo(destinationFilePath).Length; //long fileSizeInBytes = new FileInfo(imgFilePath).Length; string ins = "INSERT INTO T_BAS_FileServerFileInfo (FFILEID, FFILESERVERDIRID, FFILENAME, FLOCATIONPATH, FRELATIVEPATH, FCREATEDATE, FCREATORID, FFILESIZE, FISCOMPLETED, FSWFLOCATIONPATH, FSWFCOUNT, FFILESTORAGE, FFILESERVERID) VALUES ('" + fille + "', '232714', '" + imgFileName + "', '" + destinationFilePath + "', '\\Image\\" + currentYear + "\\" + imgFileName + "', '" + formattedTime + "', '0', '" + fileSizeInBytes + "', '1', 'NotConvert', '0', '0', '0')"; list.Add(ins); // File.Delete(imgFilePath); return list; } /// <summary> /// 生成二维码图片 /// </summary> /// <param name="data"></param> /// <returns></returns> public static string GetQrCodes(string data) { var imgFileName = Guid.NewGuid().ToString().Replace("-", "") + ".png"; var encoder = new QRCodeEncoder(); encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; //编码方法(注意:BYTE能支持中文,ALPHA_NUMERIC扫描出来的都是数字) encoder.QRCodeScale = 4; //大小(值越大生成的二维码图片像素越高) encoder.QRCodeVersion = 0; //版本(注意:设置为0主要是防止编码的字符串太长时发生错误) encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; //错误效验、错误更正(有4个等级) var bp = encoder.Encode(data, Encoding.GetEncoding("UTF-8")); var imgFilePath = AppDomain.CurrentDomain.BaseDirectory + "TempfilePath/" + imgFileName; bp.Save(imgFilePath); var imgBytes = File.ReadAllBytes(imgFilePath); // File.Delete(imgFilePath); return ""; } /// <summary> /// 操作结束后功能处理 /// </summary> /// <param name="e"></param> public override void EndOperationTransaction(EndOperationTransactionArgs e) { } } }
赞 6
6人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读