复制代码 代码如下:
ASP.NET MVC的Controller代码如下:
复制代码 代码如下:
///
/// 多选商品添加
///
/// 供货商ID
///
public ActionResult SelectGoods(string supplier)
{
ViewData["supplier"] = supplier;
return View();
}
///
/// 保存批量添加的产品信息
///
/// 选中的商品ID
/// 供货商名称
///
public JsonResult SaveSelect(string checks, string supplier)
{
JsonResult result = new JsonResult();
result.Data = false;
try
{
if (String.IsNullOrEmpty(supplier))
return result;
SupplierGoods goods = new SupplierGoods();
goods.Identifier = 0;
//拼装xml
String ids=Communion.StringHelper.BuildXmlID(checks);
goods.Goods_ID = -1;//标示批量插入
goods.Note = ids;
goods.Month_Output = Convert.ToDouble(String.IsNullOrEmpty(this.ReadFromRequest("Month_Output")) ? "0" : this.ReadFromRequest("Month_Output"));
goods.Supplier_ID = Convert.ToInt32(supplier);
goods.Create_Date = DateTime.Now;
goods.Customers = this.ReadFromRequest("Customers");
goods.Equipment = this.ReadFromRequest("Equipment");
goods.Detail_Params = this.ReadFromRequest("Detail_Params");
goods.IsDefault = Convert.ToInt32(String.IsNullOrEmpty(this.ReadFromRequest("IsDefault")) ? "0" : this.ReadFromRequest("IsDefault"));
Business business = new BusinessLogic();
int id = business.Save
if (goods.Identifier == 0)
{
goods.Identifier = id;
}
result.Data = true;
return result;
}
catch (Exception e)
{
return result;
}
}
存储过程利用xml变量对传入的xml类型的ID集合进行批量添加保存到数据库中,存储过程代码如下:
复制代码 代码如下:
ALTER PROCEDURE [dbo].[View_SupplierGoodsCreate]
@Identifier int,
@Supplier_ID int,
@Goods_ID int,
@isDefault int,
@Create_Date datetime,
@Month_Output float(8),
@Goods_Name nvarchar(400)=NULL,
@Physical nvarchar(400)=NULL,
@Chemistry nvarchar(400)=NULL,
@Customers nvarchar(400)=NULL,
@Equipment nvarchar(400)=NULL,
@Note nvarchar(MAX)=NULL,
@Detail_Params nvarchar(400)=NULL
AS
IF @Goods_ID=-1
BEGIN
--批量插入商品
DECLARE @xml xml
SET @xml=@Note
INSERT INTO Supplier_Goods(Supplier_ID,Goods_ID,Create_Date,Month_Output,Customers,Equipment,Note,isdefault,Detail_Params)
SELECT @Supplier_ID,identifier,@Create_Date,0,null,null,null,0,null
FROM Base_Goods
WHERE
Identifier in (Select
T.ID.value('.', 'int') As ID
From
@xml.nodes('/XML/ID') as T(ID)) and Identifier not in (select goods_id from Supplier_Goods where Supplier_ID=@Supplier_ID)
SET @Identifier=@Goods_ID
END