using System;
using System.Data;
using System.Collections;
using BP.DA;
using BP.Sys.Base;
using BP.En;
using System.Collections.Generic;
using System.IO;
using BP.Pub;
namespace BP.Sys
{
///
/// 映射基础
///
public class MapDataAttr : EntityNoNameAttr
{
///
/// 表单事件实体类
///
public const string FormEventEntity = "FormEventEntity";
///
/// 存储表
///
public const string PTable = "PTable";
///
/// 表存储格式0=自定义表,1=指定表,可以修改字段2=执行表不可以修改字段.
///
public const string PTableModel = "PTableModel";
///
/// 从表数量
///
public const string Dtls = "Dtls";
///
/// 实体主键
///
public const string EnPK = "EnPK";
///
/// 宽度
///
public const string FrmW = "FrmW";
///
/// 表格列(对傻瓜表单有效)
///
public const string TableCol = "TableCol";
///
/// 来源
///
public const string FrmFrom = "FrmFrom";
///
/// 设计者
///
public const string Designer = "Designer";
///
/// 设计者单位
///
public const string DesignerUnit = "DesignerUnit";
///
/// 设计者联系方式
///
public const string DesignerContact = "DesignerContact";
///
/// 设计器
///
public const string DesignerTool11 = "DesignerTool";
///
/// 表单树类别
///
public const string FK_FormTree = "FK_FormTree";
///
/// 表单类型
///
public const string FrmType = "FrmType";
///
/// 业务类型
///
public const string EntityType = "EntityType";
///
/// 表单展示方式
///
public const string FrmShowType = "FrmShowType";
///
/// 单据模板
///
public const string FrmModel = "FrmModel";
///
/// Url(对于嵌入式表单有效)
///
public const string UrlExt = "UrlExt";
///
/// Tag
///
public const string Tag = "Tag";
///
/// 备注
///
public const string Note = "Note";
///
/// Idx
///
public const string Idx = "Idx";
///
/// GUID
///
public const string GUID = "GUID";
///
/// 版本号
///
public const string Ver = "Ver";
///
/// 应用类型
///
public const string AppType = "AppType";
///
/// 表单body属性.
///
public const string BodyAttr = "BodyAttr";
///
/// 流程控件
///
public const string FlowCtrls = "FlowCtrls";
///
///组织结构.
///
public const string OrgNo = "OrgNo";
///
/// Icon.
///
public const string Icon = "Icon";
#region DBList类型的实体.
///
/// 数据源
///
public const string DBSrc = "DBSrc";
///
/// 数据源类型
///
public const string DBType = "DBType";
///
/// 单行
///
public const string ExpEn = "ExpEn";
///
/// 列表
///
public const string ExpList = "ExpList";
///
/// 表达式
///
public const string ExpCount = "ExpCount";
///
/// 分页的模式
///
public const string ExpListPageModel = "ExpListPageModel";
#endregion DBList类型的实体.
#region 报表属性(参数的方式存储).
///
/// 是否关键字查询
///
public const string IsSearchKey = "IsSearchKey";
///
/// 时间段查询方式
///
public const string DTSearchWay = "DTSearchWay";
///
/// 时间字段
///
public const string DTSearchKey = "DTSearchKey";
///
/// 查询外键枚举字段
///
public const string RptSearchKeys = "RptSearchKeys";
#endregion 报表属性(参数的方式存储).
#region 其他计算属性,参数存储.
///
/// 最左边的值
///
public const string MaxLeft = "MaxLeft";
///
/// 最右边的值
///
public const string MaxRight = "MaxRight";
///
/// 最头部的值
///
public const string MaxTop = "MaxTop";
///
/// 最底部的值
///
public const string MaxEnd = "MaxEnd";
#endregion 其他计算属性,参数存储.
#region 参数属性.
public const string EnsName = "EnsName";
///
/// 是否是加密
///
public const string IsJM = "IsJM";
#endregion 参数属性.
}
///
/// 映射基础
///
public class MapData : EntityNoName
{
#region entity 相关属性(参数属性)
///
/// 属性ens
///
public string EnsName
{
get
{
return this.GetValStringByKey(MapDataAttr.EnsName);
}
set
{
this.SetPara(MapDataAttr.EnsName, value);
}
}
///
/// 是不是加密,为铁路局增加.
///
public bool IsJM
{
get
{
return this.GetParaBoolen(MapDataAttr.IsJM);
}
set
{
this.SetPara(MapDataAttr.IsJM, value);
}
}
#endregion entity 相关操作.
#region 报表属性(参数方式存储).
///
/// 是否关键字查询
///
public bool IsSearchKey
{
get
{
return this.GetParaBoolen(MapDataAttr.IsSearchKey, true);
}
set
{
this.SetPara(MapDataAttr.IsSearchKey, value);
}
}
///
/// 时间段查询方式
///
public DTSearchWay DTSearchWay
{
get
{
return (DTSearchWay)this.GetParaInt(MapDataAttr.DTSearchWay);
}
set
{
this.SetPara(MapDataAttr.DTSearchWay, (int)value);
}
}
///
/// 查询外键枚举字段
///
public string RptSearchKeys
{
get
{
return this.GetParaString(MapDataAttr.RptSearchKeys, "*");
}
set
{
this.SetPara(MapDataAttr.RptSearchKeys, value);
}
}
///
/// 查询key.
///
public string DTSearchKey
{
get
{
return this.GetParaString(MapDataAttr.DTSearchKey);
}
set
{
this.SetPara(MapDataAttr.DTSearchKey, value);
}
}
#endregion 报表属性(参数方式存储).
#region 外键属性
///
/// 版本号
///
public int Ver2022
{
get
{
return this.GetParaInt(MapDataAttr.Ver, 1);
}
set
{
this.SetPara(MapDataAttr.Ver, value);
}
}
public string OrgNo
{
get
{
return this.GetValStringByKey(MapDataAttr.OrgNo);
}
set
{
this.SetValByKey(MapDataAttr.OrgNo, value);
}
}
///
/// 顺序号
///
public int Idx
{
get
{
return this.GetValIntByKey(MapDataAttr.Idx);
}
set
{
this.SetValByKey(MapDataAttr.Idx, value);
}
}
///
/// 框架
///
public MapFrames MapFrames
{
get
{
var ens = this.GetEntitiesAttrFromAutoNumCash(new MapFrames(),
MapExtAttr.FK_MapData, this.No);
return ens as MapFrames;
}
}
///
/// 分组字段
///
public GroupFields GroupFields
{
get
{
GroupFields obj = this.GetRefObject("GroupFields") as GroupFields;
if (obj == null)
{
obj = new GroupFields(this.No);
this.SetRefObject("GroupFields", obj);
}
return obj;
}
}
///
/// 逻辑扩展
///
public MapExts MapExts
{
get
{
var ens = this.GetEntitiesAttrFromAutoNumCash(new MapExts(),
MapExtAttr.FK_MapData, this.No);
return ens as MapExts;
//MapExts obj = this.GetRefObject("MapExts") as MapExts;
//if (obj == null)
//{
// obj = new MapExts(this.No);
// this.SetRefObject("MapExts", obj);
//}
//return obj;
}
}
///
/// 事件:
/// 1.该事件与Node,Flow,MapDtl,MapData一样的算法.
/// 2.如果一个业务逻辑有变化,其他的也要变化.
///
public FrmEvents FrmEvents
{
get
{
var ens = this.GetEntitiesAttrFromAutoNumCash(new FrmEvents(),
FrmEventAttr.FK_MapData, this.No);
return ens as FrmEvents;
}
}
///
/// 从表原始属性的获取
///
public MapDtls OrigMapDtls
{
get
{
var ens = this.GetEntitiesAttrFromAutoNumCash(new MapDtls(),
MapDtlAttr.FK_MapData, this.No, MapDtlAttr.FK_Node, 0);
return ens as MapDtls;
}
}
///
/// 查询给MapData下的所有从表数据
///
public MapDtls MapDtls
{
get
{
var ens = this.GetEntitiesAttrFromAutoNumCash(new MapDtls(),
MapDtlAttr.FK_MapData, this.No);
return ens as MapDtls;
//MapDtls obj = this.GetRefObject("MapDtls") as MapDtls;
//if (obj == null)
//{
// obj = new MapDtls(this.No);
// this.SetRefObject("MapDtls", obj);
//}
//return obj;
}
}
///
/// 枚举值
///
public SysEnums SysEnums
{
get
{
SysEnums obj = this.GetRefObject("SysEnums") as SysEnums;
obj = null;
if (obj == null)
{
obj = new SysEnums();
if (BP.Difference.SystemConfig.AppCenterDBType == DBType.MySQL)
{
string strs = "";
Paras ps = new Paras();
ps.SQL = "SELECT UIBindKey FROM Sys_MapAttr WHERE FK_MapData=" + ps.DBStr + "FK_MapData AND LGType=1";
ps.Add("FK_MapData", this.No);
DataTable dt = DBAccess.RunSQLReturnTable(ps);
foreach (DataRow dr in dt.Rows)
{
strs += "'" + dr[0].ToString() + "',";
}
if (dt.Rows.Count >= 1)
{
strs += "'ssss'";
obj.RetrieveInOrderBy("EnumKey", strs, SysEnumAttr.IntKey);
}
}
else
{
if (BP.Difference.SystemConfig.CCBPMRunModel == CCBPMRunModel.SAAS)
{
string enumKeySQL = "SELECT UIBindKey FROM Sys_MapAttr WHERE FK_MapData = '" + this.No + "' AND LGType = 1 ";
string sqlWhere = " EnumKey IN (" + enumKeySQL + ") AND OrgNo='" + BP.Web.WebUser.OrgNo + "'";
string sqlEnum = "SELECT * FROM " + BP.Sys.Base.Glo.SysEnum() + " WHERE " + sqlWhere;
sqlEnum += " UNION ";
sqlEnum += "SELECT * FROM " + BP.Sys.Base.Glo.SysEnum() + " WHERE EnumKey IN (" + enumKeySQL + ") AND EnumKey NOT IN (SELECT EnumKey FROM Sys_Enum WHERE " + sqlWhere + ") AND (OrgNo Is Null Or OrgNo='')";
sqlEnum += "Order By IntKey";
DataTable dt = DBAccess.RunSQLReturnTable(sqlEnum);
QueryObject.InitEntitiesByDataTable(obj, dt, null);
}
else
{
obj.RetrieveInSQL(SysEnumAttr.EnumKey, "SELECT UIBindKey FROM Sys_MapAttr WHERE FK_MapData='" + this.No + "' AND LGType=1 ", SysEnumAttr.IntKey);
}
}
this.SetRefObject("SysEnums", obj);
}
return obj;
}
}
///
/// 图片
///
public FrmImgs FrmImgs
{
get
{
var ens = this.GetEntitiesAttrFromAutoNumCash(new FrmImgs(),
FrmImgAttr.FK_MapData, this.No);
return ens as FrmImgs;
}
}
///
/// 附件
///
public FrmAttachments FrmAttachments
{
get
{
var ens = this.GetEntitiesAttrFromAutoNumCash(new FrmAttachments(),
FrmAttachmentAttr.FK_MapData, this.No);
return ens as FrmAttachments;
}
}
///
/// 附件模板列表
///
// public SysFileManagers sysFileManagers
// {
// get
// {
// var ens = this.GetEntitiesAttrFromAutoNumCash(new SysFileManagers(),
//SysFileManagerAttr.FK_MapData, this.No);
// return ens as SysFileManagers;
// }
// }
///
/// 图片附件
///
public FrmImgAths FrmImgAths
{
get
{
var ens = this.GetEntitiesAttrFromAutoNumCash(new FrmImgAths(),
FrmImgAthAttr.FK_MapData, this.No);
return ens as FrmImgAths;
}
}
///
/// 单选按钮
///
public FrmRBs FrmRBs
{
get
{
var ens = this.GetEntitiesAttrFromAutoNumCash(new FrmRBs(),
FrmRBAttr.FK_MapData, this.No);
return ens as FrmRBs;
}
}
///
/// 属性
///
public MapAttrs MapAttrs
{
get
{
MapAttrs obj = this.GetRefObject("MapAttrs") as MapAttrs;
if (obj == null)
{
obj = new MapAttrs(this.No);
this.SetRefObject("MapAttrs", obj);
}
return obj;
}
}
#endregion
#region 缓存方法.
public void CleanObject()
{
this.Row.SetValByKey("FrmEles", null);
this.Row.SetValByKey("MapFrames", null);
this.Row.SetValByKey("GroupFields", null);
this.Row.SetValByKey("MapExts", null);
this.Row.SetValByKey("FrmEvents", null);
this.Row.SetValByKey("MapDtls", null);
this.Row.SetValByKey("SysEnums", null);
this.Row.SetValByKey("FrmRpts", null);
this.Row.SetValByKey("FrmLinks", null);
this.Row.SetValByKey("FrmBtns", null);
this.Row.SetValByKey("FrmEles", null);
// this.Row.SetValByKey("FrmLines", null);
// this.Row.SetValByKey("FrmLabs", null);
this.Row.SetValByKey("FrmAttachments", null);
this.Row.SetValByKey("FrmImgAthDBs", null);
this.Row.SetValByKey("FrmRBs", null);
this.Row.SetValByKey("MapAttrs", null);
return;
}
///
/// 清空缓存
///
public void ClearCash()
{
CashFrmTemplate.Remove(this.No);
Cash.SetMap(this.No, null);
CleanObject();
Cash.SQL_Cash.Remove(this.No);
}
#endregion 缓存方法.
#region 基本属性.
///
/// 事件实体
///
public string FormEventEntity
{
get
{
return this.GetValStringByKey(MapDataAttr.FormEventEntity);
}
set
{
this.SetValByKey(MapDataAttr.FormEventEntity, value);
}
}
public static Boolean IsEditDtlModel
{
get
{
string s = BP.Web.WebUser.GetSessionByKey("IsEditDtlModel", "0");
if (s == "0")
return false;
else
return true;
}
set
{
BP.Web.WebUser.SetSessionByKey("IsEditDtlModel", "1");
}
}
public string ICON
{
get
{
return this.GetValStringByKey(MapDataAttr.Icon);
}
}
#endregion 基本属性.
#region 属性
///
/// 物理表
///
public string PTable
{
get
{
string s = this.GetValStrByKey(MapDataAttr.PTable);
if (DataType.IsNullOrEmpty(s) == true)
return this.No;
return s.Trim();
}
set
{
this.SetValByKey(MapDataAttr.PTable, value);
}
}
///
/// 表存储模式0=自定义表,1,指定的表,2=指定的表不能修改表结构.
/// @周朋
///
public int PTableModel
{
get
{
return this.GetValIntByKey(MapDataAttr.PTableModel);
}
set
{
this.SetValByKey(MapDataAttr.PTableModel, value);
}
}
///
/// URL
///
public string UrlExt
{
get
{
return this.GetValStrByKey(MapDataAttr.UrlExt);
}
set
{
this.SetValByKey(MapDataAttr.UrlExt, value);
}
}
public DBUrlType HisDBUrl
{
get
{
return DBUrlType.AppCenterDSN;
// return (DBUrlType)this.GetValIntByKey(MapDataAttr.DBURL);
}
}
public int HisFrmTypeInt
{
get
{
return this.GetValIntByKey(MapDataAttr.FrmType);
}
set
{
this.SetValByKey(MapDataAttr.FrmType, value);
}
}
public FrmType HisFrmType
{
get
{
return (FrmType)this.GetValIntByKey(MapDataAttr.FrmType);
}
set
{
this.SetValByKey(MapDataAttr.FrmType, (int)value);
}
}
public int HisEntityType
{
get
{
return this.GetValIntByKey(MapDataAttr.EntityType);
}
set
{
this.SetValByKey(MapDataAttr.EntityType, value);
}
}
///
/// 表单类型名称
///
public string HisFrmTypeText
{
get
{
return this.HisFrmType.ToString();
// SysEnum se = new SysEnum("FrmType", this.HisFrmTypeInt);
// return se.Lab;
}
}
///
/// 备注
///
public string Note
{
get
{
return this.GetValStrByKey(MapDataAttr.Note);
}
set
{
this.SetValByKey(MapDataAttr.Note, value);
}
}
///
/// 是否有CA.
///
public bool IsHaveCA
{
get
{
return this.GetParaBoolen("IsHaveCA", false);
}
set
{
this.SetPara("IsHaveCA", value);
}
}
///
///是否启用装载填充
///
public bool IsPageLoadFull
{
get
{
return this.GetParaBoolen("IsPageLoadFull", false);
}
set
{
this.SetPara("IsPageLoadFull", value);
}
}
///
/// 数据源
///
public string DBSrc
{
get
{
return this.GetValStrByKey(MapDataAttr.DBSrc);
}
set
{
this.SetValByKey(MapDataAttr.DBSrc, value);
}
}
///
/// 类别,可以为空.
///
public string FK_FormTree
{
get
{
return this.GetValStrByKey(MapDataAttr.FK_FormTree);
}
set
{
this.SetValByKey(MapDataAttr.FK_FormTree, value);
}
}
///
/// 类别名称
///
public string FK_FormTreeText
{
get
{
return DBAccess.RunSQLReturnStringIsNull("SELECT Name FROM Sys_FormTree WHERE No='" + this.FK_FormTree + "'", "目录错误");
}
}
///
/// 从表集合.
///
public string Dtls
{
get
{
return this.GetValStrByKey(MapDataAttr.Dtls);
}
set
{
this.SetValByKey(MapDataAttr.Dtls, value);
}
}
///
/// 主键
///
public string EnPK
{
get
{
string s = this.GetValStrByKey(MapDataAttr.EnPK);
if (DataType.IsNullOrEmpty(s))
return "OID";
return s;
}
set
{
this.SetValByKey(MapDataAttr.EnPK, value);
}
}
private Entities _HisEns = null;
public new Entities HisEns
{
get
{
if (_HisEns == null)
{
_HisEns = BP.En.ClassFactory.GetEns(this.No);
}
return _HisEns;
}
}
public Entity HisEn
{
get
{
return this.HisEns.GetNewEntity;
}
}
public float FrmW
{
get
{
return this.GetValFloatByKey(MapDataAttr.FrmW);
}
set
{
this.SetValByKey(MapDataAttr.FrmW, value);
}
}
///
/// 应用类型. 0独立表单.1节点表单
///
public string AppType
{
get
{
return this.GetValStrByKey(MapDataAttr.AppType);
}
set
{
this.SetValByKey(MapDataAttr.AppType, value);
}
}
///
/// 表单body属性.
///
public string BodyAttr
{
get
{
string str = this.GetValStrByKey(MapDataAttr.BodyAttr);
str = str.Replace("~", "'");
return str;
}
set
{
this.SetValByKey(MapDataAttr.BodyAttr, value);
}
}
///
/// 流程控件s.
///
public string FlowCtrls
{
get
{
return this.GetValStrByKey(MapDataAttr.FlowCtrls);
}
set
{
this.SetValByKey(MapDataAttr.FlowCtrls, value);
}
}
public int TableCol
{
get
{
return this.GetValIntByKey(MapDataAttr.TableCol);
}
set
{
this.SetValByKey(MapDataAttr.TableCol, value);
}
}
///
/// 实体表单类型.@0=独立表单@1=单据@2=编号名称实体@3=树结构实体
///
public EntityType EntityType
{
get
{
return (EntityType)this.GetValIntByKey(MapDataAttr.EntityType);
}
set
{
this.SetValByKey(MapDataAttr.EntityType, (int)value);
}
}
#endregion
#region 构造方法
public Map GenerHisMap()
{
MapAttrs mapAttrs = this.MapAttrs;
if (mapAttrs.Count == 0)
{
this.RepairMap();
mapAttrs = this.MapAttrs;
}
Map map = new Map(this.PTable, this.Name);
Attrs attrs = new Attrs();
foreach (MapAttr mapAttr in mapAttrs)
map.AddAttr(mapAttr.HisAttr);
// 产生从表。
MapDtls dtls = this.MapDtls; // new MapDtls(this.No);
foreach (MapDtl dtl in dtls)
{
GEDtls dtls1 = new GEDtls(dtl.No);
map.AddDtl(dtls1, "RefPK");
}
#region 查询条件.
map.IsShowSearchKey = this.IsSearchKey; //是否启用关键字查询.
// 按日期查询.
map.DTSearchWay = this.DTSearchWay; //日期查询方式.
map.DTSearchKey = this.DTSearchKey; //日期字段.
//是否是加密
map.IsJM = this.IsJM;
//加入外键查询字段.
string[] keys = this.RptSearchKeys.Split('*');
foreach (string key in keys)
{
if (DataType.IsNullOrEmpty(key))
continue;
if (map.Attrs.Contains(key) == false)
continue;
map.AddSearchAttr(key);
}
#endregion 查询条件.
return map;
}
private GEEntity _HisEn = null;
public GEEntity HisGEEn
{
get
{
if (this._HisEn == null)
_HisEn = new GEEntity(this.No);
return _HisEn;
}
}
///
/// 生成实体
///
///
///
public GEEntity GenerGEEntityByDataSet(DataSet ds)
{
// New 它的实例.
GEEntity en = this.HisGEEn;
// 它的table.
DataTable dt = ds.Tables[this.No];
//装载数据.
en.Row.LoadDataTable(dt, dt.Rows[0]);
// dtls.
MapDtls dtls = this.MapDtls;
foreach (MapDtl item in dtls)
{
DataTable dtDtls = ds.Tables[item.No];
GEDtls dtlsEn = new GEDtls(item.No);
foreach (DataRow dr in dtDtls.Rows)
{
// 产生它的Entity data.
GEDtl dtl = (GEDtl)dtlsEn.GetNewEntity;
dtl.Row.LoadDataTable(dtDtls, dr);
//加入这个集合.
dtlsEn.AddEntity(dtl);
}
//加入到他的集合里.
en.Dtls.Add(dtDtls);
}
return en;
}
///
/// 生成map.
///
///
///
public static Map GenerHisMap(string no)
{
if (BP.Difference.SystemConfig.IsDebug)
{
MapData md = new MapData();
md.No = no;
md.Retrieve();
return md.GenerHisMap();
}
else
{
Map map = Cash.GetMap(no);
if (map == null)
{
MapData md = new MapData();
md.No = no;
md.Retrieve();
map = md.GenerHisMap();
Cash.SetMap(no, map);
}
return map;
}
}
///
/// 映射基础
///
public MapData()
{
}
///
/// 映射基础
///
/// 映射编号
public MapData(string no)
{
this.No = no;
this.Retrieve();
}
///
/// EnMap
///
public override Map EnMap
{
get
{
if (this._enMap != null)
return this._enMap;
Map map = new Map("Sys_MapData", "表单注册表");
#region 基础信息.
map.AddTBStringPK(MapDataAttr.No, null, "编号", true, false, 1, 200, 100);
map.AddTBString(MapDataAttr.Name, null, "描述", true, false, 0, 500, 20);
map.AddTBString(MapDataAttr.FormEventEntity, null, "事件实体", true, true, 0, 100, 20, true);
map.AddTBString(MapDataAttr.EnPK, null, "实体主键", true, false, 0, 200, 20);
map.AddTBString(MapDataAttr.PTable, null, "物理表", true, false, 0, 500, 20);
//@周朋 表存储格式0=自定义表,1=指定表,可以修改字段2=执行表不可以修改字段.
map.AddTBInt(MapDataAttr.PTableModel, 0, "表存储模式", true, true);
map.AddTBString(MapDataAttr.UrlExt, null, "连接(对嵌入式表单有效)", true, false, 0, 500, 20);
map.AddTBString(MapDataAttr.Dtls, null, "从表", true, false, 0, 500, 20);
//格式为: @1=方案名称1@2=方案名称2@3=方案名称3
//map.AddTBString(MapDataAttr.Slns, null, "表单控制解决方案", true, false, 0, 500, 20);
map.AddTBInt(MapDataAttr.FrmW, 900, "FrmW", true, true);
// @0=4列, @1=6 列.
map.AddTBInt(MapDataAttr.TableCol, 0, "傻瓜表单显示的列", true, true);
//Tag
map.AddTBString(MapDataAttr.Tag, null, "Tag", true, false, 0, 500, 20);
// 可以为空这个字段。
//map.AddTBString(MapDataAttr.FK_FrmSort, null, "表单类别", true, false, 0, 500, 20);
map.AddTBString(MapDataAttr.FK_FormTree, null, "表单树类别", true, false, 0, 500, 20);
// enumFrmType @自由表单,@傻瓜表单,@嵌入式表单.
map.AddDDLSysEnum(MapDataAttr.FrmType, (int)BP.Sys.FrmType.FoolForm, "表单类型", true, false, MapDataAttr.FrmType);
map.AddTBInt(MapDataAttr.FrmShowType, 0, "表单展示方式", true, true);
map.AddDDLSysEnum(MapDataAttr.EntityType, 0, "业务类型", true, false, MapDataAttr.EntityType,
"@0=独立表单@1=单据@2=编号名称实体@3=树结构实体");
map.SetHelperAlert(MapDataAttr.EntityType, "该实体的类型,@0=单据@1=编号名称实体@2=树结构实体.");
map.AddBoolean("IsEnableJs", false, "是否启用自定义js函数?", true, true, true);
// 应用类型. 0独立表单.1节点表单
map.AddTBInt(MapDataAttr.AppType, 0, "应用类型", true, false);
map.AddTBString(MapDataAttr.DBSrc, "local", "数据源", true, false, 0, 100, 20);
map.AddTBString(MapDataAttr.BodyAttr, null, "表单Body属性", true, false, 0, 100, 20);
#endregion 基础信息.
#region 设计者信息.
map.AddTBString(MapDataAttr.Note, null, "备注", true, false, 0, 500, 20);
map.AddTBString(MapDataAttr.Designer, null, "设计者", true, false, 0, 500, 20);
map.AddTBString(MapDataAttr.DesignerUnit, null, "单位", true, false, 0, 500, 20);
map.AddTBString(MapDataAttr.DesignerContact, null, "联系方式", true, false, 0, 500, 20);
map.AddTBInt(MapDataAttr.Idx, 100, "顺序号", true, true);
map.AddTBString(MapDataAttr.GUID, null, "GUID", true, false, 0, 128, 20);
map.AddTBString(MapDataAttr.Ver, null, "版本号", true, false, 0, 30, 20);
map.AddTBString(MapDataAttr.Icon, null, "Icon", true, false, 0, 500, 20, true);
//流程控件.
map.AddTBString(MapDataAttr.FlowCtrls, null, "流程控件", true, true, 0, 200, 20);
//增加参数字段.
map.AddTBAtParas(4000);
#endregion
map.AddTBString(MapDataAttr.OrgNo, null, "OrgNo", true, false, 0, 50, 20);
this._enMap = map;
return this._enMap;
}
}
///
/// 执行复制.
///
///
///
///
///
public string DoCopy(string copyToFrmID, string frmName)
{
BP.Sys.CCFormAPI.CopyFrm(this.No, copyToFrmID, frmName, this.FK_FormTree);
return "执行成功";
}
///
/// 上移
///
public void DoUp()
{
this.DoOrderUp(MapDataAttr.FK_FormTree, this.FK_FormTree, MapDataAttr.Idx);
}
///
/// 下移
///
public void DoOrderDown()
{
this.DoOrderDown(MapDataAttr.FK_FormTree, this.FK_FormTree, MapDataAttr.Idx);
}
//检查表单
public void CheckPTableSaveModel(string filed)
{
if (this.PTableModel == 2)
{
/*如果是存储格式*/
if (DBAccess.IsExitsTableCol(this.PTable, filed) == false)
throw new Exception("@表单的表存储模式不允许您创建不存在的字段(" + filed + "),不允许修改表结构.");
}
}
///
/// 获得PTableModel=2模式下的表单,没有被使用的字段集合.
///
///
///
public static DataTable GetFieldsOfPTableMode2(string frmID)
{
string pTable = "";
MapDtl dtl = new MapDtl();
dtl.No = frmID;
if (dtl.RetrieveFromDBSources() == 1)
{
pTable = dtl.PTable;
}
else
{
MapData md = new MapData();
md.No = frmID;
md.RetrieveFromDBSources();
pTable = md.PTable;
}
//获得原始数据.
DataTable dt = DBAccess.GetTableSchema(pTable, false);
//创建样本表结构.
DataTable mydt = DBAccess.GetTableSchema(pTable, false);
mydt.Rows.Clear();
//获得现有的列..
MapAttrs attrs = new MapAttrs(frmID);
string flowFiels = ",GUID,PRI,PrjNo,PrjName,PEmp,AtPara,FlowNote,WFSta,PNodeID,FK_FlowSort,FK_Flow,OID,FID,Title,WFState,CDT,FlowStarter,FlowStartRDT,FK_Dept,FK_NY,FlowDaySpan,FlowEmps,FlowEnder,FlowEnderRDT,FlowEndNode,MyNum,PWorkID,PFlowNo,BillNo,ProjNo,";
//排除已经存在的列. 把所有的列都输出给前台,让前台根据类型分拣.
foreach (DataRow dr in dt.Rows)
{
string key = dr["FName"].ToString();
if (attrs.Contains(MapAttrAttr.KeyOfEn, key) == true)
continue;
if (flowFiels.Contains("," + key + ",") == true)
continue;
DataRow mydr = mydt.NewRow();
mydr["FName"] = dr["FName"];
mydr["FType"] = dr["FType"];
mydr["FLen"] = dr["FLen"];
mydr["FDesc"] = dr["FDesc"];
mydt.Rows.Add(mydr);
}
return mydt;
}
#endregion
#region 常用方法.
private FormEventBase _HisFEB = null;
public FormEventBase HisFEB
{
get
{
if (this.FormEventEntity == "")
return null;
if (_HisFEB == null)
_HisFEB = BP.Sys.Base.Glo.GetFormEventBaseByEnName(this.No);
return _HisFEB;
}
}
///
/// 升级逻辑.
///
public void Upgrade()
{
string sql = "";
#region 升级ccform控件.
//if (DBAccess.IsExitsObject("Sys_FrmLine") == true)
//{
// //重命名.
// BP.Sys.SFDBSrc dbsrc = new SFDBSrc("local");
// dbsrc.Rename("Table", "Sys_FrmLine", "Sys_FrmLineBak");
//}
if (DBAccess.IsExitsObject("Sys_FrmLab") == true)
{
//重命名.
BP.Sys.SFDBSrc dbsrc = new SFDBSrc("local");
dbsrc.Rename("Table", "Sys_FrmLab", "Sys_FrmLabBak");
}
if (DBAccess.IsExitsObject("Sys_FrmBtn") == true)
{
//重命名.
BP.Sys.SFDBSrc dbsrc = new SFDBSrc("local");
dbsrc.Rename("Table", "Sys_FrmLab", "Sys_FrmLabBak");
}
#endregion 升级ccform控件.
}
///
/// 导入数据
///
///
///
///
public static MapData ImpMapData(DataSet ds)
{
string errMsg = "";
if (ds.Tables.Contains("WF_Flow") == true)
errMsg += "@此模板文件为流程模板。";
if (ds.Tables.Contains("Sys_MapAttr") == false)
errMsg += "@缺少表:Sys_MapAttr";
if (ds.Tables.Contains("Sys_MapData") == false)
errMsg += "@缺少表:Sys_MapData";
if (errMsg != "")
throw new Exception(errMsg);
DataTable dt = ds.Tables["Sys_MapData"];
string fk_mapData = dt.Rows[0]["No"].ToString();
MapData md = new MapData();
md.No = fk_mapData;
if (md.IsExits)
throw new Exception("err@已经存在(" + fk_mapData + ")的表单ID,所以您不能导入。");
//执行删除操作.
md.Delete();
//导入.
return ImpMapData(fk_mapData, ds);
}
///
/// 设置表单为只读属性
///
/// 表单ID
public static void SetFrmIsReadonly(string fk_mapdata)
{
//把主表字段设置为只读.
MapAttrs attrs = new MapAttrs(fk_mapdata);
foreach (MapAttr attr in attrs)
{
if (attr.DefValReal.Contains("@"))
{
attr.SetValByKey(MapAttrAttr.UIIsEnable, false);
attr.setDefValReal(""); //清空默认值.
attr.SetValByKey("ExtDefVal", ""); //设置默认值.
attr.Update();
continue;
}
if (attr.UIIsEnable == true)
{
attr.SetValByKey(MapAttrAttr.UIIsEnable, false);
attr.Update();
continue;
}
}
//把从表字段设置为只读.
MapDtls dtls = new MapDtls(fk_mapdata);
foreach (MapDtl dtl in dtls)
{
dtl.IsInsert = false;
dtl.IsUpdate = false;
dtl.IsDelete = false;
dtl.Update();
attrs = new MapAttrs(dtl.No);
foreach (MapAttr attr in attrs)
{
if (attr.DefValReal.Contains("@"))
{
attr.SetValByKey(MapAttrAttr.UIIsEnable, false);
attr.setDefValReal(""); //清空默认值.
attr.SetValByKey("ExtDefVal", ""); //设置默认值.
attr.Update();
}
if (attr.UIIsEnable == true)
{
attr.SetValByKey(MapAttrAttr.UIIsEnable, false);
attr.Update();
continue;
}
}
}
//把附件设置为只读.
FrmAttachments aths = new FrmAttachments(fk_mapdata);
foreach (FrmAttachment item in aths)
{
item.IsUpload = false;
item.HisDeleteWay = AthDeleteWay.DelSelf;
//如果是从开始节点表单导入的,就默认为, 按照主键PK的方式显示.
if (fk_mapdata.IndexOf("ND") == 0)
{
item.DataRefNoOfObj = "AttachM1";
}
item.Update();
}
}
///
/// 导入表单
///
/// 指定的表单ID
/// 表单数据
/// 是否设置只读?
///
public static MapData ImpMapData(string specFrmID, DataSet ds)
{
if (DataType.IsNullOrEmpty(specFrmID) == true)
ImpMapData(ds);
#region 检查导入的数据是否完整.
string errMsg = "";
//if (ds.Tables[0].TableName != "Sys_MapData")
// errMsg += "@非表单模板。";
if (ds.Tables.Contains("WF_Flow") == true)
errMsg += "@此模板文件为流程模板。";
if (ds.Tables.Contains("Sys_MapAttr") == false)
errMsg += "@缺少表:Sys_MapAttr";
if (ds.Tables.Contains("Sys_MapData") == false)
errMsg += "@缺少表:Sys_MapData";
DataTable dtCheck = ds.Tables["Sys_MapAttr"];
bool isHave = false;
foreach (DataRow dr in dtCheck.Rows)
{
if (dr["KeyOfEn"].ToString() == "OID")
{
isHave = true;
break;
}
}
if (isHave == false)
errMsg += "@表单模版缺少列:OID";
if (errMsg != "")
throw new Exception("@以下错误不可导入,可能的原因是非表单模板文件:" + errMsg);
#endregion
// 定义在最后执行的sql.
string endDoSQL = "";
MapData mdOld = new MapData();
mdOld.No = specFrmID;
int count = mdOld.RetrieveFromDBSources();
if (count == 1)
mdOld.Delete();
// 求出dataset的map.
string oldMapID = "";
DataTable dtMap = ds.Tables["Sys_MapData"];
if (dtMap.Rows.Count == 1)
{
oldMapID = dtMap.Rows[0]["No"].ToString();
}
else
{
// 求旧的表单ID.
foreach (DataRow dr in dtMap.Rows)
oldMapID = dr["No"].ToString();
if (DataType.IsNullOrEmpty(oldMapID) == true)
oldMapID = dtMap.Rows[0]["No"].ToString();
}
//现在表单的类型
FrmType frmType = mdOld.HisFrmType;
//业务类型
int entityType = mdOld.HisEntityType;
//mdOld.Delete();
string timeKey = DateTime.Now.ToString("MMddHHmmss");
#region 表单元素
foreach (DataTable dt in ds.Tables)
{
int idx = 0;
switch (dt.TableName)
{
case "Sys_MapDtl":
foreach (DataRow dr in dt.Rows)
{
MapDtl dtl = new MapDtl();
foreach (DataColumn dc in dt.Columns)
{
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
//编号列.
string colName = dc.ColumnName.ToLower();
if (colName.Equals("no") || colName.Equals("name") || colName.Equals("fk_mapdata"))
dtl.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
else
dtl.SetValByKey(dc.ColumnName, val.ToString());
}
dtl.Insert();
}
break;
case "Sys_MapData":
foreach (DataRow dr in dt.Rows)
{
MapData md = new MapData();
string htmlCode = "";
foreach (DataColumn dc in dt.Columns)
{
if (dc.ColumnName.Equals("HtmlTemplateFile") == true)
{
htmlCode = dr[dc.ColumnName] as string;
continue;
}
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
string colName = dc.ColumnName.ToLower();
if (colName.Equals("no") == true || colName.Equals("name") == true)
md.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
else
md.SetValByKey(dc.ColumnName, val.ToString());
}
//表单类别编号不为空,则用原表单类别编号
md.FK_FormTree = mdOld.FK_FormTree;
if (DataType.IsNullOrEmpty(mdOld.PTable) == false)
md.PTable = mdOld.PTable;
//如果物理表为空,则使用编号为物理数据表
if (DataType.IsNullOrEmpty(md.PTable.Trim()) == true)
md.PTable = md.No;
if (DataType.IsNullOrEmpty(mdOld.Name) == false)
md.Name = mdOld.Name;
if (count == 1)
md.HisFrmType = mdOld.HisFrmType;
else
frmType = md.HisFrmType;
if (entityType != md.HisEntityType)
md.HisEntityType = entityType;
//表单应用类型保持不变
md.AppType = mdOld.AppType;
if (md.DirectUpdate() == 0)
md.DirectInsert();
Cash2019.UpdateRow(md.ToString(), md.No.ToString(), md.Row);
//如果是开发者表单,赋值HtmlTemplateFile数据库的值并保存到DataUser下
if (frmType == FrmType.Develop)
{
// string htmlCode = DBAccess.GetBigTextFromDB("Sys_MapData", "No", oldMapID, "HtmlTemplateFile");
if (DataType.IsNullOrEmpty(htmlCode) == false)
{
htmlCode = htmlCode.Replace(oldMapID, specFrmID);
//保存到数据库,存储html文件
//保存到DataUser/CCForm/HtmlTemplateFile/文件夹下
string filePath = BP.Difference.SystemConfig.PathOfDataUser + "CCForm/HtmlTemplateFile/";
if (Directory.Exists(filePath) == false)
Directory.CreateDirectory(filePath);
filePath = filePath + md.No + ".htm";
//写入到html 中
DataType.WriteFile(filePath, htmlCode);
// HtmlTemplateFile 保存到数据库中
DBAccess.SaveBigTextToDB(htmlCode, "Sys_MapData", "No", md.No, "HtmlTemplateFile");
}
else
{
//如果htmlCode是空的需要删除当前节点的html文件
string filePath = BP.Difference.SystemConfig.PathOfDataUser + "CCForm/HtmlTemplateFile/" + md.No + ".htm";
if (File.Exists(filePath) == true)
File.Delete(filePath);
DBAccess.SaveBigTextToDB("", "Sys_MapData", "No", md.No, "HtmlTemplateFile");
}
}
}
break;
case "Sys_FrmBtn":
foreach (DataRow dr in dt.Rows)
{
idx++;
FrmBtn en = new FrmBtn();
foreach (DataColumn dc in dt.Columns)
{
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
en.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
}
//en.setMyPK("Btn_" + idx + "_" + fk_mapdata;
en.setMyPK(DBAccess.GenerGUID());
en.Insert();
}
break;
case "Sys_FrmImg":
foreach (DataRow dr in dt.Rows)
{
idx++;
FrmImg en = new FrmImg();
foreach (DataColumn dc in dt.Columns)
{
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
en.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
}
if (DataType.IsNullOrEmpty(en.KeyOfEn) == true)
en.setMyPK(DBAccess.GenerGUID());
en.Insert();
}
break;
case "Sys_FrmImgAth":
foreach (DataRow dr in dt.Rows)
{
idx++;
FrmImgAth en = new FrmImgAth();
foreach (DataColumn dc in dt.Columns)
{
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
en.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
}
if (DataType.IsNullOrEmpty(en.CtrlID))
en.CtrlID = "ath" + idx;
en.Insert();
}
break;
case "Sys_FrmRB":
foreach (DataRow dr in dt.Rows)
{
idx++;
FrmRB en = new FrmRB();
foreach (DataColumn dc in dt.Columns)
{
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
en.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
}
try
{
en.Save();
}
catch
{
}
}
break;
case "Sys_FrmAttachment":
foreach (DataRow dr in dt.Rows)
{
idx++;
FrmAttachment en = new FrmAttachment();
foreach (DataColumn dc in dt.Columns)
{
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
en.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
}
en.setMyPK(specFrmID + "_" + en.GetValByKey("NoOfObj"));
try
{
en.Insert();
}
catch
{
}
}
break;
case "Sys_MapFrame":
foreach (DataRow dr in dt.Rows)
{
idx++;
MapFrame en = new MapFrame();
foreach (DataColumn dc in dt.Columns)
{
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
en.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
}
en.DirectInsert();
}
break;
case "Sys_MapExt":
foreach (DataRow dr in dt.Rows)
{
idx++;
MapExt en = new MapExt();
string text = "";
foreach (DataColumn dc in dt.Columns)
{
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
if (dc.ColumnName.Equals("HtmlText") == true)
{
text = dr[dc.ColumnName] as string;
continue;
}
if (DataType.IsNullOrEmpty(val.ToString()) == true)
continue;
en.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
}
//执行保存,并统一生成PK的规则.
en.InitPK();
en.DirectSave();
if (en.ExtType.Equals("HtmlText") == true && DataType.IsNullOrEmpty(text) == false)
en.SaveBigNoteHtmlText(text);
}
break;
case "Sys_MapAttr":
foreach (DataRow dr in dt.Rows)
{
MapAttr en = new MapAttr();
foreach (DataColumn dc in dt.Columns)
{
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
en.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
}
en.setMyPK(en.FK_MapData + "_" + en.KeyOfEn);
//直接插入.
try
{
en.DirectInsert();
//判断该字段是否是大文本 例如注释、说明
if (en.UIContralType == UIContralType.BigText)
{
//判断原文件是否存在
string file = BP.Difference.SystemConfig.PathOfDataUser + "CCForm/BigNoteHtmlText/" + oldMapID + ".htm";
//若文件存在,则复制
if (System.IO.File.Exists(file) == true)
{
string newFile = BP.Difference.SystemConfig.PathOfDataUser + "CCForm/BigNoteHtmlText/" + specFrmID + ".htm";
if (System.IO.File.Exists(newFile) == true)
System.IO.File.Delete(newFile);
System.IO.File.Copy(file, newFile);
}
}
}
catch
{
}
}
break;
case "Sys_GroupField":
foreach (DataRow dr in dt.Rows)
{
idx++;
GroupField en = new GroupField();
foreach (DataColumn dc in dt.Columns)
{
object val = dr[dc.ColumnName] as object;
if (val == null)
continue;
try
{
en.SetValByKey(dc.ColumnName, val.ToString().Replace(oldMapID, specFrmID));
}
catch
{
throw new Exception("val:" + val.ToString() + "oldMapID:" + oldMapID + "fk_mapdata:" + specFrmID);
}
}
int beforeID = en.OID;
en.OID = 0;
en.DirectInsert();
endDoSQL += "@UPDATE Sys_MapAttr SET GroupID=" + en.OID + " WHERE FK_MapData='" + specFrmID + "' AND GroupID='" + beforeID + "'";
}
break;
case "Sys_Enum":
case "Sys_Enums":
foreach (DataRow dr in dt.Rows)
{
SysEnum se = new Sys.SysEnum();
foreach (DataColumn dc in dt.Columns)
{
string val = dr[dc.ColumnName].ToString();// as string;
se.SetValByKey(dc.ColumnName, val);
}
if (BP.Difference.SystemConfig.CCBPMRunModel == CCBPMRunModel.SAAS)
{
se.OrgNo = BP.Web.WebUser.OrgNo;
// se.RefPK = se.OrgNo + "_" + se.EnumKey;
se.setMyPK(se.EnumKey + "_" + se.Lang + "_" + se.IntKey + "_" + se.OrgNo);
if (se.IsExits)
continue;
}
else
{
se.setMyPK(se.EnumKey + "_" + se.Lang + "_" + se.IntKey);
if (se.IsExits)
continue;
}
se.Insert();
}
break;
case "Sys_EnumMain":
foreach (DataRow dr in dt.Rows)
{
SysEnumMain sem = new Sys.SysEnumMain();
foreach (DataColumn dc in dt.Columns)
{
string val = dr[dc.ColumnName].ToString();// as string;
if (val == null)
continue;
sem.SetValByKey(dc.ColumnName, val);
}
if (BP.Difference.SystemConfig.CCBPMRunModel == CCBPMRunModel.SAAS)
{
sem.OrgNo = BP.Web.WebUser.OrgNo;
sem.No = sem.OrgNo + "_" + sem.EnumKey;
if (sem.IsExits)
continue;
}
else
{
if (sem.IsExits)
continue;
}
sem.Insert();
}
break;
case "WF_Node":
if (dt.Rows.Count > 0)
{
endDoSQL += "@UPDATE WF_Node SET FWCSta=2"
+ ",FWC_X=" + dt.Rows[0]["FWC_X"]
+ ",FWC_Y=" + dt.Rows[0]["FWC_Y"]
+ ",FWC_H=" + dt.Rows[0]["FWC_H"]
+ ",FWC_W=" + dt.Rows[0]["FWC_W"]
+ ",FWCType=" + dt.Rows[0]["FWCType"]
+ " WHERE NodeID=" + specFrmID.Replace("ND", "");
}
break;
default:
break;
}
}
#endregion
//执行最后结束的sql.
DBAccess.RunSQLs(endDoSQL);
MapData mdNew = new MapData(specFrmID);
mdNew.RepairMap();
if (mdNew.No.IndexOf("ND") == 0)
{
mdNew.FK_FormTree = "";
}
mdNew.Update();
return mdNew;
}
///
/// 修复map.
///
public void RepairMap()
{
GroupFields gfs = new GroupFields(this.No);
if (gfs.Count == 0)
{
GroupField gf = new GroupField();
gf.FrmID = this.No;
gf.Lab = this.Name;
gf.Insert();
string sqls = "";
sqls += "@UPDATE Sys_MapDtl SET GroupID=" + gf.OID + " WHERE FK_MapData='" + this.No + "'";
sqls += "@UPDATE Sys_MapAttr SET GroupID=" + gf.OID + " WHERE FK_MapData='" + this.No + "'";
//sqls += "@UPDATE Sys_MapFrame SET GroupID=" + gf.OID + " WHERE FK_MapData='" + this.No + "'";
sqls += "@UPDATE Sys_FrmAttachment SET GroupID=" + gf.OID + " WHERE FK_MapData='" + this.No + "'";
DBAccess.RunSQLs(sqls);
}
else
{
if (BP.Difference.SystemConfig.AppCenterDBType != DBType.Oracle)
{
GroupField gfFirst = gfs[0] as GroupField;
string sqls = "";
// sqls += "@UPDATE Sys_MapAttr SET GroupID=" + gfFirst.OID + " WHERE MyPK IN (SELECT X.MyPK FROM (SELECT MyPK FROM Sys_MapAttr WHERE GroupID NOT IN (SELECT OID FROM Sys_GroupField WHERE FrmID='" + this.No + "') or GroupID is null) AS X) AND FK_MapData='" + this.No + "' ";
sqls += "@UPDATE Sys_FrmAttachment SET GroupID=" + gfFirst.OID + " WHERE MyPK IN (SELECT X.MyPK FROM (SELECT MyPK FROM Sys_FrmAttachment WHERE GroupID NOT IN (SELECT OID FROM Sys_GroupField WHERE FrmID='" + this.No + "')) AS X) AND FK_MapData='" + this.No + "' ";
#warning 这些sql 对于Oracle 有问题,但是不影响使用.
try
{
DBAccess.RunSQLs(sqls);
}
catch
{
}
}
}
BP.Sys.MapAttr attr = new BP.Sys.MapAttr();
if (this.EnPK == "OID")
{
if (attr.IsExit(MapAttrAttr.KeyOfEn, "OID", MapAttrAttr.FK_MapData, this.No) == false)
{
attr.setFK_MapData(this.No);
attr.setKeyOfEn("OID");
attr.setName("OID");
attr.setMyDataType(DataType.AppInt);
attr.setUIContralType(UIContralType.TB);
attr.setLGType(FieldTypeS.Normal);
attr.SetValByKey(MapAttrAttr.UIVisible, false);
attr.SetValByKey(MapAttrAttr.UIIsEnable, false);
attr.DefVal = "0";
attr.HisEditType = BP.En.EditType.Readonly;
attr.Insert();
}
}
if (this.EnPK == "No" || this.EnPK == "MyPK")
{
if (attr.IsExit(MapAttrAttr.KeyOfEn, this.EnPK, MapAttrAttr.FK_MapData, this.No) == false)
{
attr.setFK_MapData(this.No);
attr.setKeyOfEn(this.EnPK);
attr.Name = this.EnPK;
attr.setMyDataType(DataType.AppInt);
attr.setUIContralType(UIContralType.TB);
attr.setLGType(FieldTypeS.Normal);
attr.SetValByKey(MapAttrAttr.UIVisible, false);
attr.SetValByKey(MapAttrAttr.UIIsEnable, false);
attr.DefVal = "0";
attr.HisEditType = BP.En.EditType.Readonly;
attr.Insert();
}
}
if (attr.IsExit(MapAttrAttr.KeyOfEn, "RDT", MapAttrAttr.FK_MapData, this.No) == false)
{
attr = new BP.Sys.MapAttr();
attr.setFK_MapData(this.No);
attr.setEditType(EditType.UnDel);
attr.setKeyOfEn("RDT");
attr.setName("更新时间");
attr.setGroupID(0);
attr.setMyDataType(DataType.AppDateTime);
attr.setUIContralType(UIContralType.TB);
attr.setLGType(FieldTypeS.Normal);
attr.SetValByKey(MapAttrAttr.UIVisible, false);
attr.SetValByKey(MapAttrAttr.UIIsEnable, false);
attr.DefVal = "@RDT";
attr.Tag = "1";
attr.Insert();
}
//检查特殊UIBindkey丢失的问题.
MapAttrs attrs = new MapAttrs();
attrs.Retrieve(MapAttrAttr.FK_MapData, this.No);
foreach (MapAttr item in attrs)
{
if (item.LGType == FieldTypeS.Enum || item.LGType == FieldTypeS.FK)
{
if (DataType.IsNullOrEmpty(item.UIBindKey) == true)
{
item.setLGType(FieldTypeS.Normal);
item.setUIContralType(UIContralType.TB);
item.Update();
}
}
}
}
protected override bool beforeInsert()
{
if (this.HisFrmType == FrmType.Url || this.HisFrmType == FrmType.Entity)
{
}
else
{
this.PTable = BP.Pub.PubClass.DealToFieldOrTableNames(this.PTable);
}
//写入日志.
if (this.No.StartsWith("ND") == false)
BP.Sys.Base.Glo.WriteUserLog("新建表单:" + this.No + " - " + this.Name);
this.Ver2022 = 1;
return base.beforeInsert();
}
///
/// 创建MapData后插入一条版本数据
///
protected override void afterInsert()
{
if (DataType.IsNullOrEmpty(this.FK_FormTree) == true)
{
base.afterInsert();
return;
}
MapDataVer ver = new MapDataVer();
ver.MyPK = this.No + ".1";
ver.Ver = 1; //设置当前为主版本.
ver.FrmID = this.No; //设置表单ID.
ver.IsRel = 1; //设置为主版本.
ver.Rec = Web.WebUser.No;
ver.RecName = Web.WebUser.Name;
ver.RDT = DataType.CurrentDateTime;
//设置数量.
ver.AttrsNum = 0;
ver.AthsNum = 0;
ver.DtlsNum = 0;
ver.ExtsNum = 0;
ver.Insert();
base.afterInsert();
}
protected override bool beforeUpdateInsertAction()
{
if (this.HisFrmType == FrmType.Url || this.HisFrmType == FrmType.Entity)
return base.beforeUpdateInsertAction();
//clear外键实体数量的缓存.
this.ClearAutoNumCash(false);
this.PTable = PubClass.DealToFieldOrTableNames(this.PTable);
//修改2021-09-04 注释,不知道这个代码的作用
//MapAttrs.Retrieve(MapAttrAttr.FK_MapData, PTable);
//设置OrgNo. 如果是管理员,就设置他所在的部门编号。
if (BP.Difference.SystemConfig.CCBPMRunModel != CCBPMRunModel.Single)
this.OrgNo = BP.Web.WebUser.OrgNo;
//判断是否有多个主键字段?
// string sql = "SELECT ";
//检查主键.
CheckPKFields(this.No, this.Name);
//清除缓存.
this.ClearCash();
return base.beforeUpdateInsertAction();
}
public static string CheckPKFields(string frmID, string name)
{
string sql = "SELECT KeyOfEn, Name FROM Sys_MapAttr WHERE FK_MapData='" + frmID + "' ";
sql += " AND ( ";
sql += " KeyOfEn='OID' ";
sql += " OR KeyOfEn='No' ";
sql += " OR KeyOfEn='MyPK' ";
sql += " OR KeyOfEn='NodeID' ";
sql += " OR KeyOfEn='WorkID' ";
sql += " ) ";
DataTable dt = DBAccess.RunSQLReturnTable(sql);
if (dt.Rows.Count == 1)
return "数据正确.";
if (dt.Rows.Count == 0)
return "err@表单缺少主键." + frmID + "," + name;
string msg = "err@FrmID=" + frmID + name + "主键不明确.";
foreach (DataRow dr in dt.Rows)
{
msg += "@" + dr[0] + "," + dr[1].ToString();
}
return msg;
}
///
/// 更新版本
///
public void UpdateVer()
{
string sql = "UPDATE Sys_MapData SET VER='" + DataType.CurrentDateTimess + "' WHERE No='" + this.No + "'";
DBAccess.RunSQL(sql);
}
protected override bool beforeDelete()
{
#region 判断是否是节点表单?如果是,判断节点是否被删除了.
//if (this.No.StartsWith("ND") == true)
//{
// string frmID = this.No.Replace("ND", "");
// if (BP.DA.DataType.IsNumStr(frmID) == true)
// {
// int nodeID = int.Parse(frmID);
// int count = DBAccess.RunSQLReturnValInt("SELECT COUNT(*) as NUM FROM WF_Node WHERE NodeID=" + nodeID);
// if (count == 1)
// throw new Exception("err@删除节点表单前,需要删除节点数据."+this.No+" - " +this.Name);
// }
//}
#endregion 判断是否是节点表单?如果是,判断节点是否被删除了.
#region 检查完整性.
string sql = "";
//如果存在版本就不能删除
sql = "SELECT count(*) From Sys_MapDataVer Where FrmID='" + this.No + "' AND Ver!=" + this.Ver2022;
try
{
if (DBAccess.RunSQLReturnValInt(sql) > 0)
{
throw new Exception("表单存在其他的版本,请删除其他版本后再删除表单");
return false;
}
}
catch (Exception ex)
{
MapDataVer mv = new MapDataVer();
mv.CheckPhysicsTable();
if (DBAccess.RunSQLReturnValInt(sql) > 0)
{
throw new Exception("表单存在其他的版本,请删除其他版本后再删除表单");
return false;
}
}
//如果当前版本是主版本,需要删除主版本的信息
sql = "SELECT Ver From Sys_MapDataVer WHERE FrmID='" + this.No + "' AND IsRel=1";
int ver = DBAccess.RunSQLReturnValInt(sql, 0);
if (ver == this.Ver2022)
{
//删除主版本的信息
MapData md = new MapData();
md.No = this.No + "." + ver;
if (md.RetrieveFromDBSources() == 1)
md.Delete();
DBAccess.RunSQL("DELETE FROM Sys_MapDataVer WHERE MyPK='" + md.No + "'");
}
sql = "";
sql = "SELECT * FROM Sys_MapDtl WHERE FK_MapData ='" + this.No + "'";
DataTable Sys_MapDtl = DBAccess.RunSQLReturnTable(sql);
string whereFK_MapData = "FK_MapData= '" + this.No + "' ";
string whereEnsName = "FrmID= '" + this.No + "' ";
string whereNo = "No='" + this.No + "' ";
foreach (DataRow dr in Sys_MapDtl.Rows)
{
// ids += ",'" + dr["No"] + "'";
whereFK_MapData += " OR FK_MapData='" + dr["No"] + "' ";
whereEnsName += " OR FrmID='" + dr["No"] + "' ";
whereNo += " OR No='" + dr["No"] + "' ";
}
#endregion 检查完整性.
#region 删除相关的数据。
sql = "DELETE FROM Sys_MapDtl WHERE FK_MapData='" + this.No + "'";
// sql += "@DELETE FROM Sys_FrmLine WHERE " + whereFK_MapData;
//@hongyan.
if (DBAccess.IsExitsTableCol("Sys_FrmEvent", "FrmID"))
DBAccess.RunSQL("DELETE FROM Sys_FrmEvent WHERE " + whereEnsName);
if (DBAccess.IsExitsTableCol("Sys_FrmEvent", "FK_MapData"))
DBAccess.RunSQL("DELETE FROM Sys_FrmEvent WHERE " + whereFK_MapData);
sql += "@DELETE FROM Sys_FrmBtn WHERE " + whereFK_MapData;
// sql += "@DELETE FROM Sys_FrmLab WHERE " + whereFK_MapData;
//sql += "@DELETE FROM Sys_FrmLink WHERE " + whereFK_MapData;
sql += "@DELETE FROM Sys_FrmImg WHERE " + whereFK_MapData;
sql += "@DELETE FROM Sys_FrmImgAth WHERE " + whereFK_MapData;
sql += "@DELETE FROM Sys_FrmRB WHERE " + whereFK_MapData;
sql += "@DELETE FROM Sys_FrmAttachment WHERE " + whereFK_MapData;
sql += "@DELETE FROM Sys_MapFrame WHERE " + whereFK_MapData;
if (this.No.Contains("BP.") == false)
sql += "@DELETE FROM Sys_MapExt WHERE " + whereFK_MapData;
sql += "@DELETE FROM Sys_MapAttr WHERE " + whereFK_MapData;
sql += "@DELETE FROM Sys_GroupField WHERE " + whereEnsName;
sql += "@DELETE FROM Sys_MapData WHERE " + whereNo;
// sql += "@DELETE FROM Sys_M2M WHERE " + whereFK_MapData;
sql += "@DELETE FROM WF_FrmNode WHERE FK_Frm='" + this.No + "'";
sql += "@DELETE FROM Sys_FrmSln WHERE " + whereFK_MapData;
//sql += "@DELETE FROM Sys_MapDataVer WHERE " + whereFK_MapData;
DBAccess.RunSQLs(sql);
#endregion 删除相关的数据。
#region 删除物理表。
//如果存在物理表.
if (DBAccess.IsExitsObject(this.PTable) && this.PTable.IndexOf("ND") == 0)
{
//如果其他表单引用了该表,就不能删除它.
sql = "SELECT COUNT(No) AS NUM FROM Sys_MapData WHERE PTable='" + this.PTable + "' OR ( PTable='' AND No='" + this.PTable + "')";
if (DBAccess.RunSQLReturnValInt(sql, 0) > 1)
{
/*说明有多个表单在引用.*/
}
else
{
// edit by zhoupeng 误删已经有数据的表.
if (DBAccess.RunSQLReturnValInt("SELECT COUNT(*) FROM " + this.PTable + " WHERE 1=1 ") == 0)
DBAccess.RunSQL("DROP TABLE " + this.PTable);
}
}
MapDtls dtls = new MapDtls(this.No);
foreach (MapDtl dtl in dtls)
dtl.Delete();
#endregion
#region 删除注册到的外检表.
SFTables sfs = new SFTables();
sfs.Retrieve(SFTableAttr.SrcTable, this.PTable);
foreach (SFTable item in sfs)
{
if (item.IsCanDelete() == null)
item.Delete();
}
#endregion 删除注册到的外检表.
#region 属性.
#endregion 属性.
//写入日志.
if (this.No.StartsWith("ND") == false)
BP.Sys.Base.Glo.WriteUserLog("删除表单:" + this.No + " - " + this.Name);
return base.beforeDelete();
}
#endregion 常用方法.
#region 与Excel相关的操作 .
///
/// 获得Excel文件流
///
///
///
public bool ExcelGenerFile(string pkValue, ref byte[] bytes, string saveTo)
{
try
{
byte[] by = DBAccess.GetByteFromDB(this.PTable, this.EnPK, pkValue, saveTo);
if (by != null)
{
bytes = by;
return true;
}
else //说明当前excel文件没有生成.
{
string tempExcel = BP.Difference.SystemConfig.PathOfDataUser + "FrmVSTOTemplate/" + this.No + ".xlsx";
if (System.IO.File.Exists(tempExcel) == true)
{
bytes = DataType.ConvertFileToByte(tempExcel);
return false;
}
else //模板文件也不存在时
{
throw new Exception("@没有找到模版文件." + tempExcel + " 请确认表单配置.");
}
}
}
catch (Exception ex)
{
BP.DA.Log.DebugWriteError("读取excel失败:" + ex.Message);
return false;
}
}
///
/// 保存excel文件
///
///
///
public void ExcelSaveFile(string pkValue, byte[] bty, string saveTo)
{
DBAccess.SaveBytesToDB(bty, this.PTable, this.EnPK, pkValue, saveTo);
}
#endregion 与Excel相关的操作 .
#region 与Word相关的操作 .
///
/// 获得Excel文件流
///
///
///
public void WordGenerFile(string pkValue, ref byte[] bytes, string saveTo)
{
byte[] by = DBAccess.GetByteFromDB(this.PTable, this.EnPK, pkValue, saveTo);
if (by != null)
{
bytes = by;
return;
}
else //说明当前excel文件没有生成.
{
string tempExcel = BP.Difference.SystemConfig.PathOfDataUser + "FrmVSTOTemplate/" + this.No + ".docx";
if (System.IO.File.Exists(tempExcel) == false)
tempExcel = BP.Difference.SystemConfig.PathOfDataUser + "FrmVSTOTemplate/NDxxxRpt.docx";
bytes = DataType.ConvertFileToByte(tempExcel);
return;
}
}
///
/// 保存excel文件
///
///
///
public void WordSaveFile(string pkValue, byte[] bty, string saveTo)
{
DBAccess.SaveBytesToDB(bty, this.PTable, this.EnPK, pkValue, saveTo);
}
#endregion 与Excel相关的操作 .
///
/// 创建版本
///
public string CreateMapDataVer()
{
//创建版本之前先判断当前版本是不是有数据
if (BP.DA.DBAccess.IsExitsObject(this.PTable) == false)
{
//MapData md = new MapData(this.No);
GEEntity ge = new GEEntity(this.No);
ge.CheckPhysicsTable();
}
//获得最大的版本数.
int count = DBAccess.RunSQLReturnValInt("SELECT COUNT(*) From " + this.PTable + " WHERE AtPara NOT LIKE '%@FrmVer=%'");
if (count == 0)
return "表单" + this.Name + "版本" + this.Ver2022 + "还没有使用,不用创建新的版本。";
MapDataVer ver = new MapDataVer();
MapDataVers vers = new MapDataVers();
vers.Retrieve("FrmID", this.No);
if (vers.Count == 0)
{
ver.MyPK = this.No + ".1";
ver.Ver = 1; //设置当前为主版本.
ver.FrmID = this.No; //设置表单ID.
ver.IsRel = 1; //设置为主版本.
ver.Rec = Web.WebUser.No;
ver.RecName = Web.WebUser.Name;
ver.RDT = DataType.CurrentDateTime;
//设置数量.
ver.AttrsNum = DBAccess.RunSQLReturnValInt("SELECT COUNT(*) FROM Sys_MapAttr WHERE FK_MapData='" + this.No + "'");
ver.AthsNum = DBAccess.RunSQLReturnValInt("SELECT COUNT(*) FROM Sys_Frmattachment WHERE FK_MapData='" + this.No + "'");
ver.DtlsNum = DBAccess.RunSQLReturnValInt("SELECT COUNT(*) FROM Sys_MapDtl WHERE FK_MapData='" + this.No + "'");
ver.ExtsNum = DBAccess.RunSQLReturnValInt("SELECT COUNT(*) FROM Sys_MapExt WHERE FK_MapData='" + this.No + "'");
ver.Insert();
this.Ver2022 = ver.Ver; //更新当前的版本.
this.Update();
//执行复制,表单.
BP.Sys.CCFormAPI.CopyFrm(this.No, this.No + "." + this.Ver2022, this.Name + "." + ver.Ver, this.FK_FormTree);
return "创建成功." + ver.GetValByKey(MapDataVerAttr.Ver);
}
//缺少AtPara字段
MapAttr mattr = new MapAttr();
mattr.setMyPK(this.No + "_AtPara");
if (mattr.RetrieveFromDBSources() == 0)
{
mattr.setFK_MapData(this.No);
mattr.HisEditType = EditType.UnDel;
mattr.setKeyOfEn("AtPara");
mattr.setName("参数"); // 单据编号
mattr.setMyDataType(DataType.AppString);
mattr.setUIContralType(UIContralType.TB);
mattr.setLGType(FieldTypeS.Normal);
mattr.setUIVisible(false);
mattr.setUIIsEnable(false);
mattr.UIIsLine = false;
mattr.setMinLen(0);
mattr.setMaxLen(4000);
mattr.Idx = -100;
mattr.Insert();
GEEntity en = new GEEntity(this.No);
en.CheckPhysicsTable();
}
//设置所有的版本为 0 .
string sql = "UPDATE Sys_MapDataVer SET IsRel=0 WHERE FrmID='" + this.No + "'";
DBAccess.RunSQL(sql);
#region 1. 创建新版本 执行复制,表单.
int maxVer = DBAccess.RunSQLReturnValInt("SELECT MAX(ver) FROM Sys_MapDataVer WHERE FrmID='" + this.No + "'", 0);
//执行复制,表单,创建新版本.
ver.Ver = maxVer + 1;
ver.MyPK = this.No + "." + ver.Ver;
ver.FrmID = this.No; //设置表单ID.
ver.IsRel = 1; //设置为主版本.
ver.Rec = Web.WebUser.No;
ver.RecName = Web.WebUser.Name;
ver.RDT = DataType.CurrentDateTime;
//设置数量.
ver.AttrsNum = DBAccess.RunSQLReturnValInt("SELECT COUNT(*) FROM Sys_MapAttr WHERE FK_MapData='" + this.No + "'");
ver.AthsNum = DBAccess.RunSQLReturnValInt("SELECT COUNT(*) FROM Sys_Frmattachment WHERE FK_MapData='" + this.No + "'");
ver.DtlsNum = DBAccess.RunSQLReturnValInt("SELECT COUNT(*) FROM Sys_MapDtl WHERE FK_MapData='" + this.No + "'");
ver.ExtsNum = DBAccess.RunSQLReturnValInt("SELECT COUNT(*) FROM Sys_MapExt WHERE FK_MapData='" + this.No + "'");
ver.Insert(); //创建新版本.
//生成新的表单.
BP.Sys.CCFormAPI.CopyFrm(this.No, this.No + "." + ver.Ver, this.Name + "(Ver" + ver.Ver + ".0)", this.FK_FormTree);
//把版本的FK_FormTree清空
MapData md = new MapData(this.No + "." + ver.Ver);
md.FK_FormTree = "";
md.Update();
#endregion 1. 创建新版本 执行复制,表单.
#region 2. 覆盖旧版本.
string currVer = this.No + "." + this.Ver2022.ToString(); // this.No + "." + vers.Count;
md = new MapData();
md.No = currVer;
if (md.RetrieveFromDBSources() == 1)
md.Delete();
//把表单属性的FK_FormTree清空
BP.Sys.CCFormAPI.CopyFrm(this.No, currVer, this.Name + "(Ver" + this.Ver2022.ToString() + ".0)", this.FK_FormTree);
md.Retrieve();
md.FK_FormTree = "";
md.PTable = this.PTable;
md.Update();
//修改从表的存储表
MapDtls dtls = md.MapDtls;
foreach (MapDtl dtl in dtls)
{
if (dtl.PTable.Equals(dtl.No) == true)
{
dtl.PTable = dtl.PTable.Replace(currVer, this.No);
dtl.Update();
continue;
}
}
//把当前表单对应数据改成当前的版本
DBAccess.RunSQL("UPDATE " + md.PTable + " SET AtPara=CONCAT(AtPara,'@FrmVer=" + this.Ver2022 + "') WHERE AtPara NOT LIKE '%@FrmVer=%'");
#endregion 2. 覆盖旧版本.
#region 3. 更新当前版本号.
this.Ver2022 = ver.Ver; //更新当前的版本.
this.Update();
#endregion 3. 更新当前版本号.
return "创建成功,版本号:" + ver.Ver; ;
}
}
///
/// 映射基础s
///
public class MapDatas : EntitiesNoName
{
#region 构造
///
/// 映射基础s
///
public MapDatas()
{
}
///
/// 得到它的 Entity
///
public override Entity GetNewEntity
{
get
{
return new MapData();
}
}
#endregion
#region 为了适应自动翻译成java的需要,把实体转换成List.
///
/// 转化成 java list,C#不能调用.
///
/// List
public System.Collections.Generic.IList ToJavaList()
{
return (System.Collections.Generic.IList)this;
}
///
/// 转化成list
///
/// List
public System.Collections.Generic.List Tolist()
{
System.Collections.Generic.List list = new System.Collections.Generic.List();
for (int i = 0; i < this.Count; i++)
{
list.Add((MapData)this[i]);
}
return list;
}
#endregion 为了适应自动翻译成java的需要,把实体转换成List.
}
}