/// <summary> /// 批量导入监管码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnInsertReg_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "excel files|*.xls"; DialogResult dr = openFileDialog.ShowDialog(); if (dr == DialogResult.OK) { //获取execl表的数据 DataSet ds = ExcelToDataSet(openFileDialog.FileName); if (ds == null) { return; } Service.Regulatory data; string errMsg = string.Empty; //存储错误信息 string info = string.Empty; //循环监管添加 foreach (DataRow row in ds.Tables[0].Rows) { data = new Regulatory.Service.Regulatory(); if (row[0].ToString().Length != 32) { continue; } data.RegCode = row[0].ToString(); data.AccID = accID; //判断是否存在 bool flag = service.ExistsRegulatory(connectionString, data); if (flag)//说明已存在 跳过 { info += string.Format("监管码:{0}已存在!\r\n", row[0].ToString()); continue; } //添加监管码 flag = service.AddRegulatory(connectionString, data, out errMsg); if (!flag) { info += string.Format("监管码:{0}添加失败!\r\n", row[0].ToString()); break; } } if (!string.IsNullOrEmpty(info)) { MessageBox.Show("添加完成,详细信息如下:\r\n" + info); } btnSearch_Click(null, null); } }