private void btnCheckByRegex_Click(object sender, EventArgs e) { ProductSaleNewAdapter productSaleNewAdapter = new ProductSaleNewAdapter(new SqlDb(QT.Entities.Server.ConnectionString)); List <string> lstRegex = productSaleNewAdapter.GetListBlackRegexKeyWord(); foreach (string regex in lstRegex) { List <KeywordSaleNew> lst = this.gridControl1.DataSource as List <KeywordSaleNew>; foreach (var item in lst) { string nameKeyword = item.name; if (Regex.IsMatch(nameKeyword, regex)) { item.is_selected = true; item.Regex_Novalid = regex; } } } this.gridView1.RefreshData(); }
private void btnStartRun_Click(object sender, EventArgs e) { var token = tokenSource.Token; int count = 0; Task.Factory.StartNew(() => { this.Invoke(new Action(() => { this.richTextBox1.AppendText(string.Format("Start Run")); })); MongoDbRaoVat mongoDb = new MongoDbRaoVat(); ProductSaleNewAdapter productSaleNewAdapter = new ProductSaleNewAdapter(new SqlDb(QT.Entities.Server.ConnectionStringCrawler)); List <string> lstRegexoK = productSaleNewAdapter.GetListRegexKeyword(); List <string> lstRegexBlack = productSaleNewAdapter.GetListBlackRegexKeyWord(); Dictionary <ObjectId, bool> dicUpdate = new Dictionary <ObjectId, bool>(); foreach (string str in lstRegexBlack) { string strXuanTrang = ""; try { bool bok = (Regex.IsMatch(strXuanTrang, str)); } catch (Exception ex01) { this.Invoke(new Action(() => { this.richTextBox1.AppendText(string.Format("\r\nError in regex list at:{0}", str)); })); return; } } while (true) { if (token.IsCancellationRequested) { throw new OperationCanceledException(token); } //Xử lí. List <BsonDocument> lstDocument = mongoDb.GetListKeywordNeedCheck(this.dtFrom, this.bCheckStatus); if (lstDocument.Count > 0) { foreach (var document in lstDocument) { if (!dicUpdate.ContainsKey(document["_id"].AsObjectId)) { string nameKeyword = document["name"].AsString; foreach (var strRegexBlack in lstRegexBlack) { if (Regex.IsMatch(nameKeyword, strRegexBlack)) { dicUpdate.Add(document["_id"].AsObjectId, false); break; } } if (!dicUpdate.ContainsKey(document["_id"].AsObjectId)) { dicUpdate.Add(document["_id"].AsObjectId, true); } } } foreach (var item in dicUpdate) { mongoDb.UpdateStatusOfKeyword(item.Key, (item.Value == true) ? 1 : 0); } count = count + dicUpdate.Count; this.Invoke(new Action(() => { this.richTextBox1.AppendText(string.Format("\r\nCount:{0}", count)); })); dicUpdate.Clear(); } else { this.Invoke(new Action(() => { this.richTextBox1.AppendText(string.Format("\r\n End Run:{0}", count)); })); break; } } }, token); }