void Delete()
    {
        string delid = Request["delid"];

        if (string.IsNullOrEmpty(delid))
        {
            Response.Write("请选择记录!");
            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());
            string sWhere = string.Format(" id='{0}'", delid);
            BaseObjectMgr.GetList(sWhere);
        }
        if (!BaseObjectMgr.Delete(new Guid(delid)))
        {
            Response.Write(BaseObjectMgr.Ctx.LastError);
            return;
        }
        if (!BaseObjectMgr.Save(true))
        {
            Response.Write("删除失败!");
            return;
        }
    }
Example #2
0
    void Delete()
    {
        string ids = Request["ids"];

        if (string.IsNullOrEmpty(ids))
        {
            Response.Write("请选择行!");
            return;
        }
        if (m_ViewAccessType != AccessType.write)
        {
            Response.Write("没有写权限!");
            return;
        }
        if (m_TableAccessType != AccessType.write)
        {
            Response.Write("没有写权限!");
            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());
            string sWhere = string.Format(" id in ('{0}')", ids.TrimEnd(",".ToCharArray()));
            BaseObjectMgr.GetList(sWhere);
        }
        string[] arr = ids.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
        foreach (string sId in arr)
        {
            if (!BaseObjectMgr.Delete(new Guid(sId)))
            {
                Response.Write(BaseObjectMgr.Ctx.LastError);
                return;
            }
        }

        if (!BaseObjectMgr.Save(true))
        {
            Response.Write("删除失败!");
            return;
        }
    }
Example #3
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);
        }