void trd() { timer1.Enabled = true; m_baseMgr = new CBaseObjectMgr(); m_baseMgr.Ctx = Program.Ctx; m_baseMgr.TbCode = "test5"; CTable tb = Program.Ctx.TableMgr.FindByCode("test5"); CColumn col = tb.ColumnMgr.FindByCode("val"); double dblCount = 0; while (m_bIsStart) { //for (int i = 0; i < 100; i++) //{ CBaseObject obj = new CBaseObject(); obj.Ctx = Program.Ctx; obj.TbCode = "test5"; Random rand = new Random(); obj.SetColValue(col, rand.NextDouble() * 10); m_baseMgr.AddNew(obj, true); dblCount++; this.Invoke(new myEventHandler(ChangeLabelText), new object[] { dblCount.ToString() }); //} //m_baseMgr.Save(true); } }
void PostData() { if (!ValidateData()) { return; } CBaseObject objP = (CBaseObject)Session["AddMultMasterDetailViewRecord"]; CBaseObject BaseObject = m_BaseObjectMgr.CreateBaseObject(); BaseObject.Ctx = m_BaseObjectMgr.Ctx; BaseObject.TbCode = m_BaseObjectMgr.TbCode; CColumn colP = (CColumn)objP.Table.ColumnMgr.Find(m_ViewDetail.PrimaryKey); CColumn colF = (CColumn)m_Table.ColumnMgr.Find(m_ViewDetail.ForeignKey); BaseObject.SetColValue(colF, objP.GetColValue(colP)); bool bHasVisible = false; //foreach (CBaseObject objCIVD in m_ViewDetail.ColumnInViewDetailMgr.GetList()) foreach (CBaseObject objCol in m_Table.ColumnMgr.GetList()) { //CColumnInViewDetail civd = (CColumnInViewDetail)objCIVD; //CColumn col = (CColumn)m_Table.ColumnMgr.Find(civd.FW_Column_id); CColumn col = (CColumn)objCol; if (col == null) { continue; } //判断禁止和只读权限字段 if (m_sortRestrictColumnAccessType.ContainsKey(col.Id)) { AccessType accessType = m_sortRestrictColumnAccessType[col.Id]; if (accessType == AccessType.forbide) { continue; } //只读只在界面控制,有些默认值需要只读也需要保存数据 //else if (accessType == AccessType.read) // continue; } // if (col.Code.Equals("id", StringComparison.OrdinalIgnoreCase)) { continue; } else if (col.Code.Equals("Created", StringComparison.OrdinalIgnoreCase)) { BaseObject.SetColValue(col, DateTime.Now); continue; } else if (col.Code.Equals("Creator", StringComparison.OrdinalIgnoreCase)) { CUser user = (CUser)Session["User"]; BaseObject.SetColValue(col, user.Id); continue; } else if (col.Code.Equals("Updated", StringComparison.OrdinalIgnoreCase)) { continue; } else if (col.Code.Equals("Updator", StringComparison.OrdinalIgnoreCase)) { //BaseObject.SetColValue(col, Program.User.Id); continue; } if (col.ColType == ColumnType.object_type) { HttpPostedFile postfile = Request.Files.Get("_" + col.Code); if (postfile != null && postfile.ContentLength > 0) { string sFileName = postfile.FileName; if (sFileName.LastIndexOf('\\') > -1)//有些浏览器不带路径 { sFileName = sFileName.Substring(sFileName.LastIndexOf('\\')); } byte[] byteFileName = System.Text.Encoding.Default.GetBytes(sFileName); byte[] byteValue = new byte[254 + postfile.ContentLength]; byte[] byteData = new byte[postfile.ContentLength]; postfile.InputStream.Read(byteData, 0, postfile.ContentLength); Array.Copy(byteFileName, byteValue, byteFileName.Length); Array.Copy(byteData, 0, byteValue, 254, byteData.Length); BaseObject.SetColValue(col, byteValue); } } else if (col.ColType == ColumnType.path_type) { string sUploadPath = col.UploadPath; if (sUploadPath[sUploadPath.Length - 1] != '\\') { sUploadPath += "\\"; } if (!Directory.Exists(sUploadPath)) { Directory.CreateDirectory(sUploadPath); } HttpPostedFile postfile = Request.Files.Get("_" + col.Code); if (postfile != null && postfile.ContentLength > 0) { string sFileName = postfile.FileName; if (sFileName.LastIndexOf('\\') > -1)//有些浏览器不带路径 { sFileName = sFileName.Substring(sFileName.LastIndexOf('\\')); } FileInfo fi = new FileInfo(sUploadPath + sFileName); Guid guid = Guid.NewGuid(); string sDestFile = string.Format("{0}{1}", guid.ToString().Replace("-", ""), fi.Extension); postfile.SaveAs(sUploadPath + sDestFile); string sVal = string.Format("{0}|{1}", sDestFile, sFileName); BaseObject.SetColValue(col, sVal); } } else if (col.ColType == ColumnType.bool_type) { string val = Request.Params["_" + col.Code]; if (!string.IsNullOrEmpty(val) && val.ToLower() == "on") { BaseObject.SetColValue(col, true); } else { BaseObject.SetColValue(col, false); } } else if (col.ColType == ColumnType.datetime_type) { string val = Request.Params["_" + col.Code]; if (!string.IsNullOrEmpty(val)) { BaseObject.SetColValue(col, Convert.ToDateTime(val)); } } else { BaseObject.SetColValue(col, Request.Params["_" + col.Code]); } bHasVisible = true; } if (!bHasVisible) { //Response.Write("没有可修改字段!"); Response.Write("<script>alert('没有可修改字段!');</script>"); return; } if (!m_BaseObjectMgr.AddNew(BaseObject, true)) { //Response.Write("添加失败!"); Response.Write("<script>alert('添加失败!');</script>"); return; } //在iframe里访问外面,需要parent.parent. //Response.Write("<script>parent.parent.grid.loadData(true);parent.parent.$.ligerDialog.close();</script>"); Response.Write("<script>parent.parent.onOkAddMasterDetailViewRecord();</script>"); }