添加项目文件。
This commit is contained in:
252
XXCpzs/Views/PageMain.xaml.cs
Normal file
252
XXCpzs/Views/PageMain.xaml.cs
Normal file
@@ -0,0 +1,252 @@
|
||||
|
||||
using Acr.UserDialogs;
|
||||
using Plugin.Permissions;
|
||||
using Plugin.Permissions.Abstractions;
|
||||
using Rg.Plugins.Popup.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Xamarin.Essentials;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using XXCpzs.helper;
|
||||
using XXCpzs.IOInterface;
|
||||
using XXCpzs.Models;
|
||||
using XXCpzs.Services;
|
||||
using XXCpzs.ViewModels;
|
||||
|
||||
namespace XXCpzs.Views
|
||||
{
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class PageMain : ContentPage, InterfaceLogin
|
||||
{
|
||||
MainViewModel ViewModel;
|
||||
public int companyId;
|
||||
private UserInfo userInfo;
|
||||
|
||||
|
||||
private async System.Threading.Tasks.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;
|
||||
}
|
||||
public PageMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.BindingContext = ViewModel = new MainViewModel();
|
||||
if ( CheckPerssion().Result)
|
||||
{
|
||||
// var networkConnection = DependencyService.Get<INetworkConnection>();
|
||||
// networkConnection.CheckNetworkConnection();
|
||||
// var networkStatus = networkConnection.IsConnected ? "链接" : "未连接";
|
||||
var current = Connectivity.NetworkAccess;
|
||||
|
||||
if (current == NetworkAccess.Internet){
|
||||
// IsConnected = true;
|
||||
//DisplayAlert("Alert", "网络连接成功", "OK");
|
||||
DependencyService.Get<ICommonService>().SendNotity("通知", "网络连接成功");
|
||||
}
|
||||
else{
|
||||
DisplayAlert("Alert", "网络连接失败", "OK");
|
||||
}
|
||||
}
|
||||
Button refresh = new Button
|
||||
{
|
||||
Text = "点击刷新",
|
||||
VerticalOptions = LayoutOptions.CenterAndExpand,
|
||||
HorizontalOptions = LayoutOptions.CenterAndExpand,
|
||||
};
|
||||
|
||||
|
||||
refresh.Clicked += (sender, e) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DependencyService.Get<INetworkConnection>().IsConnected)
|
||||
{
|
||||
Navigation.PushAsync(new MainPage());
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void OnAppearing() {
|
||||
|
||||
base.OnAppearing();
|
||||
UserDialogs.Instance.ShowLoading("加载中");
|
||||
new Thread(new ThreadStart(() =>
|
||||
{
|
||||
var Result = HttpHelper.Refresh<AuthorizeItem>("noun", new Dictionary<string, string>{
|
||||
{ "appid", "98573393804132392" },
|
||||
{ "appkey", "9010137b2c292b39757f94ee434e9d5a" },
|
||||
{ "device", "Droid" }
|
||||
});
|
||||
if (Result.Code == 200)
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
ViewModel.Authorize = Result.Data;
|
||||
ViewModel.CompanyName = ViewModel.Authorize.companyName;
|
||||
companyId = ViewModel.Authorize.companyId;
|
||||
ImageButtonLogin.IsEnabled = true;
|
||||
ImageButtonRegister.IsEnabled = true;
|
||||
string LocaVer = DependencyService.Get<ICommonService>().GetVersion();
|
||||
if (Convert.ToDecimal(ViewModel.Authorize.ServerVer.Version) > Convert.ToDecimal(LocaVer))
|
||||
{
|
||||
bool answer = await DisplayAlert("检测到新的版本", "是否立即更新?" + ViewModel.Authorize.ServerVer.UpContent, "Yes", "No");
|
||||
if (answer)
|
||||
{
|
||||
DependencyService.Get<ICommonService>().UpdateApp(ViewModel.Authorize.ServerVer.UpAddresss);
|
||||
|
||||
}
|
||||
}
|
||||
ITextToSpeechService service = DependencyService.Get<ITextToSpeechService>(DependencyFetchTarget.NewInstance);
|
||||
using (service as IDisposable) {
|
||||
service.SpeakAsync("Welcome to use");
|
||||
}
|
||||
UserDialogs.Instance.HideLoading();
|
||||
});
|
||||
}
|
||||
})).Start();
|
||||
|
||||
}
|
||||
|
||||
//获取权限
|
||||
int r = 0;
|
||||
int c = 0;
|
||||
|
||||
public void Loginback(UserInfo userInfo)
|
||||
{
|
||||
if (userInfo == null)
|
||||
return;
|
||||
r = 0;
|
||||
c = 0;
|
||||
MessagingCenter.Unsubscribe<PageRegister, string>(this, "RegisteResult");
|
||||
Grid121.Children.Clear();
|
||||
this.userInfo = userInfo;
|
||||
ViewModel.Department = this.userInfo.departmentName;
|
||||
ViewModel.UserName = this.userInfo.realname;
|
||||
CpzsPowers cpzsPowers = this.userInfo.CpzsPowers;
|
||||
//{"uid":1,"cx":1,"db":1,"rc":1,"cc":1,"xs":1,"fx":1,"hh":1,"th":1,"rs":1,"
|
||||
if (cpzsPowers.cx == 1)
|
||||
AddImageButton("cx");
|
||||
if (cpzsPowers.kh == 1)
|
||||
AddImageButton("kh");
|
||||
if (cpzsPowers.dd == 1)
|
||||
AddImageButton("dd");
|
||||
if (cpzsPowers.db == 1)
|
||||
AddImageButton("db");
|
||||
if (cpzsPowers.rc == 1)
|
||||
AddImageButton("rc");
|
||||
if (cpzsPowers.cc == 1)
|
||||
AddImageButton("cc");
|
||||
if (cpzsPowers.xs == 1)
|
||||
AddImageButton("xs");
|
||||
if (cpzsPowers.rs == 1)
|
||||
AddImageButton("rs");
|
||||
if (cpzsPowers.fx == 1)
|
||||
AddImageButton("fx");
|
||||
if (cpzsPowers.hh == 1)
|
||||
AddImageButton("hh");
|
||||
if (cpzsPowers.th == 1)
|
||||
AddImageButton("th");
|
||||
ImageButton imageButton = new ImageButton
|
||||
{
|
||||
Aspect = Aspect.AspectFit,
|
||||
};
|
||||
Grid121.Children.Add(imageButton);
|
||||
Grid.SetRow(imageButton, 3);
|
||||
Grid.SetColumn(imageButton, 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void AddImageButton(string fun)
|
||||
{
|
||||
ImageButton imageButton = new ImageButton
|
||||
{
|
||||
Aspect = Aspect.AspectFit,
|
||||
};
|
||||
switch (fun)
|
||||
{
|
||||
case "dd":
|
||||
imageButton.Source = "ico_order.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageOrder(userInfo)); };
|
||||
break;
|
||||
case "kh":
|
||||
imageButton.Source = "ico_customer.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageCustomer(userInfo)); };
|
||||
break;
|
||||
case "cx":
|
||||
imageButton.Source = "ico_search.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageChaXun(userInfo)); };
|
||||
break;
|
||||
case "db":
|
||||
imageButton.Source = "ico_pack.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageDaBao(userInfo)); };
|
||||
break;
|
||||
case "rc":
|
||||
imageButton.Source = "ico_cangku.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageRuCang(userInfo)); };
|
||||
break;
|
||||
case "cc":
|
||||
imageButton.Source = "ico_chucang.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageChuCang(userInfo)); };
|
||||
break;
|
||||
case "xs":
|
||||
imageButton.Source = "ico_sale.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageSale(userInfo)); };
|
||||
break;
|
||||
case "rs":
|
||||
imageButton.Source = "ico_resale.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageResale(userInfo)); };
|
||||
break;
|
||||
case "fx":
|
||||
imageButton.Source = "ico_weixiu.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageFanXiu(userInfo)); };
|
||||
break;
|
||||
case "hh":
|
||||
imageButton.Source = "ico_hh.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageHuanHuo(userInfo)); };
|
||||
break;
|
||||
case "th":
|
||||
imageButton.Source = "ico_th.png";
|
||||
imageButton.Clicked += async (s, args) => { await Navigation.PushAsync(new PageTuiHuo(userInfo)); };
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Grid121.Children.Add(imageButton);
|
||||
Grid.SetRow(imageButton, r);
|
||||
Grid.SetColumn(imageButton, c);
|
||||
if (c < 2) { c++; }
|
||||
else { c = 0; r++; }
|
||||
|
||||
}
|
||||
public async void ImageButtonLogin_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
await PopupNavigation.Instance.PushAsync(new PageLogin(this));
|
||||
}
|
||||
private async void ImageButtonRegister_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
await PopupNavigation.Instance.PushAsync(new PageRegister(this));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public delegate void ChangeLoadingClosd();
|
||||
}
|
||||
Reference in New Issue
Block a user