|
BillWoodruff wrote: Why even bother to try and figure out what this little-code-monster is, when you can get busy, and write better code
Because I'm in a testing phase right now and can't write additional code until that's done. The best I can do at the moment is try to understand what's here already. That is pretty important when taking over maintenance of undocumented apps.
|
|
|
|
|
Hello All,
I have an application that frequently uses the general List object with an bitmap type". I have two questions concerning these.
1: What is the best way to copy the bitmaps from one list to another while ensuring the Bitmaps in the original list are unchanged if changes are made to the new list. Currently i'm doing it in a forloop such as:
List<Bitmap> aviList1 = new List<Bitmap>(); aviList1.Clear();
for (int i=0; I originalList.Count; i++)
aviList1.Add(new Bitmap(originalList[i]));
2: Is calling originalList.Clear sufficient to free up the memory or would it be necessary to loop through the list and dispose of the Bitmaps individually?
Thanks in advance for the always great support here at CodeProject.
Bryan
|
|
|
|
|
Bitmaps are a scarce resource: they implement IDisposable, so you should clean up behind you, and Dispose all bitmaps you create. If you don't you may well get "Out of Memory" problems long before the actual RAM is exhausted. Additionally, depending on how you initially constructed the bitmaps, you may leave files or streams in use until the bitmap.Dispose method is called by your code, or by the garbage collector.
You need to construct a new image for each that you add to the other list, if you want the original unmodified when the aviList1[index] bitmap is changed.
However, it would look tidier with a foreach loop:
foreach (Bitmap b in originalList)
aviList1.Add(new Bitmap(b)); Or you could do it with Linq:
aviList.AddRange(originalList.Select(bm => new Bitmap(bm))); (But that just hides the loop)
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Hi OG,
I am inferring from your answer (upvoted), that, in this case, it would be best for the OP to loop through his List<bitmap> and specifically dispose of them: that he should not rely on just clearing the List<bitmap>: is that correct ?
thanks, Bill
~
“This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal
|
|
|
|
|
Yes - clearing the list does not dispose of any of the items on it (thank goodness!) so the bitmaps will be left hanging until the garbage collector gets round to disposing of them for you.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
If I may be so bold as to humbly point you to a little article[^] that I wrote a while back on memory managing images, you might find that it helps a lot. I use this a lot.
|
|
|
|
|
Sorry chaps, I couldn't find an appropriate forum so I'll take a chance I won't get flamed for using this one. I have a regex question. Given an input string like this:
Some text containing % complete and not much else
If I use a regex of \bcomplete\b I can find the whole word complete just fine. What I want to do is find % complete. I've tried \b% complete\b and \b\% complete\b and \b\x25 complete\b and other variations I can think of but I can never get it to select % complete. Does anyone know if it's possible to do it and how? I can find nothing anywhere that says % cannot participate in an expression.
I've tried two different apps, such as RegexBuilder and RegexBuddy but I can't get it working in either. Does anyone have any ideas? Thanks.
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.
|
|
|
|
|
Leslie Nielsen 151576 wrote: I couldn't find an appropriate forum
What, like this[^] one?
|
|
|
|
|
Point taken. I based my search on the menu you get when clicking discussions at the top of the page. I didn't notice the All Message Boards...
I'll post there.
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.
|
|
|
|
|
Hi,
I have a problem with treeview in windows application
for example i have a treeview as follows with checkboxes:-
Root0
Node0
Node1
Root1
Node2
Node3
now if i checked node0 nothing will happn with root0 but if node0 and node1 both are checked thn root0 can be shows as checked
and if i check on root0 thn both nodes with be checked automatically
i m trying soo hard but m found nothing still, can anyone help me with it
|
|
|
|
|
Firstly I would suggest that you explain what you have done more, possibly show some code as we can then potentially see where the problem is rather than guess.
Secondly I wouldn't post your problem multiple times as this is condsidered rude / bad form.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Please don't repost.
Modify the original question if you have to.
|
|
|
|
|
Arun kumar Gautam wrote: now if i checked node0 nothing will happn with root0 but if node0 and node1 both are checked thn root0 can be shows as checked
and if i check on root0 thn both nodes with be checked automatically
i m trying soo hard but m found nothing still, can anyone help me with it
I'd expect this behaviour; can you explain why you think it's wrong?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
wel m now able to resolve it by using
#region TreeView
private void CheckChildNode(TreeNode currNode)
{
//set the children check status to the same as the current node
bool checkStatus = currNode.Checked;
foreach (TreeNode node in currNode.Nodes)
{
node.Checked = checkStatus;
CheckChildNode(node);
}
}
private void CheckParentNode(TreeNode currNode)
{
TreeNode parentNode = currNode.Parent;
if (parentNode == null)
return;
parentNode.Checked = true;
foreach (TreeNode node in parentNode.Nodes)
{
if (!node.Checked)
{
parentNode.Checked = false;
break; // TODO: might not be correct. Was : Exit For
}
}
CheckParentNode(parentNode);
}
#endregion
private void menuCollection_AfterCheck(object sender, TreeViewEventArgs e)
{
menuCollection.AfterCheck -= menuCollection_AfterCheck;
CheckChildNode(e.Node);
CheckParentNode(e.Node);
menuCollection.AfterCheck+=menuCollection_AfterCheck;
}
hope this code helps someone in future
|
|
|
|
|
Hi,
I have a problem with treeview in windows application
for example i have a treeview as follows with checkboxes:-
Root0
Node0
Node1
Root1
Node2
Node3
now if i checked node0 nothing will happn with root0 but if node0 and node1 both are checked thn root0 can be shows as checked
and if i check on root0 thn both nodes with be checked automatically
i m trying soo hard but m found nothing still, can anyone help me with it
|
|
|
|
|
|
KeithF wrote: So basically before i carry on with my design I am wondering from an OO point of view if I am approaching this task in the right way or if what I am doing is overkill and could be greatly simplified? There is no clear and specific "right way" in OO; it's called OO once you structure your methods and data into objects.
If you think the new code is more easily to maintain than the original code, than it'd be an improvement. If the new code looks "complex" or contains a lot of repetitions, then it'd be wise to re-evaluate the design.
Is it an improvement (from your viewpoint), in terms of readability?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yeah i suppose it make the code more flexible going forward but does add a level of complexity that may make it harder for a newbie to just jump in to the code base.
|
|
|
|
|
How to filter one interface with multiple method by diffrent class in C#. Please give answer with example.
|
|
|
|
|
Using IsAssignableFrom can help you figure out if the class uses that interface.
For e.g.
typeof(IMyInterface).IsAssignableFrom(typeof(MyClass));
|
|
|
|
|
Thank u sir, please explain in detail ,I am fresher so define it with C# example
|
|
|
|
|
You can also do this to determine if a class implements a specific interface:
if (myObject is IMyInterface)
{
}
else
{
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I know this is long, so please try not to TLDR me I have a reporting service that allows users to queue reports. All fine and dandy, they queue it, it goes into a database. I have a service that polls the DB queue and runs reports. I am stuck on the run part right now. The reports are Telerik reports, but it is not really relevant as it would be the same if they were crystal or anything else. I want to store the report type in the DB and pull it at run time. The report queue looks like this:
USE [litigatorPro]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ReportQueue](
[id] [int] IDENTITY(1,1) NOT NULL,
[reportId] [int] NOT NULL,
[userId] [int] NOT NULL,
[statusId] [int] NOT NULL,
[claimId] [int] NULL,
[propertyId] [int] NULL,
[startDate] [datetime] NULL,
[endDate] [datetime] NULL,
[datestamp] [datetime] NOT NULL,
CONSTRAINT [PK_ReportQueue] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
And the Report table:
USE [litigatorPro]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Report](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](100) NOT NULL,
[fileName] [nvarchar](100) NOT NULL,
[queryString] [nvarchar](2500) NOT NULL,
[scopeId] [int] NOT NULL,
[reportType] [nvarchar](50) NULL,
CONSTRAINT [PK_Report] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Some of the fields are not use, but the important point is that the service checks the report queue table and gets the report type and parameters. I want to then process the report using something like this:
private bool RunReport<T>(int id) where T: Telerik.Reporting.Report
{
var targetReport = (T)Activator.CreateInstance(typeof(T), new object[] { id });
return false;
}
The issue, for now, is how to call the function with information from the DB. Here is what I am looking at with crossed eyes right now:
private int ProcessReport(ReportQueue item)
{
using (litigatorProEntities _db = new litigatorProEntities())
{
ReportPolling.Model.Report report = _db.Reports.Single(r => r.id == item.reportId);
Type type = Type.GetType(report.reportType);
if (RunReport<type>(report))
{
return 1;
}
return 2;
}
return 2;
}
I need to figure out how to supply the type based on a text field from the DB as seen in the line that says:
if (RunReport<type>(report))
After that I will figure out how to pass the arguments (userId, claimId, propertyId, etc...)
I am not great with some of the fundamental items like generics and boxing, so forgive me if the question is stupid.
Cheers, --EA
|
|
|
|
|
I've just started using Telerik reports and use the .trdx file, have not worked out how to pass in parameters but I'm certain it can be done then the viewer displays! Ahh the light goes on, you want it to process, I'll await further enlightenment (should have deleted this reply I suppose )
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have used Telerik a bit so I am not super unfamiliar with it. So that I am not sitting on my hands all day I decided to just switch() the report name parameter until I can figure out the anonymous access piece.
private bool RunReport(string reportName, int? claimId, int? propertyId, int? ecrId)
{
switch (reportName)
{
case "COR - Cost Summary By Address":
Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
CostSummaryByAddress myReport = new CostSummaryByAddress(ecrId, claimId);
instanceReportSource.ReportDocument = myReport;
Telerik.Reporting.Processing.RenderingResult result =
reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
string fileName = result.DocumentName + "." + result.Extension;
string path = System.IO.Path.GetTempPath();
string filePath = System.IO.Path.Combine(path, fileName);
using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
{
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}
break;
}
return true;
}
And the report class:
public partial class CostSummaryByAddress : Telerik.Reporting.Report
{
public CostSummaryByAddress(int? ecrId, int? claimId)
{
if (ecrId == null)
{
ecrId = 1;
}
InitializeComponent();
using (litigatorProEntities _db = new litigatorProEntities())
{
var model = from d in _db.ECRDatas.Where(e => e.ecrId == ecrId)
select new CostSummaryViewModel
{
claimName = d.ECR.Claim.description,
property = d.property,
totalCost = d.totalCost
};
this.DataSource = model.ToList();
}
}
Frankly, I have built all of these reports in Crystal so I am not sure I am going to stick with Telerik for reporting as all of the reporting is done on an application server with a note being emailed to the user. Since none of it is being displayed in a viewer I am thinking it is more work than it is worth. We will see, though.
Cheers, --EA
|
|
|
|