Example #1
0
        private void Scanbarcodeupdateasset_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            var Asset_list  = e.Item as AssetDisplayClass;
            var AssetRecord = AssetClass.DbToAssetClass(Database.Assets.GetAssetDataByAssetIDInternal(_connection, Asset_list.AssetIdInternal)).First();

            Navigation.PushAsync(new AddAssetPage(_connection, AssetRecord));
        }
Example #2
0
        private async void AuditButton(object sender, EventArgs e)
        {
            if (ActualQuantity_.Text == null)
            {
                _Actual = -1;
            }
            else
            {
                _Actual = Convert.ToInt16(ActualQuantity_.Text);
            }
            var _assetclass = AssetClass.DbToAssetClass(IEnumAsset_).First();

            AuditClass.Audit(_SiteID, _LocationID, _Sublocation, _Department, _assetclass, _connection, _Actual, _Person);
            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"]         = _Department;
            await Application.Current.SavePropertiesAsync();

            await DisplayAlert("Complete", "Asset Audited", "OK");

            try
            {
                await Navigation.PopModalAsync();

                MessagingCenter.Send(this, "Pop", "");
            }
            catch (Exception exc)
            {
                DependencyService.Get <IError>().SendRaygunError(exc, Application.Current.Properties["user"].ToString() ?? "unsynced", Application.Current.Properties["url"].ToString() ?? "unsynced", null);
            }
        }
Example #3
0
        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");
            }
        }
Example #4
0
        List <AssetClass> GetAssetList(LocationClass location, SublocationClass sublocation, DepartmentClass department, string searchText = null)
        {
            var AssetList = AssetClass.DbToAssetClass(Database.Assets.GetAssetListForSearch(_connection, location, sublocation, department), _Names);

            if (String.IsNullOrWhiteSpace(searchText))
            {
                return(AssetList);
            }
            return(AssetList.Where(c => (c.AssetName.Contains(searchText) || c.Barcode.Contains(searchText))).ToList());
        }
Example #5
0
        private void LoadAssetData()
        {
            if (Application.Current.Properties.ContainsKey("LastAssetID") && Application.Current.Properties["LastAssetID"] != null)
            {
                //get asset based on ID then assign it to list
                var IEnumAsset = Database.Assets.GetAssetDataByAssetIDInternal(_connection, Application.Current.Properties["LastAssetID"].ToString());
                if (Database.Settings.GetTableData(_connection).BlindAudit)
                {
                    AssetListView2.IsVisible   = true;
                    AssetListView.IsVisible    = false;
                    AssetListView2.ItemsSource = AssetClass.DbToAssetClass(IEnumAsset, _Names);
                }
                else
                {
                    AssetListView.IsVisible   = true;
                    AssetListView2.IsVisible  = false;
                    AssetListView.ItemsSource = AssetClass.DbToAssetClass(IEnumAsset, _Names);
                }
            }
            else
            {
                var _defaultAsset = new AssetClass
                {
                    AssetName                 = "Default Asset Name",
                    AuditStatusDisplay_       = _Names.AssetStatus,
                    Barcode                   = "Default Barcode",
                    QuantityDisplay_          = _Names.Quantity,
                    OriginalPartDisplay_      = _Names.OriginalPartNo,
                    UIDDisplay_               = _Names.Asset_UID,
                    AssetSerialNumberDisplay_ = _Names.SerialNo,
                    BarcodeDisplay_           = _Names.Barcode,
                    AssetJSON                 = new AssetJsonObject
                    {
                        AssetStatus    = "Default Asset Status",
                        Quantity       = 0,
                        OriginalPartNo = "00000000",
                        Asset_UID      = "Example UID",
                        AssetSerialNo  = "01010101",
                        Barcode        = "Default Barcode",
                        AuditStatus    = "RECON",
                    }
                };
                AssetListView.ItemsSource = new List <AssetClass> {
                    _defaultAsset
                };
            }


            SettingsData = Database.Settings.GetTableData(_connection);
        }
Example #6
0
        public static List <AssetClass> DbToAssetClass(IEnumerable <AssetDbClass> AssetJSON_, AssetDetailNames Names = null, SQLiteConnection _connection = null)
        {
            var AssetList = new List <AssetClass>();

            foreach (AssetDbClass AssetDBData in AssetJSON_)
            {
                var intermediateAsset = new AssetClass
                {
                    AssetIdInternal             = AssetDBData.AssetIdInternal,
                    Asset_SiteIdInternal        = AssetDBData.Asset_SiteIdInternal,
                    Asset_locationIdInternal    = AssetDBData.Asset_locationIdInternal,
                    Asset_SublocationIdInternal = AssetDBData.Asset_SublocationIdInternal,
                    AssetName              = AssetDBData.AssetName,
                    Asset_Department       = AssetDBData.Asset_Department,
                    AssetSerialNumber      = AssetDBData.AssetSerialNumber,
                    Asset_PeopleIdInternal = AssetDBData.Asset_PeopleIdInternal,
                    Barcode     = AssetDBData.Barcode,
                    AssetJSON   = JsonConvert.DeserializeObject <AssetJsonObject>(AssetDBData.AssetJSONDb),
                    ChangesMade = JsonConvert.DeserializeObject <List <Changesmade> >(AssetDBData.AssetChangesDb),
                    Synced      = AssetDBData.Synced
                };
                if (_connection != null)
                {
                    try
                    {
                        intermediateAsset.SiteName_     = Database.Sites.GetTableData(_connection).Single(cm => cm.SiteIdInternal == AssetDBData.Asset_SiteIdInternal).SiteName;
                        intermediateAsset.LocationName_ = Database.Locations.GetTableDataFromSites(_connection, AssetDBData.Asset_SiteIdInternal).Single(cm => cm.LocationIdInternal == AssetDBData.Asset_locationIdInternal).LocationName;
                    }
                    catch (Exception exc)
                    {
                        DependencyService.Get <IError>().SendRaygunError(exc, Application.Current.Properties["user"].ToString() ?? "unsynced", Application.Current.Properties["url"].ToString() ?? "unsynced", null);
                    }
                }
                if (Names != null)
                {
                    intermediateAsset.BarcodeDisplay_                     = Names.Barcode;
                    intermediateAsset.AssetSerialNumberDisplay_           = Names.SerialNo;
                    intermediateAsset.Asset_SublocationIdInternalDisplay_ = Names.SubLocation;
                    intermediateAsset.QuantityDisplay_                    = Names.Quantity;
                    intermediateAsset.OriginalPartDisplay_                = Names.OriginalPartNo;
                    intermediateAsset.AuditStatusDisplay_                 = Names.AuditStatus;
                    intermediateAsset.UIDDisplay_      = Names.Asset_UID;
                    intermediateAsset.SiteDisplay_     = Names.Site;
                    intermediateAsset.LocationDisplay_ = Names.Location;
                }
                AssetList.Add(intermediateAsset);
            }
            return(AssetList);
        }
Example #7
0
        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));
                    }
                }
            }
        }
Example #8
0
        public AssetCategoryPage(SQLiteConnection connection_, AssetClass asset = null)
        {
            if (asset != null)
            {
                _Asset = asset;
                _categoryIDInternal = _Asset.AssetJSON.AssetCategoryIDInternal;
            }
            _connection = connection_;
            InitializeComponent();
            if (Device.RuntimePlatform == Device.iOS)
            {
                Padding = new Thickness(0, 20, 20, 0);
            }
            //load root categories
            var assetCategories_ = Database.Category.GetCategoryWithParents(_connection, 0);

            CategoryList.ItemsSource = assetCategories_;
            base.OnAppearing();
        }
Example #9
0
 public AuditList(AssetDetailNames Names_, IEnumerable <AssetDbClass> AssetList, SQLiteConnection connection, bool Auditing, string Site, string Location, string Sublocation, int Department, string Person = null, string PersonName = null)
 {
     try
     {
         MessagingCenter.Subscribe <AuditRecordPage, string>(this, "Pop", (sender, arg) =>
         {
             Navigation.PopAsync();
         });
         _Names = Names_;
         InitializeComponent();
         _AssetList   = AssetList;
         _Auditing    = Auditing;
         _Site        = Site;
         _Location    = Location;
         _Sublocation = Sublocation;
         _Department  = Department;
         _connection  = connection;
         if (Database.Settings.GetTableData(_connection).BlindAudit)
         {
             AuditListView2.IsVisible   = true;
             AuditListView.IsVisible    = false;
             AuditListView2.ItemsSource = AssetClass.DbToAssetClass(_AssetList, _Names, _connection);
         }
         else
         {
             AuditListView.IsVisible   = true;
             AuditListView2.IsVisible  = false;
             AuditListView.ItemsSource = AssetClass.DbToAssetClass(_AssetList, _Names, _connection);
         }
         if (Person != null)
         {
             PersonButton.IsVisible = true;
             _PersonID        = Person;
             PersonName_.Text = PersonName + "'s Assets";
         }
     }
     catch (Exception exe)
     {
         DependencyService.Get <IError>().SendRaygunError(exe, Application.Current.Properties["user"].ToString() ?? "unsynced", Application.Current.Properties["url"].ToString() ?? "unsynced", null);
         throw (new Exception(exe.Message));
     }
 }
Example #10
0
        public ScanBarcodeUpdatePage(AssetDetailNames Names_, AssetDisplayClass details, SQLiteConnection connection_)
        {
            InitializeComponent();
            BindingContext = details;
            _connection    = connection_;
            var inermediate = Database.Assets.GetAssetDataByAssetIDInternal(_connection, details.AssetIdInternal);

            _synced          = inermediate.First().Synced;
            _Asset           = AssetClass.DbToAssetClass(inermediate).First().AssetJSON;
            details.Quantity = _Asset.Quantity;
            _Names           = Names_;
            scanbarcodeupdateasset.ItemsSource = new List <AssetDisplayClass>()
            {
                AssetDisplayClass.GetDetails(details)
            };
            //if (Application.Current.MainPage.Height <= 568)
            //{
            //    Scan_scroll.HeightRequest = 550;
            //}
        }
Example #11
0
        public static AssetDbClass AssetClassToDb(AssetClass asset, bool synced)
        {
            var returnedAssetDb = new AssetDbClass {
                AssetIdInternal          = asset.AssetIdInternal,
                Barcode                  = asset.Barcode,
                AssetName                = asset.AssetName,
                AssetSerialNumber        = asset.AssetSerialNumber,
                Asset_Department         = asset.Asset_Department,
                Asset_locationIdInternal = asset.Asset_locationIdInternal,
                Asset_PeopleIdInternal   = asset.Asset_PeopleIdInternal,
                Asset_SiteIdInternal     = asset.Asset_SiteIdInternal,
                Synced = synced,
                Asset_SublocationIdInternal = asset.Asset_SublocationIdInternal,
                AssetChangesDb = JsonConvert.SerializeObject(asset.ChangesMade),
                AssetJSONDb    = JsonConvert.SerializeObject(asset.AssetJSON),
                OriginalPartNo = asset.AssetJSON.OriginalPartNo,
            };

            return(returnedAssetDb);
        }
Example #12
0
        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");
            }
        }
Example #13
0
        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");
            }
        }
Example #14
0
        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");
            }
        }
Example #15
0
        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);
        }