当前位置: 首页>>代码示例>>C#>>正文


C# DataRow.ConvertTo方法代码示例

本文整理汇总了C#中System.Data.DataRow.ConvertTo方法的典型用法代码示例。如果您正苦于以下问题:C# DataRow.ConvertTo方法的具体用法?C# DataRow.ConvertTo怎么用?C# DataRow.ConvertTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.DataRow的用法示例。


在下文中一共展示了DataRow.ConvertTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateProviderContact

        public Contact ValidateProviderContact( DataTable objDT, System.Text.RegularExpressions.Regex objRegExZip, System.Text.RegularExpressions.Regex objRegExEmail, System.Text.RegularExpressions.Regex objRegExPhone, List<EMSC2SF.User> objExistingUsers, List<EMSC2SF.Sub_Region__c> objSubRegions, List<string> objSpecialties, string[] strSpecialtySearchFor, string[] strSpecialtySubstitutions, List<string> objLeadSources, List<string> obj2ndLeadSources, string[] strSearchFor, string[] strSubstitutions, List<Contact> objContacts, DataRow objDR )
        {
            // copy all datatable columns to contact object attributes
            Contact objNewContact = objDR.ConvertTo<Contact>( true );

            objNewContact.Middle_Name__c = objNewContact.Middle_Name__c.RemoveSpecialCharacters();

            // validate zip
            System.Text.RegularExpressions.MatchCollection objMatchZip = objRegExZip.Matches( objNewContact.Zipcode__c );
            if( objMatchZip.Count > 0 )
                objNewContact.Zipcode__c = objMatchZip[ 0 ].Value;

            objNewContact.Zipcode__c = Company2SFUtils.ValidatePostalCode( objNewContact.Zipcode__c );
            objNewContact.OtherPostalCode = Company2SFUtils.ValidatePostalCode( objNewContact.OtherPostalCode );

            // validate ssn
            if( objNewContact.SSN__c != null && objNewContact.SSN__c.Length != 9 )
                objNewContact.SSN__c = "";

            // extract and validate email
            string strUnformattedEmail = objDR[ "UnformattedEmail" ].ToString();
            strUnformattedEmail = strUnformattedEmail.Replace( ",", "." ).Replace( "..", "." ).Replace( " ", "" )
                    .Replace( ">", "." ).Replace( "@@", "@" );
            System.Text.RegularExpressions.MatchCollection objMatch = objRegExEmail.Matches( strUnformattedEmail );
            if( objMatch.Count > 0 )
                objNewContact.Email = objMatch[ 0 ].Value;
            if( objMatch.Count > 1 )
                objNewContact.Contacts_Email_No_2__c = objMatch[ 1 ].Value;
            if( objMatch.Count > 2 )
                objNewContact.Contacts_Email_No_3__c = objMatch[ 2 ].Value;
            if( objMatch.Count == 0 )
                objNewContact.Email = "";

            // validate phones
            objNewContact.HomePhone = Company2SFUtils.ValidPhone( objRegExPhone, objNewContact.HomePhone );
            objNewContact.OtherPhone = Company2SFUtils.ValidPhone( objRegExPhone, objNewContact.OtherPhone );
            objNewContact.Work_Phone__c = Company2SFUtils.ValidPhone( objRegExPhone, objNewContact.Work_Phone__c );
            objNewContact.MobilePhone = Company2SFUtils.ValidPhone( objRegExPhone, objNewContact.MobilePhone );
            objNewContact.Fax = Company2SFUtils.ValidPhone( objRegExPhone, objNewContact.Fax );

            // set the owning region using appointments, if blank, use the region in the provider's record
            string strOwningRegion = objDR[ "Default_Owning_Region" ].ToString();
            switch( strOwningRegion )
            {
                case "CEN":
                case "6":
                case "14":
                case "2":
                    strOwningRegion = "SWED";
                    break;
                case "SE":
                case "7":
                    strOwningRegion = "SED";
                    break;
                case "NE":
                    strOwningRegion = "NED";
                    break;
                case "PW":
                    strOwningRegion = "PWED";
                    break;
                case "DMS":
                    strOwningRegion = "PWDMS";
                    break;
                case "SANJ":
                    strOwningRegion = "PWSANJ";
                    break;
                case "4":
                case "1":
                case "9":
                case "11":
                case "13":
                    strOwningRegion = "";
                    break;
                case "":
                    strOwningRegion = objDR[ "Less_Reliable_Region" ].ToString();
                    break;
                default: // don't change it
                    break;
            }
            objNewContact.Owning_Region__c = strOwningRegion;

            // convert specialty
            objNewContact.Specialty__c = Company2SFUtils.ConvertToStandardValue( objSpecialties, strSpecialtySearchFor, strSpecialtySubstitutions
                , objNewContact.Specialty__c );

            // convert lead source
            LeadSourcePair objLSResults = ConvertLeadSource( objLeadSources, obj2ndLeadSources
                , strSearchFor, strSubstitutions, objNewContact.Lead_Source_1__c );
            objNewContact.Lead_Source_1__c = objLSResults.LeadSource1;
            objNewContact.Lead_Source_Text__c = objLSResults.LeadSource2;

            // convert recruiter usercode to Salesforce User ID
            if( !objDR[ "Recruiter" ].IsNullOrBlank() )
            {
                string strRecruiter = objDR[ "Recruiter" ].ToString();
                EMSC2SF.User objFound = objExistingUsers.FirstOrDefault(
                            u => u.Company_Usercode__c != null
                                && u.Company_Usercode__c.Equals( strRecruiter )
                                && u.IsActive == true );
                if( objFound != null )
//.........这里部分代码省略.........
开发者ID:fmendes,项目名称:SalesForceCSharpAPI,代码行数:101,代码来源:DataLoader.cs

示例2: ProcessCandidateRecord

        private Candidate__c ProcessCandidateRecord( List<Contact> objProviders, List<Facility__c> objFacilities
            , DataTable objDT, List<Candidate__c> objCandidates
            , List<Contact> objProvidersToUpdate
            , ref double dblRecruitingID, ref string strSiteCode
            , ref int iSkipped, DataRow objDR, ref bool bSkipThisRecord)
        {
            // copy all datatable columns to credential agency object attributes
            Candidate__c objNewCandidate = objDR.ConvertTo<Candidate__c>();

            // try match 1st 15 characters
            string strName = objDR[ "HospitalName" ].ToString().Left( 15 );
            strSiteCode = objNewCandidate.Facility_Name__c;
            Facility__c objFacility = FindFacilityByNameOrCode( objFacilities, strName, strSiteCode );
            if( objFacility == null )
            {
                tbStatus.Text = string.Concat( tbStatus.Text, "\r\nCould not find hospital matching "
                                    , objDR[ "HospitalName" ].ToString(), " or site code <"
                                    , strSiteCode, "> for ", objNewCandidate.Name );
                iSkipped++;
                //continue;
                bSkipThisRecord = true;
                return objNewCandidate;
            }
            objNewCandidate.Facility_Name__c = objFacility.Id;
            strSiteCode = objFacility.Site_Code__c;

            // link candidate to Contact/Provider using RecruitingID
            dblRecruitingID = Convert.ToDouble( objNewCandidate.Contact__c );
            double dblRecrID = dblRecruitingID;
            string strContactId = "";
            Contact objProvider = objProviders.FirstOrDefault( i => i.RecruitingID__c == dblRecrID );
            if( objProvider != null )
                strContactId = objProvider.Id;
            else // skip if provider was not found
            {
                tbStatus.Text = string.Concat( tbStatus.Text, "\r\nCould not find recruiting ID ", objNewCandidate.Contact__c, " for ", objNewCandidate.Name );
                iSkipped++;
                //continue;
                bSkipThisRecord = true;
                return objNewCandidate;
            }
            objNewCandidate.Contact__c = strContactId;

            // correct the record name using the Contact and Facility names in order to avoid duplicates
            objNewCandidate.Name = string.Concat( objProvider.Name, " at ", objFacility.Name ).Left( 80 );

            // if candidate record name is duplicate (due to facilities with same name), make it different
            // by appending the facility short name and/or site code instead
            Candidate__c objDupeFound = objCandidates.FirstOrDefault( c => c.Name.Equals( objNewCandidate.Name ) );
            if( objDupeFound != null )
                if( objFacility.Short_Name__c != null )
                    objNewCandidate.Name = string.Concat( objProvider.Name, " at ", objFacility.Short_Name__c, "-", objFacility.Site_Code__c ).Left( 80 );
                else
                    objNewCandidate.Name = string.Concat( objProvider.Name, " at ", objFacility.Site_Code__c ).Left( 80 );

            //
            // The code above probably could be changed to append the site code AFTER the facility name
            // if the limit of 80 characters allows
            //

            // if the facility's region is the same as the provider's owning region, turn on the owning region flag
            if( objFacility.Sub_Region__r != null && objFacility.Sub_Region__r.SubRegionCode__c != null )
                objNewCandidate.Owning_Region__c =
                    ( objFacility.Sub_Region__r.SubRegionCode__c.Equals( objProvider.Owning_Region__c ) );
            else
                objNewCandidate.Owning_Region__c = false;
            objNewCandidate.Owning_Region__cSpecified = true;

            if( (bool) objNewCandidate.Owning_Region__c )
            {
                string strProviderOwningStage = objProvider.Owning_Candidate_Stage__c;
                if( strProviderOwningStage != null )
                {
                    if( strProviderOwningStage.Equals( "Credentialing SAH" ) )
                        strProviderOwningStage = "Credentialing - SAH";
                    if( strProviderOwningStage.Equals( "Credentialing SAP" ) )
                        strProviderOwningStage = "Credentialing - SAP";
                    if( strProviderOwningStage.Equals( "Credentialing SAR" ) )
                        strProviderOwningStage = "Credentialing - SAR";
                }

                // check whether the candidate stage is higher than the current stage in the provider record
                CandidateStage eProviderStage = 0;
                if( strProviderOwningStage != null )
                    eProviderStage = (CandidateStage) Enum.Parse( typeof( CandidateStage )
                                , strProviderOwningStage.Replace( ' ', '_' ).Replace( '-', '_' ) );

                CandidateStage eCandidateStage = (CandidateStage) Enum.Parse( typeof( CandidateStage )
                                , objNewCandidate.Candidate_Stage__c.Replace( ' ', '_' ).Replace( '-', '_' ) );

                if( eProviderStage < eCandidateStage || objProvider.Owning_Candidate_Stage__c == null )
                    // set the owning stage if candidate stage is higher
                    objProvider.Owning_Candidate_Stage__c = objNewCandidate.Candidate_Stage__c;

                // check whether the candidate status is higher than the current status in the provider record
                CandidateStatus eProviderStatus = 0;
                if( objProvider.Owning_Candidate_Status__c != null )
                    Enum.TryParse<CandidateStatus>(
                            objProvider.Owning_Candidate_Status__c.Replace( ' ', '_' ).Replace( "(", "" ).Replace( ")", "" )
                            , out eProviderStatus );
//.........这里部分代码省略.........
开发者ID:fmendes,项目名称:SalesForceCSharpAPI,代码行数:101,代码来源:DataLoader.cs

示例3: TestAllCustomerPropertiesById

 private void TestAllCustomerPropertiesById(Customer c, DataRow dr)
 {
     Assert.That(c.FirstName, Is.EqualTo(dr.ConvertTo<string>(nameof(c.FirstName))));
     Assert.That(c.LastName, Is.EqualTo(dr.ConvertTo<string>(nameof(c.LastName))));
     Assert.That(c.Email, Is.EqualTo(dr.ConvertTo<string>(nameof(c.Email))));
     Assert.That(c.PhoneNumber, Is.EqualTo(dr.ConvertTo<string>(nameof(c.PhoneNumber))));
     Assert.That(c.Address, Is.EqualTo(dr.ConvertTo<string>(nameof(c.Address))));
     Assert.That(c.City, Is.EqualTo(dr.ConvertTo<string>(nameof(c.City))));
     Assert.That(c.State, Is.EqualTo(dr.ConvertTo<string>(nameof(c.State))));
     Assert.That(c.Zip, Is.EqualTo(dr.ConvertTo(nameof(c.Zip), 0)));
     Assert.That(c.RewardsPoints, Is.EqualTo(dr[nameof(c.RewardsPoints)]
         == DBNull.Value ? null : dr[nameof(c.RewardsPoints)]));
 }
开发者ID:Scotty-Hudson,项目名称:DotNetDataExtensions,代码行数:13,代码来源:UnitTests.cs


注:本文中的System.Data.DataRow.ConvertTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。