Exemple #1
0
 private void BtnOk_OnClick(object sender, RoutedEventArgs e)
 {
     try
     {
         if (ListBox.Items.Count > 0)
         {
             string destFolder   = txtPath.Text.Trim();
             string sourceFolder = txtSourcePath.Text.Trim();
             foreach (object t in ListBox.Items)
             {
                 string mato = "";
                 string file = destFolder + t;
                 string pos  = t.ToString().Substring(0, 6);
                 string ngay = t.ToString().Substring(7, 8);
                 cls.ClsConnect();
                 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(bll.PdfText(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")
                             {
                                 var 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);
             bll.DeleteAllFile(txtPath.Text.Trim());
             ListBox.Items.Clear();
         }
         else
         {
             MessageBox.Show("Không có File nào trong listbox", "Mess", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error + " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }