/// <summary> /// 生成单据根据 /// </summary> /// <param name="templeteFile">模板文件</param> /// <param name="saveToFile"></param> /// <param name="mainDT"></param> /// <param name="dtls"></param> public void MakeDocByDataSet(string templeteFile, string saveToPath, string saveToFileName, DataTable mainDT, DataSet dtlsDS) { string valMain = DBAccess.RunSQLReturnString("SELECT NO FROM SYS_MapData"); this.HisGEEntity = new GEEntity(valMain); this.HisGEEntity.Row.LoadDataTable(mainDT, mainDT.Rows[0]); this.AddEn(this.HisGEEntity); //增加一个主表。 if (dtlsDS != null) { foreach (DataTable dt in dtlsDS.Tables) { string dtlID = DBAccess.RunSQLReturnString("SELECT NO FROM SYS_MapDtl "); BP.Sys.GEDtls dtls = new BP.Sys.GEDtls(dtlID); foreach (DataRow dr in dt.Rows) { BP.Sys.GEDtl dtl = dtls.GetNewEntity as BP.Sys.GEDtl; dtl.Row.LoadDataTable(dt, dr); dtls.AddEntity(dtl); } this.AddDtlEns(dtls); //增加一个明晰。 } } this.MakeDoc(templeteFile, saveToPath, saveToFileName, "", false); }
/// <summary> /// 把当前实体的数据copy到指定的主键数据表里. /// </summary> /// <param name="oid">指定的主键</param> public void CopyToOID(string oid) { //实例化历史数据表单entity. string oidOID = this.MyPK; this.MyPK = oid; this.Save(); //复制从表数据. MapDtls dtls = new MapDtls(this.FK_MapData); foreach (MapDtl dtl in dtls) { //删除旧的数据. BP.DA.DBAccess.RunSQL("DELETE FROM " + dtl.PTable + " WHERE RefPK=" + this.MyPK); GEDtls ensDtl = new GEDtls(dtl.No); ensDtl.Retrieve(GEDtlAttr.RefPK, oidOID); foreach (GEDtl enDtl in ensDtl) { enDtl.RefPK = this.MyPK.ToString(); enDtl.InsertAsNew(); } } //复制附件数据. FrmAttachments aths = new FrmAttachments(this.FK_MapData); foreach (FrmAttachment ath in aths) { //删除可能存在的新oid数据。 DBAccess.RunSQL("DELETE FROM Sys_FrmAttachmentDB WHERE FK_MapData='" + this.FK_MapData + "' AND RefPKVal='" + this.MyPK + "'"); //找出旧数据. FrmAttachmentDBs athDBs = new FrmAttachmentDBs(this.FK_MapData, oidOID.ToString()); foreach (FrmAttachmentDB athDB in athDBs) { FrmAttachmentDB athDB_N = new FrmAttachmentDB(); athDB_N.Copy(athDB); athDB_N.FK_MapData = this.FK_MapData; athDB_N.RefPKVal = this.MyPK.ToString(); if (athDB_N.HisAttachmentUploadType == AttachmentUploadType.Single) { /*如果是单附件.*/ athDB_N.MyPK = athDB_N.FK_FrmAttachment + "_" + this.MyPK; if (athDB_N.IsExits == true) { continue; /*说明上一个节点或者子线程已经copy过了, 但是还有子线程向合流点传递数据的可能,所以不能用break.*/ } athDB_N.Insert(); } else { athDB_N.MyPK = DBAccess.GenerGUID(); athDB_N.Insert(); } } } }
/// <summary> /// 从另外的一个实体来copy数据. /// </summary> /// <param name="en"></param> public void CopyFromFrm(GEEntityMyPK en) { //先求出来旧的OID. string oldOID = this.MyPK; //复制主表数据. this.Copy(en); this.Save(); this.MyPK = oldOID; //复制从表数据. MapDtls dtls = new MapDtls(this.FK_MapData); //被copy的明细集合. MapDtls dtlsFrom = new MapDtls(en.FK_MapData); if (dtls.Count != dtls.Count) { throw new Exception("@复制的两个表单从表不一致..."); } //序号. int i = 0; foreach (MapDtl dtl in dtls) { //删除旧的数据. BP.DA.DBAccess.RunSQL("DELETE FROM " + dtl.PTable + " WHERE RefPK=" + this.MyPK); //求对应的Idx的,从表配置. MapDtl dtlFrom = dtlsFrom[i] as MapDtl; GEDtls ensDtlFrom = new GEDtls(dtlFrom.No); ensDtlFrom.Retrieve(GEDtlAttr.RefPK, oldOID); //创建一个实体. GEDtl dtlEnBlank = new GEDtl(dtl.No); // 遍历数据,执行copy. foreach (GEDtl enDtlFrom in ensDtlFrom) { dtlEnBlank.Copy(enDtlFrom); dtlEnBlank.RefPK = this.MyPK.ToString(); dtlEnBlank.SaveAsNew(); } i++; } //复制附件数据. FrmAttachments aths = new FrmAttachments(this.FK_MapData); FrmAttachments athsFrom = new FrmAttachments(en.FK_MapData); foreach (FrmAttachment ath in aths) { //删除数据,防止copy重复 DBAccess.RunSQL("DELETE FROM Sys_FrmAttachmentDB WHERE FK_MapData='" + this.FK_MapData + "' AND RefPKVal='" + this.MyPK + "'"); foreach (FrmAttachment athFrom in athsFrom) { if (athFrom.NoOfObj != ath.NoOfObj) { continue; } FrmAttachmentDBs athDBsFrom = new FrmAttachmentDBs(); athDBsFrom.Retrieve(FrmAttachmentDBAttr.FK_FrmAttachment, athFrom.MyPK, FrmAttachmentDBAttr.RefPKVal, en.MyPK.ToString()); foreach (FrmAttachmentDB athDBFrom in athDBsFrom) { athDBFrom.MyPK = BP.DA.DBAccess.GenerGUID(); athDBFrom.FK_FrmAttachment = ath.MyPK; athDBFrom.RefPKVal = this.MyPK.ToString(); athDBFrom.Insert(); } } } }