上传单据体数据文件
using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.JSON; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.ServiceHelper.Excel; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; using System.Threading; using System.Web; namespace XXX.K3.BGJ.COMMON.Task { [Description("引入库龄跨组织采购入库上传单据体数据文件")] [HotUpdate] public class PurinStockCrossOrgDataFile : AbstractDynamicFormPlugIn { /// <summary> /// 上传上来的文件名:完整的文件名,包含了物理路径 /// </summary> private string _fullFileName = string.Empty; public override void AfterBindData(EventArgs e) { this.View.GetControl("FOkButton").Enabled = false; } /// <summary> /// 文件上传完毕,触发此事件:通过此事件获取上传上来的文件名 /// </summary> /// <param name="e"></param> public override void CustomEvents(CustomEventsArgs e) { if (e.Key.EqualsIgnoreCase("F_JD_FileUpdate")) { this.View.GetControl("F_JD_FileUpdate").SetCustomPropertyValue("NeedCallback", true); this.View.GetControl("F_JD_FileUpdate").SetCustomPropertyValue("IsRequesting", false); if (e.EventName.ToUpper().EqualsIgnoreCase("FILECHANGED")) {// 文件上传完毕 // 取文件上传参数,文件名 JSONObject uploadInfo = KDObjectConverter.DeserializeObject<JSONObject>(e.EventArgs); if (uploadInfo != null) { JSONArray json = new JSONArray(uploadInfo["NewValue"].ToString()); if (json.Count > 0) { // 取上传的文件名 string fileName = (json[0] as Dictionary<string, object>)["ServerFileName"].ToString(); this._fullFileName = this.GetFullFileName(fileName); // 解锁确定按钮 this.View.GetControl("FOkButton").Enabled = true; } else { // 锁定确定按钮 this.View.GetControl("FOkButton").Enabled = false; } } } } } /// <summary> /// 按钮点击事件 /// </summary> /// <param name="e"></param> public override void ButtonClick(ButtonClickEventArgs e) { if (e.Key.EqualsIgnoreCase("FOkButton")) {// 确定 //this.View.ReturnToParentWindow(new FormResult(this._fullFileName)); DoImportEntry(_fullFileName); } else if (e.Key.EqualsIgnoreCase("FCancelButton")) {// 取消 this.View.Close(); } } /// <summary> /// 开始导入单据体 /// </summary> /// <param name="fullFileName">Excel文件</param> /// <remarks> /// 特别说明:此函数仅演示如何把Excel转换为DataSet, /// 并读取DataSet内容,填写到单据体, /// 未进行任何的安全处理,实际生产环境,需要对数据的合法性进行严格的判断 /// </remarks> private void DoImportEntry(string fullFileName) { using (ExcelOperation helper = new ExcelOperation(this.View)) { // 利用ExcelOperation对象,把xml文件,转为DataSet对象 // 参数说明: // filePath : 完整的文件名,包含了物理目录 // dataStartIndex : 数据开始行索引,从0开始。通常第一行为标题,第二行开始为数据行 // colNameIndex : 列名所在行索引,从0开始。如此参数为0,表明第一行为列名行 DataSet ds = helper.ReadFromFile(fullFileName, 1, 0); // DataSet ds = ReadExcelToTable(fullFileName); // 取第一个表格中的数据导入 DataTable dt = ds.Tables[0]; //发出商品临时表 string oTableName = DBServiceHelper.CreateTemporaryTableName(this.Context); if (dt != null && dt.Rows.Count > 0) { try { // 批量插入到数据库 dt.TableName = oTableName; string tempSql = "/*dialect*/" + ConstructCreateTableSql(dt).Replace("NVarChar", "nvarChar2(2000)").Replace("Decimal", "number(23,10)"); DBServiceHelper.Execute(this.Context, tempSql); DBServiceHelper.BulkInserts(this.Context, string.Empty, string.Empty, dt); if (DBServiceHelper.IsExistTable(this.Context, oTableName)) { StringBuilder sql = new StringBuilder(); sql.Clear(); sql.AppendLine("/*dialect*/ insert into HANS_T_PURINSTOCKCROSSORG(FBILLNO,FSEQ,FDATE)"); sql.AppendFormat(" select 单据编码,行号,to_date(日期,'yyyy-mm-dd') from {0}", oTableName); DBServiceHelper.Execute(this.Context, sql.ToString()); //删除临时表 DBServiceHelper.Execute(this.Context, "/*dialect*/drop table " + oTableName); } this.View.ShowMessage("导入成功!"); Thread.Sleep(2000); this.View.ReturnToParentWindow(new FormResult(this._fullFileName)); this.View.Close(); } catch (Exception ex) { throw new Exception("导入数据报错:" + ex.Message); } } } } /// <summary> /// 根据Datable参数,构建建表的SQL语句,仅对以下的数据类型进行处理 /// string, int16/32/64, double, decimal, date, bool /// 若要处理其它类型的列,需要增加相应的case语句 /// 日期类型需要选SqlDbType.DateTime2,用SqlDbType.DateTime有问题 /// </summary> /// <param name="pDt"></param> /// <returns></returns> public string ConstructCreateTableSql(DataTable pDt) { string sql = ""; sql = "CREATE TABLE " + pDt.TableName + @" ("; foreach (DataColumn col in pDt.Columns) { sql = sql + col.ColumnName; // switch (Type.GetTypeCode(col.DataType)) switch (col.DataType.Name) { //case TypeCode.Int32: //case TypeCode.Int64: //case TypeCode.Int16: case "Int": case "Int32": case "Int16": case "Int64": sql = sql + @" " + SqlDbType.Int + @" ,"; break; //case TypeCode.Decimal: //case TypeCode.Double: case "Decimal": case "Single": case "Double": sql = sql + @" " + SqlDbType.Decimal + @" ,"; break; //case TypeCode.DateTime: case "DateTime": case "Date": sql = sql + @" " + SqlDbType.Date + @" ,"; break; //case TypeCode.String: case "String": sql = sql + @" " + SqlDbType.NVarChar + @" ,"; break; //case TypeCode.Boolean: case "Boolean": sql = sql + @" " + SqlDbType.Bit + @" ,"; break; default: sql = sql + @" " + SqlDbType.NVarChar + @" ,"; break; } } sql = sql.Substring(0, sql.Length - 1) + ")"; return sql; } /// <summary> /// 产生完整的文件名,包含了物理路径 /// </summary> /// <param name="fileName"></param> /// <returns></returns> private string GetFullFileName(string fileName) { string dir = "FileUpLoadServices\\UploadFiles"; return PathUtils.GetPhysicalPath(dir, fileName); } private void DownLoadZipFile(string url) { string fileUrl = url + "File/科目导入模板.xlsx"; DynamicFormShowParameter showPara = new DynamicFormShowParameter(); showPara.FormId = "BOS_FileDownLoad"; showPara.CustomParams.Add("url", fileUrl); showPara.CustomParams.Add("linktext", Kingdee.BOS.Resource.ResManager.LoadKDString("点击下载附件", "002014030028722", Kingdee.BOS.Resource.SubSystemType.BOS)); //showPara.SetToolTip(Kingdee.BOS.Resource.ResManager.LoadKDString("准备数据完成", "002014030028723", Kingdee.BOS.Resource.SubSystemType.BOS)); //showPara.processRate = 100; this.View.Session["ProcessRateValue"] = 100; this.View.ShowForm(showPara); } } }
您好,这个事件里CustomEvents,事件名称等于filechanged时,存在文件还未上传成功至服务器的情况怎么处理的,比如在statechanged事件的时候,谢谢
上传单据体数据文件
using Kingdee.BOS.Core.DynamicForm;using Kingdee.BOS.Core.DynamicForm.PlugIn;using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;using ...
点击下载文档
本文2024-09-16 18:38:17发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-23419.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
- 鼎捷EAI整合規範文件V3.1.07 (集團).pdf
- 鼎捷OpenAPI應用場景說明_基礎資料.pdf
- 鼎捷OpenAPI應用場景說明_財務管理.pdf
- 鼎捷T100 API設計器使用手冊T100 APIDesigner(V1.0).docx
- 鼎新e-GoB2雲端ERP B2 線上課程E6-2應付票據整批郵寄 領取.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程A4使用者建立權限設定.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程C3會計開帳與會計傳票.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程E6-1應付票據.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程A5-1進銷存參數設定(初階篇).pdf
- 鼎新e-GoB2雲端ERP B2 線上課程D2帳款開帳與票據開帳.pdf
热门文章