/// <summary> /// Selects the cell action. /// </summary> /// <param name="index">The index.</param> /// <param name="column"></param> /// <param name="isMmouse"></param> 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 = (MuaModel)dataGridView.CurrentSelected(currentModelList); if (currentModel != null) { txtMaMua.Text = currentModel.MaMua; txtTenMua.Text = currentModel.TenMua; } bntLuu.Enabled = true; bntTaoMoi.Enabled = true; }
/// <summary> /// To the entity. /// </summary> /// <param name="model">The model.</param> /// <param name="destination">The destination.</param> /// <returns>Mua.</returns> public static Mua ToEntity(this MuaModel model, Mua destination) { return(model.MapTo(destination)); }
/// <summary> /// To the entity. /// </summary> /// <param name="model">The model.</param> /// <returns>Mua.</returns> public static Mua ToEntity(this MuaModel model) { return(model.MapTo <MuaModel, Mua>()); }
/// <summary> /// Handles the Click event of the bntLuaChon control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private void bntLuaChon_Click(object sender, EventArgs e) { currentModel = (MuaModel)dataGridView.CurrentSelected(currentModelList); controller.Select(currentModel); }
/// <summary> /// Handles the Click event of the bntLuu control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private void bntLuu_Click(object sender, EventArgs e) { if (txtMaMua.Text == "") { MessageBox.Show("Mã mua không được để rỗng"); return; } if (txtTenMua.Text == "") { MessageBox.Show("Tên mua không được để rỗng"); return; } currentModel = (MuaModel)dataGridView.CurrentSelected(currentModelList); if (currentModel != null) { var cm = currentModelList.Where(c => c.MaMua == txtMaMua.Text && c.ID != currentModel.ID); if (cm.Any()) { MessageBox.Show("Mã mua đã tồn tại trong một bản ghi khác"); return; } var ct = currentModelList.Where(c => c.TenMua == txtTenMua.Text && c.ID != currentModel.ID); if (ct.Any()) { MessageBox.Show("Tên mua đã tồn tại trong một bản ghi khác"); return; } currentModel.MaMua = txtMaMua.Text; currentModel.TenMua = txtTenMua.Text; controller.Update(currentModel); //re-update UI dataGridView.UpdateView("MaMua", currentModel.MaMua); dataGridView.UpdateView("TenMua", currentModel.TenMua); txtMaMua.Focus(); txtMaMua.SelectAll(); bntTaoMoi.Enabled = true; bntLuu.Enabled = true; } else { var cm = currentModelList.Where(c => c.MaMua == txtMaMua.Text); if (cm.Any()) { MessageBox.Show("Mã mua đã tồn tại"); return; } var ct = currentModelList.Where(c => c.TenMua == txtTenMua.Text); if (ct.Any()) { MessageBox.Show("Tên mua đã tồn tại"); return; } currentModel = new MuaModel { MaMua = txtMaMua.Text, TenMua = txtTenMua.Text, }; controller.Insert(currentModel); txtMaMua.Focus(); txtMaMua.SelectAll(); //txtTenMua.Text = ""; controller.ReviewGrid(); bntTaoMoi.Enabled = true; bntLuu.Enabled = true; } }