private void SelectCellAction(int index, int column, bool isMmouse) { dataGridView.Rows[index].Selected = true; if (!isMmouse) { dataGridView[0, index].Value = !Convert.ToBoolean(dataGridView.Rows[index].Cells[0].Value); } else { if (column == 0) { dataGridView[0, index].Value = !Convert.ToBoolean(dataGridView.Rows[index].Cells[0].Value); } } List <DataGridViewRow> selectedRows = (from row in dataGridView.Rows.Cast <DataGridViewRow>() where Convert.ToBoolean(row.Cells["CB"].Value) select row).ToList(); bntLuaChon.Enabled = (dataGridView.CurrentRow != null); bntXoa.Enabled = selectedRows.Count > 0; currentModel = (MauModel)dataGridView.CurrentSelected(MauModelList); if (currentModel != null) { txtMaMau.Text = currentModel.MaMau; txtTenMau.Text = currentModel.TenMau; } bntLuu.Enabled = true; bntTaoMoi.Enabled = true; }
/// <summary> /// To the entity. /// </summary> /// <param name="model">The model.</param> /// <param name="destination">The destination.</param> /// <returns>Mau.</returns> public static Mau ToEntity(this MauModel model, Mau destination) { return(model.MapTo(destination)); }
/// <summary> /// To the entity. /// </summary> /// <param name="model">The model.</param> /// <returns>Mau.</returns> public static Mau ToEntity(this MauModel model) { return(model.MapTo <MauModel, Mau>()); }
private void bntLuaChon_Click(object sender, EventArgs e) { currentModel = (MauModel)dataGridView.CurrentSelected(MauModelList); controller.Select(currentModel); }
private void bntLuu_Click(object sender, EventArgs e) { if (txtMaMau.Text == "") { MessageBox.Show("Mã màu không được để rỗng"); return; } if (txtTenMau.Text == "") { MessageBox.Show("Tên màu không được để rỗng"); return; } currentModel = (MauModel)dataGridView.CurrentSelected(MauModelList); if (currentModel != null) { var cm = MauModelList.Where(c => c.MaMau == txtMaMau.Text && c.ID != currentModel.ID); if (cm.Any()) { MessageBox.Show("Mã màu đã tồn tại trong một bản ghi khác"); return; } var ct = MauModelList.Where(c => c.TenMau == txtTenMau.Text && c.ID != currentModel.ID); if (ct.Any()) { MessageBox.Show("Tên màu đã tồn tại trong một bản ghi khác"); return; } currentModel.MaMau = txtMaMau.Text; currentModel.TenMau = txtTenMau.Text; controller.Update(currentModel); //re-update UI dataGridView.UpdateView("MaMau", currentModel.MaMau); dataGridView.UpdateView("TenMau", currentModel.TenMau); txtMaMau.Focus(); txtMaMau.SelectAll(); bntTaoMoi.Enabled = true; bntLuu.Enabled = true; } else { var cm = MauModelList.Where(c => c.MaMau == txtMaMau.Text); if (cm.Any()) { MessageBox.Show("Mã màu đã tồn tại"); return; } var ct = MauModelList.Where(c => c.TenMau == txtTenMau.Text); if (ct.Any()) { MessageBox.Show("Tên màu đã tồn tại"); return; } currentModel = new MauModel { MaMau = txtMaMau.Text, TenMau = txtTenMau.Text, }; controller.Insert(currentModel); txtMaMau.Focus(); txtMaMau.SelectAll(); //txtTenMau.Text = ""; controller.ReviewGrid(); bntTaoMoi.Enabled = true; bntLuu.Enabled = true; } }