Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"] == null)
        {
            Response.End();
        }
        m_User = (CUser)Session["User"];

        string vid = Request["vid"];

        if (string.IsNullOrEmpty(vid))
        {
            Response.End();
        }
        m_View = (CView)Global.GetCtx(Session["TopCompany"].ToString()).ViewMgr.Find(new Guid(vid));
        if (m_View == null)
        {
            Response.End();
        }
        m_Table = (CTable)Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.Find(m_View.FW_Table_id);

        //检查权限
        if (!CheckAccess())
        {
            Response.End();
        }

        string ParentId = Request["ParentId"];

        if (!string.IsNullOrEmpty(ParentId))
        {
            m_guidParentId = new Guid(ParentId);
        }

        if (Session["AddMasterDetailViewRecord"] == null)
        {
            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 obj = BaseObjectMgr.CreateBaseObject();
            obj.Ctx    = Global.GetCtx(Session["TopCompany"].ToString());
            obj.TbCode = m_Table.Code;
            CUser user = (CUser)Session["User"];
            obj.Creator = user.Id;
            Session["AddMasterDetailViewRecord"] = obj;
        }

        if (!IsPostBack)
        {
            recordCtrl.m_View  = m_View;
            recordCtrl.m_Table = m_Table;
            recordCtrl.m_sortRestrictColumnAccessType = m_sortRestrictColumnAccessType;
            if (!string.IsNullOrEmpty(Request["UIColCount"]))
            {
                recordCtrl.m_iUIColCount = Convert.ToInt32(Request["UIColCount"]);
            }
            //外面传递的默认值
            foreach (CColumn col in m_Table.ColumnMgr.GetList())
            {
                if (!string.IsNullOrEmpty(Request[col.Code]))
                {
                    recordCtrl.m_sortDefVal.Add(col.Code, Request[col.Code]);
                }
            }
            //隐藏字段
            string sHideCols = Request["HideCols"];
            if (!string.IsNullOrEmpty(sHideCols))
            {
                string[] arr = sHideCols.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string code in arr)
                {
                    recordCtrl.m_sortHideColumn.Add(code, code);
                }
            }
        }
        if (Request.Params["Action"] == "Cancel")
        {
            Session["AddMasterDetailViewRecord"] = null;
            Response.End();
        }
        else if (Request.Params["Action"] == "GetDetail")
        {
            GetDetail();
            Response.End();
        }
        else if (Request.Params["Action"] == "PostData")
        {
            PostData();
            Response.End();
        }
    }
        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);
        }
    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 = BaseObjectMgr.CreateBaseObject();

        BaseObject.Ctx    = BaseObjectMgr.Ctx;
        BaseObject.TbCode = BaseObjectMgr.TbCode;

        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;
        }
        //在iframe里访问外面,需要parent.parent.
        //Response.Write("<script>parent.parent.grid.loadData(true);parent.parent.$.ligerDialog.close();</script>");
        Response.Write("<script>parent.parent.onOkAddSingleViewRecord();</script>");
    }
        void LoadUI()
        {
            if (View == null)
            {
                return;
            }
            if (BaseObjectMgr == null)
            {
                return;
            }

            m_sortRestrictColumnAccessType = Program.User.GetRestrictColumnAccessTypeList(BaseObjectMgr.Table);

            if (BaseObject == null) //新建
            {
                BaseObject        = BaseObjectMgr.CreateBaseObject();
                BaseObject.Ctx    = BaseObjectMgr.Ctx;
                BaseObject.TbCode = BaseObjectMgr.TbCode;
                m_bIsNew          = true;
            }

            this.Controls.Clear();
            List <CBaseObject> lstCIV = View.ColumnInViewMgr.GetList();
            int nTop = 5;

            foreach (CBaseObject obj in lstCIV)
            {
                CColumnInView civ = (CColumnInView)obj;
                CColumn       col = (CColumn)BaseObjectMgr.Table.ColumnMgr.Find(civ.FW_Column_id);
                if (col == null)
                {
                    continue;
                }
                //判断禁止权限字段
                bool bReadOnly = false;
                if (m_sortRestrictColumnAccessType.ContainsKey(col.Id))
                {
                    AccessType accessType = m_sortRestrictColumnAccessType[col.Id];
                    if (accessType == AccessType.forbide)
                    {
                        continue;
                    }
                    else if (accessType == AccessType.read)
                    {
                        bReadOnly = true;
                    }
                }
                //

                Control ctrl = ColumnMapControl(col);
                if (ctrl != null)
                {
                    ctrl.Name = col.Code;
                    ctrl.Left = 10;
                    ctrl.Top  = nTop;
                    //ctrl.Width = lbCaption.Width;
                    //ctrl.Height = lbCaption.Height;
                    this.Controls.Add(ctrl);
                    //只读权限
                    if (bReadOnly)
                    {
                        ctrl.Enabled = false;
                    }
                }
                nTop = ctrl.Bottom + 5;
            }

            //具有默认值的字段
            List <CBaseObject> lstObj = View.ColumnDefaultValInViewMgr.GetList();

            foreach (CBaseObject obj in lstObj)
            {
                CColumnDefaultValInView cdviv = (CColumnDefaultValInView)obj;
                CColumn col = (CColumn)baseObjectMgr.Table.ColumnMgr.Find(cdviv.FW_Column_id);
                if (col == null)
                {
                    continue;
                }
                if (View.ColumnInViewMgr.FindByColumn(col.Id) != null) //在视图列中
                {
                    Control[] ctrls = this.Controls.Find(col.Code, true);
                    if (ctrls.Length > 0)
                    {
                        if (m_bIsNew) //新建
                        {
                            ((IColumnCtrl)ctrls[0]).SetValue(GetColumnDefaultVal(cdviv));
                        }
                        if (cdviv.ReadOnly)
                        {
                            ctrls[0].Enabled = false;
                        }
                    }
                }
                else  //不在视图列中
                {
                    Control ctrl = ColumnMapControl(col);
                    if (ctrl != null)
                    {
                        ctrl.Name = col.Code;
                        if (m_bIsNew) //新建
                        {
                            ((IColumnCtrl)ctrl).SetValue(GetColumnDefaultVal(cdviv));
                        }
                        ctrl.Visible = false; //作为隐藏字段
                        this.Controls.Add(ctrl);
                    }
                }
            }
            //
            //明细
            CViewDetail    vd  = (CViewDetail)View.ViewDetailMgr.GetFirstObj();
            ViewDetailGrid vdg = new ViewDetailGrid();

            vdg.ViewDetail = vd;
            CTable tb = (CTable)Program.Ctx.TableMgr.Find(vd.FW_Table_id);

            if (tb != null)
            {
                CBaseObjectMgr objMgr = BaseObject.GetSubObjectMgr(tb.Code, typeof(CBaseObjectMgr));
                vdg.BaseObjectMgr = objMgr;
            }
            vdg.ShowTitleBar    = false;
            vdg.m_bShowWorkflow = false;
            vdg.Left            = 10;
            vdg.Top             = nTop;
            vdg.Width           = this.Width - 20;
            vdg.Height          = 300;
            this.Controls.Add(vdg);

            nTop        = vdg.Bottom + 5;
            this.Height = nTop;
        }
Esempio n. 5
0
        void LoadUI()
        {
            if (BaseObjectMgr == null)
            {
                return;
            }
            m_sortRestrictColumnAccessType = Program.User.GetRestrictColumnAccessTypeList(BaseObjectMgr.Table);

            if (BaseObject == null) //新建
            {
                BaseObject        = BaseObjectMgr.CreateBaseObject();
                BaseObject.Ctx    = BaseObjectMgr.Ctx;
                BaseObject.TbCode = BaseObjectMgr.TbCode;
                m_bIsNew          = true;
            }

            List <CBaseObject> lstCol = BaseObjectMgr.Table.ColumnMgr.GetList();
            int nTop = 5;

            foreach (CBaseObject obj in lstCol)
            {
                CColumn col = (CColumn)obj;
                //判断禁止权限字段
                bool bReadOnly = false;
                if (m_sortRestrictColumnAccessType.ContainsKey(col.Id))
                {
                    AccessType accessType = m_sortRestrictColumnAccessType[col.Id];
                    if (accessType == AccessType.forbide)
                    {
                        continue;
                    }
                    else if (accessType == AccessType.read)
                    {
                        bReadOnly = true;
                    }
                }
                //

                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))
                {
                    continue;
                }
                else if (col.Code.Equals("Updator", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                //if (!col.IsVisible)
                //    continue;

                if (m_sortNotShowCol.ContainsKey(col.Code.ToLower()))
                {
                    continue;
                }

                Control ctrl = ColumnMapControl(col);
                if (ctrl != null)
                {
                    ctrl.Name = col.Code;
                    ctrl.Left = 10;
                    ctrl.Top  = nTop;
                    //ctrl.Width = lbCaption.Width;
                    //ctrl.Height = lbCaption.Height;
                    this.Controls.Add(ctrl);
                    //只读权限
                    if (bReadOnly)
                    {
                        ctrl.Enabled = false;
                    }

                    if (m_sortDisableCol.ContainsKey(col.Code.ToLower()))
                    {
                        ctrl.Enabled = false;
                    }
                }
                nTop = ctrl.Bottom + 5;
            }
            this.Height = nTop;
        }