Use this space to put some text. Update this text in HTML

468x60 banner ad

Advertise with Us

Powered by Blogger.

Friday, 11 March 2016

Custom Datetime String Format

We need to show the date 07/03/2016 as 7th March, 2016.
Custom  Date Format like 7th March, 2016.
we want to denote the number position in an ordered sequence such as 1st, 2nd, 3rd, 4th...etc.

 Create a ASPX page and name it custom-datetime-string-format.aspx, in the page we take a Label Control and name it to lblInvoiceDateData.

Example:
custom-datetime-string-format.aspx Page



<form id="form1" runat="server">
<table>
<tr>
  <td width="100%" valign="top" align="right">
     <span style="font-family: Calibri; font-size: 18px; font-weight: bold;">
       DATE <asp:Label ID="lblInvoiceDateData" runat="server"></asp:Label>
     </span>
  </td>
</tr>
</table>
</form>

custom-datetime-string-format.aspx.cs Page



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Test_custom_datetime_string_format : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
          
            ViewState["Invoice_ID"] = 2;

            //Master Details
            FillForm();
        }
    }
    //Fill Previous data for update
    private void FillForm()
    {
        clsCustomDatetime objInv = new clsCustomDatetime();
        DataSet ds = new DataSet();

        try
        {
            objInv.Invoice_ID = Convert.ToInt32(ViewState["Invoice_ID"]);
            ds = objInv.InvoiceReport();

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    //need to show the date 03/03/2012 as March 3rd,2012 etc
                    //lblInvoiceDateData.Text = dr["Invoice_Date"].ToString();
                    DateTime date = Convert.ToDateTime(dr["Invoice_Date"].ToString());
                    var formattedDate = string.Format(new MyCustomDateProvider(), "{0}", date);
                    lblInvoiceDateData.Text = formattedDate;

               }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            ds = null;
            objInv = null;
        }
    }
    #region Start date custom format 07/03/2012 to  7th March,2012 in c#
    public class MyCustomDateProvider : IFormatProvider, ICustomFormatter
    {
        public object GetFormat(Type formatType)
        {
            if (formatType == typeof(ICustomFormatter))
                return this;

            return null;
        }

        public string Format(string format, object arg, IFormatProvider formatProvider)
        {
            if (!(arg is DateTime)) throw new NotSupportedException();

            var dt = (DateTime)arg;

            string suffix;

            if (new[] { 11, 12, 13 }.Contains(dt.Day))
            {
                suffix = "th";
            }
            else if (dt.Day % 10 == 1)
            {
                suffix = "st";
            }
            else if (dt.Day % 10 == 2)
            {
                suffix = "nd";
            }
            else if (dt.Day % 10 == 3)
            {
                suffix = "rd";
            }
            else
            {
                suffix = "th";
            }

            return string.Format("{1}{2} {0:MMMM}, {0:yyyy}", arg, dt.Day, suffix);
        }
    }
    #endregion End date custom format 07/03/2012 to 7th March,2012 in c#
}

Result

DATE 7th March, 2016
  


Wednesday, 9 March 2016

Windows Popping Enter Network Credentials

Problem: I have 8 computers and 5 laptop on a home network and all of a sudden my laptop cannot connect to the PC with the printer attached to it. Every time I try to print I get an error message so I checked and when I try to access the PC from my laptop through the network it keeps asking me to enter a password.



The Windows 8.1 machine was the problem. I went to the

CONTROL PANEL, then to
NETWORK AND INTERNET, then to
NETWORK AND SHARING, then to

ADVANCED SHARING SETTINGS, then



HOME GROUP CONNECTIONS - I changed it from the "recommended" setting of
ALLOW WINDOWS TO MANAGE CONNECTS



and instead choose
USE USER ACCOUNTS AND PASSWORDS TO CONNECT TO OTHER COMPUTERS

Instant SUCCESS as all the other computers share directories were instantly available.






Difference between Protected and Internal

What the difference between protected and internal? What about "protected internal"?


Protected:
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

Internal:
The type or member can be accessed by any code in the same assembly, but not from another assembly.

Protected Internal:
The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly. 




Saturday, 5 March 2016

What are Access Modifiers in C-Sharp


Access modifier keywords used to specify declare accessibility of a member or a type.

1)      Access Modifiers

Public

The type or member can be accessed by any other code in the same assembly or another assembly that references it.

      Private
 
The type or member can be accessed only by code in the same class or struct.

      Protected

The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

      Internal

The type or member can be accessed by any code in the same assembly, but not from another assembly.

    Protected Internal

The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.


Multiple Inheritance in C-Sharp


Why .Net not support multiple and hybrid inheritance?

In multiple inheritance, A class is derived more than one base class. This means both base class has same functionality then it is quite difficult to derived class which base class functionality is it perform or not. It is also called ambiguity problem. Due to that reason .Net not support multiple inheritance.  





Friday, 4 March 2016

inheritance in C-Sharp


Inheritance
There are four type of inheritance.
1.      Single inheritance
2.      Multi-level/ harirachal inheritance
3.      Multiple inheritance
4.      Hybrid inheritance
Single inheritance
Single inheritance is an entity through which drive class access all the functionality of base class. And derived class has also an extra functionality.

Multi-level/harirachal inheritance
Multilevel inheritance is an entity through which derived class access all the functionality of base class. And derived class has also an extra functionality. And that derived class is accessed with another derived class and so on.

Multiple inheritance
There are two or more base class. A derived can class access the functionality of two more base class and derived class has also an extra functionality.

Hybrid inheritance
 It is multiple inheritance with any one or mixed that is hybrid.