Beispiel #1
0
        private void LoadCondition(int ConditionID = 0)
        {
            var selectedCondition = "";
            var ConditionList     = ConditionClass.DbToCondition(Database.Condition.GetTableData(_connection), _connection);

            foreach (ConditionClass condition in ConditionList)
            {
                assetCondition_.Items.Add(condition.ConditionLabel);
                if (ConditionID != 0)
                {
                    if (condition.ConditionID == ConditionID)
                    {
                        selectedCondition = condition.ConditionLabel;
                    }
                }
                if (selectedCondition != "")
                {
                    assetCondition_.SelectedItem = selectedCondition;
                }
            }
        }
Beispiel #2
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");
            }
        }