private void SetOperateForUnionCLP(DataTable unionCLPTable) { IEnumerable <DataRow> queryforSet = from uclp in unionCLPTable.AsEnumerable( ) where uclp.Field <String>("Double") == "SET" select uclp; DataTable dtSET = queryforSet.CopyToDataTable <DataRow>( ); DataTable dtNEW = dtSET.Copy( ); DataTable dtsetCopy = dtSET.Clone( ); dtsetCopy = dtSET.AsEnumerable( ).Distinct(new DataTableRowCompare("MODEL_CODE")).CopyToDataTable( ); int i = 0; foreach (DataRow row in dtsetCopy.Rows) { try { int indexlast = dtSET.Rows.IndexOf(dtSET.AsEnumerable( ).Last(e => e.Field <String>("MODEL_CODE") == row["MODEL_CODE"].ToString())); foreach (DataRow dr1 in BasicDataTable.Select("ModelCode=" + "'" + row["MODEL_CODE"].ToString( ) + "'").Skip <DataRow>(1)) { i++; DataRow dr = dtNEW.NewRow( ); dr["UNIT"] = dr1["QuanitityUnit"]; dr["HS_CODE"] = dr1["HSCode"]; dr["中文品名"] = dr1["LocalProdectName"]; dr["英文品名"] = dr1["EnglishProductName"]; dr["申报要素"] = dr1["SentialFactor"]; dr["监管条件"] = dr1["SupervisionCondition"]; dtNEW.Rows.InsertAt(dr, indexlast + i); } i++; //DataTable temp=BasicDataTable.Select( "ModelCode="+"'"+row["MODEL CODE"].ToString( )+"'" ).Skip<DataRow>( 1 ).CopyToDataTable( ); } catch (ArgumentNullException ex) { MessageBox.Show("原始资料表中SET操作" + row["MODEL_CODE"].ToString( ) + "无对应的记录!"); return; } } //添加DataTable2的数据 foreach (DataRow dr in unionCLPTable.AsEnumerable( ).Except(dtSET.AsEnumerable( ), DataRowComparer.Default).CopyToDataTable( ).Rows) { dtNEW.ImportRow(dr); } DoubleOrSetTable.Clear( ); DoubleOrSetTable = dtNEW; DoubleOrSetTable.AcceptChanges( ); //unionCLPTable=dtNEW; //MODEL CODE //var query1 = // from basicdata in BasicDataTable.AsEnumerable( ) // join setdata in dtSET.AsEnumerable( ) // on basicdata.Field<String>( "ModelCode" ) equals setdata.Field<String>( "MODEL CODE" ) // select basicdata; //DataTable dtBasicData = query1.Distinct().CopyToDataTable<DataRow>( ); }
private void DoubleOperateForUnionCLP(DataTable unionCLPTable) { bool flag; int result; foreach (DataRow row in unionCLPTable.Rows) { flag = false; result = 0; if (row["Double"].ToString( ).Trim( ).ToUpper( ) == "DOUBLE") { string strSize = row["SIZE"].ToString( ).Trim( ); if (strSize.Contains("MONTHS")) { if (int.TryParse(strSize.Split(' ')[0], out result)) { if (result > 24) { flag = true; } } } if (strSize.Contains("AGE")) { if (int.TryParse(strSize.Split(' ')[1], out result)) { if (result >= 3) { flag = true; } } } if (flag) { if (row["申报要素"].ToString( ).Contains("类别:婴儿")) { string strfilter = "ModelCode=" + "'" + row["MODEL_CODE"].ToString( ) + "'" + " AND SentialFactor<>" + "'" + row["申报要素"].ToString( ) + "'"; //DataTable dttemp=DataTableHelper.GetNewTableByDataView(BasicDataTable,strfilter); DataRow[] drs = BasicDataTable.Select(strfilter); row["UNIT"] = drs[0]["QuanitityUnit"]; row["HS_CODE"] = drs[0]["HSCode"]; row["中文品名"] = drs[0]["LocalProdectName"]; row["英文品名"] = drs[0]["EnglishProductName"]; row["申报要素"] = drs[0]["SentialFactor"]; row["监管条件"] = drs[0]["SupervisionCondition"]; row["Double"] = "N"; unionCLPTable.AcceptChanges( ); } else { row["Double"] = "N"; unionCLPTable.AcceptChanges( ); } } else { if (!row["申报要素"].ToString( ).Contains("类别:婴儿")) { string strfilter = "ModelCode=" + "'" + row["MODEL_CODE"].ToString( ) + "'" + " AND SentialFactor<>" + "'" + row["申报要素"].ToString( ) + "'"; //DataTable dttemp=DataTableHelper.GetNewTableByDataView(BasicDataTable,strfilter); DataRow[] drs = BasicDataTable.Select(strfilter); row["UNIT"] = drs[0]["QuanitityUnit"]; row["HS_CODE"] = drs[0]["HSCode"]; row["中文品名"] = drs[0]["LocalProdectName"]; row["英文品名"] = drs[0]["EnglishProductName"]; row["申报要素"] = drs[0]["SentialFactor"]; row["监管条件"] = drs[0]["SupervisionCondition"]; row["Double"] = "N"; unionCLPTable.AcceptChanges( ); } else { row["Double"] = "N"; unionCLPTable.AcceptChanges( ); } } unionCLPTable.AcceptChanges( ); } } }