Example #1
0
        private void Run(string fileName)
        {
            var dictCompanyRank      = new Dictionary <long, double>();
            var merchantscoreAdapter = new DBScoreTableAdapters.MerchantScoreTableAdapter();

            merchantscoreAdapter.Connection.ConnectionString = _connectionString;
            var merchantscoreTable = new DBScore.MerchantScoreDataTable();

            merchantscoreAdapter.FillAllMerchantId(merchantscoreTable);
            if (merchantscoreTable.Count > 0)
            {
                for (int i = 0; i < merchantscoreTable.Count; i++)
                {
                    long merchantId = Common.Obj2Int64(merchantscoreTable.Rows[i]["MerchantId"]);
                    dictCompanyRank.Add(merchantId, Common.Obj2Double(merchantscoreTable.Rows[i]["Score"]));
                }
            }
            try
            {
                int    counter = 0;
                string line;
                List <MerchantRankInfo> listMerchantFinal = new List <MerchantRankInfo>();
                // Read the file and display it line by line.
                System.IO.StreamReader file =
                    new System.IO.StreamReader(fileName);
                while ((line = file.ReadLine()) != null)
                {
                    long   idcompany = Convert.ToInt64(line.Split(',')[0]);
                    string domain    = line.Split(',')[1];
                    double score     = 0;
                    if (dictCompanyRank.ContainsKey(idcompany))
                    {
                        score = dictCompanyRank[idcompany];
                    }
                    MerchantRankInfo mrInfo = new MerchantRankInfo()
                    {
                        Domain     = domain,
                        MerchantId = idcompany.ToString(),
                        Score      = score
                    };
                    listMerchantFinal.Add(mrInfo);
                    this.Invoke(new Action(() =>
                    {
                        richTextBox1.AppendText(string.Format("{0}.MerchantId = {1} : Score: {2}", counter, idcompany, score) + System.Environment.NewLine);
                    }));
                    counter++;
                }
                this.Invoke(new Action(() =>
                {
                    gridControl1.DataSource = listMerchantFinal;
                }));
                file.Close();
            }
            catch (Exception)
            {
            }
        }
Example #2
0
        private void UpdateMerchantScoreToSQL()
        {
            DBScoreTableAdapters.MerchantScoreTableAdapter merchantscoreAdapter = new DBScoreTableAdapters.MerchantScoreTableAdapter();
            merchantscoreAdapter.Connection.ConnectionString = _connectionString;
            DBScore.MerchantScoreDataTable merchantscoreTable = new DBScore.MerchantScoreDataTable();
            HashSet <long> listidmerchant = new HashSet <long>();

            try
            {
                merchantscoreAdapter.FillAllMerchantId(merchantscoreTable);
            }
            catch (Exception ex)
            {
                this.Invoke(new Action(() =>
                {
                    rbMessage.AppendText("Error get list merchant in SQL: " + System.Environment.NewLine + ex.ToString());
                }));
                return;
            }
            if (merchantscoreTable.Count > 0)
            {
                for (int i = 0; i < merchantscoreTable.Count; i++)
                {
                    listidmerchant.Add(Common.Obj2Int64(merchantscoreTable.Rows[i]["MerchantId"]));
                }
            }
            foreach (var item in listMerchantScore)
            {
                if (listidmerchant.Contains(item.MerchantId))
                {
                    //update
                    try
                    {
                        merchantscoreAdapter.UpdateQuery(item.ScoreNumberProduct1, item.ScoreStore1, item.ScoreTraffic1, item.ScoreAdvertisementPR1,
                                                         item.ScoreScandal1, item.TotalPart1, item.ScoreAddressStore2, item.ScorePhoneNumberAvaiable2, item.ScoreCustomerServices2, item.TotalPart2,
                                                         item.ScoreProductInformation3, item.ScoreWebsosanhRate3, item.ScoreGoogleRate3, item.ScoreRateWebsite3, item.TotalPart3, item.ScoreStatusProduct4,
                                                         item.ScoreSignContract5, item.ScoreResignContract5, item.ScorePotential5, item.ScoreSales5, item.TotalPart5, item.Score, item.MerchantId);
                        this.Invoke(new Action(() =>
                        {
                            rbMessage.AppendText(item.MerchantWebsite + " update success!" + System.Environment.NewLine);
                        }));
                    }
                    catch (Exception ex)
                    {
                        this.Invoke(new Action(() =>
                        {
                            rbMessage.AppendText("Error update merchantscore: " + item.MerchantWebsite + System.Environment.NewLine + ex.ToString());
                        }));
                    }
                }
                else
                {
                    //insert
                    try
                    {
                        merchantscoreAdapter.Insert(item.MerchantId, item.ScoreNumberProduct1, item.ScoreStore1, item.ScoreTraffic1, item.ScoreAdvertisementPR1,
                                                    item.ScoreScandal1, item.TotalPart1, item.ScoreAddressStore2, item.ScorePhoneNumberAvaiable2, item.ScoreCustomerServices2, item.TotalPart2,
                                                    item.ScoreProductInformation3, item.ScoreWebsosanhRate3, item.ScoreGoogleRate3, item.ScoreRateWebsite3, item.TotalPart3, item.ScoreStatusProduct4,
                                                    item.ScoreSignContract5, item.ScoreResignContract5, item.ScorePotential5, item.ScoreSales5, item.TotalPart5, item.Score);
                        this.Invoke(new Action(() =>
                        {
                            rbMessage.AppendText(item.MerchantWebsite + " insert success!" + System.Environment.NewLine);
                        }));
                    }
                    catch (Exception ex)
                    {
                        this.Invoke(new Action(() =>
                        {
                            rbMessage.AppendText("Error insert merchantscore: " + item.MerchantWebsite + System.Environment.NewLine + ex.ToString());
                        }));
                    }
                }
            }
        }