27 Mayıs 2017 Cumartesi

Dependency Injection: What a Cool Phrase :)


If you want to change your business work flow on air you can use dependency injection in your programs. You can decide which class to use for your customers requirement dynamically via dependency injection method. Here is a sample code for dependency injection. 2 payment methods and 2 record saving methods implemented.



  interface IPay
    {
        void Pay(string amount);
    }

    class CreaditCardPay : IPay 
    {
        public void Pay(string amount)
        {
            Console.WriteLine("CreaditCardPay:" + amount);
        }
    }

    class CashPay : IPay
    {
        public void Pay(string amount)
        {
            Console.WriteLine("CashPay:" + amount);
        }
    }
--------------------------------------------------------------

    interface ISave
    {
         void Save(string amount);
    }

    class FileSave : ISave
    {
        public void Save(string Message)
        {
            Console.WriteLine("FileSave:" + Message);
        }
    }

    class DBSave : ISave 
    {
       public void Save(string Message)
        {
            Console.WriteLine("DBSave:" + Message);
        }
    }
------------------------------------------------------------------------
  <appSettings>
   
   
 
--------------------------------------------------------------------------
    class PrepareClass
    {
       public IPay createPayer()
        {
            IPay payer = null;
            if (ConfigurationSettings.AppSettings["pay"].Equals("CreaditCard"))
                payer = new CreaditCardPay();
            else
                payer = new CashPay();
            
            return payer;
        }


       public ISave createSaver()
        {
            ISave saver = null;

            if (ConfigurationSettings.AppSettings["log"].Equals("DB"))
                saver = new DBSave();
            else
                saver = new FileSave();

            return saver;

        }
    }
-------------------------------------------------------------------
    class Program
    {
        static void Main(string[] args)
        {
            PrepareClass p = new PrepareClass();
            ISave lg = p.createSaver();
            lg.Save("100$");

            IPay m = p.createPayer();
            m.Pay("100$");

           
        }
    }

3 Mayıs 2017 Çarşamba

How to migrate data from Local SqlServer to the Azure SqlServer DB via SSIS?

If you want to transfer your local SqlServer Data to the azure database you can use SSIS (Sql Server Integration Services). I like SSIS, it is a user friendly way of migration. I tried to explain how to do that below: 

1. SqlServer -> Select your DB -> Right Click-> Tasks -> Export Data



2. Next


3. Select your server and db 

4. Get your Azure Server Name from Azure Databases Page


 5. Write your server name and select your database

In this step you will get the errror below:

Firewall check failed. Cannot open server 'XXXXXXXXX' requested by the login. Client with IP address 'XXXXXXXXX' is not allowed to access the server. To enable access, use the SQL Azure Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.

In that case you need to apply the following steps to add IP of your Azure server to the firewall:

a. Click to "Set Server firewall" in DB page


Write your rule_name, and IP interval in the firewall settings page.

Wait 5 minutes and then try step 5 again.


 6. Next

7. Select the tables you want to migrate


8. Next


That's all :)




2 Şubat 2010 Salı

28 Ocak 2010 Perşembe

Disable Web Page Auto Scroll Up

If you have a long web page and when you are at the end of the page, whenever a postback is occured it will scroll up to beginning of the page.

To avoid this irritating behaviour, paste the follaowing line to your page specifications:

<%@ Page MaintainScrollPositionOnPostback="True" %>

7 Ocak 2010 Perşembe

A problem with publishing web applications in .NET ?

When I tried to publish my web application I saw the following exception:

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

A name was started with an invalid character. Error processing resource 'file://server-name/f$/Intranet/Web/Project
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Project"%> -^ 
 Solution:  
When multiple versions of ASP.NET are installed on a computer, ASP.NET is said to be running side-by-side. In this setup, Internet Information Services (IIS) needs to know which version of the ASP.NET ISAPI (aspnet_isapi.dll) should process a page in an ASP.NET application. ASP.NET IIS Registration Tool (Aspnet_regiis.exe) allows an administrator or installation program to easily update the script maps for an ASP.NET application to point to the ASP.NET ISAPI version that is associated with the tool.

How to use the tool?

---Open command prompt , go to the following path: 
%windir%\Microsoft.NET\Framework\v2.0.50727
 ---run aspnet_regiis -ua 
---when that finishes run aspnet_regiis -i

---and browse your application. :) 
Yours Sincerely...

Querying hierarchical relationships between Oracle DB records...

The start with .. connect by clause make us to select data which has a hierarchical relationship.
For example in  Country -> city -> street or Manager -> Employee relations...


Hierarchical Data Structure



PositionsTable



This clause runs recursively, starts with a specified point and returns all the chain of records ...
Query:
SELECT * FROM POSITIONS
START WITH ID = 9
CONNECT BY PRIOR MANAGER_ID =ID;

Result Of The Query:

ID POSITION                        MANAGER_ID
---  -------------------------------    ----------------------
9   DOCUMENTER                 4

4   IT TEAM LEADER             3

3   PROJECT MANAGER       1

1   SOFTWARE DIRECTOR   0


5 Ocak 2010 Salı

Textbox does not fire TextChanged Event in User Controls...

TextChanged event is fired when the mouse leaves the textbox. This means that to fire that event you have to click on another object in the page after typing a character . To get rid of this extra click you can do this:

 protected void Page_Load(object sender, EventArgs e)
{
       if (!IsPostBack)
       {
         TextBox1.Attributes.Add("OnKeyUp", "javascript:myPostBack()");
        }
}

and paste the following code to your html file under the head tag:

< script type="text/javascript" >
function myPostBack()
{  
  __doPostBack("","");
}
< /script >



After that in every keystroke, TextChanged event will be fired by textbox...

Yours sincerely