Exemple #1
0
        private void Run()
        {
            DataTable dtfinal = new DataTable();

            dtfinal = new DataTable();
            dtfinal.Columns.Add("ID", typeof(string));
            dtfinal.Columns.Add("Domain", typeof(string));
            dtfinal.Columns.Add("Detail", typeof(string));

            WSS.DownloadImageByHand.DBTableAdapters.CompanyTableAdapter companyAdapter = new DBTableAdapters.CompanyTableAdapter();
            companyAdapter.Connection.ConnectionString = connectionString;
            WSS.DownloadImageByHand.DB.CompanyDataTable companyTable = new DB.CompanyDataTable();
            var fileStream = new FileStream(txtFolder.Text, FileMode.Open, FileAccess.Read);
            int i          = 0;

            using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
            {
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    this.Invoke(new Action(() =>
                    {
                        richTextBox1.AppendText(i + ". " + line + System.Environment.NewLine);
                    }));
                    i++;
                    companyTable.Clear();
                    long idcompany = QT.Entities.Common.GetIDCompany(line);
                    companyAdapter.FillBy_ID(companyTable, idcompany);
                    if (companyTable.Rows.Count == 0)
                    {
                        DataRow dr = dtfinal.NewRow();
                        dr["ID"]     = idcompany;
                        dr["Domain"] = line;
                        dr["Detail"] = "Not in Database";
                        dtfinal.Rows.Add(dr);
                    }
                    else
                    {
                        int totalvalid = QT.Entities.Common.Obj2Int(companyTable.Rows[0]["TotalValid"].ToString());
                        if (totalvalid == 0)
                        {
                            DataRow dr = dtfinal.NewRow();
                            dr["ID"]     = idcompany;
                            dr["Domain"] = line;
                            dr["Detail"] = "Total Valid = 0";
                            dtfinal.Rows.Add(dr);
                        }
                    }
                }
                this.Invoke(new Action(() =>
                {
                    gridControl1.DataSource = dtfinal;
                }));
            }
        }
Exemple #2
0
        private void Run()
        {
            DBTableAdapters.CompanyTableAdapter companyTableAdapter = new CompanyTableAdapter();
            companyTableAdapter.Connection.ConnectionString = _connectionString;
            DBTableAdapters.Company_AddressTableAdapter addressTableAdapter = new Company_AddressTableAdapter();
            addressTableAdapter.Connection.ConnectionString = _connectionString;
            DB.CompanyDataTable companyDataTable = new DB.CompanyDataTable();
            DataTable           addressDataTable = new DataTable();
            DataTable           dtCompany        = new DataTable();

            dtCompany.Columns.Add("ID", typeof(string));
            dtCompany.Columns.Add("Domain", typeof(string));
            dtCompany.Columns.Add("Address", typeof(string));
            dtCompany.Columns.Add("ThanhPho", typeof(string));
            dtCompany.Columns.Add("Phone", typeof(string));
            var listDomain = memoEdit1.Text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            int i          = 0;

            foreach (var item in listDomain)
            {
                i++;
                this.Invoke(new Action(() =>
                {
                    rbError.AppendText(String.Format("{0}. {1}", i, item) + System.Environment.NewLine);
                }));
                companyDataTable.Clear();
                addressDataTable.Clear();
                long idCompany = Common.GetIDCompany(item); try
                {
                    companyTableAdapter.FillBy_ID(companyDataTable, idCompany);
                }
                catch (Exception exception)
                {
                    this.Invoke(new Action(() =>
                    {
                        rbError.AppendText(String.Format("{0}. {1} Fill By ID error: {2}", i, item, exception) + System.Environment.NewLine);
                    }));
                }
                if (companyDataTable.Rows.Count > 0)
                {
                    DataRow dataRow = dtCompany.NewRow();
                    dataRow["ID"]      = idCompany;
                    dataRow["Domain"]  = item;
                    dataRow["Address"] = companyDataTable.Rows[0]["Address"];
                    dataRow["Phone"]   = companyDataTable.Rows[0]["Phone"];
                    //try
                    //{
                    //    string querry = @"SELECT Distinct ThanhPho FROM Company_Address WHERE CompanyID =" + idCompany;
                    //    SqlDb sqldb = new SqlDb(_connectionString);
                    //    try
                    //    {
                    //        addressDataTable = sqldb.GetTblData(querry, CommandType.Text, null);
                    //    }
                    //    catch (Exception)
                    //    {
                    //    }
                    //    string thanhpho = "";
                    //    for (int j = 0; j < addressDataTable.Rows.Count; j++)
                    //    {
                    //        if (addressDataTable.Rows[j]["ThanhPho"] != DBNull.Value)
                    //        {
                    //            thanhpho += addressDataTable.Rows[j]["ThanhPho"].ToString()+" , ";
                    //        }
                    //    }
                    //    dataRow["ThanhPho"] = thanhpho;
                    //}
                    //catch (Exception exception)
                    //{
                    //    this.Invoke(new Action(() =>
                    //    {
                    //        rbError.AppendText(String.Format("{0}. {1} Get address error: {2}", i, item, exception));
                    //    }));
                    //}
                    dtCompany.Rows.Add(dataRow);
                }
                else
                {
                    this.Invoke(new Action(() =>
                    {
                        rbError.AppendText(String.Format("{0}. {1} Khong ton tai trong SQL", i, item) + System.Environment.NewLine);
                    }));
                }
            }
            this.Invoke(new Action(() =>
            {
                gridControl1.DataSource = dtCompany;
            }));
        }