Пример #1
0
        protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
        {
            switch (e.Item.Value)
            {
            case "Save":
                if (idPhuLuc == null)
                {
                    PhuLucHD phuluc = new PhuLucHD();
                    phuluc.IDHopDongLD    = idHopDong;
                    phuluc.SoPhuLuc       = txtSoPhuLuc.Text;
                    phuluc.TenPhuLuc      = txtTenPhuLuc.Text;
                    phuluc.NgayHieuLuc    = txtNgayUyQuyen.SelectedDate;
                    phuluc.NgayKy         = txtNgayKy.SelectedDate;
                    phuluc.IDNguoiDaiDien = Convert.ToInt32(cboNguoiDaiDien.SelectedValue);
                    if (txtTepDinhKem.UploadedFiles.Count > 0)
                    {
                        string targetFolder = txtTepDinhKem.TargetFolder;
                        phuluc.TepDinhKem = Path.Combine(Server.MapPath(targetFolder), txtSoPhuLuc.Text.Replace("/", "_") + "_" + txtTepDinhKem.UploadedFiles[0].FileName.Replace(" ", "_"));
                    }
                    phuluc.NgayTao  = phuluc.NgayCapNhat = DateTime.Now;
                    phuluc.NguoiTao = phuluc.NguoiCapNhat = idUser;
                    _entities.AddToPhuLucHDs(phuluc);
                    try
                    {
                        _entities.SaveChanges();
                        grvPhuLuc.Rebind();
                        RadWindowManager1.RadAlert("Thêm thông tin thành công", 285, 100, "Thông báo", "");
                        //LoadGrid();
                    }
                    catch (Exception ex)
                    {
                        RadWindowManager1.RadAlert("Thêm thông tin thất bại", 285, 100, "Lỗi", "");
                        throw ex;
                    }
                }
                else
                {
                    PhuLucHD phuluc = _entities.PhuLucHDs.Where(p => p.IDPhuLucHD == idPhuLuc).FirstOrDefault();
                    phuluc.IDHopDongLD    = idHopDong;
                    phuluc.SoPhuLuc       = txtSoPhuLuc.Text;
                    phuluc.TenPhuLuc      = txtTenPhuLuc.Text;
                    phuluc.NgayHieuLuc    = txtNgayUyQuyen.SelectedDate;
                    phuluc.NgayKy         = txtNgayKy.SelectedDate;
                    phuluc.IDNguoiDaiDien = Convert.ToInt32(cboNguoiDaiDien.SelectedValue);
                    if (txtTepDinhKem.UploadedFiles.Count > 0)
                    {
                        string targetFolder = txtTepDinhKem.TargetFolder;
                        phuluc.TepDinhKem = Path.Combine(Server.MapPath(targetFolder), txtSoPhuLuc.Text.Replace("/", "_") + "_" + txtTepDinhKem.UploadedFiles[0].FileName.Replace(" ", "_"));
                    }
                    phuluc.NgayCapNhat  = DateTime.Now;
                    phuluc.NguoiCapNhat = idUser;
                    try
                    {
                        _entities.SaveChanges();
                        grvPhuLuc.Rebind();
                        RadWindowManager1.RadAlert("Sửa thông tin thành công", 285, 100, "Thông báo", "");
                        //LoadGrid();
                    }
                    catch (Exception ex)
                    {
                        RadWindowManager1.RadAlert("Sửa thông tin thất bại", 285, 100, "Lỗi", "");
                        throw ex;
                    }
                }
                break;

            case "Reset":
                txtSoPhuLuc.Text = "";
                txtNgayKy.Clear();
                txtTenPhuLuc.Text = "";
                txtNgayUyQuyen.Clear();
                txtTepDinhKem.UploadedFiles.Clear();
                idPhuLuc = null;
                break;

            case "Print":
                Session["PrintType"] = "PhuLuc";
                Response.Redirect("InHD.aspx");
                break;

            case "HopDong":
                Session["idHD"] = idHopDong;
                Response.Redirect("SuaHopDong.aspx");
                break;
            }
        }