該專案由兩部分組成,第一部分是 xaml 頁面設計,其中包括 2 個按鈕,第一個按鈕用于 QR 掃描儀,第二個按鈕截取整個表單并將其保存到我的本地圖庫中,這個不是我將使用的實際設計,但我必須使用滾動視圖并重新調整設計,以使其在我的手機上作業并使 QR 掃描按鈕可見,以便能夠單擊它并對其進行測驗。
這是我的 Xamarin Forms xaml 頁面代碼的預覽:
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:forms="clr-namespace:SignaturePad.Forms;assembly=SignaturePad.Forms"
xmlns:local="clr-namespace:SignatureSample"
xmlns:effects="clr-namespace:PlainEntryAndroidSample.Effects" xmlns:effects1="clr-namespace:QRTest3.Effects"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="QRTest3.NewPage">
<ContentPage.Content >
<ScrollView>
<StackLayout BackgroundColor="White" Padding="10">
<StackLayout>
<Label Text="Tel: 00 961 44434445/6/7"
FontSize="12"
TextColor="Black"/>
<Label x:Name="x2" />
<Label x:Name="x3" />
<Label x:Name="x4" />
<Label Text="Fax: 00 961 4437 2041"
FontSize="12"
TextColor="Black"/>
<Label Text="P.O. Box 4694"
FontSize="12"
TextColor="Black"/>
</StackLayout>
<Label Text="Delivery Note"
FontSize="19"
TextColor="Black"
FontAttributes="Bold" />
<Image x:Name="logo1" Source="companylogo" HorizontalOptions="Start" Margin="550,-100,0,0" HeightRequest="108" WidthRequest="115"/>
<StackLayout>
<Label Text="Truck plate number: "
TextColor="Black"
x:Name="x5"
/>
<Label Text="Contract number: "
TextColor="Black"
x:Name="x6"
/>
<Label Text="Driver name: "
TextColor="Black"
x:Name="x7"
/>
<Button Text="Scan your QR code 󰐲 "
FontSize="12.5"
Margin="10,30,10,30"
FontFamily="MYICON"
Clicked="Button_Clicked"
CornerRadius="0"
BorderColor="Black"
BorderWidth="1"
Padding="0,0,0,0"
HorizontalOptions="Start"
BackgroundColor="#80BFE4"
WidthRequest="130"
HeightRequest="50"
TextColor="Black"
FontAttributes="None" />
<Entry x:Name="x1" Margin="300,-30,200,0" FontSize="15" HorizontalTextAlignment="Center" Placeholder="">
<Entry.Effects>
<effects1:PlainEntry/>
</Entry.Effects>
</Entry>
</StackLayout>
<Entry x:Name="x8" />
<Entry x:Name="x9" />
<Entry x:Name="x10" />
<Entry x:Name="x11" />
<Entry x:Name="x12" />
<Entry x:Name="x13" />
<Entry x:Name="x14" />
<Entry x:Name="x15" />
<Entry x:Name="x16" />
<Entry x:Name="x17" />
<Entry x:Name="x18" />
<Entry x:Name="x19" />
<Entry x:Name="x20" />
<Entry x:Name="x21" />
<Entry x:Name="x22" />
<Entry x:Name="x23" />
<Entry x:Name="x24" />
<Entry x:Name="x25" />
<Entry x:Name="x26" />
<Entry x:Name="x27" />
<Button Text="Document filled"
FontSize="12.5"
Margin="0"
HorizontalOptions="Center"
FontFamily="MYICON"
BorderColor="Black"
Padding="0"
BorderWidth="1"
BackgroundColor="White"
WidthRequest="120"
HeightRequest="23"
CornerRadius="0"
Clicked="DoPDFThings"
TextColor="Black"
FontAttributes="Bold"/>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
這是我正在使用的 C# 代碼,這不是我的,這就是我遇到問題的原因,我只是在進行設計,但我收到了這段代碼,并且預計它可以作業。它僅適用于掃描 QR 碼并顯示其資訊,我知道這是因為 DisplayAlert 但我遇到的唯一問題是代碼沒有將掃描的文本放入相應的條目中。
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using ZXing.Net.Mobile.Forms;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Grid;
using System.IO;
using System.Drawing;
using System.Collections.ObjectModel;
using Plugin.XamarinFormsSaveOpenPDFPackage;
using System.Net.Http;
using Xamarin.Essentials;
using NativeMedia;
using ImageFromXamarinUI;
namespace QRTest3
{
public partial class NewPage : ContentPage
{
public NewPage()
{
InitializeComponent();
x1.Text = "";
x2.Text = "Loading time: " "";
x3.Text = "Delivery time: " "";
x4.Text = "Incoterm: " "";
x5.Text = "Truck plate number: " "";
x6.Text = "Contract number: " "";
x7.Text = "Driver name: " "";
x8.Text = "Ship To: " "";
x9.Text = "";
x10.Text = "";
x11.Text = "";
x12.Text = "Bill To: " "";
x13.Text = "";
x14.Text = "";
x15.Text = "";
x16.Text = "Sold To " "";
x17.Text = "";
x18.Text = "";
x19.Text = "";
x20.Text = "" "";
x21.Text = "";
x22.Text = "";
x23.Text = "";
x24.Text = "" "";
x25.Text = "";
x26.Text = "Remark: " "";
}
async void Button_Clicked(System.Object sender, System.EventArgs e) // was private (Scan button)
{
var scan = new ZXingScannerPage();
await Navigation.PushModalAsync(scan); //PushModalAsync presents a page modally, with optional animation. (presents the scanner cam)
scan.OnScanResult = (result) =>
{
Device.BeginInvokeOnMainThread(async () => //An async method runs synchronously until it reaches its first await expression, at which point the method is suspended until the awaited task is complete.
{ //BeginInvokeOnMainThread checks if the current thread is the main thread, and if so, it invokes the action immediately
await Navigation.PopModalAsync(); //Asynchronously dismisses the most recent modally presented Page, with optional animation. (removes scanner after scanning qr code)
await DisplayAlert("Valeur QRCODE", "" result.Text, "OK");
//txtinput.Text = result.Text;
string xd;
/* // xd the QR code ........................
xd = "301232189;" //x1
"5/12/2022 08:05:32;" //x2
"5/12/2022 08:05:32;" //x3
"EXW;" //x4
"161410;" //x5
"000123892;" //x6
"ISAKA KISKOUSJ;" //x7
"0112398901;" //x8
"ISMET READY MIX;" //x9
"STREET TANOUS A L ACHKAR;" //x10
"DOHA QA;" //x11
"0112398901;" //x12
"ISMET READY MIX;" //x13
"STREET TANOUS A L ACHKAR;" //x14
"DOHA QA;" //x15
"0112398901;" //x16
"ISMET READY MIX;" //x17
"STREET TANOUS A L ACHKAR;" //x18
"DOHA QA;" //x19
"14000256;" //x20
"GBFS BULK;" //x21
"16.28;" //x22
"41.17;" //x23
"30.18;" //x24
"t;" //x25
"10"; //x26 // read by QR CODE ...... */
xd = result.Text;
string[] words = xd.Split(';');
string x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27;
x1 = "";
x2 = "";
x3 = "";
x4 = "";
x5 = "";
x6 = "";
x7 = "";
x8 = "";
x9 = "";
x10 = "";
x11 = "";
x12 = "";
x13 = "";
x14 = "";
x15 = "";
x16 = "";
x17 = "";
x18 = "";
x19 = "";
x20 = "";
x21 = "";
x22 = "";
x23 = "";
x24 = "";
x25 = "";
x26 = "";
x27 = "";
int i = 1;
foreach (var word in words)
{
// await DisplayAlert("NRSOFTWARE", word , "OK"); ;
if (i == 1) x1 = word;
if (i == 2) x2 = word;
if (i == 3) x3 = word;
if (i == 4) x4 = word;
if (i == 5) x5 = word;
if (i == 6) x6 = word;
if (i == 7) x7 = word;
if (i == 8) x8 = word;
if (i == 9) x9 = word;
if (i == 10) x10 = word;
if (i == 11) x11 = word;
if (i == 12) x12 = word;
if (i == 13) x13 = word;
if (i == 14) x14 = word;
if (i == 15) x15 = word;
if (i == 16) x16 = word;
if (i == 17) x17 = word;
if (i == 18) x18 = word;
if (i == 19) x19 = word;
if (i == 20) x20 = word;
if (i == 21) x21 = word;
if (i == 22) x22 = word;
if (i == 23) x23 = word;
if (i == 24) x24 = word;
if (i == 25) x25 = word;
if (i == 26) x26 = word;
if (i == 27) x27 = word;
i = 1;
}
xd = result.Text;
await DisplayAlert("Valeur QRCODE", "" x1, "OK");
});
};
}
private async void DoPDFThings(object sender, EventArgs e)
{
var screenshot = await Screenshot.CaptureAsync(); // working 100% for partial sc: was var imageStream = await header.CaptureImageAsync();
// working 100% for partial sc: await MediaGallery.SaveAsync(MediaFileType.Image, imageStream, "myScreenshot.png");
// var screenshot = await Screenshot.CaptureAsync();
await MediaGallery.SaveAsync(MediaFileType.Image, await screenshot.OpenReadAsync(), "myScreenshot.png");
}
}
}
uj5u.com熱心網友回復:
我看過你的代碼,發現你只是在構造方法中設定了一次Entry.Text。當您單擊按鈕并獲得掃描儀結果時,您沒有更新條目和標簽的文本值。
所以可以嘗試改一下foreach中的代碼,比如:
foreach (var word in words)
{
// await DisplayAlert("NRSOFTWARE", word , "OK"); ;
if (i == 1) x1.Text = word;
if (i == 2) x2.Text = word;
......
i = 1;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/483549.html
