コード例 #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 = (KichCoModel)dataGridView.CurrentSelected(currentModelList);
            if (currentModel != null)
            {
                txtMaCo.Text  = currentModel.MaCo;
                txtTenCo.Text = currentModel.TenCo;
            }
            bntLuu.Enabled    = true;
            bntTaoMoi.Enabled = true;
        }
コード例 #2
0
 /// <summary>
 /// To the entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="destination">The destination.</param>
 /// <returns>KichCo.</returns>
 public static KichCo ToEntity(this KichCoModel model, KichCo destination)
 {
     return(model.MapTo(destination));
 }
コード例 #3
0
 /// <summary>
 /// To the entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>KichCo.</returns>
 public static KichCo ToEntity(this KichCoModel model)
 {
     return(model.MapTo <KichCoModel, KichCo>());
 }
コード例 #4
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 = (KichCoModel)dataGridView.CurrentSelected(currentModelList);
     controller.Select(currentModel);
 }
コード例 #5
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 (txtMaCo.Text == "")
            {
                MessageBox.Show("Mã kích cỡ không được để rỗng");
                return;
            }
            if (txtTenCo.Text == "")
            {
                MessageBox.Show("Tên kích cỡ không được để rỗng");
                return;
            }

            currentModel = (KichCoModel)dataGridView.CurrentSelected(currentModelList);
            if (currentModel != null)
            {
                var cm = currentModelList.Where(c => c.MaCo == txtMaCo.Text &&
                                                c.ID != currentModel.ID);
                if (cm.Any())
                {
                    MessageBox.Show("Mã kích cỡ đã tồn tại trong một bản ghi khác");
                    return;
                }
                var ct = currentModelList.Where(c => c.TenCo == txtTenCo.Text &&
                                                c.ID != currentModel.ID);
                if (ct.Any())
                {
                    MessageBox.Show("Tên kích cỡ đã tồn tại trong một bản ghi khác");
                    return;
                }

                currentModel.MaCo  = txtMaCo.Text;
                currentModel.TenCo = txtTenCo.Text;
                controller.Update(currentModel);
                //re-update UI

                dataGridView.UpdateView("MaCo", currentModel.MaCo);
                dataGridView.UpdateView("TenCo", currentModel.TenCo);

                txtMaCo.Focus();
                txtMaCo.SelectAll();
                bntTaoMoi.Enabled = true;
                bntLuu.Enabled    = true;
            }
            else
            {
                var cm = currentModelList.Where(c => c.MaCo == txtMaCo.Text);
                if (cm.Any())
                {
                    MessageBox.Show("Mã kích cỡ đã tồn tại");
                    return;
                }
                var ct = currentModelList.Where(c => c.TenCo == txtTenCo.Text);
                if (ct.Any())
                {
                    MessageBox.Show("Tên kích cỡ đã tồn tại");
                    return;
                }
                currentModel = new KichCoModel {
                    MaCo  = txtMaCo.Text,
                    TenCo = txtTenCo.Text,
                };

                controller.Insert(currentModel);
                txtMaCo.Focus();
                txtMaCo.SelectAll();
                //txtTenCo.Text = "";
                controller.ReviewGrid();
                bntLuu.Enabled    = true;
                bntTaoMoi.Enabled = false;
            }
        }