示例#1
0
        public void ProcessImport(object arrControl)
        {
            OleDbDataReader reader = null;
            object          totalRow;

            try
            {
                //----- Add control process from
                ArrayList arr1          = (ArrayList)arrControl;
                Label     lblPhanTram   = (Label)arr1[0];
                NeroBar   progressBar11 = (NeroBar)arr1[1];
                Label     lblmessage    = (Label)arr1[2];

                //----- update display control
                lblPhanTram.Update();
                lblmessage.Update();
                totalRow = TongrowsText;
                if (totalRow == null)
                {
                    return;
                }
                //----- Get Data from Source

                string[] columnNames = new string[columnNamesList.Count()];

                for (int i = 0; i < columnNames.Count(); i++)
                {
                    columnNames[i] = columnNamesList[i];
                }

                /***********text*****************/

                OleDbConnection con = new OleDbConnection(connectionString);
                con.Open();

                OleDbDataAdapter dap = new OleDbDataAdapter("select * from [mau.txt]", con);

                DataTable dt = new DataTable();
                dt.TableName = "Data";
                dap.Fill(dt);


                reader = SQLDatabase.ExcOleReaderDataSource(connectionString, tableName, columnNames);

                progressBar11.MaxValue = int.Parse(totalRow.ToString());
                progressBar11.MinValue = 0;
                progressBar11.Update();
                // Set up the bulk copy object.
                using (SqlBulkCopy bulkCopy = new SqlBulkCopy(SQLDatabase.ConnectionString))
                {
                    //http://csharp-video-tutorials.blogspot.com/2014/09/part-20-sqlbulkcopy-notifyafter-example_27.html
                    bulkCopy.NotifyAfter    = 5000;
                    bulkCopy.BatchSize      = 10000;
                    bulkCopy.SqlRowsCopied += (sender, e) =>
                    {
                        progressBar11.Value = e.RowsCopied;
                        progressBar11.Update();
                        lblmessage.Text = string.Format("Insert số liệu vào database. ->{0}/{1}", e.RowsCopied.ToString("N0"), ConvertType.ToInt(totalRow).ToString("N0"));
                        Thread.Sleep(0);
                    };
                    bulkCopy.DestinationTableName = "dbo.dienthoai_new";

                    if (dict.FirstOrDefault(x => x.Key == "cbb_TelNumber").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_TelNumber = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_TelNumber").Value, "didong");
                        bulkCopy.ColumnMappings.Add(cbb_TelNumber);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_ten_khach_hang").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_ten_khach_hang = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_ten_khach_hang").Value, "ten_khach_hang");
                        bulkCopy.ColumnMappings.Add(cbb_ten_khach_hang);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_dia_chi").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_dia_chi = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_dia_chi").Value, "dia_chi");
                        bulkCopy.ColumnMappings.Add(cbb_dia_chi);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_Ngay").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_Ngay = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_Ngay").Value, "ngay");
                        bulkCopy.ColumnMappings.Add(cbb_Ngay);
                    }
                    if (dict.FirstOrDefault(x => x.Key == "cbb_Thang").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_Thang = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_Thang").Value, "thang");
                        bulkCopy.ColumnMappings.Add(cbb_Thang);
                    }
                    if (dict.FirstOrDefault(x => x.Key == "cbb_namsinh").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_namsinh = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_namsinh").Value, "namsinh");
                        bulkCopy.ColumnMappings.Add(cbb_namsinh);
                    }
                    if (dict.FirstOrDefault(x => x.Key == "cbb_nganhang").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_nganhang = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_nganhang").Value, "ngan_hang");
                        bulkCopy.ColumnMappings.Add(cbb_nganhang);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_cuoc").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_cuoc = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_cuoc").Value, "cuoc");
                        bulkCopy.ColumnMappings.Add(cbb_cuoc);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_sim").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_sim = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_sim").Value, "sim");
                        bulkCopy.ColumnMappings.Add(cbb_sim);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_tinh").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_tinh = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_tinh").Value, "tinh");
                        bulkCopy.ColumnMappings.Add(cbb_tinh);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_ghichu").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_ghichu = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_ghichu").Value, "ghi_chu");
                        bulkCopy.ColumnMappings.Add(cbb_ghichu);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_gioitinh").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_gioitinh = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_gioitinh").Value, "gioi_tinh");
                        bulkCopy.ColumnMappings.Add(cbb_gioitinh);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_tinhcuoc").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_tinhcuoc = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_tinhcuoc").Value, "tinh_cuoc");
                        bulkCopy.ColumnMappings.Add(cbb_tinhcuoc);
                    }
                    if (dict.FirstOrDefault(x => x.Key == "cbb_phuong").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_Phuong = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_phuong").Value, "phuong");
                        bulkCopy.ColumnMappings.Add(cbb_Phuong);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_quanhuyen").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_quanhuyen = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_quanhuyen").Value, "quan_huyen");
                        bulkCopy.ColumnMappings.Add(cbb_quanhuyen);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_email").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_email = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_email").Value, "email");
                        bulkCopy.ColumnMappings.Add(cbb_email);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_ngay_kich_hoat").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_ngay_kich_hoat = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_ngay_kich_hoat").Value, "ngay_kich_hoat");
                        bulkCopy.ColumnMappings.Add(cbb_ngay_kich_hoat);
                    }
                    if (dict.FirstOrDefault(x => x.Key == "cbb_goiCuoc").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_GoiCuoc = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_goiCuoc").Value, "goi_cuoc");
                        bulkCopy.ColumnMappings.Add(cbb_GoiCuoc);
                    }
                    if (dict.FirstOrDefault(x => x.Key == "cbb_dongmay").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_dongmay = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_dongmay").Value, "dong_may");
                        bulkCopy.ColumnMappings.Add(cbb_dongmay);
                    }

                    if (dict.FirstOrDefault(x => x.Key == "cbb_hedieuhanh").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_HeDieuhanh = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_hedieuhanh").Value, "he_dieu_hanh");
                        bulkCopy.ColumnMappings.Add(cbb_HeDieuhanh);
                    }
                    if (dict.FirstOrDefault(x => x.Key == "cbb_chucvu").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_chucvu = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_chucvu").Value, "chuc_vu");
                        bulkCopy.ColumnMappings.Add(cbb_chucvu);
                    }
                    if (dict.FirstOrDefault(x => x.Key == "cbb_congty").Value != "")
                    {
                        SqlBulkCopyColumnMapping cbb_congty = new SqlBulkCopyColumnMapping(dict.FirstOrDefault(x => x.Key == "cbb_congty").Value, "cong_ty");
                        bulkCopy.ColumnMappings.Add(cbb_congty);
                    }
                    try
                    {
                        bulkCopy.WriteToServer(reader);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        progressBar11.Value = 100;
                        progressBar11.Update();
                        lblmessage.Text = string.Format("Hoàn thành import {0}", int.Parse(totalRow.ToString()));
                        Thread.Sleep(0);

                        reader.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ProcessImport");
            }
        }
示例#2
0
        public static string StripHTML(object inputString)
        {
            string str = Regex.Replace(ConvertType.ToString(inputString), HTML_TAG_PATTERN, string.Empty);

            return(str);
        }