Ejemplo n.º 1
0
 private void deleteTopic_Click(object sender, EventArgs e)
 {
     if (_topic != null && !string.IsNullOrWhiteSpace(topicTitle.Text))
     {
         using (var db = new DuoContext()) {
             _topic.IsDeleted = true;
             var chk = db.Update <Topic>(_topic);
         }
         LoadData();
         return;
     }
     MessageBox.Show("Vui lòng chọn một chủ đề hay nhập thông tin chủ đề", "Dữ liệu chưa được chọn"
                     , MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Ejemplo n.º 2
0
 private void downTopic_Click(object sender, EventArgs e)
 {
     if (_topic != null && !string.IsNullOrWhiteSpace(topicTitle.Text))
     {
         int sort = _topic.Sort;
         using (var db = new DuoContext()) {
             var upTopic = db.Topics.FirstOrDefault(x => !x.IsDeleted && x.Sort > sort);
             if (upTopic == null)
             {
                 MessageBox.Show("Không thể đưa chủ đề xuống dưới vì nó đã ở dưới cùng", "Dữ liệu không thể thay đổi"
                                 , MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
             _topic.Sort  = upTopic.Sort;
             upTopic.Sort = sort;
             db.Update <Topic>(_topic);
             db.Update <Topic>(upTopic);
         }
         LoadData();
         return;
     }
     MessageBox.Show("Vui lòng chọn một chủ đề hay nhập thông tin chủ đề", "Dữ liệu chưa được chọn"
                     , MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Ejemplo n.º 3
0
 private void saveChangeTopic_Click(object sender, EventArgs e)
 {
     if (_topic == null && !string.IsNullOrWhiteSpace(topicTitle.Text))
     {
         var hashData = HashService.ComputeSha256Hash(topicTitle.Text);
         using (var db = new DuoContext()) {
             if (db.Topics.AsNoTracking().Any(x => !x.IsDeleted && x.HashCompare.Equals(hashData)))
             {
                 MessageBox.Show("Tiêu đề của chủ đề đã tồn tại trong Database", "Cảnh báo trùng lập dữ liệu"
                                 , MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 return;
             }
             var count = db.Topics.AsNoTracking().Count();
             var topic = new Topic()
             {
                 Title       = topicTitle.Text,
                 HashCompare = hashData,
                 IsDeleted   = false,
                 IsHide      = isHide.Checked,
                 Sort        = count + 1
             };
             db.Topics.Add(topic);
             db.SaveChanges();
         }
         LoadData();
         return;
     }
     if (_topic != null && !string.IsNullOrWhiteSpace(topicTitle.Text))
     {
         using (var db = new DuoContext()) {
             _topic.Title       = topicTitle.Text;
             _topic.HashCompare = HashService.ComputeSha256Hash(topicTitle.Text);
             _topic.IsHide      = isHide.Checked;
             var chk = db.Update <Topic>(_topic);
         }
         LoadData();
         return;
     }
     MessageBox.Show("Vui lòng chọn một chủ đề hay nhập thông tin chủ đề", "Dữ liệu chưa có"
                     , MessageBoxButtons.OK, MessageBoxIcon.Information);
 }