Thứ Sáu, 31 tháng 3, 2017

Add/Remove Class like jQuery using pure Javascript

/**/
    function hasClass(el, className) {
        if (el.classList)
            return el.classList.contains(className)
        else
            return !!el.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'))
    }
 
    function addClass(el, className) {
        if (el.classList)
            el.classList.add(className)
        else if (!hasClass(el, className)) el.className += " " + className
    }
 
    function removeClass(el, className) {
        if (el.classList)
            el.classList.remove(className)
        else if (hasClass(el, className)) {
            var reg = new RegExp('(\\s|^)' + className + '(\\s|$)')
            el.className = el.className.replace(reg, ' ')
        }
    }
    /**/

Chống Refresh Page Dropdown list ASPNET

 -------------
 Không refresh toàn bộ trang khi chọn item trên dropdown 1 để load data lên dropdown 2
--------------
The ScriptManager control and the UpdatePanel control. These controls remove the requirement to refresh the whole page with each postback, which improves the user experience. By default, a postback control (such as a button) inside an UpdatePanel control causes a partial-page update. By default, a button or other control outside an UpdatePanel control causes the whole page to be refreshed,
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <fieldset>
            <div class="1">
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem Text="Select..." Value="No selection made"></asp:ListItem>
                </asp:DropDownList>
            </div>
            <div class="1">
                <asp:DropDownList ID="DropDownList2" runat="server">
                    <asp:ListItem Text="Select..." Value="No selection made"></asp:ListItem>
                </asp:DropDownList>
            </div>
        </fieldset>
    </ContentTemplate>
</asp:UpdatePanel>

Thứ Ba, 21 tháng 3, 2017

Change line height in Visual Studio

Can't change directly in Visual Studio.
--> BUT You CAN change line height of font, the font you're using.
Step 1: install Fontforge.
Step 2: Open Fontforge after install finished, go to:
Element->Font Info ->OS2 -> Unit.
Change 4 value: Down win, up win, top N, down horizontal by multiplied by the desired ratio. Sample: ratio 1.5 or 2 ..etc...
(it means: if default 800, you multiple with ratio 1.5 --> result is 1200, you change 800 -->1200)
--> click OK to save setting.
Step 3: Go to File -> Generate font --> Generate with ttf format.
Step 4: Install the font just created and change font in Visual Studio.
-------------> ENJOY------------

Visual Studio WITH C# KEY BINDINGS _ hotkey

To answer the specific question, in C# you are likely to be using the C# keyboard mapping scheme, which will use these hotkeys by default:

Ctrl+E, Ctrl+D to format the entire document.
Ctrl+E, Ctrl+F to format the selection.

You can change these in Tools > Options > Environment -> Keyboard (either by selecting a different "keyboard mapping scheme", or binding individual keys to the commands "Edit.FormatDocument" and "Edit.FormatSelection").

If you have not chosen to use the C# keyboard mapping scheme, then you may find the key shortcuts are different. For example, if you are not using the C# bindings, the keys are likely to be:

Ctrl + K + D (Entire document)
Ctrl + K + F (Selection only)

To find out which key bindings apply in YOUR copy of Visual Studio, look in the Edit > Advanced menu - the keys are displayed to the right of the menu items, so it's easy to discover what they are on your system.

ADO.NET Demo

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = @"Data Source=USERMIC-42NCNNO\SQLEXPRESS;Initial Catalog=test;User id=sa;Password=7880;";
            SqlConnection con=new SqlConnection();
            con.ConnectionString=connectionString;
            if(con.State!=ConnectionState.Open)
                con.Open();
 
            /*--------------------------------LỆNH SELECT-------------------------------------*/
 
            /*
            SqlCommand cmdSQL = new SqlCommand();
            cmdSQL.Connection = con;
            cmdSQL.CommandText = "Select * from Nhanvien where tuoi>@sTuoi";
            cmdSQL.Parameters.AddWithValue("sTuoi", 27);
            SqlDataReader dr = cmdSQL.ExecuteReader();
            while (dr.Read())
            {
                Console.WriteLine(String.Format("{0} \t | {1} \t | {2} \t | {3}",
                            dr[0], dr[1], dr[2], dr[3]));
            }
            con.Close();
             */
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText="SP_NHANVIEN_SELECT";
            /*
             Store Procedure:
             CREATE PROCEDURE SP_NHANVIEN_SELECT
                @Tuoi INT
             AS
                    SELECT * FROM   NHANVIEN WHERE  TUOI > @Tuoi
             */
            cmd.Parameters.AddWithValue("@tuoi"SqlDbType.Int).Value = 34;
 
            //SqlDataReader dr = cmd.ExecuteReader();
            //while (dr.Read())
            //{
            //    Console.WriteLine(String.Format("{0} \t | {1} \t | {2} \t | {3}",
            //               dr.GetInt32(0), dr["HoTen"], dr[2], dr[3]));
            //}
            //dr.Close();
 
            //int kq = (Int32)cmd.ExecuteScalar();
            //Console.WriteLine(kq);
 
            /*---------------------------------------------------------------------*/
 
            /*--------------------------------LỆNH INSERT-------------------------------------*/
            
            //SqlCommand insertCmd = new SqlCommand();
            //insertCmd.Connection = con;
            //insertCmd.CommandText = @"insert into NhanVien(HoTen,Tuoi,PhongBanId) values(@val1,@val2,@val3)";
            //insertCmd.Parameters.AddWithValue("val1", SqlDbType.NVarChar).Value = "Anh Anh";
            //insertCmd.Parameters.AddWithValue("val2", SqlDbType.Int).Value = 26;
            //insertCmd.Parameters.AddWithValue("val3", SqlDbType.Int).Value = 1;
 
            //int sodong = insertCmd.ExecuteNonQuery();
            //Console.WriteLine(sodong);
 
            /*---------------------------------------------------------------------*/
 
            /*--------------------------------LỆNH UPDATE-------------------------------------*/
 
            //SqlCommand updateCmd = new SqlCommand();
            //updateCmd.Connection = con;
            //updateCmd.CommandText = @"update NhanVien set HoTen=@val1,Tuoi=@val2,PhongBanId=@val3 where nhanvienid=@val4";
            //updateCmd.Parameters.AddWithValue("val1", SqlDbType.NVarChar).Value = "Anh Anh Edit";
            //updateCmd.Parameters.AddWithValue("val2", SqlDbType.Int).Value = 26;
            //updateCmd.Parameters.AddWithValue("val3", SqlDbType.Int).Value = 1;
            //updateCmd.Parameters.AddWithValue("val4", SqlDbType.Int).Value = 9;
 
            //int sodong = updateCmd.ExecuteNonQuery();
            //Console.WriteLine(sodong);
 
            /*---------------------------------------------------------------------*/
 
            /*--------------------------------LỆNH DELETE-------------------------------------*/
 
            SqlCommand delCmd = new SqlCommand();
            delCmd.Connection = con;
            delCmd.CommandText = @"delete from NhanVien where nhanvienid=@id";
            delCmd.Parameters.AddWithValue("id"SqlDbType.Int).Value = 9;
 
            int sodong = delCmd.ExecuteNonQuery();
            Console.WriteLine(sodong);
 
            con.Close();
            Console.ReadKey();
        }
    }
}

Thứ Sáu, 10 tháng 3, 2017

Thứ Tư, 1 tháng 3, 2017

Navigation bar Menu dọc

HTML code:
-------------------------------------------------------------------------------------------
<ul id="nav">
  <li class="item"><a href="">item 1</a></li>
  <li class="item"><a href="">item 2</a></li>
  <li class="item"><a href="">item 3</a></li>
  <li class="item"><a href="">item 4</a></li>
</ul>
<div id="main">
  <h2>Fixed Full-height Side Nav</h2>
  <h3>Try to scroll this area, and see how the sidenav sticks to the page</h3>
  <p>Notice that this div element has a left margin of 25%. This is because the side navigation is set to 25% width. If you remove the margin, the sidenav will overlay/sit on top of this div.</p>
  <p>Also notice that we have set overflow:auto to sidenav. This will add a scrollbar when the sidenav is too long (for example if it has over 50 links inside of it).</p>
  <p>Some text..</p>
  <p>Some text..</p>
  <p>Some text..</p>
  <p>Some text..</p>
  <p>Some text..</p>
  <p>Some text..</p>
  <p>Some text..</p>
</div>
-------------------------------------------------------------------------------------------

CSS code:
-------------------------------------------------------------------------------------------
 #nav {
  list-style-type: none;
  /* xoa dau cham*/
  margin: 0px;
  padding: 0px;
  border: 1px solid blue;
  width: 25%;
  height: 100%;
  overflow: auto;
  position: fixed;
  /*co dinh doi tuong*/
  background-color: #f4f2e3;
}

.item {
  border-bottom: 1px solid gray;
  /*tao vien*/
}

.item a {
  color: #1f5393;
  font-weight: bold;
  display: block;
  /*khoi tran het chieu rong*/
  background-color: #b7e5d8;
  width: 100%;
  /*khoo mau xanh rong*/
  text-decoration: none;
  /*ko gach duoi*/
  text-align: center;
  /*can giua*/
}

.item a:hover {
  background-color: #555;
  color: white;
}

.item:last-child {
  border-bottom: none;
}

#main {
  margin-left: 25%;
  padding: 1px 16px;
  height: 1000px;
}
-------------------------------------------------------------------------------------------