171 lines
7.9 KiB
C#
171 lines
7.9 KiB
C#
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;
|
||
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 : AbstractDynamicFormPlugIn
|
||
{
|
||
|
||
public override void BarItemClick(BarItemClickEventArgs e)
|
||
{
|
||
base.BarItemClick(e);
|
||
if (e.BarItemKey.Equals("VRYF_tbButton"))
|
||
{
|
||
//this.View.ShowMessage("1233456");
|
||
//获取时间戳
|
||
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;
|
||
//获取是否不含施工,含调试费#
|
||
String F_BHSGHTSF = this.View.Model.GetValue("F_BHSGHTSF")?.ToString();
|
||
//判断是否含施工
|
||
String F_HSG = this.View.Model.GetValue("F_HSG")?.ToString();
|
||
|
||
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 = "";
|
||
string FCustIdprojectname = "";
|
||
if (oId != 438223)
|
||
{
|
||
projectname = F_projectname["NAME"]?.ToString();
|
||
//特殊符号平替解决方法:
|
||
projectname = projectname.Replace("/", "/");
|
||
projectname = projectname.Replace("+", "➕");
|
||
projectname = projectname.Replace("*", " ");
|
||
projectname = projectname.Replace(":", ":");
|
||
projectname = projectname.Replace("\"", "“");
|
||
|
||
FCustIdprojectname = FCustId["NAME"]?.ToString();
|
||
//特殊符号平替解决方法:
|
||
FCustIdprojectname = FCustIdprojectname.Replace("/", "/");
|
||
FCustIdprojectname = FCustIdprojectname.Replace("+", "➕");
|
||
FCustIdprojectname = FCustIdprojectname.Replace("*", " ");
|
||
FCustIdprojectname = FCustIdprojectname.Replace(":", ":");
|
||
FCustIdprojectname = FCustIdprojectname.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,FCustIdprojectname, FSalerId == null ? "" : FSalerId["NAME"]));
|
||
|
||
//获取金额
|
||
string fBILLNO = this.View.Model.GetValue("FBILLNO").ToString();
|
||
//获取销售报价单的合同类型,根据报价单合同类型获取模版
|
||
string sql = string.Format(@"/*dialect*/
|
||
EXEC GetSAL_QUOTATIONHT_GZTH '{0}'
|
||
", fBILLNO);
|
||
var sqlList = DBUtils.ExecuteDynamicObject(Context, sql);
|
||
//取值合同类型
|
||
var F_Ordercategory = Convert.ToString(sqlList[0]["FNUMBER"]);
|
||
String FOrdercategory = "";
|
||
|
||
//判断是哪个合同
|
||
if (F_Ordercategory == "C")
|
||
{
|
||
FOrdercategory = "XNC";
|
||
}
|
||
if(F_Ordercategory == "CS")
|
||
{
|
||
//判断含调试费
|
||
if (F_BHSGHTSF == "True")
|
||
{
|
||
FOrdercategory = "XNSGCS";
|
||
}
|
||
//判断含施工,不含调试费
|
||
else if (F_HSG == "True")
|
||
{
|
||
FOrdercategory = "XNTSCS";
|
||
}
|
||
}
|
||
if (F_Ordercategory == "CW") {
|
||
//判断是否按服务事件报价
|
||
|
||
}
|
||
|
||
//获取模板地址
|
||
var TempModelPath = SqlManage.SqlManage.GetTempModelPath(this.Context, FOrdercategory);
|
||
if (TempModelPath.Count == 0)
|
||
{
|
||
this.View.ShowErrMessage("找不到对应的word模板,CS模版需勾选是否不含施工或是否含施工复选框。");
|
||
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();
|
||
//}
|
||
}
|
||
}
|
||
}
|