| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 828 人关注过本帖
标题:[求助]C#窗体出错问题
只看楼主 加入收藏
就是你
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2006-6-29
收藏
 问题点数:0 回复次数:1 
[求助]C#窗体出错问题

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 系统
{
/// <summary>
/// WareDataManage 的摘要说明。
/// </summary>
public class WareDataManage : System.Windows.Forms.Form
{
private bool blSellTableShow;
private DataSet ds = new DataSet();
private LinkDataBase link = new LinkDataBase();
private string sendTableName = "商品清单";
private string sendStrSQL = "SELECT 货号, 条码, 拼音编码, 品名, 单位, 进货价, 销售价1, 销售价2, 规格, 产地, 类别, 最低售价 FROM 商品清单";

private System.Windows.Forms.DataGrid dgrd_WareData;
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.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txt_WareWord;
private System.Windows.Forms.Button btn_Search;
private System.ComponentModel.IContainer components;

public WareDataManage()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

//--------重载构造函数-----------
public WareDataManage(bool blShowToolBar)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
this.ds = link.SelectDataBase(sendStrSQL,sendTableName);//创建数据库连接
//如果blToolBarShow为false,则表示该窗体由销售单和进货单生成,用于双击选择商品
this.DataGridStateControl(blShowToolBar);
this.dgrd_WareData.DataSource = ds.Tables[0];
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(WareDataManage));
this.dgrd_WareData = new System.Windows.Forms.DataGrid();
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);
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();
((System.ComponentModel.ISupportInitialize)(this.dgrd_WareData)).BeginInit();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// dgrd_WareData
//
this.dgrd_WareData.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_WareData.CaptionVisible = false;
this.dgrd_WareData.DataMember = "";
this.dgrd_WareData.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dgrd_WareData.Location = new System.Drawing.Point(0, 74);
this.dgrd_WareData.Name = "dgrd_WareData";
this.dgrd_WareData.Size = new System.Drawing.Size(720, 376);
this.dgrd_WareData.TabIndex = 3;
this.dgrd_WareData.DoubleClick += new System.EventHandler(this.dgrd_WareData_DoubleClick);
//
// 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 = 4;
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;
//
// 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, 22);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(718, 50);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
//
// label1
//
this.label1.Location = new System.Drawing.Point(179, 22);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 16);
this.label1.TabIndex = 5;
this.label1.Text = "商品拼音:";
//
// txt_WareWord
//
this.txt_WareWord.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txt_WareWord.Location = new System.Drawing.Point(267, 18);
this.txt_WareWord.Name = "txt_WareWord";
this.txt_WareWord.Size = new System.Drawing.Size(200, 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(491, 17);
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);
//
// WareDataManage
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(720, 445);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.dgrd_WareData);
this.Name = "WareDataManage";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "【商品信息维护】";
((System.ComponentModel.ISupportInitialize)(this.dgrd_WareData)).EndInit();
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

//-----------设置表格格式----------
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++)//根据DataTable中的数据类型设置表格的样式
{
if (blReadOnly == true)
{
if ( i == 4 )//先为【单位】字段添加下拉列表框
{
DataTable tempTable = new DataTable();
tempTable.Columns.Add();
object[] rowValues = new object[] {"包","瓶","盒","带","箱"};
for (int j=0;j<5;j++)
{
tempTable.Rows.Add(tempTable.NewRow());
tempTable.Rows[j][0] = rowValues[j];
}
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_WareData.TableStyles.Add(ts);
}

//--------根据商品拼音编码查询商品-------------
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_WareData.CurrentCell.RowNumber;
//将当前所在行往下移动一行,为便于实现同步保存
//(否则会出现修改的最后一行无法保存,因为它还处于编辑状态)
this.dgrd_WareData.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_WareData.CurrentCell.RowNumber;
try
{
this.ds.Tables[0].Rows[intRowNumber].Delete();
//此处传入只包含被改动过的DataRow的DataSet,减少更新数据量,提高程序性能
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 dgrd_WareData_DoubleClick(object sender, System.EventArgs e)
{
if (this.dgrd_WareData.ReadOnly == true) //判断如果是在销售单或者进货单中生成的窗体则响应DataGrid的双击事件
{
int intCurrentRowNumber = this.dgrd_WareData.CurrentCell.RowNumber;
string sendWareID,sendWareName,sendWareUnit;
sendWareID = this.dgrd_WareData[intCurrentRowNumber,0].ToString().Trim();//保存商品编号
sendWareName = this.dgrd_WareData[intCurrentRowNumber,3].ToString().Trim();//保存商品名
sendWareUnit = this.dgrd_WareData[intCurrentRowNumber,4].ToString().Trim();//保存商品单位
string [] sendArray = new string [] {sendWareID,sendWareName,sendWareUnit};
if (blSellTableShow == true) //判断当前是哪个表为当前表(销售单还是售货单)
{
SellTable.inputDataGridArray[0] = sendArray[0];
SellTable.inputDataGridArray[1] = sendArray[1];
SellTable.inputDataGridArray[2] = sendArray[2];

}
else
{
StockTable.inputDataGridArray[0] = sendArray[0];
StockTable.inputDataGridArray[1] = sendArray[1];
StockTable.inputDataGridArray[2] = sendArray[2];
}
this.Close();
}
}

//---------如果是在双击选择商品状态,则表格为只读-------------
public void setDataGridReadOnly(bool blInSell)
{
this.dgrd_WareData.ReadOnly = true;
if (blInSell == true)
blSellTableShow = true;
else
blSellTableShow = false;
}

}
}
系统\WareDataManage.cs(329): 找不到类型或命名空间名称“SellTable”(是否缺少 using 指令或程序集引用?)
显示有9处类似的错误 谁能帮忙改正啊 谢谢

搜索更多相关主题的帖子: using System 窗体 summary private 
2007-05-05 11:22
June2Ling
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2007-4-9
收藏
得分:0 
SellTable未定义吧,不可以使用。从哪来的?

六月JVL风铃
2007-05-05 13:30
快速回复:[求助]C#窗体出错问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050248 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved