public DeviceManagerViewModel(BanKiemKe banKiemKe) { this.kiemke = DataProvider.GetKiemKe(banKiemKe); LoadData(); DeleteCommand = new Command <CTBKKItem>(Delete); XacNhanKKCommand = new Command(XacNhanKK); }
public async void ShowList(BanKiemKe banKiemKe) { using (Acr.UserDialogs.UserDialogs.Instance.Loading("Loading..")) { var DeviceManager = new DeviceManagerView(); var VM = new DeviceManagerViewModel(banKiemKe); DeviceManager.BindingContext = VM; await App.Current.MainPage.Navigation.PushAsync(DeviceManager); } }
public static void RemoveKiemKeByBKK(BanKiemKe deletedBKK) { foreach (KiemKe kiemke in LocalData.KiemKes) { if (kiemke.BKK.KK_CODE == deletedBKK.KK_CODE && kiemke.BKK.KK_MADONVI == deletedBKK.KK_MADONVI && DataProvider.CheckSameDate(kiemke.BKK.KK_NGAYTAO, deletedBKK.KK_NGAYTAO)) { LocalData.KiemKes.Remove(kiemke); return; } } }
public static void UpdateRecordInKiemKeInLocalData(KiemKe kiemke) { foreach (KiemKe item in LocalData.KiemKes) { BanKiemKe banKiemKe1 = item.BKK; BanKiemKe banKiemKe2 = kiemke.BKK; if (banKiemKe1.KK_CODE == banKiemKe2.KK_CODE && banKiemKe1.KK_MADONVI == banKiemKe2.KK_MADONVI && DataProvider.CheckSameDate(banKiemKe1.KK_NGAYTAO, banKiemKe2.KK_NGAYTAO)) { item.RECORDS = kiemke.RECORDS; break; } } }
public static void UpdateKiemKeInLocalData() { foreach (KiemKe kiemke in LocalData.KiemKes) { BanKiemKe banKiemKe1 = kiemke.BKK; BanKiemKe banKiemKe2 = AppValue.kiemKe.BKK; if (banKiemKe1.KK_CODE == banKiemKe2.KK_CODE && banKiemKe1.KK_MADONVI == banKiemKe2.KK_MADONVI && DataProvider.CheckSameDate(banKiemKe1.KK_NGAYTAO, banKiemKe2.KK_NGAYTAO)) { kiemke.RECORDS = AppValue.kiemKe.RECORDS; break; } } }
public static KiemKe GetKiemKe(BanKiemKe banKiemKe) { if (LocalData.KiemKes == null) { return(null); } foreach (KiemKe kiemKe in LocalData.KiemKes) { if (kiemKe.BKK.KK_CODE == banKiemKe.KK_CODE && kiemKe.BKK.KK_MADONVI == banKiemKe.KK_MADONVI && CheckSameDate(kiemKe.BKK.KK_NGAYTAO, banKiemKe.KK_NGAYTAO)) { return(kiemKe); } } return(null); }
public async void Delete(BanKiemKe deletedBKK) { //Update data ở LocalData DataUpdater.RemoveKiemKeByBKK(deletedBKK); // Update data ở UI LoadData(); //Update data xuống file DataUpdater.UpdateDataToFile(); DependencyService.Get <IMessage>().Shorttime("Xóa thành công"); //Nếu không còn item nào thì thoát if (BanKiemKes.Count == 0) { await App.Current.MainPage.Navigation.PopAsync(); } }
public async void LoginDirectly() { string BrandId = Preferences.Get("BranchId", string.Empty); using (UserDialogs.Instance.Loading("Loading..")) { //get list bkk List <BanKiemKe> banKiemKes = new List <BanKiemKe>(); try { var httpClient = new HttpClient(); var response = await httpClient.PostAsJsonAsync(Definitions.Localhost + "api/KiemKe/GetKiemKeDateAndCode?branch_ID=" + BrandId, new { }); var content = await response.Content.ReadAsStringAsync(); JObject rss = JObject.Parse(content); var resultAPI = rss["result"]; JArray arr = (resultAPI as JArray); foreach (var elem in arr) { DateTime date = DateTime.ParseExact(elem["KK_DATE"].ToString(), "yyyy/MM/dd", null); BanKiemKe newBKK = new BanKiemKe { KK_CODE = elem["KK_CODE"].ToString(), KK_NGAYTAO = date, KK_MADONVI = BrandId }; banKiemKes.Add(newBKK); } AppValue.banKiemKes = banKiemKes; } catch { await App.Current.MainPage.DisplayAlert("Lỗi", "Kết nối server bị lỗi, kiểm tra lại đường dẫn!", "OK"); return; } App.Current.MainPage = new NavigationPage(new StartUpView()); } }
private async void Confirm_Clicked(object sender, EventArgs e) { var httpClient = new HttpClient(); using (Acr.UserDialogs.UserDialogs.Instance.Loading("Updating..")) { if (AppValue.KKType == 1) //ONLINE { BanKiemKe banKiemKe = AppValue.banKiemKe; try { HttpResponseMessage response; if (!string.IsNullOrEmpty(thietBi.TB_ID)) { response = await httpClient.PostAsJsonAsync(Definitions.Localhost + "api/ChiTietBanKiemKe/CTBKK_XacNhanKK?dv_QL=" + banKiemKe.KK_MADONVI + "&bkk_ID=" + banKiemKe.KK_CODE + "&ngay_TAO=" + banKiemKe.KK_NGAYTAO.ToString("yyyy-MM-dd") + "&ma_TB=" + this.thietBi.TB_ID + "&tt_SAU=" + State_Picker.SelectedItem.ToString(), new { }); } else { response = await httpClient.PostAsJsonAsync(Definitions.Localhost + "api/ChiTietBanKiemKe/CTBKK_XacNhanKK_Ten?dv_QL=" + banKiemKe.KK_MADONVI + "&bkk_ID=" + banKiemKe.KK_CODE + "&ngay_TAO=" + banKiemKe.KK_NGAYTAO.ToString("yyyy-MM-dd") + "&ten_TB=" + this.thietBi.TB_TEN + "&tt_SAU=" + State_Picker.SelectedItem.ToString(), new { }); } var content = await response.Content.ReadAsStringAsync(); JObject rss = JObject.Parse(content); var resultAPI = rss["result"]; string validStr = (resultAPI as JArray).First["result"].ToString(); if (validStr == "Lỗi" || validStr == "Bản kiểm kê ko tồn tại") { await DisplayAlert("Lỗi", "Kiểm kê thất bại, kiểm tra lại thông tin kiểm kê!", "OK"); return; } } catch { await DisplayAlert("Lỗi", "Kết nối server bị lỗi, kiểm tra lại đường dẫn!", "OK"); return; } } else //OFFLINE { using (UserDialogs.Instance.Loading("Updating..")) { //tạo record mới ChiTietBanKiemKe chiTietBanKiemKe = new ChiTietBanKiemKe { CTBKK_MA_TB = thietBi.TB_ID, CTBKK_TEN_TB = thietBi.TB_TEN, CTBKK_TT_SAU = State_Picker.SelectedItem.ToString(), CTBKK_THOI_GIAN = DateTime.Now }; //thêm record vào list (trên source) appvalue DataUpdater.AddNewRecordToKiemKe(chiTietBanKiemKe); //update record vào LocalData(trên source) DataUpdater.UpdateKiemKeInLocalData(); //update data xuống file DataUpdater.UpdateDataToFile(); } } var scanPage = ScannerView.GetInstance(); scanPage.popupIsOpen = false; await App.Current.MainPage.Navigation.PopAsync(); } var message = "Kiểm kê thành công"; DependencyService.Get <IMessage>().Shorttime(message); }
public async void Scan() { try { FileService.CreateFileData(); } catch { await NavigationService.GetTopPage().DisplayAlert("Lỗi", "App chưa được quyền truy cập dữ liệu trong máy", "OK"); return; } BanKiemKe banKiemKe = new BanKiemKe(); foreach (BanKiemKe item in AppValue.banKiemKes) { if (CurrentBKK == item.KK_CODE) { banKiemKe = item; break; } } AppValue.banKiemKe = banKiemKe; if (Choose1) //online { AppValue.KKType = 1; } else //offline { AppValue.KKType = 2; } using (Acr.UserDialogs.UserDialogs.Instance.Loading("Loading..")) { if (Choose1) //KK ONLINE { } else //KK OFFLINE { //LẤY RA KIEMKE TRONG LOCAL DATA KiemKe kiemke = DataProvider.GetKiemKe(banKiemKe); if (kiemke == null) { kiemke = new KiemKe { BKK = banKiemKe, RECORDS = new List <ChiTietBanKiemKe>() }; LocalData.KiemKes.Add(kiemke); } //Lưu lại thông tin kiểm kê hiện tại AppValue.kiemKe = kiemke; } //chuyển sang page quét mã var scanPage = ScannerView.GetInstance(); scanPage.SetBKKInfor(); await App.Current.MainPage.Navigation.PushAsync(scanPage); } }
public async void Login() { Error = ""; string errMessage = CheckValidInfor(); if (!string.IsNullOrEmpty(errMessage)) { Error = errMessage; return; } using (UserDialogs.Instance.Loading("Logging..")) { //CALL API LOGIN JToken token; try { //[email protected] //123qwe var httpClient = new HttpClient(); var response = await httpClient.PostAsJsonAsync(Definitions.Localhost + "api/TokenAuth/Authenticate", new { userNameOrEmailAddress = Username, password = Password, twoFactorVerificationCode = "", rememberClient = false, twoFactorRememberClientToken = "", singleSignIn = false, returnUrl = "" }); var content = await response.Content.ReadAsStringAsync(); JObject rss = JObject.Parse(content); var resultAPI = rss["result"]; if (string.IsNullOrEmpty(resultAPI.ToString())) { await NavigationService.GetTopPage().DisplayAlert("Lỗi", "Thông tin Tài khoản hoặc mật khẩu không đúng, vui lòng kiểm tra lại!", "OK"); return; } token = resultAPI; } catch (Exception ex) { await App.Current.MainPage.DisplayAlert("Lỗi", "Kết nối server bị lỗi, kiểm tra lại đường dẫn!", "OK"); return; } //lấy ra branchID từ userId string UserID = token["userId"].ToString(); string BranchID; try { var httpClient = new HttpClient(); var response = await httpClient.PostAsJsonAsync(Definitions.Localhost + "api/KiemKe/GetBranchIdFromUserId?id=" + UserID, new { }); var content = await response.Content.ReadAsStringAsync(); JObject rss = JObject.Parse(content); var resultAPI = rss["result"]; BranchID = (resultAPI as JArray).First.ToString(); } catch { await App.Current.MainPage.DisplayAlert("Lỗi", "Kết nối server bị lỗi, kiểm tra lại đường dẫn!", "OK"); return; } //get list bkk List <BanKiemKe> banKiemKes = new List <BanKiemKe>(); try { var httpClient = new HttpClient(); var response = await httpClient.PostAsJsonAsync(Definitions.Localhost + "api/KiemKe/GetKiemKeDateAndCode?branch_ID=" + BranchID, new { }); var content = await response.Content.ReadAsStringAsync(); JObject rss = JObject.Parse(content); var resultAPI = rss["result"]; JArray arr = (resultAPI as JArray); foreach (var elem in arr) { DateTime date = DateTime.ParseExact(elem["KK_DATE"].ToString(), "yyyy/MM/dd", null); BanKiemKe newBKK = new BanKiemKe { KK_CODE = elem["KK_CODE"].ToString(), KK_NGAYTAO = date, KK_MADONVI = BranchID }; banKiemKes.Add(newBKK); } AppValue.banKiemKes = banKiemKes; } catch { await App.Current.MainPage.DisplayAlert("Lỗi", "Kết nối server bị lỗi, kiểm tra lại đường dẫn!", "OK"); return; } //KHI ĐÃ LOGIN THÀNH CÔNG //set giá trị login Preferences.Set("UsernameLogin", Username); Preferences.Set("PasswordLogin", Password); Preferences.Set("UserId", UserID); Preferences.Set("BranchId", BranchID); Preferences.Set("IsLogining", true); if (Remember) { Preferences.Set("Username", Username); Preferences.Set("Password", Password); Preferences.Set("Remember", true); } else { Preferences.Set("Username", ""); Preferences.Set("Password", ""); Preferences.Set("Remember", false); } App.Current.MainPage = new NavigationPage(new StartUpView()); } }
public async void XacNhanKK() { List <string> maTBs = new List <string>(); //xác nhận kk server BanKiemKe BKK = kiemke.BKK; using (UserDialogs.Instance.Loading("Updating..")) { try { //ChiTietBanKiemKe ct3 = new ChiTietBanKiemKe() //{ // CTBKK_MA_TB = "COD_00ghfg10", // CTBKK_TEN_TB = "i.CTBKK_TEN_TB", // CTBKK_TT_SAU = "Hư hỏng", // CTBKK_THOI_GIAN=DateTime.Now //}; // public string DONVI_ID { get; set; } //public string BKK_CODE { get; set; } //public DateTime NGAY_TAO { get; set; } //public string LISTTB { get; set; } var listRecordStr = JsonConvert.SerializeObject(kiemke.RECORDS); var x = new { DONVI_ID = BKK.KK_MADONVI, BKK_CODE = BKK.KK_CODE, NGAY_TAO = BKK.KK_NGAYTAO, LISTTB = listRecordStr }; //List<ChiTietBanKiemKe> lst = DataProvider.CloneRecordsFromKiemKe(kiemke); var httpClient = new HttpClient(); var response = await httpClient.PostAsJsonAsync(Definitions.Localhost + "api/KiemKe/KiemKeOfflineProcess", x); var content = await response.Content.ReadAsStringAsync(); JObject rss = JObject.Parse(content); var validStr = rss["result"].ToString(); //string validStr = (resultAPI as JArray).First["result"]; if (validStr == "Bản kiểm kê ko tồn tại") { await NavigationService.GetTopPage().DisplayAlert("Lỗi", "Bản kiểm kê ko tồn tại!", "OK"); return; } string[] parts = validStr.Split('|'); if (parts[1] == "") { } else// trả về mã các thiết bị kk sai { string list = parts[1].Substring(0, parts[1].Length - 1); maTBs = list.Split('#').ToList(); } } catch { await NavigationService.GetTopPage().DisplayAlert("Lỗi", "Kết nối server bị lỗi, kiểm tra lại đường dẫn!", "OK"); return; } //update data on view List <ChiTietBanKiemKe> wrongRecords = new List <ChiTietBanKiemKe>(); foreach (string ma in maTBs) { foreach (ChiTietBanKiemKe item in kiemke.RECORDS) { if (item.CTBKK_MA_TB == ma) { wrongRecords.Add(item); break; } } } kiemke.RECORDS = wrongRecords; LoadData(); //update data source DataUpdater.UpdateRecordInKiemKeInLocalData(kiemke); //update data file DataUpdater.UpdateDataToFile(); } DependencyService.Get <IMessage>().Shorttime("Kiểm kê thành công"); if (Records.Count == 0) { DataUpdater.RemoveEmptyKiemKe(); if (DataProvider.GetListBKK().Count == 0) { await App.Current.MainPage.Navigation.PopToRootAsync(); return; } var VM = ListBKKView.GetInstance().BindingContext as ListBKKViewModel; VM.LoadData(); await App.Current.MainPage.Navigation.PopAsync(); } }