public bool Save()
        {
            if (!Validate())
            {
                return(false);
            }

            if (baseObject == null) //新建
            {
                baseObject        = BaseObjectMgr.CreateBaseObject();
                baseObject.Ctx    = BaseObjectMgr.Ctx;
                baseObject.TbCode = BaseObjectMgr.TbCode;
                bool bHasVisible = false;
                foreach (CBaseObject obj in ViewDetail.ColumnInViewDetailMgr.GetList())
                {
                    CColumnInViewDetail civd = (CColumnInViewDetail)obj;
                    CColumn             col  = (CColumn)BaseObjectMgr.Table.ColumnMgr.Find(civd.FW_Column_id);
                    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))
                    {
                        continue;
                    }
                    else if (col.Code.Equals("Creator", StringComparison.OrdinalIgnoreCase))
                    {
                        baseObject.SetColValue(col, Program.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;
                    }


                    Control[] ctrls = this.Controls.Find(col.Code, false);
                    if (ctrls.Length > 0)
                    {
                        IColumnCtrl ctrl = (IColumnCtrl)ctrls[0];
                        baseObject.SetColValue(col, ctrl.GetValue());
                        bHasVisible = true;
                    }
                }
                //外键关联
                CBaseObject objP = BaseObjectMgr.m_Parent;
                CColumn     colP = (CColumn)objP.Table.ColumnMgr.Find(viewDetail.PrimaryKey);
                CColumn     colF = (CColumn)BaseObjectMgr.Table.ColumnMgr.Find(viewDetail.ForeignKey);
                BaseObject.SetColValue(colF, objP.GetColValue(colP));

                if (!bHasVisible)
                {
                    MessageBox.Show("没有可修改字段!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return(false);
                }
                if (!BaseObjectMgr.AddNew(baseObject, true))
                {
                    MessageBox.Show("添加失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return(false);
                }
            }
            else //修改
            {
                List <CBaseObject> lstCol = BaseObjectMgr.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))
                    {
                        continue;
                    }
                    else if (col.Code.Equals("Updated", StringComparison.OrdinalIgnoreCase))
                    {
                        baseObject.SetColValue(col, DateTime.Now);
                        continue;
                    }
                    else if (col.Code.Equals("Updator", StringComparison.OrdinalIgnoreCase))
                    {
                        baseObject.SetColValue(col, Program.User.Id);
                        continue;
                    }


                    Control[] ctrls = this.Controls.Find(col.Code, false);
                    if (ctrls.Length > 0)
                    {
                        IColumnCtrl ctrl = (IColumnCtrl)ctrls[0];
                        baseObject.SetColValue(col, ctrl.GetValue());
                        bHasVisible = true;
                    }
                }
                if (!bHasVisible)
                {
                    MessageBox.Show("没有可修改字段!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return(false);
                }
                if (!BaseObjectMgr.Update(baseObject, true))
                {
                    MessageBox.Show("修改失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
    void PostData()
    {
        if (!ValidateData())
        {
            return;
        }

        CBaseObjectMgr BaseObjectMgr = Global.GetCtx(Session["TopCompany"].ToString()).FindBaseObjectMgrCache(m_Table.Code, m_guidParentId);

        if (BaseObjectMgr == null)
        {
            BaseObjectMgr        = new CBaseObjectMgr();
            BaseObjectMgr.TbCode = m_Table.Code;
            BaseObjectMgr.Ctx    = Global.GetCtx(Session["TopCompany"].ToString());
        }

        CBaseObject BaseObject  = (CBaseObject)Session["AddMasterDetailViewRecord"];
        bool        bHasVisible = false;

        //foreach (CBaseObject objCIV in m_View.ColumnInViewMgr.GetList())
        foreach (CBaseObject objCol in m_Table.ColumnMgr.GetList())
        {
            //CColumnInView civ = (CColumnInView)objCIV;

            //CColumn col = (CColumn)m_Table.ColumnMgr.Find(civ.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;
        }
        BaseObjectMgr.AddNew(BaseObject);
        if (!BaseObjectMgr.Save(true))
        {
            //Response.Write("添加失败!");
            Response.Write("<script>alert('添加失败!');</script>");
            return;
        }
        Session["AddMasterDetailViewRecord"] = null;
        //在iframe里访问外面,需要parent.parent.
        //Response.Write("<script>parent.parent.grid.loadData(true);parent.parent.$.ligerDialog.close();</script>");
        Response.Write("<script>parent.parent.onOkAddMasterDetailViewRecord();</script>");
    }
        public bool Save()
        {
            if (!Validate())
            {
                return(false);
            }

            List <CBaseObject> lstCol = BaseObjectMgr.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))
                {
                    continue;
                }
                else if (col.Code.Equals("Updated", StringComparison.OrdinalIgnoreCase))
                {
                    BaseObject.SetColValue(col, DateTime.Now);
                    continue;
                }
                else if (col.Code.Equals("Updator", StringComparison.OrdinalIgnoreCase))
                {
                    BaseObject.SetColValue(col, Program.User.Id);
                    continue;
                }


                Control[] ctrls = this.Controls.Find(col.Code, false);
                if (ctrls.Length > 0)
                {
                    IColumnCtrl ctrl = (IColumnCtrl)ctrls[0];
                    BaseObject.SetColValue(col, ctrl.GetValue());
                    bHasVisible = true;
                }
            }
            if (!bHasVisible)
            {
                MessageBox.Show("没有可修改字段!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return(false);
            }
            if (m_bIsNew)
            {
                BaseObjectMgr.AddNew(BaseObject);
            }
            else
            {
                BaseObjectMgr.Update(BaseObject);
            }
            if (!BaseObjectMgr.Save())
            {
                MessageBox.Show("修改失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return(false);
            }
            return(true);
        }