Example #1
0
        public bool SuaDanhMucVatTu(DTO_Danhmucvt danhMuc)
        {
            try
            {
                _conn.Open();

                string query = string.Format($"UPDATE DANHMUCVATTU SET Tendanhmuc='{danhMuc.TENDANHMUC}' WHERE Maloai={danhMuc.MALOAI}");

                SqlCommand cmd = new SqlCommand(query, _conn);

                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                exception?.Invoke(ex);
                return(false);
            }
            finally
            {
                _conn.Close();
            }
        }
Example #2
0
        private void BtnSua_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = dtgvDanhMuc.SelectedRows[0];

            int    nMaDanhMuc    = int.Parse(row.Cells[0].Value.ToString());
            string strTenDanhMuc = row.Cells[1].Value.ToString();

            if (txbDanhMuc.Text == "")
            {
                MessageBox.Show("Tên danh mục không được để trống!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (strTenDanhMuc == txbDanhMuc.Text)
            {
                MessageBox.Show("Tên mới trùng với tên cũ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                DialogResult rs = MessageBox.Show($"Sửa danh mục {strTenDanhMuc} thành {txbDanhMuc.Text} ?", "Thông báo",
                                                  MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

                if (rs == DialogResult.OK)
                {
                    DTO_Danhmucvt danhMuc = new DTO_Danhmucvt(nMaDanhMuc, txbDanhMuc.Text);

                    bool isEdited = bus_DanhMuc.SuaDanhMucVatTu(danhMuc);

                    Exception ex = bus_DanhMuc.GetException();

                    if (ex != null)
                    {
                        MessageBox.Show(ex.Message, "Notification");
                        return;
                    }

                    if (isEdited == true)
                    {
                        dtgvDanhMuc.SelectedRows[0].Cells[1].Value = txbDanhMuc.Text;
                        MessageBox.Show($"Đã sửa danh mục {strTenDanhMuc} thành {txbDanhMuc.Text} !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Không thể sửa!", "Thông báo");
                    }
                }
            }
        }
Example #3
0
        public List <DTO_Danhmucvt> TimKiemDanhMuc(string TenDanhMuc)
        {
            List <DTO_Danhmucvt> listDanhMuc = new List <DTO_Danhmucvt>();

            DataTable dt = dal_DanhMuc.TimKiemDanhMuc(TenDanhMuc);

            foreach (DataRow row in dt.Rows)
            {
                DTO_Danhmucvt temp = new DTO_Danhmucvt();

                temp.MALOAI     = int.Parse(row["Maloai"].ToString());
                temp.TENDANHMUC = row["Tendanhmuc"].ToString();

                listDanhMuc.Add(temp);
            }

            return(listDanhMuc);
        }
Example #4
0
 public bool SuaDanhMucVatTu(DTO_Danhmucvt danhMuc)
 {
     return(dal_DanhMuc.SuaDanhMucVatTu(danhMuc));
 }