private List <SqlCommand> createBomHeaderCmd(string BomNo, BomInfo BomInfo, DataRow HeadRow, List <BomFormatDetail> ExcelFormatDtls) { string str = @"Insert Into MF_BOM({0}) values ({1})"; string strZ = @"Insert Into MF_BOM_Z({0}) values ({1})"; List <SqlCommand> cmds = new List <SqlCommand>(); var headerFields = ExcelFormatDtls .Where(o => o.cell_type == "SYS" && (o.diy_type == "1" || o.diy_type == "3")) .ToList(); Dictionary <string, string> dicts = new Dictionary <string, string>(); dicts.Add("bom_no", BomNo); foreach (var item in headerFields) { //Bom头主数量=1 if (item.field_no == "qty") { dicts.Add(item.field_no, "1"); } //货名以 ERP的为准 else if (item.field_no == "name") { dicts.Add(item.field_no, Service.GetPrdtName(HeadRow.GetSting("prd_no"))); } else { dicts.Add(item.field_no, HeadRow.GetSting(item.field_no)); } } if (dicts.ContainsKey("prd_knd") == false) { dicts.Add("prd_knd", BomInfo.prd_knd); } foreach (var item in BomService.DefaultBomHeaderSection) { //有了设值,覆盖默认值 if (dicts.ContainsKey(item.Key.ToLower()) == true) { continue; } dicts.Add(item.Key, GetDefaultVariable(item.Value)); } cmds.Add(new SqlCommand(str.FormatOrg( string.Join(",", dicts.Select(o => o.Key)), string.Join(",", dicts.Select(o => "'" + o.Value + "'")) ))); var headerZFields = ExcelFormatDtls .Where(o => o.cell_type == "DIY" && (o.diy_type == "1" || o.diy_type == "3")) .ToList(); if (headerZFields.Count > 0) { Dictionary <string, string> zDicts = new Dictionary <string, string>(); zDicts.Add("bom_no", BomNo); foreach (var item in headerZFields) { zDicts.Add(item.field_no, HeadRow.GetSting(item.field_no)); } cmds.Add(new SqlCommand(strZ.FormatOrg( string.Join(",", zDicts.Select(o => o.Key)), string.Join(",", zDicts.Select(o => "'" + o.Value + "'")) ))); } return(cmds); }