C # Call txt, XML, regular expression, and codesoft to print the bar code

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.