Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 清除缓存;
        this.Response.Expires         = -1;
        this.Response.ExpiresAbsolute = DateTime.Now.AddMonths(-1);
        this.Response.CacheControl    = "no-cache";
        #endregion 清除缓存

        try
        {
            #region 判断权限
            string pk = this.Request.QueryString["PK"];
            if (pk == null)
            {
                pk = this.Request.QueryString[this.CurrEn.PK];
            }

            UAC uac = this.CurrEn.HisUAC;
            if (uac.IsView == false)
            {
                throw new Exception("@对不起,您没有查看的权限!");
            }

            this.IsReadonly = !uac.IsUpdate;  //是否更有修改的权限.
            if (this.Request.QueryString["IsReadonly"] == "1" ||
                this.Request.QueryString["Readonly"] == "1")
            {
                this.IsReadonly = true;
            }
            #endregion

            this.ToolBar1.Add("  ");
            this.ToolBar1.InitFuncEn(uac, this.CurrEn);

            this.UCEn1.IsReadonly = this.IsReadonly;
            this.UCEn1.IsShowDtl  = true;
            this.UCEn1.HisEn      = this.CurrEn;
            this.UCEn1.Bind(this.CurrEn, this.CurrEn.ToString(), this.IsReadonly, true);
        }
        catch (Exception ex)
        {
            this.Response.Write(ex.Message);
            Entity en = ClassFactory.GetEns(this.EnsName).GetNewEntity;
            en.CheckPhysicsTable();
            return;
        }

        this.Page.Title = this.CurrEn.EnDesc;

        #region 设置事件
        if (this.Btn_DelFile != null)
        {
            this.Btn_DelFile.Click += new ImageClickEventHandler(Btn_DelFile_Click);
        }

        if (this.ToolBar1.IsExit(NamesOfBtn.New))
        {
            this.ToolBar1.GetBtnByID(NamesOfBtn.New).Click += new System.EventHandler(this.ToolBar1_ButtonClick);
        }

        if (this.ToolBar1.IsExit(NamesOfBtn.Save))
        {
            this.ToolBar1.GetBtnByID(NamesOfBtn.Save).Click += new System.EventHandler(this.ToolBar1_ButtonClick);
        }

        if (this.ToolBar1.IsExit(NamesOfBtn.SaveAndClose))
        {
            this.ToolBar1.GetBtnByID(NamesOfBtn.SaveAndClose).Click += new System.EventHandler(this.ToolBar1_ButtonClick);
        }

        if (this.ToolBar1.IsExit(NamesOfBtn.SaveAndNew))
        {
            this.ToolBar1.GetBtnByID(NamesOfBtn.SaveAndNew).Click += new System.EventHandler(this.ToolBar1_ButtonClick);
        }

        if (this.ToolBar1.IsExit(NamesOfBtn.Delete))
        {
            this.ToolBar1.GetBtnByID(NamesOfBtn.Delete).Click += new System.EventHandler(this.ToolBar1_ButtonClick);
        }

        AttrFiles fls = this.CurrEn.EnMap.HisAttrFiles;
        foreach (AttrFile fl in fls)
        {
            if (this.UCEn1.IsExit("Btn_DelFile" + fl.FileNo))
            {
                this.UCEn1.GetImageButtonByID("Btn_DelFile" + fl.FileNo).Click += new ImageClickEventHandler(Btn_DelFile_X_Click);
            }
        }
        #endregion 设置事件
    }
Esempio n. 2
0
    public void Save()
    {
        Entity en = this.GetEns.GetNewEntity;

        if (this.PKVal != null)
        {
            en.PKVal = this.PKVal;
            en.RetrieveFromDBSources();
        }

        en = this.UCEn1.GetEnData(en);

        this.CurrEn = en;
        en.Save();
        this.PKVal = en.PKVal;

        #region 保存 实体附件
        try
        {
            if (en.EnMap.Attrs.Contains("MyFileName"))
            {
                HtmlInputFile file = this.UCEn1.FindControl("file") as HtmlInputFile;
                if (file != null && file.Value.IndexOf(".") != -1)
                {
                    BP.Sys.EnCfg cfg = new EnCfg(en.ToString());
                    if (System.IO.Directory.Exists(cfg.FJSavePath) == false)
                    {
                        System.IO.Directory.CreateDirectory(cfg.FJSavePath);
                    }

                    /* 如果包含这二个字段。*/
                    string fileName = file.PostedFile.FileName;
                    fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);

                    string filePath = cfg.FJSavePath;
                    en.SetValByKey("MyFilePath", filePath);

                    string ext = "";
                    if (fileName.IndexOf(".") != -1)
                    {
                        ext = fileName.Substring(fileName.LastIndexOf(".") + 1);
                    }

                    en.SetValByKey("MyFileExt", ext);
                    en.SetValByKey("MyFileName", fileName);
                    en.SetValByKey("WebPath", cfg.FJWebPath + en.PKVal + "." + ext);

                    string fullFile = filePath + "/" + en.PKVal + "." + ext;

                    file.PostedFile.SaveAs(fullFile);
                    file.PostedFile.InputStream.Close();
                    file.PostedFile.InputStream.Dispose();
                    file.Dispose();

                    System.IO.FileInfo info = new System.IO.FileInfo(fullFile);
                    en.SetValByKey("MyFileSize", BP.DA.DataType.PraseToMB(info.Length));
                    if (DataType.IsImgExt(ext))
                    {
                        System.Drawing.Image img = System.Drawing.Image.FromFile(fullFile);
                        en.SetValByKey("MyFileH", img.Height);
                        en.SetValByKey("MyFileW", img.Width);
                        img.Dispose();
                    }
                    en.Update();
                }
            }
        }
        catch (Exception ex)
        {
            this.Alert("保存附件出现错误:" + ex.Message);
        }
        #endregion


        #region 保存 属性 附件
        try
        {
            AttrFiles       fils = en.EnMap.HisAttrFiles;
            SysFileManagers sfs  = new SysFileManagers(en.ToString(), en.PKVal.ToString());
            foreach (AttrFile fl in fils)
            {
                HtmlInputFile file = (HtmlInputFile)this.UCEn1.FindControl("F" + fl.FileNo);
                if (file.Value.Contains(".") == false)
                {
                    continue;
                }

                SysFileManager enFile = sfs.GetEntityByKey(SysFileManagerAttr.AttrFileNo, fl.FileNo) as SysFileManager;
                SysFileManager enN    = null;
                if (enFile == null)
                {
                    enN = this.FileSave(null, file, en);
                }
                else
                {
                    enFile.Delete();
                    enN = this.FileSave(null, file, en);
                }

                enN.AttrFileNo   = fl.FileNo;
                enN.AttrFileName = fl.FileName;
                enN.EnName       = en.ToString();
                enN.Update();
            }
        }
        catch (Exception ex)
        {
            this.Alert("保存附件出现错误:" + ex.Message);
        }
        #endregion
    }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 清除缓存;
        this.Response.Expires         = -1;
        this.Response.ExpiresAbsolute = DateTime.Now.AddMonths(-1);
        this.Response.CacheControl    = "no-cache";
        #endregion 清除缓存

        try
        {
            #region 判断权限
            string pk = this.Request.QueryString["PK"];
            if (pk == null)
            {
                pk = this.Request.QueryString[this.CurrEn.PK];
            }

            UAC uac = this.CurrEn.HisUAC;
            if (uac.IsView == false)
            {
                throw new Exception("@对不起,您没有查看的权限!");
            }

            this.IsReadonly = !uac.IsUpdate;  //是否更有修改的权限.
            if (this.Request.QueryString["IsReadonly"] == "1" ||
                this.Request.QueryString["Readonly"] == "1")
            {
                this.IsReadonly = true;
            }
            #endregion

            this.ToolBar1.InitFuncEn(uac, this.CurrEn);

            this.UCEn1.IsReadonly = this.IsReadonly;
            this.UCEn1.IsShowDtl  = true;
            this.UCEn1.HisEn      = this.CurrEn;

            EnCfg ec = new EnCfg();
            ec.No = this.EnName;
            int i = ec.RetrieveFromDBSources();

            if (i >= 1)
            {
                this.UCEn1.BindV2(this.CurrEn, this.CurrEn.ToString(), this.IsReadonly, true);
            }
            else
            {
                this.UCEn1.Bind(this.CurrEn, this.CurrEn.ToString(), this.IsReadonly, true);
            }
        }
        catch (Exception ex)
        {
            this.Response.Write(ex.Message);
            Entity en = ClassFactory.GetEns(this.EnsName).GetNewEntity;
            en.CheckPhysicsTable();
            return;
        }

        this.Page.Title = this.CurrEn.EnDesc;

        #region 设置事件
        if (this.Btn_DelFile != null)
        {
            this.Btn_DelFile.Click += new ImageClickEventHandler(Btn_DelFile_Click);
        }

        if (this.ToolBar1.IsExit(NamesOfBtn.New))
        {
            this.ToolBar1.GetLinkBtnByID(NamesOfBtn.New).Click += new System.EventHandler(this.ToolBar1_ButtonClick);
        }

        if (this.ToolBar1.IsExit(NamesOfBtn.Save))
        {
            this.ToolBar1.GetLinkBtnByID(NamesOfBtn.Save).Click += new System.EventHandler(this.ToolBar1_ButtonClick);
        }

        if (this.ToolBar1.IsExit(NamesOfBtn.SaveAndClose))
        {
            this.ToolBar1.GetLinkBtnByID(NamesOfBtn.SaveAndClose).Click += new System.EventHandler(this.ToolBar1_ButtonClick);
        }

        if (this.ToolBar1.IsExit(NamesOfBtn.SaveAndNew))
        {
            this.ToolBar1.GetLinkBtnByID(NamesOfBtn.SaveAndNew).Click += new System.EventHandler(this.ToolBar1_ButtonClick);
        }

        if (this.ToolBar1.IsExit(NamesOfBtn.Delete))
        {
            this.ToolBar1.GetLinkBtnByID(NamesOfBtn.Delete).Click += new System.EventHandler(this.ToolBar1_ButtonClick);
        }

        AttrFiles fls = this.CurrEn.EnMap.HisAttrFiles;
        foreach (AttrFile fl in fls)
        {
            if (this.UCEn1.IsExit("Btn_DelFile" + fl.FileNo))
            {
                this.UCEn1.GetImageButtonByID("Btn_DelFile" + fl.FileNo).Click += new ImageClickEventHandler(Btn_DelFile_X_Click);
            }
        }
        #endregion 设置事件

        //此处增加一个判断删除成功的逻辑,办法不太好,暂用,added by liuxc,2015-11-10
        if (!IsPostBack)
        {
            if (Request["DeleteOver"] == "1")
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "showmsg", "alert('删除成功!');", true);
            }
        }
    }