コード例 #1
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
    }
コード例 #2
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
    }
コード例 #3
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;
            }
        }
コード例 #4
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;
            }
        }
コード例 #5
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);
        }
    }
コード例 #6
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);
        }
    }