Beispiel #1
0
 public bool Add_KCPostRecord(KC_PostRecord KC_PostRecord)
 {
     try
     {
         KC_PostRecord = DataContext.KC_PostRecord.Add(KC_PostRecord);
         DataContext.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         return(false);
     }
 }
Beispiel #2
0
 public List <KC_DisMachine> Get_KC_DisMachines(KC_PostRecord KC_PostRecord)
 {
     try
     {
         return(DataContext.KC_PostRecord
                .Include("KC_DisMachines")
                .Where(i => i.Id == KC_PostRecord.Id)
                .FirstOrDefault().KC_DisMachines);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         return(null);
     }
 }
Beispiel #3
0
        public DevicePostResp(DataContext DataContext, LocalPostData LocalPostData)
        {
            Deviceid          = LocalPostData.KC_DeviceId;
            this.DataContext  = DataContext;
            IKC_ImplementBase = new KC_ImplementBase(this.DataContext);

            if (LocalPostData == null)
            {
                Exception = "Post data is empty!";
                return;
            }

            string record_time = DateTime.Now.ToString("HH:mm, dd/MM/yyyy");

            var kc_device = IKC_ImplementBase.Get_KCDevice(Deviceid);

            if (kc_device == null)
            {
                Exception = "KC_Device is null!";
                return;
            }

            var KC_PostRecord = new KC_PostRecord
            {
                UpdateTimeStr = record_time,
                KC_DeviceId   = kc_device.Id,
                BuildingId    = kc_device.BuildingId,
            };

            if (!IKC_ImplementBase.Add_KCPostRecord(KC_PostRecord))
            {
                Exception = "Can not add new post record to database!";
                return;
            }

            if (LocalPostData.Machines != null)
            {
                foreach (var machine in LocalPostData.Machines)
                {
                    var autoCutmachine = IKC_ImplementBase.Get_AutoCutMachine(machine.MachineName);
                    if (autoCutmachine == null)
                    {
                        continue;
                    }

                    var KC_DisMachine = new KC_DisMachine
                    {
                        AutoCutMachineId = autoCutmachine.Id,
                        KC_DeviceId      = kc_device.Id,
                        DateTimeStr      = record_time,
                        KC_PostRecordId  = KC_PostRecord.Id,
                        NewLeft          = machine.LeftKnife.NewKnife,
                        NewRight         = machine.RightKnife.NewKnife,
                        OldLeft          = machine.LeftKnife.OldKnife,
                        OldRight         = machine.RightKnife.OldKnife,
                    };

                    if (!IKC_ImplementBase.Add_KC_DisMachine(KC_DisMachine))
                    {
                        Exception = "Add KC_DisMachine to database failed!";
                    }
                }
            }
        }