| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 | using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.IO;using System.Linq;using System.Text;using System.Text.RegularExpressions;using System.Threading.Tasks;using System.Windows.Forms;using System.Xml;namespace OTSIncAReportApp.OTSMgrInfo{    public partial class FormNewLJFile : Form    {        private DataTable partsize = new DataTable();                public FormNewLJFile(DataTable a_dataTable)        {            partsize = a_dataTable;            InitializeComponent();        }        private bool Verify()        {            if (tb_FlieName.Text == "")            {                MessageBox.Show("输入的粒级名错误,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                tb_FlieName.Focus();                return false;            }            string tipstr = "粒级值输入错误,请输入粒级的阶段,中间使用“,”号进行分隔,例如:\r\n “1,5,10,15,20,30,40,50” \r\n或可带有小数,例如: \r\n “0.5,1.0,2.22,5.55,8.55,10.33,15,30,40” \r\n如果出现错误,请详细检查输入的格式是否正确,\r\n符号“,”与“.”的输入法是否为英文,及是否半角格式。";            //粒级值判断            if (tb_new_ljz.Text == "")            {                MessageBox.Show(tipstr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                tb_new_ljz.Focus();                return false;            }            //粒级值判断,判断是否能通过,纯数字和.及,号组合的正则表达式判断            string pat = @"^[-.,0-9]+$";//纯数字,和.及,            Regex rg = new Regex(pat);            if (false == rg.Match(tb_new_ljz.Text).Success)            {                MessageBox.Show(tipstr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                tb_new_ljz.Focus();                return false;            }            //粒级值判断,对输入的值进行拆分,然后再对拆分出的各值判断            string[] spstr = tb_new_ljz.Text.Split(',');            for (int i = 0; i < spstr.Length; i++)            {                string lsstr = spstr[i];                pat = @"^\d+(\.\d+)?$";//纯正浮点数数值,含0                rg = new Regex(pat);                if (false == rg.Match(lsstr).Success)                {                    MessageBox.Show(tipstr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                    tb_new_ljz.Focus();                    return false;                }            }            //最后转换,是否抱错            try            {                for (int i = 0; i < spstr.Length; i++)                {                    double lsd = Convert.ToDouble(spstr[i].Trim());                }            }            catch            {                MessageBox.Show(tipstr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                tb_new_ljz.Focus();                return false;            }            return true;        }        private void bt_save_Click(object sender, EventArgs e)        {            //校验输入合法性            if (Verify() == false)            {                return;            }            for (int i=0; i< partsize.Rows.Count;i++ )            {                if(partsize.Rows[i]["FileName"].ToString()== tb_FlieName.Text+ ".psf")                {                    MessageBox.Show("File name conflict");                    return;                }                if(partsize.Rows[i]["Name"].ToString() == tb_new_ljm.Text)                {                    MessageBox.Show("Particle name conflict");                    return;                }            }            FileStream file = new FileStream(Environment.CurrentDirectory + "\\Config\\ProData\\" + tb_FlieName.Text + ".psf", FileMode.CreateNew);            byte[] data = System.Text.Encoding.UTF8.GetBytes("<?xml version=\"1.0\" encoding=\"UTF-8\"?> \r\n<XMLData FileMark=\"626\" Name=\"" + tb_new_ljm.Text.Trim() + "\" Sizes=\"" + tb_new_ljz.Text.Trim() + "\" Version=\"1.1.1\" /> ");            file.Write(data, 0, data.Length);            file.Flush();            file.Close();            this.Close();        }        private void bt_export_Click(object sender, EventArgs e)        {            this.Close();        }    }}
 |