Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string Act           = HTTPRequest.GetString("Act");
            int    ReCode        = 0;
            int    CertificateID = HTTPRequest.GetInt("CertificateID", 0);
            string uCode_tem     = HTTPRequest.GetString("c");

            if (uCode_tem.Trim() != "")
            {
                //username|pwd
                uCode_tem = DES.Decode(uCode_tem, config.Passwordkey);
                if (uCode_tem.Trim() != "")
                {
                    string[] uCode_temArr = Utils.SplitString(uCode_tem, "|");
                    if (uCode_temArr != null)
                    {
                        this.userid = tbUserInfo.CheckPassword(uCode_temArr[0], uCode_temArr[1], false);
                    }
                }
            }
            if (this.userid > 0)
            {
                if (Page.Request.InputStream != null)
                {
                    string PathStr = "/ufile/" + DateTime.Now.Year + "-" + DateTime.Now.Month;
                    string PicData = HTTPRequest.GetString("PicData");
                    string filestr;
                    int    picsize = 0;
                    int    picID   = 0;

                    string          sCode    = Utils.GetRanDomCode();
                    string          _PathStr = HttpContext.Current.Server.MapPath("/") + PathStr;
                    FileExtension[] fe       = { FileExtension.GIF, FileExtension.JPG, FileExtension.PNG, FileExtension.BMP };
                    if (!Directory.Exists(_PathStr))
                    {
                        Directory.CreateDirectory(_PathStr);
                    }
                    filestr = _PathStr + "/" + sCode + ".jpg";

                    try
                    {
                        if (FileValidation.IsAllowedExtension(new MemoryStream(Convert.FromBase64String(PicData)), fe))
                        {
                            Thumbnail.SaveBmp(Thumbnail.BytesToImage(Convert.FromBase64String(PicData)), filestr);

                            FileStream stream = new FileStream(filestr, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                            try
                            {
                                picsize = int.Parse(stream.Length.ToString());
                            }
                            finally
                            {
                                stream.Close();
                                stream.Dispose();
                            }
                            CertificatePicInfo cpi = new CertificatePicInfo();
                            try
                            {
                                cpi.UserID        = userid;
                                cpi.cCode         = Utils.GetRanDomCode();
                                cpi.CertificateID = CertificateID;
                                cpi.cPic          = PathStr + "/" + sCode + ".jpg";;
                                cpi.cAppendTime   = DateTime.Now;

                                picID = Certificates.AddCertificatePicInfo(cpi);
                                if (picID > 0)
                                {
                                    eStr   = "<re picid=\"" + picID.ToString() + "\" />";
                                    ReCode = 0;
                                }
                            }
                            finally
                            {
                                cpi = null;
                            }
                        }
                        else
                        {
                            eStr   = "<error>数据错误</error>";
                            ReCode = 4;
                        }
                    }
                    catch
                    {
                        try
                        {
                            HttpFileCollection files = HttpContext.Current.Request.Files;
                            try
                            {
                                if (files.Count > 0)
                                {
                                    HttpPostedFile postedFile = files[0];
                                    int            upLength   = postedFile.ContentLength;
                                    byte[]         upArray    = new Byte[upLength];
                                    Stream         upStream   = postedFile.InputStream;
                                    upStream.Read(upArray, 0, upLength);

                                    if (FileValidation.IsAllowedExtension(new MemoryStream(upArray), fe))
                                    {
                                        Thumbnail.SaveBmp(Thumbnail.BytesToImage(upArray), filestr);

                                        FileStream stream = new FileStream(filestr, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                                        try
                                        {
                                            picsize = int.Parse(stream.Length.ToString());
                                        }
                                        finally
                                        {
                                            stream.Close();
                                            stream.Dispose();
                                        }
                                        CertificatePicInfo cpi = new CertificatePicInfo();
                                        try
                                        {
                                            cpi.UserID        = userid;
                                            cpi.cCode         = Utils.GetRanDomCode();
                                            cpi.CertificateID = CertificateID;
                                            cpi.cPic          = PathStr + "/" + sCode + ".jpg";;
                                            cpi.cAppendTime   = DateTime.Now;

                                            picID = Certificates.AddCertificatePicInfo(cpi);
                                            if (picID > 0)
                                            {
                                                eStr   = "<re picid=\"" + picID.ToString() + "\" />";
                                                ReCode = 0;
                                            }
                                        }
                                        finally
                                        {
                                            cpi = null;
                                        }
                                    }
                                }
                            }
                            finally
                            {
                                files = null;
                            }
                        }
                        catch (Exception ex)
                        {
                            eStr   = "<error>" + ex.Message.ToString() + "</error>";
                            ReCode = 3;
                        }
                    }
                }
                else
                {
                    eStr   = "<error>数据校验失败</error>";
                    ReCode = 4;
                }
            }
            else
            {
                eStr   = "<error>鉴权失败</error>";
                ReCode = 4;
            }
            ReMsg(ReCode);
        }