📄 stokerdatamanage.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 进销存管理系统
{
/// <summary>
/// StokerDataManage 的摘要说明。
/// </summary>
public class StokerDataManage : System.Windows.Forms.Form
{
private DataSet ds = new DataSet();
private LinkDataBase link = new LinkDataBase();
private string sendTableName = "供货商清单";
private string sendStrSQL = "SELECT 供货商号, 拼音编码, 名称, 业务员, 电话, 地址, 邮编, 区号, 地区, 类型, 传真, 电报, 开户行, 开户行邮编, 银行帐号, 税号, 库房地址, 库房电话, 业务部门 FROM 供货商清单";
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txt_WareWord;
private System.Windows.Forms.Button btn_Search;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton tbarBtnSave;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolBarButton tbarBtnDelete;
private System.Windows.Forms.DataGrid dgrd_StockerData;
private System.ComponentModel.IContainer components;
public StokerDataManage()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
//---------------重载构造函数-------------
public StokerDataManage(bool blShowToolBar)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
this.ds = this.link.SelectDataBase(sendStrSQL,sendTableName);
this.dgrd_StockerData.DataSource = ds;
this.dgrd_StockerData.DataMember = sendTableName;
//如果blToolBarShow为false,则表示该窗体使由销售单和进货单双击时生成
this.DataGridStateControl(blShowToolBar);
this.toolBar1.Enabled = blShowToolBar;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(StokerDataManage));
this.dgrd_StockerData = new System.Windows.Forms.DataGrid();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.txt_WareWord = new System.Windows.Forms.TextBox();
this.btn_Search = new System.Windows.Forms.Button();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.tbarBtnSave = new System.Windows.Forms.ToolBarButton();
this.tbarBtnDelete = new System.Windows.Forms.ToolBarButton();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
((System.ComponentModel.ISupportInitialize)(this.dgrd_StockerData)).BeginInit();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// dgrd_StockerData
//
this.dgrd_StockerData.AllowSorting = false;
this.dgrd_StockerData.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgrd_StockerData.CaptionVisible = false;
this.dgrd_StockerData.DataMember = "";
this.dgrd_StockerData.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dgrd_StockerData.Location = new System.Drawing.Point(0, 75);
this.dgrd_StockerData.Name = "dgrd_StockerData";
this.dgrd_StockerData.Size = new System.Drawing.Size(720, 349);
this.dgrd_StockerData.TabIndex = 3;
this.dgrd_StockerData.DoubleClick += new System.EventHandler(this.dgrd_StockerData_DoubleClick);
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.txt_WareWord);
this.groupBox1.Controls.Add(this.btn_Search);
this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.groupBox1.Location = new System.Drawing.Point(1, 23);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(718, 50);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
//
// label1
//
this.label1.Location = new System.Drawing.Point(154, 18);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 9;
this.label1.Text = "供货商拼音:";
//
// txt_WareWord
//
this.txt_WareWord.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.txt_WareWord.Location = new System.Drawing.Point(245, 14);
this.txt_WareWord.Name = "txt_WareWord";
this.txt_WareWord.Size = new System.Drawing.Size(248, 21);
this.txt_WareWord.TabIndex = 1;
this.txt_WareWord.Text = "";
//
// btn_Search
//
this.btn_Search.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_Search.Location = new System.Drawing.Point(517, 13);
this.btn_Search.Name = "btn_Search";
this.btn_Search.Size = new System.Drawing.Size(48, 24);
this.btn_Search.TabIndex = 2;
this.btn_Search.Text = "查询";
this.btn_Search.Click += new System.EventHandler(this.btn_Search_Click);
//
// toolBar1
//
this.toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.tbarBtnSave,
this.tbarBtnDelete});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(720, 29);
this.toolBar1.TabIndex = 9;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// tbarBtnSave
//
this.tbarBtnSave.ImageIndex = 0;
this.tbarBtnSave.ToolTipText = "保存修改";
//
// tbarBtnDelete
//
this.tbarBtnDelete.ImageIndex = 1;
this.tbarBtnDelete.ToolTipText = "删除数据";
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// StokerDataManage
//
this.AcceptButton = this.btn_Search;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(720, 421);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.dgrd_StockerData);
this.Name = "StokerDataManage";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "【供货商信息维护】";
((System.ComponentModel.ISupportInitialize)(this.dgrd_StockerData)).EndInit();
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//-----------根据输入的供货商拼音搜索供货商信息----------
private void btn_Search_Click(object sender, System.EventArgs e)
{
string strSpellWord = this.txt_WareWord.Text.Trim();
string tempStrSQL = "select * from 供货商清单 where 拼音编码 like '" + strSpellWord + "%'";
this.link.SelectDataBase(tempStrSQL,sendTableName);
}
//-----------向服务器提交修改--------------
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if (e.Button.ToolTipText == "保存修改")
{
try
{
int row = this.dgrd_StockerData.CurrentCell.RowNumber;
//将当前所在行往下移动一行,为便于实现同步保存
//(否则会出现修改的最后一行无法保存,因为它还处于编辑状态)
this.dgrd_StockerData.CurrentCell = new DataGridCell(row+1,0);
if (this.ds.HasChanges())
{
this.link.UpdateDataBase(this.ds.GetChanges(),sendTableName);
MessageBox.Show("数据修改成功!","信息");
}
else
{
MessageBox.Show("没有修改的数据!");
return;
}
}
catch
{
MessageBox.Show("数据保存失败,请确认所有信息输入完整且正确!","提示");
return;
}
}
if (e.Button.ToolTipText == "删除数据")
{
if (MessageBox.Show("确实要删除这条记录吗?","询问",MessageBoxButtons.YesNo) == DialogResult.Yes)
{
int intRowNumber = this.dgrd_StockerData.CurrentCell.RowNumber;
try
{
this.ds.Tables[0].Rows[intRowNumber].Delete();
this.link.UpdateDataBase(this.ds.GetChanges(),sendTableName);
MessageBox.Show("数据删除成功!","信息");
}
catch
{
MessageBox.Show("该数据不能删除!","提示");
string tempStrSQL = "select * from " + sendTableName;
this.link.SelectDataBase(tempStrSQL,sendTableName);
return;
}
}
}
}
//------------设置表格格式-----------
private void DataGridStateControl(bool blReadOnly)
{
DataGridTableStyle ts = new DataGridTableStyle();
ts.AlternatingBackColor = Color.LightGray;
ts.MappingName = this.ds.Tables[0].TableName;
ts.AllowSorting = false;
int numCols = this.ds.Tables[0].Columns.Count;
for (int i = 0;i< numCols;i++)
{
if (blReadOnly == true)
{
if ( i == 3)//设置【业务员】字段下拉列表框显示
{
DataTable tempTable = new DataTable();
tempTable = this.link.SelectDataBase("select 姓名 from 业务员清单");
DataGridComboBoxColumn aComboBoxColumn = new DataGridComboBoxColumn(tempTable,0,0);
aComboBoxColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
aComboBoxColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
aComboBoxColumn.NullText = "";
ts.GridColumnStyles.Add(aComboBoxColumn);
}
else
{
DataGridTextBoxColumn aColumnTextColumn = new DataGridTextBoxColumn();
aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
aColumnTextColumn.NullText = "";
aColumnTextColumn.Format = "F";
ts.GridColumnStyles.Add(aColumnTextColumn);
}
}
else
{
DataGridNoActiveCellColumn aColumnTextColumn = new DataGridNoActiveCellColumn();
aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
aColumnTextColumn.NullText = "";
aColumnTextColumn.Format = "F";
ts.GridColumnStyles.Add(aColumnTextColumn);
}
}
this.dgrd_StockerData.TableStyles.Add(ts);
}
//----------其他窗体调用,双击选择供货商信息并回送到调用的窗体-------------
private void dgrd_StockerData_DoubleClick(object sender, System.EventArgs e)
{
if (this.dgrd_StockerData.ReadOnly == true) //判断如果是在进货单中生成的窗体则不响应DataGrid的双击事件
{
int intCurrentRowNumber = this.dgrd_StockerData.CurrentCell.RowNumber;
string sendStokerID,sendStokerName;
sendStokerID = this.dgrd_StockerData[intCurrentRowNumber,0].ToString().Trim();
sendStokerName = this.dgrd_StockerData[intCurrentRowNumber,2].ToString().Trim();
string [] sendArray = new string [] {sendStokerID,sendStokerName};
StockTable.inputTextDataArray[0] = sendArray[0];
StockTable.inputTextDataArray[1] = sendArray[1];
this.Close();
}
}
public void setDataGridReadOnly()
{
this.dgrd_StockerData.ReadOnly = true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -