Beispiel #1
0
        public static string GetAssetsViewItem(RestCommand command, int assetID)
        {
            AssetsViewItem assetsViewItem = AssetsView.GetAssetsViewItem(command.LoginUser, assetID);

            if (assetsViewItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(assetsViewItem.GetXml("Asset", true));
        }
        public AssetsViewItemProxy GetAsset(int assetID)
        {
            AssetsViewItem asset = AssetsView.GetAssetsViewItem(TSAuthentication.GetLoginUser(), assetID);

            if (asset.OrganizationID != TSAuthentication.OrganizationID)
            {
                return(null);
            }
            return(asset.GetProxy());
        }
Beispiel #3
0
        public static string GetAssetsView(RestCommand command)
        {
            AssetsView assetsView = new AssetsView(command.LoginUser);

            assetsView.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(assetsView.GetXml("AssetsView", "AssetsViewItem", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
Beispiel #4
0
        public static string GetAssetsView(RestCommand command)
        {
            AssetsView assetsView = new AssetsView(command.LoginUser);

            try
            {
                assetsView.LoadByOrganizationID(command.Organization.OrganizationID, command.Filters);
            }
            catch (Exception ex)
            {
                //if something fails use the old method
                assetsView.LoadByOrganizationID(command.Organization.OrganizationID);
                ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestAssetsView. GetAssetsView(). SQL filtering generation failed, fell into old method.");
            }

            return(assetsView.GetXml("Assets", "Asset", true, command.Filters));
        }
        public static string CreateAsset(RestCommand command)
        {
            DateTime now    = DateTime.UtcNow;
            Assets   assets = new Assets(command.LoginUser);
            Asset    asset  = assets.AddNewAsset();

            asset.OrganizationID = command.Organization.OrganizationID;
            asset.FullReadFromXml(command.Data, true);
            if (asset.ProductID == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, "Product required");
            }
            // For consistency all assets are created in the warehouse.
            asset.Location = "2";
            // This is normally not necessary, but as the CreatorID is defined as a null field in this table it is needed.
            asset.CreatorID     = command.LoginUser.UserID;
            asset.NeedsIndexing = true;
            asset.DateCreated   = now;
            asset.DateModified  = now;
            asset.Collection.Save();
            asset.UpdateCustomFieldsFromXml(command.Data);

            string           description = String.Format("Asset {0} created via API.", GetAssetReference(asset));
            AssetHistory     history     = new AssetHistory(command.LoginUser);
            AssetHistoryItem historyItem = history.AddNewAssetHistoryItem();

            historyItem.OrganizationID    = command.Organization.OrganizationID;
            historyItem.Actor             = command.LoginUser.UserID;
            historyItem.AssetID           = asset.AssetID;
            historyItem.ActionTime        = DateTime.UtcNow;
            historyItem.ActionDescription = "Asset created via API.";
            historyItem.ShippedFrom       = 0;
            historyItem.ShippedTo         = 0;
            historyItem.TrackingNumber    = string.Empty;
            historyItem.ShippingMethod    = string.Empty;
            historyItem.ReferenceNum      = string.Empty;
            historyItem.Comments          = string.Empty;
            historyItem.DateCreated       = now;
            historyItem.DateModified      = now;

            history.Save();

            return(AssetsView.GetAssetsViewItem(command.LoginUser, asset.AssetID).GetXml("Asset", true));
        }
Beispiel #6
0
        public static string GetAssetsView(RestCommand command, int ticketIDOrTicketNumber)
        {
            AssetsView assetsView = new AssetsView(command.LoginUser);

            assetsView.LoadByTicketID(ticketIDOrTicketNumber);

            if (assetsView.IsEmpty)
            {
                assetsView = new AssetsView(command.LoginUser);
                assetsView.LoadByTicketNumber(ticketIDOrTicketNumber, command.LoginUser.OrganizationID);
            }

            if (command.Format == RestFormat.XML)
            {
                return(assetsView.GetXml("Assets", "Asset", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
        public string CreateRecentlyViewed(RecentlyViewedItem recent)
        {
            string     recentHTML;
            AssetsView assetsView = new AssetsView(TSAuthentication.GetLoginUser());

            assetsView.LoadByAssetID(recent.RefID);
            recentHTML = @" 
        <li>
          <div class=""recent-info"">
            <h4><a class=""assetlink"" data-assetid=""{0}"" href=""""><i class=""fa {1} {2}""></i>{3}</a></h4>
          </div>
        </li>";
            string icon  = "fa-truck";
            string color = "color-green";

            switch (assetsView[0].Location)
            {
            case "2":
                icon  = "fa-home";
                color = "color-amber";
                break;

            case "3":
                icon  = "fa-trash-o";
                color = "color-red";
                break;
            }
            var displayName = assetsView[0].Name;

            if (String.IsNullOrEmpty(displayName))
            {
                displayName = assetsView[0].SerialNumber;
                if (String.IsNullOrEmpty(displayName))
                {
                    displayName = assetsView[0].AssetID.ToString();
                }
            }

            return(string.Format(recentHTML, assetsView[0].AssetID, icon, color, displayName));
        }
        public string AssignAsset(int assetID, string data)
        {
            AssignAssetSave info;

            try
            {
                info = Newtonsoft.Json.JsonConvert.DeserializeObject <AssignAssetSave>(data);
            }
            catch (Exception e)
            {
                return("error");
            }

            LoginUser loginUser = TSAuthentication.GetLoginUser();
            Asset     o         = Assets.GetAsset(loginUser, assetID);

            //Location 1=assigned (shipped), 2=warehouse, 3=junkyard
            o.Location   = "1";
            o.AssignedTo = info.RefID;
            DateTime now = DateTime.UtcNow;

            o.DateModified = now;
            o.ModifierID   = loginUser.UserID;
            o.Collection.Save();

            AssetHistory     assetHistory     = new AssetHistory(loginUser);
            AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem();

            assetHistoryItem.AssetID            = assetID;
            assetHistoryItem.OrganizationID     = loginUser.OrganizationID;
            assetHistoryItem.ActionTime         = DateTime.UtcNow;
            assetHistoryItem.ActionDescription  = "Asset Shipped on " + info.DateShipped.Month.ToString() + "/" + info.DateShipped.Day.ToString() + "/" + info.DateShipped.Year.ToString();
            assetHistoryItem.ShippedFrom        = loginUser.OrganizationID;
            assetHistoryItem.ShippedFromRefType = (int)ReferenceType.Organizations;
            assetHistoryItem.ShippedTo          = info.RefID;
            assetHistoryItem.TrackingNumber     = info.TrackingNumber;
            assetHistoryItem.ShippingMethod     = info.ShippingMethod;
            assetHistoryItem.ReferenceNum       = info.ReferenceNumber;
            assetHistoryItem.Comments           = info.Comments;

            assetHistoryItem.DateCreated  = now;
            assetHistoryItem.Actor        = loginUser.UserID;
            assetHistoryItem.RefType      = info.RefType;
            assetHistoryItem.DateModified = now;
            assetHistoryItem.ModifierID   = loginUser.UserID;

            assetHistory.Save();

            AssetAssignments assetAssignments = new AssetAssignments(loginUser);
            AssetAssignment  assetAssignment  = assetAssignments.AddNewAssetAssignment();

            assetAssignment.HistoryID = assetHistoryItem.HistoryID;

            assetAssignments.Save();

            string description = String.Format("Assigned asset to {0}.", info.AssigneeName);

            ActionLogs.AddActionLog(loginUser, ActionLogType.Update, ReferenceType.Assets, assetID, description);

            AssetsView assetsView = new AssetsView(loginUser);

            assetsView.LoadByAssetID(assetID);

            StringBuilder productVersionNumberDisplayName = new StringBuilder();

            if (!string.IsNullOrEmpty(assetsView[0].ProductVersionNumber))
            {
                productVersionNumberDisplayName.Append(" - " + assetsView[0].ProductVersionNumber);
            }

            StringBuilder serialNumberDisplayValue = new StringBuilder();

            if (string.IsNullOrEmpty(assetsView[0].SerialNumber))
            {
                serialNumberDisplayValue.Append("Empty");
            }
            else
            {
                serialNumberDisplayValue.Append(assetsView[0].SerialNumber);
            }

            StringBuilder warrantyExpirationDisplayValue = new StringBuilder();

            if (assetsView[0].WarrantyExpiration == null)
            {
                warrantyExpirationDisplayValue.Append("Empty");
            }
            else
            {
                warrantyExpirationDisplayValue.Append(((DateTime)assetsView[0].WarrantyExpiration).ToString(GetDateFormatNormal()));
            }

            return(string.Format(@"<div class='list-group-item'>
                            <a href='#' id='{0}' class='assetLink'><h4 class='list-group-item-heading'>{1}</h4></a>
                            <div class='row'>
                                <div class='col-xs-8'>
                                    <p class='list-group-item-text'>{2}{3}</p>
                                </div>
                            </div>
                            <div class='row'>
                                <div class='col-xs-8'>
                                    <p class='list-group-item-text'>SN: {4} - Warr. Exp.: {5}</p>
                                </div>
                            </div>
                            </div>"

                                 , assetID
                                 , assetsView[0].DisplayName
                                 , assetsView[0].ProductName
                                 , productVersionNumberDisplayName
                                 , serialNumberDisplayValue
                                 , warrantyExpirationDisplayValue));
        }
Beispiel #9
0
        override protected void GetNextRecord()
        {
            AssetsViewItem asset = AssetsView.GetAssetsViewItem(_loginUser, _itemIDList[_rowIndex]);

            _lastItemID = asset.AssetID;
            UpdatedItems.Add((int)_lastItemID);

            StringBuilder builder = new StringBuilder();

            builder.AppendLine(asset.CreatorName
                               + " " + asset.DisplayName
                               + " " + asset.DateCreated
                               + " " + asset.DateModified
                               + " " + asset.ModifierName
                               + " " + asset.Notes
                               + " " + asset.ProductName
                               + " " + asset.ProductVersionNumber
                               + " " + asset.SerialNumber
                               + " " + asset.WarrantyExpiration);

            AssetHistoryView assetHistoryView = new AssetHistoryView(_loginUser);

            assetHistoryView.LoadByAssetID(asset.AssetID);
            foreach (AssetHistoryViewItem assetHistoryViewItem in assetHistoryView)
            {
                builder.AppendLine(assetHistoryViewItem.ActionTime
                                   + " " + assetHistoryViewItem.ActionDescription
                                   + " " + assetHistoryViewItem.NameAssignedFrom
                                   + " " + assetHistoryViewItem.NameAssignedTo
                                   + " " + assetHistoryViewItem.TrackingNumber
                                   + " " + assetHistoryViewItem.ShippingMethod
                                   + " " + assetHistoryViewItem.ReferenceNum
                                   + " " + assetHistoryViewItem.Comments
                                   + " " + assetHistoryViewItem.ActorName
                                   + " " + assetHistoryViewItem.DateModified
                                   + " " + assetHistoryViewItem.ModifierName
                                   + " " + assetHistoryViewItem.DateCreated);
            }

            DocText = builder.ToString();

            StringBuilder assetLocationString = new StringBuilder();

            switch (asset.Location)
            {
            case "1":
                assetLocationString.Append("Assigned");
                break;

            case "2":
                assetLocationString.Append("Warehouse");
                break;

            case "3":
                assetLocationString.Append("Junkyard");
                break;
            }
            _docFields.Clear();
            AddDocField("AssetID", asset.AssetID);
            AddDocField("Location", assetLocationString.ToString());
            AddDocField("SerialNumber", asset.SerialNumber);

            if (string.IsNullOrWhiteSpace(asset.Name))
            {
                if (string.IsNullOrWhiteSpace(asset.SerialNumber))
                {
                    AddDocField("Name", asset.AssetID);
                    DocDisplayName = asset.AssetID.ToString();
                }
                else
                {
                    AddDocField("Name", asset.SerialNumber);
                    DocDisplayName = asset.SerialNumber;
                }
            }
            else
            {
                AddDocField("Name", asset.Name);
                DocDisplayName = asset.Name;
            }

            InventorySearchAsset assetItem = new InventorySearchAsset(asset);

            AddDocField("**JSON", JsonConvert.SerializeObject(assetItem));

            CustomValues customValues = new CustomValues(_loginUser);

            customValues.LoadByReferenceType(_organizationID, ReferenceType.Assets, asset.AssetID);

            foreach (CustomValue value in customValues)
            {
                object o = value.Row["CustomValue"];
                string s = o == null || o == DBNull.Value ? "" : o.ToString();
                AddDocField(value.Row["Name"].ToString(), s);
            }
            DocFields = _docFields.ToString();
            DocIsFile = false;
            DocName   = asset.AssetID.ToString();
            try
            {
                DocCreatedDate  = (DateTime)asset.Row["DateCreated"];
                DocModifiedDate = (DateTime)asset.Row["DateModified"];
            }
            catch (Exception)
            {
            }
        }
Beispiel #10
0
 private void AssetsView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
 {
     Console.WriteLine("click");
     AssetsView.CommitEdit(DataGridViewDataErrorContexts.Commit);
 }
        public static string UpdateAsset(RestCommand command, int assetID)
        {
            Asset asset = Assets.GetAsset(command.LoginUser, assetID);

            if (asset == null || asset.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            string originalLocation = asset.Location;

            asset.FullReadFromXml(command.Data, false);
            if (asset.ProductID == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, "Product required");
            }

            if (
                String.IsNullOrEmpty(asset.Location.Trim()) ||
                (
                    asset.Location != "1" &&
                    asset.Location != "2" &&
                    asset.Location != "3"
                )
                )
            {
                asset.Location = originalLocation;
            }
            //Location can not be changed via the WebApp. The only change we are allowing is to bring an asset back to the Warehouse from the Junkyard.
            else if (asset.Location == "1" && originalLocation != "1")
            {
                throw new RestException(HttpStatusCode.BadRequest, "Please use a POST against the /assets/{id}/assignments/ URL to assign an asset.");
            }
            else if (asset.Location == "2" && originalLocation == "1")
            {
                throw new RestException(HttpStatusCode.BadRequest, "Please use a DELETE against the /assets/{id}/assignments/ URL to return an asset.");
            }
            else if (asset.Location == "3" && originalLocation == "1")
            {
                throw new RestException(HttpStatusCode.BadRequest, "Please return an asset to the Warehouse before sending it to the Junkyard.");
            }
            else if (asset.Location == "3" && originalLocation == "2")
            {
                throw new RestException(HttpStatusCode.BadRequest, "Please use a DELETE against the /assets/{id}/ URL to assign an asset to the Junkyard.");
            }

            asset.Collection.Save();
            asset.UpdateCustomFieldsFromXml(command.Data);

            if (asset.Location == "2" && originalLocation == "3")
            {
                DateTime         now              = DateTime.UtcNow;
                AssetHistory     assetHistory     = new AssetHistory(command.LoginUser);
                AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem();

                assetHistoryItem.AssetID            = assetID;
                assetHistoryItem.OrganizationID     = command.LoginUser.OrganizationID;
                assetHistoryItem.ActionTime         = DateTime.UtcNow;
                assetHistoryItem.ActionDescription  = "Restore asset from Junkyard via API";
                assetHistoryItem.ShippedFrom        = -1;
                assetHistoryItem.ShippedFromRefType = -1;
                assetHistoryItem.ShippedTo          = -1;
                assetHistoryItem.RefType            = -1;
                assetHistoryItem.TrackingNumber     = string.Empty;
                assetHistoryItem.ShippingMethod     = string.Empty;
                assetHistoryItem.ReferenceNum       = string.Empty;

                assetHistoryItem.DateCreated  = now;
                assetHistoryItem.Actor        = command.LoginUser.UserID;
                assetHistoryItem.DateModified = now;
                assetHistoryItem.ModifierID   = command.LoginUser.UserID;

                assetHistory.Save();
            }

            return(AssetsView.GetAssetsViewItem(command.LoginUser, assetID).GetXml("Asset", true));
        }
Beispiel #12
0
    protected void OnGlwidget1Initialized(object sender, EventArgs e)
    {
        Console.WriteLine("init");
        //if (GLinit)
        //return;
        GLinit = true;
        MainEditorView.editorBackendRenderer = new SharpSL.BackendRenderers.OpenGL.EditorOpenGLRenderer();
        SceneView.backendRenderer            = new SharpSL.BackendRenderers.OpenGL.OpenGLRenderer();
        mainEditorView.Initialize();
        mainEditorView.OnResize(glwidget1.Allocation.Width, glwidget1.Allocation.Height);

        Sharp.InputHandler.input.Initialize(MainEditorView.canvas);


        var assets = new AssetsView();


        Sharp.InputHandler.OnMouseDown += (args) => {
            Console.WriteLine("click: " + focusedView);
            if (focusedView == null)
            {
                foreach (var view in View.views)
                {
                    if (view.panel != null && view.panel.IsChild(Gwen.Input.InputHandler.HoveredControl, true))
                    {
                        view.OnMouseDown(args);
                        break;
                    }
                }
            }
            else
            {
                focusedView.OnMouseDown(args);
            }
        };
        Sharp.InputHandler.OnMouseUp += (args) => {
            if (focusedView == null)
            {
                foreach (var view in View.views)
                {
                    if (view.panel != null && view.panel.IsChild(Gwen.Input.InputHandler.HoveredControl, true))
                    {
                        view.OnMouseUp(args);
                        break;
                    }
                }
            }
            else
            {
                focusedView.OnMouseUp(args);
            }
        };
        Sharp.InputHandler.OnMouseMove += (args) => {
            if (focusedView == null)
            {
                foreach (var view in View.views)
                {
                    if (view.panel != null && view.panel.IsChild(Gwen.Input.InputHandler.HoveredControl, true))
                    {
                        view.OnMouseMove(args);
                        break;
                    }
                }
            }
            else
            {
                focusedView.OnMouseMove(args);
            }
        };

        var scene     = new SceneView();
        var structure = new SceneStructureView();
        var inspector = new InspectorView();

        var tab = new Gwen.Control.TabControl(mainEditorView.splitter);

        mainEditorView.splitter.OnSplitMoved += (o, args) => {
            scene.OnResize(glwidget1.Allocation.Width, glwidget1.Allocation.Height);
            //assets.OnResize(glwidget1.Allocation.Width,glwidget1.Allocation.Height);
        };
        var btn  = tab.AddPage("scene");
        var page = btn.Page;

        page.Margin = new Gwen.Margin(3, 3, 3, 3);
        scene.panel = btn.Page;         //make GLControl for gwen

        var tab1 = new Gwen.Control.TabControl(mainEditorView.splitter);

        btn              = tab1.AddPage("Assets");
        page             = btn.Page;
        page.Margin      = new Gwen.Margin(3, 3, 3, 3);
        page.HoverEnter += (item, args) => { Console.WriteLine("hover"); };
        assets.panel     = page;

        var tab2 = new Gwen.Control.TabControl(mainEditorView.splitter);

        btn             = tab2.AddPage("Structure");
        page            = btn.Page;
        page.Margin     = new Gwen.Margin(3, 3, 3, 3);
        structure.panel = btn.Page;

        var tab3 = new Gwen.Control.TabControl(mainEditorView.splitter);

        btn             = tab3.AddPage("Inspector");
        page            = btn.Page;
        page.Margin     = new Gwen.Margin(3, 3, 3, 3);
        inspector.panel = btn.Page;

        scene.Initialize();
        structure.Initialize();

        inspector.Initialize();
        assets.Initialize();

        inspector.OnResize(glwidget1.Allocation.Width, glwidget1.Allocation.Height);
        scene.OnResize(glwidget1.Allocation.Width, glwidget1.Allocation.Height);
        structure.OnResize(glwidget1.Allocation.Width, glwidget1.Allocation.Height);
        assets.OnResize(glwidget1.Allocation.Width, glwidget1.Allocation.Height);

        mainEditorView.splitter.SetPanel(1, tab);
        mainEditorView.splitter.SetPanel(0, tab1);
        mainEditorView.splitter.SetPanel(2, tab2);
        mainEditorView.splitter.SetPanel(3, tab3);


        foreach (var view in View.views)
        {
            view.OnContextCreated(glwidget1.Allocation.Width, glwidget1.Allocation.Height);
        }
        QueueResize();
    }