public bool UpdateToExcel(ESubmit ESubmit, ExcelPackage excelPackage, ref string Notes) { DateTime Time = ESubmit.Date; int currentHour = Time.Hour; int Area_Id = ESubmit.AreaId; int Person_Id = ESubmit.PersonId; try { var ECheckPerson = Data_Services.Get_CheckPerson(Person_Id); ExcelWorksheet currentSheet = excelPackage.Workbook.Worksheets[Area_Id]; int currentTime = 0; bool reset_note_text = false; ExcelRange NoteCell; for (int checkItem = 0; checkItem < ESubmit.ECheckingDailys.Count; checkItem++) { bool add_note = false; for (int timeLine = 0; timeLine < 12; timeLine++) { if (currentHour == 0 && timeLine == 0) { currentTime = 0; if (!reset_note_text) { currentSheet.Cells[ESubmit.ECheckingDailys.Count + 6, currentTime].Value = ""; } reset_note_text = true; if (ESubmit.ECheckingDailys[checkItem].Status == 0xFF) { currentSheet.Cells[checkItem + 5, 1].Value = "X"; currentSheet.Cells[checkItem + 5, 1].Style.Font.Bold = true; currentSheet.Cells[checkItem + 5, 2].Value = string.Empty; } else { currentSheet.Cells[checkItem + 5, 1].Value = string.Empty; currentSheet.Cells[checkItem + 5, 2].Value = "X"; currentSheet.Cells[checkItem + 5, 2].Style.Font.Bold = true; add_note = true; } } else { bool update = false; if (currentHour / 2 == timeLine) { currentTime = timeLine * 2 + 2; update = true; } else if (currentHour == timeLine * 2 + 1) { currentTime = timeLine * 2 + 1; update = true; } if (update) { if (!reset_note_text) { currentSheet.Cells[ESubmit.ECheckingDailys.Count + 6, currentTime].Value = ""; } reset_note_text = true; if (ESubmit.ECheckingDailys[checkItem].Status == 0xFF) { currentSheet.Cells[checkItem + 5, timeLine * 2 + 2].Value = "X"; currentSheet.Cells[checkItem + 5, timeLine * 2 + 2].Style.Font.Bold = true; currentSheet.Cells[checkItem + 5, timeLine * 2 + 1 + 2].Value = string.Empty; } else { currentSheet.Cells[checkItem + 5, timeLine * 2 + 2].Value = string.Empty; currentSheet.Cells[checkItem + 5, timeLine * 2 + 1 + 2].Value = "X"; currentSheet.Cells[checkItem + 5, timeLine * 2 + 1 + 2].Style.Font.Bold = true; add_note = true; } } } } if (add_note) { add_note = false; int?note = ESubmit.ECheckingDailys[checkItem].ECheckNotesId; if (note != null) { var ENote = Data_Services.Get_ECheckNote((int)note); NoteCell = currentSheet.Cells[ESubmit.ECheckingDailys.Count + 6, 2]; string text = Notes; text = $"{text} [{ESubmit.Date.ToString("HH:mm")}->{ENote.NoteName}]"; NoteCell.Value = text; Notes = text; } } } if (ECheckPerson != null) { currentSheet.Cells[ESubmit.ECheckingDailys.Count + 5, currentTime].Value = ECheckPerson.Name; } excelPackage.Save(); return(true); } catch (Exception ex) { return(false); } }
public string Update_Database(ECheckSubmit AreaData) { string Excp = string.Empty; Data_Services Data_Services = new Data_Services(DataContext); try { var area = Data_Services.Get_ECheckArea(AreaData.Area_Id); if (area == null) { return($"Can not find aread with id {AreaData.Area_Id}"); } if (area.ECheckings.Count != AreaData.CheckItems.Count) { return($"Total items not equal"); } var person = Data_Services.Get_CheckPerson(AreaData.CheckPerson_Id); if (person == null) { return($"Can not find person Id: {AreaData.CheckPerson_Id}"); } ESubmit ESubmit = new ESubmit { AreaId = area.id, PersonId = person.id, Date = DateTime.Now, UpdateTime = DateTime.Now.ToString("hh:mm tt, dd/MM/yy"), }; // update new esubmit Data_Services.Update_ESubmit(ESubmit); foreach (var item in AreaData.CheckItems) { var CheckItem = Data_Services.Get_ECheckItem(item.Item); var submit_data = new ECheckingDaily { ECheckAreaCode = area.AreaCode, ECheckAreaId = area.id, ECheckItemId = CheckItem.id, ECheckItemCode = CheckItem.ECheckItemCode, Status = item.Status, Time = DateTime.Now, CheckingPersonId = person.id, ESubmitId = ESubmit.Id, }; if (item.Status == 0x00) { submit_data.ECheckNotesId = item.Note; } if (!Data_Services.Update_ECheckDaily(submit_data)) { Excp = $"Error when add item {item.Item} to database"; } } return(Excp); } catch (Exception ex) { return(ex.ToString()); } }