- [C#] Viết ứng dụng xem và dò kết quả xổ số kiến thiết miền nam
- [EBOOK] Chia sẽ giáo trình học lập trình C - Giáo sư Phạm Văn Ất
- [C#] Hướng dẫn viết ứng dụng theo dõi máy in bao nhiêu trang (Monitor Printer)
- [C#] Lấy thông tin cấu hình máy tính xuất ra text file winform
- [C#] Chia sẽ class Install, Uninstall, Start và Stop Services Winform
- [C#] Tìm kiếm tập tin file nhanh chóng trên Winform sử dụng thư viện FastSearchLibrary
- [C#] Giới thiệu thư viện Fluent FTP Awesome dùng để làm việc với FTP
- [C#] Sử dụng thư viện Mini Profiler Integrations ghi log thực hiện các câu lệnh SQL
- [DEVEXPRESS] Thiết kế Dropdown ButtonBarItem trên Form Ribbon
- [C#] Lưu trạng thái các control trên Winform vào Registry Windows
- [C#] Ứng dụng ví dụ Simple Observer Pattern tăng giảm số lượng trên winform
- [C#] Hướng dẫn lấy thời gian thực server time trên winform
- [DEVEXPRESS] Hướng dẫn bật tính năng Scroll Pixcel in Touch trên GridView
- [DEVEXPRESS] Hướng dẫn sử dụng TileBar viết ứng dụng duyệt hình ảnh Winform
- [DEVEXPRESS] Tô màu border TextEdit trên Winform
- [C#] Lấy dữ liệu từ Console Write hiển thị lên textbox Winform
- [C#] Hiển thị Progress bar trên Window Console
- [C#] Di chuyển control Runtime và lưu layout trên winform
- [SQLSERVER] Sử dụng hàm NULL IF
- [C#] Chia sẽ source code mã đi tuần bằng giao diện Winform
[DEVEXPRESS] Hướng dẫn sử dụng Gallery Control để thiết kế phần mềm quản lý cafe
Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục hướng dẫn các bạn cách sử dụng Gallery Control trên Devexpress C#.
Thường các bạn hay nhìn thấy các phần mềm quản lý như: bán cafe, nhà hàng, hay cafe internet...
Các bạn sẽ thấy giao diện người ta hiển thị như thế này:
Ở hình trên nó sẽ hiển thị từng bàn ăn lên, và có nhiều bạn đã thắc mắc hỏi mình là làm thế nào để tạo được như vậy.
Thật ra, hình mà các bạn thấy ở trên là một ListView của Winform được View ở chế độ Large.
Trong bài này, mình sẽ giới thiệu thằng Gallery Control trong Devexpress, nó giúp chúng ta biểu diễn các bàn như trên hình vào phần mềm một cách dễ dàng.
Dưới đây, là giao diện sử dụng Gallery Control của Devexpress để thiết kế phần mềm quản lý coffee.
Trong bài viết mình đã tích hợp dữ liệu từ cở sở dữ liệu Sqlite để hiển thị lên.
Source code Gallery Control Devexpress C#:
using DevExpress.Utils.Drawing;
using DevExpress.XtraBars.Ribbon;
using FluentWinform;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DemoCoffee
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
galleryControl.Gallery.ItemClick += new GalleryItemClickEventHandler(Gallery_ItemClick);
}
private void Form1_Load(object sender, EventArgs e)
{
var provider = new Sqlite();
Image im1 = Image.FromFile("E:\\2.png");
var table_group = provider.ExecuteQuery("SELECT DISTINCT group_name FROM tbl_tablecoffee GROUP BY group_name");
var table_item = provider.ExecuteQuery("SELECT * FROM tbl_tablecoffee");
galleryControl.Gallery.ItemImageLayout = ImageLayoutMode.ZoomInside;
galleryControl.Gallery.ImageSize = new Size(80, 80);
galleryControl.Gallery.ShowItemText = true;
galleryControl.Gallery.ShowGroupCaption = true;
foreach (DataRow group in table_group.Rows)
{
var galleryItem = new GalleryItemGroup();
galleryItem.Caption = group["group_name"] as string;
galleryItem.CaptionAlignment = GalleryItemGroupCaptionAlignment.Stretch;
foreach (DataRow item in table_item.Rows)
{
if (group["group_name"].ToString().Equals(item["group_name"].ToString()))
{
var gc_item = new GalleryItem();
gc_item.AppearanceCaption.Normal.Font = new Font("Tahoma", 12, FontStyle.Bold);
gc_item.AppearanceCaption.Hovered.Font = new Font("Tahoma", 12, FontStyle.Bold);
gc_item.AppearanceCaption.Pressed.Font = new Font("Tahoma", 12, FontStyle.Bold);
if (Convert.ToBoolean(Convert.ToInt16(item["status"])))
{
gc_item.ImageOptions.Image = imageList1.Images[1];
}
else
{
gc_item.ImageOptions.Image = imageList1.Images[0];
}
gc_item.Caption = item["name"].ToString();
gc_item.Value = item["id"].ToString();
galleryItem.Items.Add(gc_item);
}
}
galleryControl.Gallery.Groups.Add(galleryItem);
}
}
private void Gallery_ItemClick(object sender, GalleryItemClickEventArgs e)
{
var gc_item = new GalleryItem();
string id = e.Item.Value.ToString();
var provider = new Sqlite();
bool is_status = Convert.ToBoolean(int.Parse(provider.ExecuteScalar($"select status from tbl_tablecoffee where id='{id}'").ToString()));
string status = (is_status) ? "0" : "1";
provider.ExecuteNonQuery($"update tbl_tablecoffee set status = '{status}' where id='{id}'").ToString();
gc_item.ImageOptions.Image = (is_status) ? imageList1.Images[0] : imageList1.Images[1];
gc_item.Caption = e.Item.Caption;
gc_item.Value = e.Item.Value;
e.Item.Assign(gc_item);
}
}
}
Các bạn có thể download source code ở bên dưới để tham khảo nhé.
Trong bài viết này, mình đang sử dụng Devexpress 18.1.6
Chúc các bạn thành công!