Пример #1
0
        public void DAL_DeleteEquipment(string equipmentid)
        {
            EQUIPMENT eq = db.EQUIPMENTs.Where(p => p.equipmentId == equipmentid).SingleOrDefault();

            db.EQUIPMENTs.Remove(eq);
            db.SaveChanges();
        }
Пример #2
0
        public void DAL_UpdateEquipment(EQUIPMENT eq2)
        {
            var sup = db.EQUIPMENTs.Where(p => p.equipmentId == eq2.equipmentId).SingleOrDefault();

            sup.roomId             = eq2.roomId;
            sup.equipmentId        = eq2.equipmentId;
            sup.equipmentName      = eq2.equipmentName;
            sup.company            = eq2.company;
            sup.dateOfInstallation = eq2.dateOfInstallation;
            db.SaveChanges();
        }
Пример #3
0
        public int DAL_CheckEquipment(EQUIPMENT eq)
        {
            int a = 1;

            foreach (var i in db.EQUIPMENTs)
            {
                if (i.equipmentId == eq.equipmentId)
                {
                    a = 0;
                    break;
                }
            }
            return(a);
        }
Пример #4
0
 public void DAL_SetEquipment(EQUIPMENT eq)
 {
     db.EQUIPMENTs.Add(eq);
     db.SaveChanges();
 }
Пример #5
0
        protected IEquipmentActionRecord UpdateEquipmentByAction(IEquipmentActionRecord actionRecord, ref string OperationResult)
        {
            //Steps in this method:
            //1- Create a record in ACTION_TAKEN_HISTORY Table with no data in EquipmentSMU and EquipmentLTD
            //2- Update Equipment, Systems and Components life
            //3- Update ACTION_TAKEN_HISTORY Table with New EquipmentSMU and EquipmentLTD
            //4- Return an IEquipmentActionRecord to use in the occuring action

            actionLifeUpdate = new ActionLifeUpdate();
            DALEquipment     = _context.EQUIPMENTs.Find(actionRecord.EquipmentId);
            if (DALEquipment == null)
            {
                return(null);
            }
            //Step1
            int aType = 0;

            try
            {
                aType = (int)actionRecord.TypeOfAction;
            }
            catch { aType = (int)ActionType.NoActionTakenYet; }

            OperationResult += "Start insert into ACTION_TAKEN_HISTORY" + System.Environment.NewLine;
            var k = new ACTION_TAKEN_HISTORY
            {
                action_type_auto = aType,
                cmu                = 0,
                event_date         = actionRecord.ActionDate,
                entry_date         = DateTime.Now,
                entry_user_auto    = actionRecord.ActionUser.Id,
                equipmentid_auto   = actionRecord.EquipmentId,
                cost               = (long)actionRecord.Cost,
                equipment_ltd      = 0, //Will be updated in Step3
                equipment_smu      = 0, //Will be updated in Step3
                comment            = actionRecord.Comment,
                GETActionHistoryId = actionRecord.GETHistoryId,
                recordStatus       = (int)RecordStatus.MiddleOfAction
            };

            _context.ACTION_TAKEN_HISTORY.Add(k);
            try
            {
                _context.SaveChanges();
                OperationResult += "Succeded" + System.Environment.NewLine;
                DALRecord        = k;
            }
            catch (Exception ex)
            {
                OperationResult += "Error :" + ex.Message + System.Environment.NewLine;
                Message          = "Saving action history failed!";
                return(null);
            }

            if (longNullableToint(k.history_id) == 0)
            {
                OperationResult += "Error: Returned Id is not valid" + System.Environment.NewLine;
                Message          = "Action history has not been saved successfully";
                return(null);
            }
            actionLifeUpdate.ActionTakenHistory = k;
            int EquipmentActualLife = actionRecord.EquipmentActualLife;
            int EquipmentCurrentSMU = actionRecord.ReadSmuNumber;

            //End of Step 1
            if (k.action_type_auto != (int)ActionType.UpdateSetupEquipment)
            {
                //Step2
                OperationResult += "Updating Equipment, Systems and Components life " + System.Environment.NewLine;
                if (!UpdateEquipmentLife(actionRecord.EquipmentId, actionRecord.ReadSmuNumber, actionRecord.ActionUser.Id, longNullableToint(k.history_id), actionRecord.ActionDate, ref OperationResult))
                {
                    return(null);
                }
                EquipmentActualLife = GetEquipmentLife(actionRecord.EquipmentId, actionRecord.ActionDate, true);
                EquipmentCurrentSMU = GetEquipmentSerialMeterUnit(actionRecord.EquipmentId, actionRecord.ActionDate, true);

                if (EquipmentActualLife < 0 || EquipmentCurrentSMU < 0)
                {
                    OperationResult += "Equipment Actual Life OR Equipment Current SMU is invalid" + System.Environment.NewLine;
                    Message          = "Stored Life or SMU of the equipment is less than zero and not correct!";
                    return(null);
                }
            }

            //Step3
            k.equipment_ltd         = EquipmentActualLife;
            k.equipment_smu         = EquipmentCurrentSMU;
            _context.Entry(k).State = System.Data.Entity.EntityState.Modified;

            try
            {
                OperationResult += "Updating Action Taken History..." + Environment.NewLine;
                _context.SaveChanges();
                OperationResult += "Succeded" + Environment.NewLine;
            }
            catch (Exception ex)
            {
                OperationResult += "Error :" + ex.Message + Environment.NewLine;
                Message          = "Updating action history failed!";
                return(null);
            }

            //Step4
            actionRecord.Id = (int)k.history_id;
            actionRecord.EquipmentActualLife = EquipmentActualLife;
            return(actionRecord);
        }
Пример #6
0
        public async Task <Tuple <long, string> > CreateNewEquipment(SetupEquipmentViewModel e)
        {
            var mmta = await _context.LU_MMTA.Where(m => m.model_auto == e.ModelId && m.make_auto == e.MakeId).FirstOrDefaultAsync();

            var creator = await _context.USER_TABLE.FindAsync(e.CreatedByUserId);

            string[] LogoArr        = e.Photo.Split(',');
            string   equipmentPhoto = "";

            if (LogoArr.Length > 1)
            {
                equipmentPhoto = LogoArr[1].Trim();
            }

            var mmtaEntity = new DAL.LU_MMTA()
            {
                make_auto  = e.MakeId,
                model_auto = e.ModelId,
                type_auto  = mmta.type_auto,
                app_auto   = e.ApplicationId,
                service_cycle_type_auto = 1,
                expiry_date             = DateTime.MaxValue,
                created_date            = DateTime.Now,
                created_user            = creator.username
            };

            _context.LU_MMTA.Add(mmtaEntity);
            try {
                await _context.SaveChangesAsync();
            } catch (Exception ex)
            {
                return(Tuple.Create((long)-1, "Failed to create the MMTA record. " + ex.Message + ". " + ex.InnerException != null ? ex.InnerException.Message : ""));
            }

            var equipmentEntity = new DAL.EQUIPMENT()
            {
                serialno                 = e.SerialNumber,
                unitno                   = e.UnitNumber,
                mmtaid_auto              = mmtaEntity.mmtaid_auto,
                measure_unit             = 1,
                op_hrs_per_day           = e.HoursOfUsePerDay,
                op_dist_uom              = 0,
                op_range                 = "DEFAULT",
                smu_at_start             = e.Smu,
                distance_at_start        = 0,
                smu_at_end               = 100000,
                distance_at_end          = 100000,
                currentsmu               = e.Smu,
                currentdistance          = 0,
                last_reading_date        = e.Date.ToLocalTime().Date,
                notes                    = "",
                LTD_at_start             = e.Ltd,
                crsf_auto                = e.JobsiteId,
                purchase_op_hrs          = e.Smu,
                purchase_op_dist         = 0,
                purchase_date            = e.Date.ToLocalTime().Date,
                deprate                  = 0,
                created_date             = DateTime.Now,
                created_user             = creator.username,
                modified_date            = DateTime.Now,
                modified_user            = creator.username,
                equip_status             = e.StatusId,
                update_accept            = true,
                da_inclusion             = true,
                dtd_at_start             = 0,
                ranking_auto             = Convert.ToByte((e.RankingId == null || e.RankingId < 0) ? 0 : e.RankingId),
                secondary_uom_isHours    = false,
                secondary_uom_isDistance = false,
                secondary_uom_isKWHours  = false,
                secondary_uom_isCalendar = false,
                secondary_uom_isFuelBurn = false,
                health_review_auto       = 0,
                vision_link_exist        = false,
                UsedMonday               = e.UsedMonday,
                UsedTuesday              = e.UsedTuesday,
                UsedWednesday            = e.UsedWednesday,
                UsedThursday             = e.UsedThursday,
                UsedFriday               = e.UsedFriday,
                UsedSaturday             = e.UsedSaturday,
                UsedSunday               = e.UsedSunday,
                EquipmentPhoto           = equipmentPhoto.Length > 0 ? Convert.FromBase64String(equipmentPhoto) : null,
                InspectEvery             = e.InspectEvery,
                InspectEveryUnitTypeId   = e.InspectEveryUnitTypeId
            };

            _context.EQUIPMENTs.Add(equipmentEntity);
            try
            {
                await _context.SaveChangesAsync();
            } catch (Exception ex)
            {
                return(Tuple.Create((long)-1, "Failed to create the new equipment. " + ex.Message + ". " + ex.InnerException != null ? ex.InnerException.Message : ""));
            }

            var moduleRegEntity = new DAL.MODULE_REGISTRATION_EQUIPMENT()
            {
                equipmentid_auto           = equipmentEntity.equipmentid_auto,
                pm_servicing               = true,
                pm_servicing_last_reg_date = DateTime.Now,
                backlog = true,
                backlog_last_reg_date           = DateTime.Now,
                scheduler                       = true,
                scheduler_last_reg_date         = DateTime.Now,
                trakalerts                      = true,
                trakalerts_last_reg_date        = DateTime.Now,
                component_manager               = true,
                component_manager_last_reg_date = DateTime.Now,
                tyre = true,
                tyre_last_reg_date = DateTime.Now,
                general_inspection = true,
                general_inspection_last_reg_date = DateTime.Now,
                get = true,
                get_last_reg_date           = DateTime.Now,
                undercarriage               = true,
                undercarriage_last_reg_date = DateTime.Now,
                body_bowl = true,
                body_bowl_last_reg_date = DateTime.Now,
                modified_user           = creator.username,
                rail = true,
                rail_last_reg_date      = DateTime.Now,
                dashboard               = true,
                dashboard_last_reg_date = DateTime.Now,
            };

            _context.MODULE_REGISTRATION_EQUIPMENT.Add(moduleRegEntity);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(Tuple.Create((long)-1, "Failed to create the equipment secondary records. " + ex.Message + ". " + ex.InnerException != null ? ex.InnerException.Message : ""));
            }
            var getSetupEvent = new GETCore.Classes.GETEquipment();

            getSetupEvent.equipmentSetupEvent(equipmentEntity.equipmentid_auto, e.Smu, e.Ltd, e.CreatedByUserId != null ? (long)e.CreatedByUserId : -1);

            if (e.UnsyncedId > 0)
            {
                new BLL.Core.Domain.Inspection(new DAL.UndercarriageContext()).MatchMobileInspection((int)equipmentEntity.equipmentid_auto, e.UnsyncedId);
            }

            return(Tuple.Create(equipmentEntity.equipmentid_auto, "Your equipment has been added successfully. "));
        }