private void AttachFile(HttpContext context)
        {
            string _upfilepath = context.Request.QueryString["UpFilePath"]; //取得上传的对象名称
            HttpPostedFile _upfile = context.Request.Files[_upfilepath];
            bool _iswater = false; //默认不打水印
            bool _isthumbnail = false; //默认不生成缩略图

            if (_upfile == null)
            {
                context.Response.Write("{\"msg\": 0, \"msgbox\": \"请选择要上传文件!\"}");
                return;
            }
            UpLoad upFiles = new UpLoad();
            string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, false, true);
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }
 private void EditorFile(HttpContext context)
 {
     bool _iswater = false; //默认不打水印
     if (context.Request.QueryString["IsWater"] == "1")
         _iswater = true;
     HttpPostedFile imgFile = context.Request.Files["imgFile"];
     if (imgFile == null)
     {
         showError(context, "请选择要上传文件!");
         return;
     }
     UpLoad upFiles = new UpLoad();
     string remsg = upFiles.fileSaveAs(imgFile, false, _iswater);
     //string pattern = @"^{\s*msg:\s*(.*)\s*,\s*msgbox:\s*\""(.*)\""\s*}$"; //键名前和键值前后都允许出现空白字符
     //Regex r = new Regex(pattern, RegexOptions.IgnoreCase); //正则表达式实例,不区分大小写
     //Match m = r.Match(remsg); //搜索匹配项
     //string msg = m.Groups[1].Value; //msg的值,正则表达式中第1个圆括号捕获的值
     //string msgbox = m.Groups[2].Value; //msgbox的值,正则表达式中第2个圆括号捕获的值
     JsonData jd = JsonMapper.ToObject(remsg);
     string msg = jd["msg"].ToString();
     string msgbox = jd["msgbox"].ToString();
     if (msg == "0")
     {
         showError(context, msgbox);
         return;
     }
     Hashtable hash = new Hashtable();
     hash["error"] = 0;
     hash["url"] = msgbox;
     context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
     context.Response.Write(JsonMapper.ToJson(hash));
     context.Response.End();
 }
        private void SingleFile(HttpContext context)
        {
            string _refilepath = DTRequest.GetQueryString("ReFilePath"); //取得返回的对象名称
            string _upfilepath = DTRequest.GetQueryString("UpFilePath"); //取得上传的对象名称
            string _delfile = DTRequest.GetString(_refilepath);
            HttpPostedFile _upfile = context.Request.Files[_upfilepath];
            bool _iswater = false; //默认不打水印
            bool _isthumbnail = false; //默认不生成缩略图
            bool _isimage = false; //默认不限制图片上传

            if (DTRequest.GetQueryString("IsWater") == "1")
                _iswater = true;
            if (DTRequest.GetQueryString("IsThumbnail") == "1")
                _isthumbnail = true;
            if (DTRequest.GetQueryString("IsImage") == "1")
                _isimage = true;

            if (_upfile == null)
            {
                context.Response.Write("{\"msg\": 0, \"msgbox\": \"请选择要上传文件!\"}");
                return;
            }
            UpLoad upFiles = new UpLoad();
            string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, _isimage);
            //删除已存在的旧文件
            Utils.DeleteUpFile(_delfile);
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }
        public void Register(string name, string password, string phoneNum, string authCode, string tourCard, string identityCard, int age, int workAge, int sex, int work, string signature, string headImage, string version, string equType, string equName)
        {
            //, byte[] headImage
            string json = String.Empty;
            int result = bll_user.CheckRegister(phoneNum, tourCard, identityCard);
            if (result == 0)
            {
                string pass = DESEncrypt.Encrypt(password); //密码加密
                string onlyCode = ""; //唯一码
                string nickNameStr = ""; //用户登录账号
                try
                {
                    int number = bll_user.GetOnlyCodeNumber();
                    onlyCode = number.ToString();//.PadLeft(6, '0');
                    nickNameStr = "sxzh" + number.ToString();
                    //bll_user.ModifyOnlyCodeStatus(number);
                }
                catch (Exception ex)
                {
                    json = "{\"status\":\"false\",\"data\":\"" + ex.Message + "\"}";
                }

                string nameStr = System.Web.HttpUtility.UrlDecode(name, System.Text.Encoding.UTF8);
                string sStr = "";
                if (signature != "")
                {
                    sStr = System.Web.HttpUtility.UrlDecode(signature, System.Text.Encoding.UTF8);
                }
                try
                {
                    Model.users model_guide = new Model.users();
                    model_guide.nick_name = nameStr;//用户姓名
                    model_guide.user_name = nickNameStr;//用户昵称sxzh_123 唯一用来登录
                    model_guide.password = pass;
                    model_guide.mobile = phoneNum;
                    model_guide.telphone = phoneNum;
                    model_guide.authcode = authCode;
                    model_guide.guid_card = tourCard;
                    model_guide.card = identityCard;
                    model_guide.age = age;
                    model_guide.work_age = workAge.ToString();
                    model_guide.sex = sex == 1 ? "男" : "女";
                    model_guide.work_type = workAge;
                    model_guide.description = sStr;
                    model_guide.onlycode = onlyCode;
                    model_guide.avatar = "";
                    model_guide.is_lock = 2;//待审核
                    model_guide.group_id = 2;//默认为五星导游
                    if (!string.IsNullOrEmpty(headImage))
                    {
                        UpLoad _uploadHelper = new UpLoad();
                        //1.定义并实例化一个内存流,以存放提交上来的字节数组。
                        ///2.定义实际文件对象,保存上载的文件。
                        model_guide.avatar = _uploadHelper.Base64ToImg(headImage);
                    }
                    int count = bll_user.Add(model_guide);
                    if (count > 0)
                    {
                        json += "{\"status\":\"true\"}";
                    }
                    else
                    {
                        json += "{\"status\":\"false\"}";
                    }
                }
                catch (Exception ex)
                {
                    json = "{\"status\":\"false\",\"data\":\"" + ex.Message + "\"}";
                }
            }
            else
                if (result == 2) //手机号已注册
                {
                    json = "{\"status\":\"false\",\"data\":\"手机号已注册\"}";
                }
                else
                    if (result == 3) //导游证已注册
                    {
                        json = "{\"status\":\"false\",\"data\":\"导游证已注册\"}";
                    }
                    else
                        if (result == 4) //身份证已注册
                        {
                            json = "{\"status\":\"false\",\"data\":\"身份证已注册\"}";
                        }
            WriteWebServiceLog(version, equType, equName, "Register", "");
            Context.Response.Write(json);
            Context.Response.End();
        }
        /// <summary>
        /// 将简单编码转换成二进制串并存入文件
        /// </summary>
        /// <param name="strData">编码串(0123456789ABCDEF)</param>
        /// <returns></returns>
        private string SaveImage(string strData)
        {
            int nLength = strData.Length / 2;
            byte[] byteData = new byte[nLength];
            for (int i = 0; i < nLength; i++)
            {
                byteData[i] = (byte)(Char2Int(strData[i * 2]) * 16 + Char2Int(strData[i * 2 + 1]));
            }
            UpLoad _uploadHelper = new UpLoad();
            string _temp = _uploadHelper.BytesToImg(byteData);

            return _temp;
        }
        public void PublishUsedGood_Andriod2(string title, string type, string quantity, string price, string description, string userId, string mobilephone, string imgarr1, string imgarr2, string imgarr3, string imgarr4, string version, string equType, string equName)
        {
            byte[] byte_img1 = Encoding.UTF8.GetBytes(imgarr1.Replace(" ", "").Replace("<", "").Replace(">", "") + "");//imgdata.Replace(" ", "").Replace("<", "").Replace(">", "")
            byte[] byte_img2 = Encoding.UTF8.GetBytes(imgarr2.Replace(" ", "").Replace("<", "").Replace(">", "") + "");
            byte[] byte_img3 = Encoding.UTF8.GetBytes(imgarr3.Replace(" ", "").Replace("<", "").Replace(">", "") + "");
            byte[] byte_img4 = Encoding.UTF8.GetBytes(imgarr4.Replace(" ", "").Replace("<", "").Replace(">", "") + "");

            string json_result = string.Empty;
            if (string.IsNullOrEmpty(title))
            {
                json_result = "{\"status\":\"false\",\"data\":\"title参数不能为空!\"}";
                Context.Response.Write(json_result);
                Context.Response.End();
                return;
            }
            //变量处理
            int _type = 0, _userId = 0, _quantity = 0;
            decimal _price = 0;

            int.TryParse(type, out _type);
            int.TryParse(quantity, out _quantity);
            int.TryParse(userId, out _userId);
            decimal.TryParse(price, out _price);

            try
            {

                bool result = true;
                Model.article_goods model = new Model.article_goods();
                model.channel_id = (int)DTEnums.ChannelEnum.goods;
                model.title = title;
                model.category_id = _type;
                model.stock_quantity = _quantity;
                model.market_price = _price;
                model.sell_price = _price;
                model.content = description;
                model.user_id = _userId;
                model.add_time = DateTime.Now;
                model.goods_no = mobilephone;
                model.img_url = "";
                //处理图片组

                //定义一个字节数组
                List<byte[]> lst_img = new List<byte[]>();

                if (byte_img1.Length > 0)
                {
                    lst_img.Add(byte_img1);
                }
                if (byte_img2.Length > 0)
                {
                    lst_img.Add(byte_img2);
                }
                if (byte_img3.Length > 0)
                {
                    lst_img.Add(byte_img3);

                }
                if (byte_img4.Length > 0)
                {
                    lst_img.Add(byte_img4);
                }

                if (lst_img.Count > 0)
                {
                    UpLoad _uploadHelper = new UpLoad();
                    List<Model.article_albums> _ls_albums = new List<Model.article_albums>();

                    string _temp = string.Empty;
                    for (int i = 0; i < lst_img.Count; i++)
                    {
                        _temp = _uploadHelper.BytesToImg(lst_img[i]);
                        if (_temp == null)
                        {
                            Context.Response.Write("{\"status\":\"false\",\"data\":\"上传图片过程中发生意外!\"}");
                            Context.Response.End();
                            return;
                        }
                        //图片上传处理(存入相册中)
                        _ls_albums.Add(new Model.article_albums
                        {
                            big_img = _temp,
                            small_img = _temp,
                            remark = ""
                        });
                        model.img_url = _temp;
                    }
                    model.albums = _ls_albums;

                }

                model.link_url = "";
                model.is_red = 0;
                model.is_slide = 0;
                model.is_top = 0;
                model.sort_id = 99;
                model.add_time = DateTime.Now;

                if (bll_article.Add(model) < 1)
                {
                    json_result = "{\"status\":\"false\",\"data\":\"添加失败!\"}";
                }
                else
                {
                    json_result = "{\"status\":\"true\",\"data\":\"添加成功!\"}";
                }

            }
            catch (Exception ex)
            {
                json_result = "{\"status\":\"false\",\"data\":\"" + ex.Message + "\"}";
            }
            WriteWebServiceLog(version, equType, equName, "PublishUsedGood_Andriod2", "");
            Context.Response.Write(json_result);
            Context.Response.End();
        }
        public void PublishUsedGood_Andriod(string title, string type, string quantity, string price, string description, string userId, string mobilephone, string imgarr, string version, string equType, string equName)
        {
            string json_result = string.Empty;
            if (string.IsNullOrEmpty(title))
            {
                json_result = "{\"status\":\"false\",\"data\":\"title参数不能为空!\"}";
                Context.Response.Write(json_result);
                Context.Response.End();
                return;
            }
            //变量处理
            int _type = 0, _userId = 0, _quantity = 0;
            decimal _price = 0;

            int.TryParse(type, out _type);
            int.TryParse(quantity, out _quantity);
            int.TryParse(userId, out _userId);
            decimal.TryParse(price, out _price);

            try
            {

                bool result = true;
                Model.article_goods model = new Model.article_goods();
                model.channel_id = (int)DTEnums.ChannelEnum.goods;
                model.title = title;
                model.category_id = _type;
                model.stock_quantity = _quantity;
                model.market_price = _price;
                model.sell_price = _price;
                model.content = description;
                model.user_id = _userId;
                model.add_time = DateTime.Now;
                model.goods_no = mobilephone;
                model.img_url = "";
                //处理图片组
                if (!string.IsNullOrEmpty(imgarr.Trim()))
                {
                    UpLoad _uploadHelper = new UpLoad();
                    List<Model.article_albums> _ls_albums = new List<Model.article_albums>();
                    string[] arr_img = imgarr.Split('|');
                    string _temp = string.Empty;
                    for (int i = 0; i < arr_img.Length; i++)
                    {
                        _temp = _uploadHelper.Base64ToImg(arr_img[i]);
                        if (_temp == null)
                        {
                            Context.Response.Write("{\"status\":\"false\",\"data\":\"上传图片过程中发生意外!\"}");
                            Context.Response.End();
                            return;
                        }
                        //图片上传处理(存入相册中)
                        _ls_albums.Add(new Model.article_albums
                        {
                            big_img = _temp,
                            small_img = _temp,
                            remark = ""
                        });
                        model.img_url = _temp;
                    }
                    model.albums = _ls_albums;

                }

                model.link_url = "";
                model.is_red = 0;
                model.is_slide = 0;
                model.is_top = 0;
                model.sort_id = 99;
                model.add_time = DateTime.Now;

                if (bll_article.Add(model) < 1)
                {
                    json_result = "{\"status\":\"false\",\"data\":\"发布失败!\"}";
                }
                else
                {
                    json_result = "{\"status\":\"true\",\"data\":\"发布成功!\"}";
                }
            }
            catch (Exception ex)
            {
                json_result = "{\"status\":\"false\",\"data\":\"" + ex.Message + "\"}";
            }
            WriteWebServiceLog(version, equType, equName, "PublishUsedGood_Andriod", "");
            Context.Response.Write(json_result);
            Context.Response.End();
        }
        public void PersonalMessage(string username, string name, string phoneNum, string tourCard, string identityCard, string age, string work, string signature, string headImage, string version, string equType, string equName)
        {
            string json = String.Empty;

            string nameStr = System.Web.HttpUtility.UrlDecode(name, System.Text.Encoding.UTF8);
            string sStr = "";
            if (signature != "")
            {
                sStr = System.Web.HttpUtility.UrlDecode(signature, System.Text.Encoding.UTF8);
            }
            try
            {
                Model.users model_guide = bll_user.GetModel(username);
                if (model_guide == null)
                {
                    //用户名或密码错误
                    json = "{\"status\":\"false\",\"data\":\"用户名不存在\"}";
                    Context.Response.Write(json);
                    Context.Response.End();
                    return;
                }

                model_guide.nick_name = nameStr;

                model_guide.mobile = phoneNum;
                model_guide.telphone = phoneNum;

                model_guide.guid_card = tourCard;
                model_guide.card = identityCard;
                model_guide.age = int.Parse(age);
                model_guide.work_age = work;

                model_guide.description = sStr;
                if (!string.IsNullOrEmpty(headImage))
                {
                    if (File.Exists(Server.MapPath(model_guide.avatar)))
                    {
                        //如果存在则删除
                        File.Delete(HttpContext.Current.Server.MapPath(model_guide.avatar));
                    }
                    UpLoad _uploadHelper = new UpLoad();

                    ///2.定义实际文件对象,保存上载的文件。
                    model_guide.avatar = _uploadHelper.Base64ToImg(headImage);
                }

                bll_user.Update(model_guide);

                json = "{\"status\":\"true\",\"imageurl\":\"" + this.webUrl + model_guide.avatar + "\"}";
            }
            catch (Exception ex)
            {
                json = "{\"status\":\"false\",\"data\":\"" + ex.Message + "\"}";
            }
            WriteWebServiceLog(version, equType, equName, "PersonalMessage", "");
            Context.Response.Write(json);
            Context.Response.End();
        }
        public void ModifyUsedGood(int usedBuyID, string title, string type, string quantity, string price, string description, string userId, string mobilephone, string imgarr, string version, string equType, string equName)
        {
            string json_result = string.Empty;
            if (usedBuyID == 0)
            {
                json_result = "{\"status\":\"false\",\"data\":\"ID不能为0!\"}";
                Context.Response.Write(json_result);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
                return;
            }
            if (string.IsNullOrEmpty(title))
            {
                json_result = "{\"status\":\"false\",\"data\":\"title内容不能为空!\"}";
                Context.Response.Write(json_result);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
                return;
            }
            //变量处理
            int _type = 0, _userId = 0, _quantity = 0;
            decimal _price = 0;

            int.TryParse(type, out _type);
            int.TryParse(quantity, out _quantity);
            int.TryParse(userId, out _userId);
            decimal.TryParse(price, out _price);

            try
            {
                Model.article_goods model = bll_article.GetGoodsModel(usedBuyID);
                if (model == null)
                {
                    json_result = "{\"status\":\"false\",\"data\":\"删除的数据已不存在!\"}";
                    Context.Response.Write(json_result);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    return;
                }
                //model.channel_id = (int)DTEnums.ChannelEnum.goods;
                model.title = title;
                model.category_id = _type;
                model.stock_quantity = _quantity;
                model.market_price = _price;
                model.sell_price = _price;
                model.content = description;
                //model.user_id = _userId;
                // model.add_time = DateTime.Now;
                model.goods_no = mobilephone;
                model.img_url = "";
                //处理图片组
                if (!string.IsNullOrEmpty(imgarr.Trim()))
                {
                    UpLoad _uploadHelper = new UpLoad();
                    List<Model.article_albums> _ls_albums = new List<Model.article_albums>();
                    string[] arr_img = imgarr.Split('|');
                    string _temp = string.Empty;
                    for (int i = 0; i < arr_img.Length; i++)
                    {
                        _temp = _uploadHelper.Base64ToImg(arr_img[i]);
                        if (_temp == null)
                        {
                            Context.Response.Write("{\"status\":\"false\",\"data\":\"上传图片过程中发生意外!\"}");
                            Context.Response.End();
                            return;
                        }
                        //图片上传处理(存入相册中)
                        _ls_albums.Add(new Model.article_albums
                        {
                            article_id = usedBuyID,
                            big_img = _temp,
                            small_img = _temp,
                            remark = ""
                        });
                        model.img_url = _temp;
                    }
                    model.albums = _ls_albums;

                }

                if (!bll_article.Update(model))
                {
                    json_result = "{\"status\":\"false\",\"data\":\"修改失败!\"}";
                }
                else
                {
                    json_result = "{\"status\":\"true\",\"data\":\"修改成功!\"}";
                }

            }
            catch (Exception ex)
            {
                json_result = "{\"status\":\"false\",\"data\":\"" + ex.Message + "\"}";
            }
            WriteWebServiceLog(version, equType, equName, "ModifyUsedGood", "");
            Context.Response.Write(json_result);
            Context.Response.End();
        }
        private void user_avatar_crop(HttpContext context)
        {
            //检查用户是否登录
            Model.users model = new BasePage().GetUserInfo();
            if (model == null)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,用户没有登录或登录超时啦!\"}");
                return;
            }
            string fileName = DTRequest.GetFormString("hideFileName");
            int x1 = DTRequest.GetFormInt("hideX1");
            int y1 = DTRequest.GetFormInt("hideY1");
            int w = DTRequest.GetFormInt("hideWidth");
            int h = DTRequest.GetFormInt("hideHeight");
            //检查是否图片

            //检查参数
            if (!Utils.FileExists(fileName) || w == 0 || h == 0)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,请先上传一张图片!\"}");
                return;
            }
            //取得保存的新文件名
            UpLoad upFiles = new UpLoad();
            bool result = upFiles.cropSaveAs(fileName, fileName, 180, 180, w, h, x1, y1);
            if (!result)
            {
                context.Response.Write("{\"msg\": 0, \"msgbox\": \"图片裁剪过程中发生意外错误!\"}");
                return;
            }
            //删除原用户头像
            Utils.DeleteFile(model.avatar);
            model.avatar = fileName;
            //修改用户头像
            new BLL.users().UpdateField(model.id, "avatar='" + model.avatar + "'");
            context.Response.Write("{\"msg\": 1, \"msgbox\": \"" + model.avatar + "\"}");
            return;
        }