Exemplo n.º 1
0
 public int Them_LoaiTK(LOAI_TK tk)
 {
     try
     {
         qlltk.LOAI_TKs.InsertOnSubmit(tk);
         qlltk.SubmitChanges();
         return(0);
     }
     catch (Exception ex) { return(1); }
 }
Exemplo n.º 2
0
 public int Them_TK(TAI_KHOAN tk)
 {
     try
     {
         qlq.TAI_KHOANs.InsertOnSubmit(tk);
         qlq.SubmitChanges();
         return(0);
     }
     catch (Exception ex) { return(1); }
 }
Exemplo n.º 3
0
 //thêm phiếu thu
 public int Them_PT(PHIEU_THU p)
 {
     if (KT_KhoaChinh(p.MAPTHU) == 1)
     {
         return(1);
     }
     qlt.PHIEU_THUs.InsertOnSubmit(p);
     update_tien_them(p);
     qlt.SubmitChanges();
     return(0);
 }
Exemplo n.º 4
0
 //thêm
 public int Them_PhieuChi(PHIEU_CHI p)
 {
     try {
         if (KT_KhoaChinh(p.MA_PCHI) == 1)
         {
             return(0);
         }
         qlc.PHIEU_CHIs.InsertOnSubmit(p);
         qlc.SubmitChanges();
         return(1);
     }
     catch (Exception ex) { return(0); }
 }
Exemplo n.º 5
0
    protected void GridView3_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //tham chieu den các đối tượng tai dong hieu chinh hien tai
        TextBox txt_HopSo      = GridView3.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox;
        TextBox txt_KTTongThe  = GridView3.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox;
        TextBox txt_TrongLuong = GridView3.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox;
        TextBox txt_ChieuDai   = GridView3.Rows[e.RowIndex].Cells[6].Controls[0] as TextBox;
        TextBox txt_ChieuRong  = GridView3.Rows[e.RowIndex].Cells[7].Controls[0] as TextBox;

        //chuan bi
        int Ma_Xe_dangsua = (int)GridView3.DataKeys[e.RowIndex].Value;
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Xe obj = tam_context.Xes.SingleOrDefault(chungloaisp => chungloaisp.Ma_Xe == Ma_Xe_dangsua);

        obj.Ma_Xe       = Ma_Xe_dangsua;
        obj.Hop_So      = txt_HopSo.Text;
        obj.KT_Tong_The = txt_KTTongThe.Text;
        obj.Trong_Luong = int.Parse(txt_TrongLuong.Text);
        obj.Chieu_Dai   = int.Parse(txt_ChieuDai.Text);
        obj.Chieu_Rong  = int.Parse(txt_ChieuRong.Text);
        //thuc hien
        tam_context.SubmitChanges();
        GridView3.EditIndex = -1;
        show_chungloai3();
    }
Exemplo n.º 6
0
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //tham chieu den các đối tượng tai dong hieu chinh hien tai
        TextBox txt_LoaiDongCo      = GridView1.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox;
        TextBox txt_DungTich_Xilanh = GridView1.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox;
        TextBox txt_DungTich_NL     = GridView1.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox;
        TextBox txt_CongSuat        = GridView1.Rows[e.RowIndex].Cells[6].Controls[0] as TextBox;
        TextBox txt_Moment          = GridView1.Rows[e.RowIndex].Cells[7].Controls[0] as TextBox;
        TextBox txt_TocDoToiDa      = GridView1.Rows[e.RowIndex].Cells[8].Controls[0] as TextBox;

        //chuan bi
        int Ma_Xe_dangsua = (int)GridView1.DataKeys[e.RowIndex].Value;
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Xe obj = tam_context.Xes.SingleOrDefault(chungloaisp => chungloaisp.Ma_Xe == Ma_Xe_dangsua);

        obj.Ma_Xe                = Ma_Xe_dangsua;
        obj.Loai_Dong_Co         = txt_LoaiDongCo.Text;
        obj.Dung_Tich            = txt_DungTich_Xilanh.Text;
        obj.Dung_Tich_Nhien_Lieu = int.Parse(txt_DungTich_NL.Text);
        obj.Cong_Suat            = txt_CongSuat.Text;
        obj.Mo_men               = txt_Moment.Text;
        obj.Van_Toc_Toi_Da       = int.Parse(txt_TocDoToiDa.Text);
        //thuc hien
        tam_context.SubmitChanges();
        GridView1.EditIndex = -1;
        show_chungloai1();
    }
 protected void imgbtnThem_Click(object sender, ImageClickEventArgs e)
 {
     if (txtTenDangNhap.Text == "")
     {
         lblErrMatKhau.Visible = true;
     }
     else if (lblErrMatKhau.Text == "")
     {
         lblErrMatKhau.Visible = true;
     }
     else
     {
         //them moi chung loại san pham
         LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
         Nguoi_Dung           obj         = new Nguoi_Dung
         {
             Ten_Nguoi_Dung = txtTenDangNhap.Text,
             Mat_Khau       = txtMatKhau.Text,
             Admin          = int.Parse(ddlAdmin.SelectedItem.Value),
             Ho_Ten         = txtHoTen.Text,
             Gioi_Tinh      = ddlGioiTinh.Text,
             Dia_Chi        = txtDiaChi.Text,
             CMND           = txtCMND.Text,
             Email          = txtEmail.Text,
             SDT            = txtSDT.Text,
         };
         tam_context.Nguoi_Dungs.InsertOnSubmit(obj);
         tam_context.SubmitChanges();
     }
     show_chungloai();
     show_chungloai1();
 }
    protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //TextBox txt_HoTen = GridView2.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox;
        //DropDownList txt_GioiTinh = GridView2.Rows[e.RowIndex].Cells[5].Controls[0] as DropDownList;
        //TextBox txt_DiaChi = GridView2.Rows[e.RowIndex].Cells[6].Controls[0] as TextBox;
        //TextBox txt_CMND = GridView2.Rows[e.RowIndex].Cells[7].Controls[0] as TextBox;
        //TextBox txt_Email = GridView2.Rows[e.RowIndex].Cells[8].Controls[0] as TextBox;
        //TextBox txt_SDT = GridView2.Rows[e.RowIndex].Cells[9].Controls[0] as TextBox;

        TextBox      txt_HoTen    = GridView2.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox;
        DropDownList ddl_GioiTinh = GridView2.Rows[e.RowIndex].FindControl("ddlGioiTinh") as DropDownList;
        TextBox      txt_DiaChi   = GridView2.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox;
        TextBox      txt_CMND     = GridView2.Rows[e.RowIndex].Cells[6].Controls[0] as TextBox;
        TextBox      txt_Email    = GridView2.Rows[e.RowIndex].Cells[7].Controls[0] as TextBox;
        TextBox      txt_SDT      = GridView2.Rows[e.RowIndex].Cells[8].Controls[0] as TextBox;
        //chuan bi
        int Ma_Nguoi_Dung_dangsua        = (int)GridView2.DataKeys[e.RowIndex].Value;
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Nguoi_Dung           obj         = tam_context.Nguoi_Dungs.SingleOrDefault(Nguoi_Dung => Nguoi_Dung.Ma_Nguoi_Dung == Ma_Nguoi_Dung_dangsua);

        obj.Ma_Nguoi_Dung = Ma_Nguoi_Dung_dangsua;
        obj.Ho_Ten        = txt_HoTen.Text;
        obj.Gioi_Tinh     = ddl_GioiTinh.SelectedItem.Value;
        obj.Dia_Chi       = txt_DiaChi.Text;
        obj.CMND          = txt_CMND.Text;
        obj.Email         = txt_Email.Text;
        obj.SDT           = txt_SDT.Text;
        //thuc hien
        tam_context.SubmitChanges();
        GridView2.EditIndex = -1;
        show_chungloai();
        show_chungloai1();
    }
Exemplo n.º 9
0
 public int Them_tiente(TIEN_TE p)
 {
     if (KT_KhoaChinh(p.MALOAI) > 0)
     {
         return(1);// trùng mã
     }
     try
     {
         qltt.TIEN_TEs.InsertOnSubmit(p);
         qltt.SubmitChanges();
         return(0);
     }
     catch (Exception ex)
     {
         return(2);//lỗi
     }
 }
Exemplo n.º 10
0
    protected void btnThem_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 1;
        lblLoaiXe.Text             = ddlLoaiXe.SelectedValue;
        lblTenXe.Text          = txtTenXe.Text;
        lblThongTin.Text       = txtThongTin.Text;
        lblLoaiDongCo.Text     = txtLoaiDongCo.Text;
        lblDungTichXilanh.Text = txtDungTichXilanh.Text;
        lblCongSuat.Text       = txtCongSuat.Text;
        lblMoment.Text         = txtMoment.Text;
        lblVanToc.Text         = txtVanToc.Text;
        lblHopSo.Text          = txtHopSo.Text;
        lblDungTichNL.Text     = txtDungTichNL.Text;
        lblKTTongThe.Text      = txtKT_TongThe.Text;
        lblChieuDai.Text       = txtChieuDai.Text;
        lblChieuRong.Text      = txtChieuRong.Text;
        lblTrongLuong.Text     = txtTrongLuong.Text;
        lblMauSac.Text         = txtMauSac.Text;
        lblGia.Text            = txtGia.Text;
        if (fuPicture.HasFile)
        {
            if (CheckFileType(fuPicture.FileName))
            {
                fuPicture.SaveAs(Server.MapPath("~/San_Pham/") + fuPicture.FileName);
                Image1.ImageUrl = "~/San_Pham/" + fuPicture.FileName;
            }
            else
            {
                lblMessage.Text = "Loại file không hợp lệ";
            }
        }
        //them moi chung loại san pham
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Xe obj = new Xe
        {
            Ten_xe               = txtTenXe.Text,
            Loai_Xe              = int.Parse(ddlLoaiXe.SelectedValue),
            Thong_Tin            = txtThongTin.Text,
            Hinh_Anh             = fuPicture.FileName,
            Loai_Dong_Co         = txtLoaiDongCo.Text,
            Dung_Tich            = txtDungTichXilanh.Text,
            Cong_Suat            = txtCongSuat.Text,
            Mo_men               = txtMoment.Text,
            Van_Toc_Toi_Da       = int.Parse(txtVanToc.Text),
            Hop_So               = txtHopSo.Text,
            Dung_Tich_Nhien_Lieu = int.Parse(txtDungTichNL.Text),
            KT_Tong_The          = txtKT_TongThe.Text,
            Trong_Luong          = int.Parse(txtTrongLuong.Text),
            Chieu_Dai            = int.Parse(txtChieuDai.Text),
            Chieu_Rong           = int.Parse(txtChieuRong.Text),
            Mau_Sac              = txtMauSac.Text,
            Gia = int.Parse(txtGia.Text),
        };

        tam_context.Xes.InsertOnSubmit(obj);
        tam_context.SubmitChanges();
        // show_chungloai();
    }
Exemplo n.º 11
0
    protected void GridView4_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int Ma_Xe_canxoa = (int)GridView4.DataKeys[e.RowIndex].Value;
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Xe obj = tam_context.Xes.SingleOrDefault(chungloaisp => chungloaisp.Ma_Xe == Ma_Xe_canxoa);

        tam_context.Xes.DeleteOnSubmit(obj);
        tam_context.SubmitChanges();
        show_chungloai();
    }
Exemplo n.º 12
0
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int Ma_VP_canxoa = (int)GridView1.DataKeys[e.RowIndex].Value;
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Van_Phong            obj         = tam_context.Van_Phongs.SingleOrDefault(Van_Phong => Van_Phong.id == Ma_VP_canxoa);

        tam_context.Van_Phongs.DeleteOnSubmit(obj);
        tam_context.SubmitChanges();
        show_chungloai();
    }
Exemplo n.º 13
0
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int Ma_TT_canxoa = (int)GridView1.DataKeys[e.RowIndex].Value;
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Trang_Thai           obj         = tam_context.Trang_Thais.SingleOrDefault(Trang_Thai => Trang_Thai.id == Ma_TT_canxoa);

        tam_context.Trang_Thais.DeleteOnSubmit(obj);
        tam_context.SubmitChanges();
        show_chungloai();
    }
Exemplo n.º 14
0
    protected void btnThem_Click1(object sender, EventArgs e)
    {
        //them moi chung loại san pham
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Loai_Xe obj = new Loai_Xe
        {
            Ten_Loai_Xe = txtTenLoaiXe.Text,
        };

        tam_context.Loai_Xes.InsertOnSubmit(obj);
        tam_context.SubmitChanges();
        show_chungloai();
    }
Exemplo n.º 15
0
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //tham chieu den các đối tượng tai dong hieu chinh hien tai
        TextBox txt_Ten_VP = GridView1.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox;

        //chuan bi
        int Ma_VP_dangsua = (int)GridView1.DataKeys[e.RowIndex].Value;
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Van_Phong            obj         = tam_context.Van_Phongs.SingleOrDefault(Van_Phong => Van_Phong.id == Ma_VP_dangsua);

        obj.id     = Ma_VP_dangsua;
        obj.Ten_VP = txt_Ten_VP.Text;

        //thuc hien
        tam_context.SubmitChanges();
        GridView1.EditIndex = -1;
        show_chungloai();
    }
Exemplo n.º 16
0
    protected void btnThem_Click1(object sender, EventArgs e)
    {
        //them moi chung loại san pham
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();

        string    sql_maxid   = "select Max(id) as MAXID from Trang_Thai";
        DataTable dt          = XLDL.docbang(sql_maxid);
        int       maxid       = int.Parse(dt.Rows[0][0].ToString());
        int       matrangthai = maxid + 1;

        Trang_Thai obj = new Trang_Thai
        {
            id         = matrangthai,
            tinh_trang = txtTenTrangThai.Text,
        };

        tam_context.Trang_Thais.InsertOnSubmit(obj);
        tam_context.SubmitChanges();
        show_chungloai();
    }
Exemplo n.º 17
0
    protected void btnThem_Click1(object sender, EventArgs e)
    {
        //them moi chung loại san pham
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();

        string    sql_maxid  = "select Max(id) as MAXID from Van_Phong";
        DataTable dt         = XLDL.docbang(sql_maxid);
        int       maxid      = int.Parse(dt.Rows[0][0].ToString());
        int       mavanphong = maxid + 1;

        Van_Phong obj = new Van_Phong
        {
            id     = mavanphong,
            Ten_VP = txtTenVanPhong.Text,
        };

        tam_context.Van_Phongs.InsertOnSubmit(obj);
        tam_context.SubmitChanges();
        show_chungloai();
    }
Exemplo n.º 18
0
    protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //tham chieu den các đối tượng tai dong hieu chinh hien tai
        TextBox      txt_TenXe    = GridView2.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox;
        DropDownList ddlLoaiXe    = (DropDownList)GridView2.Rows[e.RowIndex].FindControl("ddl_LoaiXe");
        TextBox      txt_ThongTin = GridView2.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox;
        Image        img_HinhAnh  = (Image)GridView2.Rows[e.RowIndex].FindControl("img_Hinh_Anh");
        TextBox      txt_MauSac   = GridView2.Rows[e.RowIndex].Cells[7].Controls[0] as TextBox;
        TextBox      txt_GiaTien  = GridView2.Rows[e.RowIndex].Cells[8].Controls[0] as TextBox;
        FileUpload   fu_HinhAnh   = (FileUpload)GridView2.Rows[e.RowIndex].FindControl("fileUpload");

        //chuan bi
        int Ma_Xe_dangsua = (int)GridView2.DataKeys[e.RowIndex].Value;
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Xe obj = tam_context.Xes.SingleOrDefault(chungloaisp => chungloaisp.Ma_Xe == Ma_Xe_dangsua);

        obj.Ma_Xe     = Ma_Xe_dangsua;
        obj.Loai_Xe   = int.Parse(ddlLoaiXe.SelectedValue);
        obj.Ten_xe    = txt_TenXe.Text;
        obj.Thong_Tin = txt_ThongTin.Text;

        if (fu_HinhAnh.HasFile)
        {
            if (CheckFileType(fu_HinhAnh.FileName))
            {
                fu_HinhAnh.SaveAs(Server.MapPath("~/San_Pham/") + fu_HinhAnh.FileName);
            }
            else
            {
                lblMessage.Text = "Loại file không hợp lệ";
            }
        }

        obj.Hinh_Anh = fu_HinhAnh.FileName;
        obj.Mau_Sac  = txt_MauSac.Text;
        obj.Gia      = int.Parse(txt_GiaTien.Text);
        //thuc hien
        tam_context.SubmitChanges();
        GridView2.EditIndex = -1;
        show_chungloai2();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //tham chieu den các đối tượng tai dong hieu chinh hien tai
        // TextBox txt_MaNguoiDung = GridView1.Rows[e.RowIndex].Cells[0].Controls[0] as TextBox;
        Label        lblTenNguoiDung = GridView1.Rows[e.RowIndex].Cells[3].FindControl("lblTenNguoiDung") as Label;
        TextBox      txt_MatKhau     = GridView1.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox;
        DropDownList ddlAdmin        = GridView1.Rows[e.RowIndex].FindControl("ddlAdmin") as DropDownList;

        //chuan bi
        int Ma_Nguoi_Dung_dangsua        = (int)GridView1.DataKeys[e.RowIndex].Value;
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Nguoi_Dung           obj         = tam_context.Nguoi_Dungs.SingleOrDefault(Nguoi_Dung => Nguoi_Dung.Ma_Nguoi_Dung == Ma_Nguoi_Dung_dangsua);

        obj.Ma_Nguoi_Dung  = Ma_Nguoi_Dung_dangsua;
        obj.Ten_Nguoi_Dung = lblTenNguoiDung.Text;
        obj.Mat_Khau       = txt_MatKhau.Text;
        obj.Admin          = int.Parse(ddlAdmin.SelectedItem.Value);

        //thuc hien
        tam_context.SubmitChanges();
        GridView1.EditIndex = -1;
        show_chungloai();
        show_chungloai1();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int Ma_Nguoi_Dung_canxoa         = (int)GridView1.DataKeys[e.RowIndex].Value;
        LinQtoSQLDataContext tam_context = new LinQtoSQLDataContext();
        Nguoi_Dung           obj         = tam_context.Nguoi_Dungs.SingleOrDefault(Nguoi_Dung => Nguoi_Dung.Ma_Nguoi_Dung == Ma_Nguoi_Dung_canxoa);
        string    sql = "select * from Don_Dat_Hang where Ma_KH = " + Ma_Nguoi_Dung_canxoa;
        DataTable DDH = DataProvider.getData(sql);

        if (DDH.Rows.Count > 0)
        {
            for (int i = 0; i < DDH.Rows.Count; i++)
            {
                int    Ma_DDH         = int.Parse(DDH.Rows[i]["Ma_DDH"].ToString());
                string sqldeleteCTDDH = "delete from Chi_Tiet_DDH where Ma_DDH = " + Ma_DDH;
                DataProvider.runSQL(sqldeleteCTDDH);
            }
            string sqldeleteDDH = "delete from Don_Dat_Hang where Ma_KH = " + Ma_Nguoi_Dung_canxoa;
            DataProvider.runSQL(sqldeleteDDH);
        }
        tam_context.Nguoi_Dungs.DeleteOnSubmit(obj);
        tam_context.SubmitChanges();
        show_chungloai();
        show_chungloai1();
    }
Exemplo n.º 21
0
    protected void imgbtnDangKy_Click(object sender, ImageClickEventArgs e)
    {
        string match = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
        Regex  reg   = new Regex(match);
        string email = txtEmail.Text;

        if (txtTenDangNhap.Text == "")
        {
            lblErrTenDangNhap_DangKy.Visible = true;
        }
        else if (txtMatKhau.Text == "")
        {
            lblErrMatKhauDK.Visible = true;
        }
        else if (txtXacNhanMK.Text != txtMatKhau.Text)
        {
            lblErrXacNhanMK.Visible = true;
        }
        else if (txtHoTen.Text == "")
        {
            lblErrTenKH.Visible = true;
        }
        else if (txtDiaChi.Text == "")
        {
            lblErrDiaChi.Visible = true;
        }
        else if (txtCMND.Text == "")
        {
            lblErrSoCMND.Visible = true;
        }
        else if (txtEmail.Text == "")
        {
            lblErrEmail.Visible = true;
        }
        else if (txtSDT.Text == "")
        {
            lblErrSDT.Visible = true;
        }
        else if (!reg.IsMatch(email))
        {
            lblErrEmail.Visible = true;
        }
        else
        {
            try
            {
                var qrkiemtra = from m in db.Nguoi_Dungs
                                where m.Ten_Nguoi_Dung == txtTenDangNhap.Text
                                select m;
                if (qrkiemtra.Count() == 0)
                {
                    Nguoi_Dung user = new Nguoi_Dung();
                    user.Admin          = 0;
                    user.Ten_Nguoi_Dung = txtTenDangNhap.Text;
                    user.Mat_Khau       = txtMatKhau.Text;
                    user.Ho_Ten         = txtHoTen.Text;
                    user.Gioi_Tinh      = ddlGioiTinh.SelectedItem.Value;
                    user.Dia_Chi        = txtDiaChi.Text;
                    user.CMND           = txtCMND.Text;
                    user.Email          = txtEmail.Text;
                    user.SDT            = txtSDT.Text;
                    db.Nguoi_Dungs.InsertOnSubmit(user);
                    db.SubmitChanges();
                    //Session["dangky"] = "1";
                    Response.Redirect("~/Thanh_Cong.aspx?capnhattt=&capnhatmk=&dangky=1&thanhtoan=");
                }
                else
                {
                    lbErr.Text = "Tên Đăng Nhập đã có người sử dụng";
                    //Session["dangky"] = "0";
                }
            }
            catch (Exception ex)
            {
                lbErr.Text = ex.Message;
            }
        }
    }
    protected void btnThue_Click(object sender, EventArgs e)
    {
        if (Session["nguoidung"] == null)
        {
            Response.Redirect("~/Dang_Nhap.aspx");
        }
        else
        {
            if (Request.QueryString["Ma_Xe"] != null)
            {
                Thue_Xe thuexe = new Thue_Xe();

                //xac dinh ma xe
                int maxe = int.Parse(Request.QueryString["Ma_Xe"]);

                //xac dinh ma nguoi dung
                string    tennguoidung = Session["nguoidung"].ToString();
                string    thongtinkh   = "select * from Nguoi_Dung where Ten_Nguoi_Dung='" + tennguoidung + "'";
                DataTable dt           = XLDL.docbang(thongtinkh);
                int       manguoidung  = int.Parse(dt.Rows[0][0].ToString());


                // xử lý ngày tháng
                DateTime kq_start_date = new DateTime();
                DateTime kq_end_date   = new DateTime();

                DateTime.TryParse(txtStartDate.Text, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out kq_start_date);
                DateTime.TryParse(txtEndDate.Text, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out kq_end_date);


                // kiểm tra điều kiện xe rảnh thì mới cho đăng ký thuê - Cách 1
                //var qrkiemtra = from m in db.Thue_Xes
                //                where m.carid == maxe && ( (m.start_date < kq_end_date && m.end_date > kq_end_date)
                //                        || (m.start_date < kq_start_date && m.end_date > kq_start_date)
                //                        || (m.start_date > kq_start_date && m.end_date < kq_end_date))

                //                select m;

                // kiểm tra điều kiện xe rảnh thì mới cho đăng ký thuê - Cách 2
                var qrkiemtra = from m in db.Thue_Xes
                                where (m.carid == maxe && m.end_date > kq_start_date && m.start_date < kq_end_date)
                                select m;
                if (kq_start_date < kq_end_date)
                {
                    if (qrkiemtra.Count() == 0)
                    {
                        // insert vào csdl

                        thuexe.start_date    = kq_start_date;
                        thuexe.end_date      = kq_end_date;
                        thuexe.pick_location = int.Parse(DDLPickLocation.SelectedValue);
                        thuexe.drop_location = int.Parse(DDLDropLocation.SelectedValue);
                        thuexe.carid         = maxe;
                        thuexe.userid        = manguoidung;
                        thuexe.text          = "đã được thuê";
                        thuexe.tinh_trang    = 3;


                        // insert vào csdl
                        db.Thue_Xes.InsertOnSubmit(thuexe);
                        db.SubmitChanges();


                        lblThongBao.Text = "Đã đặt xe thành công!";
                        string str = "~/Hoa_Don_Thue_Xe.aspx?Ma_Xe=" + maxe + "&startD=" + kq_start_date;

                        Response.Redirect(str);
                    }
                    else
                    {
                        lblThongBao.Text = "Xin lỗi! Xe không rảnh trong khoảng thời gian bạn chọn. Xin mời chọn xe khác hoặc chọn khoảng thời gian khác";

                        // gợi ý các xe rảnh trong khoảng thời gian người dùng đã chọn
                        var             context = new LinQtoSQLDataContext();
                        IQueryable <Xe> cars    = from car in context.Xes select car;


                        cars = from car in cars
                               where car.Thue_Xes.Count == 0 ||
                               car.Thue_Xes.Where(o => o.end_date > kq_start_date && o.start_date < kq_end_date).Count() == 0
                               select car;

                        //Không tìm thấy xe khác rảnh
                        if (cars.Count() == 0)
                        {
                            Label2.Text = "Không tìm thấy xe nào khác rảnh trong khoảng thời gian bạn chọn!";
                        }
                        else // Tìm thấy xe khác rảnh
                        {
                            Label3.Text = "<h2>Gợi ý: Có " + cars.Count() + " xe sau đây rảnh trong khoảng thời gian quý khách đã chọn</h2>";

                            Label2.Text  = "<table border=1>";
                            Label2.Text += "<tr style='text-align:center;font-weight:bold'><td>Mã xe</td><td>Tên xe</td><td>Hình</td><td>Giá thuê</td></tr>";

                            foreach (Xe car in cars)
                            {
                                Label2.Text += "<tr><td>" + car.Ma_Xe + "</td><td><a href='Dang_Ky_Thue_Xe.aspx?Ma_xe=" + car.Ma_Xe + "'>" + car.Ten_xe + "</a></td><td><img src='San_Pham/" + car.Hinh_Anh + "' width=150px ></td><td>" + car.Gia + " USD" + "</td></tr>";
                            }
                            Label2.Text += "</table>";
                        }
                    }
                }
                else
                {
                    lblThongBao.Text = "Thời gian trả xe phải sau thời gian nhận xe! Mời quý khách chọn lại thời gian";
                }
            }
            else
            {
                Response.Redirect("~/default.aspx");
            }
        }
    }