| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System;
- using System.Reflection;
- using System.Collections;
- using System.Resources;
- using System.Windows.Forms;
- using System.Data;
- using System.Data.OleDb;
- using System.Collections.Generic;
- namespace Core.Mes.Client.Common.Util
- {
- public class DataSetUtil
- {
- public static int Count(DataSet ds)
- {
- try
- {
- return ds.Tables[0].Rows.Count;
- }
- catch
- {
- }
- return 0;
- }
- public static DataSet GetDataSetWithTbColumnAndSourceDataSet(DataSet dsSource, string[] columnList)
- {
- if (Util.DataSetUtil.Count(dsSource) == 0)
- return dsSource;
- if (columnList.Length == 0)
- return dsSource;
- DataSet dsNew = new DataSet();
- DataTable dtNew = new DataTable();
- DataColumn dc = null;
- dsNew.Tables.Add(dtNew);
- foreach (string s in columnList)
- {
- if (dsSource.Tables[0].Columns.Contains(s.ToUpper()))
- dc = new DataColumn(s.ToUpper(), dsSource.Tables[0].Columns[s].DataType);
- else
- dc = new DataColumn(s.ToUpper(), System.Type.GetType("System.String"));
- dsNew.Tables[0].Columns.Add(dc);
- }
- dsNew.Tables[0].Merge(dsSource.Tables[0], false, System.Data.MissingSchemaAction.Ignore);
- dsNew.AcceptChanges();
- return dsNew;
- }
- /// <summary>
- /// 合并两个DataSet
- /// </summary>
- /// <param name="dsSouce"></param>
- /// <param name="dsNewData"></param>
- /// <param name="values"></param>
- /// <param name="columnName"></param>
- /// <returns></returns>
- public static DataSet GetMergeDataSetByAddNewData(DataSet dsSouce, DataSet dsNewData, List<string> values, string columnName)
- {
- DataSet ds = dsSouce.Copy();
- if (Count(ds) == 0)
- return ds;
- if (Count(dsNewData) == 0)
- return ds;
- foreach (DataRow dr in ds.Tables[0].Rows)
- {
- DataRow[] drs = dsNewData.Tables[0].Select(string.Format("{0} = '{1}' ", columnName, dr[columnName].ToString()));
- if (drs == null || drs.Length == 0)
- continue;
- try
- {
- foreach (string s in values)
- {
- try
- {
- dr[s] = drs[0][s];
- }
- catch
- {
- }
- }
- }
- catch
- {
- }
- }
- return ds;
- }
- }
- }
|