Example #1
0
        private void DatVeXe()
        {
            try
            {
                SqlConnection Con = KetNoiCSDL.KetNoiSQL();
                Con.Open();

                CDatVe VXe = new CDatVe();
                //idChuyen
                int index = lblMaVe.Text.IndexOf(" ");

                VXe.IdChuyen = lblMaVe.Text.Substring(index + 3);

                //Ten
                VXe.TenKhachHang = txtTen.Text;
                //CMND
                VXe.CMND = ntxtCMND.Text;
                //QueQuan
                VXe.QueQuan = DynamicCBOXQueQuan.Text;

                //NgaySinh

                VXe.NgaySinh = dateTimePicker1.Value.ToString();
                int i = VXe.NgaySinh.IndexOf(" ");
                if (i != -1)
                {
                    VXe.NgaySinh = VXe.NgaySinh.Substring(0, i);
                }

                //SDT
                VXe.SDT = ntxtSDT.Text;
                //Tien
                VXe.TienVe = TextBoxGiaTien.Text;

                //Thoi Gian Mua Ve
                VXe.ThoiGianMuaVe = "Ngày " + DateTime.Now.Day.ToString() + " Tháng " + DateTime.Now.Month.ToString() + " Năm " + DateTime.Now.Year.ToString();



                string    ThemVe               = string.Format("exec ThemVe @IdChuyen, @TenHanhKhach, @NgaySinh, @SDTHanhKhach, @CMND, @QueQuan, @GiaTien, @ThoiGianMua");
                string    UpdateChoNgoi        = string.Format("exec UpdateChoNgoi @SoGheTrong, @IdChuyen");
                string    InsertUuDaiKhachHang = string.Format("exec InsertUuDaiKhachHang @MaVeUuDai,@TenHangKhachUuDai,@SDTUuDai,@CMNDUuDai,@LoaiGiaoDich");
                DataTable user = new DataTable();

                SqlCommand Com       = new SqlCommand(ThemVe, Con);
                SqlCommand ComUpdate = new SqlCommand(UpdateChoNgoi, Con);
                SqlCommand ComUuDai  = new SqlCommand(InsertUuDaiKhachHang, Con);

                //ThemVe
                Com.Parameters.Add(new SqlParameter("@IdChuyen", VXe.IdChuyen));
                Com.Parameters.Add(new SqlParameter("@TenHanhKhach", VXe.TenKhachHang));
                Com.Parameters.Add(new SqlParameter("@NgaySinh", VXe.NgaySinh));
                Com.Parameters.Add(new SqlParameter("@SDTHanhKhach", VXe.SDT));
                Com.Parameters.Add(new SqlParameter("@CMND", VXe.CMND));
                Com.Parameters.Add(new SqlParameter("@QueQuan", VXe.QueQuan));
                Com.Parameters.Add(new SqlParameter("@GiaTien", VXe.TienVe));
                Com.Parameters.Add(new SqlParameter("@ThoiGianMua", VXe.ThoiGianMuaVe));

                //UpdateChoNgoi
                ComUpdate.Parameters.Add(new SqlParameter("@SoGheTrong", GetChoNgoi() - 1));
                ComUpdate.Parameters.Add(new SqlParameter("@IdChuyen", VXe.IdChuyen));

                //InsertUuDaiKhachHang
                ComUuDai.Parameters.Add(new SqlParameter("@MaVeUuDai", lblMaVe.Text));
                ComUuDai.Parameters.Add(new SqlParameter("@TenHangKhachUuDai", VXe.TenKhachHang));
                ComUuDai.Parameters.Add(new SqlParameter("@SDTUuDai", VXe.SDT));
                ComUuDai.Parameters.Add(new SqlParameter("@CMNDUuDai", VXe.CMND));
                ComUuDai.Parameters.Add(new SqlParameter("@LoaiGiaoDich", this.Text));


                SqlDataAdapter adapt  = new SqlDataAdapter(Com);
                SqlDataAdapter adapt1 = new SqlDataAdapter(ComUpdate);
                SqlDataAdapter adapt2 = new SqlDataAdapter(ComUuDai);
                adapt.Fill(user);
                adapt1.Fill(user);
                adapt2.Fill(user);
                Con.Close();
                MetroFramework.MetroMessageBox.Show(this, string.Format("Đã Đặt Vé Cho Khách Hàng {0}!", VXe.TenKhachHang));
            }
            catch (Exception EX)
            {
                MetroFramework.MetroMessageBox.Show(this, EX.Message);
            }
        }
        private void btnHuyVe_Click(object sender, EventArgs e)
        {
            if (MetroFramework.MetroMessageBox.Show(this, "Chắc Chắn Hay Không", "Bạn Có Chắc Huỷ Vé Này", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                CDatVe VXe = new CDatVe();

                //Ten
                VXe.TenKhachHang = txtTen.Text;
                //CMND
                VXe.CMND = ntxtCMND.Text;


                //SDT
                VXe.SDT = ntxtSDT.Text;

                //

                // int index = lblMaVe.Text.IndexOf(" ");
                string IdVe     = IdCanDoi;
                string IdChuyen = IdChuyenCanDoi;

                try
                {
                    SqlConnection Con = KetNoiCSDL.KetNoiSQL();
                    Con.Open();
                    DataTable user  = new DataTable();
                    string    HuyVe = string.Format("exec HuyVe @IdChuyen,@IdVe");
                    string    InsertUuDaiKhachHang = string.Format("exec InsertUuDaiKhachHang @MaVeUuDai,@TenHangKhachUuDai,@SDTUuDai,@CMNDUuDai,@LoaiGiaoDich");
                    string    UpdateChoNgoi        = string.Format("exec UpdateChoNgoi @SoGheTrong, @IdChuyen");

                    SqlCommand ComUuDai = new SqlCommand(InsertUuDaiKhachHang, Con);

                    SqlCommand ComUpdate = new SqlCommand(UpdateChoNgoi, Con);
                    //HuyVe
                    SqlCommand Com = new SqlCommand(HuyVe, Con);
                    Com.Parameters.Add(new SqlParameter("@IdChuyen", IdChuyen));
                    Com.Parameters.Add(new SqlParameter("@IdVe", IdVe));

                    ComUpdate.Parameters.Add(new SqlParameter("@IdChuyen", IdChuyen));
                    ComUpdate.Parameters.Add(new SqlParameter("@SoGheTrong", GetChoNgoi() + 1));

                    //InsertUuDaiKhachHang
                    ComUuDai.Parameters.Add(new SqlParameter("@MaVeUuDai", lblMaVe.Text));
                    ComUuDai.Parameters.Add(new SqlParameter("@TenHangKhachUuDai", VXe.TenKhachHang));
                    ComUuDai.Parameters.Add(new SqlParameter("@SDTUuDai", VXe.SDT));
                    ComUuDai.Parameters.Add(new SqlParameter("@CMNDUuDai", VXe.CMND));
                    ComUuDai.Parameters.Add(new SqlParameter("@LoaiGiaoDich", "Huỷ Vé"));

                    //
                    SqlDataAdapter adapt1 = new SqlDataAdapter(ComUpdate);
                    SqlDataAdapter adapt2 = new SqlDataAdapter(ComUuDai);
                    SqlDataAdapter adapt  = new SqlDataAdapter(Com);
                    adapt.Fill(user);
                    adapt1.Fill(user);
                    adapt2.Fill(user);
                    Con.Close();

                    MetroFramework.MetroMessageBox.Show(this, string.Format("Đã Delete Vé Mã Số:{0}", IdCanDoi + " - " + IdChuyenCanDoi));
                    HuyDoiVe_Load(sender, e);
                    metroPanel1.Visible = false;
                }
                catch (Exception EX)
                {
                    MetroFramework.MetroMessageBox.Show(this, EX.Message);
                }
            }
        }
Example #3
0
        private CDatVe GetInfoKhachHang()
        {
            CDatVe Info = new CDatVe();

            try
            {
                SqlConnection Con = KetNoiCSDL.KetNoiSQL();
                Con.Open();

                //IdChuyen
                string     IdChuyen = string.Format("exec  GetInfoKhachHang_IdChuyen @ID"); //Gọi Proc
                SqlCommand Com      = new SqlCommand(IdChuyen, Con);
                Com.Parameters.Add(new SqlParameter("@ID", IdVe));
                Info.IdChuyen = Com.ExecuteScalar().ToString();

                //Ten
                string Ten = string.Format("exec  GetInfoKhachHang_Ten @ID"); //Gọi Proc
                Com = new SqlCommand(Ten, Con);
                Com.Parameters.Add(new SqlParameter("@ID", IdVe));
                Info.TenKhachHang = Com.ExecuteScalar().ToString();

                //CMND
                string CMND = string.Format("exec  GetInfoKhachHang_CMND @ID"); //Gọi Proc
                Com = new SqlCommand(CMND, Con);
                Com.Parameters.Add(new SqlParameter("@ID", IdVe));
                Info.CMND = Com.ExecuteScalar().ToString();


                //LayNgaySinh
                string NgaySinh = string.Format("exec  GetInfoKhachHang_NgaySinh @ID"); //Gọi Proc
                Com = new SqlCommand(NgaySinh, Con);
                Com.Parameters.Add(new SqlParameter("@ID", IdVe));
                Info.NgaySinh = Com.ExecuteScalar().ToString();

                int index = Info.NgaySinh.IndexOf(" ");
                if (index != -1)
                {
                    Info.NgaySinh = Info.NgaySinh.Substring(0, index);
                }

                //LayDienThoai
                string SoDienThoai = string.Format("exec  GetInfoKhachHang_SDT @ID"); //Gọi Proc
                Com = new SqlCommand(SoDienThoai, Con);
                Com.Parameters.Add(new SqlParameter("@ID", IdVe));
                Info.SDT = Com.ExecuteScalar().ToString();

                //LayDiaChi
                string DiaChi = string.Format("exec  GetInfoKhachHang_DiaChi @ID"); //Gọi Proc
                Com = new SqlCommand(DiaChi, Con);
                Com.Parameters.Add(new SqlParameter("@ID", IdVe));
                Info.QueQuan = Com.ExecuteScalar().ToString();

                //Giá Vé
                Info.TienVe = TienVe;

                //LaySoXe
                string SoXe = string.Format("exec GetInfoKhachHang_SoXe  @IdChuyen"); //Gọi Proc
                Com = new SqlCommand(SoXe, Con);
                Com.Parameters.Add(new SqlParameter("@IdChuyen", Info.IdChuyen));
                Info.SoXe = Com.ExecuteScalar().ToString();

                //NgayDi
                string NgayDi = string.Format("exec GetInfoKhachHang_NgayDi  @IdChuyen"); //Gọi Proc
                Com = new SqlCommand(NgayDi, Con);
                Com.Parameters.Add(new SqlParameter("@IdChuyen", Info.IdChuyen));
                Info.NgayDi = Com.ExecuteScalar().ToString();

                //GioDi
                string GioDi = string.Format("exec GetInfoKhachHang_GioDi  @IdChuyen "); //Gọi Proc
                Com = new SqlCommand(GioDi, Con);
                Com.Parameters.Add(new SqlParameter("@IdChuyen", Info.IdChuyen));
                Info.GioDi = Com.ExecuteScalar().ToString();

                //HieuXe
                string HieuXe = string.Format("exec  GetInfoKhachHang_HieuXe  @IdChuyen"); //Gọi Proc
                Com = new SqlCommand(HieuXe, Con);
                Com.Parameters.Add(new SqlParameter("@IdChuyen", Info.IdChuyen));
                Info.HieuXe = Com.ExecuteScalar().ToString();

                //LoTrinh
                string LoTrinh = string.Format("exec GetInfoKhachHang_LoTrinh  @IdChuyen"); //Gọi Proc
                Com = new SqlCommand(LoTrinh, Con);
                Com.Parameters.Add(new SqlParameter("@IdChuyen", Info.IdChuyen));
                Info.LoTrinh = Com.ExecuteScalar().ToString();



                //TenNhanVien
                string TenNhanVien = string.Format("exec GetInfoKhachHang_TenNhanVien @IdNguoiDung"); //Gọi Proc
                Com = new SqlCommand(TenNhanVien, Con);
                Com.Parameters.Add(new SqlParameter("@IdNguoiDung", IdNguoiDung_FormDatVe));
                lblTenBanVe.Text = Com.ExecuteScalar().ToString();

                Con.Close();
            }
            catch (Exception EX)
            {
                MetroFramework.MetroMessageBox.Show(this, EX.Message);
            }
            return(Info);
        }
        private void DoiVeXe()
        {
            try
            {
                SqlConnection Con = KetNoiCSDL.KetNoiSQL();
                Con.Open();

                CDatVe VXe = new CDatVe();
                //idChuyen
                int    index = lblMaVe.Text.IndexOf(" ");
                string IdVe  = lblMaVe.Text.Substring(0, index);
                VXe.IdChuyen = lblMaVe.Text.Substring(index + 3);

                //Ten
                VXe.TenKhachHang = txtTen.Text;
                //CMND
                VXe.CMND = ntxtCMND.Text;
                //QueQuan
                VXe.QueQuan = DynamicCBOXQueQuan.Text;

                //NgaySinh

                VXe.NgaySinh = dateTimePicker1.Value.ToString();
                int i = VXe.NgaySinh.IndexOf(" ");
                if (i != -1)
                {
                    VXe.NgaySinh = VXe.NgaySinh.Substring(0, i);
                }

                //SDT
                VXe.SDT = ntxtSDT.Text;
                //Tien

                string TempTien  = TextBoxGiaTien.Text;
                int    ixdexTien = TextBoxGiaTien.Text.IndexOf(".");
                if (ixdexTien == -1)
                {
                    VXe.TienVe = Convert.ToInt32(TempTien);
                }
                else
                {
                    TempTien   = TempTien.Replace(".", "");
                    VXe.TienVe = Convert.ToInt32(TempTien);
                }


                //Thoi Gian Mua Ve
                VXe.ThoiGianMuaVe = "Ngày " + DateTime.Now.Day.ToString() + " Tháng " + DateTime.Now.Month.ToString() + " Năm " + DateTime.Now.Year.ToString();



                string DoiVe = string.Format("exec DoiVe @IdChuyenNow,@TenHanhKhach,@NgaySinh,@SDTHanhKhach,@CMND,@QueQuan,@GiaTien,@ThoiGianMua,@IdChuyenCanDoi,@IdVe");

                string    InsertUuDaiKhachHang = string.Format("exec InsertUuDaiKhachHang @MaVeUuDai,@TenHangKhachUuDai,@SDTUuDai,@CMNDUuDai,@LoaiGiaoDich");
                DataTable user = new DataTable();

                SqlCommand Com = new SqlCommand(DoiVe, Con);

                SqlCommand ComUuDai = new SqlCommand(InsertUuDaiKhachHang, Con);

                //DoiVe
                Com.Parameters.Add(new SqlParameter("@IdChuyenNow", VXe.IdChuyen));
                Com.Parameters.Add(new SqlParameter("@IdVe", IdCanDoi));
                Com.Parameters.Add(new SqlParameter("@IdChuyenCanDoi", IdChuyenCanDoi));
                Com.Parameters.Add(new SqlParameter("@TenHanhKhach", VXe.TenKhachHang));
                Com.Parameters.Add(new SqlParameter("@NgaySinh", VXe.NgaySinh));
                Com.Parameters.Add(new SqlParameter("@SDTHanhKhach", VXe.SDT));
                Com.Parameters.Add(new SqlParameter("@CMND", VXe.CMND));
                Com.Parameters.Add(new SqlParameter("@QueQuan", VXe.QueQuan));
                Com.Parameters.Add(new SqlParameter("@GiaTien", VXe.TienVe));
                Com.Parameters.Add(new SqlParameter("@ThoiGianMua", VXe.ThoiGianMuaVe));



                //InsertUuDaiKhachHang
                ComUuDai.Parameters.Add(new SqlParameter("@MaVeUuDai", lblMaVe.Text));
                ComUuDai.Parameters.Add(new SqlParameter("@TenHangKhachUuDai", VXe.TenKhachHang));
                ComUuDai.Parameters.Add(new SqlParameter("@SDTUuDai", VXe.SDT));
                ComUuDai.Parameters.Add(new SqlParameter("@CMNDUuDai", VXe.CMND));
                ComUuDai.Parameters.Add(new SqlParameter("@LoaiGiaoDich", "Đổi Vé"));

                SqlDataAdapter adapt = new SqlDataAdapter(Com);

                SqlDataAdapter adapt2 = new SqlDataAdapter(ComUuDai);
                adapt.Fill(user);
                adapt2.Fill(user);
                Con.Close();
                MetroFramework.MetroMessageBox.Show(this, string.Format("Đã Đổi Vé Cho Khách Hàng: {0}!", VXe.TenKhachHang));
            }
            catch (Exception EX)
            {
                MetroFramework.MetroMessageBox.Show(this, EX.Message);
            }
        }