示例#1
0
        /// <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 = (ChatLieuModel)dataGridView.CurrentSelected(chatLieuModelList);
            if (currentModel != null)
            {
                txtMaChatLieu.Text  = currentModel.MaChatLieu;
                txtTenChatLieu.Text = currentModel.TenChatLieu;
            }
            bntLuu.Enabled    = true;
            bntTaoMoi.Enabled = true;
        }
示例#2
0
 /// <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 = (ChatLieuModel)dataGridView.CurrentSelected(chatLieuModelList);
     controller.Select(currentModel);
 }
 /// <summary>
 /// To the entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="destination">The destination.</param>
 /// <returns>ChatLieu.</returns>
 public static ChatLieu ToEntity(this ChatLieuModel model, ChatLieu destination)
 {
     return(model.MapTo(destination));
 }
示例#4
0
        /// <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 (txtMaChatLieu.Text == "")
            {
                MessageBox.Show("Mã chất liệu không được để rỗng");
                return;
            }
            if (txtTenChatLieu.Text == "")
            {
                MessageBox.Show("Tên chất liệu không được để rỗng");
                return;
            }

            currentModel = (ChatLieuModel)dataGridView.CurrentSelected(chatLieuModelList);
            if (currentModel != null)
            {
                var cm = chatLieuModelList.Where(c => c.MaChatLieu == txtMaChatLieu.Text &&
                                                 c.ID != currentModel.ID);
                if (cm.Any())
                {
                    MessageBox.Show("Mã chất liệu đã tồn tại trong một bản ghi khác");
                    return;
                }
                var ct = chatLieuModelList.Where(c => c.TenChatLieu == txtTenChatLieu.Text &&
                                                 c.ID != currentModel.ID);
                if (ct.Any())
                {
                    MessageBox.Show("Tên chất liệu đã tồn tại trong một bản ghi khác");
                    return;
                }

                currentModel.MaChatLieu  = txtMaChatLieu.Text;
                currentModel.TenChatLieu = txtTenChatLieu.Text;
                controller.Update(currentModel);
                //re-update UI

                dataGridView.UpdateView("MaChatLieu", currentModel.MaChatLieu);
                dataGridView.UpdateView("TenChatLieu", currentModel.TenChatLieu);

                txtMaChatLieu.Focus();
                txtMaChatLieu.SelectAll();
                bntTaoMoi.Enabled = true;
                bntLuu.Enabled    = true;
            }
            else
            {
                var cm = chatLieuModelList.Where(c => c.MaChatLieu == txtMaChatLieu.Text);
                if (cm.Any())
                {
                    MessageBox.Show("Mã chất liệu đã tồn tại");
                    return;
                }
                var ct = chatLieuModelList.Where(c => c.TenChatLieu == txtTenChatLieu.Text);
                if (ct.Any())
                {
                    MessageBox.Show("Tên chất liệu đã tồn tại");
                    return;
                }
                currentModel = new ChatLieuModel {
                    MaChatLieu  = txtMaChatLieu.Text,
                    TenChatLieu = txtTenChatLieu.Text,
                };

                controller.Insert(currentModel);
                txtMaChatLieu.Focus();
                txtMaChatLieu.SelectAll();
                //txtTenChatLieu.Text = "";
                controller.ReviewGrid();
                bntTaoMoi.Enabled = true;
                bntLuu.Enabled    = true;
            }
        }
 /// <summary>
 /// To the entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>ChatLieu.</returns>
 public static ChatLieu ToEntity(this ChatLieuModel model)
 {
     return(model.MapTo <ChatLieuModel, ChatLieu>());
 }