1 Star 0 Fork 0

momoxxx/cq.Plugins

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SupplierActB.cs 15.23 KB
一键复制 编辑 原始数据 按行查看 历史
momoxxx 提交于 2024-01-09 14:40 . 添加项目文件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel;
using Kingdee.BOS;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ControlElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Business.Bill;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Core.Interaction;
using Kingdee.BOS.App;
using Kingdee.BOS.App.Core;
/// <summary>
/// 宇祥 2018.04.12
/// </summary>
namespace Odeer.FIN.AP.Plugins
{
[Description("供应商对账单-B")]
public class SupplierActB : AbstractBillPlugIn
{
public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
public override void BarItemClick(BarItemClickEventArgs e)
{
base.BarItemClick(e);
if (e.BarItemKey.EqualsIgnoreCase("tbUpdateCustBill"))//更新对帐单
{
////分录
DateTime dFirstDate = DateTime.Now;
string sMonth = "", sYearMonth = "";
sMonth = this.View.Model.GetValue("F_PIQE_BillMonth", 0).ToString();
sYearMonth = this.View.Model.GetValue("F_PIQE_YearMonth", 0).ToString().Trim();
if (!sYearMonth.Equals(""))
{
dFirstDate = Convert.ToDateTime(sYearMonth);
dFirstDate = setMonthAndDay(dFirstDate, dFirstDate.Month, 1);
string ls_sql = " EXEC sp_ODE_SupplierActB '" + dFirstDate + "'";
System.Data.IDataReader data3 = Kingdee.BOS.App.Data.DBUtils.ExecuteReader(this.Context, ls_sql);
OperationResult saveResult = new OperationResult();
OperateResult oOperateResult = new OperateResult();
int iRow = 0;
string sFSUPPLIERID = "";
while (data3.Read())
{
sFSUPPLIERID = data3["FSUPPLIERID"].ToString();//客户
oOperateResult = genMo(dFirstDate, sFSUPPLIERID);
if (oOperateResult != null)
{
oOperateResult.Name = "生成供应商对账单B:" + oOperateResult.Number + "成功";
saveResult.OperateResult.Add(oOperateResult);
}
}
data3.Close();
if (saveResult.OperateResult.Count > 0)
{
//保存成功
saveResult.MergeValidateErrors();
this.View.ShowOperateResult(saveResult.OperateResult);
}
//this.View.ShowMessage("生成成功");
}
}
}
#region 供应商对账单-A
public OperateResult genMo(DateTime dFirstDate, string sSUPPLIERID)
{
IBillView billView = this.CreateDataMOView();
// 新建一个空白物料
// billView.CreateNewModelData();
((IBillViewService)billView).LoadData();
// 触发插件的OnLoad事件:
// 组织控制基类插件,在OnLoad事件中,对主业务组织改变是否提示选项进行初始化。
// 如果不触发OnLoad事件,会导致主业务组织赋值不成功
DynamicFormViewPlugInProxy eventProxy = billView.GetService<DynamicFormViewPlugInProxy>();
eventProxy.FireOnLoad();
// 填写工单各属性
this.FillMOPropertys(billView, dFirstDate, sSUPPLIERID);
// 保存物料
OperateOption saveOption = OperateOption.Create();
return this.SaveMo(billView, saveOption);
}
/// <summary>
/// 创建一个单据视图,后续将利用此视图的各种方法,设置物料字段值
/// </summary>
/// <remarks>
/// 理论上,也可以直接修改物料的数据包达成修改数据的目的
/// 但是,利用单据视图更具有优势:
/// 1. 视图会自动触发插件,这样逻辑更加完整;
/// 2. 视图会自动利用单据元数据,填写字段默认值,不用担心字段值不符合逻辑;
/// 3. 字段改动,会触发实体服务规则;
///
/// 而手工修改数据包的方式,所有的字段值均需要自行填写,非常麻烦
/// </remarks>
private IBillView CreateDataMOView()
{
// 读取物料的元数据
FormMetadata meta = MetaDataServiceHelper.Load(this.Context, "PAEZ_SupplierActA") as FormMetadata;
Form form = meta.BusinessInfo.GetForm();
// 创建用于引入数据的单据view
Type type = Type.GetType("Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web");
var billView = (Kingdee.BOS.Core.DynamicForm.IDynamicFormViewService)Activator.CreateInstance(type);
// 开始初始化billView:
// 创建视图加载参数对象,指定各种参数,如FormId, 视图(LayoutId)等
BillOpenParameter openParam = CreateOpenParameterMO(meta);
// 动态领域模型服务提供类,通过此类,构建MVC实例
var provider = form.GetFormServiceProvider();
billView.Initialize(openParam, provider);
return billView as IBillView;
}
/// <summary>
/// 创建视图加载参数对象,指定各种初始化视图时,需要指定的属性
/// </summary>
/// <param name="meta">元数据</param>
/// <returns>视图加载参数对象</returns>
private BillOpenParameter CreateOpenParameterMO(FormMetadata meta)
{
Form form = meta.BusinessInfo.GetForm();
// 指定FormId, LayoutId
BillOpenParameter openParam = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id);
// 数据库上下文
openParam.Context = this.Context;
// 本单据模型使用的MVC框架
openParam.ServiceName = form.FormServiceName;
// 随机产生一个不重复的PageId,作为视图的标识
openParam.PageId = Guid.NewGuid().ToString();
// 元数据
openParam.FormMetaData = meta;
// 界面状态:新增 (修改、查看)
openParam.Status = OperationStatus.ADDNEW;
// 单据主键:本案例演示新建BOM,不需要设置主键
openParam.PkValue = null;
// 界面创建目的:普通无特殊目的 (为工作流、为下推、为复制等)
openParam.CreateFrom = CreateFrom.Default;
// 基础资料分组维度:基础资料允许添加多个分组字段,每个分组字段会有一个分组维度
// 具体分组维度Id,请参阅 form.FormGroups 属性
openParam.GroupId = "";
// 基础资料分组:如果需要为新建的基础资料指定所在分组,请设置此属性
openParam.ParentId = 0;
// 单据类型
openParam.DefaultBillTypeId = "";
// 业务流程
openParam.DefaultBusinessFlowId = "";
// 主业务组织改变时,不用弹出提示界面
openParam.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
// 插件
List<AbstractDynamicFormPlugIn> plugs = form.CreateFormPlugIns();
openParam.SetCustomParameter(FormConst.PlugIns, plugs);
PreOpenFormEventArgs args = new PreOpenFormEventArgs(this.Context, openParam);
foreach (var plug in plugs)
{// 触发插件PreOpenForm事件,供插件确认是否允许打开界面
plug.PreOpenForm(args);
}
if (args.Cancel == true)
{// 插件不允许打开界面
// 本案例不理会插件的诉求,继续....
}
// 返回
return openParam;
}
/// <summary>
/// 把物料的各属性,填写到IBillView当前所管理的物料中
/// </summary>
/// <param name="billView"></param>
private void FillMOPropertys(IBillView billView, DateTime dFirstDate, string sSUPPLIERID)
{
IDynamicFormViewService dynamicFormView = billView as IDynamicFormViewService;
string sOrgId = this.Context.CurrentOrganizationInfo.ID.ToString();
/********************MO页签上的字段******************/
billView.GetService<ViewService>();
DateTime dLastDate = DateTime.Now;
dFirstDate = setMonthAndDay(dFirstDate, dFirstDate.Month, 1);
dLastDate = setMonthAndDay(dFirstDate, dFirstDate.Month, DateTime.DaysInMonth(dFirstDate.Year, dFirstDate.Month));
//dynamicFormView.SetItemValueByID("FCustID", sCustId, 0);//客户代码
dynamicFormView.UpdateValue("F_PIQE_Datefrm", 0, dFirstDate);//会计日期(从)
dynamicFormView.UpdateValue("F_PIQE_Dateto", 0, dLastDate);//会计日期(至)
dynamicFormView.UpdateValue("F_PIQE_YearMonth", 0, dFirstDate);
////分录
string ls_sql = " EXEC sp_ODE_SupplierActBDetail '" + dFirstDate + "','" + sSUPPLIERID + "'";
System.Data.IDataReader data3 = Kingdee.BOS.App.Data.DBUtils.ExecuteReader(this.Context, ls_sql);
func_ClearNullRow(billView, "FEntity", "");
int iRow = 0;
while (data3.Read())
{
billView.Model.CreateNewEntryRow("FEntity");
iRow = billView.Model.GetEntryCurrentRowIndex("FEntity");
billView.Model.SetItemValueByID("F_PIQE_CustId", data3["FSUPPLIERID"].ToString(), iRow);//客户
billView.Model.SetValue("FBILLTYPE", data3["FBILLTYPE"].ToString(), iRow);//单据类型
billView.Model.SetValue("F_PIQE_Date", data3["FDATE"].ToString(), iRow);//业务日期
billView.Model.SetValue("F_PIQE_BillNo", data3["FBILLNO"].ToString(), iRow);// 单号
billView.Model.SetValue("FMTRLNO", data3["MTRLNO"].ToString(), iRow);// 物料编码
billView.Model.SetValue("FMTRLNAME", data3["MTRLNAME"].ToString(), iRow);// 物料名称
billView.Model.SetValue("FSpecification", data3["FSpecification"].ToString(), iRow);// 物料规格
billView.Model.SetValue("FPriceQty", data3["FPriceUnitQty"].ToString(), iRow);// 数量
billView.Model.SetValue("FTaxPrice", data3["FTaxPrice"].ToString(), iRow);// 单价
billView.Model.SetValue("FAllAmount", data3["FAllAmount"].ToString(), iRow);// 价税合计
billView.Model.SetValue("FRECEIVEAMT", data3["FRECEIVEAMT"].ToString(), iRow);// 已收款金额
billView.Model.SetValue("FBALAMT", data3["FBALAMT"].ToString(), iRow);// 余额
}
data3.Close();
}
/// <summary>
/// 保存物料,并显示保存结果
/// </summary>
/// <param name="billView"></param>
/// <returns></returns>
private OperateResult SaveMo(IBillView billView, OperateOption saveOption)
{
OperateResult oOperateResult = null;
// 设置FormId
Form form = billView.BillBusinessInfo.GetForm();
if (form.FormIdDynamicProperty != null)
{
form.FormIdDynamicProperty.SetValue(billView.Model.DataObject, form.Id);
}
// 调用保存操作
IOperationResult saveResult = BusinessDataServiceHelper.Save(
this.Context,
billView.BillBusinessInfo,
billView.Model.DataObject,
saveOption,
"Save");
// 显示处理结果
if (saveResult == null)
{
this.View.ShowErrMessage("未知原因导致保存失败!");
oOperateResult = saveResult.OperateResult[0];
}
else if (saveResult.IsSuccess == true)
{// 保存成功,直接显示
//this.View.ShowOperateResult(saveResult.OperateResult);
oOperateResult = saveResult.OperateResult[0];
}
else if (saveResult.InteractionContext != null
&& saveResult.InteractionContext.Option.GetInteractionFlag().Count > 0)
{// 保存失败,需要用户确认问题
InteractionUtil.DoInteraction(this.View, saveResult, saveOption,
new Action<FormResult, IInteractionResult, OperateOption>((
formResult, opResult, option) =>
{
// 用户确认完毕,重新调用保存处理
this.SaveMo(billView, option);
}));
}
else if (saveResult.ValidationErrors.Count > 0)
{
oOperateResult = new OperateResult()
{
Message = saveResult.ValidationErrors[0].Message,
Name = saveResult.ValidationErrors[0].Title,
MessageType = MessageType.FatalError,
SuccessStatus = false
};
}
return oOperateResult;
}
/// <summary>
/// 清除空行
/// </summary>
public void func_ClearNullRow(IBillView BillView, string sEntryId, string sKeyId)
{
int i = 0;
while (BillView.Model.GetEntryRowCount(sEntryId) > 0)
{
try
{
BillView.Model.DeleteEntryRow(sEntryId, i);
}
catch
{
BillView.Model.DeleteEntryRow(sEntryId, i);
}
i++;
}
}
#endregion
/// <summary>
/// 设置日期为指定的月和日
/// </summary>
/// <param name="dt">日期</param>
/// <param name="month">月</param>
/// <param name="day">日</param>
/// <returns>设置完成的日期</returns>
public DateTime setMonthAndDay(DateTime dt, int month, int day)
{
dt = dt.AddMonths(month - dt.Month);
int maxDay = DateTime.DaysInMonth(dt.Year, dt.Month);
if (maxDay < day)
{
dt = dt.AddDays(maxDay - dt.Day);
}
else
{
dt = dt.AddDays(day - dt.Day);
}
return dt;
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/momoxxx/cq.-plugins.git
git@gitee.com:momoxxx/cq.-plugins.git
momoxxx
cq.-plugins
cq.Plugins
master

搜索帮助