Пример #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                // Sửa dữ liệu
                TourDLEntities    db  = new TourDLEntities();
                QLTour.PhuongTien obj = db.PhuongTien.FirstOrDefault(x => x.MaPT == txtMaPT.Text);
                if (obj == null)
                {
                    Response.Redirect("PhuongTiens.aspx");
                }
                else
                {
                    //obj.MaPT = txtMaPT.Text;
                    obj.TenPT = txtTenPT.Text;
                    obj.MaLPT = cmbMaLPT.SelectedValue;
                    obj.SoCho = Int32.Parse(cmbSoCho.SelectedValue);

                    db.SaveChanges();
                    Response.Redirect("PhuongTiens.aspx");
                }
            }
            catch
            {
                // Lỗi
            }
        }
Пример #2
0
        protected void btnXoa_Command1(object sender, CommandEventArgs e)
        {
            string         MaPT = e.CommandArgument.ToString();
            TourDLEntities db   = new TourDLEntities();

            QLTour.PhuongTien obj = db.PhuongTien.FirstOrDefault(x => x.MaPT == MaPT);
            if (obj != null)
            {
                db.PhuongTien.Remove(obj);
                db.SaveChanges();
                getData();
            }
        }
Пример #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         getcmbMaLPT();
         getcmbSoCho();
         // kiểm tra trường hợp sửa/thêm mới
         // nếu url có dạng ?masp=123 => sửa, ngược lại là thêm mới
         if (Request.QueryString["MaPT"] == null)
         {
             // thêm mới
             btnSave.Visible  = false;
             btnAdd.Visible   = true;
             txtMaPT.Text     = Request.QueryString["MaPT"];
             txtMaPT.Enabled  = false;
             txtMaPT.CssClass = txtMaPT.CssClass + " form-control";
         }
         else
         {
             // Sửa
             btnSave.Visible  = true;
             btnAdd.Visible   = false;
             txtMaPT.Text     = Request.QueryString["MaPT"];
             txtMaPT.Enabled  = false;
             txtMaPT.CssClass = txtMaPT.CssClass + " form-control";
             // Query về db để lấy các thông tin còn lại
             TourDLEntities    db  = new TourDLEntities();
             QLTour.PhuongTien obj = db.PhuongTien.FirstOrDefault(x => x.MaPT == txtMaPT.Text);
             if (obj == null)
             {
                 Response.Redirect("PhuongTiens.aspx");
             }
             else
             {
                 txtMaPT.Text           = obj.MaPT;
                 txtTenPT.Text          = obj.TenPT;
                 cmbMaLPT.SelectedValue = obj.MaLPT;
                 cmbSoCho.SelectedValue = obj.SoCho.ToString();
             }
         }
     }
 }
Пример #4
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                TourDLEntities    db  = new TourDLEntities();
                QLTour.PhuongTien obj = db.PhuongTien.FirstOrDefault(x => x.MaPT == txtMaPT.Text);
                if (obj != null)
                {
                    // Cảnh báo mã sản phẩm đã tồn tại
                }
                else
                {
                    if (txtTenPT.Text == "")
                    {
                        lbErrordangky.Text = "Bạn chưa nhập đủ thông tin!!!";
                    }
                    else
                    {
                        obj       = new QLTour.PhuongTien();
                        obj.MaPT  = GetMaPT();
                        obj.TenPT = txtTenPT.Text;
                        obj.MaLPT = cmbMaLPT.SelectedValue;
                        obj.SoCho = Int32.Parse(cmbSoCho.SelectedValue);

                        db.PhuongTien.Add(obj);
                        db.SaveChanges();
                        Response.Redirect("PhuongTiens.aspx");
                    }
                }
            }
            catch
            {
                // Lỗi
                lbErrordangky.Text = "Lỗi không thể đăng ký!!!";
            }
        }