}                                  //전화번호(비고)

        public List <cssControlCommunicationStauts> DataTableToClass(DataTable dt)
        {
            List <cssControlCommunicationStauts> lstData = new List <cssControlCommunicationStauts>();

            if (dt == null)
            {
                return(lstData);
            }

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cssControlCommunicationStauts vio = new cssControlCommunicationStauts();
                PropertyInfo[] props = vio.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

                foreach (var property in props)
                {
                    string colName = string.Empty;
                    if (ControlCommunicationStauts.TryGetValue(property.Name, out colName))
                    {
                        property.SetValue(vio, dt.Rows[i][colName].ToString());
                    }
                }

                lstData.Add(vio);
            }


            return(lstData);
        }
Example #2
0
        /// <summary>
        /// 관제 교신 현황 저장
        /// </summary>
        /// <param name="csvFileData"></param>
        private void CopyToDataBaseFromControlCommuStatus(DataTable csvFileData)
        {
            cssControlCommunicationStauts        vio     = new cssControlCommunicationStauts();
            List <cssControlCommunicationStauts> lstData = vio.DataTableToClass(csvFileData);

            var bulk = new BulkOperations();

            // var VesselInfo = new List<VesselInfo>();

            using (TransactionScope trans = new TransactionScope())
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    bulk.Setup <cssControlCommunicationStauts>()
                    .ForCollection(lstData)
                    .WithTable("ControlCommunication")
                    .AddAllColumns()
                    .BulkInsertOrUpdate()
                    .MatchTargetOn(x => x.prtAgNm)
                    .MatchTargetOn(x => x.clsgn)
                    .MatchTargetOn(x => x.etryptYear)
                    .MatchTargetOn(x => x.etryptCo)

                    .Commit(conn);
                }

                trans.Complete();
            }
        }