Beispiel #1
0
        public void ScanBook(Image bookImage, ScannerDataProvider scannerData, User user)
        {
            scannerData.ResetData();

            try
            {
                BarcodeDecoder Scanner       = new BarcodeDecoder();
                Result         scannerResult = Scanner.Decode(new Bitmap(bookImage));

                scannerData.isbn = scannerResult.Text;

                if (scannerResult.Text.Length == 13)
                {
                    CheckISBN(scannerResult.Text, 13, scannerData, user);
                }
                else if (scannerResult.Text.Length == 10)
                {
                    CheckISBN(scannerResult.Text, 10, scannerData, user);
                }
                else
                {
                    scannerData.wrongCode = true;
                }
            }
            catch (MessagingToolkit.Barcode.NotFoundException)
            {
                scannerData.barcodeNotFound = true;
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Scanner = new BarcodeDecoder();
            Result result = Scanner.Decode(new Bitmap(pictureBox1.Image));

            MessageBox.Show(result.Text);
        }
Beispiel #3
0
        private void bunifuFlatButton1_Click(object sender, EventArgs e)
        {
            try
            {
                Scanner = new BarcodeDecoder();
                Result result = Scanner.Decode(new Bitmap(picBoxBarcode.Image));
                dataGridView1.ColumnCount     = 4;
                dataGridView1.Columns[0].Name = "ID";
                dataGridView1.Columns[1].Name = "Products";
                dataGridView1.Columns[2].Name = "Quantity";
                dataGridView1.Columns[3].Name = "Price";

                var     code        = unitofwork.ProductRepository.Get(filter: x => x.Barcode == result.Text);
                string  id          = "";
                string  productName = "";
                decimal price       = 0;
                var     qty         = Convert.ToDecimal(txtQty.Text);
                foreach (var item in code)
                {
                    id          = item.Id.ToString();
                    productName = item.Prod_Name;
                    price       = item.Price * qty;
                }
                decimal Total = Convert.ToDecimal(lblTotal.Text) + price;
                lblTotal.Text = Total.ToString();

                dataGridView1.Rows.Add(id, productName, qty, price);
            }
            catch (Exception)
            {
                MessageBox.Show("Error Occured, Product does not exist");
            }
        }
        public string DecodeDeviceImage(Bitmap ImageBitmap)
        {
            BarcodeDecoder bd            = new BarcodeDecoder();
            Result         res           = bd.Decode(ImageBitmap);
            string         DecodedResult = res.Text;

            return(DecodedResult);
        }
Beispiel #5
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     WebApiConfig.Register(GlobalConfiguration.Configuration);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     AuthConfig.RegisterAuth();
     BarcodeDecoder.Run();
     PTFDataAccess.ConnectionString = WebConfigurationManager.ConnectionStrings["PTF_ConnectionString"].ConnectionString;
 }
Beispiel #6
0
        public CommandServerViewModel()
        {
            vcsServer      = new VCSCommunicator(vcsRxQueue, vcsTxQueue);
            bacrodeDecoder = new BarcodeDecoder(agvRxQueue, vcsTxQueue);
            agvTaskDequer  = new agvTaskDequer(vcsServer);

            StartServerCommand = new DelegateCommand(exStartServerCmd, canExStartServerCmd).ObservesProperty(() => UserProperty);

            checkProcessStatusTimer.Interval = TimeSpan.FromMilliseconds(1000);
            checkProcessStatusTimer.Tick    += new EventHandler(checkProcessStatusTimer_Tick);
            checkProcessStatusTimer.Start();
        }
Beispiel #7
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
            BarcodeDecoder.Run();
            ObjectFileCache cache = new ObjectFileCache(Config.FILECACHEFOLDER);

            cache.Reset();
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            OpenFileDialog OD = new OpenFileDialog();

            OD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            if (OD.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Load(OD.FileName);
            }
            BarcodeDecoder Scanner = new BarcodeDecoder();
            Result         result  = Scanner.Decode(new Bitmap(pictureBox1.Image));

            txtCodigoBarra.Text = result.Text;
        }
        // ---

        private void camera_CaptureImageAvailable(object sender, ContentReadyEventArgs e)
        {
            capturing = false;

            Stream imageStream = (Stream)e.ImageStream;
            BarcodeDecoder barcodeDecoder = new BarcodeDecoder();

            Dictionary<DecodeOptions, object> decodingOptions =
                                new Dictionary<DecodeOptions, object>();
            List<BarcodeFormat> possibleFormats = new List<BarcodeFormat>(1);
            Result result;

            Dispatcher.BeginInvoke(
                () =>
                {

                    WriteableBitmap qrImage = new WriteableBitmap((int)camera.Resolution.Width, (int)camera.Resolution.Height);
                    imageStream.Position = 0;
                    qrImage.LoadJpeg(imageStream);

                    possibleFormats.Add(BarcodeFormat.QRCode);

                    decodingOptions.Add(
                        DecodeOptions.PossibleFormats,
                        possibleFormats);

                    try
                    {
                        result = barcodeDecoder.Decode(qrImage, decodingOptions);

                        resultText.Text = result.Text;
                    }
                    catch (NotFoundException)
                    {
                        // this is expected if the image does not contain a valid
                        // code, Or is too distorted to read
                        resultText.Text = "<nothing to display>";
                    }
                    catch (Exception ex)
                    {
                        // something else went wrong, so alert the user
                        MessageBox.Show(
                            ex.Message,
                            "Error Decoding Image",
                            MessageBoxButton.OK);
                    }
                }
            );
        }
        private Result[] ReadQRLocationsFromScreen()
        {
            using (var bitmap = ReadPrimaryScreenBitmap())
            {
                var hBitmap = bitmap.GetHbitmap();
                Logger.Info("Scanning for barcodes");
                var decoder      = new BarcodeDecoder();
                var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                DeleteObject(hBitmap);
                var writeableBitmap = new WriteableBitmap(bitmapSource);

                Result[] ret = decoder.DecodeMultiple(writeableBitmap);
                Logger.Info("Done!");
                return(ret);
            }
        }
Beispiel #11
0
        public static Result[] ReadQRsFromScreen(int sourceX, int sourceY, Size size)
        {
            Logger.Info("Scanning for barcodes");
            using (var bitmap = ReadPrimaryScreenBitmap(sourceX, sourceY, size))
            {
                var hBitmap      = bitmap.GetHbitmap();
                var decoder      = new BarcodeDecoder();
                var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                DeleteObject(hBitmap);
                var writeableBitmap = new WriteableBitmap(bitmapSource);

                Result[] results = decoder.DecodeMultiple(writeableBitmap);
                Logger.Info("Done!");

                return(results);
            }
        }
Beispiel #12
0
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            OpenFileDialog OD = new OpenFileDialog();

            OD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            if (OD.ShowDialog() == DialogResult.OK)
            {
                pictureBox2.Load(OD.FileName);
            }
            BarcodeDecoder Scanner = new BarcodeDecoder();
            Result         result  = Scanner.Decode(new Bitmap(pictureBox2.Image));

            lbDni.Text = result.Text;

            listaTarjetas        = cnx.listarTarjetas();
            btnRefrescar.Enabled = false;
            for (int i = 0; i < listaTarjetas.Count; i++)
            {
                if (listaTarjetas[i].Dni == lbDni.Text)
                {
                    upAll();
                    int mes = Convert.ToInt16(DateTime.Now.Month);
                    lbMail.Text     = listaTarjetas[i].Email;
                    txtCliente.Text = listaTarjetas[i].Email;
                    listaTratamientos.Clear();
                    listaTratamientos = cnx.listarTratamientos(listaTarjetas[i].Dni, mes);
                    tabControl1.Controls.Clear();
                    MedEncontrados.Clear();

                    for (int j = 0; j < listaTratamientos.Count; j++)
                    {
                        foreach (claseMedicamento med in listaMedicamento)
                        {
                            if (med.Nombre == listaTratamientos[j].Medicamento)
                            {
                                MedEncontrados.Add(med);
                            }
                        }
                    }
                    cargarTPV(MedEncontrados);
                }
            }
        }
Beispiel #13
0
        //Cargar codigo de un nuevo medicamento
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            claseMedicamento cm = new claseMedicamento();
            OpenFileDialog   OD = new OpenFileDialog();

            OD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            if (OD.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Load(OD.FileName);
            }
            BarcodeDecoder Scanner = new BarcodeDecoder();
            Result         result  = Scanner.Decode(new Bitmap(pictureBox1.Image));

            lblScannerNumero.Text = result.Text;
            cm                  = cnx.buscarmedicamento(lblScannerNumero.Text);
            txtNombre.Text      = cm.Nombre;
            txtPrecio.Text      = Convert.ToString(cm.Precio);
            txtStockMin.Text    = Convert.ToString(cm.Stockminimo);
            txtStockActual.Text = Convert.ToString(cm.Stockactual);

            cnx.añadirMedicamento(cm);
        }
Beispiel #14
0
        public ActionResult Scanbarcode(BarcodeModel b)
        {
            string barcode = this.Request.Params["Barcode"];

            if (!string.IsNullOrWhiteSpace(barcode))
            {
                BarcodeData data = new BarcodeDecoder().Match(barcode);
                if (data != null)
                {
                    //data.CountryID = 826;
                    //data.VoucherID = 15715619;
                    // Ravi: Don't test!
                    //if (PTFDataAccess.CheckP1Exists(data.CountryID, data.VoucherID))
                    {
                        PTFDataAccess.ExcudeFromDebitRun(data.CountryID, data.RetailerID, data.VoucherID, CurrentUser.UserID);
                        PTFDataAccess.LogVoucher(data.CountryID, data.VoucherID, CurrentUser.UserID);
                        ViewBag.Info = PTFDataAccess.SelectVoucherInfo(data.CountryID, data.VoucherID);
                        //return RedirectToAction("Index", "Home");
                    }
                    //else
                    //{
                    //    ViewBag.Err =
                    //        string.Format("P1 doesn't exist for Iso:'{0}' Branch:'{1}' Voucher:'{2}'. Please process voucher by using voucher entry in TRS.", data.CountryID, data.RetailerID, data.VoucherID);
                    //}
                }
                else
                {
                    ViewBag.Err = string.Format("Wrong barcode '{0}'. Please renter.", barcode);
                }
            }
            else
            {
                ViewBag.Err = "Barcode may not be empty.";
            }
            return(View(b));
        }
Beispiel #15
0
        private void pictureBox3_Click(object sender, EventArgs e)
        {
            OpenFileDialog OD = new OpenFileDialog();

            OD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            if (OD.ShowDialog() == DialogResult.OK)
            {
                pictureBox3.Load(OD.FileName);
            }
            BarcodeDecoder Scanner = new BarcodeDecoder();
            Result         result  = Scanner.Decode(new Bitmap(pictureBox3.Image));

            txtRecoje.Text = result.Text;

            if (txtRecoje.Text.Equals("3333"))
            {
                upAll();
            }
            else if (txtRecoje.Text.Equals("33943444"))
            {
                upAll();
            }
            else if (txtRecoje.Text.Equals("4444"))
            {
                upAll();
            }
            else
            {
                MessageBox.Show("Usuario no reconocido");
            }

            txtRecoje.Enabled   = false;
            txtRecoje.Visible   = false;
            pictureBox3.Enabled = false;
            pictureBox3.Visible = false;
        }
Beispiel #16
0
        private void barcode_toolKit(fn_share fn_share, string filename)
        {
            string json = string.Empty; string sql = string.Empty;
            string guid = string.Empty; string decoded = string.Empty; string barcode = string.Empty;

            if (db.KeyExists("recognizetask"))
            {
                JObject jo = null;
                try
                {
                    json = db.ListLeftPop("recognizetask");
                    fn_share.systemLog(filename, "-------------------------------------------------------------\r\n");
                    if (!string.IsNullOrEmpty(json))
                    {
                        jo = (JObject)JsonConvert.DeserializeObject(json);
                        //只有PDF文件才会进行条形码识别
                        sql = @"select t.* from list_attachment t where t.ordercode='" + jo.Value <string>("ordercode") + "' and upper(t.filesuffix)='PDF'";
                        DataTable dt = DBMgr.GetDataTable(sql);
                        if (dt.Rows.Count > 0)
                        {
                            DateTime d1 = DateTime.Now;
                            guid = Guid.NewGuid().ToString();
                            ConvertPDF.pdfToPic(direc_pdf + dt.Rows[0]["FILENAME"], direc_img, guid, 1, 1, ImageFormat.Jpeg);//pdf转图片
                            string fileName = direc_img + guid + ".Jpeg";
                            fn_share.systemLog(filename, "=== ConvertToImage——" + (DateTime.Now - d1) + "\r\n");
                            if (File.Exists(fileName))
                            {
                                BarcodeDecoder barcodeDecoder = new BarcodeDecoder();
                                Image          primaryImage   = Image.FromFile(fileName);
                                Bitmap         pImg           = MakeGrayscale3((Bitmap)primaryImage);
                                Dictionary <DecodeOptions, object> decodingOptions = new Dictionary <DecodeOptions, object>();
                                List <BarcodeFormat> possibleFormats = new List <BarcodeFormat>(10);
                                possibleFormats.Add(BarcodeFormat.Code128);
                                possibleFormats.Add(BarcodeFormat.EAN13);
                                decodingOptions.Add(DecodeOptions.TryHarder, true);
                                decodingOptions.Add(DecodeOptions.PossibleFormats, possibleFormats);
                                DateTime d2            = DateTime.Now;
                                Result   decodedResult = barcodeDecoder.Decode(pImg, decodingOptions);
                                Console.WriteLine("解析时长:" + (DateTime.Now - d2));
                                //while (decodedResult == null)
                                //{
                                //    System.Threading.Thread.Sleep(500);
                                //}
                                if (decodedResult != null)//有些PDF文件并无条形码
                                {
                                    barcode = decodedResult.Text;
                                }
                                else
                                {
                                    barcode = "001";
                                }
                                sql = "update list_order set cusno='" + barcode + "' where code='" + jo.Value <string>("ordercode") + "'";
                                DBMgr.ExecuteNonQuery(sql);
                            }
                            fn_share.systemLog(filename, "=== " + jo.Value <string>("ordercode") + "——" + (DateTime.Now - d1) + "——" + barcode + "\r\n");
                        }
                    }
                }
                catch (Exception ex)
                {
                    //db.ListRightPush("recognizetask", json);
                    sql = "update list_order set cusno='002' where code='" + jo.Value <string>("ordercode") + "'";
                    DBMgr.ExecuteNonQuery(sql);
                    fn_share.systemLog(filename, jo.Value <string>("ordercode") + "  异常,识别条码失败:" + ex.Message + "\r\n");
                }
            }
        }
Beispiel #17
0
 public void test_barcode()
 {
     BarcodeDecoder.Run();
     new BarcodeDecoder().Test();
 }
Beispiel #18
0
        private void Decode(Image img)
        {
            if (img == null)
            {
                return;
            }

            Bitmap bmp;
            if (img is Bitmap)
            {
                bmp = img as Bitmap;
            }
            else
            {
                bmp = new Bitmap(img.Width, img.Height);
                Graphics g = Graphics.FromImage(bmp);
                g.DrawImage(img, 0, 0, img.Width, img.Height);
                g.Flush();
                g.Save();
                g.Dispose();
            }

            if (_Decoder == null)
            {
                _Decoder = new BarcodeDecoder();
            }

            try
            {
                Dictionary<DecodeOptions, object> opt = new Dictionary<DecodeOptions, object>();
                List<BarcodeFormat> format = new List<BarcodeFormat>(10);
                format.Add(BarcodeFormat.QRCode);
                //opt.Add(DecodeOptions.PureBarcode, "");
                opt.Add(DecodeOptions.TryHarder, true);
                //opt.Add(DecodeOptions.PossibleFormats, format);

                Result result = _Decoder.Decode(bmp, opt);
                if (result == null)
                {
                    return;
                }

                CbOpt.SelectedIndex = 0;
                PbIcon.Image = bmp;
                UcUserSet.DecodeUserSet(result);
                string text = result.Text;

                string key;
                if (!Regex.IsMatch(text, "^[a-zA-z]{2,}:[^\\s]+"))
                {
                    key = EBar.OPT_TEXT;
                }
                else
                {
                    int idx = text.IndexOf(':');
                    key = text.Substring(0, idx);
                    text = text.Substring(idx + 1);
                }

                ShowOpt(key);
                if (_IOpt != null)
                {
                    _IOpt.Decode(text);
                }
            }
            catch (BarcodeDecoderException exp)
            {
                LbEcho.Text = exp.Message;
            }
        }
 private void timer2_Tick(object sender, EventArgs e)
 {
     if (!working2)
     {
         working2 = true;
         if (db.KeyExists("recognizetask"))
         {
             string json = db.ListLeftPop("recognizetask");
             if (!string.IsNullOrEmpty(json))
             {
                 try
                 {
                     JObject jo = (JObject)JsonConvert.DeserializeObject(json);
                     //只有PDF文件才会进行条形码识别
                     sql = @"select t.* from list_attachment t where t.ordercode='" + jo.Value <string>("ordercode") + "' and upper(t.filesuffix)='PDF'";
                     DataTable dt = DBMgr.GetDataTable(sql);
                     if (dt.Rows.Count > 0)
                     {
                         guid = Guid.NewGuid().ToString();
                         ConvertPDF2Image(direc_pdf + dt.Rows[0]["FILENAME"], direc_img, guid, 1, 1, ImageFormat.Jpeg, Definition.Ten);
                         BarcodeDecoder barcodeDecoder = new BarcodeDecoder();
                         if (File.Exists(direc_img + guid + ".Jpeg"))
                         {
                             System.Drawing.Bitmap image = new System.Drawing.Bitmap(direc_img + guid + ".Jpeg");
                             Dictionary <DecodeOptions, object> decodingOptions = new Dictionary <DecodeOptions, object>();
                             List <BarcodeFormat> possibleFormats = new List <BarcodeFormat>(10);
                             //possibleFormats.Add(BarcodeFormat.DataMatrix);
                             //possibleFormats.Add(BarcodeFormat.QRCode);
                             //possibleFormats.Add(BarcodeFormat.PDF417);
                             //possibleFormats.Add(BarcodeFormat.Aztec);
                             //possibleFormats.Add(BarcodeFormat.UPCE);
                             //possibleFormats.Add(BarcodeFormat.UPCA);
                             possibleFormats.Add(BarcodeFormat.Code128);
                             //possibleFormats.Add(BarcodeFormat.Code39);
                             //possibleFormats.Add(BarcodeFormat.ITF14);
                             //possibleFormats.Add(BarcodeFormat.EAN8);
                             possibleFormats.Add(BarcodeFormat.EAN13);
                             //possibleFormats.Add(BarcodeFormat.RSS14);
                             //possibleFormats.Add(BarcodeFormat.RSSExpanded);
                             //possibleFormats.Add(BarcodeFormat.Codabar);
                             //possibleFormats.Add(BarcodeFormat.MaxiCode);
                             decodingOptions.Add(DecodeOptions.TryHarder, true);
                             decodingOptions.Add(DecodeOptions.PossibleFormats, possibleFormats);
                             Result decodedResult = barcodeDecoder.Decode(image, decodingOptions);
                             //while (decodedResult == null)
                             //{
                             //    System.Threading.Thread.Sleep(500);
                             //}
                             if (decodedResult != null)//有些PDF文件并无条形码
                             {
                                 barcode = decodedResult.Text;
                                 barconvert();//编码转换
                                 sql = "update list_order set cusno='" + barcode + "' where code='" + jo.Value <string>("ordercode") + "'";
                                 DBMgr.ExecuteNonQuery(sql);
                             }
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     this.button2.Text = ex.Message;
                     this.button2.Text = json + "识别条码失败!";
                     //db.ListRightPush("recognizetask", json);
                     working2 = false;
                 }
             }
         }
         working2 = false;
     }
 }
Beispiel #20
0
        // ---

        private void camera_CaptureImageAvailable(object sender, ContentReadyEventArgs e)
        {
            capturing = false;

            Stream imageStream = (Stream)e.ImageStream;
            BarcodeDecoder barcodeDecoder = new BarcodeDecoder();

            Dictionary<DecodeOptions, object> decodingOptions =
                                new Dictionary<DecodeOptions, object>();
            List<BarcodeFormat> possibleFormats = new List<BarcodeFormat>(1);
            Result result;

            Dispatcher.BeginInvoke(
                () =>
                {

                    WriteableBitmap qrImage = new WriteableBitmap((int)camera.Resolution.Width, (int)camera.Resolution.Height);
                    imageStream.Position = 0;
                    qrImage.LoadJpeg(imageStream);

                    possibleFormats.Add(BarcodeFormat.QRCode);

                    decodingOptions.Add(
                        DecodeOptions.PossibleFormats,
                        possibleFormats);

                    try
                    {
                        result = barcodeDecoder.Decode(qrImage, decodingOptions);

                        resultText.Text = result.Text;
                        VerDonoButton.Visibility = System.Windows.Visibility.Visible;

                        foreach (var animal in PerfisControl.GetPerfilByEmail("*****@*****.**").Animais)
                        {
                            if (animal.Especie.Equals("Ovelha"))
                            {
                                LocalizacoesControl.InsertLocalizacao(new Localizacao()
                                {
                                    DataHora = DateTime.Now,
                                    Coordenada = new GeoCoordinate(-3.1243974, -59.9838239),
                                    AnimalId = animal.Id
                                });
                            }
                        }

                        //resultText.Text = "Animal identificado.";

                        //StkQRInfo.Visibility = Visibility.Visible;
                        //StkQRInfo.DataContext = new QRInfo(0);
                    }
                    catch (NotFoundException)
                    {
                        // this is expected if the image does not contain a valid
                        // code, Or is too distorted to read
                        resultText.Text = "Imagem não identificada. Aponte a câmera para o código QR na coleira do animal.";
                        VerDonoButton.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    catch (Exception ex)
                    {
                        // something else went wrong, so alert the user
                        MessageBox.Show(
                            ex.Message,
                            "Erro ao decodificar a imagem",
                            MessageBoxButton.OK);
                    }
                }
            );
        }
Beispiel #21
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (!working)//如果timer当前空闲  防止处理任务的时间大于轮循的时间
     {
         working = true;
         string        direc_pdf    = ConfigurationManager.AppSettings["PdfPath"];
         string        direc_upload = DateTime.Now.ToString("yyyy-MM-dd");
         string        barcode      = string.Empty;
         string        sql          = string.Empty;
         FtpHelper     ftp          = new FtpHelper(Uri, UserName, Password);
         DirectoryInfo dc           = new DirectoryInfo(direc_pdf);
         foreach (FileInfo file in dc.GetFiles("*.pdf", SearchOption.AllDirectories))
         {
             //1 对pdf文件进行条码识别
             if (!FileIsUsed(file.FullName))//如果文件未被占用
             {
                 try
                 {
                     guid = Guid.NewGuid().ToString(); //将文件重命名
                     file.MoveTo(direc_pdf + guid + ".pdf");
                     //将PDF文件的第一页转图片
                     ConvertPDF2Image(direc_pdf + guid + ".pdf", direc_img, guid + ".jpg", 1, 1, ImageFormat.Jpeg, Definition.Ten);
                     //在图片文件中读取条形码信息
                     BarcodeDecoder barcodeDecoder = new BarcodeDecoder();
                     if (File.Exists(direc_img + guid + ".jpg"))
                     {
                         System.Drawing.Bitmap image = new System.Drawing.Bitmap(direc_img + guid + ".jpg");
                         Dictionary <DecodeOptions, object> decodingOptions = new Dictionary <DecodeOptions, object>();
                         List <BarcodeFormat> possibleFormats = new List <BarcodeFormat>(10);
                         //possibleFormats.Add(BarcodeFormat.DataMatrix);
                         //possibleFormats.Add(BarcodeFormat.QRCode);
                         //possibleFormats.Add(BarcodeFormat.PDF417);
                         //possibleFormats.Add(BarcodeFormat.Aztec);
                         //possibleFormats.Add(BarcodeFormat.UPCE);
                         //possibleFormats.Add(BarcodeFormat.UPCA);
                         possibleFormats.Add(BarcodeFormat.Code128);
                         //possibleFormats.Add(BarcodeFormat.Code39);
                         //possibleFormats.Add(BarcodeFormat.ITF14);
                         //possibleFormats.Add(BarcodeFormat.EAN8);
                         possibleFormats.Add(BarcodeFormat.EAN13);
                         //possibleFormats.Add(BarcodeFormat.RSS14);
                         //possibleFormats.Add(BarcodeFormat.RSSExpanded);
                         //possibleFormats.Add(BarcodeFormat.Codabar);
                         //possibleFormats.Add(BarcodeFormat.MaxiCode);
                         decodingOptions.Add(DecodeOptions.TryHarder, true);
                         decodingOptions.Add(DecodeOptions.PossibleFormats, possibleFormats);
                         Result decodedResult = barcodeDecoder.Decode(image, decodingOptions);
                         while (decodedResult == null)
                         {
                             System.Threading.Thread.Sleep(500);
                         }
                         barcode = decodedResult.Text;
                     }
                 }
                 catch (Exception ex)
                 {
                     barcode = string.Empty;
                     working = false;
                 }
                 //上传文件
                 ftp.CreateDirectory(direc_upload, true);
                 bool res = ftp.UploadFile(direc_pdf + guid + ".pdf", @"\" + direc_upload + @"\" + guid + ".pdf");
                 //如果上传成功!插入数据库记录
                 if (res)
                 {
                     OracleConnection conn = new OracleConnection(ConfigurationManager.AppSettings["strconn"]);
                     conn.Open();
                     OracleCommand com = null;
                     if (!string.IsNullOrEmpty(barcode)) //如果条形码识别成功
                     {
                         sql = "select * from list_attachment where ordercode='" + barcode + "'";
                         com = new OracleCommand(sql, conn);
                         OracleDataAdapter da     = new OracleDataAdapter(com);
                         DataTable         dt_att = new DataTable();
                         da.Fill(dt_att);
                         if (dt_att.Rows.Count > 0)//如果该订单的文件已经存在 删除表记录和文件
                         {
                             sql = "delete from list_attachment where ordercode='" + barcode + "'";
                             com = new OracleCommand(sql, conn);
                             com.ExecuteNonQuery();
                             ftp.DeleteFile(dt_att.Rows[0]["FILEPATH"] + "");
                             //如果该文件曾经被复制到其他的订单号下
                             if (!string.IsNullOrEmpty(dt_att.Rows[0]["COPYORDERCODE"] + ""))
                             {
                                 sql = "select * from list_attachment where ordercode='" + dt_att.Rows[0]["COPYORDERCODE"] + "'";
                                 com = new OracleCommand(sql, conn);
                                 da  = new OracleDataAdapter(com);
                                 DataTable dt_gl = new DataTable();
                                 da.Fill(dt_gl);
                                 sql = "delete from list_attachment where ordercode='" + dt_att.Rows[0]["COPYORDERCODE"] + "'";
                                 com = new OracleCommand(sql, conn);
                                 com.ExecuteNonQuery();
                                 ftp.DeleteFile(dt_gl.Rows[0]["FILEPATH"] + "");
                             }
                         }
                     }
                     sql = @"insert into list_attachment (ID,FILEPATH,FILENAME,FILESIZE,ORDERCODE,CREATETIME,CREATEUSERID) 
                           VALUES (LIST_ATTACHMENT_ID.NEXTVAL,'{0}','{1}','{2}','{3}',sysdate,'{4}')";
                     sql = string.Format(sql, @"/" + direc_upload + @"/" + guid + ".pdf", guid + ".pdf", file.Length, barcode, this.label1.Text);
                     com = new OracleCommand(sql, conn);
                     com.ExecuteNonQuery();
                     if (!string.IsNullOrEmpty(barcode))
                     {
                         sql = "update list_order set FILERELATE='1' where code='" + barcode + "'";
                         com = new OracleCommand(sql, conn);
                         com.ExecuteNonQuery();
                     }
                     if (this.checkBox1.Checked)
                     {
                         //DJRI161100579 DJRE161100579 DJCI161100579 DJCE161100579  GJI161100553 GJE161100553
                         string newcode = string.Empty;
                         string preffix = barcode.Substring(0, 3);
                         if (preffix == "DJR" || preffix == "DJC" || preffix == "GJI" || preffix == "GJE")
                         {
                             if (barcode.IndexOf("I") > 0)
                             {
                                 newcode = barcode.Replace("I", "E");
                             }
                             if (barcode.IndexOf("E") > 0)
                             {
                                 newcode = barcode.Replace("E", "I");
                             }
                             string guid2 = Guid.NewGuid().ToString(); //复制并重命名文件
                             file.CopyTo(direc_pdf + guid2 + ".pdf");
                             sql = @"insert into list_attachment (ID,FILEPATH,FILENAME,FILESIZE,ORDERCODE,CREATETIME,CREATEUSERID,CREATENAME)
                             VALUES (LIST_ATTACHMENT_ID.NEXTVAL,'{0}','{1}','{2}','{3}',sysdate,'{4}','{5}')";
                             sql = string.Format(sql, @"/" + direc_upload + @"/" + guid2 + ".pdf", guid2 + ".pdf", file.Length, newcode, this.label1.Text, this.label2.Text);
                             com = new OracleCommand(sql, conn);
                             com.ExecuteNonQuery();
                             bool result = ftp.UploadFile(direc_pdf + guid2 + ".pdf", @"\" + direc_upload + @"\" + guid2 + ".pdf");
                             sql = "update list_attachment set copyordercode='" + newcode + "' where ordercode='" + barcode + "'";
                             com = new OracleCommand(sql, conn);
                             com.ExecuteNonQuery();
                             if (result)
                             {
                                 FileInfo fi_new = new FileInfo(direc_pdf + guid2 + ".pdf");
                                 fi_new.MoveTo(direc_img + guid2 + ".pdf");
                                 sql = "update list_order set FILERELATE='1' where code='" + newcode + "'";
                                 com = new OracleCommand(sql, conn);
                                 com.ExecuteNonQuery();
                             }
                         }
                     }
                     conn.Close();
                 }
                 //将文件搬移至已上传的目录
                 file.MoveTo(direc_img + guid + ".pdf");
             }
         }
         working = false;
     }
 }