在同一个数据库表中添加不同的数据(笛卡尔积)
/// <summary>
/// 添加检测项目
/// </summary>
private void PbitemCodeSubmit()
{
string msg = "0";
string[] oldPBItems = Request.Form["ipt_pbitemcode"].Split(',');
string strWhere = string.Format("BioTestPlanHeaderID={0}", Request.Form["ipt_biotestplanheaderid"]);
List<Model.BioTestPlanBody> bioTestPlanBodyModelList = bioTestPlanBodyBll.GetModelList(strWhere);//根据检测计划ID查询学生检测信息
strWhere = string.Format("BioTestPlanHeaderID={0}", Request.Form["ipt_biotestplanheaderid"]);
DataSet dsPBItem = dhBll.GetList("V_PBItemOfBioTestPlanBody", "*", "", strWhere);
strWhere = string.Format("BioTestPlanHeaderID={0}", Request.Form["ipt_biotestplanheaderid"]);
DataSet dsAthlete = dhBll.GetList("V_AthleteStudentBYBioTestPlanBody", "*", "", strWhere);
List<string> newPBItemList = oldPBItems.ToList<string>();
foreach (DataRow itemRow in dsPBItem.Tables[0].Rows)
{
if (!newPBItemList.Contains(itemRow["PBItemCode"].ToString()))
{
newPBItemList.Add(itemRow["PBItemCode"].ToString());
break;
}
}
if (dsAthlete.Tables[0].Rows.Count > 0)
{
for (int num = 0; num < newPBItemList.Count; num++)
{
foreach (DataRow itemRow in dsAthlete.Tables[0].Rows)
{
Model.BioTestPlanBody bioTestPlanModel = new Model.BioTestPlanBody();
bioTestPlanModel.BioTestPlanHeaderID = Convert.ToInt32(Request.Form["ipt_biotestplanheaderid"]);
bioTestPlanModel.AthleteStudentID = Convert.ToInt32(itemRow["AthleteStudentID"].ToString());
bioTestPlanModel.PBItemCode = newPBItemList[num];
bioTestPlanBodyBll.Add(bioTestPlanModel);
}
}
}
else
{
for (int num = 0; num < newPBItemList.Count; num++)
{
Model.BioTestPlanBody bioTestPlanModel = new Model.BioTestPlanBody();
bioTestPlanModel.BioTestPlanHeaderID = Convert.ToInt32(Request.Form["ipt_biotestplanheaderid"]);
bioTestPlanModel.PBItemCode = newPBItemList[num];
bioTestPlanBodyBll.Add(bioTestPlanModel);
}
}
foreach (Model.BioTestPlanBody itemModel in bioTestPlanBodyModelList)
{
bioTestPlanBodyBll.Delete(itemModel.BioTestPlanBodyID);
}
WebCommon.WriteMsg(msg);
}