1. method for obtaining the installation path of the program application. startuppath
For example:
String Path =Application. startuppath + "\ wartercode. xml";
It is equivalent to server. mappath () in ASP. NET ();
2. Operate txt
(1) Determine whether the text exists. If it does not exist, create a text and write data to it. If it exists, read the data in it.
String Path = @ "C: \ wartercode.txt ";
Fileinfo Fi = new fileinfo (PATH );
If (! Fi. exists)
{
// If it does not exist, create a text
Streamwriter Sw =Fi. createtext ();
Sw. writeline ("0 ");
Sw. Close ();
}
Else {
// If yes, the font of the data is used as the streamline.
Streamreader sr =Fi. opentext ();
Int wartercode = convert. toint32 (Sr. Readline ());
Sr. Close ();
}
(2) Determine whether the text exists. If it does not exist, create a text and write data to it. If it exists, write data directly to it.
String time = system. datetime. Now. tostring ();
String labelinfo = Common. companyid + y0 + WW + W + no34 + common. moduleid + common. Version + V;
String logpath = system. Windows. Forms. application. startuppath + "\ logs \" + system. datetime. Now. tolongdatestring () + ". txt ";
Fileinfo Fi = new fileinfo (logpath );
Streamwriter SW;
If (! Fi. exists)
{
Sw = Fi. createtext ();
}
Else {
SW= New streamwriter (logpath, true); // True indicates that the content is appended to the end of the text
}
Sw. writeline (intssss + "\ t" + time + "\ t" + labelinfo );
Sw. Close ();
3. xml operations
Write Data to XML:
string path = Application.StartupPath + "\\WarterCode.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode root = doc.SelectSingleNode("Root");
XmlNodeList list = root.SelectNodes("WarterCodeNum");
list.Item(0).InnerText = wartercode.ToString();
doc.Save("WarterCode.xml");
For the application of XML in. net, refer to: http://www.cnblogs.com/JimmyZhang/archive/2008/12/07/1349454.html
4. Call codesoft
First, add a reference to lppx2.tlb under the codesoft installation directory, and then reference the namespace using labelmanager2;
Applicationclass LBL = new applicationclass ();
Try
{
LBL. Documents. Open (@ "D: Label. Lab", false); // call the designed label file.
Document Doc = LBL. activedocument;
Doc. variables. formvariables. Item ("var0"). value = txtcontent. Text. Trim (); // pass the parameter value
Doc. variables. formvariables. Item ("var1"). value = txtcontent2.text. Trim (); // pass the value to the parameter
Int num = convert. toint32 (txtquentity. Text); // print quantity
Doc. printdocument (Num); // print
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}
Finally
{
LBL. Quit (); // exit
}
5. Use regular expressions to test the input format
RegEx = new RegEx (@ "^ \ D + $ ");
If (! RegEx. ismatch (txtprintnum. Text. Trim ())){
MessageBox. Show ("there are records in the data volume! ");
Return;
}