Esempio n. 1
0
        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 = (DoiTuongModel)dataGridView.CurrentSelected(DoiTuongModelList);
            if (currentModel != null)
            {
                txtMaDoiTuong.Text  = currentModel.MaDoiTuong;
                txtTenDoiTuong.Text = currentModel.TenDoiTuong;
            }
            bntLuu.Enabled    = true;
            bntTaoMoi.Enabled = true;
        }
 /// <summary>
 /// To the entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="destination">The destination.</param>
 /// <returns>DoiTuong.</returns>
 public static DoiTuong ToEntity(this DoiTuongModel model, DoiTuong destination)
 {
     return(model.MapTo(destination));
 }
 /// <summary>
 /// To the entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>DoiTuong.</returns>
 public static DoiTuong ToEntity(this DoiTuongModel model)
 {
     return(model.MapTo <DoiTuongModel, DoiTuong>());
 }
Esempio n. 4
0
 private void bntLuaChon_Click(object sender, EventArgs e)
 {
     currentModel = (DoiTuongModel)dataGridView.CurrentSelected(DoiTuongModelList);
     controller.Select(currentModel);
 }
Esempio n. 5
0
        private void bntLuu_Click(object sender, EventArgs e)
        {
            if (txtMaDoiTuong.Text == "")
            {
                MessageBox.Show("Mã đối tượng không được để rỗng");
                return;
            }
            if (txtTenDoiTuong.Text == "")
            {
                MessageBox.Show("Tên đối tượng không được để rỗng");
                return;
            }

            currentModel = (DoiTuongModel)dataGridView.CurrentSelected(DoiTuongModelList);
            if (currentModel != null)
            {
                var cm = DoiTuongModelList.Where(c => c.MaDoiTuong == txtMaDoiTuong.Text &&
                                                 c.ID != currentModel.ID);
                if (cm.Any())
                {
                    MessageBox.Show("Mã đối tượng đã tồn tại trong một bản ghi khác");
                    return;
                }
                var ct = DoiTuongModelList.Where(c => c.TenDoiTuong == txtTenDoiTuong.Text &&
                                                 c.ID != currentModel.ID);
                if (ct.Any())
                {
                    MessageBox.Show("Tên đối tượng đã tồn tại trong một bản ghi khác");
                    return;
                }

                currentModel.MaDoiTuong  = txtMaDoiTuong.Text;
                currentModel.TenDoiTuong = txtTenDoiTuong.Text;
                controller.Update(currentModel);
                //re-update UI

                dataGridView.UpdateView("MaDoiTuong", currentModel.MaDoiTuong);
                dataGridView.UpdateView("TenDoiTuong", currentModel.TenDoiTuong);

                txtMaDoiTuong.Focus();
                txtMaDoiTuong.SelectAll();
                bntTaoMoi.Enabled = true;
                bntLuu.Enabled    = true;
            }
            else
            {
                var cm = DoiTuongModelList.Where(c => c.MaDoiTuong == txtMaDoiTuong.Text);
                if (cm.Any())
                {
                    MessageBox.Show("Mã đối tượng đã tồn tại");
                    return;
                }
                var ct = DoiTuongModelList.Where(c => c.TenDoiTuong == txtTenDoiTuong.Text);
                if (ct.Any())
                {
                    MessageBox.Show("Tên đối tượng đã tồn tại");
                    return;
                }
                currentModel = new DoiTuongModel
                {
                    MaDoiTuong  = txtMaDoiTuong.Text,
                    TenDoiTuong = txtTenDoiTuong.Text,
                };

                controller.Insert(currentModel);
                txtMaDoiTuong.Focus();
                txtMaDoiTuong.SelectAll();
                //txtTenDoiTuong.Text = "";
                controller.ReviewGrid();
                bntTaoMoi.Enabled = true;
                bntLuu.Enabled    = true;
            }
        }