Esempio n. 1
0
    protected void btnok_Click(object sender, EventArgs e)
    {
        var js = "alert('操作失败!');";
        var manage = new T_ManagerInfo();
        manage.M_Type = Util.querySQL(dpManagerType.Text.Trim());
        manage.M_Time = DateTime.Now; //Convert.ToDateTime(Util.querySQL(txt_PressDate.Text.ToString()));
        manage.M_Content = Util.querySQL(txtContent.Text.Trim());
        manage.M_Chief = LoginUser.Instance.UserID; // Util.querySQL(txtFzr.Text.ToString().Trim());

        if (Encoding.Default.GetByteCount(txtContent.Text.Trim()) > 4000)
        {
            js = "alert('请输入少于4000个字符!');";
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "", js, true);
            return;
        }
        //新增
        var result = BLLFactory<T_ManagerInfoManager>.Instance.Insert2(manage);
        if (result > 0)
        {
            ///附件
            if (InputFile1.HasFile)
            {
                var FileName = InputFile1.FileName; //获取上传文件的文件名,包括后缀
                var ExtenName = Path.GetExtension(FileName); //获取扩展名
                var filePath = HttpContext.Current.Request.MapPath("~/UpLoadFiles/");
                var fileName = FileName.Substring(0, FileName.IndexOf('.')) + "_" + DateTime.Now.ToString("yyyyMMddhhmm") + ExtenName;
                var fileURL = Path.Combine(filePath, fileName);
                var fileURL2 = "~/UpLoadFiles/" + fileName; //Path.Combine(filePath, fileName);

                // 上传文件。
                InputFile1.MoveTo(fileURL, MoveToOptions.Overwrite);
                //更改文件数量
                manage.M_Attch = manage.M_Attch + 1;
                //保存 文件路径
                var acc = new T_SystemAccessorie();
                acc.ColName = "M_Attch";
                //  int id = BLLFactory<T_ManagerInfoManager>.Instance.FindLast().M_Id + 1;
                acc.DataID = result;
                acc.TableName = "T_Manage";
                acc.FileName = FileName;
                acc.FilePath = fileURL2;
                BLLFactory<T_SystemAccessorieManager>.Instance.Insert(acc); //插入数据库
            }
            js = "alert('新增成功!');window.opener.select();window.close();";
        }
        //if (BLLFactory<T_ManagerInfoManager>.Instance.Insert(manage))
        //{

        //}

        Page.ClientScript.RegisterClientScriptBlock(GetType(), "", js, true);
    }
Esempio n. 2
0
    public EnumMultiFile Upload(MultiFile multifile, Multi multi)
    {
        filescount = 0;
        tempfiles = new List<T_SystemAccessorie>();

        #region

        foreach (var item in multifile.Files)
        {
            // 上传文件。
            try
            {
                var FileName = item.FileName; //获取上传文件的文件名,包括后缀
                var ExtenName = Path.GetExtension(FileName); //获取扩展名
                var filePath = HttpContext.Current.Request.MapPath("~/UpLoadFiles/" + multi.PathFile + "");

                if (ExtenName != ".pdf")
                {
                    return EnumMultiFile.alert;
                }

                var fileName = FileName.Substring(0, FileName.IndexOf('.')) + "_" + DateTime.Now.ToString("yyyyMMddhhmm") + ExtenName;
                var fileURL = Path.Combine(filePath, fileName);

                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                item.SaveAs(fileURL);
                filescount++;
                var tempfile = new T_SystemAccessorie
                {
                    FileName = fileName,
                    FilePath = fileURL,
                    TableName = multi.TableName,
                    ColName = multi.ColName,
                    DataID = multi.NewID
                };
                tempfiles.Add(tempfile);
            }
            catch (Exception)
            {
                //   Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('上传文件失败!');", true);
                return EnumMultiFile.Ex;
            }
        }
        Add(tempfiles);
        return EnumMultiFile.Ok;

        #endregion
    }