|
Hi all ,
Please help me i m writing the code in VB6 Plz give me same code in C#.
Open "lpt1" For Output As #1<br />
Print #1, Chr(27) & "@" 'Initialize printer<br />
'Print #1, Chr(27) & "A" & Chr(15) ' set to 10/72"<br />
Print #1, Chr(27) & "M"<br />
Close #1
thanx in advance..
help as a alias.
Be happy and make others happy.Cheer up...........
|
|
|
|
|
System.IO.StreamWriter writer = System.IO.File.CreateText("lpt1");
writer.WriteLine("@");
writer.WriteLine("A" + ((char)15).ToString());
writer.WriteLine("M");
writer.Close();
Not sure about this, didn't test.
Next time write: "How to write to a file in c#", instead of "Give me a code", because people here usually do not like to "give a code"
Greetings - Gajatko
|
|
|
|
|
|
Is there any way to insert objects to a section in the crystal report at runtime?
I can able to add a text object to a section(say section 3) during development time and associate a data table column to that text field. Is there any way to do this at runtime?
Thanks,
Nanda
|
|
|
|
|
you can pass parameters at the time of loading of crystal report.
help as a alias.
Be happy and make others happy.Cheer up...........
|
|
|
|
|
I didn't got. Can you give a sample code?
|
|
|
|
|
if you r pass query(parameters) from the form to show the crystal report directly then i have a code for you that may help you.
<br />
private void AmountDue_Load(object sender, EventArgs e)<br />
{<br />
this.Width = 912;<br />
this.Height = 587;<br />
ParameterFields Fields = new ParameterFields();<br />
ParameterField Field = new ParameterField();<br />
ParameterDiscreteValue DescreateValue = new ParameterDiscreteValue();<br />
OleDbCommand MyCommand = new OleDbCommand();<br />
OleDbDataAdapter MyDa = new OleDbDataAdapter();<br />
DataSet MyDs = new DataSet();<br />
ReportDocument crReportDocument = new ReportDocument(); <br />
<br />
mainObj.s = sAmountDue;<br />
mainObj.choosedata();<br />
string RecordString = "Select housetype,OwnerName,meternumber,DueAmount from Client order by housetype";<br />
mainObj.passconn.Open();<br />
MyCommand.Connection = mainObj.passconn;<br />
MyCommand.CommandText = RecordString;<br />
MyCommand.CommandType = CommandType.Text;<br />
MyDa.SelectCommand = MyCommand;<br />
mainObj.passconn.Close();<br />
MyDa.Fill(MyDs);<br />
string name = "AmountDueCrystalReport";<br />
string rptPath = Application.StartupPath + "\\" + name + ".rpt";<br />
if (!System.IO.File.Exists(rptPath))<br />
{<br />
throw (new Exception("Enable To Locate File:" + rptPath));<br />
}<br />
<br />
crReportDocument.Load(rptPath);<br />
crReportDocument.PrintOptions.PaperOrientation = PaperOrientation.Portrait;<br />
crReportDocument.PrintOptions.PaperSize = PaperSize.PaperA4;<br />
crReportDocument.Refresh();<br />
crReportDocument.SetDataSource(MyDs.Tables[0]);<br />
<br />
Field.ParameterFieldName = "ColnyName";<br />
DescreateValue.Value = sAmountDue.ToString();<br />
Field.CurrentValues.Add(DescreateValue);<br />
Fields.Add(Field);<br />
crystalReportViewer1.ParameterFieldInfo = Fields;<br />
crystalReportViewer1.ShowExportButton = false;<br />
crystalReportViewer1.ShowGroupTreeButton = false;<br />
crystalReportViewer1.DisplayGroupTree = false;<br />
crystalReportViewer1.ShowRefreshButton = false;<br />
crystalReportViewer1.ReportSource = crReportDocument; <br />
}<br />
i m using the same code also you must clear the reportsource(property of crystal repoet viewer) from the page design section.
help as a alias.
Be happy and make others happy.Cheer up...........
|
|
|
|
|
hi,
if i have a class like below:
[XmlRoot("MyData")]<br />
public class MyData:ArrayList<br />
{<br />
public MyData()<br />
{<br />
}<br />
public MyData(ArrayList shape, ArrayList color, ArrayList coord, ArrayList size, ArrayList gpd)<br />
{<br />
this.ShapeTypeList = shape;<br />
this.ColorList = color;<br />
this.CoordList = coord;<br />
this.SizeList = size;<br />
this.ArrS = gpd;<br />
}.......<br />
<br />
In the Form:
MyData data=new MyData();<br />
XmlSerializer s=new XmlSerializer(typeof(MyData));<br />
generates the error:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll<br />
<br />
Additional information: There was an error reflecting type 'DrawShape.MyData'.
How can i declare XmlSerializer for a Class MyData which inherits ArrayList class?
Thanks in advance
|
|
|
|
|
Hi cyn8
At first I couldn't understand why you derived MyData from ArrayList !!
and the problem :
it is one of the boring and annoying one.I tested and my brain was going to blown (thank god for saving me) it seems it happens because xmlSerializer can just serialize public class,and it's public memebers no more no less
here is a few things must be paid attention for xml serializtion
1-your class must be public
2-your class must have parameterless constructor
3-all members are chosen must be public and if they are property type they must have both get and set
4-if your class would be embedded in another class Xml in serialization the embedded class must have XmlInclude Attribute or in the outer class type of inner class must be passed through
(another way is pass it's type throught XmlSerializer constructor in extraTypes argument but I'm not sure it works well)
hope the post would be useful
good luck
|
|
|
|
|
and these are the codes I modified and tested (I'm really sorry about what I sent two days ago it didn't work well in desrialization )
Here is Correct ones
[XmlRoot("MyData")]
[Serializable]
public class MyData
{
ArrayList shapeTypeList;
ArrayList colorList;
ArrayList coordList;
ArrayList sizeList;
ArrayList graphicsPathDataList;
[XmlArray("ShapeData")]
[XmlArrayItem("Shape")]
public ArrayList ShapeTypeList
{
get { return this.shapeTypeList; }
set { this.shapeTypeList = value; }
}
[XmlArray("ColorData")]
[XmlArrayItem("Color")]
public ArrayList ColorList
{
get { return this.colorList; }
set { this.colorList = value; }
}
[XmlArray("CoorinationData")]
[XmlArrayItem("Coordination")]
public ArrayList CoordList
{
get { return this.coordList; }
set { this.coordList= value; }
}
[XmlArray("SizeData")]
[XmlArrayItem("Size")]
public ArrayList SizeList
{
get { return this.sizeList; }
set { this.sizeList = value; }
}
[XmlArray("GPDDataCollection")]
[XmlArrayItem("GPD",Type=typeof(GraphicsPathData))]
public ArrayList GraphicsPathDataList
{
get { return this.graphicsPathDataList; }
set { this.graphicsPathDataList = value; }
}
public MyData(ArrayList shape, ArrayList color, ArrayList coord, ArrayList size, ArrayList gpd)
{
this.shapeTypeList = shape;
this.colorList = color;
this.coordList = coord;
this.sizeList = size;
this.graphicsPathDataList = gpd;
}
private MyData()
{
}
static MyData BinLoad(string path)
{
BinaryFormatter binSer=new BinaryFormatter();
FileStream fo=new FileStream(path,FileMode.Open);
object data=binSer.Deserialize(fo);
fo.Close();
return data as MyData;
}
void BinSerialize(string path)
{
BinaryFormatter binSer=new BinaryFormatter();
FileStream fo=new FileStream(path,FileMode.OpenOrCreate);
binSer.Serialize(fo,this);
fo.Close();
}
static MyData XmlLoad(string path)
{
XmlSerializer xmlSer=new XmlSerializer(typeof(MyData));
FileStream fo=new FileStream(path,FileMode.Open);
object data=xmlSer.Deserialize(fo);
fo.Close();
return data as MyData;
}
void XmlSerialize(string path)
{
XmlSerializer xmlSer=new XmlSerializer(this.GetType());
FileStream fo=new FileStream(path,FileMode.OpenOrCreate);
xmlSer.Serialize(fo,this);
fo.Close();
}
public enum SerializeTo{XML,Binary};
public void Serialize(string path,SerializeTo to)
{
if(to==SerializeTo.Binary)
this.BinSerialize(path);
else
this.XmlSerialize(path);
}
public static MyData Load(string path,SerializeTo to)
{
if(to==SerializeTo.Binary)
return BinLoad(path);
else
return XmlLoad(path);
}
}
and the GraphicspathData must be modified somewhat like this
[Serializable]
[XmlRoot("GraphicsPathData")]
[XmlInclude(typeof(GraphicsPathData))]
public class GraphicsPathData
{
byte[] types;
PointF[] points;
FillMode fillMode;
[XmlArray("Types")]
public byte[] Types
{
get { return this.types; }
set { this.types = value; }
}
[XmlArray("Points")]
public PointF[] Points
{
get { return this.points; }
set { this.points = value; }
}
[XmlElement("FillMode")]
public FillMode FillMode
{
get { return this.fillMode; }
set { this.fillMode = value; }
}
public GraphicsPathData(GraphicsPath gp)
{
this.types = gp.PathTypes;
this.points = gp.PathPoints;
this.fillMode = gp.FillMode;
}
private GraphicsPathData()
{
}
public static System.IO.Stream Serialize(GraphicsPathData gpd)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bf.Serialize(ms, gpd);
ms.Flush();
return ms;
}
public static GraphicsPathData Deserialize(System.IO.Stream stream)
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
object obj = bf.Deserialize(stream);
GraphicsPathData gpd = obj as GraphicsPathData;
return gpd;
}
public static GraphicsPath GetGraphicsPath(GraphicsPathData gpd)
{
return new GraphicsPath(gpd.points, gpd.types, gpd.fillMode);
}
public static GraphicsPath GetGraphicsPath(System.IO.Stream gpdStream)
{
return GetGraphicsPath(Deserialize(gpdStream));
}
}
good luck
|
|
|
|
|
hi, i'm sorry to say that i'm still stuck. The XML file can be generated but it is the same as shown before where there is no root and all the element is "ArrayOfAnyType"
<br />
[XmlRoot("MyData")]<br />
public class MyData<br />
{<br />
ArrayList shapeTypeList;<br />
ArrayList colorList;<br />
ArrayList coordList;<br />
ArrayList sizeList;<br />
ArrayList arrS;<br />
<br />
[XmlArray("ShapeData")]<br />
[XmlArrayItem("Shape",typeof(ShapeL))]<br />
public ArrayList ShapeTypeList<br />
{<br />
get { return this.shapeTypeList; }<br />
set{this.shapeTypeList=value;}<br />
}<br />
<br />
public class ShapeL<br />
{<br />
public ShapeL(){}<br />
public TypeOfShape c<br />
{<br />
get{return c;}<br />
set{c=value;}<br />
<br />
}<br />
<br />
}<br />
<br />
[XmlArray("ColorData")]<br />
[XmlArrayItem("Color",typeof(ColorL))]<br />
public ArrayList ColorList<br />
{<br />
get { return this.colorList; }<br />
set{this.colorList=value;}<br />
}<br />
<br />
public class ColorL<br />
{<br />
public ColorL(){}<br />
[XmlElement("color")]<br />
public Color c<br />
{<br />
get{return c;}<br />
set{c=value;}<br />
<br />
}<br />
<br />
}<br />
<br />
[XmlArray("CoordinateData")]<br />
[XmlArrayItem("Coordinate",typeof(Coordinate))]<br />
public ArrayList CoordList<br />
{<br />
get { return this.coordList; }<br />
set{this.coordList=value;}<br />
}<br />
<br />
public class Coordinate<br />
{<br />
public Coordinate(){}<br />
public Point[] point<br />
{<br />
get{return point;}<br />
set{point=value;}<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
[XmlArray("SizeData")]<br />
[XmlArrayItem("Size",typeof(SizeL))]<br />
public ArrayList SizeList<br />
{<br />
get { return this.sizeList; }<br />
set{this.sizeList=value;}<br />
}<br />
<br />
public class SizeL<br />
{<br />
public SizeL(){}<br />
public Size c<br />
{<br />
get{return c;}<br />
set{c=value;}<br />
<br />
}<br />
<br />
}<br />
<br />
[XmlArray("GPDData")]<br />
[XmlArrayItem("GPD",typeof(ArrSave))]<br />
public ArrayList ArrS<br />
{<br />
get { return this.arrS; }<br />
set{ this.arrS=value;}<br />
}<br />
public class ArrSave<br />
{<br />
public ArrSave(){}<br />
public MemoryStream c<br />
{<br />
get{return c;}<br />
set{c=value;}<br />
<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
public MyData()<br />
{<br />
}<br />
<br />
public MyData(ArrayList shape, ArrayList color, ArrayList coord, ArrayList size, ArrayList gpd)<br />
{<br />
this.ShapeTypeList = shape;<br />
this.ColorList = color;<br />
this.CoordList = coord;<br />
this.SizeList = size;<br />
this.ArrS = gpd;<br />
}<br />
<br />
<br />
<br />
public enum TypeOfShape<br />
{<br />
Square, Rect, Parallelogram, Trapezoid, Diamond, Triangle, RightAngleTriangle,Circle,Oval,Hexagon,Pentagon,None<br />
}<br />
<br />
<br />
public void save( string filename)<br />
{<br />
XmlSerializer ser = new XmlSerializer(typeof(ArrayList),new Type[] {typeof(Coordinate),typeof(ColorL),typeof(ShapeL),typeof(SizeL),typeof(ArrSave)} );<br />
<br />
ArrayList arr=new ArrayList();<br />
TextWriter w = new StreamWriter( filename );<br />
ser.Serialize( w, this.ShapeTypeList );<br />
ser.Serialize( w, this.ColorList );<br />
ser.Serialize( w,this.CoordList );<br />
ser.Serialize( w, this.SizeList );<br />
<br />
for(int i=0;i<this.ArrS.Count;i++)<br />
{<br />
GraphicsPathData gpd = new GraphicsPathData((GraphicsPath)this.ArrS[i]);
Stream gpdStream = GraphicsPathData.Serialize(gpd);<br />
arr.Add(gpdStream);<br />
<br />
}<br />
ser.Serialize( w, arr);<br />
<br />
w.Close();<br />
}
Then in save function located at the form, i write:
<br />
MyData d=new MyData(ShapeTypeList,ColorList,CoordList,SizeList,PathList);<br />
d.save(filename);
Please help...I'm been cracking my head for hours
Thanks for your helps...
-- modified at 23:13 Tuesday 21st August, 2007
|
|
|
|
|
I Saw your code you didn't pay attention to rules I said before
IF YOU SERIALIZE AN ARRAYLIST DIRECTLY IT WOULD GIVE YOU THE RESULTS LIKE THAT!
MyData class actually is scheme for xmlSerializer so you don't need to put each array in serializer (in addition I said before retriving the data would be difficult too)
just put MyData Class in Serializer and all memebers you marked with attributes would be serialized
another thing is Color Struct properties are readonly so you can't seriailize it with xmlSerializer you must create a new Color Class with specific attributes
and Please don't serialize GraphicpathData and then serialize the streams again with xmlserializer i have doubt it works in Deserializing atall and ofcourse it waste the Resources
at last i put a complete code in
http://hjk.4shared.com
or direct link
http://www.4shared.com/file/22596905/834df73f/XmlSerializationExample.html[^]
good luck
|
|
|
|
|
Sorry, the links does not seem to work. Can you please send it again? Thanks
|
|
|
|
|
Are you sure??
I test them and they works
here they are again
http://hjk.4shared.com
and there is xmlSerializationExample.Zip there after clicking on it to download
in download page yuo must wait alittle and the DownloadFile link would appear
here is the direct link to file
http://www.4shared.com/file/22596905/834df73f/XmlSerializationExample.html
here is the new link
http://rapidshare.com/files/50526458/XmlSerializationExample.zip.html
AS A TIP YOU CANNOT DOWNLOAD FROM THESE LINKS WITH DOWNLOAD MANAGERS AND ACCELERATORS
and sorry if you had problem in downloading them just give your mail if you want
hope these links work
|
|
|
|
|
THANK YOU!!! You are a LIFE SAVER!!!
Man, it is the people like you that makes this world a better place to live in:P
Your codes works like a charm.
However, there is a small problem, there seem to extra shape(exactly same shape) that is overlap on each shape. When i drag and drop on of the shape, the extra shape is temporary will be display at the original coordinate. But later if i want to drag the extra shape, it cannot be dragged and sometimes after i dragged a shape, all the extra shapes that is position on the saved shape original position will disappear. What you think that it is caused by?
Below are the codes in the Load function located in the form( ShapeTypeList,CoordList,SizeList are arraylist that contains the data for the shapes to be drawn on the form):
<br />
<br />
OpenFileDialog openFileDialog = new OpenFileDialog();<br />
ArrayList arr =new ArrayList();<br />
ArrayList ColorArr =new ArrayList();<br />
if (openFileDialog.ShowDialog() == DialogResult.OK)<br />
{<br />
filename = openFileDialog.FileName;<br />
<br />
ClearArrayList();<br />
MyData deserializeData =MyData.Load(filename);<br />
ShapeTypeList=deserializeData.ShapeTypeList;<br />
CoordList=deserializeData.CoordList;<br />
ColorArr=deserializeData.ColorList;<br />
SizeList=deserializeData.SizeList;<br />
arr=deserializeData.GraphicsPathData;<br />
<br />
for(int j=0;j<ColorArr.Count;j++)<br />
{<br />
<br />
MyColor myC=(MyColor)ColorArr[j];<br />
ColorList.Add(Color.FromArgb(myC.A,myC.R,myC.G,myC.B));<br />
<br />
}<br />
<br />
GraphicsPath myPath=new GraphicsPath();<br />
int k=0;<br />
for(int i=0;i<arr.Count;i++)<br />
{<br />
if((TypeOfShape)ShapeTypeList[i]==TypeOfShape.Oval||(TypeOfShape)ShapeTypeList[i]==TypeOfShape.Circle)<br />
{<br />
Point[] p=(Point[])CoordList[i];<br />
Size s=(Size)SizeList[k];<br />
myPath.AddEllipse(p[0].X,p[0].Y,s.Width,s.Height);<br />
k++;<br />
}<br />
<br />
else<br />
{<br />
myPath.AddPolygon((Point[])CoordList[i]);<br />
}<br />
<br />
PathList.Add(myPath);<br />
}<br />
<br />
panel1.Invalidate();<br />
}<br />
What should i do to solve this problem?
Thanks a million
-- modified at 6:53 Thursday 23rd August, 2007
|
|
|
|
|
Hi
at first thank you .
and about the problem I don't know I get it or not but it seems you want to draw eeah sahpe in a single path right?
<code>GraphicsPath myPath=new GraphicsPath();</code>
int k=0;
for(int i=0;i {
if((TypeOfShape)ShapeTypeList[i]==TypeOfShape.Oval||(TypeOfShape)ShapeTypeList[i]==TypeOfShape.Circle)
{
Point[] p=(Point[])CoordList[i];
Size s=(Size)SizeList[k];
myPath.AddEllipse(p[0].X,p[0].Y,s.Width,s.Height);
k++;
}
else
{
myPath.AddPolygon((Point[])CoordList[i]);
}
<code>PathList.Add(myPath);</code>
}
panel1.Invalidate();
}
in the code above I marked some lines as red if i was right about what you want to do
in the first red line you create an instance of the GraphicPath and darw all of the shapes inside it but in the second red line with ireratinf in the shapes you add it to a arrayList
so infact you draw all your shapes in just ine Graphic path and then for each shape add it to the arraylist so you have same Graphicpath as many as your shapes and you draw it
I think on your test so it wll make extra shape!
for solving this simply put the first red line in the loop and it would create ab instance of Graphicpath each time and prevent from extra shapes.
hope this helps
Best regards
|
|
|
|
|
Hi,
Thanks...Your solution is just what i need to do!
Now it seems that all is working properly
Thanks and best regards
Have a nice day
|
|
|
|
|
your welcome
have a nice day too
|
|
|
|
|
I tried Ping class of VS.NET but Mono doesn't support this.How can i ping on Mono like "ping -c 1 123.123.123.123" and how to get its echo(return value)?
|
|
|
|
|
bug_aonz wrote: Mono doesn't support this
Any compilation or runtime issues?
|
|
|
|
|
i want to run my C# console app with Mono-project on Linux server.My app proposes to do a realtime ping IP addresses in the list and get the state that target IP online or offline.
|
|
|
|
|
Windows XP:
C# 2005
I want to get the installed software List from my Windowsxp operting
system.Anybody help me.
Continue...
|
|
|
|
|
|
How do you call a Matlab dll mexFunction from C# code? Assuming you declare the mexFunction using the DllImport attribute, how do declare mxArray params...?
e.g.
[DllImport("mexdll.dll", EntryPoint="mexFunction")]
private static extern void mexFunction(int nlhs, ?? plhs, int nrhs, ?? prhs);
Cheers
Goose
|
|
|
|
|
First, you may want to have a look at the MATLAB Builder for .NET[^]
Second, it would have been helpful to have posted the original C calling syntax for the mexFunction , which is
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]); There is an example here Integrating MATLAB with C#[^] that might help you as well, but you probably want the mxArray parameters to be declared as ref IntPtr or possibly out IntPtr[] parameters.
|
|
|
|
|