private void btnElect1_Click(object sender, EventArgs e) { WaitForReady(); SetStatus(ProcessStatus.Election); var sigmas = Global.CurrentSigma.GetSigmasDesc(); foreach (var s in sigmas) { if (s.Value >= 2.5)//3 sigma accuracy { if (Enum.TryParse(s.Key, out ReceiptParts part)) { RocsTextService.ElectOcrLineBySigmaDeferTotalTitle(part); } } } bindingSourceElect1.DataSource = Global.OcrLines; bindingNavigatorElect1.BindingSource = bindingSourceElect1; dgElection1.DataSource = bindingSourceElect1; dgElection1.Refresh(); SetStatus(ProcessStatus.Ready); }
// Define an activity input argument of type string //[RequiredArgument] // If your activity returns a value, derive from CodeActivity<TResult> // and return the value from the Execute method. protected override void Execute(NativeActivityContext context) { // Obtain the runtime value of the Text input argument try { #region --------------------TRY CONTENT---------------------- var sigmas = Global.CurrentSigma.GetSigmasDesc(); foreach (var s in sigmas) { if (s.Value >= 3)//3 sigma accuracy { if (Enum.TryParse(s.Key, out ReceiptParts part)) { RocsTextService.ElectOcrLineBySigma(part); } } } //context.SetValue(Result, Global.CurrentSigma); #endregion } catch (Exception err) { Global.LogError("Elect---> " + err.Message); } finally { // Global.MainWindow.SafeInvoke(c => c.HideBusy()); } }
private void btnTest_Click(object sender, EventArgs e) { //TestCmd(); List <BaiOcrLine> testLines = new List <BaiOcrLine>(); BaiOcrLine ocr = new BaiOcrLine { Content = "Date:10/11/19 TIN:123456789 address: 154 bisalao st. Maligay Nov Q.C. Vendor: SEven eleven" }; testLines.Add(ocr); BaiOcrLine ocr1 = new BaiOcrLine { Content = "TOTAL:100 CHANGE:123 Cash: 500" }; testLines.Add(ocr1); List <BaiOcrLine> result = new List <BaiOcrLine>(); foreach (var thisOcr in testLines) { RocsTextService.RefineOcr(thisOcr, ref result); } int i = 0; foreach (BaiOcrLine item in result) { i += 1; item.LineNo = i; Console.WriteLine(string.Format("{0}. {1}", item.LineNo.ToString(), item.Content)); } }
private void btn2ndElection_Click(object sender, EventArgs e) { //get amounttitle now var ocrTender = Global.OcrLines.Where(o => o.ElectedAs == ReceiptParts.AmountTenderTiTle.ToString()).FirstOrDefault(); if (ocrTender != null && ocrTender.ElectedAs == ReceiptParts.AmountTenderTiTle.ToString()) { for (int i = ocrTender.LineNo; i > 5; i--) { if ((Global.OcrLines[i].Content.ToLower().Contains("total") || Global.OcrLines[i].Content.ToLower().Contains("price")) && !Global.OcrLines[i].Content.ToLower().Contains("sub")) { Global.OcrLines[i].WeightedAsTotalTitle += 7; break; } } } else { var ocrChange = Global.OcrLines.Where(o => o.ElectedAs == ReceiptParts.ChangeTitle.ToString()).FirstOrDefault(); if (ocrChange != null && ocrChange.ElectedAs == ReceiptParts.ChangeTitle.ToString()) { for (int i = ocrChange.LineNo; i > 5; i--) { if ((Global.OcrLines[i].Content.ToLower().Contains("total") || Global.OcrLines[i].Content.ToLower().Contains("price")) && !Global.OcrLines[i].Content.ToLower().Contains("sub")) { Global.OcrLines[i].WeightedAsTotalTitle += 7; break; } } } } btnSigma_Click(sender, e); var sigmas = Global.CurrentSigma.GetSigmasDesc(); foreach (var s in sigmas) { if (s.Value >= 2.5)//3 sigma accuracy { if (Enum.TryParse(s.Key, out ReceiptParts part)) { RocsTextService.ElectOcrLineBySigmaWithTotalTitle(part); } } } bindingSourceElect1.DataSource = Global.OcrLines; bindingNavigatorElect1.BindingSource = bindingSourceElect1; dgElection1.DataSource = bindingSourceElect1; dgElection1.Refresh(); }
private void btnUserSet_Click(object sender, EventArgs e) { WaitForReady(); SetStatus(ProcessStatus.Election); List <Receipt> table = new List <Receipt>(); //string user = Path.GetFileName(Global.CurrentUserFolder); var current = Global.CurrentReciept; var tinId = current.Tax_Identification; tinId = RocsTextService.RefineToPureNumber(tinId); using (MyReceiptOnlyContext db = new MyReceiptOnlyContext()) { var q = db.TableReceiptFixes.Where(r => r.UserFolder == Global.CurrentUser && r.Modified.HasValue); List <ReceiptFix> listR = new List <ReceiptFix>(); foreach (var r in q) { // && RocsTextService.RefineToPureNumber(r.Tax_Identification) == tinId if (RocsTextService.RefineToPureNumber(r.Tax_Identification) == tinId) { listR.Add(r); } } if (listR.Count > 0) { var setting = listR.OrderByDescending(r => r.Modified).ToList().FirstOrDefault(); if (setting.Id > 0) { current.Address = setting.Address; current.Comapany_Name = setting.Comapany_Name; current.Description = setting.Description; } Global.CurrentReciept = current; } } table.Add(Global.CurrentReciept); receiptBindingSource.DataSource = table; dgReceipts.DataSource = receiptBindingSource; this.bindingNavigatorReceipts.BindingSource = receiptBindingSource; SetStatus(ProcessStatus.Ready); }
private void AzureSvc_OnReadDone(object sender, EventArgs e) { if (Global.ProcessStatus == ProcessStatus.Error.ToString()) { //var err = (Exception)sender; Global.LogError("Error on AZURE."); } else if (Global.OcrLines.Count < 15) { //delete imagerow if not receipt File.Delete(Global.CurrentImagePath); bindingSource1.Remove(bindingSource1.Current); Global.LogError("Error on Scan... NOT A RECEIPT"); Global.ProcessStatus = ProcessStatus.Error.ToString(); } else { //delete imagerow File.Delete(Global.CurrentImagePath); bindingSource1.Remove(bindingSource1.Current); //refine OCR List <BaiOcrLine> result = new List <BaiOcrLine>(); foreach (var thisOcr in Global.OcrLines) { RocsTextService.RefineOcr(thisOcr, ref result); } int i = 0; foreach (BaiOcrLine item in result) { i += 1; item.LineNo = i; Console.WriteLine(string.Format("{0}. {1}", item.LineNo.ToString(), item.Content)); } Global.OcrLines = result; ///////////////////// //update ocr list bindingSourceOCR.DataSource = Global.OcrLines; dgOCR.DataSource = bindingSourceOCR; Application.DoEvents(); SetStatus(ProcessStatus.Ready); } }
private void btnCreateReceipt_Click(object sender, EventArgs e) { WaitForReady(); SetStatus(ProcessStatus.Election); List <Receipt> table = new List <Receipt>(); string user = Path.GetFileName(Global.CurrentUserFolder); Global.CurrentReciept = new Receipt { UserFolder = user }; //vendorname RocsTextService.GetReceiptVendorName(); RocsTextService.GetReceiptVendorAddress(); //TIN,Date, total etc.. foreach (BaiOcrLine ocr in Global.OcrLines) { if (ocr.ElectedAs == ReceiptParts.DateTitle.ToString()) { RocsTextService.GetReceiptDateValue(ocr.LineNo); } else if (ocr.ElectedAs == ReceiptParts.VendorTINTitle.ToString()) { RocsTextService.GetReceiptTINValue(ocr); } else if (ocr.ElectedAs == ReceiptParts.PriceTitle.ToString()) { RocsTextService.GetReceiptTotalValue(ocr); } } //last call var year = DateTime.Now.Date.Year; string strYear = year.ToString(); //var y2 ="/" + strYear.Substring(2, 2); var y19 = strYear.Substring(2, 2); if (string.IsNullOrEmpty(Global.CurrentReciept.Date) || !Global.CurrentReciept.Date.Contains(y19)) //|| !Global.CurrentReciept.Date.Contains(strYear) || !Global.CurrentReciept.Date.Contains(y2)) { RocsTextService.GetDateByYear(); } //TOTAL amount if (string.IsNullOrEmpty(Global.CurrentReciept.Amount) || Convert.ToDouble(RocsTextService.RefineToMoney(Global.CurrentReciept.Amount)) > 3000) //|| !Global.CurrentReciept.Date.Contains(strYear) || !Global.CurrentReciept.Date.Contains(y2)) { RocsTextService.GetAmountByDifference(); } table.Add(Global.CurrentReciept); receiptBindingSource.DataSource = table; dgReceipts.DataSource = receiptBindingSource; this.bindingNavigatorReceipts.BindingSource = receiptBindingSource; SetStatus(ProcessStatus.Ready); }