Beispiel #1
0
        public FrmKeyWord()
        {
            InitializeComponent();

            mySqlAdapter = new MySqlAdapterRaoVat();
            dicTerm      = mySqlAdapter.GetDicTerms();
        }
Beispiel #2
0
        private void btnAutoFindCategory_Click(object sender, EventArgs e)
        {
            MySqlAdapterRaoVat mySqlDb = new MySqlAdapterRaoVat();
            Dictionary <string, List <int> > dicmap = new Dictionary <string, List <int> >();

            try
            {
                List <string> lst = Common.GetListXPathFromString(txtRegexCatToID.Text);
                foreach (var itemCat in lst)
                {
                    var        arData   = itemCat.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);
                    string     strRegex = arData[0];
                    string     strCat   = arData[1];
                    List <int> lstCat   = new List <int>();
                    foreach (var itemCatId in strCat.Split(new char[] { ',' }, 10, StringSplitOptions.RemoveEmptyEntries))
                    {
                        int iCat = 0;
                        int.TryParse(itemCatId, out iCat);
                        if (!lstCat.Contains(iCat) && iCat > 0)
                        {
                            lstCat.Add(iCat);
                        }
                    }
                    dicmap.Add(strRegex, lstCat);
                }

                //Thêm các cat còn thiếu
                for (int i = 0; i < dicmap.Count; i++)
                {
                    List <int> lstData    = dicmap.ElementAt(i).Value;
                    List <int> lstNeedAdd = new List <int>();
                    foreach (var itemCat in lstData)
                    {
                        List <int> lstPath = mySqlDb.GetListPathOfCategory(itemCat);
                        foreach (var itemCatPath in lstPath)
                        {
                            if (!lstData.Contains(itemCatPath))
                            {
                                lstNeedAdd.Add(itemCatPath);
                            }
                        }
                    }
                    lstData.AddRange(lstNeedAdd.ToArray());
                }

                string genText = "";
                for (int i = 0; i < dicmap.Count; i++)
                {
                    string aMapText = dicmap.ElementAt(i).Key + ":" + Common.ConvertToString(dicmap.ElementAt(i).Value, ", ");
                    genText = genText + aMapText + ";\n";
                }
                txtRegexCatToID.Text = genText;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #3
0
        public void RunSync(int numberItem)
        {
            MySqlAdapterRaoVat       mySqlAdapterRaoVat = null;
            Dictionary <int, string> dicCity            = null;
            RaoVatSQLAdapter         configXPathAdapter = new RaoVatSQLAdapter(
                new SqlDb(QT.Entities.Server.ConnectionStringCrawler));

            MongoDbRaoVat mongoDb = new MongoDbRaoVat();

            while (!this.bPause)
            {
                try
                {
                    if (TypeProcess == TypeRunSync.ReloadAllProuduct)
                    {
                        bool bOK = ReloadAllProduct(numberItem, mongoDb).Result;
                        WriteLog(string.Format("Commit {0} data", numberItem));
                        Thread.Sleep(1000);
                    }
                    else if (TypeProcess == TypeRunSync.AnalyscFieldProduct)
                    {
                        mySqlAdapterRaoVat = new MySqlAdapterRaoVat();
                        dicCity            = mySqlAdapterRaoVat.GetDicCity();
                        bool bOK = AnalysicField(numberItem, mongoDb, dicCity).Result;
                        WriteLog(string.Format("Commit {0} data", numberItem));
                        Thread.Sleep(1000);
                    }
                    else if (TypeProcess == TypeRunSync.FixSlug)
                    {
                        bool OK = AnalysicKeyword(10000, mongoDb, null).Result;
                        WriteLog(string.Format("Commit {0} data", numberItem));
                        Thread.Sleep(1000);
                    }
                    else if (TypeProcess == TypeRunSync.ReloadAllKeyWord)
                    {
                        bool iProductAnalysic = AnalysicKeyword(10000, mongoDb, null).Result;
                    }
                }
                catch (OperationAbortedException ex1)
                {
                    break;
                }
                catch (Exception ex)
                {
                    WriteLog(ex.Message);
                    Thread.Sleep(10000);
                }
            }
        }
Beispiel #4
0
        private void RunData(string textProcess)
        {
            this.Invoke(new Action(() =>
            {
                this.btnStart.Visible = false;
            }));

            SqlDb sqlDb = new SqlDb(QT.Entities.Server.ConnectionStringCrawler);
            MySqlAdapterRaoVat mySqlAdapterRaoVat = new MySqlAdapterRaoVat();
            RaoVatSQLAdapter   sqlAdapterRaoVat   = new RaoVatSQLAdapter(sqlDb);

            if (textProcess == "cities")
            {
                var dicCity = mySqlAdapterRaoVat.GetDicCity();
                for (int i = 0; i < dicCity.Count; i++)
                {
                    var itemCity = dicCity.ElementAt(i);
                    if (sqlAdapterRaoVat.CheckExistCity(itemCity.Key))
                    {
                        sqlAdapterRaoVat.UpdateCity(itemCity.Key, itemCity.Value);
                    }
                    else
                    {
                        sqlAdapterRaoVat.InsertCity(itemCity.Key, itemCity.Value);
                    }
                    this.Invoke(new Action(() =>
                    {
                        this.progressBar1.Value = Convert.ToInt32(((double)i / (double)dicCity.Count) * 100);
                    }));
                }
            }
            else if (textProcess == "categories")
            {
                DataTable tblcategories = mySqlAdapterRaoVat.GetTableCategories();
                for (int i = 0; i < tblcategories.Rows.Count; i++)
                {
                    var itemCity = tblcategories.Rows[i];
                    if (sqlAdapterRaoVat.CheckExistCategories(Convert.ToInt32(itemCity["id"])))
                    {
                        sqlAdapterRaoVat.UpdateCategories(new QT.Entities.RaoVat.RaoVatCategory()
                        {
                            id        = Convert.ToInt32(itemCity["id"]),
                            level     = Convert.ToInt32(itemCity["level"]),
                            name      = Common.Obj2String(itemCity["name"]),
                            parent_id = Common.Obj2Int(itemCity["parent_id"]),
                            slug      = Common.Obj2String(itemCity["slug"]),
                            path      = Common.Obj2String(itemCity["path"])
                        });
                    }
                    else
                    {
                        sqlAdapterRaoVat.InsertCategory(new QT.Entities.RaoVat.RaoVatCategory()
                        {
                            id        = Convert.ToInt32(itemCity["id"]),
                            level     = Convert.ToInt32(itemCity["level"]),
                            name      = Common.Obj2String(itemCity["name"]),
                            parent_id = Common.Obj2Int(itemCity["parent_id"]),
                            slug      = Common.Obj2String(itemCity["slug"]),
                            path      = Common.Obj2String(itemCity["path"])
                        });
                    }
                    this.Invoke(new Action(() =>
                    {
                        this.progressBar1.Value = Convert.ToInt32(((double)i / (double)tblcategories.Rows.Count) * 100);
                    }));
                }
            }

            this.Invoke(new Action(() =>
            {
                this.btnStart.Visible = true;
            }));
        }
Beispiel #5
0
        private void FrmCategory_Load(object sender, EventArgs e)
        {
            MySqlAdapterRaoVat mySqlDb = new MySqlAdapterRaoVat();

            this.gridControl1.DataSource = mySqlDb.GetTableCategories();
        }