Пример #1
0
 public static AccountInfo GetAccountInformation()
 {
     if (!IsLoggedIn())
         throw new ApplicationException("GetAccountInformation() was called out of "
             + "sequence. An authenticated Tessitura session is required.");
     string cacheKey = AccountInfoCacheKeyBase + "["
         + HttpContext.Current.Session[UsernameSessionKey].ToString() + "]";
     AccountInfo info = (AccountInfo)HttpContext.Current.Cache[cacheKey];
     if (info == null)
     {
         DataSet accountResults = unsecuredClient.GetAccountInfo(
             HttpContext.Current.Session[TessSessionKeySessionKey].ToString());
         DataRow data = accountResults.Tables["AccountInformation"].Rows[0];
         AccountPerson person1 = null;
         AccountPerson person2 = null;
         if (data["name_status"].ToString() != "Deceased"
             && data["lname"].ToString() != "")
         {
             char? gender = null;
             if (data["gender_1"] != DBNull.Value)
                 gender = Convert.ToChar(data["gender_1"]);
             person1 = new AccountPerson(
                 data["prefix"].ToString(),
                 data["fname"].ToString(),
                 data["mname"].ToString(),
                 data["lname"].ToString(),
                 data["suffix"].ToString(),
                 gender,
                 false);
         }
         if (data["name2_status"].ToString() != "Deceased"
             && data["lname2"].ToString() != "")
         {
             char? gender = null;
             if (data["gender_2"] != DBNull.Value)
                 gender = Convert.ToChar(data["gender_2"]);
             person2 = new AccountPerson(
                 data["prefix2"].ToString(),
                 data["fname2"].ToString(),
                 data["mname2"].ToString(),
                 data["lname2"].ToString(),
                 data["suffix2"].ToString(),
                 gender,
                 false);
         }
         AccountPersonPair personPair = null;
         if (person1 != null || person2 != null)
             personPair = new AccountPersonPair(person1, person2);
         info = new AccountInfo();
         info.CustomerNumber = Convert.ToInt32(data["customer_no"]);
         info.People = personPair;
         info.Address = data["street1"].ToString();
         info.SubAddress = data["street2"].ToString();
         info.City = data["city"].ToString();
         info.StateId = data["state"].ToString();
         info.PostalCode = data["postal_code"].ToString();
         info.SetNewCountryIdWithDesc(
             Convert.ToInt32(data["country"]), data["country_name"].ToString());
         string phone = data["phone"].ToString();
         info.EmailUnprotected = data["email"].ToString();
         // data["use_avs"]
         string phone2 = data["phone2"].ToString();
         string fax = data["fax_phone"].ToString();
         // data["esal1_desc"]
         // data["esal2_desc"]
         // data["lsal_desc"]
         info.BusinessTitle = data["business_title"].ToString();
         info.CanReceiveHtmlEmail = data["html_ind"].ToString() == "Y";
         // data["original_source"]
         info.WantsMail = data["mail_ind_id"] == DBNull.Value
                          || Convert.ToInt32(data["mail_ind_id"]) == 3;
         info.WantsPhone = data["phone_ind_id"] == DBNull.Value
                           || Convert.ToInt32(data["phone_ind_id"]) == 3;
         info.WantsEmail = data["emarket_ind_id"] == DBNull.Value
                           || Convert.ToInt32(data["emarket_ind_id"]) == 3;
         // data["email_inactive"]
         DataSet constituentResults = unsecuredClient.GetConstituentInfoEx(
             HttpContext.Current.Session[TessSessionKeySessionKey].ToString(), null);
         if (constituentResults.Tables["Addresses"].Rows.Count > 0)
         {
             foreach (DataRow address in constituentResults.Tables["Addresses"].Rows)
             {
                 if (address["primary_ind"].ToString() == "Y")
                 {
                     info.SetAddressTypeIdWithDesc(
                         Convert.ToInt32(address["address_type"]),
                         address["address_type_desc"].ToString());
                     break;
                 }
             }
         }
         int? phoneId = null;
         int? phone2Id = null;
         int? faxId = null;
         if (constituentResults.Tables["Phones"].Rows.Count > 0)
         {
             foreach (DataRow phoneNumber in constituentResults.Tables["Phones"].Rows)
             {
                 string number =
                     Regex.Replace(phoneNumber["phone"].ToString(), "[^0-9]", "");
                 if (!String.IsNullOrWhiteSpace(phone) && number == phone)
                     phoneId = Convert.ToInt32(phoneNumber["phone_no"]);
                 if (!String.IsNullOrWhiteSpace(phone2) && number == phone2)
                     phone2Id = Convert.ToInt32(phoneNumber["phone_no"]);
                 if (!String.IsNullOrWhiteSpace(fax) && number == fax)
                     faxId = Convert.ToInt32(phoneNumber["phone_no"]);
             }
             if (phoneId != null)
                 info.SetPhoneWithId(phone, phoneId);
             else
                 info.Phone = phone;
             if (phone2Id != null)
                 info.SetPhone2WithId(phone2, phone2Id);
             else
                 info.Phone2 = phone2;
             if (faxId != null)
                 info.SetFaxWithId(fax, faxId);
             else
                 info.Fax = fax;
         }
         HttpContext.Current.Cache.Insert(cacheKey, info, null,
             DateTime.MaxValue, new TimeSpan(0, 10, 0));
     }
     return info;
 }