コード例 #1
0
    protected void SelectImage(object sender, EventArgs e)
    {
        bt_DeleteImage.Enabled = (ImageList.Items.Count != 0);
        bt_ResizeImage.Enabled = (ImageList.Items.Count != 0);
        ResizeWidth.Enabled    = (ImageList.Items.Count != 0);
        ResizeHeight.Enabled   = (ImageList.Items.Count != 0);

        if (ImageList.Items.Count == 0)
        {
            Image1.ImageUrl   = "";
            ResizeWidth.Text  = "";
            ResizeHeight.Text = "";
            return;
        }

        Image1.ImageUrl = string.Format(AttachmentDownloadURL, ImageList.SelectedValue);
        ATMT_AttachmentBLL att = new ATMT_AttachmentBLL(new Guid(ImageList.SelectedValue));

        if (att.Model != null && att.GetData() != null)
        {
            ImageMedia img = ImageMedia.Create(att.GetData());
            ResizeWidth.Text       = img.Width.ToString();
            ResizeHeight.Text      = img.Height.ToString();
            ImageAspectRatio.Value = "" + img.Width / (float)img.Height;

            int pos = ImageList.SelectedItem.Text.LastIndexOf('.');
            if (pos == -1)
            {
                return;
            }

            bt_OkButton.OnClientClick = "window.top.opener.CKEDITOR.dialog.getCurrent().setValueOf('info', 'txtUrl', encodeURI('" + Page.ResolveUrl(Image1.ImageUrl) + "')); window.top.close(); window.top.opener.focus();";
        }
    }
コード例 #2
0
    /// <summary>
    /// 显示缩略图
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    protected string PreViewImagePath(int id)
    {
        ATMT_Attachment m = new ATMT_AttachmentBLL(id).Model;

        if (m == null)
        {
            return("");
        }

        if (IsImage(m.ExtName))
        {
            return("~/SubModule/DownloadAttachment.aspx?GUID=" + m.GUID.ToString() + "&PreViewImage=Y");
        }
        else
        {
            string filename = "~/Images/icon/" + m.ExtName + ".png";
            if (System.IO.File.Exists(Server.MapPath(filename)))
            {
                return(filename);
            }
            else
            {
                return("~/Images/icon/other.png");
            }
        }
    }
コード例 #3
0
    protected void Upload(object sender, EventArgs e)
    {
        string filename = bt_UploadedImageFile.FileName;

        byte[] data = bt_UploadedImageFile.FileBytes;

        #region 写入新附件
        ATMT_AttachmentBLL atm = new ATMT_AttachmentBLL();

        atm.Model.RelateType = 75;
        atm.Model.Name       = filename;
        atm.Model.ExtName    = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();
        atm.Model.FileSize   = data.Length / 1024;
        atm.Model.UploadUser = Session["UserName"].ToString();
        atm.Model.IsDelete   = "N";
        int atm_id = atm.Add(data);
        if (atm_id > 0)
        {
            ddl_DirectoryList.SelectedIndex = 0;
            BindImageList();

            ImageList.SelectedValue = new ATMT_AttachmentBLL(atm_id).Model.GUID.ToString();
            SelectImage(null, null);
        }
        #endregion
    }
コード例 #4
0
ファイル: Notice.cs プロジェクト: wangmin119/GraduateProject
        private void FillModel(PN_Notice m)
        {
            if (m == null)
            {
                return;
            }

            ID         = m.ID;
            Topic      = m.Topic;
            KeyWord    = m.KeyWord;
            Content    = m.Content.Replace("/RMS/SubModule/DownloadAttachment.aspx?", MCSFramework.Common.ConfigHelper.GetConfigString("WebSiteURL") + "/DownloadAttachment.aspx?");
            CanComment = m.CanComment.ToUpper() == "Y";
            InsertTime = m.InsertTime;

            Abstract = m["Abstract"];
            if (Abstract == "")
            {
                if (Content.Length > 100)
                {
                    Abstract = Content.Substring(0, 100);
                }
                else
                {
                    Abstract = Content;
                }
            }

            Author = m["Author"];

            #region 替换描述中的图片链接
            Content = Content.Replace("src=\"/Admin/DownloadAttachment.aspx", "src=\"" + ConfigHelper.GetConfigString("WebSiteURL") + "DownloadAttachment.aspx");
            Content = Content.Replace("src=\"/MClub/DownloadAttachment.aspx", "src=\"" + ConfigHelper.GetConfigString("WebSiteURL") + "DownloadAttachment.aspx");
            #endregion

            #region 获取首要图片
            string condition = " RelateType=80 AND RelateID=" + m.ID.ToString() + " AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',1)='Y'";
            IList <ATMT_Attachment> lists = ATMT_AttachmentBLL.GetModelList(condition);
            if (lists.Count > 0 && ATMT_AttachmentBLL.IsImage(lists[0].ExtName))
            {
                ImageGUID = lists[0].GUID;
            }
            #endregion

            #region 获取附件明细
            Atts = new List <Attachment>();
            IList <ATMT_Attachment> atts = ATMT_AttachmentBLL.GetAttachmentList(80, m.ID, new DateTime(1900, 1, 1), new DateTime(2100, 1, 1));
            foreach (ATMT_Attachment att in atts.OrderBy(p => p.Name))
            {
                Attachment v = new Attachment();
                v.AttName    = att.Name;
                v.ExtName    = att.ExtName;
                v.GUID       = att.GUID;
                v.UploadTime = att.UploadTime;
                v.FileSize   = att.FileSize;
                Atts.Add(v);
            }
            #endregion
        }
コード例 #5
0
    protected void BindDirectoryList()
    {
        List <DateTime> lists = ATMT_AttachmentBLL.GetCKEditUploadDate(Session["UserName"].ToString(), false);

        foreach (DateTime date in lists.OrderByDescending(p => p))
        {
            ddl_DirectoryList.Items.Add(date.ToString("yyyy-MM-dd"));
        }
    }
コード例 #6
0
    /// <summary>
    /// 将文件存放至指定目录
    /// </summary>
    /// <param name="downloadDir">文件指定存放目录</param>
    /// <param name="AttGUID">图片GUID编码</param>
    public void SaveImgToDisk(string downloadDir, Guid AttGUID)
    {
        ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(AttGUID);

        if (bll.Model == null || !ATMT_AttachmentBLL.IsImage(bll.Model.ExtName))
        {
            MessageBox.Show(this, "文件不存在或无文件类型" + AttGUID.ToString());
            return;
        }

        //创建文件名
        CM_Client client   = new CM_ClientBLL(bll.Model.RelateID).Model;
        string    fileName = client.FullName + "_" + client.Code + "_" + bll.Model.Name + "_" + bll.Model.UploadTime.ToString("yyyMMddHHmmss") + "." + bll.Model.ExtName;

        #region 替换不能包括的非法字符
        fileName = fileName.Replace("/", "");
        fileName = fileName.Replace("\\", "");
        fileName = fileName.Replace(":", "");
        fileName = fileName.Replace("*", "");
        fileName = fileName.Replace("?", "");
        fileName = fileName.Replace("<", "");
        fileName = fileName.Replace(">", "");
        fileName = fileName.Replace("|", "");
        fileName = fileName.Replace("\"", "");
        #endregion

        try
        {
            //数据库中存在该文件路径则直接从文件目录查找并移动
            if (!string.IsNullOrEmpty(bll.Model.Path))
            {
                string tempPath = bll.Model.Path.StartsWith("~") ? Server.MapPath(bll.Model.Path) : bll.Model.Path.Replace("/", "\\");
                string filename = bll.Model.Name + "." + bll.Model.ExtName;
                if (File.Exists(bll.Model.Path))
                {
                    File.Copy(tempPath, downloadDir + "\\" + fileName);
                    return;
                }
            }
            else//读取二进制流并生成文件
            {
                byte[] data = bll.GetData();
                if (data != null)
                {
                    FileStream fs = File.Create(downloadDir + "\\" + fileName);
                    fs.Write(data, 0, data.Length);
                    fs.Close();
                    return;
                }
            }
        }
        catch { }
    }
コード例 #7
0
    private void Download(string Path, Guid guid)
    {
        ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(guid);

        if (bll.Model == null)
        {
            MessageBox.ShowAndRedirect(this, "指定ID的附件不存在,参数错误!", "desktop.aspx");
            return;
        }

        if (string.IsNullOrEmpty(bll.Model.Path))
        {
            byte[] data = bll.GetData();
            if (data != null)
            {
                FileStream fs = File.Create(Path + "\\" + bll.Model.GUID + "." + bll.Model.ExtName);
                fs.Write(data, 0, data.Length);
                fs.Close();

                SendAttachmentData(data, bll.Model.Name, bll.Model.ExtName);
            }
        }
        else
        {
            string filepath = bll.Model.Path;

            if (filepath.StartsWith("~"))
            {
                filepath = Server.MapPath(filepath);
            }

            if (!File.Exists(filepath))
            {
                MessageBox.ShowAndRedirect(this, "附件在服务器上不存在!", "desktop.aspx");
                return;
            }

            #region 从本地目录中加载图片
            byte[] data = File.ReadAllBytes(filepath);

            string extname = "";
            int    p       = filepath.LastIndexOf('.');
            if (p > 0)
            {
                extname = filepath.Substring(p + 1);
            }

            SendAttachmentData(data, bll.Model.Name, extname);
            #endregion
        }
    }
コード例 #8
0
    protected void ResizeImage(object sender, EventArgs e)
    {
        ATMT_AttachmentBLL att = new ATMT_AttachmentBLL(new Guid(ImageList.SelectedValue));
        int width  = Util.Parse <int>(ResizeWidth.Text);
        int height = Util.Parse <int>(ResizeHeight.Text);

        ImageMedia img = ImageMedia.Create(att.GetData());

        img.Resize(width, height);

        att.UploadFileData(img.ToByteArray());

        ResizeMessage.Text = "Image successfully resized!";
        SelectImage(null, null);
    }
コード例 #9
0
    /// <summary>
    /// 获取符合页面查询条件的附件信息
    /// </summary>
    /// <returns></returns>
    public IList <MCSFramework.Model.Pub.ATMT_Attachment> GetPageCondition()
    {
        DateTime timeBegin = DateTime.Parse(tbx_begin.Text);
        DateTime timeEnd   = DateTime.Parse(tbx_end.Text);

        string condition = " RelateType = 30 AND lower(ExtName) in ('bmp','jpg','gif','png') AND IsDelete!='Y' AND UploadTime BETWEEN '" + timeBegin.ToString("yyyy-MM-dd") + "' AND '" + timeEnd.ToString("yyyy-MM-dd 23:59:59") + "'";

        if (tbx_FindName.Text != "")
        {
            condition += " AND Name like '%" + tbx_FindName.Text + "%'";
        }

        if (select_Client.SelectValue != "")
        {
            condition += " AND RelateID = " + select_Client.SelectValue.ToString();
        }
        else
        {
            if (tr_OrganizeCity.SelectValue == "1" || tr_OrganizeCity.SelectValue == "0")
            {
                condition += @" AND RelateID IN 
                    (SELECT ID FROM MCS_CM.dbo.CM_Client WHERE ActiveFlag=1 AND ApproveFlag=1 AND ClientType=3)";
            }
            else
            {
                Addr_OrganizeCityBLL orgcity = new Addr_OrganizeCityBLL(int.Parse(tr_OrganizeCity.SelectValue));
                string orgcitys = orgcity.GetAllChildNodeIDs();
                if (!string.IsNullOrEmpty(orgcitys))
                {
                    orgcitys += "," + tr_OrganizeCity.SelectValue;
                }
                else
                {
                    orgcitys += tr_OrganizeCity.SelectValue;
                }
                if (orgcitys != "")
                {
                    condition += @" AND RelateID IN 
                (SELECT ID FROM MCS_CM.dbo.CM_Client 
                 WHERE ActiveFlag=1 AND ApproveFlag=1 AND ClientType=3  AND OrganizeCity IN (" + orgcitys + ") )";
                }
            }
        }
        return(ATMT_AttachmentBLL.GetModelList(condition));
    }
コード例 #10
0
    private void Download(string Path, Guid guid)
    {
        ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(guid);
        if (bll.Model == null)
        {
            MessageBox.ShowAndRedirect(this, "指定ID的附件不存在,参数错误!", "desktop.aspx");
            return;
        }

        if (string.IsNullOrEmpty(bll.Model.Path))
        {
            byte[] data = bll.GetData();
            if (data != null)
            {
                FileStream fs = File.Create(Path + "\\" + bll.Model.GUID + "." + bll.Model.ExtName);
                fs.Write(data, 0, data.Length);
                fs.Close();

                SendAttachmentData(data, bll.Model.Name, bll.Model.ExtName);
            }
        }
        else
        {
            string filepath = bll.Model.Path;

            if (filepath.StartsWith("~")) filepath = Server.MapPath(filepath);

            if (!File.Exists(filepath))
            {
                MessageBox.ShowAndRedirect(this, "附件在服务器上不存在!", "desktop.aspx");
                return;
            }

            #region 从本地目录中加载图片
            byte[] data = File.ReadAllBytes(filepath);

            string extname = "";
            int p = filepath.LastIndexOf('.');
            if (p > 0) extname = filepath.Substring(p + 1);

            SendAttachmentData(data, bll.Model.Name, extname);
            #endregion
        }
    }
コード例 #11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(Request.QueryString["GUID"]))
            {
                MessageBox.ShowAndRedirect(this, "下载附件时参数错误1!", "Default.aspx");
                return;
            }

            try
            {
                Guid guid = Request.QueryString["GUID"] == null ? Guid.Empty : new Guid(Request.QueryString["GUID"]);

                ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(guid);
                if (bll.Model == null)
                {
                    MessageBox.ShowAndRedirect(this, "指定ID的附件不存在,参数错误!", "Default.aspx");
                    return;
                }

                string[] atttypes = ConfigHelper.GetConfigString("CanDownlodAttTypeUnLogin").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (!atttypes.Contains(bll.Model.RelateType.ToString()))
                {
                    MessageBox.ShowAndRedirect(this, "对不起,该附件无权下载!", "Default.aspx");
                    return;
                }

                if (string.IsNullOrEmpty(Request.QueryString["PreViewImage"]))
                {
                    Download(bll);
                }
                else
                {
                    DownPreViewImage(bll);
                }
            }
            catch
            {
                MessageBox.ShowAndRedirect(this, "下载附件时参数错误2!", "desktop.aspx");
                return;
            }
        }
    }
コード例 #12
0
    private void BindData()
    {
        ORD_OrderApplyDetail m       = new ORD_OrderApplyBLL().GetDetailModel((int)ViewState["ID"]);
        PDT_Product          product = new PDT_ProductBLL(m.Product).Model;

        lb_Product.Text = product.FullName;

        img_Product.ImageUrl = ATMT_AttachmentBLL.GetFirstPreviewPicture(11, m.Product);
        if (img_Product.ImageUrl == "")
        {
            img_Product.Visible = false;
        }

        lb_Package1.Text = DictionaryBLL.GetDicCollections("PDT_Packaging")[product.TrafficPackaging.ToString()].Name;
        lb_Package2.Text = lb_Package1.Text;

        lb_BookQuantity_T.Text     = (m.BookQuantity / product.ConvertFactor).ToString();
        tbx_ApproveQuantity_T.Text = ((m.BookQuantity + m.AdjustQuantity) / product.ConvertFactor).ToString();
    }
コード例 #13
0
    protected void BindImageList()
    {
        ImageList.Items.Clear();
        DateTime uploaddate = DateTime.Today;

        DateTime.TryParse(ddl_DirectoryList.SelectedItem.Text, out uploaddate);

        IList <ATMT_Attachment> atts = ATMT_AttachmentBLL.GetCKEditAttachmentList(uploaddate, Session["UserName"].ToString(), false);

        foreach (ATMT_Attachment att in atts)
        {
            ImageList.Items.Add(new ListItem(att.Name, att.GUID.ToString()));
        }

        if (atts.Count > 0)
        {
            ImageList.SelectedIndex = 0;
        }
    }
コード例 #14
0
    protected void GridAttachment_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)//判断当前行是否是数据行
        {
            int    rowIndex = (int)e.Row.RowIndex;
            Image  img      = (Image)e.Row.FindControl("img");
            string a        = GridAttachment.DataKeys[rowIndex]["ID"].ToString();
            Guid   imgGUID  = (Guid)GridAttachment.DataKeys[rowIndex]["GUID"];
            img.ImageUrl = "~/SubModule/DownloadAttachment.aspx?GUID=" + imgGUID.ToString() + "&PreViewImage=Y";

            Guid AttGUID                 = (Guid)GridAttachment.DataKeys[rowIndex]["GUID"];
            ATMT_AttachmentBLL bll       = new ATMT_AttachmentBLL(AttGUID);
            CM_ClientBLL       clientBLL = new CM_ClientBLL(bll.Model.RelateID);
            if (clientBLL.Model != null)
            {
                e.Row.Cells[1].Text = clientBLL.Model.FullName;
                e.Row.Cells[2].Text = clientBLL.Model.Code;
            }
        }
    }
コード例 #15
0
    protected void bt_Delete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < lv_list.Items.Count; i++)
        {
            ListViewItem item = lv_list.Items[i];
            if (((CheckBox)item.FindControl("cb_ck")).Checked)
            {
                int id = (int)lv_list.DataKeys[i].Value;

                ATMT_AttachmentBLL att = new ATMT_AttachmentBLL(id);
                try
                {
                    File.Delete(Server.MapPath(att.Model.Path));
                }
                catch { }
                att.Delete();
            }
        }

        lv_list.DataBind();
    }
コード例 #16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(Request.QueryString["GUID"]))
            {
                MessageBox.ShowAndRedirect(this, "下载附件时参数错误1!", "Default.aspx");
                return;
            }

            try
            {
                Guid guid = Request.QueryString["GUID"] == null ? Guid.Empty : new Guid(Request.QueryString["GUID"]);

                ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(guid);
                if (bll.Model == null)
                {
                    MessageBox.ShowAndRedirect(this, "指定ID的附件不存在,参数错误!", "Default.aspx");
                    return;
                }

                string[] atttypes = ConfigHelper.GetConfigString("CanDownlodAttTypeUnLogin").Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
                if (!atttypes.Contains(bll.Model.RelateType.ToString()))
                {
                    MessageBox.ShowAndRedirect(this, "对不起,该附件无权下载!", "Default.aspx");
                    return;
                }

                if (string.IsNullOrEmpty(Request.QueryString["PreViewImage"]))
                    Download(bll);
                else
                    DownPreViewImage(bll);
            }
            catch
            {
                MessageBox.ShowAndRedirect(this, "下载附件时参数错误2!", "desktop.aspx");
                return;
            }
        }
    }
コード例 #17
0
    protected void bt_SetFirstPicture_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < lv_list.Items.Count; i++)
        {
            ListViewItem item = lv_list.Items[i];
            if (((CheckBox)item.FindControl("cb_ck")).Checked)
            {
                int id = (int)lv_list.DataKeys[i].Value;

                ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(id);

                if (IsImage(bll.Model.ExtName))
                {
                    bll.Model["IsFirstPicture"] = "Y";
                    bll.Update();


                    IList <ATMT_Attachment> lists = ATMT_AttachmentBLL.GetAttachmentList(RelateType, RelateID, BeginTime, EndTime, "");
                    foreach (ATMT_Attachment att in lists)
                    {
                        if (att.ID != id && att["IsFirstPicture"] == "Y")
                        {
                            ATMT_AttachmentBLL bll2 = new ATMT_AttachmentBLL(att.ID);
                            bll2.Model["IsFirstPicture"] = "N";
                            bll2.Update();
                        }
                    }
                }
                else
                {
                    MessageBox.Show(this.Page, "对不起,您选中的附件不是图片文件!");
                    return;
                }
                break;
            }
        }
        lv_list.DataBind();
    }
コード例 #18
0
    private void DownPreViewImage(Guid guid)
    {
        ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(guid);
        if (bll.Model == null)
        {
            MessageBox.ShowAndRedirect(this, "指定ID的附件不存在,参数错误!", "desktop.aspx");
            return;
        }
        if (!ATMT_AttachmentBLL.IsImage(bll.Model.ExtName))
        {
            return;
        }
        Response.Clear();
        Response.BufferOutput = true;

        #region 确定ContentType
        switch (bll.Model.ExtName.ToLower())
        {
            case "jpg":
            case "jpeg":
            case "jpe":
                Response.ContentType = "image/jpeg";
                break;
            case "gif":
                Response.ContentType = "image/gif";
                break;
            case "bmp":
                Response.ContentType = "image/bmp";
                break;
            case "png":
                Response.ContentType = "image/png";
                break;
            case "tiff":
            case "tif":
                Response.ContentType = "image/tiff";
                break;
            default:
                Response.ContentType = "application/octet-stream";
                break;
        }
        #endregion

        if (string.IsNullOrEmpty(bll.Model.Path))
        {
            byte[] data = bll.GetThumbnailData();
            if (data != null && data.Length > 0)
                Response.OutputStream.Write(data, 0, data.Length);
            else
            {
                data = bll.GetData();
                if (data != null && data.Length > 0)
                {
                    Stream filestream = new MemoryStream(data);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(filestream);
                    filestream.Close();

                    System.Drawing.Image preview = ImageProcess.MakeThumbnail(image, 0, 80, "H");

                    Stream prestream = new MemoryStream();
                    preview.Save(prestream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    prestream.Position = 0;

                    byte[] predata = new byte[prestream.Length];
                    prestream.Read(predata, 0, (int)prestream.Length);

                    bll.UploadThumbnailData(predata);

                    Response.OutputStream.Write(predata, 0, predata.Length);
                }

            }
        }
        else
        {
            string filepath = "";

            if (bll.Model.Path.StartsWith("~"))
                filepath = Server.MapPath(bll.Model.Path);
            else
                filepath = bll.Model.Path.Replace("/", "\\");

            if (!File.Exists(filepath))
            {
                MessageBox.ShowAndRedirect(this, "附件在服务器上不存在!" + filepath, "desktop.aspx");
                return;
            }

            string filename = filepath.Substring(filepath.LastIndexOf('\\') + 1);
            string previewimagepath = filepath.Substring(0, filepath.LastIndexOf('\\') + 1) + "Preview_" + filename;            //取得缩略图文件名
            previewimagepath = previewimagepath.Substring(0, previewimagepath.LastIndexOf('.') + 1) + "jpg";    //将缩略图扩展名改为JPG

            if (!System.IO.File.Exists(previewimagepath))
                ImageProcess.MakeThumbnail(filepath, previewimagepath, 0, 80, "H");

            Response.WriteFile(previewimagepath);
        }

        Response.Flush();
        Response.End();
    }
コード例 #19
0
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            if (RelateID == 0)
            {
                MessageBox.Show(this.Page, "请先关联要上传的对象! RelateID can not null!");
                return;
            }

            #region 保存文件
            if (!FileUpload1.HasFile)
            {
                MessageBox.Show(this.Page, "请选择要上传的文件!");
                return;
            }
            int FileSize = (FileUpload1.PostedFile.ContentLength / 1024);

            if (!Roles.IsUserInRole("管理员") && FileSize > ConfigHelper.GetConfigInt("MaxAttachmentSize"))
            {
                MessageBox.Show(this.Page, "上传的文件不能大于" + ConfigHelper.GetConfigInt("MaxAttachmentSize") +
                                "KB!当前上传文件大小为:" + FileSize.ToString() + "KB");
                return;
            }

            //判断文件格式
            string FileName = FileUpload1.PostedFile.FileName;
            FileName = FileName.Substring(FileName.LastIndexOf('\\') + 1);
            FileName = FileName.Substring(0, FileName.LastIndexOf('.'));

            string PicType = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(".") + 1).ToLowerInvariant();

            byte[] filedata;
            Stream filestream = FileUpload1.PostedFile.InputStream;

            #region 自动压缩上传的图片
            if (cb_AutoCompress.Checked && IsImage(PicType))
            {
                try
                {
                    System.Drawing.Image originalImage = System.Drawing.Image.FromStream(filestream);
                    filestream.Position = 0;

                    int width = originalImage.Width;

                    if (width > 1024 || PicType == "bmp")
                    {
                        if (width > 1024)
                        {
                            width = 1024;
                        }

                        System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                        MemoryStream thumbnailstream = new MemoryStream();
                        thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        thumbnailstream.Position = 0;
                        FileSize = (int)(thumbnailstream.Length / 1024);
                        PicType  = "jpg";

                        filestream = thumbnailstream;
                    }
                }
                catch { }
            }
            #endregion

            filedata = new byte[filestream.Length];
            filestream.Read(filedata, 0, (int)filestream.Length);
            filestream.Close();
            #endregion

            ATMT_AttachmentBLL atm = new ATMT_AttachmentBLL();

            atm.Model.RelateType = RelateType;
            atm.Model.RelateID   = RelateID;
            atm.Model.Name       = tbx_Name.Text.Trim() == "" ? FileName : tbx_Name.Text.Trim();
            //atm.Model.Path = SaveFullPath;
            atm.Model.ExtName     = PicType;
            atm.Model.FileSize    = FileSize;
            atm.Model.Description = tbx_Description.Text;
            atm.Model.UploadUser  = Session["UserName"].ToString();
            atm.Model.IsDelete    = "N";

            #region 判断当前关联对象有没有其他图片附件
            if (IsImage(PicType))
            {
                IList <ATMT_Attachment> lists = ATMT_AttachmentBLL.GetAttachmentList(RelateType, RelateID, BeginTime, EndTime, "lower(ExtName) in ('bmp','jpg','gif','png')");

                //如果当前上传的图片是第一张图片,则默认设为首要图片
                if (lists.Count == 0)
                {
                    atm.Model["IsFirstPicture"] = "Y";
                }
            }
            #endregion

            if (atm.Add(filedata) > 0)
            {
                MessageBox.Show(this.Page, "上传成功!");
            }
            else
            {
                MessageBox.Show(this.Page, "上传失败请重新上传!");
            }
            BindGrid();
        }
        catch (System.Exception err)
        {
            MessageBox.Show(this.Page, err.Message);
        }
    }
コード例 #20
0
    private void DownPreViewImage(ATMT_AttachmentBLL bll)
    {
        if (bll.Model == null)
        {
            MessageBox.ShowAndRedirect(this, "指定ID的附件不存在,参数错误!", "desktop.aspx");
            return;
        }
        if (!ATMT_AttachmentBLL.IsImage(bll.Model.ExtName))
        {
            return;
        }
        Response.Clear();
        Response.BufferOutput = true;

        #region 确定ContentType
        switch (bll.Model.ExtName.ToLower())
        {
        case "jpg":
        case "jpeg":
        case "jpe":
            Response.ContentType = "image/jpeg";
            break;

        case "gif":
            Response.ContentType = "image/gif";
            break;

        case "bmp":
            Response.ContentType = "image/bmp";
            break;

        case "png":
            Response.ContentType = "image/png";
            break;

        case "tiff":
        case "tif":
            Response.ContentType = "image/tiff";
            break;

        default:
            Response.ContentType = "application/octet-stream";
            break;
        }
        #endregion

        if (string.IsNullOrEmpty(bll.Model.Path))
        {
            byte[] data = bll.GetThumbnailData();
            if (data != null && data.Length > 0)
            {
                Response.OutputStream.Write(data, 0, data.Length);
            }
            else
            {
                data = bll.GetData();
                if (data != null && data.Length > 0)
                {
                    Stream filestream          = new MemoryStream(data);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(filestream);
                    filestream.Close();

                    System.Drawing.Image preview = ImageProcess.MakeThumbnail(image, 0, 80, "H");

                    Stream prestream = new MemoryStream();
                    preview.Save(prestream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    prestream.Position = 0;

                    byte[] predata = new byte[prestream.Length];
                    prestream.Read(predata, 0, (int)prestream.Length);

                    bll.UploadThumbnailData(predata);

                    Response.OutputStream.Write(predata, 0, predata.Length);
                }
            }
        }
        else
        {
            string filepath = "";

            if (bll.Model.Path.StartsWith("~"))
            {
                filepath = Server.MapPath(bll.Model.Path);
            }
            else
            {
                filepath = bll.Model.Path.Replace("/", "\\");
            }

            if (!File.Exists(filepath))
            {
                MessageBox.ShowAndRedirect(this, "附件在服务器上不存在!" + filepath, "desktop.aspx");
                return;
            }

            string filename         = filepath.Substring(filepath.LastIndexOf('\\') + 1);
            string previewimagepath = filepath.Substring(0, filepath.LastIndexOf('\\') + 1) + "Preview_" + filename; //取得缩略图文件名
            previewimagepath = previewimagepath.Substring(0, previewimagepath.LastIndexOf('.') + 1) + "jpg";         //将缩略图扩展名改为JPG

            if (!System.IO.File.Exists(previewimagepath))
            {
                ImageProcess.MakeThumbnail(filepath, previewimagepath, 0, 80, "H");
            }

            Response.WriteFile(previewimagepath);
        }

        Response.Flush();
        Response.End();
    }
コード例 #21
0
    /// <summary>
    /// 显示缩略图
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    protected string PreViewImagePath(int id)
    {
        ATMT_Attachment m = new ATMT_AttachmentBLL(id).Model;
        if (m == null) return "";

        if (IsImage(m.ExtName))
        {
            return "~/SubModule/DownloadAttachment.aspx?GUID=" + m.GUID.ToString() + "&PreViewImage=Y";
        }
        else
        {
            string filename = "~/Images/icon/" + m.ExtName + ".png";
            if (System.IO.File.Exists(Server.MapPath(filename)))
            {
                return filename;
            }
            else
            {
                return "~/Images/icon/other.png";
            }
        }
    }
コード例 #22
0
    //Upload Attachment
    protected void btn_Up_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            try
            {
                string fullfilename = FileUpload1.FileName;

                if (fullfilename.LastIndexOf(".") < 0)
                {
                    MessageBox.Show(this, "无法识别的附件格式!");
                    return;
                }

                int FileSize = (FileUpload1.PostedFile.ContentLength / 1024);
                if (FileSize > ConfigHelper.GetConfigInt("MaxAttachmentSize"))
                {
                    MessageBox.Show(this.Page, "上传的文件不能大于" + ConfigHelper.GetConfigInt("MaxAttachmentSize") +
                                    "KB!当前上传文件大小为:" + FileSize.ToString() + "KB");
                    return;
                }
                string extendname = fullfilename.Substring(fullfilename.LastIndexOf(".") + 1).ToLowerInvariant();
                string filename   = fullfilename.Substring(0, fullfilename.LastIndexOf("."));

                byte[] filedata;
                Stream filestream = FileUpload1.PostedFile.InputStream;

                #region 自动压缩上传的图片
                if (ATMT_AttachmentBLL.IsImage(extendname))
                {
                    try
                    {
                        System.Drawing.Image originalImage = System.Drawing.Image.FromStream(filestream);
                        filestream.Position = 0;

                        int width = originalImage.Width;

                        if (width > 1024 || extendname == "bmp")
                        {
                            if (width > 1024)
                            {
                                width = 1024;
                            }

                            System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                            MemoryStream thumbnailstream = new MemoryStream();
                            thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            thumbnailstream.Position = 0;
                            FileSize   = (int)(thumbnailstream.Length / 1024);
                            extendname = "jpg";

                            filestream = thumbnailstream;
                        }
                    }
                    catch { }
                }
                #endregion

                filedata = new byte[filestream.Length];
                filestream.Read(filedata, 0, (int)filestream.Length);
                filestream.Close();

                EWF_Task_AttachmentBLL ta = new EWF_Task_AttachmentBLL();
                ta.Model.Task = (int)ViewState["TaskID"];
                ta.Model.Name = this.tbx_AttachmentName.Text.Trim();
                if (ta.Model.Name == "")
                {
                    ta.Model.Name = filename;
                }
                ta.Model.Description = this.tbx_AttachmentDescription.Text.Trim();
                //ta.Model.FilePath = saveasfilename;
                ta.Model.UploadStaff = int.Parse(Session["UserID"].ToString());
                ta.Model.FileSize    = FileUpload1.PostedFile.ContentLength / 1024;
                ta.Model.FileType    = extendname.ToUpper();

                if (ta.Add(filedata) > 0)
                {
                    BindAttachmentList();
                }
                else
                {
                    MessageBox.Show(this, "附件上传失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
                return;
            }
        }
        else
        {
            MessageBox.Show(this, "未选择要上传的附件!");
            return;
        }
    }
コード例 #23
0
    protected void bt_Delete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < lv_list.Items.Count; i++)
        {
            ListViewItem item = lv_list.Items[i];
            if (((CheckBox)item.FindControl("cb_ck")).Checked)
            {
                int id = (int)lv_list.DataKeys[i].Value;

                ATMT_AttachmentBLL att = new ATMT_AttachmentBLL(id);
                try
                {
                    File.Delete(Server.MapPath(att.Model.Path));
                }
                catch { }
                att.Delete();

            }

        }

        lv_list.DataBind();
    }
コード例 #24
0
    protected void bt_SetFirstPicture_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < lv_list.Items.Count; i++)
        {
            ListViewItem item = lv_list.Items[i];
            if (((CheckBox)item.FindControl("cb_ck")).Checked)
            {
                int id = (int)lv_list.DataKeys[i].Value;

                ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(id);

                if (IsImage(bll.Model.ExtName))
                {

                    bll.Model["IsFirstPicture"] = "Y";
                    bll.Update();

                    IList<ATMT_Attachment> lists = ATMT_AttachmentBLL.GetAttachmentList(RelateType, RelateID, BeginTime, EndTime, "");
                    foreach (ATMT_Attachment att in lists)
                    {
                        if (att.ID != id && att["IsFirstPicture"] == "Y")
                        {
                            ATMT_AttachmentBLL bll2 = new ATMT_AttachmentBLL(att.ID);
                            bll2.Model["IsFirstPicture"] = "N";
                            bll2.Update();
                        }
                    }
                }
                else
                {
                    MessageBox.Show(this.Page, "对不起,您选中的附件不是图片文件!");
                    return;
                }
                break;
            }
        }
        lv_list.DataBind();
    }
コード例 #25
0
    private void Download(ATMT_AttachmentBLL bll)
    {
        if (bll.Model == null)
        {
            MessageBox.ShowAndRedirect(this, "指定ID的附件不存在,参数错误!", "desktop.aspx");
            return;
        }

        Response.Clear();
        Response.BufferOutput = true;

        #region 确定ContentType
        switch (bll.Model.ExtName.ToLower())
        {
        case "jpg":
        case "jpeg":
        case "jpe":
            Response.ContentType = "image/jpeg";
            break;

        case "gif":
            Response.ContentType = "image/gif";
            break;

        case "bmp":
            Response.ContentType = "image/bmp";
            break;

        case "png":
            Response.ContentType = "image/png";
            break;

        case "tiff":
        case "tif":
            Response.ContentType = "image/tiff";
            break;

        case "doc":
        case "docx":
            Response.ContentType = "application/ms-word";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            break;

        case "xls":
        case "xlsx":
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            break;

        case "ppt":
        case "pptx":
            Response.ContentType = "application/ms-powerpoint";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            break;

        case "pdf":
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            break;

        case "zip":
            Response.ContentType = "application/zip";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            break;

        case "rar":
            Response.ContentType = "application/rar";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            break;

        case "txt":
            Response.ContentType = "text/plain";
            break;

        case "htm":
        case "html":
            Response.ContentType = "text/html";
            break;

        default:
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
            break;
        }
        #endregion

        if (string.IsNullOrEmpty(bll.Model.Path))
        {
            byte[] data = bll.GetData();
            if (data != null)
            {
                Response.OutputStream.Write(data, 0, data.Length);
            }
        }
        else
        {
            string filepath = bll.Model.Path;

            if (filepath.StartsWith("~"))
            {
                filepath = Server.MapPath(filepath);
            }

            if (!File.Exists(filepath))
            {
                MessageBox.ShowAndRedirect(this, "附件在服务器上不存在!", "desktop.aspx");
                return;
            }
            Response.WriteFile(filepath);
        }

        Response.Flush();
        Response.End();
    }
コード例 #26
0
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            if (RelateID == 0)
            {
                MessageBox.Show(this.Page, "请先关联要上传的对象! RelateID can not null!");
                return;
            }

            #region 保存文件
            if (!FileUpload1.HasFile)
            {
                MessageBox.Show(this.Page, "请选择要上传的文件!");
                return;
            }
            int FileSize = (FileUpload1.PostedFile.ContentLength / 1024);

            if (!Roles.IsUserInRole("管理员") && FileSize > ConfigHelper.GetConfigInt("MaxAttachmentSize"))
            {
                MessageBox.Show(this.Page, "上传的文件不能大于" + ConfigHelper.GetConfigInt("MaxAttachmentSize") +
                    "KB!当前上传文件大小为:" + FileSize.ToString() + "KB");
                return;
            }

            //判断文件格式
            string FileName = FileUpload1.PostedFile.FileName;
            FileName = FileName.Substring(FileName.LastIndexOf('\\') + 1);
            FileName = FileName.Substring(0, FileName.LastIndexOf('.'));

            string PicType = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(".") + 1).ToLowerInvariant();

            byte[] filedata;
            Stream filestream = FileUpload1.PostedFile.InputStream;

            #region 自动压缩上传的图片
            if (cb_AutoCompress.Checked && IsImage(PicType))
            {
                try
                {
                    System.Drawing.Image originalImage = System.Drawing.Image.FromStream(filestream);
                    filestream.Position = 0;

                    int width = originalImage.Width;

                    if (width > 1024 || PicType == "bmp")
                    {
                        if (width > 1024) width = 1024;

                        System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                        MemoryStream thumbnailstream = new MemoryStream();
                        thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        thumbnailstream.Position = 0;
                        FileSize = (int)(thumbnailstream.Length / 1024);
                        PicType = "jpg";

                        filestream = thumbnailstream;
                    }
                }
                catch { }
            }
            #endregion

            filedata = new byte[filestream.Length];
            filestream.Read(filedata, 0, (int)filestream.Length);
            filestream.Close();
            #endregion

            ATMT_AttachmentBLL atm = new ATMT_AttachmentBLL();

            atm.Model.RelateType = RelateType;
            atm.Model.RelateID = RelateID;
            atm.Model.Name = tbx_Name.Text.Trim() == "" ? FileName : tbx_Name.Text.Trim();
            //atm.Model.Path = SaveFullPath;
            atm.Model.ExtName = PicType;
            atm.Model.FileSize = FileSize;
            atm.Model.Description = tbx_Description.Text;
            atm.Model.UploadUser = Session["UserName"].ToString();
            atm.Model.IsDelete = "N";

            #region 判断当前关联对象有没有其他图片附件
            if (IsImage(PicType))
            {
                IList<ATMT_Attachment> lists = ATMT_AttachmentBLL.GetAttachmentList(RelateType, RelateID, BeginTime, EndTime, "lower(ExtName) in ('bmp','jpg','gif','png')");

                //如果当前上传的图片是第一张图片,则默认设为首要图片
                if (lists.Count == 0) atm.Model["IsFirstPicture"] = "Y";
            }
            #endregion

            if (atm.Add(filedata) > 0)
            {
                MessageBox.Show(this.Page, "上传成功!");
            }
            else
            {
                MessageBox.Show(this.Page, "上传失败请重新上传!");
            }
            BindGrid();
        }
        catch (System.Exception err)
        {
            MessageBox.Show(this.Page, err.Message);
        }
    }
コード例 #27
0
    protected void bt_AddToWriteOffList_Click(object sender, EventArgs e)
    {
        ListTable <FNA_FeeWriteOffDetail> _details = Session["FeeWriteOffDetails"] as ListTable <FNA_FeeWriteOffDetail>;
        int maxid = 0;

        if (_details != null)
        {
            if (_details.GetListItem().Count > 0)
            {
                maxid = _details.GetListItem().Max(p => p.ID);
            }
        }
        maxid++;

        foreach (GridViewRow row in gv_FeeAplyList.Rows)
        {
            CheckBox cb_Selected = (CheckBox)row.FindControl("cb_Selected");
            if (cb_Selected.Checked)
            {
                int applyid       = (int)gv_FeeAplyList.DataKeys[row.RowIndex][0];
                int applydetialid = (int)gv_FeeAplyList.DataKeys[row.RowIndex][1];

                FNA_FeeApplyBLL    applyBLL    = new FNA_FeeApplyBLL(applyid);
                FNA_FeeApply       apply       = applyBLL.Model;
                FNA_FeeApplyDetail applydetail = applyBLL.GetDetailModel(applydetialid);

                #region 陈列、返利费用判断协议是否关联合同
                IList <CM_Contract> contractList;
                contractList = CM_ContractBLL.GetModelList(@"ContractCode!='' AND ContractCode=MCS_SYS.dbo.UF_Spilt('" + applydetail.Remark + "',':',2)");
                if (applydetail.RelateContractDetail != 0)
                {
                    int ID = 0;
                    CM_ContractDetail detail = new CM_ContractBLL().GetDetailModel(applydetail.RelateContractDetail);
                    if (detail != null)
                    {
                        ID = detail.ContractID;
                    }
                    contractList = CM_ContractBLL.GetModelList("ID=" + ID.ToString());
                }

                if (contractList.Count > 0 && contractList[0].Classify < 3 && ATMT_AttachmentBLL.GetModelList("RelateType=35 AND RelateID=" + contractList[0].ID.ToString()).Count == 0)
                {
                    MessageBox.Show(this, "陈列、返利费用操作费用核销申请时,门店协议必须上传附件,请上传后再核销!");
                    return;
                }
                #endregion

                FNA_FeeWriteOffDetail m = new FNA_FeeWriteOffDetail();
                m.ID            = maxid++;
                m.ApplyDetailID = applydetialid;
                m.Client        = applydetail.Client;
                m.AccountTitle  = applydetail.AccountTitle;
                m.ProductBrand  = apply.ProductBrand;
                m.ApplyCost     = applydetail.AvailCost;
                m.BeginMonth    = applydetail.BeginMonth;
                m.EndMonth      = applydetail.EndMonth;
                m.BeginDate     = applydetail.BeginDate;
                m.EndDate       = applydetail.EndDate;
                m.WriteOffCost  = applydetail.AvailCost;
                m.Remark        = applydetail.Remark;
                if (applydetail["BankVoucherNo"] != "")
                {
                    m.Remark += ",凭证:" + applydetail["BankVoucherNo"];
                }

                if (applydetail.Remark.IndexOf("是否CA") > 0)
                {
                    m.Remark = applydetail.Remark.Substring(applydetail.Remark.IndexOf("是否CA") - 1);
                }
                if (_details == null)
                {
                    _details = new ListTable <FNA_FeeWriteOffDetail>(new List <FNA_FeeWriteOffDetail>(), "ID");
                }
                _details.Add(m);
            }
        }

        BindGrid();
        gv_FeeAplyList.PageIndex = 0;
        BindFeeApplyNoWriteOff();
    }
コード例 #28
0
    private void DownPreViewImage(string Path, Guid guid)
    {
        ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(guid);
        if (bll.Model == null)
        {
            MessageBox.ShowAndRedirect(this, "指定ID的附件不存在,参数错误!", "desktop.aspx");
            return;
        }
        if (!ATMT_AttachmentBLL.IsImage(bll.Model.ExtName))
        {
            return;
        }

        string AttachmentPath = ConfigHelper.GetConfigString("AttachmentPath");
        if (string.IsNullOrEmpty(AttachmentPath)) AttachmentPath = "D:\\Attachment";

        if (string.IsNullOrEmpty(bll.Model.Path))
        {
            byte[] data = bll.GetThumbnailData();
            if (data != null && data.Length > 0)
            {
                if (data != null)
                {
                    FileStream fs = File.Create(Path + "\\" + bll.Model.GUID + "." + bll.Model.ExtName);
                    fs.Write(data, 0, data.Length);
                    fs.Close();

                    SendAttachmentData(data, bll.Model.Name, bll.Model.ExtName);
                }
            }
            else
            {
                data = bll.GetData();
                if (data != null && data.Length > 0)
                {
                    #region 生成缩略图
                    Stream filestream = new MemoryStream(data);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(filestream);
                    filestream.Close();

                    System.Drawing.Image preview = ImageProcess.MakeThumbnail(image, 0, 140, "H");

                    Stream prestream = new MemoryStream();
                    preview.Save(prestream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    prestream.Position = 0;

                    byte[] predata = new byte[prestream.Length];
                    prestream.Read(predata, 0, (int)prestream.Length);

                    bll.UploadThumbnailData(predata);

                    FileStream fs = File.Create(AttachmentPath + "\\" + "P_" + bll.Model.GUID + "." + bll.Model.ExtName);
                    fs.Write(predata, 0, predata.Length);
                    fs.Close();
                    #endregion

                    SendAttachmentData(data, bll.Model.Name, bll.Model.ExtName);
                }

            }
        }
        else
        {
            string filepath = "";

            if (bll.Model.Path.StartsWith("~"))
                filepath = Server.MapPath(bll.Model.Path);
            else
                filepath = bll.Model.Path.Replace("/", "\\");

            if (!File.Exists(filepath))
            {
                MessageBox.ShowAndRedirect(this, "附件在服务器上不存在!" + filepath, "desktop.aspx");
                return;
            }

            string filename = filepath.Substring(filepath.LastIndexOf('\\') + 1);
            string previewimagepath = filepath.Substring(0, filepath.LastIndexOf('\\') + 1) + "Preview_" + filename;            //取得缩略图文件名
            previewimagepath = previewimagepath.Substring(0, previewimagepath.LastIndexOf('.') + 1) + "jpg";    //将缩略图扩展名改为JPG

            if (!System.IO.File.Exists(previewimagepath))
                ImageProcess.MakeThumbnail(filepath, previewimagepath, 0, 140, "H");

            #region 从本地目录中加载图片
            byte[] data = File.ReadAllBytes(previewimagepath);

            string extname = "";
            int p = previewimagepath.LastIndexOf('.');
            if (p > 0) extname = previewimagepath.Substring(p + 1);

            SendAttachmentData(data, bll.Model.Name, extname);
            #endregion
        }
    }
コード例 #29
0
    protected void cmdOK_ServerClick(object sender, System.EventArgs e)
    {
        #region 添加论文的主题内容
        BBS_ForumItemBLL itembll = new BBS_ForumItemBLL();
        itembll.Model.Board         = Convert.ToInt32(ViewState["BoardID"]);
        itembll.Model.Title         = Title.Value;
        itembll.Model.Content       = ckedit_content.Text;
        itembll.Model.Sender        = Session["UserName"].ToString();
        itembll.Model.SendTime      = DateTime.Now;
        itembll.Model.HitTimes      = 0;                                   //点击次数默认的设置为0
        itembll.Model.ReplyTimes    = 0;                                   //回复次数默认的设置为0
        itembll.Model.LastReplyer   = Session["UserName"].ToString();      //默认的设置为本人
        itembll.Model.LastReplyTime = DateTime.Now;
        itembll.Model.IPAddr        = Request.ServerVariables.Get("REMOTE_ADDR").ToString();

        itembll.Model["IsTop"]  = "N"; //是否置顶
        itembll.Model["IsPith"] = "N"; //是否是精贴

        int itemid = itembll.Add();    // 返回已经发布的论文的ID
        #endregion

        #region 添加论文的附件
        ArrayList upattlist = (ArrayList)ViewState["UpattList"];
        if (upattlist != null && upattlist.Count > 0)
        {
            string _content = "<br/><font color=red><b>附件列表:</b></font><br/>";

            foreach (BBS_ForumAttachment att in upattlist)
            {
                string path = att.Path;
                if (path.StartsWith("~"))
                {
                    path = Server.MapPath(path);
                }
                FileStream stream = new FileStream(path, FileMode.Open);
                byte[]     buff   = new byte[stream.Length];
                stream.Read(buff, 0, buff.Length);
                stream.Close();
                att.Path   = "";
                att.ItemID = itemid;

                #region 自动压缩上传的图片
                if (ATMT_AttachmentBLL.IsImage(att.ExtName))
                {
                    try
                    {
                        MemoryStream         s             = new MemoryStream(buff);
                        System.Drawing.Image originalImage = System.Drawing.Image.FromStream(s);
                        s.Close();

                        int width = originalImage.Width;

                        if (width > 1024 || att.ExtName == "bmp")
                        {
                            if (width > 1024)
                            {
                                width = 1024;
                            }

                            System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                            MemoryStream thumbnailstream = new MemoryStream();
                            thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            thumbnailstream.Position = 0;
                            att.FileSize             = (int)(thumbnailstream.Length / 1024);
                            att.ExtName = "jpg";

                            byte[] b = new byte[thumbnailstream.Length];
                            thumbnailstream.Read(b, 0, b.Length);
                            thumbnailstream.Close();
                            buff = b;
                        }
                    }
                    catch { }
                }
                #endregion

                BBS_ForumAttachmentBLL bll = new BBS_ForumAttachmentBLL();
                bll.Model = att;
                bll.Add(buff);

                BBS_ForumAttachment m = bll.Model;
                string _uploadcontent = "";     //插入主表中

                switch (att.ExtName.ToLower())
                {
                case "jpg":
                case "gif":
                case "bmp":
                case "png":
                    _uploadcontent = " [IMG]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/IMG]<br/>";
                    break;

                case "mp3":
                    _uploadcontent = " [MP=320,70]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "avi":
                    _uploadcontent = " [MP=320,240]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "swf":
                    _uploadcontent = " [FLASH]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/FLASH]<br/>";
                    break;

                default:
                    _uploadcontent = "<a href=DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + ">" + att.Name + "." + att.ExtName + "</a><br/>";
                    break;
                }
                _content += _uploadcontent + "<br/>";
            }

            if (ViewState["SavePath"] != null)
            {
                try
                {
                    string path = (string)ViewState["SavePath"];
                    path = path.Substring(0, path.LastIndexOf("\\"));
                    Directory.Delete(path, true);
                    ViewState["SavePath"] = null;
                }
                catch { }
            }

            //将附件的路径添加到发帖主表中去
            itembll.Model.Content += _content;
            itembll.Update();

            //清空附件的列表
            for (int i = upattlist.Count - 1; i >= 0; i--)
            {
                upattlist.RemoveAt(i);
            }
            ViewState["UpattList"] = upattlist;
        }
        #endregion

        Server.Transfer("listview.aspx?Board=" + ViewState["BoardID"].ToString());
    }
コード例 #30
0
        private void FillClientInfo(CM_Client m, int TDP)
        {
            if (m == null)
            {
                return;
            }

            CM_ClientBLL ClientBLL = new CM_ClientBLL(m.ID);

            if (ClientBLL.Model == null)
            {
                return;
            }

            #region 绑定基本资料
            ID           = m.ID;
            Code         = m.Code;
            FullName     = m.FullName == "" ? m.ShortName : m.FullName;
            ShortName    = m.ShortName;
            OfficialCity = m.OfficialCity;
            Address      = m.Address;
            ClientType   = m.ClientType;
            LinkManName  = m.LinkManName;
            TeleNum      = m.TeleNum;
            Mobile       = m.Mobile == "" ? m.TeleNum : m.Mobile;

            OfficialCityName = TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OfficialCity", m.OfficialCity).Replace("->", " ");
            #endregion

            #region 绑定供货信息
            CM_ClientSupplierInfo SupplierInfo = ClientBLL.GetSupplierInfo(TDP);
            if (SupplierInfo != null)
            {
                CodeBySupplier = SupplierInfo.Code;
                Supplier       = SupplierInfo.Supplier;
                StandardPrice  = SupplierInfo.StandardPrice;
                TDPChannel     = SupplierInfo.TDPChannel;
                TDPSalesArea   = SupplierInfo.TDPSalesArea;
                VisitRoute     = SupplierInfo.VisitRoute;
                VisitSequence  = SupplierInfo.VisitSequence;
                VisitTemplate  = SupplierInfo.VisitTemplate;

                #region 获取供货商名称
                CM_Client s = new CM_ClientBLL(Supplier).Model;
                if (s != null)
                {
                    SupplierName = s.ShortName == "" ? s.ShortName : s.FullName;
                }
                #endregion

                #region 获取价表名称
                if (StandardPrice != 0)
                {
                    PDT_StandardPrice price = new PDT_StandardPriceBLL(StandardPrice).Model;
                    if (price != null)
                    {
                        StandardPriceName = price.Name;
                    }
                }
                #endregion

                #region 获取渠道名称
                if (TDPChannel > 0)
                {
                    CM_RTChannel_TDP channel = new CM_RTChannel_TDPBLL(TDPChannel).Model;
                    if (channel != null)
                    {
                        TDPChannelName = channel.Name;
                    }
                }
                #endregion

                #region 获取区域名称
                if (TDPSalesArea > 0)
                {
                    CM_RTSalesArea_TDP area = new CM_RTSalesArea_TDPBLL(TDPSalesArea).Model;
                    if (area != null)
                    {
                        TDPSalesAreaName = area.Name;
                    }
                }
                #endregion

                #region 获取路线及拜访模板名称
                if (VisitRoute != 0)
                {
                    VST_Route r = new VST_RouteBLL(VisitRoute).Model;
                    if (r != null)
                    {
                        VisitRouteName = r.Name;
                    }
                }

                if (VisitTemplate != 0)
                {
                    VST_VisitTemplate t = new VST_VisitTemplateBLL(VisitTemplate).Model;
                    if (t != null)
                    {
                        VisitTemplateName = t.Name;
                    }
                }
                #endregion

                #region 获取销售员名称
                if (Salesman != 0)
                {
                    Org_Staff staff = new Org_StaffBLL(Salesman).Model;
                    if (staff != null)
                    {
                        SalesmanName = staff.RealName;
                    }
                }
                #endregion
            }
            #endregion

            #region 绑定厂商管理信息
            int manufacturer = 0;           //归属厂商
            if (m.ClientType == 3)
            {
                //门店的归属厂商为当前TDP所归属的厂商
                CM_Client supplier = new CM_ClientBLL(TDP).Model;
                if (supplier != null)
                {
                    manufacturer = supplier.OwnerClient;
                }
            }
            else if (m.ClientType == 2)
            {
                //TDP经销商的归属厂商
                manufacturer = m.OwnerClient;
            }

            CM_ClientManufactInfo ManufactInfo = ClientBLL.GetManufactInfo(manufacturer);
            if (ManufactInfo != null)
            {
                CodeByManufaturer = ManufactInfo.Code;
            }
            #endregion

            #region 绑定客户定位信息
            CM_ClientGeoInfo geo = CM_ClientGeoInfoBLL.GetGeoInfoByClient(m.ID);
            if (geo != null)
            {
                Latitude  = (float)geo.Latitude;
                Longitude = (float)geo.Longitude;
            }
            #endregion

            #region 绑定客户供货产品目录
            ClientProductLists = new List <ProductList>();
            foreach (CM_ClientProductList item in CM_ClientProductListBLL.GetModelList
                         ("Client=" + m.ID.ToString() + (TDP == 0 ? "" : " AND Supplier=" + TDP.ToString())))
            {
                ClientProductLists.Add(new ProductList(item));
            }
            #endregion

            #region 查询预收款余额
            AC_CurrentAccount ac = AC_CurrentAccountBLL.GetByTradeClient(TDP, m.ID);
            if (ac != null)
            {
                ARBalance = ac.PreReceivedAmount - ac.AR;
            }
            #endregion

            #region 获取附件明细
            IList <ATMT_Attachment> atts = ATMT_AttachmentBLL.GetAttachmentList(30, m.ID, DateTime.Today.AddMonths(-3), new DateTime(2100, 1, 1));
            Atts = new List <Attachment>(atts.Count);
            foreach (ATMT_Attachment item in atts.OrderByDescending(p => p.UploadTime))
            {
                Atts.Add(new Attachment(item));
            }
            #endregion
        }
コード例 #31
0
    protected void GridAttachment_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)//判断当前行是否是数据行
        {
            int rowIndex = (int)e.Row.RowIndex;
            Image img = (Image)e.Row.FindControl("img");
            string a = GridAttachment.DataKeys[rowIndex]["ID"].ToString();
            Guid imgGUID = (Guid)GridAttachment.DataKeys[rowIndex]["GUID"];
            img.ImageUrl = "~/SubModule/DownloadAttachment.aspx?GUID=" + imgGUID.ToString() + "&PreViewImage=Y";

            Guid AttGUID = (Guid)GridAttachment.DataKeys[rowIndex]["GUID"];
            ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(AttGUID);
            CM_ClientBLL clientBLL = new CM_ClientBLL(bll.Model.RelateID);
            if (clientBLL.Model != null)
            {
                e.Row.Cells[1].Text = clientBLL.Model.FullName;
                e.Row.Cells[2].Text = clientBLL.Model.Code;
            }
        }
    }
コード例 #32
0
        /// <summary>
        /// 上传巡店工作日志关联照片
        /// </summary>
        /// <param name="AuthKey"></param>
        /// <param name="ClientID">巡店工作日志ID</param>
        /// <param name="PicName">图片名称(可选)</param>
        /// <param name="PicData">图片数据</param>
        /// <returns>大于0:成功 -1:巡店工作日志ID无效 -4:照片格式不正确</returns>
        public static int UploadVisitWorkPicture(UserInfo User, int VisitWorkID, string PicName, string Description, string PicData, out Guid PicGUID)
        {
            PicGUID = Guid.Empty;
            LogWriter.WriteLog("PBMIFService.UploadVisitWorkPicture:UserName="******",VisitWorkID=" + VisitWorkID.ToString()
                + ",PicName=" + PicName + ",Description=" + Description + ",PicDataLength=" + PicData.Length);

            try
            {
                if (VisitWorkID == 0) return -1;        //必须指定巡店工作日志ID

                if (string.IsNullOrEmpty(PicData)) return -4;
                byte[] buffer = Convert.FromBase64String(PicData);
                if (buffer.Length == 0 && buffer.Length > 1024 * 1024 * 10) return -4;

                ATMT_AttachmentBLL atm = new ATMT_AttachmentBLL();
                atm.Model.RelateType = 95;          //巡店工作日志
                atm.Model.RelateID = VisitWorkID;
                atm.Model.Name = string.IsNullOrEmpty(PicName) ? "照片" : PicName;
                atm.Model.ExtName = "jpg";          //默认为JPG图片
                atm.Model.FileSize = PicData.Length / 1024;
                atm.Model.Description = Description;
                atm.Model.UploadUser = User.UserName;
                atm.Model.IsDelete = "N";

                int ret = atm.Add(buffer, out PicGUID);
                LogWriter.WriteLog("PBMIFService.UploadVisitWorkPicture Upload Result:UserName="******",VisitWorkID=" + VisitWorkID.ToString()
                    + ",PicGUID=" + PicGUID.ToString() + ",Ret=" + ret.ToString());
                return ret;
            }
            catch (System.Exception err)
            {
                LogWriter.WriteLog("PBMIFService.UploadVisitWorkPicture Exception Error!", err);
                return -100;
            }
        }
コード例 #33
0
    protected void btn_OK_Click(object sender, EventArgs e)
    {
        #region 帖子的回复

        #region 添加帖子的回复
        BBS_ForumReplyBLL replybll = new BBS_ForumReplyBLL();
        replybll.Model.ItemID    = Convert.ToInt32(ViewState["ItemID"]);
        replybll.Model.Title     = Title.Value;
        replybll.Model.Content   = ckedit_content.Text;
        replybll.Model.Replyer   = Session["UserName"].ToString();
        replybll.Model.ReplyTime = DateTime.Now;
        replybll.Model.IPAddress = Request.ServerVariables.Get("REMOTE_ADDR").ToString();
        int replyid = replybll.Add();    // 返回已经回复的帖子的ID

        //修改论坛文章的留言量
        BBS_ForumItemBLL itembll = new BBS_ForumItemBLL(Convert.ToInt32(ViewState["ItemID"]));
        itembll.UpdateAddReplyTimes(Convert.ToInt32(ViewState["ItemID"]));
        #endregion

        #region 添加留言的附件
        ArrayList upattlist = (ArrayList)ViewState["UpattList"];
        if (upattlist != null && upattlist.Count > 0)
        {
            foreach (BBS_ForumAttachment att in upattlist)
            {
                string path = att.Path;
                if (path.StartsWith("~"))
                {
                    path = Server.MapPath(path);
                }
                FileStream stream = new FileStream(path, FileMode.Open);
                byte[]     buff   = new byte[stream.Length];
                stream.Read(buff, 0, buff.Length);
                stream.Close();
                att.Path   = "";
                att.ItemID = (int)ViewState["ItemID"];

                #region 自动压缩上传的图片
                if (ATMT_AttachmentBLL.IsImage(att.ExtName))
                {
                    try
                    {
                        MemoryStream         s             = new MemoryStream(buff);
                        System.Drawing.Image originalImage = System.Drawing.Image.FromStream(s);
                        s.Close();

                        int width = originalImage.Width;

                        if (width > 1024 || att.ExtName == "bmp")
                        {
                            if (width > 1024)
                            {
                                width = 1024;
                            }

                            System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                            MemoryStream thumbnailstream = new MemoryStream();
                            thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            thumbnailstream.Position = 0;
                            att.FileSize             = (int)(thumbnailstream.Length / 1024);
                            att.ExtName = "jpg";

                            byte[] b = new byte[thumbnailstream.Length];
                            thumbnailstream.Read(b, 0, b.Length);
                            thumbnailstream.Close();
                            buff = b;
                        }
                    }
                    catch { }
                }
                #endregion

                att.Reply = replyid;
                BBS_ForumAttachmentBLL bll = new BBS_ForumAttachmentBLL();
                bll.Model = att;
                bll.Add(buff);

                BBS_ForumAttachment m = bll.Model;
                string uploadcontent  = "";    //插入主表中

                switch (att.ExtName.ToLower())
                {
                case "jpg":
                case "gif":
                case "bmp":
                case "png":
                    uploadcontent = " [IMG]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/IMG]<br/>";
                    break;

                case "mp3":
                    uploadcontent = " [MP=320,70]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "avi":
                    uploadcontent = " [MP=320,240]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "swf":
                    uploadcontent = " [FLASH]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/FLASH]<br/>";
                    break;

                default:
                    uploadcontent = "<a href=DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + ">" + att.Name + "." + att.ExtName + "</a><br/>";
                    break;
                }
                ViewState["Content"] += uploadcontent + "<br/>";
            }

            if (ViewState["SavePath"] != null)
            {
                try
                {
                    string path = (string)ViewState["SavePath"];
                    path = path.Substring(0, path.LastIndexOf("\\"));
                    Directory.Delete(path, true);
                    ViewState["SavePath"] = null;
                }
                catch { }
            }

            //将附件的路径添加到回复主表中去
            replybll.Model.Content += "<br/><font color=red><b>附件列表:</b></font><br/>" + ViewState["Content"].ToString();
            replybll.Update();

            //清空附件的列表
            for (int i = upattlist.Count - 1; i >= 0; i--)
            {
                this.lbx_AttList.Items.RemoveAt(i);
                upattlist.RemoveAt(i);
            }
            ViewState["UpattList"] = upattlist;
        }
        #endregion

        #endregion

        Response.Redirect("display.aspx?ID=" + ViewState["ItemID"].ToString() + "&BoardID=" + ViewState["BoardID"].ToString());
    }
コード例 #34
0
        private void FillModel(PDT_Product m, int TDP)
        {
            ID            = m.ID;
            FullName      = m.FullName;
            ShortName     = m.ShortName;
            Code          = m.Code;
            BarCode       = m.BarCode;
            BoxBarCode    = m.BoxBarCode;
            ConvertFactor = m.ConvertFactor;
            Spec          = m.Spec;
            Remark        = m.Remark;
            Grade         = m.Grade;
            Category      = m.Category;
            FactoryCode   = m.FactoryCode;
            FactoryName   = m.FactoryName;

            #region 获取商品的TDP扩展管理信息
            if (TDP != 0)
            {
                IList <PDT_ProductExtInfo> exts = PDT_ProductExtInfoBLL.GetModelList("Supplier=" + TDP.ToString() + " AND Product=" + m.ID.ToString());
                if (exts.Count > 0)
                {
                    TDPCode = exts[0].Code;
                    if (exts[0].Category != 0)
                    {
                        Category = exts[0].Category;
                    }
                    BuyPrice   = exts[0].BuyPrice;
                    SalesPrice = exts[0].SalesPrice;
                }
            }
            #endregion

            #region 获取品牌、系列、类别名称
            if (m.Brand > 0)
            {
                PDT_Brand brand = new PDT_BrandBLL(m.Brand).Model;
                if (brand != null)
                {
                    BrandName = brand.Name;
                }
            }
            if (m.Classify > 0)
            {
                PDT_Classify classify = new PDT_ClassifyBLL(m.Classify).Model;
                if (classify != null)
                {
                    ClassifyName = classify.Name;
                }
            }
            if (Category > 0)
            {
                CategoryName = PDT_CategoryBLL.GetFullCategoryName(Category);
            }
            #endregion

            #region 获取字典表名称
            try
            {
                if (m.Grade > 0)
                {
                    Dictionary_Data dic = DictionaryBLL.GetDicCollections("PDT_Grade")[m.Grade.ToString()];
                    if (dic != null)
                    {
                        GradeName = dic.Name;
                    }
                }

                if (m.TrafficPackaging > 0)
                {
                    Dictionary_Data dic = DictionaryBLL.GetDicCollections("PDT_Packaging")[m.TrafficPackaging.ToString()];
                    if (dic != null)
                    {
                        TrafficPackagingName = dic.Name;
                    }
                }
                if (m.Packaging > 0)
                {
                    Dictionary_Data dic = DictionaryBLL.GetDicCollections("PDT_Packaging")[m.Packaging.ToString()];
                    if (dic != null)
                    {
                        PackagingName = dic.Name;
                    }
                }
            }
            catch (System.Exception err)
            {
                LogWriter.WriteLog("MCSFramework.WSI.Product", err);
            }
            #endregion

            #region 获取首要图片
            string condition = " RelateType=11 AND RelateID=" + m.ID.ToString() + " AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',1)='Y'";
            IList <ATMT_Attachment> lists = ATMT_AttachmentBLL.GetModelList(condition);
            if (lists.Count > 0 && ATMT_AttachmentBLL.IsImage(lists[0].ExtName))
            {
                ImageGUID = lists[0].GUID;
            }
            #endregion

            #region 获取附件明细
            Atts = new List <Attachment>();
            IList <ATMT_Attachment> atts = ATMT_AttachmentBLL.GetAttachmentList(11, m.ID, new DateTime(1900, 1, 1), new DateTime(2100, 1, 1));
            foreach (ATMT_Attachment item in atts.OrderBy(p => p.Name))
            {
                Atts.Add(new Attachment(item));
            }
            #endregion
        }
コード例 #35
0
    private void Download(Guid guid)
    {
        ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(guid);
        if (bll.Model == null)
        {
            MessageBox.ShowAndRedirect(this, "指定ID的附件不存在,参数错误!", "desktop.aspx");
            return;
        }

        Response.Clear();
        Response.BufferOutput = true;

        #region 确定ContentType
        switch (bll.Model.ExtName.ToLower())
        {
            case "jpg":
            case "jpeg":
            case "jpe":
                Response.ContentType = "image/jpeg";
                break;
            case "gif":
                Response.ContentType = "image/gif";
                break;
            case "bmp":
                Response.ContentType = "image/bmp";
                break;
            case "png":
                Response.ContentType = "image/png";
                break;
            case "tiff":
            case "tif":
                Response.ContentType = "image/tiff";
                break;
            case "doc":
            case "docx":
                Response.ContentType = "application/ms-word";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                break;
            case "xls":
            case "xlsx":
                Response.ContentType = "application/ms-excel";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                break;
            case "ppt":
            case "pptx":
                Response.ContentType = "application/ms-powerpoint";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                break;
            case "pdf":
                Response.ContentType = "application/pdf";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                break;
            case "zip":
                Response.ContentType = "application/zip";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                break;
            case "rar":
                Response.ContentType = "application/rar";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                break;
            case "txt":
                Response.ContentType = "text/plain";
                break;
            case "htm":
            case "html":
                Response.ContentType = "text/html";
                break;
            default:
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(bll.Model.Name + "." + bll.Model.ExtName));
                break;
        }
        #endregion

        if (string.IsNullOrEmpty(bll.Model.Path))
        {
            byte[] data = bll.GetData();
            if (data != null) Response.OutputStream.Write(data, 0, data.Length);
        }
        else
        {
            string filepath = bll.Model.Path;

            if (filepath.StartsWith("~")) filepath = Server.MapPath(filepath);

            if (!File.Exists(filepath))
            {
                MessageBox.ShowAndRedirect(this, "附件在服务器上不存在!", "desktop.aspx");
                return;
            }
            Response.WriteFile(filepath);
        }

        Response.Flush();
        Response.End();
    }
コード例 #36
0
        /// <summary>
        /// 上传门店照片
        /// </summary>
        /// <param name="AuthKey"></param>
        /// <param name="ClientID">会员店ID,上传当前门店时可置0</param>
        /// <param name="PicName">图片名称(可选)</param>
        /// <param name="PicData">图片数据</param>
        /// <returns>大于0:成功 -1:会员店ID无效 -4:照片格式不正确</returns>
        public static int UploadRetailerPicture(UserInfo User, int ClientID, string PicName, string Description, string PicData, out Guid PicGUID)
        {
            PicGUID = Guid.Empty;
            LogWriter.WriteLog("PBMIFService.UploadRetailerPicture:UserName="******",ClientID=" + ClientID.ToString()
                + ",PicName=" + PicName + ",Description=" + Description + ",PicDataLength=" + PicData.Length);

            try
            {
                if (ClientID == 0 && User.ClientID > 0) ClientID = User.ClientID;

                CM_Client _c = new CM_ClientBLL(ClientID).Model;
                if (_c == null) return -1;

                if (string.IsNullOrEmpty(PicData)) return -4;
                byte[] buffer = Convert.FromBase64String(PicData);
                if (buffer.Length == 0 && buffer.Length > 1024 * 1024 * 10) return -4;

                ATMT_AttachmentBLL atm = new ATMT_AttachmentBLL();
                atm.Model.RelateType = 30;          //终端门店
                atm.Model.RelateID = ClientID;
                atm.Model.Name = string.IsNullOrEmpty(PicName) ? "门店照片" : PicName;
                atm.Model.ExtName = "jpg";          //默认为JPG图片
                atm.Model.FileSize = PicData.Length / 1024;
                atm.Model.Description = Description;
                atm.Model.UploadUser = User.UserName;
                atm.Model.IsDelete = "N";

                return atm.Add(buffer, out PicGUID);
            }
            catch (System.Exception err)
            {
                LogWriter.WriteLog("PBMIFService.UploadRetailerPicture Exception Error!", err);
                return -100;
            }
        }
コード例 #37
0
    private void DownPreViewImage(string Path, Guid guid)
    {
        ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(guid);

        if (bll.Model == null)
        {
            MessageBox.ShowAndRedirect(this, "指定ID的附件不存在,参数错误!", "desktop.aspx");
            return;
        }
        if (!ATMT_AttachmentBLL.IsImage(bll.Model.ExtName))
        {
            return;
        }

        string AttachmentPath = ConfigHelper.GetConfigString("AttachmentPath");

        if (string.IsNullOrEmpty(AttachmentPath))
        {
            AttachmentPath = "D:\\Attachment";
        }

        if (string.IsNullOrEmpty(bll.Model.Path))
        {
            byte[] data = bll.GetThumbnailData();
            if (data != null && data.Length > 0)
            {
                if (data != null)
                {
                    FileStream fs = File.Create(Path + "\\" + bll.Model.GUID + "." + bll.Model.ExtName);
                    fs.Write(data, 0, data.Length);
                    fs.Close();

                    SendAttachmentData(data, bll.Model.Name, bll.Model.ExtName);
                }
            }
            else
            {
                data = bll.GetData();
                if (data != null && data.Length > 0)
                {
                    #region 生成缩略图
                    Stream filestream          = new MemoryStream(data);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(filestream);
                    filestream.Close();

                    System.Drawing.Image preview = ImageProcess.MakeThumbnail(image, 0, 140, "H");

                    Stream prestream = new MemoryStream();
                    preview.Save(prestream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    prestream.Position = 0;

                    byte[] predata = new byte[prestream.Length];
                    prestream.Read(predata, 0, (int)prestream.Length);

                    bll.UploadThumbnailData(predata);

                    FileStream fs = File.Create(AttachmentPath + "\\" + "P_" + bll.Model.GUID + "." + bll.Model.ExtName);
                    fs.Write(predata, 0, predata.Length);
                    fs.Close();
                    #endregion

                    SendAttachmentData(data, bll.Model.Name, bll.Model.ExtName);
                }
            }
        }
        else
        {
            string filepath = "";

            if (bll.Model.Path.StartsWith("~"))
            {
                filepath = Server.MapPath(bll.Model.Path);
            }
            else
            {
                filepath = bll.Model.Path.Replace("/", "\\");
            }

            if (!File.Exists(filepath))
            {
                MessageBox.ShowAndRedirect(this, "附件在服务器上不存在!" + filepath, "desktop.aspx");
                return;
            }

            string filename         = filepath.Substring(filepath.LastIndexOf('\\') + 1);
            string previewimagepath = filepath.Substring(0, filepath.LastIndexOf('\\') + 1) + "Preview_" + filename; //取得缩略图文件名
            previewimagepath = previewimagepath.Substring(0, previewimagepath.LastIndexOf('.') + 1) + "jpg";         //将缩略图扩展名改为JPG

            if (!System.IO.File.Exists(previewimagepath))
            {
                ImageProcess.MakeThumbnail(filepath, previewimagepath, 0, 140, "H");
            }

            #region 从本地目录中加载图片
            byte[] data = File.ReadAllBytes(previewimagepath);

            string extname = "";
            int    p       = previewimagepath.LastIndexOf('.');
            if (p > 0)
            {
                extname = previewimagepath.Substring(p + 1);
            }

            SendAttachmentData(data, bll.Model.Name, extname);
            #endregion
        }
    }
コード例 #38
0
    protected void Upload(object sender, EventArgs e)
    {
        string filename = bt_UploadedImageFile.FileName;
        byte[] data = bt_UploadedImageFile.FileBytes;

        #region 写入新附件
        ATMT_AttachmentBLL atm = new ATMT_AttachmentBLL();

        atm.Model.RelateType = 75;
        atm.Model.Name = filename;
        atm.Model.ExtName = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();
        atm.Model.FileSize = data.Length / 1024;
        atm.Model.UploadUser = Session["UserName"].ToString();
        atm.Model.IsDelete = "N";
        int atm_id = atm.Add(data);
        if (atm_id > 0)
        {
            ddl_DirectoryList.SelectedIndex = 0;
            BindImageList();

            ImageList.SelectedValue = new ATMT_AttachmentBLL(atm_id).Model.GUID.ToString();
            SelectImage(null, null);
        }
        #endregion
    }
コード例 #39
0
    /// <summary>
    /// 将文件存放至指定目录
    /// </summary>
    /// <param name="downloadDir">文件指定存放目录</param>
    /// <param name="AttGUID">图片GUID编码</param>
    public void SaveImgToDisk(string downloadDir, Guid AttGUID)
    {
        ATMT_AttachmentBLL bll = new ATMT_AttachmentBLL(AttGUID);
        if (bll.Model == null || !ATMT_AttachmentBLL.IsImage(bll.Model.ExtName))
        {
            MessageBox.Show(this, "文件不存在或无文件类型" + AttGUID.ToString());
            return;
        }

        //创建文件名
        CM_Client client = new CM_ClientBLL(bll.Model.RelateID).Model;
        string fileName = client.FullName + "_" + client.Code + "_" + bll.Model.Name + "_" + bll.Model.UploadTime.ToString("yyyMMddHHmmss") + "." + bll.Model.ExtName;

        #region 替换不能包括的非法字符
        fileName = fileName.Replace("/", "");
        fileName = fileName.Replace("\\", "");
        fileName = fileName.Replace(":", "");
        fileName = fileName.Replace("*", "");
        fileName = fileName.Replace("?", "");
        fileName = fileName.Replace("<", "");
        fileName = fileName.Replace(">", "");
        fileName = fileName.Replace("|", "");
        fileName = fileName.Replace("\"", "");
        #endregion

        try
        {
            //数据库中存在该文件路径则直接从文件目录查找并移动
            if (!string.IsNullOrEmpty(bll.Model.Path))
            {
                string tempPath = bll.Model.Path.StartsWith("~") ? Server.MapPath(bll.Model.Path) : bll.Model.Path.Replace("/", "\\");
                string filename = bll.Model.Name + "." + bll.Model.ExtName;
                if (File.Exists(bll.Model.Path))
                {
                    File.Copy(tempPath, downloadDir + "\\" + fileName);
                    return;
                }
            }
            else//读取二进制流并生成文件
            {
                byte[] data = bll.GetData();
                if (data != null)
                {
                    FileStream fs = File.Create(downloadDir + "\\" + fileName);
                    fs.Write(data, 0, data.Length);
                    fs.Close();
                    return;
                }
            }
        }
        catch { }
    }