|
Hi everybody:
I am relatively new in C#, I am working with visual studio 2008, I am making an application with winforms with
reports.
I need to show in a report a details screen for a person of the database, one of the fields of a person is the
image path relative to the root of the aplication , I am using in the Report.rdlc an Image object placed in the
report with the following properties: Source = External, Value = First(Fields!picture.Value, "Personas_persona")
but the problem is that when I run the aplication the image is not show in the report.
Could somebody please help me ???
I woulds thanks any help.
REgards
Ariel
|
|
|
|
|
I'm trying to build a treeview of 4 layers, using 4 tables in the database.
Layer 1: Departments
Layer 2: Groups
Layer 3: Products
Layer 4: Barcodes
No I've had a go at getting the 4 tables in as a dataset, and tried to populate the treeview, but only the first 2 layers will show up in my tree view.
If I make layer 2 my first layer, only layer 2 and 3 will show up.
<br />
private void Load_tree()<br />
{<br />
DataSet ds = new DataSet();<br />
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CCS_HOConnectionString"].ConnectionString);<br />
SqlDataAdapter daDepts = new SqlDataAdapter("barcodePrinter_get_Departments", conn);<br />
SqlDataAdapter daGroups = new SqlDataAdapter("barcodePrinter_get_Groups", conn);<br />
SqlDataAdapter daProducts = new SqlDataAdapter("barcodePrinter_get_Products", conn);<br />
SqlDataAdapter daBarcode = new SqlDataAdapter("barcodePrinter_get_Barcode", conn);<br />
<br />
<br />
daDepts.Fill(ds, "DEPTS");<br />
daGroups.Fill(ds, "PRODGRP");<br />
daProducts.Fill(ds, "PRODUCT");<br />
daBarcode.Fill(ds, "product_barcode");<br />
<br />
<br />
ds.Relations.Add("Depts_Group", ds.Tables["DEPTS"].Columns["DEPTCODE"], ds.Tables["PRODGRP"].Columns["PGRPDEPT"]);<br />
ds.Relations.Add("Group_Product", ds.Tables["PRODGRP"].Columns["PGRPID"], ds.Tables["PRODUCT"].Columns["PRODGRP"]);<br />
ds.Relations.Add("ProdBarcode", ds.Tables["PRODUCT"].Columns["PRODCODE"], ds.Tables["product_barcode"].Columns["prodcode"]);<br />
<br />
dataGridView1.DataSource = ds.Tables["DEPTS"];<br />
dataGridView2.DataSource = ds.Tables["PRODGRP"];<br />
dataGridView3.DataSource = ds.Tables["PRODUCT"];<br />
dataGridView4.DataSource = ds.Tables["product_barcode"];<br />
<br />
foreach (DataRow dr in ds.Tables["DEPTS"].Rows)<br />
{<br />
TreeNode tn = new TreeNode(dr["DEPTSHORT"].ToString());<br />
foreach (DataRow drGroup in dr.GetChildRows("Depts_Group"))<br />
{<br />
TreeNode tnn = new TreeNode(drGroup["PGRPSHORT"].ToString());<br />
foreach (DataRow drProduct in dr.GetChildRows("Group_Product"))<br />
{<br />
TreeNode tnnn = new TreeNode(drProduct["PRODSHORT"].ToString());<br />
foreach (DataRow drBarcode in dr.GetChildRows("Product_Barcode"))<br />
{<br />
tnnn.Nodes.Add(drBarcode["barcode"].ToString());<br />
}<br />
tnn.Nodes.Add(tnnn);<br />
}<br />
tn.Nodes.Add(tnn);<br />
}<br />
trvBarcodes.Nodes.Add(tn);<br />
}<br />
trvBarcodes.ExpandAll();<br />
}<br />
I'm looking for a solution that will make all 4 layers show in the treeview.
Like
+Department 1
-+Group 1
--+Product 1
----Barcode 1
----Barcode 2
-+Group 2
--+Product 2
----Barcode 3
--+Product 3
----Barcode 4
I never know how many layers there will be within the child node, this is decided by the list in the database and that one can change.
modified 4-Nov-20 21:00pm.
|
|
|
|
|
Do a search in the articles for treeview, there are a number of strategies for this, I have done one suing the heirarchyid, there are a number using relationships in datasets and some using a single table with a calculated relationship field.
This is too big a question to be answered by a forum post!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have two methods used to compate Lists, and I would like to combine them if possible. The purpose is to ensure that all elements in two lists match.
private bool matchList_DateTime(List<DateTime> List1, List<DateTime> List2)
{
if (List1.Count != List2.Count) return false;
foreach (DateTime L1 in List1) if (!List2.Contains(L1)) return false;
return true;
}
private bool matchList_String(List<string> List1, List<string> List2)
{
if (List1.Count != List2.Count) return false;
foreach (string L1 in List1) if (!List2.Contains(L1)) return false;
return true;
}
modified on Tuesday, June 15, 2010 4:29 PM
|
|
|
|
|
An ideal candidate for generics
bool CompareLists<T>(List<T> listA, List<T> listB)
{
if (listA.Count != listB.Count)
return false;
foreach (T item in listA)
if (!listB.Contains(item))
return false;
return true;
}
Edit: I haven't optimised your code at all - just converted it to accept generics. You should probably null check both parameters - if both are null it's up to you how you want it to return. As this is nothing really to do with an actual class it may be useful to make it static and possibly an extension method if using 3.0 or above.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
That works, thank you. I was trying to find a way to pass them as IEquatables, which wasn't working out.
|
|
|
|
|
Timothy CIAN wrote: I was trying to find a way to pass them as IEquatables, which wasn't working out.
Why that?Perhaps using generic type constraints will help.
Life is a stage and we are all actors!
|
|
|
|
|
As a general List comparator, your method is flawed in one or two ways:
1. the order of items is disregarded (you may want to describe what "matching lists" is meant to mean);
2. when List1 holds duplicates, your method may return true even when List2 is not at all equivalent (even holding items that are not present in List1, or different quantities of List1 items).
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Good points. In this case, both lists contain distinct values (no duplicates).
The order is insignificant, the point of the method is to determine if all items in List A exist in List B, and no others.
|
|
|
|
|
Does it matter if the contents of those items are also identical?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Revised version...
private static bool matchList<T>(List<T> List1, List<T> List2)
{
if (List1 == null || List2 == null) return false;
if ((List1.Count == List2.Count) && (List1.Count == List1.Intersect(List2).Count()))
return true;
return false;
}
|
|
|
|
|
Revision revised... I realized that I could simply return the comparison, as it is bool.
private static bool matchList<T>(List<T> List1, List<T> List2)
{
if (List1 == null || List2 == null) return false;
return ((List1.Count == List2.Count) && (List1.Count == List1.Intersect(List2).Count()));
}
|
|
|
|
|
An interesting approach. thanks.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
|
Hello,
I am trying to add google maps in my C# application but i can't figure out how to do it because i am new in C#. I've checked all of the online tutorials but nothing comes up. I want to add google maps in the rectangle shown in the picture below. If any one can help me this would be very good for me.
http://yfrog.com/0kgoogleaep[^]
Thanks,
John
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:27am.
|
|
|
|
|
But i want to take information from the map. For example when i click in London i want to store it for later use!
|
|
|
|
|
You will need to register your URL with Google in order to use the maps API. They will provide a script block that must be included in your header.
You will also need a map canvas div, and use JS to create a new GMap2 object (with the div name as a parameter), create the icon objects you need, and use addOverlay methods to place icon instances at specific latitude/longitudes. Personally, I wrap all of these into a function that is called from BODY onLoad.
I would recommend reading the API documentation carefully. They have examples, also.
|
|
|
|
|
can you please link me with an example like this?
thanks for you help mate
|
|
|
|
|
Here is an example. Note that if you want to add markers using C#, you will need to create the entire "initialize" function in your code (that is, create C# code that writes the JavaScript code).
Hope this helps.
<html lang="en-us">
<head>
<title>Map Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://maps.google.com/maps?file=<Google will provide this>" type="text/javascript"></script>
<script type="text/javascript">
function initialize()
{
if (GBrowserIsCompatible())
{
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(20, 0), 2);
map.enableScrollWheelZoom();
var redIcon = new GIcon(G_DEFAULT_ICON);
redIcon.image = "Images/RedCircle.png";
redIcon.shadow = "Images/transparent.png";
redIcon.iconSize = new GSize(32, 32);
redIcon.shadowSize = redIcon.iconSize;
redIcon.iconAnchor = new GPoint(16, 16);
map.addOverlay(new GMarker(new GLatLng(50, 110), { icon:redIcon } ));
map.addOverlay(new GMarker(new GLatLng(100, 200), { icon:redIcon } ));
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 1600px; height: 1000px"></div>
</body>
</html>
|
|
|
|
|
|
OK, this program is from a class I'm taking, it's an example out of our book. You have four classes, D inherits from C, C from B and B from A. I kind of understand how this works but I'm not sure.
Question. Is this considered a single object? Only one object is created but do the references make the other classes(or the methods within them) part of the same object?
I think I understand the rest.
1.) D is called and outputs 'D' becuase that is the method within D.
2.) Since C is virtual and it's child class D overries it, C also outputs 'D'.
3.) Since C is declared 'new' that hides C from B (I assume it also hides D from B) and therefore B outputs it own method and displays 'B'
4.) A is virtual and since its child class B overrides it, it also outputs 'B'.
Sorry, but I think my brain actually froze for a while when I was trying to figure this out and I'm just trying to see if anyone has any input or knows if I'm right.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Example
{
class A
{
public virtual void M() { Console.WriteLine("A"); }
}
class B : A
{
public override void M() { Console.WriteLine("B"); }
}
class C : B
{
new public virtual void M() { Console.WriteLine("C"); }
}
class D : C
{
public override void M() { Console.WriteLine("D"); }
}
class Program
{
static void Main(string[] args)
{
D d = new D();
C c = d;
B b = c;
A a = b;
d.M();
c.M();
b.M();
a.M();
}
}
}
|
|
|
|
|
It is indeed one object, but depending on how you type the object, you're getting different methods to execute. The type you reference an object by can definitely impact what functionality is executed.
It's kind of like explicitly implementing interfaces, check this[^] out.
|
|
|
|
|
Thank you, I thought that it was the same object but I wasn't sure.
I think you answered the 'why' question also.
Your saying that that like interfaces (I'm still trying to grasp those also) You can take the same data but manipulate it differently.
With an interface you explicitly cast the data using the interface you want.
With inheratance you use the same object but use a different reference to the object.
|
|
|
|
|
It sounds like your close to the correct understanding. Be aware though, this is NOT a normal situation in coding. The only reason you would ever use new is that the member is NOT virtual and you need to override its functionality. Because the method is virtual, there is really no need to shadow it with new . Typically shadowing can get you into a lot of confusion if you're not careful, hence why when its not necessary it is strictly avoided.
As an example of why its not needed, if you change the definition of the method in C to:
class C : B
{
public override void M() { Console.WriteLine("C"); }
}
It'll print out four "D"s.
As for interfaces, they don't represent a class you can create (eg. new IList() ), but rather just an expected contract of functionality.
I mention explicit implementation of interfaces because they represent something similar to the behavior seen in the code you posted. Basically, how you reference an object determines exactly what functionality is called.
When you down cast class D to C, that is an implicit cast (ie. .NET assumes you mean to do that). It'd be exactly the same as if you had typed:
C c = (C)d;
Ok, he comes some really confusing stuff, hopefully it won't make things worse.
If you look at the reflected IL code of the Main method, you'll see this:
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 1
.locals init (
[0] class Example.D d,
[1] class Example.C c,
[2] class Example.B b,
[3] class Example.A a)
L_0000: nop
L_0001: newobj instance void Example.D::.ctor()
L_0006: stloc.0
L_0007: ldloc.0
L_0008: stloc.1
L_0009: ldloc.1
L_000a: stloc.2
L_000b: ldloc.2
L_000c: stloc.3
L_000d: ldloc.0
L_000e: callvirt instance void Example.C::M()
L_0013: nop
L_0014: ldloc.1
L_0015: callvirt instance void Example.C::M()
L_001a: nop
L_001b: ldloc.2
L_001c: callvirt instance void Example.A::M()
L_0021: nop
L_0022: ldloc.3
L_0023: callvirt instance void Example.A::M()
L_0028: nop
L_0029: ret
}
I've underlined the calls to d.M(), c.M(), etc. You'll notice that its going back to the class that defines the original signature of the method. Because of the 'new' keyword, that inheritance starts over so to speak. So, from a code perspective, it'll burrow its way through the currently defined type you're referencing it as, until it finds a 'new' keyword or the 'virtual' keyword. From there, it'll find the furthest up the inheritance chain it can go before it reaches the real type of the class or another 'new' keyword. By using 'new', you break all inheritance hence forth.
I hope that helps you, rather than confuses you.
|
|
|
|
|