void PostData() { if (!ValidateData()) { return; } List <CBaseObject> lstCol = m_Table.ColumnMgr.GetList(); bool bHasVisible = false; foreach (CBaseObject obj in lstCol) { CColumn col = (CColumn)obj; //判断禁止和只读权限字段 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)) { continue; } else if (col.Code.Equals("Creator", StringComparison.OrdinalIgnoreCase)) { //BaseObject.SetColValue(col, Program.User.Id); continue; } else if (col.Code.Equals("Updated", StringComparison.OrdinalIgnoreCase)) { m_BaseObject.SetColValue(col, DateTime.Now); continue; } else if (col.Code.Equals("Updator", StringComparison.OrdinalIgnoreCase)) { CUser u = (CUser)Session["User"]; m_BaseObject.SetColValue(col, u.Id); continue; } if (col.ColType == ColumnType.object_type) { string ckVal = Request.Params["ckClear_" + col.Code]; if (!string.IsNullOrEmpty(ckVal) && ckVal.ToLower() == "on") { //清空附件 m_BaseObject.SetColValue(col, null); } else { 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); m_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); } string ckVal = Request.Params["ckClear_" + col.Code]; if (!string.IsNullOrEmpty(ckVal) && ckVal.ToLower() == "on") { //清空附件 m_BaseObject.SetColValue(col, ""); } else { 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); m_BaseObject.SetColValue(col, sVal); } } } else if (col.ColType == ColumnType.bool_type) { string val = Request.Params["_" + col.Code]; if (!string.IsNullOrEmpty(val) && val.ToLower() == "on") { m_BaseObject.SetColValue(col, true); } else { m_BaseObject.SetColValue(col, false); } } else if (col.ColType == ColumnType.datetime_type) { string val = Request.Params["_" + col.Code]; if (!string.IsNullOrEmpty(val)) { m_BaseObject.SetColValue(col, Convert.ToDateTime(val)); } } else { m_BaseObject.SetColValue(col, Request.Params["_" + col.Code]); } bHasVisible = true; } if (!bHasVisible) { //Response.Write("没有可修改字段!"); Response.Write("<script>alert('没有可修改字段!');</script>"); return; } SortedList <Guid, CBaseObject> arrP = (SortedList <Guid, CBaseObject>)Session["EditMasterDetailViewRecord"]; CBaseObject objP = arrP.Values[0]; //外键关联 CColumn colP = (CColumn)objP.Table.ColumnMgr.Find(m_ViewDetail.PrimaryKey); CColumn colF = (CColumn)m_Table.ColumnMgr.Find(m_ViewDetail.ForeignKey); m_BaseObject.SetColValue(colF, objP.GetColValue(colP)); CUser user = (CUser)Session["User"]; m_BaseObject.Updator = user.Id; m_BaseObjectMgr.Update(m_BaseObject); if (!m_BaseObjectMgr.Save(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.onOkEditDetailRecord2();</script>"); }
void PostData() { if (!ValidateData()) { return; } List <CBaseObject> lstCol = m_Table.ColumnMgr.GetList(); bool bHasVisible = false; foreach (CBaseObject obj in lstCol) { CColumn col = (CColumn)obj; if (col.Code.Equals("id", StringComparison.OrdinalIgnoreCase)) { continue; } else if (col.Code.Equals("Created", StringComparison.OrdinalIgnoreCase)) { continue; } else if (col.Code.Equals("Creator", StringComparison.OrdinalIgnoreCase)) { //BaseObject.SetColValue(col, Program.User.Id); continue; } else if (col.Code.Equals("Updated", StringComparison.OrdinalIgnoreCase)) { m_BaseObject.SetColValue(col, DateTime.Now); continue; } else if (col.Code.Equals("Updator", StringComparison.OrdinalIgnoreCase)) { CUser user = (CUser)Session["User"]; m_BaseObject.SetColValue(col, 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); m_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); m_BaseObject.SetColValue(col, sVal); } } else if (col.ColType == ColumnType.bool_type) { string val = Request.Params["_" + col.Code]; if (!string.IsNullOrEmpty(val) && val.ToLower() == "on") { m_BaseObject.SetColValue(col, true); } else { m_BaseObject.SetColValue(col, false); } } else if (col.ColType == ColumnType.datetime_type) { string val = Request.Params["_" + col.Code]; if (!string.IsNullOrEmpty(val)) { m_BaseObject.SetColValue(col, Convert.ToDateTime(val)); } } else { m_BaseObject.SetColValue(col, Request.Params["_" + col.Code]); } bHasVisible = true; } if (!bHasVisible) { //Response.Write("没有可修改字段!"); Response.Write("<script>parent.$.ligerDialog.warn('没有可修改字段!');</script>"); return; } if (!m_BaseObjectMgr.Update(m_BaseObject, true)) { //Response.Write("修改失败!"); Response.Write("<script>parent.$.ligerDialog.warn('修改失败!');</script>"); return; } //在iframe里访问外面,需要parent.parent. //Response.Write("<script>parent.parent.grid.loadData(true);parent.parent.$.ligerDialog.close();</script>"); Response.Write("<script>parent.parent.onOkEdit();</script>"); }