Tuesday, June 08, 2021

C#: create mural WS SOAP Request Example

 using System.Xml;

using System.Net;
using System.IO;

public static void CallWebService()
{
    var _url = "http://xxxxxxxxx/Service1.asmx";
    var _action = "http://xxxxxxxx/Service1.asmx?op=HelloWorld";

    XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
    HttpWebRequest webRequest = CreateWebRequest(_url, _action);
    InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

    // begin async call to web request.
    IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

    // suspend this thread until call is complete. You might want to
    // do something usefull here like update your UI.
    asyncResult.AsyncWaitHandle.WaitOne();

    // get the response from the completed web request.
    string soapResult;
    using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
    {
        using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
        {
            soapResult = rd.ReadToEnd();
        }
        Console.Write(soapResult);        
    }
}

private static HttpWebRequest CreateWebRequest(string url, string action)
{
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
    webRequest.Headers.Add("SOAPAction", action);
    webRequest.ContentType = "text/xml;charset=\"utf-8\"";
    webRequest.Accept = "text/xml";
    webRequest.Method = "POST";
    return webRequest;
}

private static XmlDocument CreateSoapEnvelope()
{
    XmlDocument soapEnvelopeDocument = new XmlDocument();
    soapEnvelopeDocument.LoadXml(@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/1999/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema""><SOAP-ENV:Body><HelloWorld xmlns=""http://tempuri.org/"" SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""><int1 xsi:type=""xsd:integer"">12</int1><int2 xsi:type=""xsd:integer"">32</int2></HelloWorld></SOAP-ENV:Body></SOAP-ENV:Envelope>");
    return soapEnvelopeDocument;
}

private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
    using (Stream stream = webRequest.GetRequestStream())
    {
        soapEnvelopeXml.Save(stream);
    }
}

Thursday, May 27, 2021

Calculate the difference between two dates - Javascript

 

Calculate the difference between two dates

There are multiple options to calculate the difference between dates.

1. getDateDiff

The easiest approach is to use getDateDiff. See this calculation:

getDateDiff('{date2}','{date1}','y')

In this calculation:

  • '{date2}'  = the variable name of the date field that contains the most recent date 
  • '{date1}' = the variable name of the date field with the older date
  • 'y' = the unit in which the difference is returned, i.e. 'years' in this case

Replace date1 and date2 with your own variable names. Make sure to keep the '{ }' (curly brackets surrounding the variables and the quotation marks). You can change 'y' to any unit you want to use:

  • Year: 'y'
  • Day: 'd'
  • Hour: 'h'
  • Minutes: 'm'


2. Date difference with Moment objects  

You can also create Moment objects and then calculate the difference:  

var admission = moment('{date1}', 'DD-MM-YYYY'); 
var discharge = moment('{date2}', 'DD-MM-YYYY');
discharge.diff(admission, 'days');

Instead of days you can also use: 'months' or 'years', or 'weeks' depending on what you want to measure. Check this template in the calculation helper.  


3. Date difference with today

You can also calculate the difference between now (today) and a date of choice, e.g. if you want to know how many days passed between today and the date the patient had their last visit:

var dateofvisit = moment('{visit}', 'DD-MM-YYYY');
var today = moment();
today.diff(dateofvisit, 'days');

In this calculation '{visit}' is the variable name of the date of the visit. Replace this variable with your own variable. Check this template in the calculation helper.

Note: This calculation will always update when you open the step where it is located in a record, since it calculates the actual moment at the time you are in that step.


4.  Converting number of days to number of weeks and days

If the number of days is known, it is possible to easily convert the number of days to the number of the weeks with the following template:

var amountWeeks = {amountDays}/7
var remainingDays = {amountDays}%7;
remainingDays = remainingDays.toFixed(0)
Math.floor(amountWeeks) + " weeks, " + (remainingDays) + " days"

In this calculation {amountDays} is the variable in which the number of days is collected. Test this template using calculation helper.


5. Calculating the difference between two dates using date and time field

If you are using a date and time field and would like to output the difference between the two dates in days, hours and minutes, use the following template:

var m1 = moment('{admission}', 'DD-MM-YYYY HH:mm'); 
var m2 = moment('{discharge}', 'DD-MM-YYYY HH:mm'); 
var m3 = m2.diff(m1,'minutes'); 
var m4 = m2.diff(m1,'h'); 


var numdays = Math.floor(m3 / 1440); 
var numhours = Math.floor((m3 % 1440) / 60); 
var numminutes = Math.floor((m3 % 1440) % 60); 
numdays + " day(s) " + numhours +"h " + numminutes +"m";

Monday, April 12, 2021

How to open Package manager Visual Studio .Net

 How to open Package manager Visual Studio .Net

Tools >>NuGet Package manager >> Package manager console 



Monday, February 22, 2021

How to Backup a table in SQL Server with SELECT INTO statement

 The first method involves using a SELECT INTO statement to create a copy of the table. The basic format of this statement is as follows:


SELECT *
INTO tableCopy
FROM originalTable


This statement WILL CREATE the table called tableCopy, thus you do not have to previously create it. Due to the fact that the statement is a SELECT statement, you can have WHERE clauses if you want to filter your data, or you can add specific columns into your table copy, if not the entire table should be backed up.

This form of backing up a table is not as the traditional method of backing up a database to a file, as it is just a simple way to create a copy of a table, in the same database, which you can later use in the form of a backup.

Advantages:

      • This method is by far the fastest. It can copy a very large number of rows very quickly.

Disadvantages:

      • Unfortunately, by using SELECT INTO, the major downfall is that it does not carry over the Keys, Indexes and Constraints of the table.
      • Also, the backup of the table is still stored in the database