Пример #1
0
 public override void ParseCode(Document doc, BarcodeFormat format, string codeText)
 {
     switch (format) {
     case BarcodeFormat.CODE_39:
         ParseCode39 (doc, codeText);
         break;
     case BarcodeFormat.EAN_13:
         ParseCode13 (doc, codeText);
         break;
     default:
         logger.Error ("Нет правил разбора для штрих-кода {0}.", format);
         break;
     }
 }
Пример #2
0
        private void ParseCode39(Document doc, string codeText)
        {
            if (String.IsNullOrWhiteSpace (codeText))
            {
                logger.Error ("Штрих код пустой.");
                return;
            }

            if(!codeText.Contains ("-"))
            {
                logger.Error ("Разделитель даты и номера не найден. Штрих код должен быть в формате {ddmmyy-n}");
                return;
            }

            var split = codeText.Split (new char[] {'-'}, 2);
            var dateText = split [0];
            var numText = split [1];

            if(!String.IsNullOrWhiteSpace (numText))
            {
                logger.Debug ("Номер документа: {0}", numText);
                doc.DocNumber = numText;
                doc.DocNumberConfidence = 1;
            }

            if(dateText.Length != 6)
            {
                logger.Error ("Дата должна быть в формате {ddmmyy}");
                return;
            }

            DateTime date;
            var formated = dateText.Insert (4, ".").Insert (2, ".");

            if(DateTime.TryParse (formated, out date))
            {
                logger.Debug ("Дата документа: {0:D}", date);
                doc.DocDate = date;
                doc.DocDateConfidence = 1;
            }
            else
            {
                logger.Error ("Строку {0}(до преобразования {1}) не удалось разобрать как дату.", formated, dateText);
            }
        }
Пример #3
0
        private void ParseCode13(Document doc, string codeText)
        {
            if (String.IsNullOrWhiteSpace (codeText))
            {
                logger.Error ("Штрих код пустой.");
                return;
            }

            if(codeText.Length != 13)
            {
                logger.Error ("Код имеет неправильную длинну.");
                return;
            }

            var dateText = codeText.Substring (0, 6);
            var numText = codeText.Substring (6, 6);

            if(!String.IsNullOrWhiteSpace (numText))
            {
                logger.Debug ("Номер документа: {0}", numText);
                doc.DocNumber = numText;
                doc.DocNumberConfidence = 1;
            }

            if(dateText.Length != 6)
            {
                logger.Error ("Дата должна быть в формате {yymmdd}");
                return;
            }

            int day = int.Parse (dateText.Substring (4, 2));
            int month = int.Parse (dateText.Substring (2, 2));
            int year = int.Parse (dateText.Substring (0, 2)) + 2000;

            DateTime date = new DateTime(year, month, day);

            logger.Debug ("Дата документа: {0:D}", date);
            doc.DocDate = date;
            doc.DocDateConfidence = 1;
        }
Пример #4
0
 public RecognizeDoc(Document doc, Pixbuf[] images)
 {
     Doc = doc;
     Images = images;
 }
Пример #5
0
 protected void OnTreeviewImagesSelectionChanged(object sender, EventArgs e)
 {
     TreeIter iter, iterimage, iterdoc;
     logger.Debug ("OnTreeviewImagesSelectionChanged");
     if(treeviewImages.Selection.GetSelected(out iter))
     {
         if(ImageList.IterHasChild(iter))
         {
             ImageList.IterNthChild(out iterimage, iter, 0);
             iterdoc = iter;
         }
         else
         {
             iterimage = iter;
             ImageList.IterParent (out iterdoc, iter);
         }
         if(ImageList.GetPath(CurrentDocIter) == null || ImageList.GetPath(iterdoc).Compare(ImageList.GetPath(CurrentDocIter)) != 0 )
         {
             CurrentDocIter = iterdoc;
             CurrentDoc = (Document)ImageList.GetValue (iterdoc, 3);
             UpdateFieldsWidgets(true);
         }
         if(ImageList.GetValue (iterimage, 5) != null)
         {
             CurrentImage = iterimage;
             zoomFitAction.Activate ();
         }
     }
     else
     {
         logger.Debug ("Doc disselect.");
         CurrentDoc = null;
         CurrentDocIter = TreeIter.Zero;
         UpdateFieldsWidgets(true);
         CurrentImage = TreeIter.Zero;
         zoomFitAction.Activate ();
     }
 }
Пример #6
0
 protected void OnImageListPopupDocTypeAll(object sender, ButtonPressEventArgs arg)
 {
     int Typeid = -1;
     foreach(object[] row in (ListStore)comboType.Model)
     {
         if((string)row[0] == ((Gtk.AccelLabel)((Gtk.MenuItem)sender).Child).LabelProp)
             Typeid = (int)row[1];
     }
     if(Typeid > 0)
     {
         TreeIter iter;
         if(!ImageList.GetIterFirst(out iter))
             return;
         do
         {
             if(ImageList.IterDepth(iter) == 0)
             {
                 Document doc = new Document(Typeid);
                 ImageList.SetValue(iter, 3, doc);
                 ImageList.SetValue(iter, 7, doc.TypeName);
             }
         }while(ImageList.IterNext(ref iter));
     }
 }
Пример #7
0
 protected void OnImageListPopupDocType(object sender, EventArgs Arg)
 {
     TreeIter iter;
     treeviewImages.Selection.GetSelected(out iter);
     if(ImageList.IterDepth(iter) == 1)
     {
         TreeIter parent;
         ImageList.IterParent (out parent, iter);
         iter = parent;
     }
     int Typeid = -1;
     Console.WriteLine(((Gtk.AccelLabel)((Gtk.MenuItem)sender).Child).LabelProp);
     foreach(object[] row in (ListStore)comboType.Model)
     {
         if((string)row[0] == ((Gtk.AccelLabel)((Gtk.MenuItem)sender).Child).LabelProp)
             Typeid = (int)row[1];
     }
     if(Typeid > 0)
     {
         Document doc = new Document(Typeid);
         ImageList.SetValue(iter, 3, doc);
         ImageList.SetValue(iter, 7, doc.TypeName);
         CurrentDoc = doc;
         UpdateFieldsWidgets(true);
     }
 }
Пример #8
0
 protected void OnComboTypeChanged(object sender, EventArgs e)
 {
     TreeIter iter;
     if(!ImageList.IterIsValid(CurrentDocIter))
         return;
     if(!Clearing && comboType.GetActiveIter(out iter))
     {
         int Type = (int)comboType.Model.GetValue(iter, 1);
         Document doc = new Document(Type);
         ImageList.SetValue(CurrentDocIter, 3, doc);
         ImageList.SetValue(CurrentDocIter, 7, doc.TypeName);
         CurrentDoc = doc;
         UpdateFieldsWidgets(false);
     }
 }
Пример #9
0
 protected void OnTreeviewImagesCursorChanged(object sender, EventArgs e)
 {
     TreeIter iter, iterimage, iterdoc;
     if(treeviewImages.Selection.GetSelected(out iter))
     {
         if(ImageList.IterHasChild(iter))
         {
             ImageList.IterNthChild(out iterimage, iter, 0);
             iterdoc = iter;
         }
         else
         {
             iterimage = iter;
             ImageList.IterParent (out iterdoc, iter);
         }
         CurrentDocIter = iterdoc;
         if(ImageList.GetValue (iterimage, 5) != null)
         {
             CurrentImage = iterimage;
             zoomFitAction.Activate ();
         }
         if((Document)ImageList.GetValue (iterdoc, 3) != CurrentDoc)
         {
             CurrentDoc = (Document)ImageList.GetValue (iterdoc, 3);
             UpdateFieldsWidgets(true);
         }
     }
     else
     {
         comboType.Sensitive = false;
         entryNumber.Sensitive = false;
         dateDoc.Sensitive = false;
     }
 }
Пример #10
0
 public abstract void ParseCode(Document doc, BarcodeFormat format, string codeText);