Joseph Michael Pesch
VP Programming

JavaScript Payment Calculator

by 17. September 2010 18:33

double xpmt = pv * (rate / (1 - Math.Pow(1 + rate, -nper)));

Tags:

[None]

HTML JavaScript Web Service Call

by 17. September 2010 14:56

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

  <title></title>

  <script type="text/javascript">

    function MakeSoapCall(WebServiceUrl, Namespace, WebMethod, WebMethodParams) {

      var xmlHttp;

      function SoapCall() {

        // creatng the xmlHttp object

        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

        // Calling the web service using post and true means asynchronous call

        // WebServiceUrl Sample: http://localhost/MyWebService.asmx

        xmlHttp.open("post", WebServiceUrl, true);

        // Setting the request header to let the web service identify the soap request we would be sending

        xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

        // SoapAction Sample: http://MyNameSpace.com/MyWebMethod – name of the webmethod

        // Example: [WebService(Namespace = "http://MyNameSpace.com/")] applied to our web service class

        xmlHttp.setRequestHeader("SOAPAction", "http://" + Namespace + "/" + WebMethod);

        xmlHttp.onreadystatechange = doUpdate;

        // setting the soap request body

        var soapRequest = "<?xml version='1.0' encoding='utf-8'?>" +

          "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +

          " xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +

          "<soap:Body>" +

          "<" + WebMethod + " xmlns='http://" + Namespace + "/'>" +

          WebMethodParams +

          "</" + WebMethod + ">" +

          " </soap:Body>" +

          "</soap:Envelope>";

        // send the request

        document.all('WebMethodParamsTextArea').value = soapRequest;

        xmlHttp.send(soapRequest);

        return false;

      }

      function doUpdate() {

        debugger;

        if (xmlHttp.readyState == 4) {

          var responseXMLResult = xmlHttp.responseXML;

          // var result = responseXMLResult.lastChild.nodeTypedValue;

          alert(responseXMLResult.xml);

        }

      }

      SoapCall();

    }

   

  </script>

</head>

<body>

  <form id="form1" runat="server">

  <div style="font-family: Calibri;">

    <table>

      <tr>

        <td>

          Web Service URL:

        </td>

        <td>

          <input type="text" id="WebServiceUrlControl" size="100" value="http://www.27seconds.com/Holidays/US/Dates/USHolidayDates.asmx" />

        </td>

      </tr>

      <tr>

        <td>

          Namespace:

        </td>

        <td>

          <input type="text" id="NamespaceControl" size="100" value="www.27seconds.com/Holidays/US/Dates" />

        </td>

      </tr>

      <tr>

        <td>

          Web Method:

        </td>

        <td>

          <input type="text" id="WebMethodControl" size="100" value="GetChristmasDay" />

        </td>

      </tr>

      <tr>

        <td valign="top">

          Web Method Paramaters:

        </td>

        <td>

          <textarea id="WebMethodParamsTextArea" rows="5" cols="75">

<year>2010</year>

          </textarea>

        </td>

      </tr>

      <tr>

        <td>

        </td>

        <td>

        </td>

      </tr>

    </table>

    <br />

    <input type="button" value="Make Soap Call" onclick="MakeSoapCall(document.all('WebServiceUrlControl').value, document.all('NamespaceControl').value, document.all('WebMethodControl').value, document.all('WebMethodParamsTextArea').value);" />

  </div>

  </form>

</body>

</html>

 

 

Tags:

HTML | JavaScript

iTextSharp Read Text from PDF

by 15. September 2010 18:14

Tags:

[None]

SQL Script to Document Database Roles/Permissions

by 11. September 2010 05:32

Script to Reverse Engineer SQL Server Object User Permissions

--Written By Bradley Morris (http://www.sql-server-performance.com/articles/dba/object_permission_scripts_p1.aspx)
--In Query Analyzer be sure to go to
--Query -> Current Connection Options -> Advanced (Tab)
--and set Maximum characters per column
--to a high number, such as 10000, so
--that all the code will be displayed.


DECLARE @DatabaseUserName [sysname]
SET @DatabaseUserName = 'user_name_goes_here'

SET NOCOUNT ON
DECLARE
@errStatement [varchar](8000),
@msgStatement [varchar](8000),
@DatabaseUserID [smallint],
@ServerUserName [sysname],
@RoleName [varchar](8000),
@ObjectID [int],
@ObjectName [varchar](261)

SELECT
@DatabaseUserID = [sysusers].[uid],
@ServerUserName = [master].[dbo].[syslogins].[loginname]
FROM [dbo].[sysusers]
INNER JOIN [master].[dbo].[syslogins]
ON [sysusers].[sid] = [master].[dbo].[syslogins].[sid]
WHERE [sysusers].[name] = @DatabaseUserName
IF @DatabaseUserID IS NULL
BEGIN
SET @errStatement = 'User ' + @DatabaseUserName + ' does not exist in ' + DB_NAME() + CHAR(13) +
'Please provide the name of a current user in ' + DB_NAME() + ' you wish to script.'
RAISERROR(@errStatement, 16, 1)
END
ELSE
BEGIN
SET @msgStatement = '--Security creation script for user ' + @ServerUserName + CHAR(13) +
'--Created At: ' + CONVERT(varchar, GETDATE(), 112) + REPLACE(CONVERT(varchar, GETDATE(), 108), ':', '') + CHAR(13) +
'--Created By: ' + SUSER_NAME() + CHAR(13) +
'--Add User To Database' + CHAR(13) +
'USE [' + DB_NAME() + ']' + CHAR(13) +
'EXEC [sp_grantdbaccess]' + CHAR(13) +
CHAR(9) + '@loginame = ''' + @ServerUserName + ''',' + CHAR(13) +
CHAR(9) + '@name_in_db = ''' + @DatabaseUserName + '''' + CHAR(13) +
'GO' + CHAR(13) +
'--Add User To Roles'
PRINT @msgStatement
DECLARE _sysusers
CURSOR
LOCAL
FORWARD_ONLY
READ_ONLY
FOR
SELECT
[name]
FROM [dbo].[sysusers]
WHERE
[uid] IN
(
SELECT
[groupuid]
FROM [dbo].[sysmembers]
WHERE [memberuid] = @DatabaseUserID
)
OPEN _sysusers
FETCH
NEXT
FROM _sysusers
INTO @RoleName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @msgStatement = 'EXEC [sp_addrolemember]' + CHAR(13) +
CHAR(9) + '@rolename = ''' + @RoleName + ''',' + CHAR(13) +
CHAR(9) + '@membername = ''' + @DatabaseUserName + ''''
PRINT @msgStatement
FETCH
NEXT
FROM _sysusers
INTO @RoleName
END
SET @msgStatement = 'GO' + CHAR(13) +
'--Set Object Specific Permissions'
PRINT @msgStatement
DECLARE _sysobjects
CURSOR
LOCAL
FORWARD_ONLY
READ_ONLY
FOR
SELECT
DISTINCT([sysobjects].[id]),
'[' + USER_NAME([sysobjects].[uid]) + '].[' + [sysobjects].[name] + ']'
FROM [dbo].[sysprotects]
INNER JOIN [dbo].[sysobjects]
ON [sysprotects].[id] = [sysobjects].[id]
WHERE [sysprotects].[uid] = @DatabaseUserID
OPEN _sysobjects
FETCH
NEXT
FROM _sysobjects
INTO
@ObjectID,
@ObjectName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @msgStatement = ''
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 193 AND [protecttype] = 205)
SET @msgStatement = @msgStatement + 'SELECT,'
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 195 AND [protecttype] = 205)
SET @msgStatement = @msgStatement + 'INSERT,'
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 197 AND [protecttype] = 205)
SET @msgStatement = @msgStatement + 'UPDATE,'
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 196 AND [protecttype] = 205)
SET @msgStatement = @msgStatement + 'DELETE,'
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 224 AND [protecttype] = 205)
SET @msgStatement = @msgStatement + 'EXECUTE,'
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 26 AND [protecttype] = 205)
SET @msgStatement = @msgStatement + 'REFERENCES,'
IF LEN(@msgStatement) > 0
BEGIN
IF RIGHT(@msgStatement, 1) = ','
SET @msgStatement = LEFT(@msgStatement, LEN(@msgStatement) - 1)
SET @msgStatement = 'GRANT' + CHAR(13) +
CHAR(9) + @msgStatement + CHAR(13) +
CHAR(9) + 'ON ' + @ObjectName + CHAR(13) +
CHAR(9) + 'TO ' + @DatabaseUserName
PRINT @msgStatement
END
SET @msgStatement = ''
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 193 AND [protecttype] = 206)
SET @msgStatement = @msgStatement + 'SELECT,'
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 195 AND [protecttype] = 206)
SET @msgStatement = @msgStatement + 'INSERT,'
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 197 AND [protecttype] = 206)
SET @msgStatement = @msgStatement + 'UPDATE,'
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 196 AND [protecttype] = 206)
SET @msgStatement = @msgStatement + 'DELETE,'
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 224 AND [protecttype] = 206)
SET @msgStatement = @msgStatement + 'EXECUTE,'
IF EXISTS(SELECT * FROM [dbo].[sysprotects] WHERE [id] = @ObjectID AND [uid] = @DatabaseUserID AND [action] = 26 AND [protecttype] = 206)
SET @msgStatement = @msgStatement + 'REFERENCES,'
IF LEN(@msgStatement) > 0
BEGIN
IF RIGHT(@msgStatement, 1) = ','
SET @msgStatement = LEFT(@msgStatement, LEN(@msgStatement) - 1)
SET @msgStatement = 'DENY' + CHAR(13) +
CHAR(9) + @msgStatement + CHAR(13) +
CHAR(9) + 'ON ' + @ObjectName + CHAR(13) +
CHAR(9) + 'TO ' + @DatabaseUserName
PRINT @msgStatement
END
FETCH
NEXT
FROM _sysobjects
INTO
@ObjectID,
@ObjectName
END
CLOSE _sysobjects
DEALLOCATE _sysobjects
PRINT 'GO'
END

Tags:

SQL Server

MS CRM SOAP Call to WebService

by 1. September 2010 21:55

This sample would link to Client Address Zip Code field (onchange event) to find the State that corresponds to the zip code entered.

function Address1_PostalCode_OnChange() {

  var xmlHttp;

  function SoapCall() {

    // Get zip code from screen field

    var oField = event.srcElement;

    var zipCode = "";

    if (typeof (oField) != "undefined" && oField != null) {

      zipCode = oField.value;

    }

 

    // creatng the xmlHttp object

    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

    // Calling the web service using post and true means asynchronous call

    xmlHttp.open("post", "http://mysite.com/ZipCountyWS/ZipCountyWS.asmx", true);

    // Setting the request header to let the web service identify the soap request we would be sending

    xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

    // http://mynamespace.com/GetStateAndCountyByZipCode – name of the webmethod

    //[WebService(Namespace = "http://mynamespace.com/")] which we had applied to our web service class

    xmlHttp.setRequestHeader("SOAPAction", "http://mynamespace.com/GetStateAndCountyByZipCode");

    xmlHttp.onreadystatechange = doUpdate;

    // setting the soap request body

    var soapRequest = "<?xml version='1.0' encoding='utf-8'?>" +

          "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +

          " xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +

          "<soap:Body>" +

          "<GetStateAndCountyByZipCode xmlns='http://mynamespace.com/'>" +

          "<ZipCode>" + zipCode + "</ZipCode> " +

          "</GetStateAndCountyByZipCode>" +

          " </soap:Body>" +

          "</soap:Envelope>";

    // send the request

    xmlHttp.send(soapRequest);

    return false;

  }

  function doUpdate() {

    debugger;

    if (xmlHttp.readyState == 4) {

      var responseXMLResult = xmlHttp.responseXML;

      var result = responseXMLResult.lastChild.nodeTypedValue;

      crmForm.address1_stateorprovince.value = '';

      crmForm.address1_county.value = '';

      if (result.indexOf('UNKNOWN') == -1) {

        crmForm.address1_country.value = 'USA';

      }

      else {

        alert('Please confirm zip code: '

        + crmForm.address1_postalcode.value

        + ' is valid, no county record was found.'

        + '\r'

        + 'If this is a valid zip code please alert the system administrator.'

      );

      }

      crmForm.address1_stateorprovince.value = result.split(':')[0];

      crmForm.address1_county.value = result.split(':')[1];

    }

  }

  SoapCall();

}

 

 

Tags:

JavaScript | MS CRM

MS CRM Get Picklist Values from Web Service SDK

by 1. September 2010 21:21

This code will get picklist name/value pairs from MS CRM.  Passing the Entity and Attribute being searched.

public sealed class AuthenticationType

{

    // Fields

    public const int AD = 0;

    public const int Passport = 1;

    public const int Spla = 2;

}

 

public static CrmService GetCrmService()

{

    CrmSdk.CrmAuthenticationToken token = new CrmSdk.CrmAuthenticationToken();

    token.AuthenticationType = AuthenticationType.AD;

    token.OrganizationName = Crm.Organization;

 

    CrmService crmService = new CrmService();

    crmService.Url = "http://CRM:80/MSCRMServices/2007/CrmService.asmx";

    crmService.CrmAuthenticationTokenValue = token;

    crmService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

 

    return crmService;

}

public static MetadataService GetMetadataService()

{

    CrmMeta.CrmAuthenticationToken token = new CrmMeta.CrmAuthenticationToken();

    token.AuthenticationType = AuthenticationType.AD;

    token.OrganizationName = Crm.Organization;

 

    MetadataService svc = new MetadataService();

    crmService.Url = "http://CRM:80/MSCRMServices/2007/MetadataService.asmx";

    svc.CrmAuthenticationTokenValue = token;

    svc.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

 

    return svc;

}

 

public class PickListOptions

{

    public PickListOptions() { }

    public string ItemLabel { get; set; }

    public string ItemValue { get; set; }

}

static public List<PickListOptions> GetPickList(string EntityName, string AttributeName)

{

    // Sample: EntityName = "new_debttransaction"; AttributeName = "new_stage"

    // Setup the request

    RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();

    // Entity reference

    attributeRequest.EntityLogicalName = EntityName;

    // Picklist attribute inside of entity

    attributeRequest.LogicalName = AttributeName;

    attributeRequest.RetrieveAsIfPublished = true;

    // Post the request

    RetrieveAttributeResponse response = (RetrieveAttributeResponse)GetMetadataService().Execute(attributeRequest);

    PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;

    // Convert the results

    List<PickListOptions> lst = new List<PickListOptions>();

    foreach (Option o in picklist.Options)

    {

    lst.Add(new PickListOptions() { ItemLabel = o.Label.LocLabels[0].Label

           , ItemValue = o.Value.Value.ToString() });

    }

    return lst;

}

 

 Note: You may receive a server error when attempting to run the code if you CRM user account does not have the appropriate security settings shown below.  Click the “Customization” tab, and then set the “Read” permissions on “Entity”, “Attribute” and “Relationship” as shown below:

Tags:

[None]