打开文件获取文件名,正则表达式获取特定字符

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Data.OleDb;
using System.Collections;
namespace namenum2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string filePath = “”;
DataTable dtmedicode = new DataTable();

    DataTable dtgroove = new DataTable();
    private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog file = new OpenFileDialog();
        DialogResult result = file.ShowDialog();
        if (result == DialogResult.OK)
        {
            filePath = file.SafeFileName;
            int index = 0;
            string StrEX = string.Empty;
            string[] strtemp = { };
            Regex r = new Regex(@"[a-zA-Z]+");
            Match m = r.Match(filePath);
            StrEX = m.Value;

            if (StrEX.Substring(0, 1) == "A")
            {
                int lastindex = filePath.IndexOf('.', 0, filePath.Length);
                int startindex = filePath.IndexOf('A', 0, filePath.Length);
                int count = lastindex - startindex;
                string stemp = filePath.Substring(startindex, count);
                strtemp = stemp.Split('_');
            }
            else
            {
                int lastindex = filePath.IndexOf('.', 0, filePath.Length);
                int startindex = filePath.IndexOf('B', 0, filePath.Length);
                int count = lastindex - startindex;
                string stemp = filePath.Substring(startindex, count);
                strtemp = stemp.Split('_');
            }
            List<string[]> list_out = new List<string[]>();
            for (int i = 0; i < strtemp.Length; i++)
            {
                string[] str = {"","" };
                str[0] = strtemp[i].Substring(0, 2) + "-" + strtemp[i].Substring(2, 1) + "-" + strtemp[i].Substring(3, 1);
                str[1] = strtemp[i].Substring(4, 1);
                list_out.Add(str);
            }
            
            string show ="";
            for (int i = 0; i < list_out.Count; i++)
            {

                string drug_dic = list_out[i][0];
                int amount =Convert.ToInt32(list_out[i][1]);

                string strcon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Administrator\Desktop\name\data.mdb";
                using (OleDbConnection conn1 = new OleDbConnection(strcon))
                {
                    conn1.Open();
                    OleDbCommand cmd = conn1.CreateCommand();
                    cmd.CommandText = "SELECT 底座编号,药品名称 FROM Sheet1 WHERE 底座编号='"+drug_dic+"'";
                    OleDbDataReader reader = cmd.ExecuteReader();
                    string data="";
                    while (reader.Read())
                    {
                        data= string.Format("{0} ", reader[1]);
                
                    }
                    show=show+data+list_out[i][1]+"\r\n";
                    reader.Close();
                }


            }

            textBox1.Multiline = true;
            textBox1.Text = show;
            textBox1.Height = 100;
        }
    }

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值