public static void SaveDtl(string fk_mapdata, string ctrlID, float x, float y, float h, float w) { MapDtl dtl = new MapDtl(); dtl.No = ctrlID; dtl.RetrieveFromDBSources(); dtl.FK_MapData = fk_mapdata; dtl.X = x; dtl.Y = y; dtl.W = w; dtl.H = h; dtl.Update(); }
void btn_Pub_Click(object sender, EventArgs e) { #region 获得选择的ID string ids = ""; foreach (Control ctl in this.Pub2.Controls) { if (ctl == null || ctl.ID == null || ctl.ID.Contains("CB_") == false) { continue; } CheckBox cb = ctl as CheckBox; if (cb == null) { continue; } if (cb.Checked == false) { continue; } ids += ctl.ID.Replace("CB_", "") + ","; } if (string.IsNullOrEmpty(ids) == true) { BP.Sys.PubClass.Alert("您没有选择项目."); return; } this.Alert("成功将:" + ids + "放入了数据表..."); #endregion 获得选择的ID #region 获得数据. MapDtl dtl = new BP.Sys.MapDtl(this.FK_MapDtl); string sql = ""; DataTable dt = null; try { sql = dtl.ImpSQLFull.Clone() as string; ids = ids.Replace(",", "','"); sql = sql.Replace("@Keys", ids.Substring(0, ids.Length - 3)); dt = BP.DA.DBAccess.RunSQLReturnTable(sql); //当ID是int类型是可能抛出异常. } catch { sql = dtl.ImpSQLFull.Clone() as string; sql = sql.Replace("@Keys", ids.Substring(0, ids.Length - 2)); dt = BP.DA.DBAccess.RunSQLReturnTable(sql); } #endregion 获得数据. #region 把数据放入明细表. GEDtl gedtl = new BP.Sys.GEDtl(this.FK_MapDtl); foreach (DataRow dr in dt.Rows) { gedtl.RefPK = this.WorkID.ToString(); gedtl.FID = this.FID; gedtl.Rec = WebUser.No; foreach (DataColumn dc in dt.Columns) { //赋值. gedtl.SetValByKey(dc.ColumnName, dr[dc.ColumnName]); } gedtl.InsertAsOID(BP.DA.DBAccess.GenerOID()); } #endregion 把数据放入明细表. Button btn = sender as Button; if (btn.ID == "Btn_Pub1") { this.Alert("放入成功"); } else { this.WinCloseWithMsg("放入成功"); } }
protected void Page_Load(object sender, EventArgs e) { if (this.DoType != null) { return; } MapDtl dtl = new BP.Sys.MapDtl(this.FK_MapDtl); this.Title = dtl.Name; this.Label1.Text = dtl.Name; this.Pub1.Add(" 请输入关键字:"); TextBox tb = new TextBox(); tb.ID = "TB_Key"; tb.Text = this.SKey; this.Pub1.Add(tb); Button btn = new Button(); btn.ID = "Btn1"; btn.Text = "查询"; btn.Click += new EventHandler(btn_Click); this.Pub1.Add(btn); #region 显示数据. string key = this.Pub1.GetTextBoxByID("TB_Key").Text.Trim(); string sql = ""; if (this.SKey == null) { sql = dtl.ImpSQLInit.Clone() as string; sql = sql.Replace("~", "'"); } else { sql = dtl.ImpSQLSearch.Clone() as string; sql = sql.Replace("@Key", key); sql = sql.Replace("~", "'"); } sql = sql.Replace("@WebUser.No", WebUser.No); sql = sql.Replace("@WebUser.Name", WebUser.Name); sql = sql.Replace("@WebUser.FK_Dept", WebUser.FK_Dept); sql = sql.Replace("@WebUser.FK_DeptName", WebUser.FK_DeptName); DataTable dt = BP.DA.DBAccess.RunSQLReturnTable(sql); this.BindTableMulti(dt); //增加启动流程. Button button = new Button(); button.ID = "Btn_Pub1"; button.Text = "放入"; button.Click += new EventHandler(btn_Pub_Click); this.Pub1.Add(button); button = new Button(); button.ID = "Btn_Pub2"; button.Text = "放入并关闭"; button.Click += new EventHandler(btn_Pub_Click); this.Pub1.Add(button); #endregion 显示数据. }
/// <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(); } } } }