添加项目文件。
This commit is contained in:
115
XXCpzs/Views/PageDaBao.xaml.cs
Normal file
115
XXCpzs/Views/PageDaBao.xaml.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using Plugin.Permissions;
|
||||
using Plugin.Permissions.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using XXCpzs.helper;
|
||||
using XXCpzs.Models;
|
||||
using XXCpzs.ViewModels;
|
||||
using ZXing.Mobile;
|
||||
|
||||
namespace XXCpzs.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class PageDaBao : ContentPage
|
||||
{
|
||||
DabaoViewModel ViewModel;
|
||||
private int BrandId = 0;
|
||||
private int TypeId = 0;
|
||||
private int Uid = 0;
|
||||
private int deviceId = 1;
|
||||
private UserInfo userInfo;
|
||||
|
||||
public PageDaBao(UserInfo userInfo)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Uid = userInfo.uid;
|
||||
this.userInfo = userInfo;
|
||||
this.BindingContext = ViewModel = new DabaoViewModel(Uid);
|
||||
}
|
||||
|
||||
private void TypePicker_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
var picker = (Picker)sender;
|
||||
int selectedIndex = picker.SelectedIndex;
|
||||
if (selectedIndex != -1)
|
||||
{
|
||||
TypeId = ViewModel.dabaoTypes[selectedIndex].id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void BrandPicker_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
var picker = (Picker)sender;
|
||||
int selectedIndex = picker.SelectedIndex;
|
||||
if (selectedIndex != -1)
|
||||
{
|
||||
BrandId = ViewModel.dabaoBrands[selectedIndex].id;
|
||||
}
|
||||
}
|
||||
|
||||
private async void Button_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
if (BrandId != 0 && TypeId != 0 && Uid != 0 && SerialNumber.Text != string.Empty)
|
||||
{
|
||||
Dictionary<string, string> _body = new Dictionary<string, string>{
|
||||
{"Sn", SerialNumber.Text},
|
||||
{"typeId",this.TypeId.ToString() },
|
||||
{"brandId", this.BrandId.ToString() },
|
||||
{"Uid", this.Uid.ToString()},
|
||||
{"deviceId", this.deviceId.ToString()}
|
||||
};
|
||||
var request = await HttpHelper.RequestPost(09, _body);
|
||||
if (request.Code == 200)
|
||||
{
|
||||
ViewModel.Items.Add(new ResultModel() { Code = request.Code, Data = request.Data, Msg = request.Msg });
|
||||
}
|
||||
else
|
||||
{
|
||||
await DisplayAlert("访问出错", request.Msg, "OK");
|
||||
//Button_ClickedAsync(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
private async void OnScan(object sender, EventArgs e)
|
||||
{
|
||||
if (this.BrandId == 0 )
|
||||
{
|
||||
await DisplayAlert("注意","请选择产品供应商", "OK"); return;
|
||||
}
|
||||
|
||||
if ( this.TypeId == 0)
|
||||
{
|
||||
await DisplayAlert("访问出错", "请选择产品名称", "OK"); return;
|
||||
}
|
||||
|
||||
if (await CheckPerssion())
|
||||
{
|
||||
var scanner = new MobileBarcodeScanner();
|
||||
var result = await scanner.Scan();
|
||||
if (result != null)
|
||||
{
|
||||
SerialNumber.Text = result.Text;
|
||||
Button_Clicked(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> CheckPerssion()
|
||||
{
|
||||
var current = CrossPermissions.Current;
|
||||
//检查权限
|
||||
var status = await current.CheckPermissionStatusAsync(Permission.Camera);
|
||||
if (status != PermissionStatus.Granted)
|
||||
{
|
||||
var result = await current.RequestPermissionsAsync(Permission.Camera);
|
||||
status = result[Permission.Camera];
|
||||
}
|
||||
return status == PermissionStatus.Granted;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user