Ejemplo 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 = (MauModel)dataGridView.CurrentSelected(MauModelList);
            if (currentModel != null)
            {
                txtMaMau.Text  = currentModel.MaMau;
                txtTenMau.Text = currentModel.TenMau;
            }
            bntLuu.Enabled    = true;
            bntTaoMoi.Enabled = true;
        }
Ejemplo n.º 2
0
 /// <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));
 }
Ejemplo n.º 3
0
 /// <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>());
 }
Ejemplo n.º 4
0
 private void bntLuaChon_Click(object sender, EventArgs e)
 {
     currentModel = (MauModel)dataGridView.CurrentSelected(MauModelList);
     controller.Select(currentModel);
 }
Ejemplo n.º 5
0
        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;
            }
        }