public fileToSend GenerateContractDoc(int employeeId) { fileToSend file = new fileToSend(); byte[] docForm = GetDocumentFormById(2); if (docForm == null) { return(null); } RecruitmentData data = new RecruitmentData(_context); ContractWordDataModel dataModel = data.GetContractDataDoc(employeeId); if (dataModel == null) { file.data = docForm; file.name = "trudovoi dogovor"; file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return(file); } else { byte[] result = WordShedule.CreateContractDoc(dataModel, docForm); file.data = result; file.name = Translit(dataModel.fullName) + " trudovoi dogovor"; file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return(file); } }
public fileToSend GenerateVacationSheduleDoc() { VacationSheduleData vacData = new VacationSheduleData(_context); fileToSend file = new fileToSend(); byte[] docForm = GetDocumentFormById(4); //id графика отпусков в бд 4 if (docForm == null) { return(null); } ICollection <VacationSheduleWordModel> data = vacData.GetDataGenerateVacationSheduleDoc(); if (data == null) { file.data = docForm; file.name = "grafic otpuskov"; file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return(file); } else { byte[] result = WordShedule.CreateDoc(data, docForm); file.data = result; file.name = "grafic otpuskov"; file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return(file); } }
public fileToSend GetPartTimeTemplate(int idEmployee, int idDocument) //старая версия документа { fileToSend file = new fileToSend(); byte[] docForm = GetOldDocumentFormById(idDocument); //id графика "трудовой договор для совместителей.docx" в бд 3 if (docForm == null) { return(null); } PartTimeDataModel data = GetPartTimeData(idEmployee); if (data == null) { file.data = docForm; file.name = "trudovoi dogovor dla sovmestiteley"; file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return(file); } else { byte[] result = WordShedule.CreatePartTimeDoc(data, docForm); file.data = result; file.name = Translit(data.fullName) + " trudovoi dogovor dla sovmestiteley"; file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return(file); } }
public fileToSend GeneratePersonalEmployeeCard(int employeeId) { fileToSend file = new fileToSend(); EmployeeData empData = new EmployeeData(_context); var data = empData.GetDataEmployeeCardDoc(employeeId); byte[] result = WordShedule.CreateEmployeeCard(data); file.data = result; file.name = "Personal Employee Card"; file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return(file); }
public fileToSend GenerateVacationSheduleDoc(int idOldVersionDocument) { VacationSheduleData vacData = new VacationSheduleData(_context); fileToSend file = new fileToSend(); byte[] docForm = GetOldDocumentFormById(idOldVersionDocument); //id графика "трудовой договор для совместителей.docx" в бд 3 ICollection <VacationSheduleWordModel> data = vacData.GetDataGenerateVacationSheduleDoc(); if (data == null) { file.data = docForm; file.name = "grafic otpuskov"; file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return(file); } else { byte[] result = WordShedule.CreateDoc(data, docForm); file.data = result; file.name = "grafic otpuskov"; file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return(file); } }
public fileToSend GenerateTimeSheet(int date) { fileToSend file = new fileToSend(); file.name = "tabel za mesac"; file.mime = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; using (var stream = new MemoryStream()) using (SpreadsheetDocument document = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook)) { WorkbookPart workbookPart = document.AddWorkbookPart(); workbookPart.Workbook = new Workbook(); WorksheetPart worksheetPart = workbookPart.AddNewPart <WorksheetPart>(); FileVersion fv = new FileVersion(); fv.ApplicationName = "Microsoft Office Excel"; worksheetPart.Worksheet = new Worksheet(new SheetData()); WorkbookStylesPart wbsp = workbookPart.AddNewPart <WorkbookStylesPart>(); wbsp.Stylesheet = GenerateStyleSheet(); wbsp.Stylesheet.Save(); Columns lstColumns = worksheetPart.Worksheet.GetFirstChild <Columns>(); Boolean needToInsertColumns = false; if (lstColumns == null) { lstColumns = new Columns(); needToInsertColumns = true; } var dateTime = Utils.ConvertFromUnixTimestamp(date); string month_year = $"{dateTime.ToString("MMMMMMMM_yyyy")}"; DateTime last = new DateTime(dateTime.Year, dateTime.Month + 1, 1).AddDays(-1); uint lastDay = (uint)last.Day; lstColumns.Append(new Column() { Min = 1, Max = 1, Width = 20, CustomWidth = true }); for (uint i = 1; i <= lastDay; i++) { lstColumns.Append(new Column() { Min = i + 1, Max = i + 1, Width = 20, CustomWidth = true }); } if (needToInsertColumns) { worksheetPart.Worksheet.InsertAt(lstColumns, 0); } Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets()); Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Лист" }; sheets.Append(sheet); SheetData sheetData = worksheetPart.Worksheet.GetFirstChild <SheetData>(); Row row = new Row() { RowIndex = 1 }; sheetData.Append(row); uint styleNum = 1; InsertCell(row, 1, "", CellValues.String, styleNum); for (int i = 1; i <= lastDay; i++) { InsertCell(row, i + 1, ReplaceHexadecimalSymbols(i.ToString()), CellValues.String, styleNum); } TimeSheetData tsData = new TimeSheetData(_context); UInt32 rowIndex = 2; styleNum = 2; List <employeeShortData> users = getEmployee(); //все юзеры var timeSheet = tsData.GetTimeSheetByDate(date); //данные из timesheet var defaultCalendar = tsData.GetProductionCalendarDayByDate(date); // стандартный календарь //idUser, (день, значение) Dictionary <int, Dictionary <int, string> > dictDay = new Dictionary <int, Dictionary <int, string> >(); foreach (var user in users) { Dictionary <int, string> dict = new Dictionary <int, string>(); DateTime start = new DateTime(dateTime.Year, dateTime.Month, 1); for (int i = 1; i <= lastDay; i++) { if (user.rate != null) { var defaultCalendarDay = defaultCalendar.Where(x => x.date == start).FirstOrDefault(); if (defaultCalendarDay == null) { break; } var hourse = (float)user.rate.Value * defaultCalendarDay.countWorkHours; string resultTimeSheet = defaultCalendarDay.isHoliday ? "В(0)" : $"{ReplaceHexadecimalSymbols($"Ф({hourse})")}"; dict.Add(i, resultTimeSheet); } else { dict.Add(i, ""); } start = start.AddDays(1); } dictDay.Add(user.id, dict); } foreach (var time in timeSheet) { if (dictDay.ContainsKey(time.userId)) { var day = Utils.ConvertFromUnixTimestamp(time.date).Day; dictDay[time.userId][day] = getStringWorkCodes(time.userId, timeSheet, day); } } rowIndex = 2; foreach (var user in dictDay) { row = new Row() { RowIndex = rowIndex }; var nameUser = users.Where(x => x.id == user.Key).FirstOrDefault().name; InsertCell(row, 1, ReplaceHexadecimalSymbols(nameUser), CellValues.String, styleNum); for (int i = 1; i <= lastDay; i++) { var codeWork = user.Value[i]; InsertCell(row, i + 1, codeWork, CellValues.String, styleNum); } sheetData.Append(row); rowIndex++; } workbookPart.Workbook.Save(); document.Close(); file.data = stream.ToArray(); } return(file); }