编辑
2025-09-29
C#
00

目录

摘要
正文

摘要

ADO.NET 是一组向 .NET Framework 程序员公开数据访问服务的类。 ADO.NET 为创建分布式数据共享应用程序提供了一组丰富的组件。 它提供了对关系数据、XML 和应用程序数据的访问,因此是 .NET Framework 中不可缺少的一部分。 ADO.NET 支持多种开发需求,包括创建由应用程序、工具、语言或 Internet 浏览器使用的前端数据库客户端和中间层业务对象。

ADO.net之间就有ADO,这个是一个COM组件,在VB6时代用的特别多,再就是现在还在用的vbs, 也在用这个。Connectiong、 Command、 Recordset和 Field

正文

基本结构

image.png

image.png

DataSet

image.png

Connection连接对象

Connection对象也称为数据库连接对象,Connection对象的功能是负责对数据源的连接。 所有Connection对象的基类都是DbConnection类。 

基本语法:数据源(Data Source)+数据库名称(Initial Catalog)+用户名(User ID)+密码(Password)

SQL Server连接字符串

Data Source=.;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

或者

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;Trusted_Connection=False;

可信连接: Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;或者 Server=myServerAddress;Database=myDatabase;Trusted_Connection=True; 

其它连接

Access连接字符串

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myDatabase.mdb;User Id=admin;Password=;

MySQL连接字符串

Server=myServerAddress;Database=myDatabase;Uid=myUsername;Pwd=myPassword;

Oracle连接字符串

Data Source=TORCL;User Id=myUsername;Password=myPassword; 

连接数据库

Connection对象有两个重要属性: 

ConnectionString:表示用于打开 SQL Server 数据库的字符串; 

State:表示 Connection 的状态,有Closed和Open两种状态。

Connection对象有两个重要方法:

Open()方法:指示打开数据库;

Close()方法:指示关闭数据库。

image.png

image.png

DataSet

image.png

Connection连接对象

Connection对象也称为数据库连接对象,Connection对象的功能是负责对数据源的连接。 所有Connection对象的基类都是DbConnection类。 

基本语法:数据源(Data Source)+数据库名称(Initial Catalog)+用户名(User ID)+密码(Password)

SQL Server连接字符串

Data Source=.;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

或者

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;Trusted_Connection=False;

可信连接: Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;或者 Server=myServerAddress;Database=myDatabase;Trusted_Connection=True; 

其它连接

Access连接字符串

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myDatabase.mdb;User Id=admin;Password=;

MySQL连接字符串

Server=myServerAddress;Database=myDatabase;Uid=myUsername;Pwd=myPassword;

Oracle连接字符串

Data Source=TORCL;User Id=myUsername;Password=myPassword; 

连接数据库

Connection对象有两个重要属性: 

ConnectionString:表示用于打开 SQL Server 数据库的字符串; 

State:表示 Connection 的状态,有Closed和Open两种状态。

Connection对象有两个重要方法:

Open()方法:指示打开数据库;

Close()方法:指示关闭数据库。

开发一个Helper类

打开一个connection

运行脚本

关闭connection

C#
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace zado { public class SqlHelper { //数据库连接 private SqlConnection conn = new SqlConnection(); //连接字符串 private string strConn { get; set; } /// <summary> /// 单例模试 /// </summary> private static SqlHelper instance; public static SqlHelper GetInstance() { if (instance == null) { instance = new SqlHelper(); } return instance; } /// <summary> /// 构造 /// </summary> public SqlHelper() { this.strConn = System.Configuration.ConfigurationManager.AppSettings["DataConnString"].ToString(); this.conn.ConnectionString = strConn; } /// <summary> /// 构造-传入数据库连接 /// </summary> /// <param name="ConfigKey"></param> public SqlHelper(string ConfigKey) { this.strConn = ConfigKey; this.conn.ConnectionString = strConn; } /// <summary> /// 打开数据库连接 /// </summary> private void Open() { if (conn.State == ConnectionState.Closed) { try { conn.Open(); } catch (Exception ex) { //输出日志 } } } /// <summary> /// 关闭数据库连接 /// </summary> private void Close() { try { conn.Close(); } catch (Exception ex) { //输出日志 } } /// <summary> /// 执行SQL脚本无返回 /// </summary> /// <param name="sql"></param> /// <returns></returns> public string ExecuteSqlNonQuery(string sql) { string ret = ""; try { SqlCommand sqlcom = new SqlCommand(); this.Open(); sqlcom.Connection = conn; sqlcom.CommandText = sql; sqlcom.CommandType = CommandType.Text; sqlcom.CommandTimeout = 600; sqlcom.ExecuteNonQuery(); } catch (Exception ex) { //输出日志 ret = "Error"; } finally { this.Close(); } return ret; } /// <summary> /// 返回单一值 /// </summary> /// <param name="sql"></param> /// <returns></returns> public dynamic ExecuteSqlScalar(string sql) { using (conn) { try { this.Open(); SqlCommand sqlcom = new SqlCommand(); sqlcom.CommandText = sql; sqlcom.Connection = conn; sqlcom.CommandTimeout = 600; return sqlcom.ExecuteScalar(); } catch (Exception ex) { //输出日志 } } return ""; } /// <summary> /// 填充一个DataSet /// </summary> /// <param name="sql"></param> /// <returns></returns> public DataSet ExecuteSqlDataSet(string sql) { DataSet ds = null; try { SqlCommand sqlcom = new SqlCommand(); this.Open(); sqlcom.Connection = conn; sqlcom.CommandText = sql; sqlcom.CommandTimeout = 600; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = sqlcom; ds = new DataSet(); da.Fill(ds); } catch (Exception ex) { ds = null; } finally { this.Close(); } return ds; } /// <summary> /// 填充一个DataSet /// </summary> /// <param name="sql"></param> /// <param name="tableName"></param> /// <returns></returns> public DataSet ExecuteSqlDataSet(string sql, string tableName) { DataSet ds = null; try { SqlCommand sqlcom = new SqlCommand(); this.Open(); sqlcom.Connection = conn; sqlcom.CommandText = sql; sqlcom.CommandTimeout = 600; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = sqlcom; da.Fill(ds, tableName); } catch (Exception ex) { ds = null; } finally { this.Close(); } return ds; } /// <summary> /// 执行存储过程无返回 /// </summary> /// <param name="lst"></param> /// <param name="spName"></param> /// <returns></returns> public string ExecuteSpNoQuery(List<object> lst, string spName) { string ret = ""; try { this.Open(); SqlCommand sqlcom = new SqlCommand(); sqlcom.CommandType = CommandType.StoredProcedure; sqlcom.CommandText = spName; sqlcom.Connection = conn; SqlCommandBuilder.DeriveParameters(sqlcom); for (int i = 0; i < lst.Count; i++) { sqlcom.Parameters[i + 1].Value = lst[i] == null ? DBNull.Value : lst[i]; } sqlcom.ExecuteNonQuery(); } catch (Exception ex) { ret = "Error"; //输出日志 } finally { this.Close(); } return ret; } /// <summary> /// 执行存储过程返回单一值 /// </summary> /// <param name="lst"></param> /// <param name="spName"></param> /// <returns></returns> public string ExcuteSpExecuteScalar(List<object> lst, string spName) { string ret = ""; try { this.Open(); SqlCommand sqlcom = new SqlCommand(); sqlcom.CommandText = spName; sqlcom.CommandType = CommandType.StoredProcedure; sqlcom.Connection = conn; sqlcom.CommandTimeout = 600; SqlCommandBuilder.DeriveParameters(sqlcom); for (int i = 0; i < lst.Count; i++) { sqlcom.Parameters[i + 1].Value = lst[i] == null ? DBNull.Value : lst[i]; } ret = sqlcom.ExecuteScalar().ToString(); } catch (Exception ex) { ret = ""; //输出日志 } finally { this.Close(); } return ret; } /// <summary> /// 执行存储过程返回DataSet /// </summary> /// <param name="lst"></param> /// <param name="spName"></param> /// <returns></returns> public DataSet ExcuteSpDataSet(List<object> lst, string spName) { DataSet ds = null; try { this.Open(); SqlCommand sqlcom = new SqlCommand(); sqlcom.Connection = conn; sqlcom.CommandText = spName; sqlcom.CommandType = CommandType.StoredProcedure; sqlcom.CommandTimeout = 600; SqlCommandBuilder.DeriveParameters(sqlcom); for (int i = 0; i < lst.Count; i++) { sqlcom.Parameters[i + 1].Value = lst[i] == null ? DBNull.Value : lst[i]; } SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = sqlcom; ds = new DataSet(); da.Fill(ds); } catch (Exception ex) { ds = null; //输出日志 } finally { this.Close(); } return ds; } /// <summary> /// 返回DataTable与返回总计录,用于分页 /// </summary> /// <param name="lst"></param> /// <param name="spName"></param> /// <param name="ReturnName"></param> /// <param name="ReturnValue"></param> /// <returns></returns> public DataTable ExcuteSpPagingDataSet(List<object> lst, string spName, string ReturnName, ref object ReturnValue) { DataTable dt = null; try { dt = new DataTable(); this.Open(); SqlCommand sqlcom = new SqlCommand(spName, conn); sqlcom.CommandTimeout = 600; sqlcom.CommandType = CommandType.StoredProcedure; //初使化参数PARAMETER_NAME SqlCommandBuilder.DeriveParameters(sqlcom); for (int i = 0; i < lst.Count; i++) { sqlcom.Parameters[i + 1].Value = lst[i] == null ? DBNull.Value : lst[i]; } DataSet ds = new DataSet(); SqlDataAdapter daMain = new SqlDataAdapter(); daMain.SelectCommand = sqlcom; //返回一个DataTable //sqlcom.ExecuteNonQuery(); daMain.Fill(ds); dt = ds.Tables[0]; ReturnValue = sqlcom.Parameters["@" + ReturnName].Value.ToString(); } catch (Exception ex) { dt = null; } finally { this.Close(); } return dt; } /// <summary> /// 执行多条SQL语句-事务 /// </summary> /// <param name="sqls"></param> /// <returns></returns> public bool ExcuteTransaction(string[] sqls) { try { this.Open(); using (SqlTransaction transaction = conn.BeginTransaction()) { using (SqlCommand command = conn.CreateCommand()) { command.Transaction = transaction; try { foreach (var item in sqls) { command.CommandText = item; command.ExecuteNonQuery(); } transaction.Commit(); return true; } catch { transaction.Rollback(); } } } } catch (Exception ex) { } return false; } } }

完整例子

image.png

image.png

App.config

XML
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="DataConnString" value="Server=localhost;Database=bzscada;Max Pool Size=50;Min Pool Size=5;Uid=sa;Pwd=123" /> </appSettings> </configuration>

Inventory类

  1. 分页查询
  2. 下拦菜单维护
  3. 保存
  4. 详细信息
SQL
Create PROCEDURE [dbo].[sp_getgridpages] ( @Tables nvarchar(1000), --表名 @ColName nvarchar(50), --排序字段 @Fields nvarchar(max) = '*', --显示字段名 @Pageindex int = 1, --当前页数  @PageSize int = 10, --页大小 @Filter nvarchar(1000) = '', --Where条件,不能为null @Sort nvarchar(200) = '', --排序字段, 不能为null, @TotalCount int output ) AS BEGIN -------------------------- Declare @sql nvarchar(4000); declare @TSQL nvarchar(4000); declare @SortName nvarchar(50); declare @SSQL nvarchar(4000); --取得列名称 --set @SSQL='select @a=Name from syscolumns where id=object_id(N'''+@Tables+''') and colorder='+convert(varchar(5),@SortIndex) --exec sp_executesql @SSQL,N'@a nvarchar(50) output',@ColName output -------------------------- If @Sort = '' begin Set @Sort = 'DESC' end If @Filter = '' begin Set @Filter = 'where 1=1' end else begin Set @Filter = 'where '+@Filter end set @Pageindex=@Pageindex-1 --拼SQL语句 begin set @sql = 'WITH [tempTable] AS (SELECT '+@Fields+''+ ', ROW_NUMBER() OVER (ORDER BY '+@ColName+' '+@Sort+') AS ''RowNumber'' '+ 'FROM '+@Tables+' '+@Filter+') SELECT '+@Fields+' FROM [tempTable] WHERE '+ 'RowNumber BETWEEN '+convert(varchar(20),@Pageindex*@PageSize+1)+' AND '+ convert(varchar(20),(@Pageindex*@PageSize+@PageSize)) end -------------------------- exec (@sql) print @sql --返回最大行数 set @TSQL='select @a=COUNT(*) from '+ @Tables + ' '+ @Filter exec sp_executesql @TSQL,N'@a int output',@TotalCount output END
C#
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace zado { public class Inventory { SqlHelper sqlHelper = new SqlHelper(); public Dictionary<string, object> Search(string value, int pageIndex = 1) { string table = "wms_inventory"; string colname = "ship_date"; string fields = "*"; int pageSize = 20; string filter = "(part_no like '%" + value + "%') or (box_no like '%" + value + "%')"; string sort = "desc"; object totalCount = 0; List<object> lst = new List<object>(); lst.Add(table); lst.Add(colname); lst.Add(fields); lst.Add(pageIndex); lst.Add(pageSize); lst.Add(filter); lst.Add(sort); lst.Add(totalCount); DataTable dt = sqlHelper.ExcuteSpPagingDataSet(lst, "sp_getgridpages", "totalCount", ref totalCount); Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("dt", dt); dic.Add("totalCount", totalCount); return dic; } public DataSet SiteCode() { string sql = "SELECT site_code FROM wms_basic_location group by site_code order by site_code"; DataSet ds = sqlHelper.ExecuteSqlDataSet(sql); return ds; } public DataSet LocationCode(string site_code) { string sql = "SELECT location_code FROM wms_basic_location where site_code='" + site_code + "' group by location_code order by location_code"; DataSet ds = sqlHelper.ExecuteSqlDataSet(sql); return ds; } public bool Save(string asn_no, string part_no , int qty, int problem_qty, string group_no, string box_no , string rack_no, string location_code, string site_code, string po, DateTime ship_date,string keyId,string operType) { string sql = ""; if (operType == "edit") { sql = "update wms_inventory set asn_no='{0}', part_no='{1}', qty={2}, problem_qty={3}" + ", group_no='{4}', box_no='{5}', rack_no='{6}', location_code='{7}', site_code='{8}', po='{9}', ship_date='{10}' where id='{11}'"; sql = string.Format(sql, asn_no, part_no, qty, problem_qty, group_no, box_no, rack_no, location_code, site_code, po, ship_date,keyId); } else { sql = "INSERT INTO wms_inventory(id, asn_no, part_no, qty, problem_qty, group_no, box_no, rack_no, location_code, site_code, po, ship_date)" + " VALUES ('{0}','{1}','{2}',{3},{4},'{5}','{6}','{7}','{8}','{9}','{10}','{11}')"; sql = string.Format(sql, keyId, asn_no, part_no, qty, problem_qty, group_no, box_no, rack_no, location_code, site_code, po, keyId); } string ret = sqlHelper.ExecuteSqlNonQuery(sql); return ret == ""; } public DataSet Detail(string keyId) { string sql = "SELECT id, asn_no, part_no, qty, problem_qty, group_no, box_no, rack_no, location_code" + ", site_code, po, is_qdr, is_scrap, is_outbound, qdr_date, outbound_date, ship_date, created_date FROM wms_inventory where id='" + keyId + "'"; DataSet ds = sqlHelper.ExecuteSqlDataSet(sql); return ds; } } }

主窗体代码

C#
using System.Data; namespace zado { public partial class FrmMain : Form { public ListViewItem currentRow { get; set; } int totalPage = 0; int curPage = 0; public FrmMain() { InitializeComponent(); init(); } private void btnSearch_Click(object sender, EventArgs e) { Search(txtSearchValue.Text); } public void Search(string value, int pageIndex = 1) { Inventory inventory = new Inventory(); Dictionary<string, object> ret = inventory.Search(value, pageIndex); totalPage = int.Parse(Math.Ceiling((int.Parse(ret["totalCount"].ToString()) / 20.0)).ToString()); stsMain_btnPage.Text = "找到" + ret["totalCount"].ToString() + "记录"; LoadView(ret); } public void LoadView(Dictionary<string, object> ret) { lsvMain.Items.Clear(); DataTable dt = (DataTable)ret["dt"]; for (int i = 0; i < dt.Rows.Count; i++) { ListViewItem item = new ListViewItem(); item.Text = dt.Rows[i]["asn_no"].ToString(); item.Tag = dt.Rows[i]["id"].ToString(); item.SubItems.Add(dt.Rows[i]["part_no"].ToString()); item.SubItems.Add(dt.Rows[i]["qty"].ToString()); item.SubItems.Add(dt.Rows[i]["problem_qty"].ToString()); item.SubItems.Add(dt.Rows[i]["group_no"].ToString()); item.SubItems.Add(dt.Rows[i]["box_no"].ToString()); item.SubItems.Add(dt.Rows[i]["rack_no"].ToString()); item.SubItems.Add(dt.Rows[i]["location_code"].ToString()); item.SubItems.Add(dt.Rows[i]["site_code"].ToString()); item.SubItems.Add(dt.Rows[i]["po"].ToString()); item.SubItems.Add(dt.Rows[i]["is_qdr"].ToString()); item.SubItems.Add(dt.Rows[i]["is_scrap"].ToString()); item.SubItems.Add(dt.Rows[i]["is_outbound"].ToString()); item.SubItems.Add(dt.Rows[i]["qdr_date"].ToString()); item.SubItems.Add(dt.Rows[i]["outbound_date"].ToString()); item.SubItems.Add(dt.Rows[i]["ship_date"].ToString()); lsvMain.Items.Add(item); } for (int i = 0; i < lsvMain.Columns.Count; i++) { lsvMain.Columns[i].Width = -2; } } private void init() { lsvMain.Columns.Add("预通知号"); lsvMain.Columns.Add("零件号"); lsvMain.Columns.Add("数量"); lsvMain.Columns.Add("问题数量"); lsvMain.Columns.Add("分组"); lsvMain.Columns.Add("箱号"); lsvMain.Columns.Add("货架"); lsvMain.Columns.Add("地点"); lsvMain.Columns.Add("成本中心"); lsvMain.Columns.Add("订单号"); lsvMain.Columns.Add("是否质检"); lsvMain.Columns.Add("是否报废"); lsvMain.Columns.Add("是否出库"); lsvMain.Columns.Add("质检日期"); lsvMain.Columns.Add("出库日期"); lsvMain.Columns.Add("到货日期"); lsvMain.Columns.Add("创建日期"); } private void cmnuPage_First_Click(object sender, EventArgs e) { curPage = 1; Search(txtSearchValue.Text, 1); } private void cmnuPage_Last_Click(object sender, EventArgs e) { curPage = totalPage; Search(txtSearchValue.Text, curPage); } private void cmnuPage_Pre_Click(object sender, EventArgs e) { if (curPage <= 2) { curPage = 1; } else { curPage--; } Search(txtSearchValue.Text, curPage); } private void cmnuPage_Next_Click(object sender, EventArgs e) { if (curPage > totalPage) { curPage = totalPage; } else { curPage++; } Search(txtSearchValue.Text, curPage); } private void btnAdd_Click(object sender, EventArgs e) { FrmEdit frmEdit = new FrmEdit(); frmEdit.operType = "add"; frmEdit.Show(); } private void lsvMain_DoubleClick(object sender, EventArgs e) { string keyId = ""; if (lsvMain.SelectedItems[0].Tag == null) { return; } keyId = lsvMain.SelectedItems[0].Tag.ToString(); FrmEdit frmEdit = new FrmEdit(); frmEdit.keyId = keyId; frmEdit.operType = "detail"; frmEdit.currentRow = lsvMain.SelectedItems[0]; frmEdit.ShowDialog(this); //if (frmEdit.ShowDialog(this) == DialogResult.OK) //{ // if (currentRow != null) // { // lsvMain.SelectedItems[0].Text = currentRow.Text; // lsvMain.SelectedItems[0].SubItems[1].Text = currentRow.SubItems[1].Text; // } //} } } }

这里需要思考一下父对子的传值,子对父的回传。

C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace zado { public partial class FrmEdit : Form { public ListViewItem currentRow { get; set; } public string keyId { get; set; } public string operType { get; set; } Inventory inventory = new Inventory(); public FrmEdit() { InitializeComponent(); } private void init() { txtcreated_date.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); DataSet ds = inventory.SiteCode(); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { cbosite_code.Items.Add(ds.Tables[0].Rows[i]["site_code"].ToString()); } } } private void btnSave_Click(object sender, EventArgs e) { keyId = keyId == null ? Guid.NewGuid().ToString() : keyId; bool ret = inventory.Save(txtasn_no.Text, txtpart_no.Text, int.Parse(txtqty.Text), int.Parse(txtproblem_qty.Text) , txtgroup_no.Text, txtbox_no.Text, txtrack_no.Text, cbolocation_code.Text, cbosite_code.Text, txtpo.Text, dtpship_date.Value, keyId, operType); if (ret) { MessageBox.Show("保存成功!"); this.DialogResult = DialogResult.OK; currentRow.Text = txtasn_no.Text; currentRow.Tag = keyId; currentRow.SubItems[1].Text = txtpart_no.Text; currentRow.SubItems[2].Text = txtqty.Text; currentRow.SubItems[3].Text = txtproblem_qty.Text; currentRow.SubItems[4].Text = txtgroup_no.Text; currentRow.SubItems[5].Text = txtbox_no.Text; currentRow.SubItems[6].Text = txtrack_no.Text; currentRow.SubItems[7].Text = cbolocation_code.Text; currentRow.SubItems[8].Text = cbosite_code.Text; currentRow.SubItems[9].Text = txtpo.Text; currentRow.SubItems[15].Text = dtpship_date.Text; this.Close(); } else { MessageBox.Show("保存出错!"); } } private void Detail() { DataSet ds = inventory.Detail(keyId); if (ds != null && ds.Tables[0].Rows.Count > 0) { txtasn_no.Text = ds.Tables[0].Rows[0]["asn_no"].ToString(); txtpart_no.Text = ds.Tables[0].Rows[0]["part_no"].ToString(); txtqty.Text = ds.Tables[0].Rows[0]["qty"].ToString(); txtproblem_qty.Text = ds.Tables[0].Rows[0]["problem_qty"].ToString(); txtgroup_no.Text = ds.Tables[0].Rows[0]["group_no"].ToString(); txtbox_no.Text = ds.Tables[0].Rows[0]["box_no"].ToString(); txtrack_no.Text = ds.Tables[0].Rows[0]["rack_no"].ToString(); cbosite_code.Text = ds.Tables[0].Rows[0]["site_code"].ToString(); cbolocation_code.Text = ds.Tables[0].Rows[0]["location_code"].ToString(); txtpo.Text = ds.Tables[0].Rows[0]["po"].ToString(); dtpship_date.Text = ds.Tables[0].Rows[0]["ship_date"].ToString(); txtcreated_date.Text = ds.Tables[0].Rows[0]["created_date"].ToString(); } } private void cbosite_code_SelectedIndexChanged(object sender, EventArgs e) { cbolocation_code.Items.Clear(); DataSet ds = inventory.LocationCode(cbosite_code.Text); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { cbolocation_code.Items.Add(ds.Tables[0].Rows[i]["location_code"].ToString()); } } } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } private void FrmEdit_Load(object sender, EventArgs e) { init(); if (operType == "detail" && keyId != null) { ControlEnabled(false); Detail(); } if (operType == "add") { btnEdit.Visible = false; } } private void ControlEnabled(bool ret) { txtasn_no.Enabled = ret; txtpart_no.Enabled = ret; txtqty.Enabled = ret; txtproblem_qty.Enabled = ret; txtgroup_no.Enabled = ret; txtrack_no.Enabled = ret; txtbox_no.Enabled = ret; cbosite_code.Enabled = ret; cbolocation_code.Enabled = ret; txtpo.Enabled = ret; dtpship_date.Enabled = ret; txtcreated_date.Enabled = false; btnSave.Visible = ret; btnEdit.Visible = !ret; } private void btnEdit_Click(object sender, EventArgs e) { operType = "edit"; ControlEnabled(true); } } }

将质检功能完成,可以多选一并质检,需要维护is_qdr,qdr_date,两个字段

将出库功能完成,可以多选一并出度,需要维护is_outbound,outbound_date,两个字段,出库时需要判断只有is_qdr为真的才能出库。

本文作者:技术老小子

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!