using Microsoft.SqlServer.Server; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; namespace Bottleneckv11 { public partial class DetailFPlantbl { //public string DenoIDfromfile { get; set; } public string IDTOUpdate // property { get { return "PU" + ProcessUnitID + "-" + PlanDate.ToString("ddMMyyyy"); } // get method //set { name = value; } // set method } } public class DetailedCollection : List, IEnumerable { IEnumerator IEnumerable.GetEnumerator() { var sqlRow = new SqlDataRecord( new SqlMetaData("@PlanDate", SqlDbType.Date), new SqlMetaData("@ProcessUnitID", SqlDbType.VarChar,50), new SqlMetaData("@DActualcumSAPUnit", SqlDbType.NChar, 10), new SqlMetaData("@DActualcumSAP", SqlDbType.Decimal,7,3), new SqlMetaData("@DActualperdaySAPUnit", SqlDbType.NChar, 10), new SqlMetaData("@DActualperdaySAP", SqlDbType.Decimal, 7, 3), new SqlMetaData("@DActualcumtotalUnit", SqlDbType.NChar, 10), new SqlMetaData("@DActualcumtotal", SqlDbType.Decimal, 7, 3), new SqlMetaData("@DTargetcumUnit", SqlDbType.NChar,10), new SqlMetaData("@DTargetcum", SqlDbType.Decimal, 7, 3), new SqlMetaData("@DTargetperdayUnit", SqlDbType.NChar, 10), new SqlMetaData("@DTargetperday", SqlDbType.Decimal, 7, 3), new SqlMetaData("@DTargetcumtotalUnit", SqlDbType.NChar, 10), new SqlMetaData("@DTargetcumtotal", SqlDbType.Decimal, 7, 3), new SqlMetaData("@IDtoUpdate", SqlDbType.VarChar, 50), new SqlMetaData("@DenoIDfromfile", SqlDbType.VarChar,10) ); foreach (DetailFPlantbl cust in this) { sqlRow.SetDateTime(0, cust.PlanDate); sqlRow.SetString(1, cust.ProcessUnitID); sqlRow.SetString(2, cust.DActualcumSAPUnit); sqlRow.SetDecimal(3, cust.DActualcumSAP); sqlRow.SetString(4, cust.DActualperdaySAPUnit); sqlRow.SetDecimal(5, cust.DActualperdaySAP); sqlRow.SetString(6, cust.DActualcumtotalUnit); sqlRow.SetDecimal(7, cust.DActualcumtotal); sqlRow.SetString(8, cust.DTargetcumUnit); sqlRow.SetDecimal(9, cust.DTargetcum); sqlRow.SetString(10, cust.DTargetperdayUnit); sqlRow.SetDecimal(11, cust.DTargetperday); sqlRow.SetString(12, cust.DTargetcumtotalUnit); sqlRow.SetDecimal(13, cust.DTargetcumtotal); sqlRow.SetString(14, cust.IDTOUpdate); sqlRow.SetString(15, cust.DenoIDfromfile); yield return sqlRow; } } } public static class ExtensionSqlDataRecord { public static void SetDateTime(this SqlDataRecord record, int ordinal, DateTime? value) { if (value != null) { record.SetDateTime(ordinal, (DateTime)value); } else { record.SetDBNull(ordinal); } } public static void SetInt32(this SqlDataRecord record, int ordinal, int? value) { if (value != null) { record.SetInt32(ordinal, (int)value); } else { record.SetDBNull(ordinal); } } public static void SetByte(this SqlDataRecord record, int ordinal, byte? value) { if (value != null) { record.SetByte(ordinal, (byte)value); } else { record.SetDBNull(ordinal); } } public static void SetDecimal(this SqlDataRecord record, int ordinal, decimal? value) { if (value != null) { record.SetDecimal(ordinal, (decimal)value); } else { record.SetDBNull(ordinal); } } public static void SetBoolean(this SqlDataRecord record, int ordinal, bool? value) { if (value != null) { record.SetBoolean(ordinal, (bool)value); } else { record.SetDBNull(ordinal); } } } }