|
Gerry Schmitz wrote: You mean: C# and SQL.
Me? My comment does say C#?
And although I was thinking about SQL I did mean just database in the first part.
But I also was not sure about what persistent data store they would be using. Their post did suggest something odd so I wanted it generic.
And re-reading I can see that the database is 'firebase' which is in fact a NoSQL database. So learning SQL is not appropriate in this case.
|
|
|
|
|
"Everything" I see dealing with Enums (in different name spaces) is lots of "recasting" to the underlying type or lots of namespace qualifying.
I needed to integrate "duplicate" Enums in different exe's and dll's that were "not the same" (or easily accessible) due to namespaces.
Now in my sender "POCO" I might have:
[DataMember]
public ServiceArm ServiceArm { get; set; } = ServiceArm.Undefined;
So I added to the POCO:
public string ServiceName => Enum.GetName( typeof( ServiceArm ), this.ServiceArm );
And in the consumer (different namespace; different exe / dll):
block.ServiceArm = Enum.Parse<ServiceArm>( unit.ServiceName );
No fiddling with namespaces; no obscure casting.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I may not be getting this correctly.
Are you trying to make use of several different independent enum definitions in different name spaces as if they were one, matching them on the enum name?
You can of course set up a demo to show that it works (today), but wouldn't it lead to a lot of maintenance problems, if the various enum definitions are updated independently of each other?
(I can't tell how much I miss a proper enum concept like the one we had in Pascal, where "underlaying type" was irrelevant: enums are not names of integers. They do not have any "underlaying type" but are literal values in the same sense as 'true' and 'false' in their own right as enum constants. 'using myEnumDefs' make these enum symbol available just like 'using myFunctions' make the function symbols available. But even programmers who never coded C/C++ seems to have adopted the idea that enums 'really' are integers with a name!)
|
|
|
|
|
What is an "interface"? I "tell" you a "valid" (Enum) "name" is the "interface" to the .exe / dll. And who tells who what to use? (I also happen to be serializing and deserializing)
The enum happens to be a handy implementation in this case.
The alternative is: a "standard" dll with "every" enum that anybody could possible need: creating one big dependency.
It also implies, I have to rewrite every exe / dll to "migrate out" every reference to this "master" enum into it's own dll.
(You had musing about a "universal language": this pattern can give different "names" based on context that "translate" to different enum values)
The whole "point" was to not have to muck with xxxx.aaa.xxx.ssss.ServiceArm, etc.
(If you don't code in C#, this is probably meaningless)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
OK, I did not really intend to bemoan your use of the available facilities.
I was more focused on the lack of facilities, that could have been provided if C# had a proper enumeration type. So it was a sidetrack.
Now that C# does not provide a proper enumeration type, your workaround is fair enough. I am not happy with such workarounds being required, but I accept them - reluctantly.
|
|
|
|
|
What is a "proper" enum? The issue I'm addressing pertains to classes as well; which is "long namespaces".
You ignored the whole "central maintenance" issue.
If I had implemented it as a dictionary, would that have made a difference? No, just clumsier.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
The simpler solution for you is probably setting up an #include file with sequence of #define entries defining the proper constant names for you.
|
|
|
|
|
The actual translation in messaging layers should not be a significant problem.
Problems come about more because messages end up being modified far more than they should - probably because insufficient design or because there is no adherence to longer term roadmaps.
But if enums are a problem then move them, and only them into their own namespace (and dll.) Or redesign so static values are not used at all. That does of course trade strictness for ease of use.
|
|
|
|
|
The "Name", of the enum "value", is the "key", not the value.
The "personal" Enums happen to be "views" (I just made that up)
The fact that one uses bytes (I do) or ints, makes no difference.
The more I think about it, the more I like it.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Hi,
I have implemented a billing application in c#. I have stored customer data and billing data into sqlite database. I have created Setup project for the same. I need help here, when I install application, sqlite database(*.db) was not created automatically. I tried couple of custom actions(Install and commit) but sqlite database was not created during installation. Let me know if anyone have solution?
Thank You!
|
|
|
|
|
Do you have an empty copy of the database that you're looking to install, or are you wanting the install program to run a Sqlite command to create a new, empty database file?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
You could create the database from code; use scripts or code to create your tables.
It is far easier to create a DB that contains all tables but no data. Then you simply copy the empty DB to the appropriate location using the installer.
That means, NOT in the "Program Files" directory. I'd expect this DB to live in a single user-account. If you want multiple users, then SQLite isn't your best starting-ground.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I am new to ASP.NET Core. I have written a code that works on my local computer but when I publish the app to our test environment the behavior is strange. The scenario is as follows:
When the user clicks a link, the app exports data to an excel file which is downloaded. On my PC / dev env, the data is downloaded fine and you can see it on the Excel sheet however on Test, it is rather the webpage that is on the Excel sheet hence giving a message "The file format and extension of summary.xls don't match. The file could be corrupted or unsafe" when you open the Excel file.
Find below my code:
In ReportController.cs
[HttpGet]
public ActionResult ExportSummaryToExcel(string startDate, string endDate, string postalCode)
{
string strStartDate = startDate;
string strEndDate = endDate;
string strRequestedPostalCode = postalCode;
ViewBag.StartDate = startDate;
ViewBag.EndDate = endDate;
ViewBag.RequestedPostalCode = postalCode;
DataTable rsReportDataByPostalCode = _summaryByAgeStagePostalCodeService.
GetSummaryByPostalCode(strStartDate + " 00:00:00.000000000", strEndDate + " 23:59:59.000000000", strRequestedPostalCode);
ReportViewModel reportViewModel = new ReportViewModel();
reportViewModel.ReportDataByPostalCodeTable = rsReportDataByPostalCode;
return View("_ExportSummaryToExcel", reportViewModel);
}
In _ExportSummaryToExcel.cshtml
@using System.Data;
@using BHTS.Service;
@using Microsoft.AspNetCore.Hosting;
@using NPOI.HSSF.UserModel;
@using NPOI.SS.UserModel;
@using NPOI.Util;
@using System.IO;
@using Microsoft.AspNetCore.Http;
@using System.Web;
@using NPOI.XSSF.UserModel;
@inject IHostingEnvironment _hostingEnvironment
@inject IHttpContextAccessor HttpContextAccessor
@model BHTS.Service.ViewModels.ReportViewModel
@{
Context.Response.ContentType = "application/vnd.ms-excel";
Context.Response.Headers.Add("Content-Disposition", "attachment; filename=\"Summary.xls\"");
}
@{
string strExceptionMessage ;
try{
string strNewPostalCode = "";
string strRequestedPostalCode = "";
string strStartDate = "";
string strEndDate = "";
strRequestedPostalCode = ViewBag.RequestedPostalCode;
strStartDate = ViewBag.StartDate;
strEndDate = ViewBag.EndDate;
String strExcelTemplatePath = "";
strExcelTemplatePath = _hostingEnvironment.ContentRootPath + "\\Views\\Reports\\SummaryByAgeStagePostalBlank.xls";
HSSFWorkbook wb = new HSSFWorkbook(new FileStream(strExcelTemplatePath, FileMode.Open, FileAccess.ReadWrite));
ISheet sheet = wb.GetSheetAt(0);
DataTable rsReportDataByPostalCode;
rsReportDataByPostalCode = Model.ReportDataByPostalCodeTable;
int rowCount = rsReportDataByPostalCode.Rows.Count;
int currentRowNumber = 2;
sheet.GetRow(0).GetCell(0).SetCellValue("Summary Data For Postal Code " + strRequestedPostalCode );
sheet.GetRow(0).GetCell(4).SetCellValue("Start Date: " + strStartDate );
sheet.GetRow(0).GetCell(7).SetCellValue("End Date: " + strEndDate );
if(rsReportDataByPostalCode != null && rowCount!=0)
{
try
{
foreach (DataRow rsReportDataByPostalCodeRow in @rsReportDataByPostalCode.Rows)
{
strNewPostalCode = rsReportDataByPostalCodeRow["Postal_Code"].ToString();
sheet.GetRow(currentRowNumber).GetCell(0).SetCellValue(rsReportDataByPostalCodeRow["Stage"].ToString());
sheet.GetRow(currentRowNumber).GetCell(1).SetCellValue(rsReportDataByPostalCodeRow["<20"].ToString());
sheet.GetRow(currentRowNumber).GetCell(2).SetCellValue(rsReportDataByPostalCodeRow["20-24"].ToString());
sheet.GetRow(currentRowNumber).GetCell(3).SetCellValue(rsReportDataByPostalCodeRow["25-29"].ToString());
sheet.GetRow(currentRowNumber).GetCell(4).SetCellValue(rsReportDataByPostalCodeRow["30-34"].ToString());
sheet.GetRow(currentRowNumber).GetCell(5).SetCellValue(rsReportDataByPostalCodeRow["35-39"].ToString());
sheet.GetRow(currentRowNumber).GetCell(6).SetCellValue(rsReportDataByPostalCodeRow["40-44"].ToString());
sheet.GetRow(currentRowNumber).GetCell(7).SetCellValue(rsReportDataByPostalCodeRow["45-49"].ToString());
sheet.GetRow(currentRowNumber).GetCell(8).SetCellValue(rsReportDataByPostalCodeRow["50-54"].ToString());
sheet.GetRow(currentRowNumber).GetCell(9).SetCellValue(rsReportDataByPostalCodeRow["55-59"].ToString());
sheet.GetRow(currentRowNumber).GetCell(10).SetCellValue(rsReportDataByPostalCodeRow["60-64"].ToString());
sheet.GetRow(currentRowNumber).GetCell(11).SetCellValue(rsReportDataByPostalCodeRow["65-69"].ToString());
sheet.GetRow(currentRowNumber).GetCell(12).SetCellValue(rsReportDataByPostalCodeRow["70-74"].ToString());
sheet.GetRow(currentRowNumber).GetCell(13).SetCellValue(rsReportDataByPostalCodeRow["75-79"].ToString());
sheet.GetRow(currentRowNumber).GetCell(14).SetCellValue(rsReportDataByPostalCodeRow["80-84"].ToString());
sheet.GetRow(currentRowNumber).GetCell(15).SetCellValue(rsReportDataByPostalCodeRow["85-89"].ToString());
sheet.GetRow(currentRowNumber).GetCell(16).SetCellValue(rsReportDataByPostalCodeRow["90-94"].ToString());
sheet.GetRow(currentRowNumber).GetCell(17).SetCellValue(rsReportDataByPostalCodeRow["95-99"].ToString());
sheet.GetRow(currentRowNumber).GetCell(18).SetCellValue(rsReportDataByPostalCodeRow["100+"].ToString());
currentRowNumber++;
}
}
catch (Exception ex)
{
strExceptionMessage = ex.Message;
}
}
var originalBody = Context.Response.Body;
wb.Write(originalBody);
HttpContextAccessor.HttpContext.Response.Body.Flush();
HttpContextAccessor.HttpContext.Response.Body.Close();
}
catch (Exception ex)
{
}
}
Could the issue be that Context.Reponse.Body is not working right on our test environment ?
I have also tried another alternative by putting the entire download operation in my Controller but have experience same issue
On visual studio where is working I run the code with IIS Espress. Our test environment is on IIS
Also, we have checked the logs and there are no error messages to help point us to the root cause of the issue
I will appreciate any help to fix this
|
|
|
|
|
I'm doing something similar with product called Gembox. In a nutshell, I create the excel file and save it to a path under the website. In my case it is normally a folder called ExcelTemp. I save the file to that folder then use the following code to save it on the enduser's pc. This code will prompt them to save it unless the browser is set to automatically put it somewhere.
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.IO.Path.GetFileName(fileName));
Response.Charset = "";
Response.WriteFile(fileName);
Response.End();
The code need the fileName as a string.
HTH
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
Fokwa Divine wrote: Also, we have checked the logs and there are no error messages to help point us to the root cause of the issue
Well, that's hardly surprising - your code swallows any exceptions that are thrown!
Fokwa Divine wrote:
catch (Exception ex)
{
}
At a guess, the server has response buffering turned off for performance reasons. As a result, the Stream returned from Context.Response.Body is not "seekable", and the wb.Write call is failing for that reason.
Looking through the NPOI examples repo[^], you should write the workbook to a MemoryStream first, then copy that to the response.
Also, there's no need to use HttpContextAccessor within your view; you already have access to the current response via the Context.Response property.
I would strongly recommend generating the workbook in your controller, or preferable a service that you call from your controller, and sending it back to the client in a custom response type.
For example:
public HSSFExcelResult : FileStreamResult
{
private const ExcelMimeType = "application/vnd.ms-excel";
private static Stream SaveWorkbook(HSSFWorkbook workbook)
{
ArgumentNullException.ThrowIfNull(workbook);
MemoryStream ms = new();
workbook.Write(ms);
ms.Seek(0L, SeekOrigin.Begin);
return ms;
}
public HSSFExcelResult(HSSFWorkbook workbook) : base(SaveWorkbook(workbook), ExcelMimeType)
{
}
}
[HttpGet]
public ActionResult ExportSummaryToExcel(string startDate, string endDate, string postalCode)
{
HSSFWorkbook workbook = _summaryByAgeStagePostalCodeService.ExportSummaryToExcel(startDate, endDate, postalCode);
return new HSSFExcelResult(workbook) { FileDownloadName = "Summary.xls" };
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
We finally found the issue. This template file
SummaryByAgeStagePostalBlank.xls was not getting copied along when we publish the project to our Test environment. We set the property for the file on Visual Studio to always copy if newer. The initial setting was "Do not copy".
|
|
|
|
|
Your code needs better error detection.
As already noted do not eat exceptions.
Also do checks to make sure you actually did something. For example, did you read the file but it was empty?
|
|
|
|
|
Hi Guys
me again, old man again .. I have used Scanner set as com port and I like to change it to use Bluetooth, used as com port.
I have register device and change it to use it as com port in Windows 11. I am using SerialPort and add
SerialErrorReceivedEventHandler . This event never happens. I cannot find any suggestion. Can you help me please ?
Regards John
|
|
|
|
|
Jan 1947 wrote: This event never happens. Perhaps there are no errors.
|
|
|
|
|
Hi Richard.
no errors, The Receive Data Event not working. the com port is in /foreach(string port in ports) / as well it shows as com port in Device Manager as 'Standard Serial over Bluetooth link (COM4)'. I use standard Serial port structure <serialport(port)>. It works as HID, when I scan barcode while in Note Pad ?!!?? In device manager I have its HID disabled. When I change the driver to do as com port, my software works. I have an issue with the com port driver supplied with the scanner, and this is the reason I like to change it.
Regards John
|
|
|
|
|
If it is a problem with the device you are connecting to then there is very little anyone here can do to help.
|
|
|
|
|
Hi Richard
maybe I have not been clear. I do not want to use the faulty driver as it has problems. This is why I like to use Scanner via Bluetooth and redirected to operate as com port. The Bluetooth driver is Microsoft and redirection is done via Windows 11, so no faulty driver to be used.
regards John
|
|
|
|
|
Sorry, maybe I am being dense, but I still do not understand what you are asking for.
|
|
|
|
|
Hi Richard
I want to use Bluetooth connection and use it to communicate as serial port with <serialdatareceivedeventhandler> to operate. Maybe I am asking for something which cannot be done
appreciate you help
regards John
|
|
|
|