/// <summary> /// Builds a <see cref="IOfferSettings"/> given an <see cref="OfferSettingsDto"/> /// </summary> /// <param name="dto"> /// The dto. /// </param> /// <returns> /// The <see cref="IOfferSettings"/>. /// </returns> public IOfferSettings BuildEntity(OfferSettingsDto dto) { var configurations = JsonConvert.DeserializeObject <IEnumerable <OfferComponentConfiguration> >(dto.ConfigurationData); var definitionCollection = new OfferComponentDefinitionCollection(); foreach (var config in configurations) { definitionCollection.Add(new OfferComponentDefinition(config)); } var settings = new OfferSettings(dto.Name, dto.OfferCode, dto.OfferProviderKey, definitionCollection) { Key = dto.Key, Active = dto.Active, OfferStartsDate = dto.OfferStartsDate.ConvertDateTimeNullToMinValue(), OfferEndsDate = dto.OfferEndsDate.ConvertDateTimeNullToMaxValue(), CreateDate = dto.CreateDate, UpdateDate = dto.UpdateDate }; settings.ResetDirtyProperties(); return(settings); }
public HomeController(IMapper mapper, IJackRepository jackRepository, IOptionsSnapshot <OfferSettings> options, IHostingEnvironment host, IToastNotification toastNotification) { _mapper = mapper; _jackRepository = jackRepository; _host = host; _toastNotification = toastNotification; _offerSettings = options.Value; }
/// <summary> /// Собрать пары маппингов столбцов /// </summary> /// <param name="offerSettings"></param> /// <param name="lastCol"></param> /// <returns></returns> private List <FieldAddress> GetFields(OfferSettings offerSettings, int lastCol) { List <FieldAddress> fields = new List <FieldAddress>(); int k = 0; foreach (OfferColumnMapping columnOffer in offerSettings.Columns) { if (string.IsNullOrEmpty(columnOffer.ColumnSymbol)) { continue; } ColumnMapping сolumnProject = _CurrentProject.Columns.Find(a => a.Name == columnOffer.Name); if (сolumnProject == null) { continue; } if (сolumnProject.Obligatory) { try { сolumnProject.Column = ExcelHelper.GetColumn(сolumnProject.ColumnSymbol, _sheetProject); int colPaste = lastCol + k; int colOffer = ExcelHelper.GetColumn(columnOffer.ColumnSymbol, _sheetProject); fields.Add(new FieldAddress() { ColumnOffer = colOffer, ColumnPaste = colPaste, MappingAnalysis = сolumnProject }); k++; } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } return(fields); }
/// <summary> /// Creates a <see cref="IOfferSettings"/> without saving it to the database /// </summary> /// <param name="name"> /// The name. /// </param> /// <param name="offerCode"> /// The offer code. /// </param> /// <param name="offerProviderKey"> /// The offer provider key. /// </param> /// <param name="componentDefinitions"> /// The component definitions. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> /// <returns> /// The <see cref="IOfferSettings"/>. /// </returns> public IOfferSettings CreateOfferSettings( string name, string offerCode, Guid offerProviderKey, OfferComponentDefinitionCollection componentDefinitions, bool raiseEvents = true) { Mandate.ParameterNotNullOrEmpty(name, "name"); Mandate.ParameterNotNullOrEmpty(offerCode, "offerCode"); Mandate.ParameterCondition(!Guid.Empty.Equals(offerProviderKey), "offerProviderKey"); Mandate.ParameterNotNull(componentDefinitions, "componentDefinitions"); var offerSettings = new OfferSettings(name, offerCode, offerProviderKey, componentDefinitions); if (raiseEvents) { if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IOfferSettings>(offerSettings), this)) { offerSettings.WasCancelled = true; } } return(offerSettings); }
/// <summary> /// Печать КП /// </summary> /// <param name="offer"></param> internal void Print(IProgressBarWithLogUI pb, string offerSettingsName) { // Ищем настройки столбцов OfferSettings offerSettings = _offerManager.Mappings.Find(s => s.Name == offerSettingsName); pb.Writeline($"Выбор листа {offerSettings.SheetName}"); // Лист данных КП Excel.Worksheet offerSheet = ExcelHelper.GetSheet(_offerBook, offerSettings.SheetName); pb.Writeline("Разгруппировка строк"); ShowSheetRows(offerSheet); ListAnalysis SheetAnalysis = new ListAnalysis(_sheetProject, _CurrentProject); pb.Writeline("Адресация полей"); /// Адресация полей КП List <FieldAddress> addresslist = GetFields(offerSettings, SheetAnalysis.ColumnStartPrint); Excel.Worksheet tamplateSheet = ExcelHelper.GetSheet(_wb, "Шаблоны"); pb.Writeline("Печать заголовков"); SheetAnalysis.PrintTitle(tamplateSheet, addresslist); int lastRowOffer = offerSheet.UsedRange.Row + offerSheet.UsedRange.Rows.Count - 1; pb.Writeline("Чтение массива данных"); // Массив загружаемых данных object[,] arrData = GetArrData(offerSheet, offerSettings.RowStart, lastRowOffer); int countRows = lastRowOffer - offerSettings.RowStart + 1; pb.SetSubBarVolume(countRows); pb.Writeline("Вывод строк"); for (int i = 1; i <= countRows; i++) { pb.SubBarTick(); if (pb.IsAborted) { throw new AddInException("Процесс остановлен."); } Record offerRecord = new Record { Addresslist = addresslist }; // Сбор данных foreach (FieldAddress field in addresslist) { object val = arrData[i, field.ColumnOffer]; string text = val?.ToString() ?? ""; offerRecord.Values.Add(field.ColumnPaste, val); if (field.MappingAnalysis.Name == Project.ColumnsNames[StaticColumns.Level]) { offerRecord.Level = int.TryParse(text, out int lvl) ? lvl : 0; } if (field.MappingAnalysis.Name == Project.ColumnsNames[StaticColumns.Number]) { offerRecord.Number = text; } if (field.MappingAnalysis.Check) { offerRecord.KeyFilds.Add(text); } } SheetAnalysis.PrintRecord(offerRecord); } pb.Writeline("Группировка столбцов"); SheetAnalysis.GroupColumn(); if (pb.IsAborted) { throw new AddInException("Процесс остановлен."); } pb.Writeline("Формулы \"Комментарии Спектрум к заявке участника\""); }
/// <summary> /// Печать КП /// </summary> /// <param name="offer"></param> internal void PrintBaseEstimate(IProgressBarWithLogUI pb, string offerSettingsName) { OfferSettings offerSettings = _offerManager.Mappings.Find(s => s.Name == offerSettingsName); Excel.Worksheet offerSheet = ExcelHelper.GetSheet(_offerBook, offerSettings.SheetName); ShowSheetRows(offerSheet); _sheetProject = ExcelHelper.GetSheet(_wb, _CurrentProject.AnalysisSheetName); /// Столбец "номер п.п." OfferColumnMapping colNumber = offerSettings.Columns.Find(x => x.Name == Project.ColumnsNames[StaticColumns.Number]); int lastRow = GetLastRow(offerSheet, colNumber.ColumnSymbol); int countRows = lastRow - offerSettings.RowStart + 1; pb.SetSubBarVolume(countRows);///100-1 List <(int, int)> colPair = new List <(int projectCollumn, int offerColumn)>(); int rightColumn = 10; foreach (OfferColumnMapping col in offerSettings.Columns) { if (string.IsNullOrEmpty(col.ColumnSymbol)) { continue; } ColumnMapping projectColumn = _CurrentProject.Columns.Find(a => a.Name == col.Name); if (!string.IsNullOrWhiteSpace(projectColumn?.ColumnSymbol ?? "")) { int cnP = ExcelHelper.GetColumn(projectColumn.ColumnSymbol, _sheetProject); int cnO = ExcelHelper.GetColumn(col.ColumnSymbol, _sheetProject); colPair.Add((cnP, cnO)); if (rightColumn < cnO) { rightColumn = cnO; } } } Excel.Range RngData = offerSheet.Range[offerSheet.Cells[offerSettings.RowStart, 1], offerSheet.Cells[lastRow, rightColumn]]; object[,] arrData = RngData.Value; for (int i = 1; i <= countRows; i++) { int rowPaste = _CurrentProject.RowStart + i - 1; pb.SubBarTick(); if (pb.IsAborted) { return; } foreach ((int projectCollumn, int offerColumn) in colPair) { object val = arrData[i, offerColumn]; string text = val?.ToString() ?? ""; Excel.Range cellPrint = _sheetProject.Cells[rowPaste, projectCollumn]; if (double.TryParse(text, out double number)) { cellPrint.Value = Math.Round(number, 2); } else if (!string.IsNullOrEmpty(text)) { cellPrint.Value = text; } } } pb.ClearSubBar(); }
private static OfferSettings CreateBaseEstimateSettings(string filename) { List <OfferColumnMapping> columns = new List <OfferColumnMapping> { new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.Name], ColumnSymbol = "M" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.Level], ColumnSymbol = "I" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.Cipher], ColumnSymbol = "L" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.Label], ColumnSymbol = "" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.Number], ColumnSymbol = "K" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.Unit], ColumnSymbol = "T" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.Amount], ColumnSymbol = "U" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.CostMaterialsPerUnit], ColumnSymbol = "V" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.CostMaterialsTotal], ColumnSymbol = "W" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.CostWorksPerUnit], ColumnSymbol = "X" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.CostWorksTotal], ColumnSymbol = "Y" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.CostTotalPerUnit], ColumnSymbol = "Z" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.CostTotal], ColumnSymbol = "AA" }, new OfferColumnMapping() { Name = Project.ColumnsNames[StaticColumns.Comment], ColumnSymbol = "AB" } }; OfferSettings BaseEstimateSettings = new OfferSettings() { Name = "Базовая оценка", FileName = filename, RowStart = 23, SheetName = "Рсч-П", Columns = columns }; BaseEstimateSettings.Save(); return(BaseEstimateSettings); }