public KnifeCpatureDevice(KC_Device KC_Device) { InitializeComponent(); UpdateTimer.Tick += UpdateTimer_Tick; Menu = new ContextMenu(new MenuItem[] { new MenuItem("Export to excel", ExportToExcel_Callback, Shortcut.CtrlE) }); this.ContextMenu = Menu; DataContext = new DataContext(); this.KC_Device = KC_Device; KC_ImplementBase = new KC_ImplementBase(DataContext); UpdateDeviceScreen(); }
public List <KnifeCaptureTracking> Get_KnifeCaptureTrackings(KC_Device KC_Device) { try { return(DataContext.KC_Device .Include("KnifeCaptureTrackings") .Where(i => i.Id == KC_Device.Id) .FirstOrDefault().KnifeCaptureTrackings); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }
public KC_PostRecord Get_KC_LastPostRecord(KC_Device KC_Device) { try { return(DataContext.KC_PostRecord .Where(i => i.KC_DeviceId == KC_Device.Id) .OrderByDescending(i => i.Id) .First()); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }
public List <KC_PostRecord> Get_KC_PostRecord(KC_Device KC_Device) { try { return(DataContext.KC_Device .Include("KC_PostRecords") .Where(i => i.Id == KC_Device.Id) .FirstOrDefault().KC_PostRecords); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }
public List <KC_DisMachine> Get_KC_DisMachines(KC_Device ParentDevice) { try { return(DataContext.KC_Device .Include("KC_DisMachines") .Where(i => i.Id == ParentDevice.Id) .FirstOrDefault().KC_DisMachines); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }
public List <KC_PostRecord> Get_KC_PostRecord(KC_Device KC_Device, DateTime GetDate) { try { string request_date = GetDate.ToString("dd/MM/yyyy"); return(DataContext.KC_PostRecord .Where(i => i.KC_DeviceId == KC_Device.Id && i.UpdateTimeStr.Contains(request_date)) .ToList()); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }
public static string ExportToExcel_KC_Device(KC_Device KC_Device, string StorageFolder, DateTime ExportDateOfWeek) { // get all post file on date var records = KC_ImplementBase.Get_KC_PostRecord(KC_Device, ExportDateOfWeek); if (records == null) { records = KC_ImplementBase.Get_KC_PostRecord(KC_Device); if (records == null) { return(null); } } // get last post file var last_record = records.OrderByDescending(i => i.Id).FirstOrDefault(); if (last_record == null) { return(null); } var machines = KC_ImplementBase.Get_KC_DisMachines(last_record); if (machines == null) { return(null); } string FullFilePath = GetCurrentEditingFilePath(StorageFolder, ExportDateOfWeek); // Initialize CurrentEditFile FileInfo CurrentEditFile = new FileInfo(FullFilePath); using (ExcelPackage package = new ExcelPackage(CurrentEditFile)) { int SheetIndex = 0; while (package.Workbook.Worksheets.Count() < machines.Count) { package.Workbook.Worksheets.Add(Guid.NewGuid().ToString()); } foreach (var item in machines) { var autoCutMachine = KC_ImplementBase.Get_AutoCutMachine((int)item.AutoCutMachineId); if (autoCutMachine == null) { continue; } SheetIndex++; string SheetName = $"{autoCutMachine.MachineName}"; package.Workbook.Worksheets[SheetIndex].Name = SheetName; ExcelWorksheet CurrentEditSheet = package.Workbook.Worksheets[SheetIndex]; ExportToExcel_KC_Machine(autoCutMachine, CurrentEditSheet, ExportDateOfWeek); } package.Save(); } return(FullFilePath); }