Exemplo n.º 1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtChuongTrinh.Text.Trim()))
            {
                txtChuongTrinh.BorderColor          = Color.Red;
                txtChuongTrinh.PlaceholderText      = "bạn chưa nhập tên tiêu chuẩn";
                txtChuongTrinh.PlaceholderForeColor = Color.Red;
            }
            else
            {
                if (flagluu == 0)
                {
                    CHUONG_TRINH ct = QL_Chuong_TrinhBLL.Get(x => x.MaChuongTrinh.ToString() == txtID.Text.Trim());
                    if (ct == null)
                    {
                        ct = new CHUONG_TRINH();
                        ct.TenChuongTrinh = txtChuongTrinh.Text;
                        ct.MaTieuChuan    = Convert.ToInt32(cbTieuChuan.SelectedValue.ToString());
                        ct.ThoiGianDienRa = dtpkThoiGian.Value;
                        ct.DonViToChuc    = cbDonVi.Text;
                        QL_Chuong_TrinhBLL.Add(ct);
                        MessageBox.Show("Thêm Thành Công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ShowChuongTrinh(QL_Chuong_TrinhBLL.dschuongtrinh().Skip((pagenumber - 1) * numberRecord).Take(numberRecord).ToList());
                        loadbtnluu();
                        btnThemHD.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show("Thêm thất bại!!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    try
                    {
                        CHUONG_TRINH ct = QL_Chuong_TrinhBLL.Get(x => x.MaChuongTrinh.ToString() == txtID.Text.Trim());

                        ct.TenChuongTrinh = txtChuongTrinh.Text;
                        ct.MaTieuChuan    = Convert.ToInt32(cbTieuChuan.SelectedValue.ToString());
                        ct.ThoiGianDienRa = dtpkThoiGian.Value;
                        ct.DonViToChuc    = cbDonVi.Text;
                        QL_Chuong_TrinhBLL.Edit(ct);
                        MessageBox.Show("Sửa Thành Công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ShowChuongTrinh(QL_Chuong_TrinhBLL.dschuongtrinh().Skip((pagenumber - 1) * numberRecord).Take(numberRecord).ToList());
                        loadbtnluu();
                        btnThemHD.Enabled = true;
                    }
                    catch (NullReferenceException)
                    {
                        MessageBox.Show("Sửa thất bại!!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }