|
1) Write down a precise description of what you want, how you want it to work, and what you want it to look like.
2) Write some code to implement the view.
3) Test it. Does it work? Great. If not, go back to step 2 and fix your code.
Seriously, nobody can help you based on such a vague description. You either need to put a lot more thought into what you want, or go back to whoever gave you the task and ask for a lot more detail.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That depends on what you actually want to achieve, and what you expect the UI to look and work like.
At the moment, this is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?
That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!
I'd suggest that most likely you want to start with some kind of UserControl, or perhaps a TabControl but with your minimalist description we can't help you much, if at all!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'm reporting your "name" as a spam link.
"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 have some CSV files encoded in GBK, aka codepage 936, and need to load them as strings (or something sufficiently string-like, whatever) for further processing. In the old days, I could call some function such as File.ReadAllText (or read the file line by line etc) and specify CP936 as the encoding. But in .NET 6, I can't. The only valid options are ASCII, Latin 1, and a couple of flavours of UTF.
That sounds unlikely, right? But here is the documentation for the Encoding class, and in the big table halfway down the page, you can see that almost everything is gone. Almost as if the thinking is now "people should just use UTF-8 or UTF-16 nowadays". If it were up to me, those file would be encoded in UTF-8, but they're just not.
So, right now what I do is this, assuming that I've read the file into an array byte[] raw and int size bytes were successfully read into it:
char[] buffer = new char[size];
int numberOfChars;
fixed (char* bufferptr = buffer)
fixed (byte* rawptr = raw)
numberOfChars = MultiByteToWideChar(936, 0, rawptr, readSize, bufferptr, buffer.Length);
Calling MultiByteToWideChar via a dllimport. Then afterwards I can use numberOfChars to create a Span<char> of the appropriate length.
That works, but it seems like a serious step backwards compared to .NET 4. Also there seems to be no way (no reasonable way anyway) to read/convert chunks of the file this way, as MultiByteToWideChar does not report the leftover bytes at the end of the chunk.
Are there any better options?
|
|
|
|
|
|
|
As far as I can see, code page 936 is called "gb2312" in .NET Framework, but .NET 6 doesn't seem to know about it - as you said, the Encoding.GetEncodings method only lists seven options.
It looks like you need to register the code pages provider from the System.Text.Encoding.CodePages package, which seems to be included in .NET 6 by default:
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding gb2312 = Encoding.GetEncoding(936);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Good, that works and isn't weird
|
|
|
|
|
I'm using Syncfusion PdfViewer in my project. When I click an item in a list, the related pdf file is loaded and shown in the PdfViewer:
private void PdfReport(string address)
{
FileStream fs = new FileStream(address, FileMode.Open);
PdfSource = fs;
}
The problem is that each time I load a pdf file, a new instance of FileStream is created and the memory usage increases. When I try to dispose FileStream like the following code, the pdf is not shown in the viewer:
private void PdfReport(string address)
{
FileStream fs = new FileStream(address, FileMode.Open);
PdfSource = fs;
fs.Dispose();
}
How can I solve this problem?
modified 8-Aug-22 2:14am.
|
|
|
|
|
Don't Dispose the stream until you are finished with it: setting a variable to the stream doesn't do anything useful unless the variable is actually a property of a class inheriting from the pdf viewer and does some very naughty loading in the setter.
Once you Dispose a stream, it's closed, and all it's resources are freed immediately: you can't later use the stream to load the data into a control, any more than you can correct the spelling in a letter once you have sealed the envelope.
If you are using memory, then Dispose the stream (and maybe the viewer control) when your user has finished with it, not before.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I solved the problem using this:
if (PdfSource is not null)
PdfSource.Dispose();
PdfSource = new FileStream(address, FileMode.Open);
|
|
|
|
|
That's better - you are disposing of the stream when you no longer need it!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If you are using C# 6 or later, then there is a much shorter form of this:
if (PdfSource is not null)
PdfSource.Dispose();
PdfSource = new FileStream(address, FileMode.Open); Try this:
PdfSource?.Dispose();
PdfSource = new FileStream(address, FileMode.Open); The null conditional operator is quite handy!
Member access operators and expressions - C# reference | Microsoft Docs[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I have store procedure which insert and update data and at the end it return multiple data.
i am using SQL helper utility class to call store procedure. i use
ds = await SqlHelper.ExecuteDatasetAsync(ConnectionManager.GetConnectionString(), CommandType.StoredProcedure, "USP_InsertBMAsLineItem", spParameter);
execution stuck at this line. i am not able to figure out where i made the mistake. when i execute SP from SSMS then everything goes fine. please see my store procedure and c# code. tell me where i made the mistake.
ALTER PROC USP_InsertBMAsLineItem
(
@TickerID VARCHAR(20),
@CommaSeparatedItems VARCHAR(MAX),
@UserID VARCHAR(20)
)
AS
BEGIN
Declare @Start INT, @Count INT,@MaxOrder INT
SET @Start=1
SET @Count=1
SET @MaxOrder=0
BEGIN TRY
BEGIN TRAN
DROP TABLE IF EXISTS #Tmpdata
CREATE TABLE #Tmpdata
(
ID INT Identity,
LineItem VARCHAR(MAX)
)
INSERT INTO #Tmpdata(LineItem)
(
SELECT value as LineItem
FROM STRING_SPLIT(@CommaSeparatedItems, ',')
)
MERGE INTO TblLineItemTemplate Trg
USING
(
SELECT value as LineItem
FROM STRING_SPLIT(@CommaSeparatedItems, ',')
) AS Src
ON UPPER(TRIM(Trg.LineItem)) = UPPER(TRIM(Src.LineItem))
AND Trg.TickerID = @TickerID
WHEN MATCHED THEN
UPDATE SET Trg.Action = 'U', ModifiedBy=@UserID
WHEN NOT MATCHED THEN
INSERT
(
TickerID,
LineItem,
Action,
InsertedOn,
InsertedBy
)
VALUES
(TRIM(@TickerID), TRIM(Src.LineItem), 'I', GETDATE(),@UserID);
SELECT @Start=MIN(ID) FROM #Tmpdata
SELECT @Count=MAX(ID) FROM #Tmpdata
WHILE (@Start<=@Count)
BEGIN
IF NOT EXISTS(SELECT * FROM tblSectionLineItemTemplate WHERE TickerID=@TickerID
AND SectionID IN (SELECT SectionID FROM tblSectionTemplate WHERE TickerID=@TickerID AND Section='Model Output' AND Action<>'D')
AND LineItemID IN (SELECT LineItemId FROM TblLineItemTemplate WHERE TickerID=@TickerID
AND LineItem IN (
SELECT LineItem FROM #Tmpdata WHERE ID=@Start
)))
BEGIN
SELECT @MaxOrder=MAX(ISNULL(OrderID,0))+1 FROM tblSectionLineItemTemplate WHERE TickerID=@TickerID
INSERT INTO tblSectionLineItemTemplate
(
TickerID,
SectionID,
LineItemID,
OrderID,
InsertedOn,
UserID
)
VALUES
(
@TickerID,
(SELECT SectionID FROM tblSectionTemplate WHERE TickerID=@TickerID AND Section='Model Output' AND Action<>'D'),
(SELECT LineItemId FROM TblLineItemTemplate WHERE TickerID=@TickerID AND LineItem IN (SELECT LineItem FROM #Tmpdata WHERE ID=@Start)),
@MaxOrder,
GETDate(),
@UserID
)
END
SET @Start=@Start+1
END
SELECT L.LineItemId,L.LineItem from TblLineItemTemplate L INNER JOIN
(
SELECT value as LineItem
FROM STRING_SPLIT(@CommaSeparatedItems, ',')
) V
ON UPPER(TRIM(L.LineItem))=UPPER(TRIM(V.LineItem)) AND L.TickerID=@TickerID
DROP TABLE IF EXISTS #Tmpdata
COMMIT TRAN
END TRY
BEGIN CATCH
ROLLBACK TRAN
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
SELECT @ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();
RAISERROR( @ErrorMessage,
@ErrorSeverity,
@ErrorState
);
END CATCH
END
My C# code which would call SP
public async Task<ResponseContextDto> ConvertToPercentLineItem(string tickerid, string items)
{
DataSet ds = new DataSet();
DataTable dt=new DataTable();
string userid = GlobalVariable.strLoginID;
ResponseContextDto oResponseContext = new ResponseContextDto();
string? message = "";
try
{
#region db operation start
SqlParameter[] spParameter = new SqlParameter[3];
spParameter[0] = new SqlParameter("@TickerID", SqlDbType.VarChar);
spParameter[0].Direction = ParameterDirection.Input;
spParameter[0].Value = tickerid;
spParameter[1] = new SqlParameter("@CommaSeparatedItems", SqlDbType.VarChar);
spParameter[1].Direction = ParameterDirection.Input;
spParameter[1].Value = items;
spParameter[2] = new SqlParameter("@UserID", SqlDbType.VarChar);
spParameter[2].Direction = ParameterDirection.Input;
spParameter[2].Value = userid;
ds = await SqlHelper.ExecuteDatasetAsync(ConnectionManager.GetConnectionString(), CommandType.StoredProcedure, "USP_InsertBMAsLineItem", spParameter);
oResponseContext.IsSuccess = Status.Success;
oResponseContext.Message = Status.Message(Status.Success);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
dt = ds.Tables[0];
oResponseContext.ResponseData = dt;
}
else
{
oResponseContext.ResponseData = null;
}
#endregion
}
catch (Exception ex)
{
oResponseContext.IsSuccess = Status.Fail;
oResponseContext.Message = "Error " + ex.Message;
oResponseContext.ResponseData = null;
}
return oResponseContext;
}
I also tried this way to capture return tabular data from SP into c# datatable but still no luck.
string userid = GlobalVariable.strLoginID;
ResponseContextDto oResponseContext = new ResponseContextDto();
DataTable table = new DataTable();
using (var con = new SqlConnection(ConnectionManager.GetConnectionString()))
using (var cmd = new SqlCommand("USP_InsertBMAsLineItem", con))
using (var da = new SqlDataAdapter(cmd))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@TickerID", tickerid));
cmd.Parameters.Add(new SqlParameter("@CommaSeparatedItems", items));
cmd.Parameters.Add(new SqlParameter("@UserID", userid));
da.Fill(table);
}
please guide me what to change in c# code or in SP code.
Thanks
|
|
|
|
|
You haven't explained what you mean by "execution stuck" or "still no luck".
If you want us to help you, you need to explain precisely what the problem is.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sir there was a problem in SP code. now everything is working fine after fixing. Thanks
|
|
|
|
|
Mou_kol wrote: here was a problem in SP code.
But you wrote yesterday:
Quote: when i execute SP from SSMS then everything goes fine
|
|
|
|
|
What's the issue? Any error? Include that in your question always.
|
|
|
|
|
You prototype with a trivial example; when that that works, you throw the kitchen sink at it; not before.
"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'm using WPF MVVM in my project. I have used Interaction.Behaviors in the root section of one of my views:
<interactivity:Interaction.Behaviors>
<local:SfDataPagerBehavior_OnDemand />
<local:SfDataPagerBehavior_File />
</interactivity:Interaction.Behaviors>
One of the Behavior classes is:
public class SfDataPagerBehavior_File : Behavior<EquipmentIdentitySetting>, IRecipient<FileFilterText>, IRecipient<UpdateDatagrid_Pdf>
{
public SfDataPagerBehavior_File()
{
WeakReferenceMessenger.Default.Register<FileFilterText>(this);
WeakReferenceMessenger.Default.Register<UpdateDatagrid_Pdf>(this);
}
protected override void OnAttached()
{
base.OnAttached();
.
.
AssociatedObject.dataPager_file.OnDemandLoading += OnOnDemandLoading;
.
.
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.dataPager_file.OnDemandLoading -= OnOnDemandLoading;
}
public async void Receive(FileFilterText message)
{
}
public async void Receive(UpdateDatagrid_Pdf message)
{
}
}
I want to dispose all Interaction.Behaviors in the view by pressing a button.
How can I do this?
|
|
|
|
|
That's one of the traps of MVVM: over-engineering in order to fit the app to the pattern. It presumes one is incapable of coming up with something better on their own for their app's needs.
"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 have the following model:
public class Equipment
{
[Key]
public int EquipmentId { get; set; }
[Required]
public string EquipmentCode { get; set; }
[Required]
public string EquipmentTitle { get; set; }
[Required]
public int CostCenterId { get; set; }
public CostCenter CostCenter { get; set; }
public int? InfoId { get; set; }
[ForeignKey("InfoId")]
public EqInfo? EqInfo { get; set; }
public Catalogue? Catalogue { get; set; }
}
public class EqInfo
{
[Key]
public int InfoId { get; set; }
[Required]
public string InfoFileName { get; set; }
public virtual List<Equipment> Equipments { get; set; }
}
I want to update the EqInfo entity to null in a list of selected items:
foreach (var row in AssociatedObject.dataGrid.SelectedItems)
{
var _sqliteContext = new SQLiteContext();
var selectedRecord = _sqliteContext.Equipments.Include(x => x.EqInfo).FirstOrDefault(x => x.EquipmentId == (int)reflector2.GetValue(row, "EquipmentId"));
selectedRecord.EqInfo = null;
list2.Add(selectedRecord);
_sqliteContext.Dispose();
}
selectedRecord.EqInfo = null; not works as expected. It keeps the previous value and is not set to null.
How can I fix it?
|
|
|
|
|
You are adding a new record to list2 with the value null , not updating the existing one.
|
|
|
|
|
I use BulkUpdate but I need to have a list of modified entities first. My problem is in the modification part. I did not provide the BulkUpdate part because I don't have any problem with it. Setting a null value to the EqInfo does not nullify the record.
modified 1-Aug-22 4:19am.
|
|
|
|
|