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