//方法2
        /// <summary>
        /// 图片保存到数据库
        /// </summary>
        /// <param name="UP_FILE1"></param>
        public void SavePicToDB(System.Web.UI.WebControls.FileUpload UP_FILE1)
        {
            HttpPostedFile UpFile     = UP_FILE1.PostedFile;       //HttpPostedFile对象,用于读取图象 文件属性
            Int64          FileLength = UpFile.InputStream.Length; //记录文件长度变量

            try
            {
                if (FileLength == 0)
                {   //文件长度为零时
                    JsHelper.MsgBox("请选择图片");
                }
                else
                {
                    Byte[] FileByteArray = new Byte[FileLength];               //图象文件临时储存Byte数组
                    Stream StreamObject  = UpFile.InputStream;                 //建立数据流对像
                    //读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
                    StreamObject.Read(FileByteArray, 0, UpFile.ContentLength); //建立SQL Server链接

                    SqlHelper.SqlCheckIsExists("SQL语句");
                    JsHelper.MsgBox("你已经成功上传你的图片");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
    /// <summary>
    /// 上传图片(传递控件)
    /// </summary>
    /// <param name="myFile">控件名称</param>
    /// <param name="myFileName">文件名称</param>
    /// <param name="myFileSize">文件大小(M)</param>
    /// <param name="myFileType">允许上传的文件类别</param>
    /// <param name="mySaveDirectory">文件保存路径</param>
    /// <param name="file_fg">如果文件存在是否覆盖,TRUE覆盖,FALSE不覆盖</param>
    public static bool myUpFile(System.Web.UI.WebControls.FileUpload myFile, string myFileName, int myFileSize, string myFileType, string mySaveDirectory, string file_fg)
    {
        try
        {
            //判断文件是否存在或有数据
            if (myFile.PostedFile.ContentLength <= 0)
            {
                JsHelper.MsgBox("请选择您要上传的图片!");
                return(false);
            }

            //判断文件是否超过限制
            if (myFile.PostedFile.ContentLength / 1048576d > myFileSize)
            {
                JsHelper.MsgBox("上传的文件不能超过 " + myFileSize.ToString() + "M!");
                return(false);
            }

            //判断文件类别是否允许上传
            string myType = System.IO.Path.GetExtension(myFile.PostedFile.FileName).Substring(1).ToLower();
            if (myFileType.IndexOf(myType) < 0)
            {
                JsHelper.MsgBox("对不起,只允许 " + myFileType + " 类别的文件上传!");
                return(false);
            }

            //判断文件夹是否存在
            if (!Directory.Exists(mySaveDirectory))
            {
                Directory.CreateDirectory(mySaveDirectory);
            }

            //获取文件物理路径
            string mySaveFile = mySaveDirectory + myFileName;
            //判断文件是否存在
            if (System.IO.File.Exists(mySaveFile))
            {
                if (file_fg == "FALSE")
                {
                    JsHelper.MsgBox("文件已经存在,请选择其它要上传的文件!");
                    return(false);
                }
            }
            myFile.PostedFile.SaveAs(mySaveFile);
            return(true);
        }
        catch (Exception ex)
        {
            JsHelper.MsgBox(ex.Message);
            return(false);
        }
    }
Exemple #3
0
        /// <summary>
        /// 检测附件大小
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private bool Attachment_MaiInit(string path)
        {
            FileStream_my = new FileStream(path, FileMode.Open);
            string name = FileStream_my.Name;
            int    size = (int)(FileStream_my.Length / 1024 / 1024);

            FileStream_my.Close();
            //控制文件大小不大于10M
            if (size > 10)
            {
                JsHelper.MsgBox("文件长度不能大于10M!你选择的文件大小为" + size.ToString() + "M");
                return(false);
            }
            return(true);
        }
    /// <summary>
    /// 判断是否可用资源文件
    /// </summary>
    /// <returns></returns>
    public static bool IsEnroll()
    {
        DateTime nowDate = DateTime.Parse(CommonDAL.GetServerDate(""));
        DateTime endDate = DateTime.Parse("2015-12-25");

        int haha = DateTime.Compare(endDate, nowDate);

        if (haha > 0)
        {
            return(true);
        }
        else
        {
            JsHelper.MsgBox("DoNetFrame is null,引用为空,无法判断其引用地址!  请联系软件原著作者!");
            JsHelper.MsgBox("DoNetFrame is null,引用为空!使用了非法的操作!");
            return(false);
        }
    }
Exemple #5
0
        /// <summary>
        /// 发送邮件1
        /// </summary>
        /// <param name="sendto">发送给对方邮箱名称</param>
        /// <param name="title">标题</param>
        /// <param name="text">内容</param>
        /// <param name="attachPath">附件地址</param>
        /// <returns></returns>
        public bool SendeMail(string sendto, string title, string text, string attachPath = "")
        {
            string mailserver     = ConfigHelper.GetAppStr("mailserver");
            string mailserverUser = ConfigHelper.GetAppStr("mailusername");
            string mailserverPass = ConfigHelper.GetAppStr("mailpassword");

            //检测附件大小 发件必需小于10M 否则返回  不会执行以下代码
            if (attachPath != "")
            {
                if (!Attachment_MaiInit(attachPath))
                {
                    return(false);
                }
            }

            try
            {
                SetSmtpClient(mailserver);//初始化Smtp服务器信息
            }
            catch (Exception Ex)
            {
                JsHelper.MsgBox("邮件发送失败,请确定SMTP服务名是否正确!");
                return(false);
            }

            try
            {
                SetAddressform(mailserverUser, mailserverPass);//验证发件邮箱地址和密码
            }
            catch (Exception Ex)
            {
                JsHelper.MsgBox("邮件发送失败,请确定发件邮箱地址和密码的正确性!");
                return(false);
            }

            try
            {
                MailMessage_Mai.To.Clear();             //清空历史发送信息 以防发送时收件人收到的错误信息(收件人列表会不断重复)
                MailAddress_to = new MailAddress(sendto);
                MailMessage_Mai.To.Add(MailAddress_to); //添加收件人邮箱地址
                //发件人邮箱
                MailMessage_Mai.From = MailAddress_from;
                //邮件主题
                MailMessage_Mai.Subject         = title;
                MailMessage_Mai.SubjectEncoding = System.Text.Encoding.UTF8;
                //邮件正文
                MailMessage_Mai.Body         = text;
                MailMessage_Mai.BodyEncoding = System.Text.Encoding.UTF8;
                //清空历史附件  以防附件重复发送
                MailMessage_Mai.Attachments.Clear();
                //添加附件
                if (attachPath != "")
                {
                    MailMessage_Mai.Attachments.Add(new Attachment(attachPath, MediaTypeNames.Application.Octet));
                }
                //注册邮件发送完毕后的处理事件
                //SmtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
                //开始发送邮件
                //SmtpClient.SendAsync(MailMessage_Mai, "000000");
                SmtpClient.Send(MailMessage_Mai);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(true);
        }