开发工具与关键技术:Visual Studio 2015
作者:杨镇虹
撰写时间:2020.09.18
一、 采购商品
1、 增加按钮(XML页面代码) 给个点击事件Click
<Button Grid.Row="0" Grid.Column="0" Name="tex_InsertOrderGoods" Content="增加" Height="30" Width="60" Style="{StaticResource BtnInsertStyle}" Click="tex_InsertOrderGoods_Click"/>
2、 增加按钮-点击事件 弹出增加窗口(后台代码块)
//增加 订单订货 制作
private void tex_InsertOrderGoods_Click(object sender, RoutedEventArgs e)
{//获取订单 最大单号
string strOrderNumber = dt.Rows[0][“OrderNumber”].ToString();
//实例化 新增订单订货制作窗口
WD_InsertOrderGoods myWD_InsertOrderGoods = new WD_InsertOrderGoods(strOrderNumber);
myWD_InsertOrderGoods.ShowDialog();//弹出窗口
selectOrderGoods();//刷新 订单表格数据}
3、保存新增操作(后台代码)
//保存 新增订单
private void btnSave_Click(object sender, RoutedEventArgs e) {
try{//获取页面数据
string strOrderOdd = tex_OrderOdd.Text.ToString().Trim();//订单号 DateTime dtOrderDate = Convert.ToDateTime(tex_OrderDate.Text.ToString().Trim());//下单日期
int intClientName = Convert.ToInt32(tex_ClientName.SelectedValue);//订货人
int intMaterialEtc = Convert.ToInt32(tex_MaterialEtc.SelectedValue);//供货单位
string strtex_Remark = tex_Remark.Text.ToString().Trim();//备注
//判断页面数据是否填写完整
if (strOrderOdd != “” && dtOrderDate != null && intClientName > 0 && intMaterialEtc > 0 && strtex_Remark != string.Empty && tex_ReachDate.Text.ToString().Trim() != “”){
DateTime dtR = Convert.ToDateTime((tex_ReachDate.Text));//到货日期
if (dtR >= dtOrderDate)
{//声明一个变量-接收选中了多少个多选框
int intchked = 0;//项数
//声明一个变量-接收合计金额
int intPerMoney = 0;//每一项的合计金额 int intMoney = 0;//总合计金额
int intPartsID = 0;//零件ID int intOrderGoodsRequired = 0;//订货数
//for循环-订货零件表的条数 获取选择零件项数和总合计金额
for (int i = 0; i < dgOrderGoodsParts.Items.Count; i++)
{//判断是否选中多选框
if (Convert.ToBoolean(dtOrderGoodsParts.Rows[i][“chked”]) == true)
{
intchked++;//项数自加加
//获取零件ID
intPartsID = Convert.ToInt32(((DataRowView)dgOrderGoodsParts.Items[i]).Row[“PartsID”]);
intOrderGoodsRequired = Convert.ToInt32(((DataRowView)dgOrderGoodsParts.Items[i]).Row[“OrderGoodsRequired”]);//订货数
int intPrice = Convert.ToInt32(((DataRowView)dgOrderGoodsParts.Items[i]).Row[“Price”]);//订货单价 //判断订货数是否大于零
if (intOrderGoodsRequired > 0) {
intPerMoney = intOrderGoodsRequired * intPrice;//订货数跟订货单价相乘
intMoney += intPerMoney;//合计金额}}}
string strTermsNumber = tex_TermsNumber.Text = intchked.ToString();//赋值项数
string strMoney = tex_Money.Text = intMoney.ToString();//赋值合计金额
bool blStatus = false;//设置订单状态为false
//执行 新增订单表操作
int count = Convert.ToInt32(myClient.btnSave_Click_Order(intMaterialEtc, intClientName, strOrderOdd, dtOrderDate, strTermsNumber, strMoney, blStatus, dtR, strtex_Remark));
if (count > 0) //判断新增订单成功是否大于零{
DataTable dtOrder = myClient.Select_OrderOdd(strOrderOdd).Tables[0]; //根据订单号查询
int intOrderID = Convert.ToInt32(dtOrder.Rows[0][“OrderID”]);//获取订单ID
int intcount = 0;
//for循环新增 订货表
for (int j = 0; j < dgOrderGoodsParts.Items.Count; j++){
if (Convert.ToBoolean(dtOrderGoodsParts.Rows[j][“chked”]) == true) //判断是否选中多选框
{//获取零件ID
int intParts = Convert.ToInt32(((DataRowView)dgOrderGoodsParts.Items[j]).Row[“PartsID”]);
int intOrderGoodsRequireds = Convert.ToInt32(((DataRowView)dgOrderGoodsParts.Items[j]).Row[“OrderGoodsRequired”]);
//根据零件ID 查询数据转换表格
DataTable dtGoods = myClient.Select_GoodsID(intParts).Tables[0];
for (int g = 0; g < dtGoods.Rows.Count; g++){
int intGoodsID = Convert.ToInt32(dtGoods.Rows[0][“GoodsID”]);
nt intp = 1;
intcount = Convert.ToInt32(myClient.btnSave_Click_OrderGoods(intGoodsID, intOrderID, intp, intOrderGoodsRequireds.ToString()));//新增订货表}
}
}
if (intcount > 0 || count > 0) //判断 是否新增成功{ MessageBoxResult dr = MessageBox.Show(“新增订单成功!”, “系统提示”, MessageBoxButton.OK, MessageBoxImage.Information);
if (dr == MessageBoxResult.OK) {
this.Close();//关闭窗口}
}
}else{MessageBox.Show(“已存在该订单号”, “系统提示”);}
}else{MessageBox.Show(“到货日期不能小于下单日期!”, “系统提示”, MessageBoxButton.OK, MessageBoxImage.Warning);
}
}else {MessageBox.Show(“请填写完整页面数据!”, “系统提示”, MessageBoxButton.OK, MessageBoxImage.Warning); }
}catch (Exception ex) { MessageBox.Show(“数据异常” +ex.ToString(),“系统提示”,MessageBoxButton.OK,MessageBoxImage.Error); } }