[password]123456[/password]
[code]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core;
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.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ControlElement;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.ServiceHelper.Excel;
using Kingdee.BOS.Util;
namespace YEA.K3.MIS.Business.PlugIn.CW
{
[Description("动态表单插件:Bom 成本采购价格查询报表")]
public class DynamicBomOfNewPriceAndAuxPriceRept : AbstractDynamicFormPlugIn
{
private BusinessInfo _currInfo;
private LayoutInfo _currLayout;
private string _fBomNumber;
private string _fItemNumber;
private string _fbeginDate;
private string _fendDate;
#region 按钮点击事件
public override void AfterButtonClick(AfterButtonClickEventArgs e)
{
base.AfterButtonClick(e);
if (e.Key.ToUpper().Equals("FQUERYBTN"))
{
Search(); //查询
}
else if (e.Key.ToUpper().Equals("FEXCELOUT"))
{
//导出Excel
List
returnDatas.Add("FList");
YEA.K3.MIS.APP.Core.CommonUtil.ExcelOut(returnDatas, this.View);
}
}
#endregion
#region 数据查询
private DataTable GetEntryData()
{
string sql = "/*dialect*/[YL_proc_getBomOfNewPriceAndAuxPrice]";
_fBomNumber = this.Model.GetValue("FBomNumber") == null ? "" : this.Model.GetValue("FBomNumber").ToString();
_fItemNumber = this.Model.GetValue("FItemNumber") == null ? "" : this.Model.GetValue("FItemNumber").ToString();
_fbeginDate = this.Model.GetValue("FbeginDate") == null
? "1900-01-01 00:00:00"
: this.Model.GetValue("FbeginDate").ToString();
_fendDate = this.Model.GetValue("FendDate") == null
? "1900-01-01 00:00:00"
: this.Model.GetValue("FendDate").ToString();
List
list.Add(new SqlParam("@FBomNumber", KDDbType.String, _fBomNumber));
list.Add(new SqlParam("@FItemNumber", KDDbType.String, _fItemNumber));
list.Add(new SqlParam("@FbeginDate", KDDbType.DateTime, Convert.ToDateTime(_fbeginDate)));
list.Add(new SqlParam("@FendDate", KDDbType.DateTime, Convert.ToDateTime(_fendDate)));
DataTable dt = DBUtils.ExecuteDataSet(this.Context, CommandType.StoredProcedure, sql, list).Tables[0];
return dt;
}
#endregion
#region 查询
private void Search()
{
DataTable dyobj = GetEntryData();
if (dyobj != null)
{
// 修改元数据
this.ReBuildFields(dyobj);
// 根据新的元数据,重构单据体表格列
EntryGrid grid = this.View.GetControl
grid.SetAllowLayoutSetting(false); // 列按照索引显示
grid.Enabled = false; //不可编辑
EntityAppearance listAppearance = _currLayout.GetEntityAppearance("FList");
grid.CreateDyanmicList(listAppearance);
// 填充数据
this.SetData(dyobj);
// 下达一个指令
this.View.SendDynamicFormAction(this.View);
this.View.UpdateView("FList"); //解决单据体刷新
}
}
#endregion
#region 重新构造单据体
///
/// 初始化界面元数据时触发此事件
///
///
///
/// 通常在此事件中,修改界面元数据;
/// 本示例,在此事件中,把界面元数据复制到本地,避免与其他实例公用元数据,造成串账
///
public override void OnSetBusinessInfo(SetBusinessInfoArgs e)
{
// 复制界面元数据到本地变量
FormMetadata currMeta = (FormMetadata)ObjectUtils.CreateCopy(
this.View.OpenParameter.FormMetaData);
_currInfo = currMeta.BusinessInfo;
_currLayout = currMeta.GetLayoutInfo();
// 用本地的元数据,替换动态表单引擎持有的元数据
e.BusinessInfo = _currInfo;
e.BillBusinessInfo = _currInfo;
}
///
/// 初始化界面元数据时触发此事件
///
///
///
/// 通常在此事件中,修改界面元数据;
/// 本示例,在此事件中,把界面元数据复制到本地,避免与其他实例公用元数据,造成串账
///
public override void OnSetLayoutInfo(SetLayoutInfoArgs e)
{
e.LayoutInfo = _currLayout;
e.BillLayoutInfo = _currLayout;
}
///
/// 行点击事件
///
///
//public override void EntityRowClick(EntityRowClickEventArgs e)
//{
// base.EntityRowClick(e);
// SetEntityColor("FList"); //隔行换色--解决分页样式显示问题
//}
///
/// 在单据体元数据中,重新构建字段。字段数量由参数决定
///
private void ReBuildFields(DataTable dyobj)
{
// 获取单据体表格的元数据及外观
Entity entity = _currInfo.GetEntity("FList");
EntityAppearance entityApp = _currLayout.GetEntityAppearance("FList");
// 清除全部字段
int oldCount = entity.Fields.Count;
for (int i = oldCount - 1; i >= 0; i--)
{
Field fld = entity.Fields[i];
_currInfo.Remove(fld);
Appearance fldApp = _currLayout.GetAppearance(fld.Key);
_currLayout.Remove(fldApp);
}
// 重新添加字段
for (int i = 0; i < dyobj.Columns.Count; i++)
{
// 构建文本字段
Field fld;
/*if (dyobj.Columns[i].DataType == typeof(int))
{
fld = new QtyField();
}
else if (dyobj.Columns[i].DataType == typeof(double) || dyobj.Columns[i].DataType == typeof(decimal))
{
fld = new DecimalField();
}
else
{
// 构建文本字段
fld = new TextField();
}*/
fld = new TextField();
fld.Key = string.Format("F{0}", i);
fld.Name = new LocaleValue(string.Format("{0}", dyobj.Columns[i].ColumnName.ToString()));
fld.PropertyName = fld.Key;
fld.EntityKey = "FList";
fld.Entity = entity;
_currInfo.Add(fld);
TextFieldAppearance fldApp = new TextFieldAppearance();
fldApp.Key = fld.Key;
fldApp.Caption = fld.Name;
fldApp.EntityKey = fld.EntityKey;
fldApp.Width = new LocaleValue("90");
fldApp.LabelWidth = new LocaleValue("80");
fldApp.Tabindex = i;
fldApp.Field = fld;
fldApp.TextEditStyle = 1;
if (i == 2)
{
fldApp.Width = new LocaleValue("200");
}
_currLayout.Add(fldApp);
}
}
///
/// 为单据体全部数据
///
private void SetData(DataTable dyobj)
{
// 使用最新的元数据,重新界面数据包
_currInfo.GetDynamicObjectType(true);
this.Model.CreateNewData();
this.Model.BeginIniti();
#region 查询条件重新赋值
this.Model.SetValue("FBomNumber", _fBomNumber);
this.Model.SetValue("FItemNumber", _fItemNumber);
this.Model.SetValue("FbeginDate", _fbeginDate);
this.Model.SetValue("FendDate", _fendDate);
#endregion
for (int i = 0; i < dyobj.Rows.Count; i++)
{
this.Model.CreateNewEntryRow("FList");
foreach (var fld in _currInfo.GetEntity("FList").Fields)
{
if (fld is TextField)
{
this.Model.SetValue(fld.Key, string.Format("{0}",
dyobj.Rows[i][Convert.ToInt32(fld.Key.Replace("F", ""))]), i);
}
else
{
this.Model.SetValue(fld.Key,
string.IsNullOrEmpty(dyobj.Rows[i][Convert.ToInt32(fld.Key.Replace("F", ""))].ToString()) ? null : dyobj.Rows[i][Convert.ToInt32(fld.Key.Replace("F", ""))].ToString(), i);
}
}
}
this.Model.EndIniti();
}
///
/// 设置表体行背景
///
private void SetEntityColor(string entryName)
{
List
int entityCount = this.Model.GetEntryRowCount(entryName);
for (int rowIndex = 0; rowIndex < entityCount; rowIndex++)
{
if (rowIndex % 2 == 0)
{
colors.Add(new KeyValuePair
}
else
{
colors.Add(new KeyValuePair
}
}
EntryGrid grid = this.View.GetControl
if (colors.Count > 0)
{
grid.SetRowBackcolor(colors);
}
List
backcolors.Add(new KeyValuePair
grid.SetRowBackcolor(backcolors);
}
#endregion
}
}
[/code]
推荐阅读