|
damianrda wrote: Hey, just wondering what the best method would be for storing simple objects in an mysql table.
One popular method is called Object Relational Mapping[^]
led mike
|
|
|
|
|
Ok, well i managed to serialize the object using a binaryformatter and then base64'd the result.
<br />
public string Serialize()<br />
{<br />
MemoryStream MemStream = new MemoryStream();<br />
BinaryFormatter Serializer = new BinaryFormatter();<br />
<br />
Serializer.Serialize(MemStream, this);<br />
<br />
return Encoding.ASCII.GetString(MemStream.ToArray()).ToBase64();<br />
}<br />
but im having some issues when deserializing:
"End of stream encountered before parsing was completed."
<br />
public static Address Deserialize(string SerializedData)<br />
{<br />
Address Address;<br />
MemoryStream MemStream = new MemoryStream();<br />
BinaryFormatter Serializer = new BinaryFormatter();<br />
<br />
string Decoded = SerializedData.FromBase64();<br />
byte[] Buffer = Encoding.ASCII.GetBytes(Decoded);<br />
MemStream.Write(Buffer, 0, Buffer.Length);<br />
<br />
Address = (Address)Serializer.Deserialize(MemStream); <-- fails right here...<br />
<br />
return Address;<br />
}<br />
|
|
|
|
|
Basically, what you're missing is seeking the
stream pointer to the beginning after writing
to the memstream but before calling Deserialize().
Try
public string Serialize()
{
MemoryStream MemStream = new MemoryStream();
BinaryFormatter Serializer = new BinaryFormatter();
Serializer.Serialize(MemStream, this);
return Convert.ToBase64String(MemStream.ToArray());
}
public static Address Deserialize(string SerializedData)
{
byte[] Buffer = Convert.FromBase64String(SerializedData);
MemoryStream MemStream = new MemoryStream(Buffer);
BinaryFormatter Serializer = new BinaryFormatter();
return (Address)Serializer.Deserialize(MemStream);
}
*edit* condensed Deserialize() a bit
Mark Salsbery
Microsoft MVP - Visual C++
modified on Wednesday, July 30, 2008 6:29 PM
|
|
|
|
|
Hi,
Iam developing an application/service for printers.The scenario is as follows
1. When a user selects a document and then he says the print command(no through my application...he selects normal print in file menu)then i have to catch some details like printername,no.of pages,document name..and so on...This action should be done before it get out from spooler.
2. As all of you that after printing data from spooler will be deleted..but in general for example for HP printer 3 files like lpr1234.tmp,shockwaveobject file ,.shd are generated. In this I have take take required files and keep them in my own spooler.
On my extensive search I came to know that by using WMI and WindowsAPI functions I can get to this goal...
But Iam unable to get into the right way....
If I have to use APIs then kindly tell what are the method I have to implement(if possible give me documentation link)
If through WMI....kindly guide me for the same
ALL these should be act as a service.....
thanks in Advance
|
|
|
|
|
Application -> GDI -> Winspool.drv -> Spoolsv.exe
Your intension is to catch all the printer jobs that are generated from any window on your PC . That should be easy if you have only one window
we can use simple hook , but now we need to put a hook before the spooler.exe . Hey but what Winspool.drv does an RPC to the Spooler.exe.
1. Put a hook on the "winspool.Drv" EntryPoint="StartPagePrinter"
that is just as we do it with normal DLL
2. I am not sure but you can check this article
http://msdn.microsoft.com/en-us/library/aa230613(VS.60).aspx[^]
Vikas Amin
My First Article on CP" Virtual Serail Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
|
Hi,
Thanks for your help and very valuable suggestion
Now I developed a service that can pause my documents came for printing.This should also be done when a new document came for printing.
But how to achieve this Iam unable to do it.
for example...
I have given a document1,document2 for printing....then if i manually start my service it is making them into pause state..this is fine
But again a new one say document3 came for printing...Iam unable to make it to Pause state..Iam lacking here..
So I want to make my servcie work in such a way that it should identify a new document arrival for printing ..and automatically make it to pause state
If I have to make a scheduler what I have to write in that?
Kindly help me for that...
|
|
|
|
|
Sytem wide processes monitoring is complicated .
So did u try to put hook on the driver or the spooler ?
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
|
FindFirstPrinterChangeNotification
http://www.tech-archive.net/Archive/VC/microsoft.public.vc.mfc/2005-10/msg00013.html
http://msdn.microsoft.com/en-us/library/ms535514(VS.85).aspx
http://binaryworld.net/Main/CodeDetail.aspx?CodeId=3643
PRINTER_INFO_1 contains the page number information for the pritner job
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
hi all,
i write the following code for extract the data from a database, data also retrieved but there is a problem ...code is here
OracleConnection dataConnection = new OracleConnection();
ArrayList objList = new ArrayList();
try
{
dataConnection.ConnectionString = "Data Source=orc;Persist Security Info=True;User ID=scott;Password=tiger;Unicode=True";
dataConnection.Open();
OracleCommand datacommand = new OracleCommand("SELECT * FROM DEPT", dataConnection);
OracleDataReader datareader = datacommand.ExecuteReader();
Dept d = new Dept();
while (datareader.Read())
{
d.DNAME = datareader["DNAME"].ToString();
d.DEPTNO = datareader["DEPTNO"].ToString();
d.LOC = datareader["LOC"].ToString();
objList.Add(d);
}
datareader.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
dataConnection.Close();
}
try
{
cmbDname.DataSource = objList;
cmbDname.DisplayMember = "DNAME";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
but i amazed ......all filled data of combobox is same i.e DNAME
like : OPERATIONS (which is last row of DEPT table)
because
objList store only last data (OPERATIONS)........
but when i replace
objList.Add(d); with
objList.Add(d.DNAME); then objList store different DNAME..........but this time objList has only one colum <dname>....
my problem is that how can i store whole row in objList
|
|
|
|
|
Hi,
You actually create only one Dept object which is added to the list many times. So switch from
...
Dept d = new Dept();
while (datareader.Read())
{
...
to
...
Dept d;
while (datareader.Read())
{
d = new Dept();
...
Hope this helps,
Mika
p.s. Do not cross-post
|
|
|
|
|
i try
Dept d;
while (datareader.Read())
{
d = new Dept()
but fail i think problem is here .......
class Dept
{
public static string Deptno;
public static string Dname;
public static string Loc;
public string DNAME
{
get { return Dname; }
set { Dname = value; }
}
public string DEPTNO
{
get { return Deptno; }
set { Deptno = value; }
}
public string LOC
{
get { return Loc; }
set { Loc = value; }
}
}
|
|
|
|
|
What is the error message?
Mika
|
|
|
|
|
there is no syntax error ....there is a logical error..........
"objList" replace the previous data with new data on every loop....and that is problem....
|
|
|
|
|
Yes, the problem is in Dept class. Don't use static keyword on the fields containing the data since there is only one copy of the data.
Also it would make sense to protect the fields since you have public properties for setting and getting the field value.
class Dept {
private static string Deptno;
private static string Dname;
private static string Loc;
public string DNAME {
get { return Dname; }
set { Dname = value; }
}
public string DEPTNO {
get { return Deptno; }
set { Deptno = value; }
}
public string LOC {
get { return Loc; }
set { Loc = value; }
}
}
Hope this helps,
Mika
|
|
|
|
|
Mika beat me to it.
Yeah....applying the static modifier to the properties in your class makes it so that the "Department" class will maintain a SINGLE value for all instances of that class.
if you remove "static" as Mika suggested, you should be able to restructure your code as such to provide the functionality you're requesting:
ArrayList departments= new ArrayList();
Dept department;
while(reader.Read)
{
department = new Dept();
department.DName = reader["DepartmentName"]
department.DEPTNO = reader["DepartmentNumber"]
departments.Add(department);
}
One suggestion, simply from a coding style perspective: Don't abbreviate things that don't need to be abbreviated(unless you have some unknown technical limitation) Your objects are obviously being used for storing Department data, so why is your class not called "Department" ?
Your "DName" property would more appropriately be called "DepartmentName", but then again, with your class already named "Department", why would you need to restate the owner of the name? With a property of "Name", your object interface would be cleaner
department.Name;
"I need build Skynet. Plz send code"
|
|
|
|
|
thanks...thanks.........i (you) solve the problem
|
|
|
|
|
You're welcome
Mika
|
|
|
|
|
Using VS2005:
I've created a form, added a label control, and when I try to show it in my app, the label control is invisible, and the spot where it should be on the form is transparent (I can see the window contents of the window under the form).
I have not changed ANY properties in the form or the control. I'm using Form.Show() to display the form (I want it modeless).
BTW, if I use ShowDialog() to display it, calling Form.Close() does not dismiss the form (but calling Close() does work when I use Form.Show() ).
What have I done?
"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." - Jason Jystad, 10/26/2001
modified on Wednesday, July 30, 2008 12:19 PM
|
|
|
|
|
Hi,
Can you post the designer.cs code? It would be easier to try to find out the reason.
Mika
|
|
|
|
|
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
this.label1.BackColor = System.Drawing.Color.White;
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label1.CausesValidation = false;
this.label1.Font = new System.Drawing.Font("Arial", 9.75F,
((System.Drawing.FontStyle)
((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))),
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.ForeColor = System.Drawing.Color.DarkRed;
this.label1.Location = new System.Drawing.Point(47, 128);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(198, 24);
this.label1.TabIndex = 0;
this.label1.Text = "Loading program. Please wait...";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Lime;
this.CausesValidation = false;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "SplashPanel2";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.TransparencyKey = System.Drawing.Color.Lime;
this.ResumeLayout(false);
}
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
This is really odd,
Try to remove the TransparencyKey for the form. That corrected the problem for me, but then again the result isn't what you want.
[Modification starts]
Found this one which could be useful to you
http://support.microsoft.com/kb/820640/en-us?spid=7796&sid=195[^]
[Modification ends]
Mika
modified on Wednesday, July 30, 2008 1:47 PM
|
|
|
|
|
That was happening *before* I changed the transparency key.
As a test, I create a new form and added a label to it. I changed none of the properties. I compiled and ran the app, and it still looks like i described.
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hope you noticed the link I added to my previus post (we posted simultaneously )
I tried the same but the second form was acting nicely. However I may have some differences in setup (vista, vs2005+vs2008 etc) which could affect the result.
I also added SetStyle(ControlStyles.DoubleBuffer, false); to the constructor of the form (which has the problem-label) and after that the label is drawing fine, but I still cannot click the window. If I try, the object under the window is receiving click
Are you experiencing the same?
Mika
|
|
|
|