|
|
Hello all,
m trying to apply sql transaction on many insert command,
the problem that m using multi-tear application and Typed Data Set and i want to do the commet and the rollback on the UI layer ,
so any suggestions are welcomed!
|
|
|
|
|
i fixed the problem
thx!!!
|
|
|
|
|
Yes: DON'T PUT DATABASE ACCESS IN THE UI!!!
|
|
|
|
|
I buid a UserControl , and how to forbid it to get focus?
And how to forbid a ToolStripControlHost to get focus ,when the ToolStripDropDown is opened?
|
|
|
|
|
Try setting .CanFocus to false?
I don't know whether or not it does what you want, I've always found trying to control focus rather frustrating so I don't bother anymore.
|
|
|
|
|
just put visible = false or enable = false.
Do you want to triggers a control from other usercontrol/form?
(place another post).
|
|
|
|
|
Hi
I am using nHibeernate version 1.0.4., which I took from SourceForge.Net with the configuration settings given in the site itself. I am getting the follwing error in Mapping a file.
Error Could not find a getter for property 'UN' in class 'Address.Info'
A first chance exception of type 'System.NullReferenceException' occurred in Address.exe
Please find below my code files: PLease replace &lt; with '<' and &gt; with '>'.
class Info
{
private int id;
private string UN;
private string PN;
}
My mapping File with name Info.hbm.xml:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name ="Address.Info, Address" table ="Info">
<id name ="Id" column="LoginID" type ="Int32" unsaved-value ="0">
<generator class="native" />
</id>
<property name="UN" column="UN" type="String(50)" />
<property name="PN" column="PN" type="String(50)" />
</class>
</hibernate-mapping>
Could you please tell me what I need to do to reslove this issue??
Thanks in Advance
With Regards,
Puneet
|
|
|
|
|
Well, have you looked around at NHibernate's documentation?
puneet.bhatnagar123@gmail.com wrote: PLease replace < with '<' and > with '>'.
There is a checkbox at the bottom that says Ignore HTML tags in this message (good for code snippets)
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Finally got to a point where I need to use my own interface but got a bit stuck here.
I have a simple interface
public interface IStockItem : IComparable
{
string StockCode { get; set; }
}
and two structs that implement it fully: SparePart and ServiceTool
and collections of the two structs SparePartCollection<SparePart> and ServiceToolCollection<ServiceTool>
Now I need to get all the SparePart and ServiceTool objects together and sort them by the StockCode property.
What's the best way to collate the object collections to one collection based on the interface, and how do I implement CompareTo on that collection?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
The solution depends on how you sort the SparePart s and ServiceTool s.
One solution would be to add both collections to a single collection and then sort using a delegate, like this:
private static int CompareStockItems(IStockItem x, IStockItem y)
{
if (x.StockCode.Length < y.StockCode.Length)
return -1;
else if (x.StockCode.Length > y.StockCode.Length)
return 1;
else
return 0;
}
List<IStockItem> items = new List<IStockItem>();
items.AddRange(sparePartCollection);
items.AddRange(serviceToolCollection);
items.Sort(CompareStockItems);
You can also just do items.Sort() without specifying a sorting delegate, then the CompareTo methods of the two classes will be used.
This however depends on the implementation of the CompareTo method. If you want SparePart s only to be compared between themselves and ServiceTool s also only between ServiceTool s, then both CompareTo methods are likely to be different and you'd have to use a delegate to sort them in the list.
If the comparison is the same for both stock item types though, then you can duplicate the CompareTo method in both implementations and use something like:
public int CompareTo(object obj)
{
IStockItem item = obj as IStockItem;
if (item == null)
return -1;
else
{
if (this.StockCode.Length < item.StockCode.Length)
return -1;
else if (this.StockCode.Length > item.StockCode.Length)
return 1;
else
return 0;
}
}
for both stock item implementations. I don't recommend this design though, as a change in one implementation needs to be changed in the other accordingly.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Excellent and very helpful answer - thankyou!
I'll have a play with the various solutions ASAP
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Got it working - thanks.
Only problem is using the AddRange method - I get:
Argument '1': cannot convert from 'SparePartCollection' to 'System.Collections.Generic.IEnumerable<IStockItem>'
I can fix this by making the SparePartCollection : List<IStockItem> but that will be no use as I need the collection to be a List<SparePart>
(Obviously the same applies to ServiceToolCollection)
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
I've managed to make it work by using the ConvertAll method but it seems messy!
items.AddRange(spares.ConvertAll(new Converter<SparePart, IStockItem>(SparePart.ToIStockItem)));
and in SparePart struct
public static IStockItem ToIStockItem(SparePart value)
{
return (IStockItem)value;
}
Is there a better way?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
/edit: my initial advice didn't work.
Looks like you really have to convert the entire collection. However, you can save the static method by using an anonymous method:
items.AddRange(collection.ConvertAll(new Converter<SparePart,IStockItem>(delegate(SparePart value) { return (IStockItem)value; })));
In 3.5 and the System.Linq namespace, you can also use this:
items.AddRange(collection.Cast<IStockItem>());
regards
modified on Saturday, August 2, 2008 11:35 AM
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: items.AddRange(collection.Cast<istockitem>());
Yay - good old Linq
Thanks for all your help.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
I've adapted your code(s) to my real world code (more complex than the example I posted) and it's working superbly. Thanks very much - again. I wish there was a way I could vote 10 for your help with this!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi
I am drawing a rectangle using OnmouseClick(vector image)..how can i convert to meta file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnMouseClick(MouseEventArgs e)
{
Graphics g = this.CreateGraphics();
g.DrawRectangle(new Pen(Color.Blue), new Rectangle(e.X, e.Y, 20, 40)); // How can i convert this vector in to a \\ meta file
base.OnMouseClick(e);
}
protected override void OnPaint(PaintEventArgs e)
{
//how to display the meatfile here
base.OnPaint(e);
}
}
}
Can anyone please explain this with source code.
Regards,
ALGATES
algates
|
|
|
|
|
It is very bad practice to paint on a form through a non-graphic event. (For assistance purposes, I am assuming a meta file is an image). The following is pseudocode (not syntactically accurate).
public Form:Form
{
bool isClickedPerformed=false;
public override OnMouseClick(...)
{
if(e.MouseButton==MouseButton.Right)
isClickedPerformed=true;
this.invalidate();
}
public override OnPaint(....)
{
if(isClickedPerformed)
e.graphics.drawimage(...follow paramters/usage based on either MSDN Documentation or Object Browser in VS IDE);
}
}
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
Hi all,
How to find Content datatype in a String.
ex: String str="";
In above string accepting only numeric or only characters(string).
i.e: str = "3";
str ="abcdefgh";
I have to find content data type in 'str' variable i.e whether the assigned value is integer or string.
Please suggest me, how to find that.
Thanks in advance
sekhar
|
|
|
|
|
If you want to accept only a number, why not use an integer? You can always convert the integer to string. I'd be shocked if C# didn't have something like ToString().
|
|
|
|
|
int.TrypParse(string, out int) method. Some other ther types have the TryParse method too - all return a bool indicating whether it was successful and an out parameter which passes the value to a variable of the type you were checking for.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi,
you can use regex match to determine its content.
|
|
|
|
|
ThanQ for your response.
Could you please write code for that.
Regards
sekhar
|
|
|
|
|
sekhar.k wrote: Could you please write code for that.
I thought that this was a forum for programmers, not copy-pasters...
if (Regex.Match(str, "^\d+$").Success) ...
^ = start of string
\d = any digit
+ = one or more times
$ = end of string
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|