예제 #1
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            var dieu = new Dieu()
            {
                Id     = Int64.Parse(lblId.Text),
                MaDieu = txtMaDieu.Text.Trim(),
                MoTa   = txtMoTa.Text.Trim(),
                GhiChu = txtGhiChu.Text.Trim(),
            };

            bool success = bDieu.Update(dieu);

            if (success)
            {
                XtraMessageBox.Show(ValueContants.SuccessMesage.CapNhatThanhCong, ValueContants.SuccessMesage.ThongBao, MessageBoxButtons.OK, MessageBoxIcon.Information);
                LoadDanhMucDieu();
                ClearAll();
            }
            else
            {
                XtraMessageBox.Show(ValueContants.ErrorMessage.LoiLuu, ValueContants.ErrorMessage.CanhBao, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #2
0
        public bool Insert(Dieu dto)
        {
            if (string.IsNullOrEmpty(dto.MaDieu) || string.IsNullOrEmpty(dto.MoTa))
            {
                return(false);
            }

            int dem = context.Dieux.Count(x => x.MaDieu.Contains(dto.MaDieu));

            if (dem > 0)
            {
                return(false);
            }

            try
            {
                context.Dieux.Add(dto);
                context.SaveChanges();

                return(true);
            }
            catch { return(false); }
        }
예제 #3
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            var dieu = new Dieu()
            {
                MaDieu   = txtMaDieu.Text.Trim(),
                MoTa     = txtMoTa.Text.Trim(),
                GhiChu   = txtGhiChu.Text.Trim(),
                IsDelete = false,
            };

            bool success = bDieu.Insert(dieu);

            if (success)
            {
                XtraMessageBox.Show(ValueContants.SuccessMesage.LuuThanhCong, ValueContants.SuccessMesage.ThongBao, MessageBoxButtons.OK, MessageBoxIcon.Information);
                ClearAll();
                LoadDanhMucDieu();
            }
            else
            {
                XtraMessageBox.Show(ValueContants.ErrorMessage.LoiLuu, ValueContants.ErrorMessage.CanhBao, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #4
0
        public bool Update(Dieu dto)
        {
            if (string.IsNullOrEmpty(dto.MaDieu) || string.IsNullOrEmpty(dto.MoTa))
            {
                return(false);
            }

            var dieu = context.Dieux.Find(dto.Id);

            if (dieu == null)
            {
                return(false);
            }
            try
            {
                dieu.MaDieu = dto.MaDieu;
                dieu.MoTa   = dto.MoTa;
                dieu.GhiChu = dto.GhiChu;
                context.SaveChanges();

                return(true);
            }
            catch { return(false); }
        }