Piolot_Order_TH/SAL_QUOTATION/DownLoadFile.cs
李狗蛋 397ee99bd8 1
2025-04-01 11:44:11 +08:00

167 lines
7.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm;
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.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GZ_LTHPilot_ORDER.SAL_QUOTATION
{
[Description("【表单插件】销售报价单-下载Word"), HotUpdate]
public class DownLoadFile : AbstractBillPlugIn
{
public override void AfterDoOperation(AfterDoOperationEventArgs e)
{
base.AfterDoOperation(e);
//下载word
if (e.Operation.Operation.Equals("VRYF_tbButton"))
{
//获取时间戳
var ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
var _TimeSpan = Convert.ToInt64(ts.TotalSeconds).ToString();
DynamicObject FSaleOrgId = this.View.Model.GetValue("FSaleOrgId") as DynamicObject;
var oId = Convert.ToInt32(FSaleOrgId["Id"]);
//获取单据日期
DateTime FDATE = Convert.ToDateTime(this.View.Model.GetValue("FDATE"));
//获取纸质合同号
string F_cocntractnumber = Convert.ToString(this.View.Model.GetValue("F_contractnumber"));
//获取客户
DynamicObject FCustId = this.View.Model.GetValue("FCustId") as DynamicObject;
//获取销售员
DynamicObject FSalerId = this.View.Model.GetValue("FSalerId") as DynamicObject;
//获取是否含调试
string FIsDebugging = this.View.Model.GetValue("FIsDebugging")?.ToString();
//获取工程项目
DynamicObject F_projectname = this.View.Model.GetValue("F_projectname") as DynamicObject;
if (FCustId == null)
{
this.View.ShowErrMessage("客户不允许为空!");
return;
}
if (FSalerId == null)
{
this.View.ShowErrMessage("销售员不允许为空!");
return;
}
if (F_projectname == null && oId != 438223)
{
this.View.ShowErrMessage("工程项目不允许为空");
return;
}
string projectname = "";
if (oId != 438223)
{
projectname = F_projectname["NAME"]?.ToString();
//特殊符号平替解决方法:
projectname = projectname.Replace("/", "");
projectname = projectname.Replace("+", "");
projectname = projectname.Replace("*", " ");
projectname = projectname.Replace(":", "");
}
string FPath = string.Format(@"D:\导出Word\{0}\{1}\{2}\{3}年\{4}月\{5}日\{6}.docx", this.Context.DataCenterName, "销售订单",
this.View.Model.DataObject["Billno"], DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, string.Format("{0}-{1}-{2}-{3}-{4}", FDATE.ToString("yyyy-MM-dd"), F_cocntractnumber
, string.IsNullOrWhiteSpace(projectname) ? "" : projectname, FCustId == null ? "" : FCustId["NAME"], FSalerId == null ? "" : FSalerId["NAME"]));
//获取订单类型编码
DynamicObject F_Ordercategory = this.View.Model.GetValue("F_Ordercategory") as DynamicObject;
if (F_Ordercategory == null)
{
return;
}
string FOrdercategory = Convert.ToString(F_Ordercategory["FNumber"]);
//获取金额
string fBILLNO = this.View.Model.GetValue("FBILLNO").ToString();
string sql = string.Format(@"/*dialect*/Select B.FBillAllAmount as 'FBillAllAmount' From T_SAL_QUOTATION A
JOIN T_SAL_QUOTATIONFIN B on A.FID = B.FID Where A.FBILLNO = '{0}'", fBILLNO);
var sqlList = DBUtils.ExecuteDynamicObject(Context, sql);
var fAmount = Convert.ToDecimal(sqlList[0]["FBillAllAmount"]);
if (fAmount >= 200000 && FOrdercategory == "P")
{
FOrdercategory = "PP";
}
var ntess = FIsDebugging;
if (FOrdercategory == "SX" && FIsDebugging == "1")
{
FOrdercategory = "SX-1";
}
if (FOrdercategory == "SX" && FIsDebugging == "0")
{
FOrdercategory = "SX-2";
}
//判断退货/换货
var splitList = F_cocntractnumber.Split('-');
if (splitList.Count() > 1)
{
if (splitList[1].ToString().Contains("TH"))
{
FOrdercategory = "TH";
}
else
{
FOrdercategory = "HH";
}
}
//获取模板地址
var TempModelPath = SqlManage.SqlManage.GetTempModelPath(this.Context, FOrdercategory);
if (TempModelPath == null)
{
this.View.ShowErrMessage("找不到对应的word模板");
return;
}
//获取内容
var TempModelData = SqlManage.SqlManage.GetTempModelData(this.Context, Convert.ToString(this.View.Model.DataObject["Id"]), FOrdercategory);
// 提取文件名
string fileProjectname = Path.GetFileName(FPath);
// 在临时文件目录,生成一个完整的文件名: C:\Program Files\Kingdee\K3Cloud\WebSite\...\JD.xls
string filePath = PathUtils.GetPhysicalPath(KeyConst.TEMPFILEPATH, Path.GetFileName(FPath));
// 生成一个供用户下载文件的url地址: http:\\localhost\K3Cloud\...\JD.xls
string fileUrl = PathUtils.GetServerPath(KeyConst.TEMPFILEPATH, Path.GetFileName(FPath));
//另存为word
Common.CommonHelper.DolondWord(Convert.ToString(TempModelPath[0]["FTempPath"]), TempModelData, FPath, FOrdercategory);
//另存为word
Common.CommonHelper.DolondWord(Convert.ToString(TempModelPath[0]["FTempPath"]), TempModelData, filePath, FOrdercategory);
//下载word
if (!string.IsNullOrEmpty(FPath))
{
//打开文件下载界面
DynamicFormShowParameter showParameter = new DynamicFormShowParameter();
showParameter.FormId = "BOS_FileDownload";
showParameter.OpenStyle.ShowType = ShowType.Modal;
showParameter.CustomComplexParams.Add("url", fileUrl);
//显示
this.View.ShowForm(showParameter);
}
}
string opt = e.Operation.Operation;
if (opt == "Save" && e.OperationResult.IsSuccess)
{
this.View.Refresh();
}
}
}
}