예제 #1
0
        private InboundPara BuildInboundPara()
        {
            if (this.curOutbound == null || this.curOutbound.OutboundOrder == null || this.curOutbound.OutboundDetails == null || this.curOutbound.OutboundDetails.Count == 0)
            {
                return(null);
            }

            int                totalCount     = 0;
            decimal            totalPrice     = 0;
            decimal            totalCost      = 0;
            List <BoundDetail> inboundDetails = new List <BoundDetail>();
            string             id             = IDHelper.GetID(OrderPrefix.InboundOrder, CommonGlobalCache.CurrentShop.AutoCode);

            foreach (BoundDetail detail in this.curOutbound.OutboundDetails)
            {
                //if (detail.SumCount <= 0)
                //{
                //    continue;

                //}
                totalCost  += detail.SumCost;
                totalCount += detail.SumCount;
                totalPrice += detail.SumMoney;
                inboundDetails.Add(OutboundDetailConvertToInboundDetail(detail, id));
            }
            if (CommonGlobalCache.CurrentUser.Type == UserInfoType.Admin)
            {
                AllocateOrder allocateOrder = CommonGlobalCache.ServerProxy.GetAllocateOrder(this.curOutbound.OutboundOrder.SourceOrderID);
                shopID = allocateOrder.DestShopID;
            }
            InboundOrder inboundOrder = new InboundOrder()
            {
                SourceOrderID  = this.curOutbound.OutboundOrder.SourceOrderID,
                ShopID         = shopID,
                ID             = id,
                OperatorUserID = //IsPos ? (string)this.guideComboBox1.SelectedValue :
                                 CommonGlobalCache.CurrentUserID,
                CreateTime = DateTime.Now,
                EntryTime  = DateTime.Now,
                TotalCost  = totalCost,
                TotalCount = totalCount,

                TotalPrice = totalPrice,
                Remarks    = this.skinTextBox_Remarks.SkinTxt.Text,
            };

            return(new InboundPara()
            {
                InboundOrder = inboundOrder,
                InboundDetails = inboundDetails
            });
        }
예제 #2
0
        private Outbound BuildOutbound()
        {
            if (this.curReplenishOrder == null || this.curReplenishDetailList == null || this.curReplenishDetailList.Count == 0)
            {
                return(null);
            }
            int                totalCount = 0;
            decimal            totalPrice = 0;
            decimal            totalCost  = 0;
            List <BoundDetail> details    = new List <BoundDetail>();

            //使用补货申请单的店铺ID信息

            Shop   shop             = GlobalCache.ShopList.Find(t => t.ID == this.curReplenishOrder.ShopID);
            string id               = IDHelper.GetID(OrderPrefix.OutboundOrder, shop.AutoCode);
            string replenishOrderid = IDHelper.GetID(OrderPrefix.ReplenishOrder, shop.AutoCode);

            foreach (ReplenishDetail detail in this.curReplenishDetailList)

            {
                if (detail.SumCount <= 0)
                {
                    continue;
                }
                totalCost  += detail.SumCost;
                totalCount += detail.SumCount;
                totalPrice += detail.SumMoney;
                details.Add(this.ReplenishDetailConvertToOutboundDetail(detail, id));
            }

            OutboundOrder order = new OutboundOrder()
            {
                SourceOrderID  = curReplenishOrder.IsRedo?  replenishOrderid:this.curReplenishOrder.ID,
                ID             = id,
                OperatorUserID = GlobalCache.CurrentUserID,
                ShopID         = GlobalCache.ServerProxy.GetGeneralStoreShopID(),
                CreateTime     = DateTime.Now,
                TotalCount     = totalCount,
                TotalPrice     = totalPrice,
                TotalCost      = totalCost,
                Remarks        = this.skinTextBox_Remarks.SkinTxt.Text
            };

            return(new Outbound()
            {
                OutboundDetails = details,
                OutboundOrder = order
            });
        }
예제 #3
0
        public bool EditSubCategory(SubCategoryViewModel model)
        {
            pub_SubCategoryEntity entity = AutoMapHelper.ToEntity <SubCategoryViewModel, pub_SubCategoryEntity>(model);

            if (entity.Id == 0)
            {
                entity.SubCategoryId = IDHelper.Create("S");
                categoryRepository.InsertSubCategory(entity);
            }
            else
            {
                categoryRepository.UpdateSubCategory(entity);
            }
            return(true);
        }
        public static Guid GenerateBotId()
        {
            if (_botId != Guid.Empty)
            {
                return(_botId);
            }

            var hostName  = Dns.GetHostName();
            var processId = Process.GetCurrentProcess().Id;
            var ts        = GetTimestamp();
            var idStr     = hostName + processId + ts;

            _botId = IDHelper.GetGuid(idStr);
            return(_botId);
        }
예제 #5
0
        /// <summary>
        /// 生成ReplenishCostume对象
        /// </summary>
        /// <returns></returns>
        private ReplenishCostume BuildReplenishCostume()
        {
            if (this.curReplenishDetailList == null || this.curReplenishDetailList.Count == 0)
            {
                return(null);
            }

            string id = IDHelper.GetID(OrderPrefix.ReplenishOrder, GlobalCache.GetShop(shopID).AutoCode);

            if (action == OperationEnum.Pick)
            {
                id = this.order?.ID;
            }
            int     totalCount          = 0;
            decimal totalMoney          = 0;
            List <ReplenishDetail> list = new List <ReplenishDetail>();

            for (int i = 0; i < this.curReplenishDetailList.Count; i++)
            {
                if (this.curReplenishDetailList[i].SumCount == 0)
                {
                    continue;
                }
                list.Add(this.curReplenishDetailList[i]);
                totalCount += this.curReplenishDetailList[i].SumCount;
                totalMoney += this.curReplenishDetailList[i].SumMoney;
                this.curReplenishDetailList[i].ReplenishOrderID = id;
            }

            ReplenishOrder replenishOrder = new ReplenishOrder()
            {
                ID             = id,
                RequestGuideID = GlobalCache.CurrentUserID,// (string)this.guideComboBox1.SelectedValue,
                ShopID         = shopID,
                Remarks        = this.skinTextBox_Remarks.SkinTxt.Text,
                State          = (byte)ReplenishOrderState.NotProcessing,
                TotalCount     = totalCount,
                TotalPrice     = totalMoney,
                CreateTime     = DateTime.Now,
                FinishedTime   = SystemDefault.DateTimeNull,
            };

            return(new ReplenishCostume()
            {
                ReplenishOrder = replenishOrder,
                ReplenishDetailList = list
            });
        }
예제 #6
0
    public virtual void Create(T entity)
    {
        //// Save the entity with safe mode (WriteConcern.Acknowledged)
        entity.MyId = IDHelper.GetNextId(typeof(T).Name);
        var result = this.MongoConnectionHandler.MongoCollection.Save(
            entity,
            new MongoInsertOptions
        {
            WriteConcern = WriteConcern.Acknowledged
        });

        if (!result.Ok)
        {
            //// Something went wrong
        }
    }
예제 #7
0
        /// <summary>
        /// 发布通知接口
        /// </summary>
        /// <param name="VisitorID">游客ID,如果Admin代表管理员</param>
        /// <param name="NoticeType"></param>
        /// <param name="OccurTime"></param>
        /// <param name="OccurAddress"></param>
        /// <param name="NoticeDetail"></param>
        /// <returns></returns>
        public Stream PublishNotice(string VisitorID, int NoticeType, string OccurTime, string OccurAddress, string NoticeDetail)
        {
            if (VisitorID != "Admin" && NoticeType == 2)//合法性检查
            {
                return(ResponseHelper.Failure("只有管理员可以发布活动通知!"));
            }

            string id     = IDHelper.getNextNoticeID(DateTime.Now);
            Notice notice = new Notice()
            {
                NoticeID     = id,
                VisitorID    = VisitorID,
                NoticeType   = NoticeType,
                NoticeTime   = DateTime.Now,
                OccurTime    = OccurTime,
                OccurAddress = OccurAddress,
                NoticeDetail = NoticeDetail,
                NoticeStatus = 0,
                Remarks      = "",
                CheckTime    = null
            };

            if (VisitorID == "Admin")
            {
                notice.NoticeStatus = 1;
                notice.CheckTime    = DateTime.Now;
            }


            try
            {
                EFHelper.Add <Notice>(notice);  //通知信息提交数据库
                return(ResponseHelper.Success(new List <string>()
                {
                    "发布成功,等待审核!"
                }));
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                return(ResponseHelper.Failure(ex.Message));
            }
        }
        public List <WX_links> Query(IW2S_WX_BaiduCommend searchTsk, List <IW2S_WX_BaiduCommend> taskList)
        {
            List <WX_links>           linkvaluelist = new List <WX_links>();
            WX_BotTaskService         WX_bt         = new WX_BotTaskService();
            List <IW2S_WX_level1link> linklist      = WX_bt.GetLinkTitleList(searchTsk.ProjectId);
            int index = 0;

            for (int i = 0; i < taskList.Count; i++)
            {
                if (searchTsk.CommendKeyword == taskList[i].CommendKeyword)
                {
                    index = i;
                }
            }
            for (int i = 0; i < taskList.Count; i++)
            {
                WX_links lk = new WX_links();
                //if (searchTsk.CommendKeyword == taskList[i].CommendKeyword)
                //{
                //}
                //else
                //{
                lk.source    = index;
                lk.target    = i;
                lk.KeywordId = searchTsk._id;
                lk.ProjectId = searchTsk.ProjectId;
                int linkNum = 0;
                foreach (var item in linklist)
                {
                    if (!string.IsNullOrEmpty(item.Title))
                    {
                        if (item.Title.Contains(searchTsk.CommendKeyword) && item.Title.Contains(taskList[i].CommendKeyword))
                        {
                            linkNum = linkNum + 1;
                        }
                    }
                }
                lk.value = linkNum;
                lk.Gid   = IDHelper.GetGuid("{0}/{1}/{2}/{3}".FormatStr(lk.source, lk.target, lk.KeywordId, lk.ProjectId));
                linkvaluelist.Add(lk);
                //  }
            }
            WX_SaveResult(linkvaluelist);
            return(linkvaluelist);
        }
예제 #9
0
        private static InboundPara BuildInboundPara(Outbound curOutbound, AllocateOrder allocateOrder)
        {
            if (curOutbound == null || curOutbound.OutboundOrder == null || curOutbound.OutboundDetails == null || curOutbound.OutboundDetails.Count == 0)
            {
                return(null);
            }

            int                totalCount     = 0;
            decimal            totalCost      = 0;
            decimal            totalPrice     = 0;
            List <BoundDetail> inboundDetails = new List <BoundDetail>();
            string             id             = IDHelper.GetID(OrderPrefix.InboundOrder, CommonGlobalCache.CurrentShop.AutoCode);

            foreach (BoundDetail detail in curOutbound.OutboundDetails)
            {
                //if (detail.SumCount <= 0)
                //{
                //    continue;
                //}
                totalCost  += detail.SumCost;
                totalCount += detail.SumCount;
                totalPrice += detail.SumMoney;
                inboundDetails.Add(OutboundDetailConvertToInboundDetail(detail, id));
            }

            InboundOrder inboundOrder = new InboundOrder()
            {
                SourceOrderID  = curOutbound.OutboundOrder.SourceOrderID,
                ShopID         = allocateOrder.DestShopID,
                ID             = id,
                OperatorUserID = string.Empty,
                CreateTime     = allocateOrder.CreateTime,
                EntryTime      = DateTime.Now,
                TotalCost      = totalCost,
                TotalCount     = totalCount,
                TotalPrice     = totalPrice,
                Remarks        = "自动入库",
            };

            return(new InboundPara()
            {
                InboundOrder = inboundOrder,
                InboundDetails = inboundDetails
            });
        }
예제 #10
0
        public bool EditArticle(ArticleViewModel model)
        {
            ArticleEntity entity = AutoMapHelper.ToEntity <ArticleViewModel, ArticleEntity>(model);

            if (entity.Id == 0)
            {
                entity.ArticleId = IDHelper.Create("A");
                articleRepository.InsertArticle(entity);
            }
            else
            {
                var last = articleRepository.GetArticleById(entity.Id);
                entity.CreateTime = last.CreateTime;
                entity.ArticleId  = last.ArticleId;
                articleRepository.UpdateArticle(entity);
            }
            return(true);
        }
예제 #11
0
        private PfCustomerRetailInfo Build()
        {
            if (
                this.PfCustomerRetailDetailList == null || this.PfCustomerRetailDetailList.Count == 0)
            {
                return(null);
            }
            int totalCount = 0;
            List <PfCustomerRetailDetail> details = new List <PfCustomerRetailDetail>();

            //使用补货申请单的店铺ID信息


            string id = IDHelper.GetID(OrderPrefix.PfCustomerRetailOrder, CommonGlobalCache.CurrentShop.AutoCode);

            foreach (PfCustomerRetailDetail detail in this.PfCustomerRetailDetailList)
            {
                //if (detail.BuyCount <= 0)
                //{
                //    continue;
                //}
                detail.PfCustomerRetailOrderID = id;
                totalCount += detail.BuyCount;

                details.Add(detail);
            }

            PfCustomerRetailOrder pOrder = new PfCustomerRetailOrder()
            {
                PfCustomerID = lastAddCustomer.ID,
                ID           = id,
                CreateTime   = this.dateTimePicker_Start.Value,
                TotalCount   = totalCount,
                Comment      = this.skinTextBox_Remarks.SkinTxt.Text,
            };

            return(new PfCustomerRetailInfo()
            {
                PfCustomerRetailOrder = pOrder,
                PfCustomerRetailDetails = details
            });
        }
예제 #12
0
        /// <summary>
        /// 卡充值
        /// </summary>
        /// <param name="VisitorID">游客ID</param>
        /// <param name="Amount">充值金额</param>
        /// <param name="PaymentType">付款方式</param>
        /// <returns>生成的OrderID</returns>
        public Stream Recharge(string VisitorID, float Amount, int PaymentType)
        {
            #region 数据完整性检查
            if (VisitorID == null)
            {
                return(ResponseHelper.Failure("游客信息缺失!"));
            }
            if (Amount <= 0)
            {
                return(ResponseHelper.Failure("充值金额无效!"));
            }
            #endregion

            //根据游客ID查询卡ID
            string CardID = "";
            try
            {
                using (var db = new EFDbContext())
                {
                    var card = from v2c in db.Visitor2Cards
                               where v2c.VisitorID == VisitorID
                               select v2c;
                    if (card.Count() == 0)
                    {
                        return(ResponseHelper.Failure("该游客没有绑定游园卡!"));
                    }

                    CardID = card.Single().CardID;//记录卡ID
                }
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                return(ResponseHelper.Failure(ex.Message));
            }

            #region 新增订单,新增支付信息,新增游客订单映射
            string id = IDHelper.getNextOrderID(DateTime.Now, 3);
            //生成新订单
            Order RechargeOrder = new Order()
            {
                OrderID       = id,
                OrderTime     = DateTime.Now,
                OrderState    = 1, //已支付
                CommodityID   = CardID,
                CommodityType = 3, //卡相关
                CommodityNum  = (int)Amount,
                DoneTime      = Convert.ToDateTime(DateTime.Now)
            };
            //生成新支付信息
            Payment RechargePay = new Payment()
            {
                OrderID       = RechargeOrder.OrderID,
                PaymentType   = PaymentType,
                PaymentTime   = DateTime.Now,
                PaymentAmount = Amount
            };
            //增加游客订单映射
            Visitor2Order v2o = new Visitor2Order()
            {
                VisitorID = VisitorID,
                CardID    = CardID,
                OrderID   = id
            };
            #endregion

            #region 修改数据库,返回订单ID
            //在数据库V2C表中修改卡余额
            try
            {
                using (var db = new EFDbContext())
                {
                    //订单、支付、游客订单映射信息——提交数据库
                    db.Orders.Add(RechargeOrder);
                    db.Payments.Add(RechargePay);
                    db.Visitor2Orders.Add(v2o);

                    //修改余额(增加)
                    Visitor2Card new_v2c = db.Visitor2Cards.Where(v => v.VisitorID == VisitorID).Single();
                    new_v2c.Balance += Amount;

                    db.SaveChanges();
                    return(ResponseHelper.Success(new List <string>()
                    {
                        RechargeOrder.OrderID
                    }));                                                                         //返回OrderID
                }
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                return(ResponseHelper.Failure(ex.Message));
            }
            #endregion
        }
예제 #13
0
        public List <Dnl_Google_level1link> GetLinks(string link, Dnl_Google_BaiduCommend searchTsk)
        {
            List <Dnl_Google_level1link> result = new List <Dnl_Google_level1link>();
            int nohist_pages = 0;
            int quried_pages = 0;
            int fanye        = 0;

            //最多搜索10页
            while (!string.IsNullOrEmpty(link) && quried_pages <= 10)
            {
                log(link);
                CookieContainer  cc               = new CookieContainer();
                Encoding         enc              = null;
                CookieCollection cookiesColl      = new CookieCollection();
                CookieCollection cookieCollection = new CookieCollection();
                string           Rurl             = "https://www.google.com";
                string           cookie           = "";

                WebClient webClient = new WebClient();
                webClient.Credentials = CredentialCache.DefaultCredentials;
                Byte[] pageData = webClient.DownloadData(link);

                string pageHtml = Encoding.GetEncoding("Big5").GetString(pageData);

                pageHtml = Strings.StrConv(pageHtml, VbStrConv.SimplifiedChinese, 0);

                //string hhhtml = TaobaoWebHelper.GetContentByIndex(Rurl, 80000, cc, ref enc, out Rurl, ref cookiesColl, out cookieCollection);
                //cookiesColl = cookieCollection;
                //int gg = new Random().Next(2000, 5000);
                //Thread.Sleep(gg);

                //Rurl = link;
                //var html = get_html(link, 8000, cc, ref enc, out Rurl, cookie, ref cookiesColl, out cookieCollection);// GetContent(link, 8000, cc, ref enc, out Rurl);
                //cookiesColl = cookieCollection;

                var html = pageHtml;

                if (html == null)
                {
                    break;
                }
                //  html = Regex.Unescape(html);
                if (html.Contains("没有找到搜索内容!"))
                {
                    break;
                }

                var tags = html.SubAfter("<body").SubAfter("center_col").SubBefore("id=\"foot\"");


                var tagsD = tags.SplitWith("class=\"g\"");

                if (tagsD == null || tagsD.Length == 0)
                {
                    log("BLOCKED " + searchTsk.Keyword + " " + searchTsk.CommendKeyword);
                    break;
                }
                bool nohit = true;
                foreach (var tag in tagsD)
                {
                    if (!tag.Contains("h3"))
                    {
                        continue;
                    }

                    //if (!tag.Contains("sp_requery"))
                    //{
                    //    continue;
                    //}
                    var    a     = tag.SubAfter("h3").SubAfter("a");
                    string title = RemoveInivalidChar(a.RemoveSpace().GetLower().SubBefore("</h3>").GetTxtFromHtml2().RemoveSpace().GetLower()); // RemoveInivalidChar(tag.SubAfter("<h4").SubBefore("</h4>").GetTxtFromHtml2().RemoveSpace());
                    string href  = a.GetFirstHref2();                                                                                            //tag.SubAfter("<h4").SubBefore("</a>").GetFirstHref2();

                    if (href.Contains("/url?q="))
                    {
                        href = href.Replace("/url?q=", "");
                    }


                    if (!href.Contains("http"))
                    {
                        href = "https://www.google.com" + href;
                    }

                    if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(href))
                    {
                        continue;
                    }
                    href = href.Replace("amp;", "");
                    var    sdsfdsf = GetDomain(href);
                    string abs     = RemoveInivalidChar(tag.SubAfter("class=\"st\"").SubBefore("</span").GetTxtFromHtml2().RemoveSpace().GetLower()); //RemoveInivalidChar(tag.SubAfter("<h4>").SubBefore("\"s-p\"").SubBefore("<script>").GetTxtFromHtml2().RemoveSpace());
                    string timesp  = "";
                    string domain  = GetDomain(href);
                    //tag.SubLastStringAfter("\"s-p\"").SubBefore("</a").GetTxtFromHtml2().SubAfter("(").SubAfter("(").SubBefore(",").Replace('"', ' ').Trim();
                    //domain = BaiduQuery.GetDomain(domain);

                    int maxScore = 0;

                    byte appType = 0;
                    //没有包含需要protect item信息的过滤掉
                    string txt = "{0},{1}".FormatStr(title, abs);
                    if (string.IsNullOrEmpty(txt))
                    {
                        continue;
                    }

                    int nn = new Random().Next(8000, 20000);
                    Thread.Sleep(nn);
                    var htmldetail = "";

                    try
                    {
                        // htmldetail = get_Detailehtml(href, 8000, cc, ref enc, out Rurl, cookie, ref cookiesColl, out cookieCollection);// GetContent(href, 8000, cc, ref enc, out Rurl);

                        WebClient webClient2 = new WebClient();
                        webClient2.Credentials = CredentialCache.DefaultCredentials;
                        Byte[] pageData2 = webClient2.DownloadData(href);

                        htmldetail = Encoding.GetEncoding("Big5").GetString(pageData2);

                        htmldetail = Strings.StrConv(htmldetail, VbStrConv.SimplifiedChinese, 0);
                    }
                    catch (Exception)
                    {
                        //htmldetail = "";
                    }

                    Regex reg = new Regex("(20\\d{2}[-/]\\d{1,2}[-/]\\d{1,2})|(20\\d{2}年\\d{1,2}月\\d{1,2}日)");
                    Match m   = reg.Match(htmldetail);
                    //MatchCollection cols = reg.Matches(item.Html);

                    if (m.Groups.Count > 0)
                    {
                        timesp = m.Groups[0].Value;
                    }

                    bool          is_title_matched = title.GetLower().IsContains2(searchTsk.Keyword.ToLower(), searchTsk.CommendKeyword.ToLower());
                    bool          is_abstr_matched = abs.GetLower().IsContains2(searchTsk.Keyword.GetLower(), searchTsk.CommendKeyword.GetLower());
                    BaiduItemPart part             = is_title_matched && is_abstr_matched ? BaiduItemPart.TitleAbstract :
                                                     is_title_matched ? BaiduItemPart.Title :
                                                     is_abstr_matched ? BaiduItemPart.Abstract : BaiduItemPart.None;
                    bool is_itm_title_matched = txt.GetLower().IsContains(searchTsk.Keyword.GetLower());
                    bool is_bus_matched       = txt.GetLower().IsContains2(searchTsk.CommendKeyword.GetLower());



                    Dnl_Google_level1link l1 = new Dnl_Google_level1link
                    {
                        UsrId           = searchTsk.UsrId,
                        Domain          = domain.Replace("http://", "").Replace("https://", ""),
                        TopDomain       = GetLevel1Domain(domain),
                        Keywords        = string.Format("{0} + {1}", searchTsk.Keyword, searchTsk.CommendKeyword),
                        LinkUrl         = href,
                        MatchAt         = (byte)part,
                        Html            = htmldetail,
                        MatchType       = (byte)((is_bus_matched ? 1 : 0) + (is_itm_title_matched ? 2 : 0)),
                        AppType         = appType,
                        BizId           = IDHelper.GetGuid("{0}/{1}/{2}".FormatStr(href, searchTsk.UsrId, searchTsk.Keyword)),
                        SearchkeywordId = searchTsk._id.ToString(),
                        CreatedAt       = DateTime.UtcNow.AddHours(8),
                        Description     = abs,
                        Title           = title,
                        Score           = maxScore,
                        Abstract        = abs,
                        ProjectId       = searchTsk.ProjectId,
                        PublishTime     = timesp
                    };
                    if (is_bus_matched)
                    {
                        l1.MatchType = l1.MatchType;
                    }
                    if (is_itm_title_matched)
                    {
                        l1.MatchType = l1.MatchType;
                    }
                    byte MatchType = (byte)((is_bus_matched ? 10 : 0) + (is_itm_title_matched ? 30 : 0));
                    if (is_bus_matched == true && is_itm_title_matched == true)
                    {
                        //l1.Score = busTsk.Score + 5;
                        l1.Score = 80 + 10;
                    }
                    if (is_bus_matched == true && is_itm_title_matched == false)
                    {
                        l1.Score = 80;
                    }
                    if (is_bus_matched == false && is_itm_title_matched == true)
                    {
                        l1.Score = 50;
                    }

                    result.Add(l1);
                    nohit        = false;
                    nohist_pages = 0;
                }

                if (nohit)
                {
                    nohist_pages++;
                }
                //如果连续3页都没有结果,就跳出
                if (nohist_pages > 3)
                {
                    break;
                }

                quried_pages++;
                pages++;

                //****** sougou 需要重写 *********************
                link = html.SubAfter("id=\"foot\"").SubAfter("text-align:left").SubBefore("下一页").GetLastHref2();
                if (!string.IsNullOrEmpty(link) && !link.IsStartWith("http"))
                {
                    if (link.IsStartWith("/"))
                    {
                        link = link.SubAfter("/");
                    }
                    link = "https://www.google.com/".GetContact(link);

                    link = link.Replace("amp;", "");
                }
                fanye = fanye + 10;

                SaveResult(result);
                result.Clear();

                int n = new Random().Next(8000, 15000);
                Thread.Sleep(n);
            }
            return(result);
        }
예제 #14
0
        public Stream Invite(string InviterID, string InviteeID)
        {
            if (string.IsNullOrEmpty(InviterID) || string.IsNullOrEmpty(InviteeID))
            {
                return(ResponseHelper.Failure("InviterID或InviteeID信息不完全!"));
            }

            try
            {
                if (EFHelper.GetAll <Visitor>().Where(t => t.VisitorID == InviterID).Count() == 0)
                {
                    return(ResponseHelper.Failure("Inviter游客不存在!"));
                }
                if (EFHelper.GetAll <Visitor>().Where(t => t.VisitorID == InviteeID).Count() == 0)
                {
                    return(ResponseHelper.Failure("Invitee游客不存在!"));
                }

                using (var db = new EFDbContext())
                {
                    //判断邀请者是否已拥有队伍
                    var inviterGroup = db.Groups.Where(t => t.VisitorID == InviterID && t.InviteeState == 1);
                    //若没有,则新建队伍
                    if (inviterGroup.Count() == 0)
                    {
                        string groupID = IDHelper.getNextGroupID(DateTime.Now);
                        //自己邀请自己即为建立队伍
                        db.Groups.Add(new Group()
                        {
                            GroupID      = groupID,
                            VisitorID    = InviterID,
                            InviteeState = 1,
                            InviterID    = InviterID
                        });
                        db.Groups.Add(new Group()
                        {
                            GroupID      = groupID,
                            VisitorID    = InviteeID,
                            InviteeState = 0,
                            InviterID    = InviterID
                        });
                    }
                    else  //否则以邀请者队伍进行邀请
                    {
                        var group = inviterGroup.Single();
                        db.Groups.Add(new Group()
                        {
                            GroupID      = group.GroupID,
                            VisitorID    = InviteeID,
                            InviteeState = 0,
                            InviterID    = InviterID
                        });
                    }

                    db.SaveChanges();
                    return(ResponseHelper.Success(null));
                }
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                return(ResponseHelper.Failure(ex.Message));
            }
        }
예제 #15
0
        // 1. Load each file with links in memory
        // 2. Filter the links
        // 3. Write the filtered links to the same file (overwrite)
        // This methid works only for raw web links. If it is used twice in a row, then results will be empty.
        public static void FilterLinks(string pathDataDir)
        {
            Console.WriteLine("Starting links filtering . . .");

            IEnumerable <string> letterDirectories = Directory.EnumerateDirectories(pathDataDir, "?", SearchOption.TopDirectoryOnly);

            foreach (string pathLetterDir in letterDirectories)
            {
                /* 1. Get ch_links_?.csv from the current directory
                 * 2. Load all information from there into a Dictionary<Guid, List<string>>
                 * 3. Filter all the links for each entry in the dictionary, delete entry if list is empty
                 */

                Console.WriteLine("Filtering links in " + pathLetterDir);

                List <List <string> > characterLinks = new List <List <string> >();

                string pathChLinks = FileManager.GetLinksFilePath(pathLetterDir);
                using (StreamReader reader = new StreamReader(pathChLinks))
                {
                    while (!reader.EndOfStream)
                    {
                        string input = reader.ReadLine();

                        if (!input.Equals(String.Empty))
                        {
                            string[]      linksInfo    = input.Split(',');
                            List <string> newLinksInfo = new List <string>();
                            // Add ID to the new list of links
                            newLinksInfo.Add(linksInfo[0]);
                            // Add all links
                            for (int i = 1; i < linksInfo.Length; ++i)
                            {
                                string linkToTest = linksInfo[i];
                                if (IsValidLink(linkToTest))
                                {
                                    newLinksInfo.Add(IDHelper.GetIDFromLink(linkToTest, Path.GetFileName(pathLetterDir)));
                                }
                            }
                            characterLinks.Add(newLinksInfo);
                        }
                    }
                }


                // 4. Write all the links to ch_links_?.csv
                using (StreamWriter writer = new StreamWriter(pathChLinks))
                {
                    foreach (List <string> listLinks in characterLinks)
                    {
                        if (listLinks.Count > 1)
                        {
                            writer.Write(listLinks[0]);
                            for (int i = 1; i < listLinks.Count; ++i)
                            {
                                writer.Write(String.Format(",{0}", listLinks[i]));
                            }
                            writer.WriteLine();
                        }
                    }
                }
            }

            Console.WriteLine("Finished links filtering.");
        }
예제 #16
0
        private void TimeProject_Tick(object sender, EventArgs e)
        {
            if (isProjectInventory)
            {
                try
                {
                    var updateItems = from project in projectTemp
                                      group project by project.EPCString into up
                                      select new { CardID = up.Key, Time = up.Max(t => t.Time) };


                    var v2c = from v in EFHelper.GetAll <Visitor2Card>()
                              join u in updateItems on v.CardID equals u.CardID
                              join vi in EFHelper.GetAll <Visitor>() on v.VisitorID equals vi.VisitorID
                              select new { v.VisitorID, vi.Name, u.Time, v.Balance, v.CardID };

                    if (v2c.Count() > 0)
                    {
                        var charge = EFHelper.GetAll <ChargeProject>().First(t => t.ProjectID == ProjectID);

                        foreach (var v in v2c)
                        {
                            if (v.Balance < charge.ProjectPrice)
                            {
                                MessageBox.Show(string.Format("ID:{0},用户:{1} 的余额不足 {2} 元,请充值后再尝试游玩!", v.VisitorID, v.Name, charge.ProjectPrice));
                                continue;
                            }

                            //判断是否重复刷卡
                            var isAgain = EFHelper.GetAll <Operation>().Where(t => t.VisitorID == v.VisitorID && t.PlayState == 1);
                            if (isAgain.Count() > 0)
                            {
                                continue;
                            }

                            using (var db = new EFDbContext())
                            {
                                var operation = db.ProjectOperation.First(t => t.ProjectID == ProjectID && t.VisitorID == v.VisitorID);
                                //改变项目实时信息
                                if (operation != null)
                                {
                                    operation.PlayState = 1;
                                }
                                //增加项目历史记录
                                db.ProjectRecord.Add(new ProRecord()
                                {
                                    ProjectID = ProjectID,
                                    VisitorID = v.VisitorID,
                                    Timestamp = v.Time,
                                    PlayState = 1
                                });
                                //生成消费订单
                                string orderId = IDHelper.getNextOrderID(DateTime.Now, 1);
                                db.Orders.Add(new Order()
                                {
                                    OrderID       = orderId,
                                    OrderState    = 1,
                                    OrderTime     = DateTime.Now,
                                    CommodityID   = charge.ProjectID,
                                    CommodityNum  = 1,
                                    CommodityType = 1,
                                    DoneTime      = DateTime.Now
                                });
                                //成对应的支付信息
                                db.Payments.Add(new Payment()
                                {
                                    OrderID       = orderId,
                                    PaymentAmount = charge.ProjectPrice,
                                    PaymentTime   = DateTime.Now,
                                    PaymentType   = 4
                                });
                                //增加游客支付的映射
                                db.Visitor2Orders.Add(new Visitor2Order()
                                {
                                    CardID    = v.CardID,
                                    OrderID   = orderId,
                                    VisitorID = v.VisitorID
                                });
                                //扣去游客卡上的余额
                                var visitor = db.Visitor2Cards.Where(t => t.VisitorID == v.VisitorID).Single();
                                visitor.Balance -= charge.ProjectPrice;
                                //提交事务
                                db.SaveChanges();
                            }
                        }
                    }

                    projectTemp.Clear();
                }
                catch (Exception ex)
                {
                }
            }
        }
예제 #17
0
        public IW2SUserDto Regist(string uName, string uPwd1, string uPwd2, string email)
        {
            //var code = VerifyCodeClass.YzmCode;
            //if (YZM.ToLower() != code.ToLower())
            //{
            //    return new IW2SUserDto { Error = "验证码填写错误!" };
            //}
            if (string.IsNullOrEmpty(uName) || string.IsNullOrEmpty(uPwd1))
            {
                return new IW2SUserDto {
                           Error = "用户名和密码不能为空"
                }
            }
            ;
            if (!uPwd1.Equals(uPwd2))
            {
                return new IW2SUserDto {
                           Error = "密码不一致!"
                }
            }
            ;
            if (string.IsNullOrEmpty(email))
            {
                return new IW2SUserDto {
                           Error = "邮箱不能为空!"
                }
            }
            ;
            bool dd = System.Text.RegularExpressions.Regex.IsMatch(email, @"[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?");

            if (dd == false)
            {
                return new IW2SUserDto {
                           Error = "邮箱格式不正确!"
                }
            }
            ;
            var builder = Builders <IW2SUser> .Filter;
            var filter  = builder.Eq(x => x.LoginName, uName);
            var _usr    = MongoDBHelper.Instance.Get_IW2SUser().Find(filter).FirstOrDefault();

            if (_usr != null)
            {
                return new IW2SUserDto {
                           Error = "用户名已经存在"
                }
            }
            ;
            //  var queryTask1 = new QueryDocument { { "UsrEmail", email } };
            filter = builder.Eq(x => x.UsrEmail, email);
            IW2SUser _usr1 = MongoDBHelper.Instance.Get_IW2SUser().Find(filter).FirstOrDefault();

            if (_usr1 != null)
            {
                return new IW2SUserDto {
                           Error = "该邮箱已经注册过,请换一个试试!"
                }
            }
            ;
            var md5 = EncryptHelper.GetEncryPwd(uPwd1.ToLower());

            _usr = new IW2SUser()
            {
                _id              = ObjectId.GenerateNewId(),
                LoginName        = uName,
                LoginPwd         = md5,
                UsrKey           = IDHelper.GetGuid(uName + usr_key),
                applicationState = false,
                IsEmailConfirmed = false,
                UsrEmail         = email,
                UsrRole          = UserTypes.Free,
                UsrNum           = 1,
                Gender           = "",
                MobileNo         = "",
                Remarks          = "",
                PictureSrc       = "",
                CreatedAt        = DateTime.Now.AddHours(8),
                ProjectNum       = 2,
                KeywordNum       = 20,
                ReportNum        = 2,
                LinkNum          = 2000
            };
            MongoDBHelper.Instance.Get_IW2SUser().InsertOne(_usr);
            IW2SUserDto freDto = new IW2SUserDto();

            freDto._id              = _usr._id.ToString();
            freDto.LoginName        = _usr.LoginName;
            freDto.LoginPwd         = _usr.LoginPwd;
            freDto.UsrRole          = _usr.UsrRole;
            freDto.UsrKey           = _usr.UsrKey;
            freDto.UsrEmail         = _usr.UsrEmail;
            freDto.IsEmailConfirmed = _usr.IsEmailConfirmed;
            freDto.applicationState = _usr.applicationState;
            freDto.UsrNum           = _usr.UsrNum;
            //freDto.Token = Helpers.IprAuthorizeAttribute.GetToken(_usr.LoginName, _usr.UsrRole);
            return(freDto);
        }
예제 #18
0
        public void Run()
        {
            while (true)
            {
                Random r = new Random();
                var    p = get_search_to_count();
                if (p == null)
                {
                    SetReady();
                    Thread.Sleep(r.Next(30000, 100000));
                    continue;
                }
                int LinkCount = 0;
                try
                {
                    SetBusy();
                    //                    var ipaddrs = System.Net.Dns.GetHostEntry(System.Environment.MachineName).AddressList;
                    //                    string ip = string.Empty;
                    //                    if (ipaddrs.Length >= 3)
                    //                    {
                    //                        ip = ipaddrs[2].ToString();
                    //                    }
                    //                    else if (string.IsNullOrEmpty(ip) && ipaddrs.Length >= 0)
                    //                    {
                    //                        ip = ipaddrs[0].ToString();
                    //                    }

                    //var internetIp = Utility.GetInternetIpAddress();
                    var botId = Utility.GenerateBotId().ToString().Replace("-", "");

                    var    pro         = Process.GetCurrentProcess();
                    string processName = IDHelper.GetGuid(pro.MainModule.FileName).ToString();
                    int    botInterval = p.BotIntervalHours == 0 ? 7 * 24 : p.BotIntervalHours;
                    var    update      = new UpdateDocument {
                        { "$set", new QueryDocument {
                              { "BotStatus", 1 }, { "NextBotStartAt", DateTime.UtcNow.AddHours((double)botInterval + 8) }
                              , { "BotTag", string.Format("{0}#", processName) },
                              { "BotId", botId }
                          } }
                    };

                    var result = MongoDBHelper.Instance.GetIW2S_Projects().UpdateOne(new QueryDocument {
                        { "_id", p._id }
                    }, update);

                    LinkCount = count(p);
                }
                catch (Exception ex)
                {
                    while (ex != null)
                    {
                        log("Project_BaiduLinkCount_Count ERROR.Message:{0},Statck:{1}".FormatStr(ex.Message, ex.StackTrace));
                        ex = ex.InnerException;
                    }
                }
                //Convert.ToDateTime(doc["CreateTime"]).ToLocalTime().ToString("yyyy-MM-dd HH:mm")
                try
                {
                    var update = new UpdateDocument {
                        { "$set", new QueryDocument {
                              { "LastBotEndAt", DateTime.UtcNow.AddHours(8) },
                              { "BotStatus", 2 }, { "BaiduLinkCount", LinkCount }
                          } }
                    };
                    var commendCol = MongoDBHelper.Instance.GetIW2S_Projects();
                    var result     = commendCol.UpdateOne(new QueryDocument {
                        { "_id", p._id }
                    }, update);
                }
                catch (Exception ex)
                {
                    log("get_proj_to_count ERROR ." + ex.Message);
                    Thread.Sleep(5000);
                }
            }
        }
        private void HanleTagData(IW2S_BaiduCommend tsk, List <IW2S_ExcludeKeyword> excludedKeywords, IW2SBotMng botmng, string[] searchKeywords, List <KeywordScore> patterns, string title, string href, string abs, ref string domain, string tag, bool isMarket, int rank)
        {
            int    maxScore = 0;
            string realUrl = null, detailHtml = null, abstracts = null;
            byte   appType = 0;

            int?baiduVStar = null;

            if (tag.Contains("c-icon-v1"))
            {
                baiduVStar = 1;
            }
            else if (tag.Contains("c-icon-v2"))
            {
                baiduVStar = 2;
            }
            else if (tag.Contains("c-icon-v3"))
            {
                baiduVStar = 3;
            }

            if (!string.IsNullOrWhiteSpace(href))
            {
                //Encoding enc = Encoding.UTF8;
                //detailHtml = HtmlQueryHelper.GetContent(href, 8000, ref enc, out realUrl);
                var tuplehtml = get_htmlUrl(href);
                if (tuplehtml != null && !string.IsNullOrEmpty(tuplehtml.Item1))
                {
                    realUrl = tuplehtml.Item1;
                }
                if (tuplehtml != null && !string.IsNullOrEmpty(tuplehtml.Item2))
                {
                    detailHtml = tuplehtml.Item2;
                }
                if (!string.IsNullOrEmpty(realUrl) && string.IsNullOrEmpty(domain))
                {
                    domain = GetDomain(realUrl);
                }
            }
            if (!string.IsNullOrEmpty(detailHtml) && detailHtml.Contains("document.getElementById(\"link\").click()"))
            {
                var gourl = detailHtml.GetFirstHref2();
                if (!string.IsNullOrEmpty(gourl))
                {
                    var tuplehtml = get_htmlUrl(gourl);
                    if (tuplehtml != null && !string.IsNullOrEmpty(tuplehtml.Item1))
                    {
                        realUrl = tuplehtml.Item1;
                    }
                    if (tuplehtml != null && !string.IsNullOrEmpty(tuplehtml.Item2))
                    {
                        detailHtml = tuplehtml.Item2;
                    }
                    if (!string.IsNullOrEmpty(realUrl) && string.IsNullOrEmpty(domain))
                    {
                        domain = GetDomain(realUrl);
                    }
                }
            }
            if (string.IsNullOrEmpty(realUrl))
            {
                realUrl = href;
            }
            List <KeywordScore> matchpatterns = new List <KeywordScore>();

            if (string.IsNullOrEmpty(detailHtml))
            {
                return;
            }
            else
            {
                //if (!detailHtml.Contains(tsk.CommendKeyword))
                //{
                //    return;
                //}
                var           hrefs          = detailHtml.GetDescendents("a", "href");
                StringBuilder sbabstracts    = new StringBuilder();
                List <string> abstractlist   = new List <string>();
                StringBuilder sbabstractlist = new StringBuilder();

                foreach (KeywordScore pattern in patterns)
                {
                    string[] splitDetailHtmls = detailHtml.SplitWith(pattern.Keyword);
                    if (splitDetailHtmls.Length > 1)
                    {
                        matchpatterns.Add(pattern);
                    }
                    StringBuilder sbpatternStr = new StringBuilder();
                    for (int i = 0; i < splitDetailHtmls.Length - 1; i++)
                    {
                        string splitDetailHtml1 = splitDetailHtmls[i];
                        string splitDetailHtml2 = i < splitDetailHtmls.Length - 2 ? splitDetailHtmls[i + 1] : "";
                        for (int j = splitDetailHtml1.Length - 1; j >= 0; j--)
                        {
                            if (split_bef_commas.Contains(splitDetailHtml1[j]) && j - 1 >= 0 && !split_num_commas.Contains(splitDetailHtml1[j - 1]))
                            {
                                break;
                            }
                            sbpatternStr.Append(splitDetailHtml1[j]);
                        }
                        for (int q = sbpatternStr.Length - 1; q >= 0; q--)
                        {
                            sbabstracts.Append(sbpatternStr[q]);
                        }
                        sbabstracts.Append(pattern.Keyword);
                        sbpatternStr.Clear();
                        for (int j = 0; j < splitDetailHtml2.Length; j++)
                        {
                            if (split_aft_commas.Contains(splitDetailHtml2[j]) && j + 1 < splitDetailHtml2.Length && !split_num_commas.Contains(splitDetailHtml2[j + 1]))
                            {
                                break;
                            }
                            sbpatternStr.Append(splitDetailHtml2[j]);
                        }
                        sbabstracts.Append(sbpatternStr);
                        sbpatternStr.Clear();

                        string tmpsbabstracts = sbabstracts.ToString();
                        tmpsbabstracts = IW2SBaiduQuery.RemoveInivalidChar(tmpsbabstracts.GetTxtFromHtml2().RemoveSpace().GetLower());
                        if (!abstractlist.Contains(tmpsbabstracts))
                        {
                            abstractlist.Add(tmpsbabstracts);
                            sbabstractlist.Append(tmpsbabstracts).Append(" ");
                        }
                        sbabstracts.Clear();
                    }
                }
                //获取摘要
                abstracts = sbabstractlist.ToString();
                if (!string.IsNullOrEmpty(abstracts) && matchpatterns.Count > 0)
                {
                    maxScore  = matchpatterns.Max(x => x.Score ?? 50);
                    appType   = matchpatterns.Where(x => x.BizType > 0).OrderByDescending(x => x.Score).Select(x => x.BizType).FirstOrDefault();
                    maxScore += matchpatterns.Sum(x => (x.Score ?? 50) / 10);
                    maxScore -= matchpatterns.Max(x => (x.Score ?? 50) / 10);
                }
            }
            if (string.IsNullOrEmpty(abstracts) && !string.IsNullOrEmpty(abs))
            {
                matchpatterns = patterns.Where(x => abs.Contains(x.Keyword)).ToList();
                if (matchpatterns.Count > 0)
                {
                    maxScore = matchpatterns.Max(x => x.Score ?? 50);
                    appType  = matchpatterns.Where(x => x.BizType > 0).OrderByDescending(x => x.Score).Select(x => x.BizType).FirstOrDefault();

                    maxScore += matchpatterns.Sum(x => (x.Score ?? 50) / 10);
                    maxScore -= matchpatterns.Max(x => (x.Score ?? 50) / 10);
                }
            }
            if (maxScore > 100)
            {
                maxScore = 100;
            }


            bool          is_title_matched = title.GetLower().IsContains2(searchKeywords);
            bool          is_abstr_matched = abs.IsContains2(searchKeywords);
            BaiduItemPart part             = is_title_matched && is_abstr_matched ? BaiduItemPart.TitleAbstract :
                                             is_title_matched ? BaiduItemPart.Title :
                                             is_abstr_matched ? BaiduItemPart.Abstract : BaiduItemPart.None;

            Regex           reg = new Regex("(20\\d{2}[-/]\\d{1,2}[-/]\\d{1,2})|(20\\d{2}年\\d{1,2}月\\d{1,2}日)");
            MatchCollection mc  = reg.Matches(detailHtml);
            //MatchCollection cols = reg.Matches(item.Html);
            string time = "";

            if (mc.Count > 0)
            {
                foreach (Match x in mc)
                {
                    //判断是正文中的还是代码和注释中的时间
                    if (!string.IsNullOrEmpty(x.Value))
                    {
                        var txt    = detailHtml.SubAfter(x.Value);
                        var index1 = txt.IndexOf('<');
                        var index2 = txt.IndexOf('>');
                        var index3 = txt.IndexOf('\"');
                        //只使用正文中的时间
                        if (index1 < index2 && index1 < index3)
                        {
                            time = x.Value;
                            break;
                        }
                    }
                }
            }


            IW2S_level1link l1 = new IW2S_level1link
            {
                UsrId     = tsk.UsrId,
                Domain    = domain,
                TopDomain = GetLevel1Domain(domain),
                Keywords  = string.Format("{0}", tsk.CommendKeyword),
                LinkUrl   = realUrl,
                MatchAt   = (byte)part,
                Html      = detailHtml,

                AppType         = appType,
                BizId           = IDHelper.GetGuid("{0}/{1}".FormatStr(realUrl, tsk._id.ToString())),
                SearchkeywordId = tsk._id.ToString(),
                CreatedAt       = DateTime.UtcNow.AddHours(8),
                Description     = abs,
                Title           = title,
                Score           = maxScore,
                Abstract        = abstracts,
                IsMarket        = isMarket,
                ProjectId       = tsk.ProjectId,
                PublishTime     = time,
                AlternateFields = "0",
                Rank            = rank
            };

            if (baiduVStar.HasValue)
            {
                l1.BaiduVStar = baiduVStar.Value;
            }

            botmng.save_level1_links(new List <IW2S_level1link> {
                l1
            }, tsk, excludedKeywords);
        }
예제 #20
0
 public static void GenerateEmployees(List <Employee> EmployeeList)
 {
     EmployeeList.Add(new Employee("John Doe", 918237423, "Filler addr1", "Doctor", IDHelper.GenerateID(), "9:00 - 13:00"));
     EmployeeList.Add(new Employee("Mary Sue", 918233223, "Filler addr2", "Doctor", IDHelper.GenerateID(), "10:00 - 12:00"));
     EmployeeList.Add(new Employee("Mike Law", 728783212, "Filler addr3", "Groomer", IDHelper.GenerateID(), "16:00 - 18:00"));
     EmployeeList.Add(new Employee("Larry John", 289374621, "Filler addr4", "Nurse", IDHelper.GenerateID(), "8:00 - 12:00"));
 }
 public static Guid GetEncryPwd(string pwd)
 {
     return(IDHelper.GetGuid(pwd + pwd_key));
 }
예제 #22
0
        void SaveResult(List <XListing> listings, BotTypes botType, string recordId, FreeTask tsk)
        {
            listings.ToList().ForEach(x =>
            {
                if (string.IsNullOrEmpty(x.ShopName) && !string.IsNullOrEmpty(x.SiteName) && !x.BotShopID.HasValue &&
                    !x.SiteName.ToLower().Contains("taobao") && !x.SiteName.ToLower().Contains("alibaba"))
                {
                    x.ShopName  = x.SiteName;
                    x.BotShopID = x.SiteID;
                }
                if (!x.BotShopID.HasValue && !string.IsNullOrEmpty(x.ShopName))
                {
                    x.BotShopID = IDHelper.GetGuid(string.Format("{0},{1},{2},{3}", x.ShopName, x.SiteName, tsk._id, x.ShopID));
                }
            });
            var shopList = listings;

            shopList = shopList.DistinctBy(x => x.BotShopID);
            //var exists_ids = MySqlDbHelper.GetExsitsIds<Guid?>(com, "bot_shops", "Shop_id", shopList.Select(x => x.BotShopID).ToArray());
            //if (exists_ids != null && exists_ids.Count > 0)
            //{
            //    shopList = shopList.Where(x => !exists_ids.Contains(x.BotShopID)).ToList();
            //}

            FieldsDocument shopfd = new FieldsDocument();

            shopfd.Add("BotShopID", 1);
            // MongoCollection<Guid> shopcol = MongoDBHelper<Guid>.GetMongoDB().GetCollection<Guid>("FreeBotShop");
            var shopcol = MongoDBHelper.Instance.Get_FreeBotShop();
            var builder = Builders <FreeBotShop> .Filter;

            List <Guid?> BotShopID = shopList.Select(x => x.BotShopID).ToList();
            //  var existsshop_objs = shopcol.Find(MongoDB.Driver.Builders.Query.In("BotShopID", new BsonArray(BotShopID))).SetFields(shopfd);
            var          existsshop_objs = shopcol.Find(builder.In(x => x.Shop_id, BotShopID)).Project(x => x.Shop_id).ToList();
            List <Guid?> exists_ids      = new List <Guid?>();

            foreach (var result in existsshop_objs)
            {
                exists_ids.Add(result);
            }
            if (exists_ids != null && exists_ids.Count > 0)
            {
                shopList = shopList.Where(x => !exists_ids.Contains(x.BotShopID)).ToList();
            }
            if (shopList == null || shopList.Count == 0)
            {
                return;
            }
            List <FreeBotShop> dt = null;

            if (shopList.Count > 0)
            {
                dt = GetShopList(shopList);
                //  var saved = MongoDBHelper<FreeBotShop>.BatchInsertData(dt, "FreeBotShop");
                shopcol.InsertMany(dt);
                log("to save bot_shops");
                log("Done");
            }
            listings.ToList().ForEach(x =>
            {
                if (!x.BotItemID.HasValue && !string.IsNullOrEmpty(x.ItemName))
                {
                    x.BotItemID = IDHelper.GetGuid(string.Format("{0},{1},{2},{3}", x.ItemName, x.SiteName, tsk._id, x.ItemID));
                }
            });
            var itemList = listings;

            itemList = itemList.DistinctBy(x => x.BotItemID);
            //var exists_itemids = MySqlDbHelper.GetExsitsIds<Guid?>(com, "bot_items", "ItemId", itemList.Select(x => x.BotItemID).ToArray());
            //if (exists_itemids != null && exists_itemids.Count > 0)
            //{
            //    itemList = itemList.Where(x => !exists_itemids.Contains(x.BotItemID)).ToList();
            //}

            FieldsDocument fd = new FieldsDocument();

            fd.Add("BotItemID", 1);
            //   MongoCollection<Guid> col = MongoDBHelper<Guid>.GetMongoDB().GetCollection<Guid>("FreeBotItem");
            var          col         = MongoDBHelper.Instance.Get_FreeBotItem();
            var          itemBuilder = Builders <FreeBotItem> .Filter;
            List <Guid?> BotItemID   = itemList.Select(x => x.BotItemID).ToList();
            //  var exists_objs = col.Find(MongoDB.Driver.Builders.Query.In("BotItemID", new BsonArray(BotItemID))).SetFields(fd);
            var          exists_objs    = col.Find(itemBuilder.In(x => x.ItemId, BotItemID)).Project(x => x.ItemId).ToList();
            List <Guid?> existsitem_ids = new List <Guid?>();

            foreach (var result in exists_objs)
            {
                existsitem_ids.Add(result);
            }
            if (existsitem_ids != null && existsitem_ids.Count > 0)
            {
                itemList = itemList.Where(x => !existsitem_ids.Contains(x.BotItemID)).ToList();
            }

            List <XListing> updatelinks = new List <XListing>();

            if (existsitem_ids != null && existsitem_ids.Count > 0)
            {
                updatelinks = updatelinks.Where(x => existsitem_ids.Contains(x.BotItemID)).ToList();
            }
            update_level1_links(updatelinks, botType, recordId, tsk);
            if (itemList == null || itemList.Count == 0)
            {
                return;
            }

            var itemdt = GetItemList(itemList);

            //  var savedListings = MySqlDbHelper.BatchInsert(con, "bot_items", itemdt);
            // var savedListings = MongoDBHelper<FreeBotItem>.BatchInsertData(itemdt, "FreeBotItem");
            col.InsertMany(itemdt);

            // var wequery = new QueryDocument { { "_id", new ObjectId(recordId) } };
            // FreeTaskRecord TaskList = MongoDBHelper<FreeTaskRecord>.Find1("FreeTaskRecord", wequery);
            var            colRecord     = MongoDBHelper.Instance.Get_FreeTaskRecord();
            var            RecordBuilder = Builders <FreeTaskRecord> .Filter;
            FreeTaskRecord TaskList      = colRecord.Find(RecordBuilder.Eq(x => x._id, new ObjectId(recordId))).FirstOrDefault();
            int            LinksNum      = 0;
            int            ShopsNum      = 0;

            LinksNum = TaskList.LinksNum + itemdt.Count;
            ShopsNum = TaskList.ShopsNum + dt.Count;
            var updateWebsiteCount = new UpdateDocument {
                { "$set", new QueryDocument {
                      { "LinksNum", LinksNum }, { "ShopsNum", ShopsNum }
                  } }
            };

            //  MongoDBHelper<FreeTaskRecord>.Update("FreeTaskRecord", wequery, updateWebsiteCount);
            MongoDBHelper.Instance.Get_FreeTaskRecord().UpdateOne(new QueryDocument {
                { "_id", new ObjectId(recordId) }
            }, updateWebsiteCount);


            var      colTask      = MongoDBHelper.Instance.Get_FreeTask();
            var      TaskBuilder  = Builders <FreeTask> .Filter;
            FreeTask Task2List    = colTask.Find(TaskBuilder.Eq(x => x._id, itemdt[0].taskId)).FirstOrDefault();
            int      TaskLinksNum = 0;
            int      TaskShopsNum = 0;

            TaskLinksNum = Task2List.LinksNum + itemdt.Count;
            TaskShopsNum = Task2List.ShopsNum + dt.Count;
            var TaskupdateWebsiteCount = new UpdateDocument {
                { "$set", new QueryDocument {
                      { "LinksNum", TaskLinksNum }, { "ShopsNum", TaskShopsNum }
                  } }
            };

            //  MongoDBHelper<FreeTaskRecord>.Update("FreeTaskRecord", wequery, updateWebsiteCount);
            MongoDBHelper.Instance.Get_FreeTask().UpdateOne(new QueryDocument {
                { "_id", itemdt[0].taskId }
            }, TaskupdateWebsiteCount);

            log("to save listings");
            log("Done");
        }
예제 #23
0
        public void SetID(XTask tsk)
        {
            Listings.ToList().ForEach(x =>
            {
                if (tsk != null)
                {
                    x.CompanyName        = tsk.CompanyName;
                    x.SiteName           = tsk.SiteName;
                    x.DetailQueryName    = tsk.DetailQueryName;
                    x.CommentQueryName   = tsk.CommentQueryName;
                    x.BuyerListQueryName = tsk.BuyerListQueryName;
                    x.BotComments        = tsk.BotComments;
                    x.BotBuyerList       = tsk.BotBuyerList;
                    x.RealBrandName      = tsk.BrandName;
                    x.RealProductName    = tsk.ProductName;
                    if (tsk.ItemID.HasValue)
                    {
                        x.BotItemID = tsk.ItemID.Value;
                    }
                    if (tsk.ShopID.HasValue)
                    {
                        x.BotShopID = tsk.ShopID.Value;
                    }
                }

                if (!x.BotShopID.HasValue && !string.IsNullOrEmpty(x.ShopName))
                {
                    x.BotShopID = IDHelper.GetGuid(string.Format("{0},{1}", x.ShopID ?? x.ShopName, x.SiteName));
                }
                if (!x.BotItemID.HasValue && !string.IsNullOrEmpty(x.ItemName))
                {
                    if (!string.IsNullOrEmpty(x.ItemID))
                    {
                        x.BotItemID = IDHelper.GetGuid(string.Format("{0},{1}", x.ItemID, x.SiteName));
                    }
                    else if (x.BotShopID.HasValue)
                    {
                        x.BotItemID = IDHelper.GetGuid(string.Format("{0},{1}", x.ItemName, x.BotShopID));
                    }
                    else if (!string.IsNullOrEmpty(x.ItemDetailUrl))
                    {
                        x.BotItemID = IDHelper.GetGuid(x.ItemDetailUrl);
                    }
                    else
                    {
                        x.BotItemID = IDHelper.GetGuid(string.Format("{0},{1}", x.ItemName, x.SiteName));
                    }
                }
                if (x.ItemBotStatus == BotStatus.Removed)
                {
                    x.ClosedAt = DateTime.Now;
                }
                x.ItemCommentList.ForEach(y =>
                {
                    y.EntityID = x.BotItemID;
                    y.ID       = IDHelper.GetGuid(string.Format("{0},{1},{2}", x.BotItemID, y.Poster, y.PostAt));
                });
                x.SalesRecords.ForEach(y =>
                {
                    y.PackageID = x.BotItemID;
                });
            });
        }
예제 #24
0
        private void BaseButton_ConfirmRefund_Click(object sender, EventArgs e)
        {
            try
            {
                if (originalRetailCostume == null)
                {
                    GlobalMessageBox.Show("请选择销售单!");
                    return;
                }
                if (!string.IsNullOrEmpty(this.originalRetailCostume.RetailOrder.RefundOrderID))
                {
                    GlobalMessageBox.Show("该销售单号已经退过货,不能再次退货!");
                    return;
                }
                if (this.originalRetailCostume.RetailOrder.IsCancel)
                {
                    GlobalMessageBox.Show("该销售单号已被冲单!");
                    return;
                }

                if (this.guideComboBox1.SelectedIndex == 0)
                {
                    GlobalMessageBox.Show("该笔单的导购员不能为空!");
                    return;
                }
                string id = IDHelper.GetID(OrderPrefix.RefundOrder, GlobalCache.GetShop(shopID).AutoCode);

                //if (this.currentRetailCostume.RetailOrder.ShopID != shopID || this.currentRetailCostume.RetailOrder.EmOnline)
                //{
                //    GlobalMessageBox.Show("该商品不是在本店销售的,不能退货!");
                //    return;
                //}
                bool isNoHasGuidFlag = false;
                if (this.currentRetailCostume.RetailDetailList != null && this.currentRetailCostume.RetailDetailList.Count > 0)
                {
                    foreach (RetailDetail detail in this.currentRetailCostume.RetailDetailList)
                    {
                        if (detail.GuideID == null || detail.GuideID == "")
                        {
                            isNoHasGuidFlag = true;
                            break;
                        }
                    }
                }
                if (isNoHasGuidFlag)
                {
                    GlobalMessageBox.Show("导购员不能为空,请检查列表里所有款号的导购员!");
                    return;
                }

                #region 创建RefundCostume对象


                string selectShopid = ValidateUtil.CheckEmptyValue(this.skinComboBoxShopID.SelectedValue);

                List <Guide> guideList = CommonGlobalCache.GuideList.FindAll(t => t.State == 0 && t.ShopID == selectShopid);

                this.GuideName.DataSource    = guideList;
                this.GuideName.DisplayMember = "Name";
                this.GuideName.ValueMember   = "ID";

                RefundCostume costume = new RefundCostume()
                {
                    RefundOrder      = null,
                    RefundDetailList = new List <RetailDetail>()
                };
                int     totalCount = 0;
                decimal totalPrice = 0;
                decimal totalCost  = 0;
                foreach (RetailDetail detail in this.currentRetailCostume.RetailDetailList)
                {
                    if (detail.IsRefund && detail.RefundCount > 0)
                    {
                        totalCount += detail.RefundCount;
                        totalPrice += detail.RefundCount * detail.Price;
                        totalCost  += detail.RefundCount * detail.CostPrice;

                        costume.RefundDetailList.Add(this.RetailDetailToRefundDetail(detail, id));
                    }
                }
                List <String> costumeIds = new List <string>();
                foreach (var item in costume.RefundDetailList)
                {
                    if (!costumeIds.Contains(item.CostumeID))
                    {
                        costumeIds.Add(item.CostumeID);
                    }
                }

                if (costumeIds != null && costumeIds.Count > 0)
                {
                    //判断是否又禁用的商品,并提示返回
                    InteractResult interactResult = GlobalCache.ServerProxy.IsCostumeValid(costumeIds);
                    if (interactResult.ExeResult == ExeResult.Error)
                    {
                        GlobalMessageBox.Show(interactResult.Msg);
                        return;
                    }
                }

                RetailOrder refundOrder = new RetailOrder()
                {
                    ID            = id,
                    IsRefundOrder = true,
                    OriginOrderID = this.currentRetailCostume.RetailOrder.ID,
                    // GuideID = this.currentRetailCostume.RetailOrder.GuideID,
                    //  OperateGuideID = this.currentRetailCostume.RetailOrder.GuideID,
                    GuideID          = (string)this.guideComboBox1.SelectedValue,
                    ShopID           = shopID,
                    MemeberID        = this.currentRetailCostume.RetailOrder.MemeberID,
                    SalesPromotionID = this.currentRetailCostume.RetailOrder.SalesPromotionID,
                    PromotionText    = this.currentRetailCostume.RetailOrder.PromotionText,
                    EntryUserID      = CommonGlobalCache.CurrentUserID,
                    //   TotalMoneyReceived = this.currentRetailCostume.RetailOrder.TotalMoneyReceived,
                    // TotalMoneyReceivedActual = this.currentRetailCostume.RetailOrder.TotalMoneyReceivedActual,
                    MoneyBankCard     = 0,
                    MoneyWeiXin       = 0,
                    MoneyAlipay       = 0,
                    MoneyOther        = 0,
                    SmallMoneyRemoved = 0,
                    MoneyChange       = 0,
                    TotalCount        = totalCount * -1,
                    TotalCost         = totalCost * -1,
                    TotalPrice        = totalPrice * -1,
                    MoneyDiscounted   = -totalCount == this.originalRetailCostume.RetailOrder.TotalCount ? this.originalRetailCostume.RetailOrder.MoneyDiscounted * -1 : 0,//若是全部退款,折扣金额为原始折扣金额,否则为0
                    Remarks           = this.skinTextBox_RefundReason.SkinTxt.Text.Trim(),
                    CreateTime        = dateTimePicker_Start.Value,
                    EntryTime         = DateTime.Now,
                    IsNotPay          = this.currentRetailCostume.RetailOrder.IsNotPay,
                };
                costume.RefundOrder = refundOrder;
                #endregion
                decimal sourceTotalMoneyReceived = this.currentRetailCostume.RetailOrder.TotalMoneyReceived;

                #region 根据活动获取退款的金额,并赋值给RefundCostume
                decimal originalDonate = 0;
                if (this.originalRetailCostume.RetailOrder.MoneyVipCard != 0)
                {
                    originalDonate = this.originalRetailCostume.RetailOrder.MoneyVipCardDonate / this.originalRetailCostume.RetailOrder.MoneyVipCard;
                }
                //应该退还的金额

                decimal moneyBuyByTicket = CalGiftTicket(costume);

                SettlementMoney settlementMoney = new SettlementMoney(balanceRound);

                RefundMoney refundMoney = settlementMoney.GetRefundMoney(this.originalRetailCostume, costume, moneyBuyByTicket, GlobalCache.GetSalesPromotionFromAll(this.originalRetailCostume.RetailOrder.SalesPromotionID), GlobalCache.CurrentShop.MinDiscount);
                costume.RefundOrder.MoneyCash          = refundMoney.RefundCash * -1;
                costume.RefundOrder.MoneyCash2         = costume.RefundOrder.MoneyCash;
                costume.RefundOrder.MoneyIntegration   = refundMoney.RefundIntegration * -1;
                costume.RefundOrder.MoneyVipCard       = refundMoney.RefundStoredCard * -1;
                costume.RefundOrder.MoneyVipCardMain   = refundMoney.RefundStoredCard * (1 - originalDonate) * -1;
                costume.RefundOrder.MoneyVipCardDonate = refundMoney.RefundStoredCard * originalDonate * -1;
                //costume.RefundOrder.MoneyBuyByTicket = moneyBuyByTicket;
                costume.RefundOrder.RetailMoneyDeductedByTicket = originalRetailCostume.RetailOrder.MoneyDeductedByTicket;
                costume.RefundOrder.MoneyDeductedByTicket       = moneyBuyByTicket;

                //总计=现金+积分+VIP卡+优惠券
                //这笔单的应收金额 - (不退的那几件以原价* 数量 -满减金额) - (退的那几件)优惠券
                costume.RefundOrder.TotalMoneyReceived       = costume.RefundOrder.MoneyCash + costume.RefundOrder.MoneyIntegration + costume.RefundOrder.MoneyVipCard;
                costume.RefundOrder.TotalMoneyReceivedActual = costume.RefundOrder.MoneyCash + costume.RefundOrder.MoneyVipCardMain;
                costume.RefundOrder.Benefit = costume.RefundOrder.TotalMoneyReceivedActual - costume.RefundOrder.TotalCost;
                ////平摊

                #endregion
                if (Math.Abs(costume.RefundOrder.TotalCount) < 1)
                {
                    GlobalMessageBox.Show("退货数量不能小于1");
                    return;
                }


                //foreach (RetailDetail detail in costume.RefundDetailList)
                //{
                //    if (detail.IsRefund && detail.RefundCount > 0)
                //    {
                //        detail.SinglePrice = detail.SumMoney / detail.BuyCount * -1;
                //    }
                //}

                ConfirmRefundForm confirmRefundForm = new ConfirmRefundForm(costume, shopID, this.dataGridView1, sourceTotalMoneyReceived, 1);
                DialogResult      result            = confirmRefundForm.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                this.ResetForm();
            }
            catch (Exception ee)
            {
                GlobalUtil.ShowError(ee);
            }
        }
        public void Run()
        {
            while (true)
            {
                Random r = new Random();
                var    p = get_search_to_qry();
                if (p == null)
                {
                    SetReady();
                    Thread.Sleep(r.Next(30000, 100000));
                    continue;
                }

                try
                {
                    SetBusy();

                    //var internetIp = IWSBot.Utility.Utility.GetInternetIpAddress();
                    var botId = IWSBot.Utility.Utility.GenerateBotId().ToString().Replace("-", "");

                    var    pro         = Process.GetCurrentProcess();
                    string processName = IDHelper.GetGuid(pro.MainModule.FileName).ToString();
                    int    botInterval = p.BotIntervalHours == 0 ? 7 * 24 : p.BotIntervalHours;
                    var    update      = new UpdateDocument {
                        { "$set", new QueryDocument {
                              { "BotStatus", 1 }, { "NextBotStartAt", DateTime.UtcNow.AddHours((double)botInterval + 8) }
                              , { "BotTag", string.Format("{0}#", processName) },
                              { "BotId", botId }
                          } }
                    };

                    var result = MongoDBHelper.Instance.GetIW2S_WB_BaiduCommends().UpdateOne(new QueryDocument {
                        { "_id", p._id }
                    }, update);

                    query(p);
                }
                catch (Exception ex)
                {
                    while (ex != null)
                    {
                        Console.WriteLine("baidu_query ERROR.Message:{0},Statck:{1}".FormatStr(ex.Message, ex.StackTrace));
                        ex = ex.InnerException;
                    }
                }
                //Convert.ToDateTime(doc["CreateTime"]).ToLocalTime().ToString("yyyy-MM-dd HH:mm")
                try
                {
                    var update = new UpdateDocument {
                        { "$set", new QueryDocument {
                              { "LastBotEndAt", DateTime.UtcNow.AddHours(8) },
                              { "BotStatus", 2 }
                          } }
                    };
                    var commendCol = MongoDBHelper.Instance.GetIW2S_WB_BaiduCommends();
                    var result     = commendCol.UpdateOne(new QueryDocument {
                        { "_id", p._id }
                    }, update);

                    var builder = Builders <IW2S_WB_level1link> .Filter;
                    var filter  = builder.Eq(x => x.UsrId, p.UsrId);
                    filter &= builder.Eq(x => x.SearchkeywordId, p._id);
                    filter &= builder.Ne(x => x.DataCleanStatus, (byte)2);
                    filter &= builder.Regex(x => x.Description, new BsonRegularExpression("/.*" + p.Keyword + ".*/i"));

                    var col        = MongoDBHelper.Instance.GetIW2S_WB_level1links();
                    var agreresult = col.Aggregate().Match(filter)
                                     .Group(new BsonDocument {
                        { "_id", "$_id" }, { "Count", new BsonDocument("$sum", 1) }
                    })
                                     .ToListAsync()
                                     .Result;

                    var vallinkCount = agreresult.Count;
                    update = new UpdateDocument {
                        { "$set", new QueryDocument {
                              { "ValLinkCount", vallinkCount }
                          } }
                    };

                    commendCol.UpdateOne(new QueryDocument {
                        { "_id", p._id }
                    }, update);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("get_proj_to_qry ERROR ." + ex.Message);
                    Thread.Sleep(5000);
                }
            }
        }
        private void BaseButtonConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.bean == null)
                {
                    GlobalMessageBox.Show(this, "找不到客户信息");
                    this.textBoxCustomer.Focus();
                    return;
                }

                if (this.textBoxAmount.Value == 0)
                {
                    GlobalMessageBox.Show(this, "请输入金额");
                    this.textBoxAmount.Focus();
                    return;
                }

                if (CommonGlobalUtil.EngineUnconnectioned(this))
                {
                    return;
                }


                PfCustomerRechargeRecord pfCustomerRechargeRecord = new PfCustomerRechargeRecord()
                {
                    BalanceOld = this.bean.Balance,
                    BalanceNew = this.bean.Balance + decimal.ToInt32(textBoxAmount.Value),
                    ID         = IDHelper.GetID(OrderPrefix.PfCustomerRechargeRecord, CommonGlobalCache.CurrentShop.AutoCode),
                    //  BalanceOld =
                    Remarks       = richTextBoxRemark.Text,
                    PfCustomerID  = bean.ID,
                    CreateTime    = DateTime.Now,
                    RechargeMoney = decimal.ToInt32(textBoxAmount.Value)
                };

                InteractResult result = GlobalCache.ServerProxy.InsertPfCustomerRechargeRecord(pfCustomerRechargeRecord);
                switch (result.ExeResult)
                {
                case ExeResult.Success:
                    GlobalMessageBox.Show(this.FindForm(), "添加成功!");
                    this.bean.Balance = pfCustomerRechargeRecord.BalanceNew;
                    //TabPageClose(this.CurrentTabPage, this.SourceCtrlType);
                    PfCustomerRechargeRecordSuccess?.Invoke(pfCustomerRechargeRecord);
                    this.Close();
                    break;

                case ExeResult.Error:
                    GlobalMessageBox.Show(this.FindForm(), result.Msg);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex) { ShowError(ex); }
            finally
            {
                UnLockPage();
            }
        }
예제 #27
0
        private ReturnCostume Build()
        {
            if (
                this.curDetailList == null || this.curDetailList.Count == 0)
            {
                return(null);
            }
            int                totalCount = 0;
            decimal            totalPrice = 0;
            decimal            totalCost  = 0;
            List <BoundDetail> details    = new List <BoundDetail>();

            //使用补货申请单的店铺ID信息

            // Shop shop = GlobalCache.ShopList.Find(t => t.ID == this.curReplenishOrder.ShopID);
            Shop   shop          = (Shop)this.skinComboBoxShopID.SelectedItem;
            string id            = IDHelper.GetID(OrderPrefix.OutboundOrder, shop.AutoCode);
            string returnOrderId = IDHelper.GetID(OrderPrefix.ReturnOrder, shop.AutoCode);

            if (action == OperationEnum.Pick)
            {
                returnOrderId = this.order?.ID;
            }
            foreach (BoundDetail detail in this.curDetailList)
            {
                if (detail.SumCount <= 0)
                {
                    continue;
                }
                detail.SumCount = -detail.SumCount;
                detail.SumMoney = -detail.SumMoney;
                //  detail.SumCount = -detail.SumMoney;
                totalCount         += detail.SumCount;
                totalPrice         += detail.SumMoney;
                totalCost          += detail.SumCost;
                detail.BoundOrderID = id;
                detail.SupplierID   = ValidateUtil.CheckEmptyValue(skinComboBoxSupplierID.SelectedValue);
                details.Add(detail);
                //   details.Add(this.OutboundDetailConvertToOutboundDetail(detail, id));
            }

            OutboundOrder order = new OutboundOrder()
            {
                SourceOrderID  = returnOrderId,
                ID             = id,
                OperatorUserID = GlobalCache.CurrentUserID,
                ShopID         = ValidateUtil.CheckEmptyValue(this.skinComboBoxShopID.SelectedValue),
                CreateTime     = dateTimePicker_Start.Value,
                EntryTime      = DateTime.Now,
                TotalCount     = totalCount,
                TotalPrice     = totalPrice,
                TotalCost      = totalCost,
                Remarks        = this.skinTextBox_Remarks.SkinTxt.Text
            };


            PurchaseOrder pOrder = new PurchaseOrder()
            {
                SupplierID     = ValidateUtil.CheckEmptyValue(this.skinComboBoxSupplierID.SelectedValue),
                ID             = returnOrderId,
                AdminUserID    = GlobalCache.CurrentUserID,
                InboundOrderID = order.ID,
                DestShopID     = order.ShopID,
                CreateTime     = dateTimePicker_Start.Value,
                EntryTime      = DateTime.Now,
                TotalCount     = totalCount,
                TotalPrice     = totalPrice,
                TotalCost      = totalCost,
                Remarks        = this.skinTextBox_Remarks.SkinTxt.Text
            };

            return(new ReturnCostume()
            {
                ReturnOrder = pOrder,
                OutboundOrder = order,
                OutboundDetailList = details
            });
        }
예제 #28
0
        /// <summary>
        /// Loads data from the Marvel Chronology Project (MCP) site
        /// and saves it into the specified directory. Note that KEY is
        /// not extracted, you have to get it manually.
        /// </summary>
        /// <param name="pathResultsDir">
        /// Path to the directory where the results will be saved.
        /// </param>
        public static void LoadGraphFromInternet(string pathResultsDir)
        {
            Console.WriteLine("Starting to extract data from Marvel Chronology Project . . .");

            HashSet <string> setCharactersID = new HashSet <string>();

            List <string> inputPages = ReadInputPages();

            int i = 1;

            foreach (string page in inputPages)
            {
                // Load html page
                Console.WriteLine("Loading page " + i + " of " + inputPages.Count + " . . .");
                HtmlWeb      htmlWeb  = new HtmlWeb();
                HtmlDocument htmlPage = htmlWeb.Load(page);

                // Start data extraction
                Console.WriteLine("Extracting data from " + page + " . . .");
                var tagTitle = htmlPage.DocumentNode.SelectNodes("html/head/title");
                foreach (HtmlNode node in tagTitle)
                {
                    Console.WriteLine("Page title: " + node.InnerText);
                }

                List <HtmlNode> chrons = htmlPage.DocumentNode.Descendants("div").Where(x => x.Id == "chrons").ToList();

                if (chrons.Count > 1)
                {
                    Console.WriteLine("ERROR! More than 1 element with ID = \"chrons\" has been found.");
                    return;
                }

                var charactersInfo = from HtmlNode pTag in chrons[0].Descendants("p")
                                     where (pTag.ChildNodes.Where(x => x.Name == "span").Count() == 2)
                                     select new
                {
                    Name = (((from HtmlNode spanChar in pTag.Descendants("span")
                              where (spanChar.Attributes["class"].Value == "char")
                              select spanChar.Descendants("b"))
                             .ElementAt(0).ElementAt(0) as HtmlNode)
                            .InnerText as string)
                           .Trim().ToLower()
                           .Replace(',', ' ').Replace('\n', ' ').Replace("  ", " "),

                    Id = (pTag.Id as string)
                         .Trim().ToLower(),

                    Links = (from HtmlNode tagA in pTag.Descendants("a")
                             where (tagA.Attributes["href"] != null)
                             select tagA.Attributes["href"].Value)
                            .Select(x => x.Trim().ToLower())
                            .ToList <string>(),

                    Comics = ((from HtmlNode spanChron in pTag.Descendants("span")
                               where (spanChron.Attributes["class"].Value == "chron")
                               select spanChron.InnerText)
                              .ElementAt(0) as string)
                             .Trim().ToLower()
                             .Replace(',', ' ').Replace("  ", " ")
                             .Split('\n')
                             .ToList <string>()
                };

                Console.WriteLine("Saving data . . .");

                // Example: MAIN_DIR\a. Needed letter is the 5th character from the end because
                // every URL ends with ?.php. UGLY
                string currentLetter = page[page.Length - 5].ToString();
                string pathTargetDir = Path.Combine(pathResultsDir, currentLetter);
                if (!Directory.Exists(pathTargetDir))
                {
                    Directory.CreateDirectory(pathTargetDir);
                }

                using (StreamWriter writerChNames = new StreamWriter(FileManager.GetNamesFilePath(pathTargetDir), false))
                    using (StreamWriter writerChComics = new StreamWriter(FileManager.GetComicsFilePath(pathTargetDir), false))
                        using (StreamWriter writerChLinks = new StreamWriter(FileManager.GetLinksFilePath(pathTargetDir), false))
                        {
                            foreach (var character in charactersInfo)
                            {
                                string uniqueCharacterId = character.Id;

                                if (uniqueCharacterId.Equals(String.Empty))
                                {
                                    uniqueCharacterId = Guid.NewGuid().ToString();
                                    Console.WriteLine(String.Format("WARNING! Empty ID was detected. Unique GUID was generated instead. GUID: {0}. Character's Name: {1}.",
                                                                    uniqueCharacterId, character.Name));
                                }
                                else
                                {
                                    uniqueCharacterId = IDHelper.AddIDParentLetter(IDHelper.NormalizeID(character.Id), currentLetter);

                                    int index = 1;
                                    while (setCharactersID.Contains(uniqueCharacterId))
                                    {
                                        uniqueCharacterId = IDHelper.AddIDParentLetter(IDHelper.NormalizeID(character.Id), currentLetter) + String.Format("({0})", index);
                                        ++index;
                                    }

                                    setCharactersID.Add(uniqueCharacterId);
                                }

                                // Write names
                                writerChNames.WriteLine(String.Format("{0},{1}", uniqueCharacterId, character.Name));

                                // Write comics
                                writerChComics.Write(uniqueCharacterId);
                                foreach (string comic in character.Comics)
                                {
                                    writerChComics.Write(String.Format(",{0}", comic));
                                }
                                writerChComics.WriteLine();

                                //// Write links
                                if ((character.Links != null) && (character.Links.Count() > 0))
                                {
                                    writerChLinks.Write(uniqueCharacterId);
                                    foreach (string link in character.Links)
                                    {
                                        writerChLinks.Write(String.Format(",{0}", link));
                                    }
                                    writerChLinks.WriteLine();
                                }
                            }
                        }

                Console.WriteLine("Finished processing " + page);

                ++i;
            }

            Console.WriteLine("Data extraction finished.");
        }
        public List <IW2S_Bing_level1link> GetLinks(string link, IW2S_Bing_BaiduCommend searchTsk)
        {
            List <IW2S_Bing_level1link> result = new List <IW2S_Bing_level1link>();
            int nohist_pages = 0;
            int quried_pages = 0;
            int fanye        = 0;

            //最多搜索10页
            while (!string.IsNullOrEmpty(link) && quried_pages <= 10)
            {
                log(link);
                CookieContainer  cc               = new CookieContainer();
                Encoding         enc              = null;
                CookieCollection cookiesColl      = new CookieCollection();
                CookieCollection cookieCollection = new CookieCollection();
                string           Rurl             = "http://cn.bing.com/";
                string           cookie           = "";
                string           hhhtml           = TaobaoWebHelper.GetContentByIndex(Rurl, 8000, cc, ref enc, out Rurl, ref cookiesColl, out cookieCollection);
                cookiesColl = cookieCollection;
                int gg = new Random().Next(2000, 5000);
                Thread.Sleep(gg);

                Rurl = link;
                var html = get_html(link, 8000, cc, ref enc, out Rurl, cookie, ref cookiesColl, out cookieCollection);// GetContent(link, 8000, cc, ref enc, out Rurl);
                cookiesColl = cookieCollection;
                if (html == null)
                {
                    break;
                }

                if (html.Contains("没有找到搜索内容!"))
                {
                    break;
                }

                var tags  = html.SubAfter("body").SubBefore("/body").SplitWith("b_content");
                var tagsD = tags[tags.Length - 1].SubAfter("搜索结果").SubBefore("</ol>").ToString().SplitWith("</li>");
                if (tagsD == null || tagsD.Length == 0 || tagsD.Length == 1)
                {
                    tags = html.SplitWith("b_content");
                }
                if (tagsD == null || tagsD.Length == 0)
                {
                    log("BLOCKED " + searchTsk.Keyword + " " + searchTsk.CommendKeyword);
                    break;
                }
                bool nohit = true;
                foreach (var tag in tagsD)
                {
                    if (!tag.Contains("h2"))
                    {
                        continue;
                    }

                    //if (!tag.Contains("sp_requery"))
                    //{
                    //    continue;
                    //}

                    var    a     = tag.SubAfter("h2").SubAfter("a");
                    string title = RemoveInivalidChar(a.RemoveSpace().GetLower().SubBefore("</h2>").GetTxtFromHtml2().RemoveSpace().GetLower()); // RemoveInivalidChar(tag.SubAfter("<h4").SubBefore("</h4>").GetTxtFromHtml2().RemoveSpace());
                    string href  = a.GetFirstHref2();                                                                                            //tag.SubAfter("<h4").SubBefore("</a>").GetFirstHref2();
                    if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(href))
                    {
                        continue;
                    }

                    href = href.Replace("amp;", "");


                    var sdsfdsf = GetDomain(href);



                    string abs = RemoveInivalidChar(tag.SubAfter("<p>").SubBefore("</p").GetTxtFromHtml2().RemoveSpace().GetLower()); //RemoveInivalidChar(tag.SubAfter("<h4>").SubBefore("\"s-p\"").SubBefore("<script>").GetTxtFromHtml2().RemoveSpace());

                    string timesp = "";

                    if (tag.Contains("此网站的操作"))
                    {
                        timesp = tag.SubAfter("此网站的操作").SubAfter("</a>").SubBefore("</div>").Replace('"', ' ');
                    }

                    string domain = GetDomain(href); //tag.SubLastStringAfter("\"s-p\"").SubBefore("</a").GetTxtFromHtml2().SubAfter("(").SubAfter("(").SubBefore(",").Replace('"', ' ').Trim();
                    //domain = BaiduQuery.GetDomain(domain);

                    int maxScore = 0;

                    byte appType = 0;
                    //没有包含需要protect item信息的过滤掉
                    string txt = "{0},{1}".FormatStr(title, abs);
                    if (string.IsNullOrEmpty(txt))
                    {
                        continue;
                    }

                    int nn = new Random().Next(8000, 20000);
                    Thread.Sleep(nn);
                    var htmldetail = "";

                    try
                    {
                        htmldetail = get_Detailehtml(href, 8000, cc, ref enc, out Rurl, cookie, ref cookiesColl, out cookieCollection);// GetContent(href, 8000, cc, ref enc, out Rurl);
                    }
                    catch (Exception)
                    {
                        //htmldetail = "";
                        href = "http://cn.bing.com" + href;
                    }
                    bool          is_title_matched = title.GetLower().IsContains2(searchTsk.Keyword.ToLower(), searchTsk.CommendKeyword.ToLower());
                    bool          is_abstr_matched = abs.GetLower().IsContains2(searchTsk.Keyword.GetLower(), searchTsk.CommendKeyword.GetLower());
                    BaiduItemPart part             = is_title_matched && is_abstr_matched ? BaiduItemPart.TitleAbstract :
                                                     is_title_matched ? BaiduItemPart.Title :
                                                     is_abstr_matched ? BaiduItemPart.Abstract : BaiduItemPart.None;
                    bool is_itm_title_matched = txt.GetLower().IsContains(searchTsk.Keyword.GetLower());
                    bool is_bus_matched       = txt.GetLower().IsContains2(searchTsk.CommendKeyword.GetLower());



                    IW2S_Bing_level1link l1 = new IW2S_Bing_level1link
                    {
                        UsrId           = searchTsk.UsrId,
                        Domain          = domain,
                        TopDomain       = GetLevel1Domain(domain),
                        Keywords        = string.Format("{0} + {1}", searchTsk.Keyword, searchTsk.CommendKeyword),
                        LinkUrl         = href,
                        MatchAt         = (byte)part,
                        Html            = htmldetail,
                        MatchType       = (byte)((is_bus_matched ? 1 : 0) + (is_itm_title_matched ? 2 : 0)),
                        AppType         = appType,
                        BizId           = IDHelper.GetGuid("{0}/{1}/{2}".FormatStr(href, searchTsk.UsrId, searchTsk.Keyword)),
                        SearchkeywordId = searchTsk._id.ToString(),
                        CreatedAt       = DateTime.UtcNow.AddHours(8),
                        Description     = abs,
                        Title           = title,
                        Score           = maxScore,
                        Abstract        = abs,
                        ProjectId       = searchTsk.ProjectId
                    };
                    if (is_bus_matched)
                    {
                        l1.MatchType = l1.MatchType;
                    }
                    if (is_itm_title_matched)
                    {
                        l1.MatchType = l1.MatchType;
                    }
                    byte MatchType = (byte)((is_bus_matched ? 10 : 0) + (is_itm_title_matched ? 30 : 0));
                    if (is_bus_matched == true && is_itm_title_matched == true)
                    {
                        //l1.Score = busTsk.Score + 5;
                        l1.Score = 80 + 10;
                    }
                    if (is_bus_matched == true && is_itm_title_matched == false)
                    {
                        l1.Score = 80;
                    }
                    if (is_bus_matched == false && is_itm_title_matched == true)
                    {
                        l1.Score = 50;
                    }

                    result.Add(l1);
                    nohit        = false;
                    nohist_pages = 0;
                }

                if (nohit)
                {
                    nohist_pages++;
                }
                //如果连续3页都没有结果,就跳出
                if (nohist_pages > 3)
                {
                    break;
                }

                quried_pages++;
                pages++;

                //****** sougou 需要重写 *********************
                link = html.SubAfter("sb_pagN").SubBefore("下一页").GetLastHref2();
                if (!string.IsNullOrEmpty(link) && !link.IsStartWith("http"))
                {
                    if (link.IsStartWith("/"))
                    {
                        link = link.SubAfter("/");
                    }
                    link = "http://cn.bing.com/".GetContact(link);
                }
                fanye = fanye + 10;
                link  = "http://cn.bing.com/search?q={0}&first={1}&FORM=PERE3".FormatStr(searchTsk.Keyword, fanye);
                SaveResult(result);
                result.Clear();

                int n = new Random().Next(8000, 15000);
                Thread.Sleep(n);
            }
            return(result);
        }
        private void BaseButtonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (GlobalMessageBox.Show("是否确认操作?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    return;
                }
                if (CommonGlobalUtil.EngineUnconnectioned(this))
                {
                    return;
                }
                string id = IDHelper.GetID(OrderPrefix.ConfusedStoreAdjustRecord, shop.AutoCode);

                ConfusedStoreAdjustRecord para = new ConfusedStoreAdjustRecord()
                {
                    OrderID        = id,
                    CostumeID      = currentSelectedItem?.Costume?.ID,
                    ColorName1     = ValidateUtil.CheckEmptyValue(skinComboBox_Color.SelectedValue),
                    ColorName2     = ValidateUtil.CheckEmptyValue(skinComboBox_Color1.SelectedValue),
                    SizeName1      = CostumeStoreHelper.GetCostumeSize(ValidateUtil.CheckEmptyValue(skinComboBox_Size.SelectedValue), CommonGlobalCache.DefaultSizeGroup),
                    SizeName2      = CostumeStoreHelper.GetCostumeSize(ValidateUtil.CheckEmptyValue(skinComboBox_Size1.SelectedValue), CommonGlobalCache.DefaultSizeGroup),
                    Remarks        = skinTextBox_Remark.Text,
                    CountPre1      = skinLabelStore,
                    CountPre2      = skinLabelStore1,
                    CountNow1      = skinLabelStore - int.Parse(skinTextBox_MoneyCash.Text),
                    CountNow2      = skinLabelStore1 + int.Parse(skinTextBox_MoneyCash1.Text),
                    ShopID         = ValidateUtil.CheckEmptyValue(skinComboBoxShopID.SelectedValue),
                    OperatorUserID = userID,
                };

                if (String.IsNullOrEmpty(para.CostumeID))
                {
                    GlobalMessageBox.Show("请选择款号!");
                    return;
                }
                if (para.ColorName1 == para.ColorName2 && para.SizeName1 == para.SizeName2)
                {
                    GlobalMessageBox.Show("请选择不同颜色或者尺码!");
                    return;
                }
                if (para.CountPre1 == 0)
                {
                    GlobalMessageBox.Show("库存为0,不能向下调整!");
                    return;
                }
                InteractResult result = CommonGlobalCache.ServerProxy.AddConfusedStoreAdjustRecord(para);
                switch (result.ExeResult)
                {
                case ExeResult.Success:
                    GlobalMessageBox.Show("调整成功!");
                    //重新获取该款库存信息
                    this.skinTextBox_costumeID.Reload();
                    //this.TabPageClose(CurrentTabPage, SourceCtrlType);
                    break;

                case ExeResult.Error:
                    GlobalMessageBox.Show("内部错误!");
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                UnLockPage();
            }
        }