Wednesday, December 10, 2014

find the different between 2 list

//DELETE
var oldDifferentList = oldSchool.Students.Except(newSchool.Students, new StudentComparer()).ToList();

//ADD 
var newDifferentList = newSchool.Students.Except(oldSchool.Students, new StudentComparer ()).ToList();

//EDIT

var statusChangedList = oldSchool.Students.Union(newSchool.Students).GroupBy(x => x.StudentID).Where(y => y.First().Status!= y.Last().Status).ToList();



//COMPARER
public class StudentComparer : IEqualityComparer<Student>
{
        public bool Equals(Student p1, Student p2)
        {
            if (Object.ReferenceEquals(p1, p2))
                return true;

            return p1.StudentID == p2.StudentID && p1.City == p2.City;
        }

        public int GetHashCode(Student obj)
        {
            if (Object.ReferenceEquals(obj, null)) return 0;

            int hashStudentID = obj.StudentID.GetHashCode();
            int hashCity = obj.City.GetHashCode();


            return hashStudentID ^ hashCity;
        }
}

Wednesday, December 3, 2014

Display Flexible Decimal Places

Display Flexible Decimal Places, e.g. 22.1000 will display as 22.1
.ToString("#,0.####")

Gridview > Text='<%# Eval("Price", "{0:#,0.####}")%>'

<asp:BoundField DataField="Price" HeaderText="Price" DataFormatString="{0:#,0.####}" />
<asp:BoundField DataField="EDate" DataFormatString="{0:dd-MM-yyyy}" HeaderText=" Date" />
<asp:BoundField DataField="EDate" DataFormatString="{0:HH:mm}" HeaderText="Time" />

Thursday, October 23, 2014

Grid view Dynamically

2 Method to Create Grid view Dynamically
Postback will disappear , Every postback need to create again.

a. Generate GridView

public
GridView GenerateGridView(int m_instanceCount)
{
    GridView newGridView = new GridView();
    newGridView.ID = GvBroadcastTitle.ID + m_instanceCount;
    newGridView.CssClass = "tabsummary";
    newGridView.GridLines = GridLines.None;
    newGridView.AlternatingRowStyle.CssClass = "alt";
    newGridView.AutoGenerateColumns = false;
    newGridView.AllowPaging = false;
    newGridView.CellSpacing = 1;
    newGridView.PageIndexChanging += new GridViewPageEventHandler(GvTitle_PageIndexChanging);
    newGridView.RowCommand += new GridViewCommandEventHandler(GvTitle _RowCommand);

    //Title ItemTemplate
    templateField titleField = new TemplateField();
    titleField.HeaderText = "Title";
    titleField.ItemTemplate = new AddTitleTemplateToGridView();
    newGridView.Columns.Add(titleField);

    // Bound Field
    foreach (DataControlField dc in GvTitle.Columns)
    {
      if (dc.GetType() == typeof(BoundField))
      {
        BoundField col = new BoundField();
        col.DataField = ((BoundField)dc).DataField;
        col.HeaderText = dc.HeaderText;
        newGridView.Columns.Add(col);
       }
     }

       return newGridView;
}

public class AddTitleTemplateToGridView : ITemplate
{
     LinkButton ht = new LinkButton();
     public AddTitleTemplateToGridView()}

     public virtual void OnInit(object sender, EventArgs e){ }
           
           
     void ITemplate.InstantiateIn(System.Web.UI.Control container)
     {
        ht = new LinkButton();
        ht.CommandName = "viewTitle";
        ht.Init += new EventHandler(OnInit);
        ht.DataBinding += new EventHandler(ht_DataBinding);
        container.Controls.Add(ht);
     }

     void ht_DataBinding(object sender, EventArgs e)
     {
        LinkButton lnk = sender as LinkButton;
        GridViewRow container = lnk.NamingContainer as GridViewRow;
        object dataValue = DataBinder.Eval(container.DataItem, "Title");
        if (dataValue != null)
        {
            lnk.Text = dataValue.ToString();
            lnk.CommandArgument = dataValue.ToString();
         }
       }
}


======================================================================================

b. Generate GridView

public GridView CopyGridView(GridView gridview, int m_instanceCount)
{
     Type t = gridview.GetType();
     GridView newGridView = (GridView)t.InvokeMember("", BindingFlags.CreateInstance, null, null, null);

     foreach (PropertyInfo prop in t.GetProperties())
     {
        if (prop.CanWrite)
        {
           if (prop.Name == "ID")
                 newGridView.ID = gridview.ID + m_instanceCount;
           else
                 prop.SetValue(newGridView, prop.GetValue(gridview, null), null);
        }
     }

     foreach (DataControlField item in gridview.Columns)
     {
          newGridView.Columns.Add(item);
     }
   
    newGridView.AlternatingRowStyle.CssClass = "alt";
    newGridView.RowCommand += new GridViewCommandEventHandler(GvTitle_RowCommand);               
     return newGridView;
}




Wednesday, October 15, 2014

Insert Table with Select Statement

2 Method to Insert Table with Select Statement (VALUES no need )

INSERT INTO table2
(column_name(s))
SELECT column_name(s)
FROM table1;


1 as [ColumnName]

*Use this when Primary key is auto generate.

OR

INSERT INTO table2
SELECT * FROM table1;

Tuesday, October 14, 2014

Network Domain

Path : C:\Windows\System32\drivers\etc\hosts
type in : 192.16.29.32    db.testing.com
Testing >  cmd  : ping db.testing.com

Tuesday, October 7, 2014

From & To XML

 public class CustomSerializer<T>
{
        public string ToXml(T obj)
        {
            return ToXml(obj, new Type[] { });
        }

        public string ToXml(T obj, Type[] extraTypes)
        {
            string output = string.Empty;

            using (StringWriter writer = new StringWriter())
            {
                XmlSerializer serializer = null;

                // Serialize the entity.
                serializer = new XmlSerializer(typeof(T), extraTypes);
                serializer.Serialize(writer, obj);

                // Get serialized string.
                output = writer.ToString();
                writer.Close();

                return output;
            }
        }

        public T FromXml(string xmlString)
        {
            return FromXml(xmlString, new Type[] { });
        }

        public T FromXml(string xmlString, Type[] extraTypes)
        {
            T result = default(T);
            XmlSerializer serializer = null;

            using (StringReader reader = new StringReader(xmlString))
            {
                // Deserialize the entity.
                serializer = new XmlSerializer(typeof(T), extraTypes);
                result = (T)serializer.Deserialize(reader);
            }
            return result;
        }

}

WorkFlow

Add Workflow by LASG


  1. Click to get NameSpace.
  2. Every workflow1st Time need to Add Binding (URL).
  3. 'Receive and Send Reply', 'Can create instance' for every 1st Call
  4. Select Persistence Store.


Parameter



Receiver 


 Correlates On and Initializers



Activites


Reply - No Content and Initializers


Duration Set (time span)

_EffectiveDate.Subtract(DateTime.Now)

Workflow Behaviour 

pick -------> mutiple task, but will choose 1 to run 
reply ------> will return to user , else will keep refeshing.
parallel ---> its same as pick, but will run 2 together
sequence ---> just grouping
persist ----> will store the variable to the database 


if got 3 task , then will run all the 3 ,
if got receive ? then will stop until got ppl call, else will straight run

Confirmation Box with Gridview Rows

function ConfirmationUpdate() 
{
    var totalRows = $('TABLE[id*=gvPerson] tr').length; //If Record = 2
    if (totalRows > 0) {
            return confirm('It Overwrite the Person update. Do you want to continue?');
    }
}

<asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="return ConfirmationUpdate()" OnClick="btnSave_Click" />

Grid Use this
OnClientClick="return confirm('Confirm to remove');"




OnClientClick='<%# Item.IsAlive ? "return confirm(\"OFF\");"  : "return confirm(\"ON\");" %>'
 OnClientClick='<%# Eval("ProviderName", "return confirm(\"Delete the datasource {0}?\");") %>'


Others Condition

if ($('INPUT[id*=hfChangeInactive]').val() == "Inactive

Wednesday, September 17, 2014

Gridview Function

<asp:GridView ID="TrainingGrid" runat="server" ItemType="TrainingTutorial.Entities.Training"
             DataKeyNames="TrainingID" SelectMethod="trainingGrid_GetData"
             UpdateMethod="trainingGrid_UpdateItem"
             EmptyDataText="No training records available."
             OnRowCommand="trainingGrid_RowCommand" PageSize="5"
             AutoGenerateColumns="False" Width="700px" AllowPaging="True" AllowSorting="True"
             <Columns>
                 <asp:TemplateField HeaderText="Action" ItemStyle-HorizontalAlign="Center">
                     <ItemTemplate>
                         <asp:LinkButton ID="approveButton" runat="server" CommandName="Update" CommandArgument="Approved" Text="Approve" Visible="<%# Item.Status == TrainingTutorial.Entities.TrainingStatus.Pending.ToString()  %>"></asp:LinkButton>
                         <asp:Label ID="Label1" runat="server" Text=" | " Visible="<%# Item.Status == TrainingTutorial.Entities.TrainingStatus.Pending.ToString()  %>"></asp:Label>
                         <asp:LinkButton ID="cancelButton" runat="server" CommandName="Update" CommandArgument="Cancelled" Text="Cancel" Visible="<%# Item.Status == TrainingTutorial.Entities.TrainingStatus.Pending.ToString()  %>"></asp:LinkButton>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:BoundField DataField="TrainingID" HeaderText="ID" Visible="false" ItemStyle-HorizontalAlign="Center">
                 </asp:BoundField>
                 <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-HorizontalAlign="Center" SortExpression="Name">
                 </asp:BoundField>
                <asp:BoundField DataField="EffectiveDate" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Effective Date" />

                <asp:BoundField DataField="EffectiveDate"  DataFormatString="{0:HH:mm}"  HeaderText="Effective Time" />
             </Columns>
         </asp:GridView>

OnRowCommand is to click the button of row
e.CommandArgument is get command arguement , e.g. CommandArgument="Cancelled"

DataKeyNames as an agurment for method (Update)
public void trainingGrid_UpdateItem(int trainingID)