3.1首页workshop.aspx的制作
本页为车间管理系统的首页,提供到各个页面的链接,如下图3.1所示,
其中:
【车间参数设置】指向parameter.aspx
【物料管理】指向materiel.aspx
【生产任务管理】指向mission.aspx
【生产优先级设置】指向priority.aspx
【任务例外信息】指向except.aspx
图3.1车间管理首页
3.2 车间参数设置页面parameter.aspx的制作
3.2.1浏览功能
提供客户对参数的浏览功能是必要的,建立一个sqlDataAdapter,对参数设置文件parameter的所有记录进行查询,sql语句为 “SELECT workshopid, cargoid, outperday, setupid FROM parameter”.然后建立DataSet,将查找出的数据存入其中的DataTable中,并建立名为Client_data的会话(Session)来缓存数据,并用于各DataSet之间的数据交换中介.其关键源代码如下:
private void LoadData()
{
DataSet ds=new DataSet();
DataTable dt=new DataTable("parameter");
ds.Tables.Add(dt);
this.sqlDataAdapter1.Fill(ds);
Session["parameter"] = ds;
}
然后建立Web窗体DataGrid,用于在页面中显示查找出来的数据,如下图3.2所示.此DataGrid的数据源应绑定到DataSet上,关键代码如下:
private void UpdateView()
{
DataSet ds=(DataSet)Session["parameter"];//从Session中读出数据
DataGrid1.DataSource = ds.Tables["parameter"];
this.DataGrid1.DataBind();
}
图3.2车间参数设置页面
3.2.2编辑功能
为此DataGrid增加编辑、删除功能列,并将删除列转换为模板列,在页脚中添加“新建”链接按钮,指向本页面,用于实现新建客户资料记录功能。
为DataGrid配置grid_DeleteCommand,grid_UpdateCommand,DataGrid1_EditCommand,grid_CancelCommand,分别实现删除记录,更新记录,转到编辑模式,取消更新等功能。本系统中的编辑功能采用即地编辑模式。新建界面如下图3.3所示:
图3.3车间参数设置的编辑页面
删除操作的处理过程,只要点击【删除】按钮,就将调用grid_DeleteCommnad,删除所选择的行,更新数据库并刷新页面。
编辑操作的处理过程如下:点击【编辑】按钮,调用DataGrid1_EditCommand将选中行转换到编辑模式如图3.3,在编辑框中输入数据后点击【更新】,将调用grid_UpdateCommand,将输入数据更新到数据库,并刷新页面显示。若点击【取消】按钮,将调用grid_CancelCommand取消更新,回到原页面。
下面详细介绍grid_DeleteCommnad和grid_UpdateCommand,其原理都是使用SqlCommand对数据库进行操作。而SqlCommand的参数由DataGrid传递。源代码如下(注意DataGrid的DataKeyField应设置为CLIENT表的主键CLIENTID,以用于增删改查):
private void grid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
String strCmd = "DELETE FROM parameter WHERE setupid=@ID";
SqlCommand cmd = new SqlCommand(strCmd, this.sqlConnection1);
SqlParameter p1 = new SqlParameter("@ID", SqlDbType.Int);
p1.Direction = ParameterDirection.Input;
p1.Value = DataGrid1.DataKeys[e.Item.ItemIndex];
cmd.Parameters.Add(p1);
this.sqlConnection1.Open();
cmd.ExecuteNonQuery();
this.sqlConnection1.Close();
LoadData();
UpdateView();
}
grid_UpdateCommand的源代码如下:
private void grid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
TextBox txtworkshopid = (TextBox) e.Item.Cells[1].Controls[0];
TextBox txtcargoid = (TextBox) e.Item.Cells[2].Controls[0];
TextBox txtoutperday = (TextBox) e.Item.Cells[3].Controls[0];
// MUST decide whether to UPDATE or to INSERT. The decision is made based on
// the fact that the DataSet has added rows
DataSet ds = (DataSet) Session["parameter"];
DataTable dt = ds.Tables["parameter"];
DataRow drLast = dt.Rows[dt.Rows.Count-1];
if (drLast.RowState == DataRowState.Added)
{
// Drop the newly added row from memory
//drLast.RejectChanges();
String strCmd = "INSERT parameter ( workshopid,cargoid,outperday ) VALUES( @workshopid,@cargoid,@outperday )";
SqlCommand cmd = new SqlCommand(strCmd, this.sqlConnection1);
//ID is an identity column
SqlParameter p1 = new SqlParameter("@workshopid", SqlDbType.Int, 4);
p1.Direction = ParameterDirection.Input;
p1.Value = Convert.ToInt32(txtworkshopid.Text);
cmd.Parameters.Add(p1);
SqlParameter p2 = new SqlParameter("@cargoid", SqlDbType.Int, 4);
p2.Direction = ParameterDirection.Input;
p2.Value = Convert.ToInt32(txtcargoid.Text);
cmd.Parameters.Add(p2);
SqlParameter p3 = new SqlParameter("@outperday", SqlDbType.Int,4);
p3.Direction = ParameterDirection.Input;
p3.Value=Convert.ToInt32(txtoutperday.Text);
cmd.Parameters.Add(p3);
this.sqlConnection1.Open();
cmd.ExecuteNonQuery();
this.sqlConnection1.Close();
}
else
{
// Prepare the command text
String strCmd = "UPDATE parameter SET workshopid=@workshopid,cargoid=@cargoid, outperday=@outperday WHERE setupid=@ID";
SqlCommand cmd = new SqlCommand(strCmd, this.sqlConnection1);
SqlParameter p1 = new SqlParameter("@ID", SqlDbType.Int);
p1.Direction = ParameterDirection.Input;
p1.Value = DataGrid1.DataKeys[e.Item.ItemIndex];
cmd.Parameters.Add(p1);
SqlParameter p2 = new SqlParameter("@workshopid", SqlDbType.Int, 4);
p2.Direction = ParameterDirection.Input;
p2.Value = Convert.ToInt32(txtworkshopid.Text);
cmd.Parameters.Add(p2);
SqlParameter p3 = new SqlParameter("@cargoid", SqlDbType.Int, 4);
p3.Direction = ParameterDirection.Input;
p3.Value = Convert.ToInt32(txtcargoid.Text);
cmd.Parameters.Add(p3);
SqlParameter p4 = new SqlParameter("@outperday", SqlDbType.Int,4);
p4.Direction = ParameterDirection.Input;
p4.Value= Convert.ToInt32(txtoutperday.Text);
cmd.Parameters.Add(p4);
this.sqlConnection1.Open();
cmd.ExecuteNonQuery();
this.sqlConnection1.Close();
}
// Reset the edit mode for the current item
DataGrid1.EditItemIndex = -1;
// Refresh the grid
LoadData();
UpdateView();
}
}
3.3 物料管理页面materiel.aspx的制作
3.3.1浏览功能
浏览功能的建立类似于参数设置页面,其SQL语句为“SELECT materielid, materielna, materielnu, missionid, fileid, productid FROM materiel”,页面效果如下图3.4:
图3.4物料管理页面
3.3.2编辑功能
本页面同样提供了删除,编辑,新建三个页面编辑功能,同样利用grid_DeleteCommand,grid_UpdateCommand,DataGrid1_EditCommand,grid_CancelCommand来实现,而且设置与车间参数设置页面基本相同。如下图3.5所示。
图3.5物料管理编辑页面
3.4 生产任务设置页面mission.aspx的制作
3.4.1浏览功能
浏览功能与上述页面的设置类似,其SQL语句为“SELECT workshopid, cargoid, cargoname, cargonumber, creatdate, donedate, curdate, missionid, productid, finishnum FROM mission”,页面效果如下图3.6所示。
图3.6生产任务设置页面
3.4.2编辑功能
这里介绍一下DataGrid1_EditCommand,grid_CancelCommand,其原理都是使用SqlCommand对数据库进行操作。而SqlCommand的参数由DataGrid传递。源代码如下:
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// Set the current item to edit mode
DataGrid1.EditItemIndex = e.Item.ItemIndex;
// Refresh the grid
UpdateView();
}
grid_CancelCommand源代码如下:
private void grid_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
// Reject changes on the last row
DataSet ds = (DataSet) Session["materiel"];
DataTable dt = ds.Tables["materiel"];
DataRow drLast = dt.Rows[dt.Rows.Count-1];
if (drLast.RowState == DataRowState.Added)
{
drLast.RejectChanges();
}
// Refresh the grid
UpdateView();
}
本页面同样提供了删除、新建、编辑三个页面编辑功能,利用grid_DeleteCommand,grid_UpdateCommand,DataGrid1_EditCommand,grid_CancelCommand来实现,而且设置与车间参数设置页面基本相同。如下图3.7所示。
图3.7生产任务设置页面编辑功能
3.5生产优先级设置priority.aspx的制作
3.5.1浏览功能
浏览功能与上述页面的设置类似,其SQL语句为“SELECT missionid, priid FROM priority”,其页面如下图3.8所示。
图3.8优先级设置页面
3.5.2编辑功能
本页面提供了删除、新建、编辑三个页面编辑功能,利用grid_DeleteCommand,grid_UpdateCommand,DataGrid1_EditCommand,grid_CancelCommand来实现,而且设置与车间参数设置页面基本相同。如下图3.9所示。
图3.9优先级设置编辑页面
3.6 任务例外信息except.aspx页面的制作
3.6.1浏览功能
浏览功能与上述页面的设置类似,其SQL语句为“SELECT missionid, reason FROM exceptions”,其页面如下图3.10所示。
图3.10任务例外信息页面
3.6.2编辑功能
本页面提供了删除、新建、编辑三个页面编辑功能,利用grid_DeleteCommand,grid_UpdateCommand,DataGrid1_EditCommand,grid_CancelCommand来实现,而且设置与上述页面基本相同。如下图3.11所示。
图3.11任务例外信息编辑页面