Ads

Ads
zzzz
Showing posts with label Huong Dan Lap Trinh. Show all posts
Showing posts with label Huong Dan Lap Trinh. Show all posts

Thursday, May 22, 2014

Hướng dẫn cách đánh số trang trong Word 2007-2010 từ trang bất kỳ đến số trang bất kỳ

20Me Reviews     9:53 AM    

BÀI VIẾT CÓ HÌNH ẢNH MINH HỌA, BẠN CHỜ LOAD ẢNH XONG RỒI HÃY LÀM!
Bước 1:
Click chuột trái đến số trang bạn cần đánh, ở đây mình lấy ví dụ là 1 bài khóa luận tốt nghiệp, số trang bắt đầu tính từ Chương 1

Bước 2:
Chọn Page Layout => Breaks => Next Page

Bước 3:
Sau khi tạo section ở bước 1, chọn tiếp insert => Page numbers => format page numbers => tại ô start at: chọn 1


Bước 4:
Như vậy quá trình tạo số trang và section đã hoàn thành, bây giờ bạn có thể đánh số trang bằng header, footer, page number thoải mả (ở đây mình chọn footer để đánh số trang)i:

Bước 5:
Định dạng lại số trang ở footer (nếu xuất hiện 2 section như trong hình vẽ có nghĩa bước 1 bạn đã làm đúng):

Bước 6:
Đây là 1 bước cực kỳ quan trọng, nó giúp bạn xóa liên kết giữa section 1 và 2 => đây là tiền đề để xóa trang không cần đánh

Bước 7:
Xóa những trang không cần đánh, cụ thể là các trang ở phía trên chương 1

Bước 8:
Đến đây là xong và bạn chỉ cần đóng footer
Bước 9:
Làm tường tự với những trang không cần đánh, ở đây là từ phần kết luận đến hết khóa luận tốt nghiệp

Lưu ý: cách này dùng để áp dụng xóa những header không muốn hiển thị từ số trang bất kỳ.
Cách xóa section, chọn chế độ xem darft, tìm dòng section break rồi xóa
Chúc các bạn thành công

Truy vấn dữ liệu với LinQ

20Me Reviews     9:48 AM    
Lấy mẫu tin đầu tiên trong bảng(Lấy sản phẩm đầu tiên trong bảng Products). Hai câu truy vấn sau đây trả về cùng kết quả.
var products = context.Products.FirstOrDefault();
var products = (from p in context.Products select p).Skip(0).Take(1); //Tương đương SELECT TOP 1 trong SQL
Lấy mẫu tin cuối cùng(Sản phẩm cuối cùng trong bảng Products).
var products = context.Products.LastOrDefault(); //LastOrDefault vẫn chưa đươc hỗ trợ trong .NET 3.5
var products = (from p in context.Products orderby p.ProductID descending
select p).Skip(0).Take(1);
Lấy sản phẩm cố định trong bảng Products.
Product products = context.Products.Single(p=>p.ProductID == 22);
Lấy 10 sản phẩm đầu tiên trong bảng Products.
var products = (from p in context.Products select p).Take(10);
//Tương đươngSELECT TOP 10 trong SQL
Lấy sản phẩm thứ 11 đến 20.
var products = (from p in context.Products select p).Skip(10).Take(10);
Lấy tất cả các sản phẩm trong bảng Products.
var products = from p in context.Products select p;
//Tương đương SELECT * trong SQL
Lấy các cột cố định trong bảng Products.
var products = from p in context.Products  select new 
{
p.ProductID,
p.ProductName,
p.UnitPrice,
p.UnitsInStock,
p.UnitsOnOrder
};
Thay đổi tiêu đề cột.
var products = from p in context.Products select new 
{
MaSanPham = p.ProductID,
TenSanPham =p.ProductName,
DonGia = p.UnitPrice,
SoLuong =p.UnitsInStock,
SoLuongBan = p.UnitsOnOrder
};//Tương đương Alias columns
Sắp xếp các cột trong kết quả trả về.
var products = from p in context.Products
orderby p.ProductID descending, p.ProductName//Tương đương ORDER BY trong SQL
select new 
{
p.ProductID,
p.ProductName,
p.UnitPrice,
p.UnitsInStock,
p.UnitsOnOrder
};
Loại bỏ các dòng dữ liệu trùng nhau.
var products = (from od in context.Order_Details  join p in context.Products on od.ProductID equals p.ProductID
select new { od.ProductID, p.ProductName}).Distinct();
//Tương đương SELECT DISTINCT trong SQ
Lấy hóa đơn có sản phẩm bán là 7(ProductID = 7)
var customers = from od in context.Order_Details where od.ProductID == 7
select od;
Lấy sản phẩm có đơn giá trong khoảng 20-30.
var products = from p in context.Products
where p.UnitPrice >= 20 && p.UnitPrice <= 30//Tương đương BETWEEN trong SQL
select new { p.ProductName, p.UnitPrice, p.UnitsInStock, p.UnitsOnOrder };
Lấy tất cả các sản phẩm đã bán ra.
var products = from p in context.Products where (from od in context.Order_Detailsselect od.ProductID).Contains(p.ProductID)
select new {p.ProductID, p.ProductName, p.UnitPrice, p.UnitsInStock,
p.UnitsOnOrder };//Tương đương từ khóa IN trong SQL
Lấy tất cả các sản phẩm chưa bán ra.
var products = from p in context.Products
where !(from od in context.Order_Details
select od.ProductID).Contains(p.ProductID)
//Tương đương từ khóa NOT IN trong SQL
select new {
p.ProductID, p.ProductName, p.UnitPrice, p.UnitsInStock, p.UnitsOnOrder };
Lấy danh sách khách hàng có tên bắt đầu là “Sa”.
var customers = from c in context.Customers
where c.CompanyName.StartsWith("Sa")//Tương đương LIKE 'Sa%' trong SQL
select new { c.CustomerID, c.CompanyName, c.ContactName, c.City, c.Country };
Lấy danh sách khách hàng có tên kết thúc bằng “es”.
var customers = from c in context.Customers
where c.CompanyName.EndsWith("es")//Tương đương LIKE '%es' trong SQL
select new { c.CustomerID, c.CompanyName, c.ContactName, c.City, c.Country };
Lấy danh sách khách hàng có chứa chuỗi “sa” trong CompanyName.
var customers = from c in context.Customers
where c.CompanyName.Contains("Sa")//Tương đương LIKE '%Sa%' trong SQL
select new { c.CustomerID, c.CompanyName, c.ContactName, c.City, c.Country };
Lấy danh sách khách hàng tại Anh và Pháp.
var customers = (from c in context.Customers
where c.Country == "UK"
select new
{
c.CustomerID,
c.CompanyName,
c.ContactName,
c.City, c.Country
}).Union(//Tương đương PHÉP HỢP UNION trong SQL
from c in context.Customers
where c.Country == "France"
select new {
c.CustomerID,
c.CompanyName,
c.ContactName,
c.City,
c.Country } );
Lấy danh sách khách hàng có hóa đơn.
var customers = from c in context.Customers
join o in context.Orders on c.CustomerID equals o.CustomerID
//Tương đương INNER JOIN trong SQL
orderby c.CustomerID, o.OrderID
select new {
c.CustomerID,
o.OrderID,
OrderDate = o.OrderDate.Value.ToShortDateString(),
c.CompanyName,
c.City,
c.Country };
Lấy hóa đơn của khách hàng, bao gồm khách hàng không có hóa đơn.
var customers = from c in context.Customers
join o in context.Orders
on c.CustomerID equals o.CustomerID into OD
from o in OD.DefaultIfEmpty()//Tương đương OUTER JOIN trong SQL
select new
{
CustomerID = c.CustomerID,
CompanyName = c.CompanyName,
OrderID = o == null ? 0 : o.OrderID
};
Đếm số hóa đơn đối với mỗi khách hàng
var customers = from c in context.Customers
select new { c.CustomerID, c.CompanyName, c.Orders.Count };
Đếm số hóa đơn đối với khách hàng có lớn hơn 5 hóa đơn.
var customers = from c in context.Customers
where c.Orders.Count >5
select new {c.CustomerID, c.CompanyName, c.Orders.Count };
Đếm số hàng hóa trên mỗi hóa đơn và tính đơn giá bình quân của hóa đơn.
var orders = from od in context.Order_Details
group od by od.OrderID into OD//Tương đương GROUP BY trong SQL
orderby OD.Key
select new
{
OrderID = OD.Key,
ProductID = OD.Count(),
UnitPrice = OD.Average(m => m.UnitPrice)
};
Đếm số hàng hóa trên mỗi hóa đơn và tính giá trị hóa đơn.
var orders = from od in context.Order_Details
group od by od.OrderID into OD
orderby OD.Key
select new
{
OrderID = OD.Key,
Product = OD.Count(),
UnitPrice = OD.Sum(m => m.UnitPrice)
};
Lấy sản phẩm có giá bán cao nhất và thấp nhất trong mỗi hóa đơn.
var orders = from od in context.Order_Details
group od by od.OrderID into OD
orderby OD.Key
select new 
{
OrderID = OD.Key,
MinPrice = OD.Min(m => m.UnitPrice),
MaxPrice = OD.Max(m => m.UnitPrice)
};
Lấy giá bán cao nhất và thấp nhất của mỏi sản phẩm.
var orders = from od in context.Order_Details
join p in context.Products on od.ProductID equals p.ProductID
group od by new { p.ProductID, p.ProductName } into OD
orderby OD.Key.ProductID
select new 
{
ProductID = OD.Key.ProductID,
ProductName = OD.Key.ProductName,
MaxPrice = OD.Max(m => m.UnitPrice),
MinPrice = OD.Min(m => m.UnitPrice)
};
Nguồn: http//vietshare.vn

Thêm, xóa, sửa CSDL dùng Web Service trong ASP.Net

20Me Reviews     9:45 AM    
1. Tạo data base
mo-ta-csdl-demo-web-service

2. Tạo web services
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
SqlConnection con;
SqlDataAdapter da;
SqlCommand cmd;
DataSet ds;
[WebMethod]
public DataSet GetAccount()
{
    con = new SqlConnection("server=.; database=AccountDB; integrated security = true;");
    da = new SqlDataAdapter("Select * From NguoiDung", con);
    ds = new DataSet();
    da.Fill(ds);
    return ds;
}
[WebMethod]
public void InsertAccount(string mand, string hoten, string tendangnhap, string matkhau, bool gioitinh, string email)
{
    con = new SqlConnection("server=.; database=AccountDB; integrated security = true;");
    con.Open();
    cmd = new SqlCommand("INSERT INTO NguoiDung VALUES('" + mand + "', '" + hoten + "', '" + tendangnhap + "', '" + matkhau + "', '" + gioitinh + "', '" + email + "')", con);
    cmd.ExecuteNonQuery();
    con.Close();
}
[WebMethod]
public void UpdateAccount(string mand, string hoten, string tendangnhap, string matkhau, bool gioitinh, string email)
{
    con = new SqlConnection("server=.; database=AccountDB; integrated security = true;");
    con.Open();
    cmd = new SqlCommand("Update NguoiDung Set HoTen='" + hoten + "', TenDangNhap='" + tendangnhap + "', MatKhau='" + matkhau + "', GioiTinh='" + gioitinh + "', Email='" + email + "' Where MaND='" + mand + "'", con);
    cmd.ExecuteNonQuery();
    con.Close();
}
[WebMethod]
public void DeleteAccount(int mand)
{
    con = new SqlConnection("server=.; database=AccountDB; integrated security = true;");
    con.Open();
    cmd = new SqlCommand("Delete From NguoiDung Where MaND='" + mand + "'", con);
    cmd.ExecuteNonQuery();
    con.Close();
}
3.Gọi web services
Lấy dữ liệu dùng Web Service
Trong sự kiện PageLoad mình sẽ thực hiện chức năng lấy dữ liệu lên bằng cách khai báo đối tượng Web Service và sử dụng hàm GetAccount() từ đó đổ vào trong GridView (gvNguoiDung) qua DataSource.
1
2
3
4
5
6
7
8
9
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        account.Service1 sv1 = new account.Service1();
        gvNguoiDung.DataSource = sv1.GetAccount();
        gvNguoiDung.DataBind();
    }
}
Thêm mới 1 dòng
Giao-dien-demo-them-xoa-sua
1
2
3
4
5
6
7
8
9
10
11
12
protected void btThem_Click(object sender, EventArgs e)
{
    account.Service1 sv1 = new account.Service1();
    string mand = txtMaNguoiDung.Text;
    string hoten = txtHovaTen.Text;
    string tendn = txtTenDangNhap.Text;
    string matkhau = txtMatKhau.Text;
    bool gioitinh = bool.Parse(radioGioiTinh.SelectedValue);
    string email = txtEmail.Text;
    sv1.InsertAccount(mand, hoten, tendn, matkhau, gioitinh, email);

© 2014-2015 Ebook-Coding Share and Learning | Distributed By My Blogger Themes | Designed By Ebook-coding