Beispiel #1
0
        //one same function to every DataGridView
        public static void LoadAllToGridView
        (
            DataGridView gridView,
            string[] columnNames,      //order
            List <T> customList = null //if the list is null then use GetAll()
        )
        {
            var list  = customList ?? GetAll();
            var table = ListToDataTable(list);

            LessLazyWorker.SetColumnsOrder(table, columnNames);
            table.Columns.Add("Filter");
            foreach (DataRow row in table.Rows)
            {
                row["Filter"] = DataRowToObject(row).ToString();
            }

            gridView.DataSource = table;
        }
        private void LoadAllBills()
        {
            LazyWorker <BillDisplay> .LoadAllToGridView
            (
                BillGridView,
                new string[] { "Id", "Customer_", "Employee_", "CreatingDay" },
                LessLazyWorker.GetAllBills()
            );

            DataTable table = (DataTable)BillGridView.DataSource;

            table.Columns.Add("Customer");
            table.Columns.Add("Employee");
            LessLazyWorker.SetColumnsOrder(table,
                                           new string[] { "Customer", "Employee", "CreatingDay", "TotalPrice" });

            foreach (DataRow row in table.Rows)
            {
                BillDisplay bill = LazyWorker <BillDisplay> .DataRowToObject(row);

                row["Customer"] = bill.Customer_ != null ? bill.Customer_.FullName : "";
                row["Employee"] = bill.Employee_ != null ? bill.Employee_.FullName : "";
            }

            BillGridView.DataSource = table;

            BillGridView.Columns["Id"].Visible        = false;
            BillGridView.Columns["Filter"].Visible    = false;
            BillGridView.Columns["Customer_"].Visible = false;
            BillGridView.Columns["Employee_"].Visible = false;

            BillGridView.Columns["CreatingDay"].HeaderText             = "Ngày khởi tạo";
            BillGridView.Columns["Customer"].HeaderText                = "Tên khách";
            BillGridView.Columns["Employee"].HeaderText                = "Tạo bởi";
            BillGridView.Columns["TotalPrice"].HeaderText              = "Tổng tiền";
            BillGridView.Columns["TotalPrice"].DefaultCellStyle.Format = "### ### ### ###";
        }