Example #1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(txtCat.Text))
     {
         MessageBox.Show(this, "Tên danh mục không thể trống", "lỗi");
     }
     else
     {
         try
         {
             var cate = new CategoryVB
             {
                 NameCate = txtCat.Text,
                 Active   = chkActive.Checked
             };
             var tempCat = db.CategoryVBs.Where(m => m.NameCate == txtCat.Text).FirstOrDefault();
             if (tempCat != null)
             {
                 MessageBox.Show(this, "Tên danh mục đã tồn tại", "LỖI!");
             }
             else
             {
                 db.CategoryVBs.Add(cate);
                 db.SaveChanges();
                 MessageBox.Show(this, "Thêm mới thành công", "Success!");
                 Reload_Data();
             }
         }
         catch
         {
             MessageBox.Show(this, "Không thể thêm mới", "lỗi");
         }
     }
 }
Example #2
0
        private void Congvanden_Load(object sender, EventArgs e)
        {
            //Add new comment
            string filePath = ConfigurationManager.AppSettings["Role"];

            if (filePath == "1")
            {
                btnAdd.Enabled = btnSave.Enabled = btnDelete.Enabled = btnReload.Enabled = false;
            }
            this.KeyPreview     = true;
            lblID.Visible       = false;
            lblCurrentPage.Text = "1";
            lblTotalPage.Text   = "1";
            ReloadData();
            dpValidate.Value       = DateTime.Now.AddDays(3);
            dpValidate.Enabled     = false;
            cbValidate.Checked     = false;
            cbSearchByDate.Enabled = true;
            var items = new[] {
                new { Text = "Tất cả các ngày", Value = "1" },
                new { Text = "Tìm theo khoảng ngày", Value = "2" },
                new { Text = "Tìm ngày chính xác", Value = "3" },
            };

            cbSearchByDate.DisplayMember = "Text";
            cbSearchByDate.ValueMember   = "Value";
            cbSearchByDate.DataSource    = items;

            listCate = db.CategoryVBs.Where(m => m.Active == true).ToList();

            cbCategory.DisplayMember = "NameCate";
            cbCategory.ValueMember   = "Id";
            cbCategory.DataSource    = listCate;

            listCateSearch = db.CategoryVBs.ToList();

            var itemSearch = new CategoryVB {
                Id = 0, NameCate = "Tất cả"
            };

            listCateSearch.Insert(0, itemSearch);

            comboSearchCategory.DisplayMember = "NameCate";
            comboSearchCategory.ValueMember   = "Id";
            comboSearchCategory.DataSource    = listCateSearch;


            Application.EnableVisualStyles();
            txtSoCV.ShortcutsEnabled             = txtAnhscan.ShortcutsEnabled
                                                 = txtGhichu.ShortcutsEnabled = txtNguoikyCV.ShortcutsEnabled
                                                                                    = txtNoidung.ShortcutsEnabled = txtNoiguiCV.ShortcutsEnabled
                                                                                                                        = txtYkienchidao.ShortcutsEnabled = true;
            btnNext.Enabled = btnPrev.Enabled = false;
        }