Example #1
0
 protected void btnTapdonhang_Click(object sender, EventArgs e)
 {//
     try
     {
         if (Session["idchangtau"] != null)
         {
             int _idchangtau;
             if (int.TryParse(Session["idchangtau"].ToString(), out _idchangtau))
             {
                 KhachHang _tblKhachHang = new KhachHang();
                 _tblKhachHang.HoTen    = hotenkhachhang.Text ?? null;
                 _tblKhachHang.GioiTinh = gioitinh.Text ?? null;
                 _tblKhachHang.Email    = Email.Text ?? null;
                 _tblKhachHang.DiaChi   = Diachi.Text ?? null;
                 _tblKhachHang.CMT      = CMT.Text ?? null;
                 _tblKhachHang.SDT      = SDT.Text ?? null;
                 db.KhachHangs.Add(_tblKhachHang);
                 db.SaveChanges();
                 ChangTau _ct      = db.ChangTaus.Where(p => p.Id == _idchangtau).FirstOrDefault();
                 DonHang  _donhang = new DonHang();;
                 Session["ThemDonHang"] = null;
                 Session["ThemDonHang"] = "Bạn đã đặt vé thành công";
                 var _don = new BanVeTauEntities();
                 _don.ThemDonHang(_tblKhachHang.Id, _idchangtau, "Chưa xác nhận");
                 db.SaveChanges();
                 Response.Redirect("~/Themdonhangthanhcong.aspx");
             }
         }
     }
     catch
     {
         //}
     }
 }
 protected void btn_themga_Click(object sender, EventArgs e)
 {
     try
     {
         ChangTau _ct = new ChangTau();
         _ct.MaChuyenDi   = txt_MaChuyenDi.Text == null ? "" : txt_MaChuyenDi.Text;
         _ct.TenChuyenDi  = txt_TenChuyenDi.Text == null ? "" : txt_TenChuyenDi.Text;
         _ct.DiemDi       = int.Parse(cb_DiemDi.SelectedValue.ToString());
         _ct.DiemDen      = int.Parse(cb_DiemDen.SelectedValue.ToString());
         _ct.NgayDen      = DateTime.Parse(txt_NgayDen.Text);
         _ct.NgayDi       = DateTime.Parse(txt_NgayDi.Text);
         _ct.SoLuongChang = int.Parse(txt_SoLuongChang.Text);
         _ct.GiaVe        = int.Parse(txt_GiaVe.Text);
         db.ChangTaus.Add(_ct);
         db.SaveChanges();
         LoadData();
         //Page.ClientScript.RegisterClientScriptBlock(e.GetType(), "alert", MyHelper.MessagerSuccess("Thêm ga đến thành công."), true);
         ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "alert", MyHelper.MessagerstrSuccess("Thêm chặng tàu thành công."), true);
         txt_MaChuyenDi.Text = txt_TenChuyenDi.Text = cb_DiemDen.Text = cb_DiemDi.Text = txt_NgayDen.Text = txt_NgayDi.Text = txt_SoLuongChang.Text = txt_GiaVe.Text = null;
     }
     catch
     {
     }
 }