private void AddAssetData(int department_) { try { var AssetCategory = Database.Category.GetTableData(_connection).First().AssetCategoryIDInternal; var AssetUsage = Database.Usage.GetTableData(_connection).First().UsageID; var AssetCondition = Database.Condition.GetTableData(_connection).First().ConditionID; var time = DateTime.Now; var newAsset = new AssetJsonObject { DateModified = time, SubLocation = _Sublocation, AssetName = "RECON-Added Asset", AssetDescription = "Asset created during audit.", Barcode = AuditSearchBar.Text, AssetIDInternal = GUID.Generate(), AssetCategoryIDInternal = AssetCategory, LocationIDInternal = _LocationID, SiteIDInternal = _SiteID, PeopleIDInternal = "00000000-0000-0000-0000-000000000000", AssetUsageID = AssetUsage, AssetConditionID = AssetCondition, AssetStatus = "", AssetSerialNo = "", Price = 0, PurchaseDate = Convert.ToDateTime("1/1/1900"), PurchaseOrderNo = "", Quantity = 1, ShortageOverage = 1, Vendor = "", IsActive = true, AuditDate = time, AuditStatus = "RECON-Added", Asset_UID = "", DataGatherID = department_, Mfg = "", Model = "", POLine = 0, POStatus = "N", OriginalPartNo = "", ThumbnailImage = "", }; Application.Current.Properties["LastAssetID"] = newAsset.AssetIDInternal; AssetClass asset = new AssetClass(newAsset); ///make into databse format var AssetForDb = AssetClass.AssetClassToDb(asset, false); //save to database Database.Assets.Insert(_connection, AssetForDb); LoadSound(1); //DisplayAlert("Complete", "Asset Audited", "OK"); LoadAssetData(); } catch (Exception exc) { DependencyService.Get <IError>().SendRaygunError(exc, Application.Current.Properties["user"].ToString() ?? "unsynced", Application.Current.Properties["url"].ToString() ?? "unsynced", null); DisplayAlert("Error", exc.Message, "OK"); } }
private async void AuditListView_ItemTapped(object sender, ItemTappedEventArgs e) { if (_Auditing) { //Get asset class var asset_class = e.Item as AssetClass; //convert class to DB var asset = AssetClass.AssetClassToDb(asset_class, asset_class.Synced); if (_PersonID != null) { await Navigation.PushModalAsync(new AuditRecordPage(_Names, asset, _Site, _Location, _Sublocation, _Department, _connection, _PersonID)); } else { var SettingsData = Database.Settings.GetTableData(_connection); if (SettingsData.FastAudit && !SettingsData.FastAuditEntry) { try { var _assetclass = AssetClass.DbToAssetClass(new List <AssetDbClass> { asset }, _Names).First(); AuditClass.Audit(_Site, _Location, _Sublocation, _Department, _assetclass, _connection); Application.Current.Properties["AuditedSite"] = _Site; Application.Current.Properties["AuditedLocation"] = _Location; Application.Current.Properties["AuditedSublocation"] = _Sublocation; Application.Current.Properties["LastAssetID"] = _assetclass.AssetIdInternal; Application.Current.Properties["Department"] = _Department; await Application.Current.SavePropertiesAsync(); await DisplayAlert("Complete", "Asset Audited", "OK"); await Navigation.PopAsync(); } catch (Exception exc) { DependencyService.Get <IError>().SendRaygunError(exc, Application.Current.Properties["user"].ToString() ?? "unsynced", Application.Current.Properties["url"].ToString() ?? "unsynced", asset_class); await DisplayAlert("Error", exc.Message, "OK"); } } else { await Navigation.PushModalAsync(new AuditRecordPage(_Names, asset, _Site, _Location, _Sublocation, _Department, _connection)); } } } }
private async void Update(object sender, EventArgs e) { try { bool quantityUsed = true; bool costUsed = true; bool updated = false; if (quantity_.Text == null) { quantityUsed = false; } if (price_.Text == null) { costUsed = false; } if (quantityUsed && int.TryParse(quantity_.Text, out var n)) { //quantity is being used and is a valid number _Asset.Quantity = _Asset.Quantity + n; updated = true; //add n to quantity } if (costUsed && double.TryParse(price_.Text, out var o)) { _Asset.Price = o; updated = true; } if (updated) { updated = false; var assetDetailsold = Database.Assets.GetAssetDataByAssetIDInternal(_connection, _Asset.AssetIDInternal); var assetRecord = Database.Assets.Compare(assetDetailsold.First(), _Asset); if (assetRecord.ChangesMade.Count < 1) { await DisplayAlert("Error", "Nothing was changed in this asset.", "OK"); } else { var time = DateTime.Now; assetRecord.AssetJSON.DateModified = time; //Convert to be stored var AssetForDb = AssetClass.AssetClassToDb(assetRecord, assetDetailsold.First().Synced); //store to the database Database.Assets.Update(_connection, AssetForDb); // Update Record on List var display = Database.Assets.GetDisplayeDataByAssetIDInternal(_connection, AssetForDb.AssetIdInternal); display.First().Quantity = _Asset.Quantity; display.First().Cost = _Asset.Price; var __ = new List <AssetDisplayClass>() { AssetDisplayClass.FullDetails(display.First(), _Names) }; scanbarcodeupdateasset.ItemsSource = __; await DisplayAlert("Complete", "Asset Updated", "OK"); } } else { await DisplayAlert("Error", "There is no data to update.", "OK"); } } catch (Exception exe) { DependencyService.Get <IError>().SendRaygunError(exe, Application.Current.Properties["user"].ToString() ?? "unsynced", Application.Current.Properties["url"].ToString() ?? "unsynced", null); await DisplayAlert("Error", exe.Message, "OK"); } }
private async void Button_Clicked_1(object sender, EventArgs e) { try { if (CheckValues()) { LocationClass LocationInfo = new LocationClass(); string _LocationID = "00000000-0000-0000-0000-00000000"; string _Sublocation = null; int _Department = 0; string desc = "Asset created during audit. "; string siteName = assetSite_.Items[assetSite_.SelectedIndex]; string _SiteID = SitesClass.DbToSite(Database.Sites.GetTableData(_connection), _connection).First(cm => cm.SiteName == siteName).SiteIdInternal; //gets location id internal if (assetLocation_.SelectedIndex >= 0) { _LocationID = GUID.Generate().Substring(0, 7); if (assetLocation_.SelectedIndex == 0) { if (MissingLoc.Text == null) { MissingLoc.Text = "Location added without name"; } Database.Locations.Insert(_connection, new LocationsDbTable { LocationBarcode = "Added " + _Names.Location, LocationDescription = "Added " + _Names.Location, LocationIdInternal = _LocationID, LocationName = MissingLoc.Text, SiteIdInternal = _SiteID, }); desc = desc + MissingLoc.Text; } else { string locationName = assetLocation_.Items[assetLocation_.SelectedIndex]; _LocationID = LocationClass.DbToLocation(Database.Locations.GetTableDataFromSites(_connection, _siteID), _connection).First(cm => cm.LocationName == locationName).LocationIdInternal; } } if (assetSubLocation_.SelectedIndex == -1) { _Sublocation = null; } else { _Sublocation = assetSubLocation_.Items[assetSubLocation_.SelectedIndex]; } if (assetDepartment_.SelectedIndex >= 0) { string departmentName = assetDepartment_.Items[assetDepartment_.SelectedIndex]; _Department = DepartmentClass.DbToDepartment(Database.Department.GetTableData(_connection)).First(cm => cm.DepartmentName == departmentName).ID; } //gets condition ConditionClass conditionInfo = new ConditionClass(); if (assetCondition_.SelectedIndex >= 0) { string conditionName = assetCondition_.Items[assetCondition_.SelectedIndex]; conditionInfo = ConditionClass.DbToCondition(Database.Condition.GetTableData(_connection), _connection).First(cm => cm.ConditionLabel == conditionName); } //gets usages UsageClass UsageInfo = new UsageClass(); if (assetUsage_.SelectedIndex >= 0) { string usageName = assetUsage_.Items[assetUsage_.SelectedIndex]; UsageInfo = UsageClass.DbToUsage(Database.Usage.GetTableData(_connection), _connection).First(cm => cm.UsageLabel == usageName); } string defcategory = Database.Category.GetTableData(_connection).First().AssetCategoryIDInternal; AssetJsonObject newAsset = new AssetJsonObject { SiteIDInternal = _SiteID, LocationIDInternal = _LocationID, SubLocation = _Sublocation, DataGatherID = _Department, AssetIDInternal = GUID.Generate(), IsActive = true, DateModified = DateTime.Now, AuditDate = DateTime.Now, AuditStatus = "RECON-Added", AssetName = "RECON-Added Asset", AssetDescription = desc, Barcode = assetBarcode_.Text, PeopleIDInternal = "00000000-0000-0000-0000-000000000000", AssetStatus = "", AssetSerialNo = "", Price = 0, PurchaseDate = Convert.ToDateTime("1/1/1900"), PurchaseOrderNo = "", Quantity = 1, ShortageOverage = 1, Vendor = "", Asset_UID = "", ThumbnailImage = "", OriginalPartNo = "", POStatus = "N", POLine = 0, Model = "", Mfg = "", AssetConditionID = conditionInfo.ConditionID, AssetUsageID = UsageInfo.UsageID, AssetCategoryIDInternal = defcategory }; //make into class AssetClass asset = new AssetClass(newAsset); ///make into databse format var AssetForDb = AssetClass.AssetClassToDb(asset, false); //save to database Database.Assets.Insert(_connection, AssetForDb); Application.Current.Properties["AuditedSite"] = newAsset.SiteIDInternal; Application.Current.Properties["AuditedLocation"] = newAsset.LocationIDInternal; Application.Current.Properties["AuditedSublocation"] = newAsset.SubLocation; Application.Current.Properties["LastAssetID"] = newAsset.AssetIDInternal; Application.Current.Properties["Department"] = newAsset.DataGatherID; await DisplayAlert("Complete", "Asset Audited", "OK"); await Navigation.PopModalAsync(); } else { await DisplayAlert("Error", "There is a missing required data field. \"" + MissingField + "\" ", "OK"); } } catch (Exception exe) { DependencyService.Get <IError>().SendRaygunError(exe, Application.Current.Properties["user"].ToString() ?? "Unsynced", Application.Current.Properties["url"].ToString() ?? "Unsynced", null); await DisplayAlert("Error", exe.Message, "OK"); } }
private async void Button_Clicked(object sender, EventArgs e) { try { SearchButton.IsEnabled = false; string departmentName; DepartmentClass departmentInfo = new DepartmentClass(); if (assetDepartment_.SelectedIndex >= 1) { departmentName = assetDepartment_.Items[assetDepartment_.SelectedIndex]; departmentInfo = DepartmentClass.DbToDepartment(Database.Department.GetTableData(_connection)).First(cm => cm.DepartmentName == departmentName); } if (AuditSearchBar.Text == null) { await DisplayAlert("Error", "Please enter a barcode", "OK"); } else { var assetData = Database.Assets.GetTableDataByBarcodeLike(_connection, AuditSearchBar.Text); if (assetData.Count() > 0) { //Not empty 1 or greater if (assetData.Count() == 1) { if (SettingsData.FastAudit) { //Fast audit turned on on single asset try { var _assetclass = AssetClass.DbToAssetClass(assetData, _Names).First(); AuditClass.Audit(_SiteID, _LocationID, _Sublocation, departmentInfo.ID, _assetclass, _connection); Application.Current.Properties["AuditedSite"] = _SiteID; Application.Current.Properties["AuditedLocation"] = _LocationID; Application.Current.Properties["AuditedSublocation"] = _Sublocation; Application.Current.Properties["LastAssetID"] = _assetclass.AssetIdInternal; Application.Current.Properties["Department"] = departmentInfo.ID; await Application.Current.SavePropertiesAsync(); LoadSound(1); //await DisplayAlert("Complete","Asset Audited", "OK"); LoadAssetData(); } catch (Exception exc) { SearchButton.IsEnabled = true; DependencyService.Get <IError>().SendRaygunError(exc, Application.Current.Properties["user"].ToString() ?? "unsynced", Application.Current.Properties["url"].ToString() ?? "unsynced", null); await DisplayAlert("Error", exc.Message, "OK"); } } else { //regular audit await Navigation.PushModalAsync(new AuditRecordPage(_Names, assetData.First(), _SiteID, _LocationID, _Sublocation, departmentInfo.ID, _connection)); //bring up screen } } else { //Display multiple LoadSound(2); await Navigation.PushAsync(new AuditList(_Names, assetData, _connection, true, _SiteID, _LocationID, _Sublocation, departmentInfo.ID)); } } else { if (CrossConnectivity.Current.IsConnected) { //check database for asset var logindata_ = Database.Login.GetTableData(_connection); var test = await SyncClass.NewSyncClass.API_GetAssetByBarcode(logindata_.First().UserID, Application.Current.Properties["url"].ToString(), AuditSearchBar.Text); var record = JsonConvert.DeserializeObject <List <AssetJsonObject> >(test); if (record.Count() > 0) { var AssetClassRecord = new AssetClass(record.First(), true); Database.Assets.Insert(_connection, AssetClass.AssetClassToDb(AssetClassRecord, true)); if (SettingsData.FastAudit) { //may need to insert then audit AuditClass.Audit(_SiteID, _LocationID, _Sublocation, departmentInfo.ID, AssetClassRecord, _connection); Application.Current.Properties["AuditedSite"] = _SiteID; Application.Current.Properties["AuditedLocation"] = _LocationID; Application.Current.Properties["AuditedSublocation"] = _Sublocation; Application.Current.Properties["LastAssetID"] = AssetClassRecord.AssetIdInternal; LoadSound(1); //await DisplayAlert("Complete", "Asset Audited", "OK"); LoadAssetData(); } else { //display the asset record pulled //convert asset class to asset db class await Navigation.PushModalAsync(new AuditRecordPage(_Names, AssetClass.AssetClassToDb(AssetClassRecord, false), _SiteID, _LocationID, _Sublocation, departmentInfo.ID, _connection)); } } else { if (SettingsData.FastAudit && !SettingsData.FastAuditEntry) { AddAssetData(departmentInfo.ID); } else { LoadSound(0); //display screen to add asset await Navigation.PushModalAsync(new AddAuditPage(_Names, _SiteID, _LocationID, _Sublocation, departmentInfo.ID, AuditSearchBar.Text, _connection)); } } } else { LoadSound(0); //Add Asset if (SettingsData.FastAudit && !SettingsData.FastAuditEntry) { AddAssetData(departmentInfo.ID); } else { //display screen to add asset await Navigation.PushModalAsync(new AddAuditPage(_Names, _SiteID, _LocationID, _Sublocation, departmentInfo.ID, AuditSearchBar.Text, _connection)); } } } } SearchButton.IsEnabled = true; } catch (Exception exc) { SearchButton.IsEnabled = true; DependencyService.Get <IError>().SendRaygunError(exc, Application.Current.Properties["user"].ToString() ?? "unsynced", Application.Current.Properties["url"].ToString() ?? "unsynced", null); await DisplayAlert("OK", exc.Message, "OK"); } }
public static void Audit(string SiteID, string LocationID, string SublocationID, int DepartmentID, AssetClass asset, SQLiteConnection _connection, int actualQuantity = -1, string Person = null) { var assetDetails = Database.Assets.GetAssetDataByAssetIDInternal(_connection, asset.AssetIdInternal).First(); var UpdatedValue = JsonConvert.DeserializeObject <AssetJsonObject>(assetDetails.AssetJSONDb); var time = DateTime.Now; if (actualQuantity != -1) { UpdatedValue.ShortageOverage = actualQuantity; } else { UpdatedValue.ShortageOverage = asset.AssetJSON.Quantity; actualQuantity = asset.AssetJSON.Quantity; } UpdatedValue.DateModified = time; UpdatedValue.AuditDate = time; if (asset.Asset_SiteIdInternal == SiteID && asset.Asset_locationIdInternal == LocationID) { //site and location match, continue if (SublocationID != null) { //sublocation was used if (SublocationID == asset.Asset_SublocationIdInternal) { //sublocation matched, continue if (DepartmentID != 0) { //department was used if (DepartmentID == asset.Asset_Department) { //department matches, check Quantity if (actualQuantity == -1 || actualQuantity == asset.AssetJSON.Quantity) { //Quantity isnt used or matches if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.AuditStatus = "AUDITED"; } else { UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } else { //Quantity doesn't match if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.AuditStatus = "RECON-Quantity"; } else { //Person doesnt match UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } } else { //Department doesnt match if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.DataGatherID = DepartmentID; UpdatedValue.AuditStatus = "RECON-Department"; } else { //Person doesnt match UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } } else { //department was not used if (actualQuantity == -1 || actualQuantity == asset.AssetJSON.Quantity) { //Quantity isn't used or matches if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.AuditStatus = "AUDITED"; } else { //Person doesnt match UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } else { //Quantity used, doesnt match if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.AuditStatus = "RECON-Quantity"; } else { //Person doesnt match UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } } } else { //sublocation did not match, recon moved. but still check department to see if it changed if (DepartmentID != 0) { //Department changed UpdatedValue.SubLocation = SublocationID; UpdatedValue.DataGatherID = DepartmentID; if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.AuditStatus = "RECON-Moved"; } else { //Person doesnt match UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } } } else { if (asset.Asset_SublocationIdInternal != "" || asset.Asset_SublocationIdInternal != null) { UpdatedValue.SubLocation = ""; } //sublocation was not used if (DepartmentID != 0) { //department was used if (DepartmentID == asset.Asset_Department) { //department matches if (actualQuantity == -1 || actualQuantity == asset.AssetJSON.Quantity) { if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.AuditStatus = "AUDITED"; } else { //Person doesnt match UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } else { if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.AuditStatus = "RECON-Quantity"; } else { //Person doesnt match UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } } else { if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.AuditStatus = "RECON-Department"; UpdatedValue.DataGatherID = DepartmentID; } else { //Person doesnt match UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } } else { //department was not used if (actualQuantity == -1 || actualQuantity == asset.AssetJSON.Quantity) { if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.AuditStatus = "AUDITED"; } else { //Person doesnt match UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } else { if (Person == null || asset.AssetJSON.PeopleIDInternal == Person) { //person isnt used or matches UpdatedValue.AuditStatus = "RECON-Quantity"; } else { //Person doesnt match UpdatedValue.AuditStatus = "RECON-Custodian"; UpdatedValue.PeopleIDInternal = Person; } } } } } else { //Site and location do not match, recon moved UpdatedValue.AuditDate = time; UpdatedValue.AuditStatus = "RECON-Moved"; UpdatedValue.SiteIDInternal = SiteID; UpdatedValue.LocationIDInternal = LocationID; if (SublocationID != null) { //set sublocation to whatever SublocationID is (still recon Moved) UpdatedValue.SubLocation = SublocationID; } else { if (asset.Asset_SublocationIdInternal != "" || asset.Asset_SublocationIdInternal != null) { UpdatedValue.SubLocation = ""; } } if (DepartmentID != 0) { //set department to whatever dpt is(still mark as RECON Moved) UpdatedValue.DataGatherID = DepartmentID; } } var assetRecord = Database.Assets.Compare(assetDetails, UpdatedValue); var AssetForDb = AssetClass.AssetClassToDb(assetRecord, assetDetails.Synced); Database.Assets.Update(_connection, AssetForDb); }