Ejemplo n.º 1
0
        static public int SaveAssetComputer(Guid OrgId, int DepartmentID, AssetComputerData data, bool AddNewOnly, int?AccountId, int?LocationId, ref int?CategoryId, ref int?TypeId, DateTime?DTUpdated)
        {
            LastLog = "SaveAssetComputer ";
            if (DTUpdated == null)
            {
                DTUpdated = DateTime.UtcNow;
            }
            lib.bwa.bigWebDesk.LinqBll.Context.MutiBaseDataContext dc = new lib.bwa.bigWebDesk.LinqBll.Context.MutiBaseDataContext(OrgId, DepartmentID);

            bool isNew = true;

            lib.bwa.bigWebDesk.LinqBll.Context.Assets A = null;

            if (data.AssetNumber > 1)
            {
                A = (
                    from a in dc.Assets
                    where a.DepartmentId == DepartmentID && a.AssetNumber == data.AssetNumber
                    select a
                    ).FirstOrNull();
                isNew = A == null;
            }

            if (isNew && data.MotherboardSerialNumber != null)
            {
                A = (
                    from a in dc.Assets
                    join ac in dc.AssetComputers on new { a.DepartmentId, AssetId = a.Id } equals new { ac.DepartmentId, ac.AssetId }
                    join t in dc.AssetTypes on new { a.DepartmentId, a.TypeId } equals new { t.DepartmentId, TypeId = t.Id }
                    where a.DepartmentId == DepartmentID && t.AssetProfileId == 1 && a.Unique7 == data.MotherboardSerialNumber
                    select a
                    ).FirstOrNull();
                isNew = A == null;
            }

            if (isNew)
            {
                A = (
                    from a in dc.Assets
                    join t in dc.AssetTypes on new { a.DepartmentId, a.TypeId } equals new { t.DepartmentId, TypeId = t.Id }
                    where a.DepartmentId == DepartmentID && t.AssetProfileId == 1 && a.SerialNumber == data.PCSerialNumber
                    select a
                    ).FirstOrNull();
                isNew = A == null;
            }

            LastLog += " isNew=" + isNew;

            if (AddNewOnly && !isNew)
            {
                return(0);
            }

            if (isNew)
            {
                A           = new lib.bwa.bigWebDesk.LinqBll.Context.Assets();
                A.AssetGUID = Guid.NewGuid();
                int?MaxNumber = (from a in dc.Asset where a.DId == DepartmentID select(int?) a.AssetNumber).Max();
                if (MaxNumber == null || (int)MaxNumber < 1)
                {
                    A.AssetNumber = 1;
                }
                else
                {
                    A.AssetNumber = (int)MaxNumber + 1;
                }
            }

            if (data.AssetSort > 0)
            {
                A.AssetSort = data.AssetSort;
            }
            if (data.DateAquired != null)
            {
                A.DateAquired = data.DateAquired;
            }
            if (data.DateDeployed != null)
            {
                A.DateDeployed = data.DateDeployed;
            }
            if (data.DateDisposed != null)
            {
                A.DateDisposed = data.DateDisposed;
            }
            if (data.DateEntered != null)
            {
                A.DateEntered = data.DateEntered;
            }
            if (data.DateEntered != null)
            {
                A.DateEntered = data.DateEntered;
            }
            if (data.DateOutOfService != null)
            {
                A.DateOutOfService = data.DateOutOfService;
            }
            if (data.DatePurchased != null)
            {
                A.DatePurchased = data.DatePurchased;
            }
            if (data.DateReceived != null)
            {
                A.DateReceived = data.DateReceived;
            }
            if (data.Description != null)
            {
                A.Description = data.Description;
            }
            if (data.FundingCode != null)
            {
                A.FundingCode = data.FundingCode;
            }
            if (data.FundingSource != null)
            {
                A.FundingSource = data.FundingSource;
            }
            if (data.LaborWarrantyLength != null)
            {
                A.LaborWarrantyLength = data.LaborWarrantyLength;
            }
            if (data.Notes != null)
            {
                A.Notes = data.Notes;
            }
            if (data.PartsWarrantyLength != null)
            {
                A.PartsWarrantyLength = data.PartsWarrantyLength;
            }
            if (data.PONumber != null)
            {
                A.PONumber = data.PONumber;
            }
            if (data.Room != null)
            {
                A.Room = data.Room;
            }
            if (data.ValueCurrent != null)
            {
                A.ValueCurrent = data.ValueCurrent;
            }
            if (data.ValueDepreciated != null)
            {
                A.ValueDepreciated = data.ValueDepreciated;
            }
            if (data.ValueReplacement != null)
            {
                A.ValueReplacement = data.ValueReplacement;
            }
            if (data.ValueSalvage != null)
            {
                A.ValueSalvage = data.ValueSalvage;
            }

            A.Unique7      = data.MotherboardSerialNumber;
            A.SerialNumber = data.PCSerialNumber;
            A.DtUpdated    = (DateTime)DTUpdated;

            if (CategoryId != null && TypeId != null)
            {
                A.CategoryId = (int)CategoryId;
                A.TypeId     = (int)TypeId;
                LastLog     += " Direct_TypeId";
            }
            else
            {
                if (string.IsNullOrEmpty(data.Type))
                {
                    if (isNew)
                    {
                        LastLog += " Name_TypeId";
                        var at = (from t in dc.AssetTypes where t.DepartmentId == DepartmentID && t.AssetProfileId == 1 select t).FirstOrDefault();
                        if (at == null || at.Id == 0)
                        {
                            throw new Exception("Cann not find Asset Type with 'Computer profile'");
                        }
                        A.CategoryId = at.CategoryId;
                        A.TypeId     = at.Id;
                    }
                }
                else
                {
                    LastLog += " First_TypeId";
                    var at = (from t in dc.AssetTypes where t.DepartmentId == DepartmentID && t.AssetProfileId == 1 && t.Name == data.Type select t).FirstOrDefault();
                    if (at == null || at.Id == 0)
                    {
                        if (isNew)
                        {
                            throw new Exception("Cann not find '" + data.Type + "' Asset Type");
                        }
                    }
                    else
                    {
                        A.CategoryId = at.CategoryId;
                        A.TypeId     = at.Id;
                    }
                }
            }

            CategoryId = A.CategoryId;
            TypeId     = A.TypeId;

            A.StatusId = Assets.GetStatus(dc, data.Status);
            A.MakeId   = Assets.GetMakeId(dc, DepartmentID, data.Make, A.TypeId);
            A.ModelId  = Assets.GetModelId(dc, DepartmentID, data.Model, A.MakeId);

            if (AccountId != null)
            {
                A.AccountId = AccountId;
            }
            else
            {
                A.AccountId = Assets.GetAccountId(dc, DepartmentID, data.Account);
            }
            if (LocationId != null)
            {
                A.LocationId = LocationId;
            }
            else
            {
                A.LocationId = Assets.GetLocationId(dc, DepartmentID, data.AccountLocation, A.AccountId);
            }

            A.VendorId       = Assets.GetVendorId(dc, DepartmentID, data.PurchaseVendor);
            A.WarrantyVendor = Assets.GetVendorId(dc, DepartmentID, data.WarrantyVendor);
            A.DepartmentId   = DepartmentID;

            if (isNew)
            {
                dc.Assets.InsertOnSubmit(A);
            }
            dc.SubmitChanges();
            data.AssetNumber = A.Id;
            LastLog         += " Id=" + A.Id;

            try { SaveComputers(DepartmentID, dc, data); } catch { }
            try { SaveComputerLogicalDrives(DepartmentID, dc, data); } catch { }
            try { SaveComputerProcessors(DepartmentID, dc, data); } catch { }
            try { SaveComputerPrinters(DepartmentID, dc, data); } catch { }
            try { SaveComputerSoftwares(DepartmentID, dc, data); } catch { }

            dc.SubmitChanges();
            return(A.Id);
        }
Ejemplo n.º 2
0
        public static int SaveAssetComputer(Guid OrgId, int DepartmentID, AssetComputerData data, bool AddNewOnly, int? AccountId, int? LocationId, ref int? CategoryId, ref int? TypeId, DateTime? DTUpdated)
        {
            LastLog = "SaveAssetComputer ";
            if(DTUpdated==null) DTUpdated = DateTime.UtcNow;
            lib.bwa.bigWebDesk.LinqBll.Context.MutiBaseDataContext dc = new lib.bwa.bigWebDesk.LinqBll.Context.MutiBaseDataContext(OrgId, DepartmentID);

            bool isNew = true;
            lib.bwa.bigWebDesk.LinqBll.Context.Assets A = null;

            if(data.AssetNumber>1)
            {
                A = (
                    from a in dc.Assets
                    where a.DepartmentId == DepartmentID && a.AssetNumber==data.AssetNumber
                    select a
                    ).FirstOrNull();
                isNew = A == null;
            }

            if (isNew && data.MotherboardSerialNumber != null)
            {
                A = (
                    from a in dc.Assets
                    join ac in dc.AssetComputers on new { a.DepartmentId, AssetId = a.Id } equals new { ac.DepartmentId, ac.AssetId }
                    join t in dc.AssetTypes on new { a.DepartmentId, a.TypeId } equals new { t.DepartmentId, TypeId = t.Id }
                    where a.DepartmentId == DepartmentID && t.AssetProfileId == 1 && a.Unique7 == data.MotherboardSerialNumber
                    select a
                    ).FirstOrNull();
                isNew = A == null;
            }

            if (isNew)
            {
                A = (
                    from a in dc.Assets
                    join t in dc.AssetTypes on new { a.DepartmentId, a.TypeId } equals new { t.DepartmentId, TypeId = t.Id }
                    where a.DepartmentId == DepartmentID && t.AssetProfileId == 1 && a.SerialNumber == data.PCSerialNumber
                    select a
                    ).FirstOrNull();
                isNew = A == null;
            }

            LastLog += " isNew=" + isNew;

            if (AddNewOnly && !isNew) return 0;

            if (isNew)
            {
                A = new lib.bwa.bigWebDesk.LinqBll.Context.Assets();
                A.AssetGUID = Guid.NewGuid();
                int? MaxNumber = (from a in dc.Asset where a.DId==DepartmentID select (int?)a.AssetNumber).Max();
                if (MaxNumber == null || (int)MaxNumber < 1) A.AssetNumber = 1;
                else A.AssetNumber = (int)MaxNumber + 1;
            }

            if (data.AssetSort>0) A.AssetSort = data.AssetSort;
            if (data.DateAquired != null) A.DateAquired = data.DateAquired;
            if (data.DateDeployed != null) A.DateDeployed = data.DateDeployed;
            if (data.DateDisposed != null) A.DateDisposed = data.DateDisposed;
            if (data.DateEntered != null) A.DateEntered = data.DateEntered;
            if (data.DateEntered != null) A.DateEntered = data.DateEntered;
            if (data.DateOutOfService != null) A.DateOutOfService = data.DateOutOfService;
            if (data.DatePurchased != null) A.DatePurchased = data.DatePurchased;
            if (data.DateReceived != null) A.DateReceived = data.DateReceived;
            if (data.Description != null) A.Description = data.Description;
            if (data.FundingCode != null) A.FundingCode = data.FundingCode;
            if (data.FundingSource != null) A.FundingSource = data.FundingSource;
            if (data.LaborWarrantyLength != null) A.LaborWarrantyLength = data.LaborWarrantyLength;
            if (data.Notes != null) A.Notes = data.Notes;
            if (data.PartsWarrantyLength != null) A.PartsWarrantyLength = data.PartsWarrantyLength;
            if (data.PONumber != null) A.PONumber = data.PONumber;
            if (data.Room != null) A.Room = data.Room;
            if (data.ValueCurrent != null) A.ValueCurrent = data.ValueCurrent;
            if (data.ValueDepreciated != null) A.ValueDepreciated = data.ValueDepreciated;
            if (data.ValueReplacement != null) A.ValueReplacement = data.ValueReplacement;
            if (data.ValueSalvage != null) A.ValueSalvage = data.ValueSalvage;

            A.Unique7 = data.MotherboardSerialNumber;
            A.SerialNumber = data.PCSerialNumber;
            A.DtUpdated = (DateTime)DTUpdated;

            if (CategoryId != null && TypeId != null)
            {
                A.CategoryId = (int)CategoryId;
                A.TypeId = (int)TypeId;
                LastLog += " Direct_TypeId";
            }
            else
            {

                if (string.IsNullOrEmpty(data.Type))
                {
                    if (isNew)
                    {
                        LastLog += " Name_TypeId";
                        var at = (from t in dc.AssetTypes where t.DepartmentId == DepartmentID && t.AssetProfileId == 1 select t).FirstOrDefault();
                        if (at == null || at.Id == 0) throw new Exception("Cann not find Asset Type with 'Computer profile'");
                        A.CategoryId = at.CategoryId;
                        A.TypeId = at.Id;
                    }
                }
                else
                {
                    LastLog += " First_TypeId";
                    var at = (from t in dc.AssetTypes where t.DepartmentId == DepartmentID && t.AssetProfileId == 1 && t.Name == data.Type select t).FirstOrDefault();
                    if (at == null || at.Id == 0)
                    {
                        if (isNew) throw new Exception("Cann not find '" + data.Type + "' Asset Type");
                    }
                    else
                    {
                        A.CategoryId = at.CategoryId;
                        A.TypeId = at.Id;
                    }
                }
            }

            CategoryId = A.CategoryId;
            TypeId = A.TypeId;

            A.StatusId = Assets.GetStatus(dc, data.Status);
            A.MakeId = Assets.GetMakeId(dc, DepartmentID, data.Make, A.TypeId);
            A.ModelId = Assets.GetModelId(dc, DepartmentID, data.Model, A.MakeId);

            if(AccountId!=null) A.AccountId = AccountId;
            else A.AccountId = Assets.GetAccountId(dc, DepartmentID, data.Account);
            if (LocationId!=null) A.LocationId = LocationId;
            else A.LocationId = Assets.GetLocationId(dc, DepartmentID, data.AccountLocation, A.AccountId);

            A.VendorId = Assets.GetVendorId(dc, DepartmentID, data.PurchaseVendor);
            A.WarrantyVendor = Assets.GetVendorId(dc, DepartmentID, data.WarrantyVendor);
            A.DepartmentId = DepartmentID;

            if (isNew) dc.Assets.InsertOnSubmit(A);
            dc.SubmitChanges();
            data.AssetNumber = A.Id;
            LastLog += " Id=" + A.Id;

            try { SaveComputers(DepartmentID, dc, data); } catch { }
            try { SaveComputerLogicalDrives(DepartmentID, dc, data); } catch { }
            try { SaveComputerProcessors(DepartmentID, dc, data); } catch { }
            try { SaveComputerPrinters(DepartmentID, dc, data); } catch { }
            try { SaveComputerSoftwares(DepartmentID, dc, data); } catch { }

            dc.SubmitChanges();
            return A.Id;
        }
Ejemplo n.º 3
0
        public static string Merge(Guid OrgId, int DepartmentId, List <lib.bwa.bigWebDesk.LinqBll.Context.Assets> OldAssets, lib.bwa.bigWebDesk.LinqBll.Context.Assets NewAsset, int?OldAssetComputerId)
        {
            using (lib.bwa.bigWebDesk.LinqBll.Context.MutiBaseDataContext dc = new lib.bwa.bigWebDesk.LinqBll.Context.MutiBaseDataContext(OrgId, DepartmentId))
            {
                int?InactiveMergedStatusID = (from s in dc.AssetStatus where s.VchStatus == "Deleted" select s.Id).FirstOrDefault();
                if (InactiveMergedStatusID == null || InactiveMergedStatusID == 0)
                {
                    return("Can not find 'Deleted' asset status");
                }

                dc.Assets.InsertOnSubmit(NewAsset);
                dc.SubmitChanges();
                if (OldAssetComputerId != null)
                {
                    var OldAC = (from ac in dc.AssetComputers where ac.DepartmentId == DepartmentId && ac.AssetId == OldAssetComputerId select ac).FirstOrNull();
                    if (OldAC != null)
                    {
                        lib.bwa.bigWebDesk.LinqBll.Context.AssetComputers NewAC = new lib.bwa.bigWebDesk.LinqBll.Context.AssetComputers()
                        {
                            DepartmentId            = DepartmentId,
                            AssetId                 = NewAsset.Id,
                            MotherboardSerial       = OldAC.MotherboardSerial,
                            BiosSerial              = OldAC.BiosSerial,
                            OSSerial                = OldAC.OSSerial,
                            RegisteredUser          = OldAC.RegisteredUser,
                            OperatingSystem         = OldAC.OperatingSystem,
                            RamMbytes               = OldAC.RamMbytes,
                            VideoDescription        = OldAC.VideoDescription,
                            VideoMemoryMbytes       = OldAC.VideoMemoryMbytes,
                            VideoHResolution        = OldAC.VideoHResolution,
                            VideoVResolution        = OldAC.VideoVResolution,
                            NetworkName             = OldAC.NetworkName,
                            NetworkDomain           = OldAC.NetworkDomain,
                            NetworkCard1IP          = OldAC.NetworkCard1IP,
                            NetworkCard1Mask        = OldAC.NetworkCard1Mask,
                            NetworkCard1Gate        = OldAC.NetworkCard1Gate,
                            NetworkCard1Address     = OldAC.NetworkCard1Address,
                            NetworkCard1Description = OldAC.NetworkCard1Description
                        };

                        dc.AssetComputers.InsertOnSubmit(NewAC);

                        CopyLogicalDrives(dc, DepartmentId, (int)OldAssetComputerId, (int)NewAsset.Id);
                        CopyPrinters(dc, DepartmentId, (int)OldAssetComputerId, (int)NewAsset.Id);
                        CopyProcessors(dc, DepartmentId, (int)OldAssetComputerId, (int)NewAsset.Id);
                        CopySoftwares(dc, DepartmentId, (int)OldAssetComputerId, (int)NewAsset.Id);
                    }
                }

                foreach (lib.bwa.bigWebDesk.LinqBll.Context.Assets OldAsset in OldAssets)
                {
                    var SchedTicketAssets = dc.SchedTicketAssets.Where(sta => sta.DId == DepartmentId && sta.AssetId == OldAsset.Id);
                    foreach (var SchedTicketAsset in SchedTicketAssets)
                    {
                        SchedTicketAsset.AssetId = NewAsset.Id;
                    }

                    var TicketAssets = dc.TicketAssets.Where(ta => ta.DId == DepartmentId && ta.AssetId == OldAsset.Id);
                    foreach (var TicketAsset in TicketAssets)
                    {
                        TicketAsset.AssetId = NewAsset.Id;
                    }

                    var Asset = dc.Assets.Where(a => a.Id == OldAsset.Id).FirstOrNull();
                    Asset.StatusId = (int)InactiveMergedStatusID;
                    Asset.MergedId = NewAsset.Id;
                }
                dc.SubmitChanges();
                return(null);
            }
        }