public void PopulateFrom(Provider p)
 {
     this.address_match_policy_cd_id.Value = GSC(SystemCodeType.ADDRESS_MATCH_POLICY, p.AddressMatchPolicy);
     this.agency_email_from_address.Value = p.AgencyEmailFromAddress;
     this.coverage_level_cd_id.Value = GSC(SystemCodeType.COVERAGE_LEVEL, p.CoverageLevel);
     this.dupe_auth_policy_cd_id.Value = GSC(SystemCodeType.DUPE_AUTH_POLICY, p.DupeAuthPolicy);
     this.expedite_fee_policy_cd_id.Value = GSC(SystemCodeType.EXPEDITE_FEE_POLICY, p.ExpeditedFeePolicy);
     this.expedited_order_criteria_cd_id.Value = GSC(SystemCodeType.EXPEDITE_FEE_POLICY, p.ExpeditedOrderCriteria);
     this.is_applicant_data_required.Value = p.IsApplicantDataRequired;
     this.is_batch_required_for_shipping.Value = p.IsBatchRequiredForShipping;
     this.is_close_inhouse.Value = p.IsCloseInhouse;
     this.is_credentialed.Value = p.IsCredentialed;
     this.is_exempt_from_dst.Value = p.IsExemptFromDST;
     this.is_legacy_location.Value = p.IsLegacyLocation;
     this.is_pos_id_required.Value = p.IsPosRequired;
     this.is_premium.Value = p.IsPremium;
     this.is_process_inhouse.Value = p.IsInhouse;
     this.is_process_mail_inhouse.Value = p.IsProcessMailInhouse;
     this.is_requires_quality_control.Value = p.IsRequiresQC;
     this.is_send_agency_email_via_vitalchek_servers.Value = p.IsSendAgencyEmailViaVitalchekServers;
     this.is_shipping_signature_required.Value = p.IsShippingSigRequired;
     this.latest_delivery_time.Value = p.LatestDeliveryTime;
     //this.location_code
     this.max_closeout_items.Value = p.MaxCloseoutItems;
     this.max_copies_per_line_item.Value = p.MaxCopiesPerLineItem;
     this.max_copies_per_order.Value = p.MaxCopiesPerOrder;
     this.max_copies_per_order_override_cap.Value = p.MaxCopiesPerOrderOverrideCap;
     this.max_days_between_closeout.Value = p.MaxDaysBetweenCloseout;
     this.max_line_items_per_order.Value = p.MaxLineItemsPerOrder;
     this.max_line_items_per_order_pos.Value = p.MaxLineItemsPerOrderPos;
     this.max_order_amount.Value = p.MaxOrderAmount;
     this.max_processing_time.Value = p.MaxProcessingTime;
     this.min_processing_time.Value = p.MinProcessingTime;
     this.name_match_policy_cd_id.Value = GSC(SystemCodeType.ADDRESS_MATCH_POLICY, p.NameMatchPolicy);
     this.order_delivery_method_cd_id.Value = GSC(SystemCodeType.SYSTEM, p.DeliveryMethod);
     this.password_expiration_days.Value = p.PasswordExpirationDays;
     this.pos_session_expiration_minutes.Value = p.PosSessionExpirationMinutes;
     //this.processing_time_rule_cd_id.Value = GSC(SystemCodeType.
     this.processing_time_unit_cd_id.Value = GSC(SystemCodeType.TIME_UNIT, p.ProcessingTimeUnit);
     this.receipt_print_rule_cd_id.Value = GSC(SystemCodeType.RECEIPT_PRINT_EVENT_RULE, p.ReceiptPrintRule);
     this.time_zone_cd_id.Value = GSC(SystemCodeType.TIME_ZONE, p.TimeZone);
     this.user_id_logon_tries.Value = p.UserIdLogonTries;
     this.user_session_expiration_minutes.Value = p.UserSessionExpirationMinutes;
     this.acct_status_cd_id.Value = GSC(SystemCodeType.BU_ACCT_STATUS_CODE, p.Status);
     this.acct_type_cd_id.Value = GSC(SystemCodeType.ACCOUNT_TYPE, p.AccountType);
     this.business_unit_code.Value = p.Code;
     this.business_unit_name.Value = p.Name;
     this.business_unit_type_cd_id.Value = GSC(SystemCodeType.BUSINESS_UNIT_TYPE, p.BusinessType);
     this.business_unit_url.Value = p.Url;
     this.delivery_system_cd_id.Value = GSC(SystemCodeType.SYSTEM, p.DeliverySystem);
     this.display_rank.Value = p.DisplayRank;
     this.end_date.Value = p.DisableDate;
     this.start_date.Value = p.EnableDate;
 }
        public void GenerateScript(Provider p)
        {
            string now = DateTime.Now.ToShortDateString().Replace("/", "-");
            _provider = p;
            velocityCtx = new NVelocity.VelocityContext();
            _coverageAreas.Clear();
            _usedCodes.Clear();
            _sqlEntities.Clear();
            _baseProducts.Clear();
            _services.Clear();
            _feeScheduleMap.Clear();
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();

            velocityCtx.Put("version", Kernel.VERSION);
            velocityCtx.Put("username", System.Security.Principal.WindowsIdentity.GetCurrent().Name);
            velocityCtx.Put("produced_date", DateTime.Now.ToString());
            velocityCtx.Put("option_reportEnabled", ReportEnabled.ToString());
            velocityCtx.Put("option_writeSqlScriptToReport", WriteSqlScriptToReport);
            velocityCtx.Put("option_WriteRadScriptToReport", WriteRadScriptToReport);
            velocityCtx.Put("option_IncludeUnreferencedSqlVariables", IncludeUnreferencedSqlVariables);
            velocityCtx.Put("option_UseMarkdown", UseMarkdown);
            velocityCtx.Put("rad_script", HttpUtility.HtmlEncode(ScriptExpression.Trim()));
            velocityCtx.Put("num_validation_errors", DomainEntityValidations.Count);

            List<HtmlTable> entityTables = RenderReportEntities();
            using (MemoryStream ms = new MemoryStream())
            {
                HtmlTextWriter htmlWriter = new HtmlTextWriter(new StreamWriter(ms));
                foreach (var table in entityTables)
                {
                    table.RenderControl(htmlWriter);
                    htmlWriter.WriteBreak();
                }
                htmlWriter.Flush();
                StreamReader reader = new StreamReader(ms);
                ms.Position = 0;
                string x = reader.ReadToEnd();
                velocityCtx.Put("entity_tables", x);
            }

            if (DomainEntityValidations.Count == 0)
            {
                Gather();
                string sql = GenerateSql();
                string sqlFilename = Path.Combine(Path.GetTempPath(), _provider.Name + " " + now + ".sql");
                StreamWriter sqlWriter = new StreamWriter(sqlFilename);
                velocityCtx.Put("sql_script", HttpUtility.HtmlEncode(sql));
                velocityCtx.Put("sql_validation_errors", _sqlValidations.Count);
                sqlWriter.WriteLine(sql);
                sqlWriter.Flush();
                sqlWriter.Close();
                //Process.Start(sqlFilename);
            }

            foreach (var qpi in _popups.Values)
            {
                qpi.Content = qpi.Content
                    .Replace("'", "''")
                    .Replace("\r\n", "<br />")
                    .Replace("\r", "<br />")
                    .Replace("\n", "<br />");
            }

            watch.Stop();
            velocityCtx.Put("processing_time", watch.Elapsed.TotalMilliseconds.ToString() + "ms");
            velocityCtx.Put("qtip_popups", _popups.Values);

            string reportFilename = Path.Combine(Path.GetTempPath(), _provider.Name + " " + now + ".html");
            StreamWriter reportWriter = new StreamWriter(reportFilename);
            Velocity.Evaluate(velocityCtx, reportWriter, null, Resource1.Report);
            reportWriter.Close();

            if (ReportEnabled)
                Process.Start(reportFilename);
        }
 public void PopulateFrom(Provider p)
 {
     this.end_date.Value = p.DisableDate;
     this.first_name.Value = null;
     this.is_internal.Value = false;
     this.start_date.Value = p.EnableDate;
     //this.email_address.Value
     //this.is_supervisor.Value = 0;
     //this.last_name = null;
     //this.last_name_2 = null;
     //this.middle_name = null;
     //this.party_code
     //this.party_type_cd_id
     //this.profile_type_cd_id
     //this.suffix
     //this.title_cd_id
 }