Exemplo n.º 1
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        public void BinderData()
        {
            int sourceCount = 0;
            List <Expression <Func <FD_SaleSource, bool> > > parmList = new List <Expression <Func <FD_SaleSource, bool> > >();
            Expression <Func <FD_SaleSource, DateTime?> >    Order    = c => c.CreateDate;

            if (!string.IsNullOrEmpty(Request["txtSourceName"]))
            {
                string name = Request["txtSourceName"].ToString();
                parmList.Add(c => c.SourceName.Contains(name));
            }

            if (ddlSaleType.SelectedValue.ToInt32() > 0)
            {
                parmList.Add(c => c.SaleTypeId.ToString() == ddlSaleType.SelectedValue);
            }

            var DataList = _saleSourceService.GetPagedList <DateTime?>(CtrPageIndex.CurrentPageIndex, CtrPageIndex.PageSize, ref sourceCount, parmList, Order, false);

            CtrPageIndex.RecordCount = sourceCount;
            foreach (var item in DataList)
            {
                item.letter = PinYin.GetFirstLetter(item.SourceName);
                _saleSourceService.Update(item);
            }
            SavePage(CtrPageIndex);
            repSaleSource.DataSource = DataList;
            repSaleSource.DataBind();
        }
Exemplo n.º 2
0
        public AjaxMessage CreateSaleSource(FD_SaleSource saleSource)
        {
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            ajax.Message   = "";
            try
            {
                if (saleSource != null)
                {
                    saleSource.CreateDate     = DateTime.Now;
                    saleSource.CreateEmployee = LoginInfo.UserInfo.EmployeeId;
                    saleSource.Status         = (byte)SysStatus.Enable;
                    saleSource.letter         = PinYin.GetFirstLetter(saleSource.SourceName);

                    var result = _SaleSourceSerrvice.Add(saleSource);
                    if (result != null)
                    {
                        ajax.Message   = "添加成功";
                        ajax.IsSuccess = true;
                    }
                }
            }
            catch (Exception e)
            {
                ajax.Message = e.Message;
            }
            return(ajax);
        }
Exemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string zi    = context.Request["zi"];
            int    count = Convert.ToInt32(context.Request["count"]);

            List <Books> list = (List <Books>)CacheHelper.GetCache("books");

            if (list == null)
            {
                list = bbl.GetModelList("");
                CacheHelper.SetCache("books", list);
            }
            PinYin p     = new PinYin();
            var    books = list.Where(b => p.GetFirstLetter(b.Title).Contains(zi.ToUpper())).Take(count);

            //每次搜索之后都要将搜索的字存到数据库中
            SearchDetails sd = new SearchDetails()
            {
                KeyWords       = zi,
                SearchDateTime = DateTime.Now
            };

            new SearchDetailsBll().Add(sd);
            //序列化
            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            string json = jss.Serialize(books);

            //输出
            context.Response.Write(json);
        }
Exemplo n.º 4
0
        public AjaxMessage InsertHotel(FD_Hotel hotel)
        {
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            ajax.Message   = "";
            if (hotel != null)
            {
                bool isExists = _hotelService.IsExists(hotel.HotelName);
                if (isExists == false)          //酒店不存在  就新增
                {
                    hotel.CreateDate = DateTime.Now;
                    hotel.Letter     = PinYin.GetFirstLetter(hotel.HotelName.ToString());
                    hotel.Status     = (byte)SysStatus.Enable;

                    int result = _hotelService.Insert(hotel);
                    if (result > 0)
                    {
                        ajax.IsSuccess = true;
                        ajax.Message   = "添加成功";
                    }
                }
                else
                {
                    ajax.Message = "酒店名称已经存在";
                }
            }

            return(ajax);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 封装对象
        /// </summary>
        private UserInfo FengZhuangDuiXiang_UserInfo()
        {
            UserInfo objUserInfo = new UserInfo()
            {
                人员编号     = this.txtUserID.Text.Trim(),
                姓名       = this.txtName.Text.Trim(),
                性别       = this.cmbSex.Text.Trim(),
                出生日期     = Convert.ToDateTime(this.txtBirthday.Text.Trim()),
                身份证号     = this.txtIDNumber.Text.Trim(),
                参加工作日期   = Convert.ToDateTime(this.txtWorkingDate.Text.Trim()),
                加入华能系统日期 = Convert.ToDateTime(this.txtJoinHNDate.Text.Trim()),
                加入本单位日期  = Convert.ToDateTime(this.txtJoinOurEnterpriseDate.Text.Trim()),
                入职原因     = this.cmbRuZhiYuanYin.SelectedIndex == -1 ? null : this.cmbRuZhiYuanYin.SelectedValue.ToString(),
                入职学历     = this.cmbRuZhiXueLi.SelectedIndex == -1 ? null : this.cmbRuZhiXueLi.SelectedValue.ToString(),
                工资标识     = this.cmbGongZiBiaoShi.SelectedIndex == -1 ? null : this.cmbGongZiBiaoShi.SelectedValue.ToString(),
                工资账号     = this.txtSalaryBankAccountNumber.Text.Trim(),
                奖金标识     = this.cmbJiangJinBiaoShi.SelectedIndex == -1 ? null : this.cmbJiangJinBiaoShi.SelectedValue.ToString(),
                奖金账号     = this.txtbounsBankAccountNumber.Text.Trim(),
                备注       = this.txtRemark.Text.Trim(),
                拼音码      = objPinYinService.GetFirstLetter(this.txtName.Text.Trim()),
                更改者      = Program.currentAdmin.username,
                更改日期     = DateTime.Now
            };

            return(objUserInfo);
        }
Exemplo n.º 6
0
        public AjaxMessage UpdateHotel(FD_Hotel hotel)
        {
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            ajax.Message   = "";

            bool isExists = _hotelService.UpdateisExists(hotel.HotelID, hotel.HotelName);

            if (isExists == false)
            {
                var m_hotel = _hotelService.GetByID(hotel.HotelID);
                m_hotel.HotelName    = hotel.HotelName;
                m_hotel.Area         = hotel.Area;
                m_hotel.Address      = hotel.Address;
                m_hotel.HotelType    = hotel.HotelType;
                m_hotel.Phone        = hotel.Phone;
                m_hotel.DeskCount    = hotel.DeskCount;
                m_hotel.Start        = hotel.Start;
                m_hotel.End          = hotel.End;
                m_hotel.Sort         = hotel.Sort;
                m_hotel.Label        = hotel.Label;
                m_hotel.LabelContent = hotel.LabelContent;
                m_hotel.Description  = hotel.Description;

                m_hotel.Letter = PinYin.GetFirstLetter(hotel.HotelName.ToString());

                int result = _hotelService.Update(m_hotel);
                if (result > 0)
                {
                    ajax.IsSuccess = true;
                    ajax.Message   = "修改成功";
                }
            }
            else
            {
                ajax.Message = "酒店名称已经存在";
            }


            return(ajax);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 执行内容解析
        /// </summary>
        ///<param name="webArgs"></param>
        /// <param name="content">要解析的内容</param>
        /// <returns>返回需要的字段对应的字典</returns>
        public override Dictionary <string, object> ResolveSearchPageContent(BaseFetchWebPageArgument webArgs, string content)
        {
            var resultBag = new Dictionary <string, object>();

            try
            {
                string jsonData = string.Empty;

                if (content.IndexOf("g_page_config") < 0)
                {
                    return(null);//无效的页面结果数据
                }


                //send request for load other data of first search page
                Task <string> tskSilcedJsonpContent = null;
                if (webArgs.PageIndex == 0)
                {
                    tskSilcedJsonpContent = Task.Factory.StartNew(() =>
                    {
                        string jsonpContent = "";
                        ////1 打开tcp 链接
                        ////2 发送参数
                        ////3 解析结果
                        if (!webArgs.SystemAttachParas.ContainsKey("SoapTcpConnectionString"))
                        {
                            return(jsonpContent);
                        }
                        var connStrConfig = webArgs.SystemAttachParas["SoapTcpConnectionString"] as WebCrawlerConnection;
                        if (null == connStrConfig)
                        {
                            return(jsonpContent);
                        }
                        //重写解析地址-首页的分片jsonp地址
                        string urlOfSlicedJsonp = this.ResolveSlicedSearchPageSilcedUrl(webArgs);
                        webArgs.ResolvedUrl     = new ResolvedSearchUrlWithParas {
                            Url = urlOfSlicedJsonp
                        };
                        using (var conn = new SoapTcpConnection(connStrConfig))
                        {
                            if (conn.State == ConnectionState.Closed)
                            {
                                conn.Open();
                            }

                            //发送soap
                            var soapCmd = new SoapMessage()
                            {
                                Head = CommandConstants.CMD_FetchPage
                            };
                            soapCmd.Body      = JsonConvert.SerializeObject(webArgs);
                            var dataContainer = conn.SendSoapMessage(soapCmd);
                            if (null != dataContainer && dataContainer.Status == 1)
                            {
                                jsonpContent = dataContainer.Result;
                            }
                            else
                            {
                                StringBuilder errMsg = new StringBuilder("抓取网页请求失败!参数:");
                                errMsg.Append(soapCmd.Body);
                                if (null != dataContainer && !string.IsNullOrEmpty(dataContainer.ErrorMsg))
                                {
                                    errMsg.Append(";服务端错误消息:")
                                    .Append(dataContainer.ErrorMsg);
                                }
                                PluginContext.Logger.Error(errMsg.ToString());
                            }
                        }

                        return(jsonpContent);
                    });
                }


                int startPos      = content.IndexOf("g_page_config");
                int endPos        = content.IndexOf("g_srp_loadCss") - startPos;
                var secondContent = content.Substring(startPos, endPos);
                int secStartPos   = secondContent.IndexOf('{');
                int secEndPos     = secondContent.IndexOf("};") - secStartPos + 1;
                jsonData = secondContent.Substring(secStartPos, secEndPos);



                TaobaoPageJsonResut pageJsonObj = JsonConvert.DeserializeObject <TaobaoPageJsonResut>(jsonData);
                if (null == pageJsonObj)
                {
                    return(null);
                }

                if (webArgs.IsNeedResolveHeaderTags == true)
                {
                    var navNode = pageJsonObj.mods.nav;
                    if (null != navNode && null != navNode.data)
                    {
                        var commonNode = navNode.data.common;
                        var advNode    = navNode.data.adv;

                        //解析common节点
                        if (null != commonNode && commonNode.Any())
                        {
                            //1 检测是否有品牌,有的话 解析品牌
                            #region 品牌解析


                            var brandNode = commonNode.FirstOrDefault(x => x.text == "品牌" && x.sub != null);
                            if (null != brandNode && brandNode.sub != null)
                            {
                                var lstBrands = new List <BrandTag>();
                                foreach (var subItem in brandNode.sub)
                                {
                                    var model = new BrandTag();
                                    model.Platform    = SupportPlatformEnum.Taobao;
                                    model.FilterField = "ppath";//使用的过滤字段参数

                                    model.BrandId   = subItem.value;
                                    model.BrandName = subItem.text;
                                    model.CharIndex = PinYin.GetFirstLetter(model.BrandName);
                                    lstBrands.Add(model);
                                }
                                //解析完毕品牌
                                resultBag.Add("Brands", lstBrands);
                            }

                            #endregion
                        }


                        //2其他筛选节点的分析

                        #region tags 解析


                        var lstTags = new List <KeyWordTagGroup>();

                        var otherFilterNode1 = commonNode.Where(x => x.text != "品牌" && x.sub != null);
                        foreach (var itemNode in otherFilterNode1)
                        {
                            //找到归属的组
                            string groupName = itemNode.text;
                            ProcessTags(lstTags, itemNode.sub, groupName);
                        }
                        ////////if (null!= advNode)----高级筛选不要了
                        ////////{
                        ////////    //advNode 的解析
                        ////////    foreach (var itemNode in advNode)
                        ////////    {
                        ////////        //找到归属的组
                        ////////        string groupName = itemNode.text;
                        ////////        ProcessTags(lstTags, itemNode.sub, groupName);
                        ////////    }
                        ////////}

                        resultBag.Add("Tags", lstTags);

                        #endregion
                    }
                }

                #region products  解析
                var lstProducts = new ProductBaseCollection();
                resultBag.Add("Products", lstProducts);

                var itemListNode = pageJsonObj.mods.itemlist;
                if (null != itemListNode && itemListNode.data != null && null != itemListNode.data.auctions)
                {
                    foreach (var itemProduct in itemListNode.data.auctions)
                    {
                        TaobaoProduct modelProduct = this.ResolverProductDom(itemProduct);

                        if (null != modelProduct)
                        {
                            lstProducts.Add(modelProduct);
                        }
                    }
                }

                //淘宝的搜索列表 - 第一页的数据是进行了分片的,在加载html ;36条数据, 后续会进行一次jsonp的请求;加载12条数据
                if (webArgs.PageIndex == 0 && null != tskSilcedJsonpContent)
                {
                    string jsonpContent = tskSilcedJsonpContent.Result;
                    if (!string.IsNullOrEmpty(jsonpContent) && jsonpContent.Contains("API.CustomizedApi"))
                    {
                        int    startIdx         = jsonpContent.IndexOf(':') + 1;
                        int    endIdx           = jsonpContent.Length - startIdx - 3;
                        string pureJsonContent  = jsonpContent.Substring(startIdx, endIdx);
                        var    slicedJsonpResut = JsonConvert.DeserializeObject <TaobaoSlicedJsonpResut>(pureJsonContent);


                        if (null != slicedJsonpResut)
                        {
                            var itemList = slicedJsonpResut.itemlist;
                            if (null != itemList && itemList.auctions != null)
                            {
                                foreach (var itemProduct in itemList.auctions)
                                {
                                    TaobaoProduct modelProduct = this.ResolverProductDom(itemProduct);

                                    if (null != modelProduct)
                                    {
                                        lstProducts.Add(modelProduct);
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                PluginContext.Logger.Error(ex);
            }
            return(resultBag);// string.Concat("has process input :" + content);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 执行内容解析
        /// </summary>
        ///<param name="webArgs"> </param>
        /// <param name="content">要解析的内容</param>
        /// <returns>返回需要的字段对应的字典</returns>
        public override Dictionary <string, object> ResolveSearchPageContent(BaseFetchWebPageArgument webArgs, string content)
        {
            var resultBag = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(content))
            {
                if (content.Contains("环境有异常"))
                {
                    PluginContext.Logger.Error("天猫查询被进行蜘蛛验证!关键词:" + webArgs.KeyWord);
                    return(resultBag);
                }
                if (content.Contains("member/login"))
                {
                    PluginContext.Logger.Error("天猫查询结果页面被强制跳转到了登录页!关键词:" + webArgs.KeyWord);
                    return(resultBag);
                }
            }


            try
            {
                //创建html 文档对象
                HtmlParser htmlParser   = new HtmlParser();
                var        htmlDoc      = htmlParser.Parse(content);
                var        div_AttrsDom = htmlDoc.QuerySelector("div.j_NavAttrs");

                if (webArgs.IsNeedResolveHeaderTags == true && null != div_AttrsDom)
                {
                    #region 品牌解析
                    var lstBrands = new List <BrandTag>();
                    var brandDom  = div_AttrsDom.QuerySelector("div.j_Brand");
                    if (null != brandDom)
                    {
                        //从属性区域解析dom-品牌内容
                        var brandULDom = brandDom.QuerySelector("div.attrValues>ul");//ulDomArray[0];//

                        if (null != brandULDom)
                        {
                            var regex_MatchBrandId = new Regex(@"brand=(\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                            var li_ADomArray       = brandULDom.QuerySelectorAll("li>a");
                            foreach (var itemADom in li_ADomArray)
                            {
                                var model = new BrandTag();
                                model.Platform    = SupportPlatformEnum.Tmall;
                                model.FilterField = "brand";//使用的过滤字段参数
                                var urlBrand = itemADom.GetAttribute("href");
                                if (!string.IsNullOrEmpty(urlBrand) && urlBrand.Contains("brand="))
                                {
                                    model.BrandId = regex_MatchBrandId.Match(urlBrand).Groups[1].Value;//new//品牌id   href="?brand=110910&amp;q=%B4%F3%C3%D7&amp;sort=s&amp;style=g&amp;from=sn_1_brand-qp&amp;spm=a220m.1000858.1000720.1.348abe64rj5JVg#J_crumbs
                                }
                                model.BrandName = itemADom.GetAttribute("title");
                                model.CharIndex = PinYin.GetFirstLetter(model.BrandName);
                                lstBrands.Add(model);
                            }
                        }
                    }
                    resultBag.Add("Brands", lstBrands);

                    #endregion

                    // tags 解析
                    //var lstTags = new List<KeyWordTag> {
                    //new KeyWordTag {
                    //    Platform = NTCPMessage.EntityPackage.SupportPlatformEnum.Tmall,
                    //    TagName = "大衣", Value = "dayi", FilterFiled = "sku"
                    //} };
                    var ulDomArray = div_AttrsDom.QuerySelectorAll("div.attrValues>ul");

                    var lstTags = new List <KeyWordTagGroup>();
                    if (null != div_AttrsDom)
                    {
                        var blockList = new BlockingCollection <KeyWordTagGroup>();

                        //分类 or 属性;品牌是第一个,其他属性是后续
                        int startIdx = brandDom == null ? 0 : 1;// //是否存在品牌的判断

                        var taskArray = new Task[ulDomArray.Length - startIdx];
                        int counter   = 0;


                        for (int i = startIdx; i < ulDomArray.Length; i++)
                        {
                            int cursor = i;

                            var taskResolveAEmelems = Task.Factory.StartNew(() =>
                            {
                                var itemUl = ulDomArray[cursor];

                                //找到归属的组
                                var attrKeyDom   = itemUl.ParentElement.ParentElement.QuerySelector("div.attrKey");
                                string groupName = "";
                                if (null != attrKeyDom)
                                {
                                    groupName = attrKeyDom.TextContent.Replace("\n", "").Trim();
                                }

                                var tagGroup = new KeyWordTagGroup(groupName);

                                var childLiADomArray = itemUl.QuerySelectorAll("li>a");
                                foreach (var itemADom in childLiADomArray)
                                {
                                    var modelTag           = new KeyWordTag();
                                    modelTag.Platform      = SupportPlatformEnum.Tmall;
                                    modelTag.TagName       = itemADom.TextContent.Replace("\n", "");//标签名称
                                    modelTag.GroupShowName = groupName;

                                    //////----解析 a标签开始-------
                                    //////检查 a 的href 中的参数;cat 或者prop
                                    string hrefValue = itemADom.GetAttribute("href");
                                    if (!string.IsNullOrEmpty(hrefValue))
                                    {
                                        var urlParas = HttpUtility.ParseQueryString(hrefValue, Encoding.UTF8);
                                        if (null != urlParas)
                                        {
                                            if (hrefValue.IndexOf("cat=") > -1)
                                            {
                                                //1 cat
                                                string catValue      = urlParas["cat"];
                                                modelTag.FilterFiled = "cat";
                                                modelTag.Value       = catValue;
                                            }
                                            else if (hrefValue.IndexOf("prop=") > -1)
                                            {
                                                //2 prop
                                                string propValue     = urlParas["prop"];
                                                modelTag.FilterFiled = "prop";
                                                modelTag.Value       = propValue;
                                            }
                                        }
                                    }
                                    tagGroup.Tags.Add(modelTag);
                                }

                                //----解析 a标签完毕-------
                                blockList.Add(tagGroup);
                            });
                            //将并行任务放到数组
                            taskArray[counter] = taskResolveAEmelems;
                            counter           += 1;
                        }
                        var safeTaskArray = taskArray.Where(x => null != x).ToArray();
                        Task.WaitAll(safeTaskArray);
                        lstTags = blockList.ToList();
                    }
                    resultBag.Add("Tags", lstTags);
                }

                #region products  解析
                //ProductBaseCollection lstProducts = new ProductBaseCollection()
                //{
                //    new TmallProduct { ItemId=1,Title="测试大衣"}
                //};
                var lstProducts = new ProductBaseCollection();
                //多任务并行解析商品
                //BlockingCollection<TmallProduct> blockingList_Products = new BlockingCollection<TmallProduct>();
                ConcurrentDictionary <string, ProductOrdered <TmallProduct> > blockingList_Products = new ConcurrentDictionary <string, ProductOrdered <TmallProduct> >();

                var div_J_ItemListDom = htmlDoc.QuerySelector("div#J_ItemList");
                if (null != div_J_ItemListDom)
                {
                    var div_productDomArray = div_J_ItemListDom.QuerySelectorAll("div.product");
                    if (null != div_productDomArray && div_productDomArray.Any())
                    {
                        var pids = div_productDomArray
                                   .Select(x => { return(x.GetAttribute("data-id")); });
                        //设定排序对象
                        int counter_pid = 0;
                        foreach (var itemPid in pids)
                        {
                            if (null != itemPid)
                            {
                                blockingList_Products.TryAdd(itemPid, new ProductOrdered <TmallProduct> {
                                    UniqKey = itemPid, IndexOrder = counter_pid
                                });
                                counter_pid++;
                            }
                        }

                        //并行解析 并保留原序列
                        div_productDomArray.AsParallel()
                        .ForAll((itemProductDom) =>
                        {
                            //解析一个商品的节点
                            TmallProduct modelProduct = this.ResolverProductDom(itemProductDom);
                            if (null != modelProduct && modelProduct.ItemId > 0)
                            {
                                var orderedObj     = blockingList_Products[modelProduct.ItemId.ToString()];
                                orderedObj.Product = modelProduct;
                            }
                        });

                        //进行排序
                        var productsList = blockingList_Products
                                           .Where(x => x.Value != null)
                                           .OrderBy(x => x.Value.IndexOrder)
                                           .Select(x => x.Value.Product);
                        lstProducts.AddRange(productsList);
                    }
                }
                resultBag.Add("Products", lstProducts);

                #endregion
            }
            catch (Exception ex)
            {
                PluginContext.Logger.Error(ex);
            }
            return(resultBag);// string.Concat("has process input :" + content);
        }