/// <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 = (TheLoaiModel)dataGridView.CurrentSelected(currentModelList);
            if (currentModel != null)
            {
                txtMaLoai.Text  = currentModel.MaLoai;
                txtTenLoai.Text = currentModel.TenLoai;
            }
            bntLuu.Enabled    = true;
            bntTaoMoi.Enabled = true;
        }
        public void ThemTheLoai(TheLoaiModel model)
        {
            TheLoai entity = new TheLoai()
            {
                TenTheLoai = model.TenTheLoai
            };

            _repository.Insert(entity);
        }
Beispiel #3
0
 public IActionResult ThemTheLoai(TheLoaiModel model)
 {
     if (ModelState.IsValid)
     {
         _theLoaiService.ThemTheLoai(model);
         return(Redirect("Index"));
     }
     return(View(model));
 }
        public void ThemTheLoai(TheLoaiModel model)
        {
            var theLoai = new TheLoai()
            {
                TenTheLoai = model.TenTheLoai
            };

            _theloaiRepository.Insert(theLoai);
        }
Beispiel #5
0
 private void gridTheLoai_SelectedItemChanged(object sender, DevExpress.Xpf.Grid.SelectedItemChangedEventArgs e)
 {
     try
     {
         TheLoaiModel select  = gridTheLoai.SelectedItem as TheLoaiModel;
         TheLoai      theloai = theloaiControll.GetById(select.MaTheLoai);
         _txtmatheloai.Text  = theloai.MaTheLoai;
         _txttentheloai.Text = theloai.TenTheLoai;
     }
     catch { }
 }
Beispiel #6
0
 public TheLoaiModel UpdateTL([FromBody] TheLoaiModel model)
 {
     if (model.image != null)
     {
         var arrData = model.image.Split(';');
         if (arrData.Length == 3)
         {
             var savePath  = $@"assets/Upload/TheLoai/{arrData[0]}";
             var savePathh = $@"assets/Upload/TheLoai/{arrData[0]}";
             model.image = $"{savePath}";
             SaveFileFromBase64String(savePath, arrData[2]);
             SaveFileFromBase64(savePathh, arrData[2]);
         }
     }
     theloai.Update(model);
     return(model);
 }
Beispiel #7
0
        public bool Update(TheLoaiModel model)
        {
            string msgError = "";

            try
            {
                var result = _dbHelper.ExecuteScalarSProcedureWithTransaction(out msgError, "sp_theloai_update",
                                                                              "@id", model.id,
                                                                              "@tentheloai", model.tentheloai,
                                                                              "@image", model.image);
                if ((result != null && !string.IsNullOrEmpty(result.ToString())) || !string.IsNullOrEmpty(msgError))
                {
                    throw new Exception(Convert.ToString(result) + msgError);
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 /// <summary>
 /// To the entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="destination">The destination.</param>
 /// <returns>TheLoai.</returns>
 public static TheLoai ToEntity(this TheLoaiModel model, TheLoai destination)
 {
     return(model.MapTo(destination));
 }
 /// <summary>
 /// To the entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>TheLoai.</returns>
 public static TheLoai ToEntity(this TheLoaiModel model)
 {
     return(model.MapTo <TheLoaiModel, TheLoai>());
 }
 public List <TheLoaiModel> GetListTableModelBySearch(string search)
 {
     return(TheLoaiModel.ToListByListTheLoai(_theloaiControls.GetBySearch(search)));
 }
Beispiel #11
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 = (TheLoaiModel)dataGridView.CurrentSelected(currentModelList);
     controller.Select(currentModel);
 }
Beispiel #12
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 (txtMaLoai.Text == "")
            {
                MessageBox.Show("Mã thể loại không được để rỗng");
                return;
            }
            if (txtTenLoai.Text == "")
            {
                MessageBox.Show("Tên thể loại không được để rỗng");
                return;
            }

            currentModel = (TheLoaiModel)dataGridView.CurrentSelected(currentModelList);
            if (currentModel != null)
            {
                var cm = currentModelList.Where(c => c.MaLoai == txtMaLoai.Text &&
                                                c.ID != currentModel.ID);
                if (cm.Any())
                {
                    MessageBox.Show("Mã thể loại đã tồn tại trong một bản ghi khác");
                    return;
                }
                var ct = currentModelList.Where(c => c.TenLoai == txtTenLoai.Text &&
                                                c.ID != currentModel.ID);
                if (ct.Any())
                {
                    MessageBox.Show("Tên thể loại đã tồn tại trong một bản ghi khác");
                    return;
                }

                currentModel.MaLoai  = txtMaLoai.Text;
                currentModel.TenLoai = txtTenLoai.Text;
                controller.Update(currentModel);
                //re-update UI

                dataGridView.UpdateView("MaLoai", currentModel.MaLoai);
                dataGridView.UpdateView("TenLoai", currentModel.TenLoai);

                txtMaLoai.Focus();
                txtMaLoai.SelectAll();
                bntTaoMoi.Enabled = true;
                bntLuu.Enabled    = true;
            }
            else
            {
                var cm = currentModelList.Where(c => c.MaLoai == txtMaLoai.Text);
                if (cm.Any())
                {
                    MessageBox.Show("Mã thể loại đã tồn tại");
                    return;
                }
                var ct = currentModelList.Where(c => c.TenLoai == txtTenLoai.Text);
                if (ct.Any())
                {
                    MessageBox.Show("Tên thể loại đã tồn tại");
                    return;
                }
                currentModel = new TheLoaiModel {
                    MaLoai  = txtMaLoai.Text,
                    TenLoai = txtTenLoai.Text,
                };

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