private void LoadTable() { tablelist = Table_BUS.LoadTable(); for (int i = 0; i < Table_BUS.CountTable(); i++) { Button btn = new Button() { Width = 80, Height = 80 }; Object id = tablelist.Rows[i]["IdTable"]; Object name = tablelist.Rows[i]["Name"]; Object status = tablelist.Rows[i]["Status"]; btn.Click += new EventHandler(this.buttonTable_Click); btn.Name = id.ToString(); btn.Text = Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + "" + name.ToString(); btn.ForeColor = Color.White; btn.Font = new Font(btn.Font.Name, btn.Font.Size, FontStyle.Bold); if (status.ToString() == "0") { btn.Image = (Image)(Properties.Resources.available); btn.BackColor = Color.FromArgb(15, 216, 52); } else { btn.Image = (Image)(Properties.Resources.occupy); btn.BackColor = Color.FromArgb(249, 64, 64); } flowLayoutPanel1.Controls.Add(btn); } }
private void btnLuu_Click(object sender, EventArgs e) { if (txtBan.Text.Trim() != "" && txtViTri.Text.Trim() != "") { if (flag == 1) //thêm { if (Table_BUS.CheckValidTable(txtBan.Text) == 1) { string status; if (cbxTinhTrang.Text == "Trống") { status = "0"; } else { status = "1"; } Table_DTO table = new Table_DTO(txtBan.Text, txtViTri.Text, status); Table_BUS.AddTable(table); MessageBox.Show("Lưu thành công"); } else { MessageBox.Show("Đã Tồn tại bàn " + txtBan.Text); } } else //sửa { string status; if (cbxTinhTrang.Text == "Trống") { status = "0"; } else { status = "1"; } DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle); Table_DTO table = new Table_DTO(txtBan.Text, txtViTri.Text, status); Table_BUS.EditTable(table, row[0].ToString()); MessageBox.Show("Sửa thành công"); } dgvBan.DataSource = Table_BUS.LoadTable(); bindingData(); txtBan.ReadOnly = true; txtViTri.ReadOnly = true; cbxTinhTrang.Enabled = false; txtSoLuong.Text = Table_BUS.CountTable().ToString(); btnLuu.Enabled = false; btnThem.Enabled = true; btnSua.Enabled = true; btnXoa.Enabled = true; } else { MessageBox.Show("Vui lòng điền đầy đủ thông tin"); } }
private void btnHuy_Click(object sender, EventArgs e) { LoadTable(); dgvBan.DataSource = Table_BUS.LoadTable(); bindingData(); btnThem.Enabled = true; btnSua.Enabled = true; btnXoa.Enabled = true; btnLuu.Enabled = false; }
private void btnXoa_Click(object sender, EventArgs e) { if (MessageBox.Show("Bạn chắc chắn muốn xóa " + txtBan.Text + " ?", "Xác Nhận", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle); Table_BUS.DeleteTable(row[0].ToString()); MessageBox.Show("Xóa hoàn tất"); } dgvBan.DataSource = Table_BUS.LoadTable(); bindingData(); txtSoLuong.Text = Table_BUS.CountTable().ToString(); }
private void frmTable_Load(object sender, EventArgs e) { dgvBan.DataSource = Table_BUS.LoadTable(); bindingData(); btnLuu.Enabled = false; }