|
Then you're going to have to write code to create the filepath to that image. All a OpenFileDialog does is let the user select a file or files and return their filepaths, that's it. It doesn't actually do the "open" operation on the file. That's up to your code.
|
|
|
|
|
Thanks for your guide, but can you give me the code, I am beginner and I can't write the code by myself! I can read the code and try to understand it. Thank you
|
|
|
|
|
Code for WHAT? I have no idea what you're doing or what you need code for. This site is not in the business of writing code for people on demand.
|
|
|
|
|
Hai all,
i need a solution, to download file from google drive using c#.
|
|
|
|
|
|
A classically bad question deserves a classically bad answer[^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I need to add deserialized data from xml file to the model in Entity Framework cod efirst in order to generate my database in SQL Server CE.
The problem was that I have two tables , the first was done without problems but when I added the second model I got an exception :
{"Exception has been thrown by the type initializer for 'DAL.MyModel.InformationContext."}
I will be so thankful if someone could help me .
Here my source code in the Program.cs:
using (InformationContext db = new InformationContext())
{
db.Balances.Add(new Balance_Model()
{
EuroBookingBalance = Bal.ElementAt(0).EuroBookingBalance,
Id = Bal.ElementAt(0).Id,
ABI = Bal.ElementAt(0).Account.ABI,
BBAN = Bal.ElementAt(0).Account.BBAN,
CIN = Bal.ElementAt(0).Account.CIN,
Currency = Bal.ElementAt(0).Account.Currency,
Description = Bal.ElementAt(0).Account.Description,
Number = Bal.ElementAt(0).Account.Number,
AccountId = Bal.ElementAt(0).Account.Id,
Date = Bal.ElementAt(0).Date.ToString(),
AccountHolder = Bal.ElementAt(0).Account.AccountHolder,
CAB = Bal.ElementAt(0).Account.CAB,
CurrencyBookingBalance = Bal.ElementAt(0).CurrencyBookingBalance
});
db.Transactions.Add(new Transaction_Model()
{
ABI = tra.ElementAt(0).Account.ABI,
AccountDescription = tra.ElementAt(0).Account.Description.ToString(),
Amount = tra.ElementAt(0).Amount,
TransactionDate = tra.ElementAt(0).TransactionDate.ToString(),
AdditionalDescription = tra.ElementAt(0).AdditionalDescription,
AccountHolder = tra.ElementAt(0).Account.AccountHolder,
CAB = tra.ElementAt(0).Account.CAB,
Currency = tra.ElementAt(0).Currency,
Description = tra.ElementAt(0).Description,
Id = tra.ElementAt(0).Id,
Number = tra.ElementAt(0).Account.Number.ToString(),
ValueDate = tra.ElementAt(0).ValueDate.ToString(),
AbiReason = tra.ElementAt(0).AbiReason.ToString()
});
db.SaveChanges();
Here my Initializer class ;
class DbInitializer : DropCreateDatabaseAlways<InformationContext>
{
protected override void Seed(InformationContext context)
{
string pathXml = @"C:\Users\Mohamed amine sifi\Desktop\balancess.xml";
Balances Bal = new Balances();
XmlSerializer serializer = new XmlSerializer(typeof(Balances), null, null, new XmlRootAttribute("Balances"), "urn:Cedac:WebContoc:Balances:v1");
StreamReader reader = new StreamReader(pathXml);
var xmlReader = XmlReader.Create(reader.BaseStream);
object deserialized = (Balances)serializer.Deserialize(xmlReader);
Bal = (Balances)deserialized;
string pathXmlt = @"C:\Users\Mohamed amine sifi\Desktop\transactions.xml";
TransactionsList tra = new TransactionsList();
XmlSerializer serializert = new XmlSerializer(typeof(TransactionsList), null, null, new XmlRootAttribute("Transactions"), "urn:Cedac:WebContoc:Transactions:v1");
StreamReader readert = new StreamReader(pathXmlt);
var xmlReadert = XmlReader.Create(readert.BaseStream);
object deserializedt = (TransactionsList)serializer.Deserialize(xmlReader);
tra = (TransactionsList)deserializedt;
context.Balances.Add(new Balance_Model()
{
EuroBookingBalance = Bal.ElementAt(1).EuroBookingBalance,
Id = Bal.ElementAt(1).Id,
ABI = Bal.ElementAt(1).Account.ABI,
BBAN = Bal.ElementAt(1).Account.BBAN,
CIN = Bal.ElementAt(1).Account.CIN,
Currency = Bal.ElementAt(1).Account.Currency,
Description = Bal.ElementAt(1).Account.Description,
Number = Bal.ElementAt(1).Account.Number,
AccountId = Bal.ElementAt(1).Account.Id,
Date = Bal.ElementAt(1).Date.ToString(),
AccountHolder = Bal.ElementAt(1).Account.AccountHolder,
CAB = Bal.ElementAt(1).Account.CAB,
CurrencyBookingBalance = Bal.ElementAt(1).CurrencyBookingBalance
});
context.Transactions.Add(new Transaction_Model()
{
ABI = tra.ElementAt(1).Account.ABI,
AccountDescription = tra.ElementAt(1).Account.Description,
Amount = tra.ElementAt(1).Amount,
TransactionDate = tra.ElementAt(1).TransactionDate.ToString(),
AdditionalDescription = tra.ElementAt(1).AdditionalDescription.ToString(),
AccountHolder = tra.ElementAt(1).Account.AccountHolder,
CAB = tra.ElementAt(1).Account.CAB,
Currency = tra.ElementAt(1).Currency,
Description = tra.ElementAt(1).Description,
Id = tra.ElementAt(1).Id,
Number = tra.ElementAt(1).Account.Number.ToString(),
ValueDate = tra.ElementAt(1).ValueDate.ToString(),
AbiReason = tra.ElementAt(1).AbiReason
});
base.Seed(context);
}
}
|
|
|
|
|
And the exception message would be .....?? Without it, there's nothing anyone can do to help you.
|
|
|
|
|
I have a Menustrip, in which there are 2 toolStripMenuItems called File and Help and their fore color is White while back color is a shade of blue
Help in it's dropdown has 4 other toolStripMenuItems, now when i click Help, the 4 items display but their parent toolStripMenuItem(Help) and it's back color goes white.
Can somebody tell me what i can do for it.
|
|
|
|
|
Hi i want to design account class. with lock keyword in withdraw method.
|
|
|
|
|
|
Unless you are using threading within your application, lock is pretty much irrelevant. It will not prevent other instances of your application from making changes, even if they are on the same PC.
However, the MSDN[^] article on lock covers it prety well if you are threading.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Ok, but that's not a question. What do you want to know?
|
|
|
|
|
I am attempting to filter a list, nothing unusual, done it 1000s of times.
List<NBAggDB> lAgg = lNBAgg.Where(x => x.NodeKey.StartsWith(oParentNode.NodeKey)).ToList();
ParentNode is populated and has a NodeKey, lNBAgg is a List<nbaggdb> and is populated and all have valid NodeKeys
Yet I get the following exception an the only null object is x and the following is highlighted by the exception.
x.NodeKey.StartsWith(oParentNode.NodeKey)
{System.NullReferenceException: Object reference not set to an instance of an object.
at Texas.ViewModels.NewBusinessVM.<>c__DisplayClass11.<LoadAggRows>b__10(NBAggDB x)
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Texas.ViewModels.NewBusinessVM.LoadAggRows(TreeNodeNB oParentNode)
at Texas.ViewModels.NewBusinessVM.LoadBudgetCells(TreeNodeNB oNode)
at Texas.ViewModels.NewBusinessVM.LoadNodeChildren(TreeNodeNB oParentNode)
at Texas.ViewModels.NewBusinessVM.LoadNodeChildren(TreeNodeNB oParentNode)
at Texas.ViewModels.NewBusinessVM.LoadNodeChildren(TreeNodeNB oParentNode)
at Texas.ViewModels.NewBusinessVM.LoadNodeChildren(TreeNodeNB oParentNode)
at Texas.ViewModels.NewBusinessVM.<LoadNBBudget>b__2(String sErrorMsg, ObservableCollection`1 lResult)
at Texas.DataServices.NBBudgetDS.NBBudgetForPeriodCompleted(Object sender, NBBudgetForPeriodCompletedEventArgs e)
at Texas.TexasSvc.TexasSvcClient.OnNBBudgetForPeriodCompleted(Object state)}
How the hell am I supposed to debug that?
[edit] lNBAgg is populated with null objects [/edit]
Never underestimate the power of human stupidity
RAH
modified 10-Apr-14 20:38pm.
|
|
|
|
|
I've run into this a couple of times with the database I'm working with.
The code works, right up until one of your NodeKey objects is null, OR, in your case, oParentNode is null. Somewhere in that pile of data you're working with...
|
|
|
|
|
It was actually caused by a type mismatch between the database and the object, the conversion is done in the DAL and returns a null object when there is a mismatch, I forgot to put in the error trap and got bitten AGAIN! The code is all generated at that level and I have not moved the trap into the code generator .
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
That sounds like a better problem to have than the one I've got! Trust me, you don't want to know. On top of that, it's a problem of my own creation!
|
|
|
|
|
Hello,
I am writing a visual C# program to read GPS coordinates (x,y) and will like to plot the points on a form as a bitmap, can someone advise me on the most effective way in doing that?
Thanks,
Ron
|
|
|
|
|
You just need to scale the points to the coordinate system that you use in your bitmap. For example, if your bitmap is 100 x 100, and your latitude and longitude cover a range of 20 degrees each. Then each degree covers a range of 5 pixels, or alternatively each pixel is equivalent to 12 minutes. So to convert a latitude of 10'30" to pixel point, convert to minutes 10 * 60 + 30 = 630, divide by 12 = 52.5, rounded = 53. So that point lies at Y coordinate 53.
|
|
|
|
|
Thanks for the ideas, I'll see how this works out
Ron
|
|
|
|
|
In addition to what Richard said if I need to draw I usually use GDI+ for simple things.
You can add a panel to your form and make the background white.
Then you can get a Graphics [^]object from that. You use the FromHwnd[^] method and pass the panel's handle to it. Now you can use the Graphics object to draw.
Note that this also uses coordinates with 0,0 on the top left corner. The width and height of the panel are your maximum lengths to draw within the boundaries. Note that the x-axis is going to the right and the y-axis is going down!
Hope this helps.
(PS: there's probably a charting library available on Codeproject, you could search for that)
modified 11-Apr-14 4:59am.
|
|
|
|
|
You may also take a look at my article Bernie’s Trackviewer[^]. There, the corrdinates are loaded from gpx files.
|
|
|
|
|
I have a class that implements 2 interfaces.
I have a property that is of the type of one of those 2 interfaces.
Problem is, I want to use the other interface.
So class A implements interfaces B(my own interface) & C(third party interface).
In class D, I have a property E of type C.
How do I cast property E to type B?
ICustomControl control = (ICustomControl)Component;
is basically what I'm trying to do. But I get an exception when I try to do that.
the value of Component is a class that inherits from interface ICustomControl. The property Component is of type IComponent.
Any help would be appreciated.
|
|
|
|
|
Nico Haegens wrote: But I get an exception when I try to do that.
You'll need to post the details of the exception. Based on your description, the code you've posted will work:
interface IComponent {}
interface ICustomControl {}
class A : IComponent, ICustomControl {}
class D
{
public IComponent TheProperty
{
get { return new A(); }
}
}
static void Main()
{
D container = new D();
ICustomControl value = (ICustomControl)container.TheProperty;
Console.WriteLine(value);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'll provide more details:
Got 3 classes & 1 interface
1 class that has all the functionality and implements an interface
1 class that makes that class generic, has 1 property named DataItemTypeName and inherits from above class
1 class that wraps the generic class so it's usable in a webpage and also inherits from the first class.
in the controldesigner, I'm trying to access the control I made through the property Component which runtimetype is the type of the generic class.
What I understood from the exception is that it's trying to cast class nr 2 to the interface that it's baseclass implements and fails.
When I get to a line of code that says:
ICustomRepeater control = (ICustomRepeater)Component;
I get the exception below:
System.InvalidCastException was unhandled by user code
HResult=-2147467262
Message=Unable to cast object of type 'CustomRepeaterNS.CustomGenericItemsControl`1[TestApp.DummyTestClass]' to type 'CustomRepeaterNS.ICustomRepeater'.
Source=CustomRepeater
StackTrace:
at CustomRepeaterNS.CustomRepeaterDesigner.GetDesignTimeHtml() in d:\CustomRepeater\CustomRepeater\CustomRepeater.cs:line 842
at System.Web.UI.Design.ControlDesigner.GetDesignTimeHtml(DesignerRegionCollection regions)
at CustomRepeaterNS.CustomRepeaterDesigner.GetDesignTimeHtml(DesignerRegionCollection regions) in d:\CustomRepeater\CustomRepeater\CustomRepeater.cs:line 807
at System.Web.UI.Design.ControlDesigner.GetViewRendering(ControlDesigner designer)
InnerException:
|
|
|
|
|