📄 datain.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using Jinrm.Data;
using GzglClient.Froms;
namespace GzglClient.Views
{
/// <summary>
/// DataIn 的摘要说明。
/// </summary>
public class DataIn : System.Windows.Forms.UserControl , IView
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox FileName;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button btnOpenFileJG;
private System.Windows.Forms.Button btnOpenFileSY;
private System.Windows.Forms.OpenFileDialog openFileJG;
private System.Windows.Forms.OpenFileDialog openFileSY;
private System.Windows.Forms.ColumnHeader columnHeader7;
private System.Windows.Forms.ColumnHeader columnHeader8;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ListView ResultItemList;
private System.Windows.Forms.ProgressBar PB;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public DataIn()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
// TODO: 在 InitializeComponent 调用后添加任何初始化
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.FileName = new System.Windows.Forms.TextBox();
this.btnOpenFileJG = new System.Windows.Forms.Button();
this.PB = new System.Windows.Forms.ProgressBar();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.btnOpenFileSY = new System.Windows.Forms.Button();
this.openFileJG = new System.Windows.Forms.OpenFileDialog();
this.openFileSY = new System.Windows.Forms.OpenFileDialog();
this.ResultItemList = new System.Windows.Forms.ListView();
this.columnHeader7 = new System.Windows.Forms.ColumnHeader();
this.columnHeader8 = new System.Windows.Forms.ColumnHeader();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.FileName);
this.groupBox1.Controls.Add(this.btnOpenFileJG);
this.groupBox1.Controls.Add(this.btnOpenFileSY);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(16, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(648, 88);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "标准表数据效验--机关";
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 31);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 16);
this.label1.TabIndex = 2;
this.label1.Text = "机关";
//
// FileName
//
this.FileName.Enabled = false;
this.FileName.Location = new System.Drawing.Point(88, 24);
this.FileName.Name = "FileName";
this.FileName.Size = new System.Drawing.Size(296, 21);
this.FileName.TabIndex = 1;
this.FileName.Text = "";
//
// btnOpenFileJG
//
this.btnOpenFileJG.Location = new System.Drawing.Point(392, 24);
this.btnOpenFileJG.Name = "btnOpenFileJG";
this.btnOpenFileJG.TabIndex = 0;
this.btnOpenFileJG.Text = "选择文件";
this.btnOpenFileJG.Click += new System.EventHandler(this.btnOpenFileJG_Click);
//
// PB
//
this.PB.Location = new System.Drawing.Point(16, 120);
this.PB.Name = "PB";
this.PB.Size = new System.Drawing.Size(800, 23);
this.PB.TabIndex = 4;
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 61);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 16);
this.label2.TabIndex = 2;
this.label2.Text = "事业";
//
// textBox1
//
this.textBox1.Enabled = false;
this.textBox1.Location = new System.Drawing.Point(88, 56);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(296, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// btnOpenFileSY
//
this.btnOpenFileSY.Location = new System.Drawing.Point(392, 56);
this.btnOpenFileSY.Name = "btnOpenFileSY";
this.btnOpenFileSY.TabIndex = 0;
this.btnOpenFileSY.Text = "选择文件";
this.btnOpenFileSY.Click += new System.EventHandler(this.btnOpenFileSY_Click);
//
// openFileJG
//
this.openFileJG.Filter = "Excel文件(*.xls)|*.xls";
//
// openFileSY
//
this.openFileSY.Filter = "Excel文件(*.xls)|*.xls";
//
// ResultItemList
//
this.ResultItemList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader7,
this.columnHeader8,
this.columnHeader1});
this.ResultItemList.Dock = System.Windows.Forms.DockStyle.Bottom;
this.ResultItemList.FullRowSelect = true;
this.ResultItemList.GridLines = true;
this.ResultItemList.HideSelection = false;
this.ResultItemList.Location = new System.Drawing.Point(0, 160);
this.ResultItemList.Name = "ResultItemList";
this.ResultItemList.Size = new System.Drawing.Size(900, 440);
this.ResultItemList.TabIndex = 13;
this.ResultItemList.View = System.Windows.Forms.View.Details;
//
// columnHeader7
//
this.columnHeader7.Text = "行";
this.columnHeader7.Width = 50;
//
// columnHeader8
//
this.columnHeader8.Text = "字段名";
this.columnHeader8.Width = 150;
//
// columnHeader1
//
this.columnHeader1.Text = "错误类型";
this.columnHeader1.Width = 400;
//
// DataIn
//
this.AutoScroll = true;
this.Controls.Add(this.ResultItemList);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.PB);
this.Name = "DataIn";
this.Size = new System.Drawing.Size(900, 600);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void btnOpenFileJG_Click(object sender, System.EventArgs e)
{
if (openFileJG.ShowDialog() == DialogResult.OK)
{
ResultItemList.Items.Clear();
FileName.Text = openFileJG.FileName;
string strConn = "provider=microsoft.jet.oledb.4.0;data source=" + openFileJG.FileName + ";extended properties=excel 8.0;";
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$] where [姓名] <> '' ", strConn);
DataSet ds = new DataSet();
myCommand.Fill(ds);
PB.Minimum = 0;
PB.Maximum = ds.Tables[0].Rows.Count;
//MessageBox.Show(ds.Tables[0].Rows[1]["出生时间"].ToString());
//return;
#region 验证
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
if(ds.Tables[0].Rows[i]["姓名"].ToString() == "")
{
}
else
{
#region 姓名
if(ds.Tables[0].Rows[i]["姓名"].ToString() == "")
{
ListViewItem it = new ListViewItem((i+1).ToString());
it.SubItems.Add("姓名");
it.SubItems.Add("不能为空");
ResultItemList.Items.Add(it);
}
#endregion
#region 性别
if(ds.Tables[0].Rows[i]["性别"].ToString() != "男" && ds.Tables[0].Rows[i]["性别"].ToString() != "女")
{
ListViewItem it = new ListViewItem((i+1).ToString());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -