Wpf中的修改,需要应用三个地方,第一个SQL第二个service第三个client,顾名思义SQL是用来写方法的,service是调用在SQL里写的方法的,client是对service中的调用进行执行的。
下面来用一些代码来展示使用的具体方法,使用商贸系统中的商品修改案例;第一SQL:
-----修改商品
IF(@Type='Update_Commodity')
BEGIN
---EXISTS用于检查子查询是否至少会返回一行数据,该子查询实际上并不返回任何数据,而是返回值True或False
---EXISTS 指定一个子查询,检测 行 的存在。
if exists(select 0 from PW_Commodity where ShopYard=@ShopYard and CommodityID!=CommodityID)--验证店内码
begin
return
end
else
UPDATE PW_Commodity
SET CommodityName=@CommodityName, CommodityNumber=@CommodityNumber, ShopYard=@ShopYard,
Unit = @Unit, CommoditySpecification = @CommoditySpecification,
StockPrice = @StockPrice, TradePrice = @TradePrice, RetailPrice = @RetailPrice, member = @member,
simple_code = @simple_code, ElectronicScale = @ElectronicScale, Rem = @Rem
WHERE PW_Commodity.CommodityID=@CommodityID
END
第二service:
[OperationContract]
//修改商品信息
public int Update_Commodity(string strCommodityName, string strCommodityNumber, string strShopYard, string strUnit, string strCommoditySpecification, decimal deStockPrice,decimal deTradePrice, decimal deRetailPrice, decimal demember, string strsimple_code, bool blElectronicScale, string strRem,int intCommodityID)
{
SqlParameter[] SQLupdate =
{
new SqlParameter("@Type",SqlDbType.Char),
new SqlParameter("@CommodityName",SqlDbType.NChar),
new SqlParameter("@CommodityNumber",SqlDbType.NChar),
new SqlParameter("@ShopYard",SqlDbType.NChar),
new SqlParameter("@Unit",SqlDbType.NChar),
new SqlParameter("@CommoditySpecification",SqlDbType.NChar),
new SqlParameter("@StockPrice",SqlDbType.Decimal),
new SqlParameter("@TradePrice",SqlDbType.Decimal),
new SqlParameter("@RetailPrice",SqlDbType.Decimal),
new SqlParameter("@member",SqlDbType.Decimal),
new SqlParameter("@simple_code",SqlDbType.NChar),
new SqlParameter("@ElectronicScale",SqlDbType.Bit),
new SqlParameter("@Rem",SqlDbType.NChar),
new SqlParameter("@CommodityID",SqlDbType.Int),
};
SQLupdate[0].Value = "Update_Commodity";
SQLupdate[1].Value = strCommodityName;
SQLupdate[2].Value = strCommodityNumber;
SQLupdate[3].Value = strShopYard;
SQLupdate[4].Value = strUnit;
SQLupdate[5].Value = strCommoditySpecification;
SQLupdate[6].Value = deStockPrice;
SQLupdate[7].Value = deTradePrice;
SQLupdate[8].Value = deRetailPrice;
SQLupdate[9].Value = demember;
SQLupdate[10].Value = strsimple_code;
SQLupdate[11].Value = blElectronicScale;
SQLupdate[12].Value = strRem;
SQLupdate[13].Value = intCommodityID;
int count = myDAL.UpdateData("WD_Commodity", SQLupdate);
return count;
}
第三client:获取 数据–判断 数据–保存 数据
//保存
private void SaveComm_Click(object sender, RoutedEventArgs e)
{
try
{
// DataRow dr;
//获取页面数据
string strCommodityName = txt_CommodityName.Text.ToString();//商品名称
string strCommodityNumber = txt_CommNum.Text.ToString();//商品条码
string strShopYard = txt_ShopYard.Text.ToString();//店内码
string strUnit = txt_Unit.Text.ToString();//单位
string strCommoditySpecification = txt_CommoditySpecification.Text.ToString();//规格
decimal deStockPrice = Convert.ToDecimal(txt_StockPrice.Text.ToString());//进货价
decimal deTradePrice = 0 ;//批发价
deTradePrice = Convert.ToInt32(deTradePrice);
decimal deRetailPrice = Convert.ToDecimal(txt_RetailPrice.Text.ToString());//零售价
decimal demember = Convert.ToDecimal(txt_RetailPrice.Text.ToString());//会员价
string strsimple_code = txt_simple_code.Text.ToString();//拼音助记
string strRem = txt_Rem.Text.ToString();//备注
// int intCommodityTypeID = Convert.ToInt32(treeView.SelectedValue);//商品类型
string strSupportName = txt_SupportName.Text.ToString();//供应商名称
string strSupportNumber = txt_SupportNumber.Text.ToString();//供应商编码
//是否用到电子秤
bool blElectronicScale = true || false;
if (cbo_ElectronicScale.Text.Equals("是"))
{
blElectronicScale = true;
}
else if (cbo_ElectronicScale.Text.Equals("否"))
{
blElectronicScale = false;
}
// treeView.SelectedValuePath = Convert.ToInt32(DGVR.Row["CommodityTypeID"]).ToString();
//判断必填项不能为空treeView.SelectedValue.ToString() != string.Empty &&//商品类型
if (
txt_CommNum.Text.ToString() != string.Empty //商品条码
&& txt_ShopYard.Text.ToString() != string.Empty //店内吗
&& txt_StockPrice.Text.ToString() != string.Empty//进货价
&& txt_TradePrice.Text.ToString() != string.Empty//批发价
&& txt_RetailPrice.Text.ToString() != string.Empty//零售价
&& txt_CommodityName.Text.ToString() != string.Empty)//商品名称)
{
#region 修改保存
/*
1.修改商品表,需要根据商品ID进行修改
2.修改供应商名称|编号,根据商品ID查询供应商数据 进行修改
3.商品进行修改的时候商品类型是不可删除的
*/
//执行修改商品信息表
int comUpdate = myClient.Update_Commodity(strCommodityName, strCommodityNumber, strShopYard, strUnit, strCommoditySpecification,
deStockPrice,deTradePrice, deRetailPrice, demember, strsimple_code, blElectronicScale, strRem, Convert.ToInt32(DGVR.Row["CommodityID"]));
if (comUpdate >0)
{
//执行修改供应商名称|编号
int comUpdate1 = myClient.Update_SupportNameNumber(strSupportNumber, strSupportName, Convert.ToInt32(DGVR.Row["SupportID"]));
if (comUpdate1 > 0)
{
//执行修改商品类型
//int comUpdate2 = myClient.Update_Common_Type(intCommodityTypeID, Convert.ToInt32(DGVR.Row["Common_TypeID"]));
//if (comUpdate2 >0)
//{
MessageBoxResult dr = MessageBox.Show("修改成功!", "系统提示", MessageBoxButton.OKCancel,
MessageBoxImage.Information); //弹出确定对话框
//关闭当前窗口
if (dr == MessageBoxResult.OK) //如果点了确定按钮
{
//关闭当前窗口
this.Close();
}
//}
}
else
{
MessageBox.Show("修改供应商名称|编号失败!", "系统提示", MessageBoxButton.OKCancel, MessageBoxImage.Error);
}
}
else
{
MessageBox.Show("修改商品信息失败(重复)!", "系统提示", MessageBoxButton.OKCancel, MessageBoxImage.Error);
}
#endregion
}
else
{
MessageBox.Show("商品信息还没完整填完,请继续!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
catch (Exception)
{
MessageBox.Show("保存失败!", "系统提示", MessageBoxButton.OKCancel, MessageBoxImage.Error);
// throw;
}
}