private void btnRead_Click(object sender, RoutedEventArgs e) { try { #region if (ListBox.Items.Count > 0) { string destFolder = txtPath.Text.Trim(); string sourceFolder = txtSourcePath.Text.Trim(); foreach (object t in ListBox.Items) { string file = destFolder + t; string pos = t.ToString().Substring(0, 6); string ngay = t.ToString().Substring(7, 8); string fileTxt = sourceFolder + pos + "_" + ngay + "_LEND30.txt"; //MessageBox.Show(file+" "+fileTxt); bll.Pdf2Text(file, fileTxt); } ListText.Items.Clear(); DirectoryInfo dir = new DirectoryInfo(sourceFolder); FileInfo[] files = dir.GetFiles("*.txt*"); foreach (FileInfo file in files) { string ngay = file.Name.Trim().Substring(7, 8); if (dtpNgay.SelectedDate != null && ngay == dtpNgay.SelectedDate.Value.ToString("ddMMyyyy")) { //MessageBox.Show(file.ToString()); ListText.Items.Add(file); } } if (ListText.Items.Count == 0) { MessageBox.Show("Not Files found ! ", "Mess", MessageBoxButton.OK, MessageBoxImage.Warning); } else { cls.ClsConnect(); foreach (object t in ListText.Items) { string mato = ""; string soku = ""; string file = sourceFolder + t; string pos = t.ToString().Substring(0, 6); string ngay = t.ToString().Substring(7, 8); string ng = dtpNgay.SelectedDate.Value.ToString("yyyy-MM-dd"); string sqlchk = "select top 1 * from PSPDF where NGAY='" + ng + "' and KU_MAPGD='" + pos + "'"; dt = cls.LoadDataText(sqlchk); if (dt.Rows.Count > 0) { MessageBox.Show("Số liệu ngày : " + ng + " Pos : " + pos + " đã tồn tại", "Mess", MessageBoxButton.OK, MessageBoxImage.Information); } else { string str = bll.XoaKyTuTrang(File.ReadAllText(file)); string[] arrStr = str.Split(' '); foreach (var item in arrStr) { if ((item.Trim().Length == 8 && bll.Right(item.Trim(), 1) == ":") || (item.Trim().Length == 16 && bll.Left(item.Trim(), 2) == "66")) { if (item.Trim().Length == 8 && bll.Right(item.Trim(), 1) == ":") { mato = bll.Left(item, 7); } if (item.Trim().Length == 16 && bll.Left(item.Trim(), 2) == "66") { soku = item.Trim(); //MessageBox.Show(ng+" "+pos+" "+mato + " " + soku); string sql = "insert into PSPDF (NGAY,KU_MAPGD,KU_MATO,KU_SOKU) values ('" + ng + "','" + pos + "','" + mato + "','" + soku + "')"; cls.UpdateDataText(sql); } } } } } cls.DongKetNoi(); MessageBox.Show("OK", "Mess", MessageBoxButton.OK, MessageBoxImage.Information); } } else { MessageBox.Show("Không có file nào!", "Mess", MessageBoxButton.OK, MessageBoxImage.Warning); } #region /* * string[] files = Directory.GetFiles(destFolder); * foreach (string file in files) * { * string Ngay = file.Substring(14, 8); * if (dtpNgay.SelectedDate != null && Ngay == dtpNgay.SelectedDate.Value.ToString("ddMMyyyy")) * { * MessageBox.Show(file); * } * } */ //MessageBox.Show(bll.PdfText(txtPath.Text.Trim())); //string str = bll.XoaKyTuTrang(bll.PdfText(txtPath.Text.Trim())); //MessageBox.Show(str); /* * // MessageBox.Show(bll.XoaKyTuTrang(bll.pdfText(txtPath.Text.Trim()))); * for (int i = 0; i < ListBox.Items.Count; i++) * { * string mato = ""; * string soku = ""; * string str = bll.XoaKyTuTrang(bll.pdfText(txtPath.Text.Trim())); * MessageBox.Show(str); * * string[] arrStr = str.Split(' '); * foreach (var item in arrStr) * { * if ((item.Trim().Length == 8 && bll.Right(item.Trim(), 1) == ":") || * (item.Trim().Length == 16 && bll.Left(item.Trim(), 2) == "66")) * { * if (item.Trim().Length == 8 && bll.Right(item.Trim(), 1) == ":") * { * //MessageBox.Show("Ma to "+bll.Left(item,7)); * mato = bll.Left(item, 7); * //strmoi = strmoi + mato+" "; * } * if (item.Trim().Length == 16 && bll.Left(item.Trim(), 2) == "66") * { * //MessageBox.Show("soku " + item.Trim()); * soku = item.Trim(); * //strmoi = strmoi + soku+" "; * MessageBox.Show(mato + " " + soku); * } * } * } * //MessageBox.Show(strmoi); * } */ #endregion } catch (Exception ex) { MessageBox.Show("Error + " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } #endregion bll.DeleteAllFile(txtPath.Text.Trim()); bll.DeleteAllFile(txtSourcePath.Text.Trim()); ListBox.Items.Clear(); ListText.Items.Clear(); }