public async Task <IActionResult> OnPostExportAsync(int currentPage, int pageSize, string categoryName, string sortOrder) { Forms = await InitiateView(currentPage, pageSize, categoryName, sortOrder); string sWebRootFolder = _hostingEnvironment.WebRootPath; string sFileName = @"Forms Data.xlsx"; string URL = string.Format("{0}://{1}/{2}", Request.Scheme, Request.Host, sFileName); FileInfo file = new FileInfo(Path.Combine(sWebRootFolder, sFileName)); var memory = new MemoryStream(); using (var fs = new FileStream(Path.Combine(sWebRootFolder, sFileName), FileMode.Create, FileAccess.Write)) { ExcelPackage package = new ExcelPackage(); package.Workbook.Worksheets.Add("Forms"); ExcelWorksheet formsSheet = package.Workbook.Worksheets["Forms"]; using (var range = formsSheet.Cells["A1:C1"]) { range.Style.Font.Bold = true; range.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(23, 121, 186)); range.Style.Font.Color.SetColor(Color.White); } formsSheet.Cells[1, 1].Value = "Form Id"; formsSheet.Cells[1, 2].Value = "Form Name"; formsSheet.Cells[1, 3].Value = "Form Status"; formsSheet.Cells[1, 1, 1, 3].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thick); for (int r = 0; r < Forms.Count(); r++) { Form formC = _context.Forms.FirstOrDefault(c => c.Form_ID == Forms.ToList()[r].Form_ID); formsSheet.Cells[r + 2, 1].Value = Forms.ToList()[r].Form_ID; formsSheet.Cells[r + 2, 2].Value = Forms.ToList()[r].FormName; formsSheet.Cells[r + 2, 3].Value = Forms.ToList()[r].Status; formsSheet.Cells[1, 1, 1, 3].AutoFitColumns(); } package.SaveAs(fs); package.Dispose(); } using (var stream = new FileStream(Path.Combine(sWebRootFolder, sFileName), FileMode.Open)) { await stream.CopyToAsync(memory); } memory.Position = 0; TempData["StatusMessage"] = "Forms successfully exported to file " + sFileName; return(File(memory, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", sFileName)); }
public override IList <ValidationException> Review() { IList <ValidationException> answer = new List <ValidationException>(); // Ensure 40% of applicants have signed the intent to purchase form var projectInfo = (CcEcpInfo)ProjectInfo; var requiredTenantAgreements = Math.Round(.4f * projectInfo.NumberOfUnits); int numberofSignedTenants = Forms.Count(x => (x is TenantIntentToPurchase || x is TenantIntentToAcceptOfferOfLtl) && x.IsAssigned); if (numberofSignedTenants < requiredTenantAgreements) { answer.Add(new ValidationException($"Currently only {requiredTenantAgreements} have either signed their intent to purchase" + " the unit or accept their offer of lifetime lease. " + $"This application requires at least {requiredTenantAgreements}")); } return(answer); }
private void CreateSearchMenuItems() { if (Refresh == true) { MenuExMon.Items.RemoveAt(MenuExMon.Items.Count - 1); } string[] Forms; string FormsList = ""; string UserType = CommFunc.Fetch_DB_Value("Access", "UserDim", "Username = '******'"); if (UserType == "SUPER USER") { FormsList = CommFunc.Fetch_DB_Value("FrmName", "FormDim", ""); } else if (UserType == "LIMITED") { FormsList = CommFunc.Fetch_DB_Value("FrmName", "FormDim", "Access in ('LIMITED', 'ALL')"); } else { FormsList = CommFunc.Fetch_DB_Value("FrmName", "FormDim", "Access = 'ALL'"); } Forms = FormsList.Split('|'); int Counter = 0; ToolStripMenuItem DimensionalView = new ToolStripMenuItem(); DimensionalView.Text = "Dimensional View"; while (Counter < Forms.Count()) { ToolStripMenuItem DView = new ToolStripMenuItem(Forms[Counter]); DView.Click += DimensionalViewClick; DimensionalView.DropDownItems.Add(DView); Counter++; } MenuExMon.Items.Add(DimensionalView); }
public void Save(IEnumerable <string> removeMasters) { Log.Info("Saving plugin " + fileName); byte thisPluginNumber = context.Plugins.GetPluginNumber(this); // Collect all masters (Always add the main plugin as master) HashSet <byte> collectedMasters = new HashSet <byte>() { 0 }; // Collect all referenced form IDs HashSet <uint> referencedFormIds = GetReferencedFormIds(); foreach (var id in referencedFormIds) { if (!context.Forms.Contains(id)) { //Log.Warning("Unable to determine the master of unresolved reference [0x{0:X8}].", id); // Skip unresolved references, a warning will be issued while writing // Handle unresolved references as best as possible, derive plugin number from formId and add it as a master byte assumedPluginNumber = (byte)(id >> 24); if (assumedPluginNumber != thisPluginNumber) { if (!collectedMasters.Contains(assumedPluginNumber)) { collectedMasters.Add(assumedPluginNumber); } } Log.Warning("Assumed unresolved form {0:X8} plugin {1}.", id, context.Plugins[assumedPluginNumber].FileName); } else { var form = context.Forms[id]; // Find the original form // to add the original plugin which adds it as the master and not the last plugin which edits the referenced form while (form.OverridesForm != null) { form = form.OverridesForm; } // Add if not of the current plugin if (form.PluginNumber != thisPluginNumber) { if (!collectedMasters.Contains(form.PluginNumber)) { collectedMasters.Add(form.PluginNumber); } } } } // Form IDs this plugin is overriding var overridenForms = Forms.Where(f => f.IsOverriding); foreach (var form in overridenForms) { // Go through all overriden forms until the original form var overridenForm = form.OverridesForm; while (overridenForm != null) { if (!collectedMasters.Contains(overridenForm.PluginNumber)) { collectedMasters.Add(overridenForm.PluginNumber); } // Next overriden form by this form overridenForm = overridenForm.OverridesForm; } } // Add masters (will be sorted by pluginNumber) foreach (var number in collectedMasters.OrderBy(i => i)) { var masterFileName = context.Plugins[number].FileName; // Force remove masters if (removeMasters != null && removeMasters.Contains(masterFileName)) { continue; } // Already added (when appending) if (header.GetMasterFiles().Contains(masterFileName)) { continue; } header.AddMasterFile(masterFileName); Log.Fine("Added master: {0}", masterFileName); } //// Make a backup of existing file //string backupPath = null; //if (File.Exists(path)) //{ // backupPath = path + "-" + (ulong)DateTime.Now.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; // File.Move(path, backupPath); //} if (!Forms.Any()) { Log.Warning("No forms to write. Empty plugin will be generated."); } int count = 0; long total = Forms.Count(); using (var progress = Display.StartProgress("Saving plugin")) { // Save plugin to memory stream using (var stream = new MemoryStream()) { using (var writer = context.CreateWriter(stream)) { // Prepare reference mapper writer.ReferenceMapper = new PluginReferenceMapper(this); // Write header header.PluginVersion = context.GetLatestPluginVersion(); writer.WriteHeader(header); Log.Fine("Written header record"); // Write forms by type foreach (var type in context.Forms.GetFormKinds()) { var formOfType = Forms.Where(f => f.FormKind == type); if (formOfType.Any()) { Log.Fine("Writting {0}", type); } foreach (var form in formOfType) { writer.WriteRecord(form.Record, form.FormId); count++; progress.Update(count, total, "{0}:{1}", FileName, type); } } Log.Fine("Written {0} form(s)", count); writer.Close(); // Write memory stream to file // only if changed stream.Position = 0; var file = context.DataFileProvider.GetDataFile(FileMode.Create, fileName); if (!file.CopyFrom(stream, true)) { Log.Info("New plugin content is the same as that of the existing plugin."); } } } } Log.Info("Plugin saved"); }