Saturday 25 April 2015

Addition of two matrix in c# asp.net.


In the program below I have written the addition of two matrix in c#. This program will ask to enter the number of row and column of both matrix. Then it will ask enter all elements of both matrix one by one. And  then it will print the both matrx and thrid  matrxi as a sum of both.

Source code:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Globalization;
using System.Data;

namespace ConsoleDemoApp
{
    class MatrxAddition
    {
        /* program to write a exception in c# */

        public static void Main(string[] args)
        {
            int row, col, i, j;
            Console.Write("Enter Number Of Rows And Columns Of Matrices A : ");
            row = Convert.ToInt16(Console.ReadLine());
            Console.Write("Enter Number Of Rows And Columns Of Matrices B : ");
            col = Convert.ToInt16(Console.ReadLine());
            int[,] A = new int[row, col];
            Console.Write("\nEnter The First Matrix : \n");
            for (i = 0; i < row; i++)
            {
                for (j = 0; j <  col; j++)
                {
                    A[i, j] = Convert.ToInt16(Console.ReadLine());
                }
            }

            int[,] B = new int[row, col];
            Console.Write("\nEnter The Second Matrix:\n");
            for (i = 0; i < row; i++)
            {
                for (j = 0; j <  col; j++)
                {
                    B[i, j] = Convert.ToInt16(Console.ReadLine());
                }
            }
            //Console.Clear();
            Console.WriteLine("\nMatrix A : ");
            for (i = 0; i < row; i++)
            {
                for (j = 0; j <  col; j++)
                {
                    Console.Write(A[i, j] + "\t");

                }
                Console.WriteLine();
            }
            Console.WriteLine("\nMatrix B: ");
            for (i = 0; i < row; i++)
            {
                for (j = 0; j <  col; j++)
                {
                    Console.Write(B[i, j] + "\t");

                }
                Console.WriteLine();
            }
            int[,] C = new int[10, 10];
            for (i = 0; i < row; i++)
            {
                for (j = 0; j <  col; j++)
                {
                    C[i, j] = A[i, j] + B[i, j];
                }
            }
            Console.Write("\nSum Matrix :\n");
            for (i = 0; i < row; i++)
            {
                for (j = 0; j <  col; j++)
                {
                    Console.Write(C[i, j] + "\t");

                }
                Console.WriteLine();
            }
            Console.Read();
        }
    }
}


Output



Friday 24 April 2015

How to send SMS using SQL Server ? OR How to send SMS using SQl store Procedure ?

Here I have written a sql store Procedure to send SMS using Thrid pary api.

Step 1 :-  Configure   sp_configure to enable Ole Automation Procedures
Step 2 :- Create  sp_OACreate 
Step 3 :- Open  sp_OAMethod
Step 4 :-  Send  sp_OAMethod
Step 5 :-  Get Error using  sp_OAGetErrorInfo
Step 6 :-  Destroy Object using   sp_OADestroy
Step 7 :-  Configure   sp_configure to disable Ole Automation Procedures
           

USE [DemoDb]
GO
/****** Object:  StoredProcedure [PWS].[Sms_Sender]    Script Date: 25-04-2015 12:14:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [PWS].[Sms_Sender] 
 ( @MobileNo bigint, 
    @smstext as varchar(300))
as 
BEGIN 
   Declare @obj int,@Result int 
   Declare @sUrl as varchar(500) 
   DECLARE @errorSource VARCHAR(8000)
   DECLARE @errorDescription VARCHAR(8000) 
   DECLARE @sResponse VARCHAR(50)

   
     if((SELECT value FROM sys.configurations where name='show advanced options')=0)
      begin 
      Exec sp_configure 'show advanced options', 1;
      RECONFIGURE with override;
      end

     if((SELECT value FROM sys.configurations where name='Ole Automation Procedures')=0)
     begin 
     Exec sp_configure 'Ole Automation Procedures', 1;
     RECONFIGURE with override;
     end
--exec [PWS].[sp_Enable_OleAutomation] 

    EXEC @Result = sp_OACreate 'WinHttp.WinHttpRequest.5.1', @obj OUT
   
set @sUrl='http://enterprise.smsgupshup.com/GatewayAPI/rest?method=sendMessage&send_to=#MobNo#&msg=Test&userid=userId&password=*******
&msg=#Msg#&v=1.1&msg_type=TEXT&auth_scheme=PLAIN'

   set @sUrl=REPLACE(@sUrl,'#MobNo#',@MobileNo) 
   set @sUrl=REPLACE(@sUrl,'#Msg#',@smstext) 
   EXEC @Result = sp_OAMethod @obj, 'Open', NULL, 'GET', @sUrl, false 
   EXEC @Result = sp_OAMethod @obj, 'send' 
  select @obj

   if @Result <> 0 
       Begin 
       EXEC sp_OAGetErrorInfo @obj, @errorSource OUTPUT, @errorDescription OUTPUT
       SELECT [Error Source] = @errorSource, [Description] = @errorDescription
       Raiserror('sp_OAMethod Send FAILED!', 16, 1) 
      end 
  else 
      Begin
      EXEC @Result = sp_OAGetProperty @obj,'responseText', @sResponse OUT 
      end
 Exec sp_OADestroy @obj

if((SELECT value FROM sys.configurations where name='Ole Automation Procedures')=1)
    begin 
    Exec sp_configure 'Ole Automation Procedures',0;
    RECONFIGURE;
    end


    if((SELECT value FROM sys.configurations where name='show advanced options')=1)
begin 
Exec sp_configure 'show advanced options', 0;
RECONFIGURE;
end

end