Beispiel #1
0
        /// <summary>
        /// hàm xử lý địa chỉ chạy ngầm để cải thiện tốc độ load form.
        /// -Trong khi đó có 1 cờ bật lên.không cho phép lưu hoặc tắt form trong khi đang xử lý.
        /// </summary>
        private void ProcessAutoDiaChi()
        {
            G_TongTien = 0;
            AppendTextBox(txtKmDuKien, string.Empty);
            AppendTextBox(deTGDuKienDen, string.Empty);
            AppendTextBox(txtTienDuKien, string.Empty);
            AppendTextBox(txtLoTrinh, string.Empty);
            IsProcess = true;
            PointLatLng start = auDiaChiDon.TempLat > 0 ? new PointLatLng(auDiaChiDon.TempLat, auDiaChiDon.TempLng) : new PointLatLng(auDiaChiDon.Lat, auDiaChiDon.Lng);
            PointLatLng end   = new PointLatLng(auDiaChiTra.Lat, auDiaChiTra.Lng);

            var loTrinh = TaxiReturn_Process.LayLoTrinh(start, end);

            if (!string.IsNullOrEmpty(loTrinh.LoTrinh_DiaChi))
            {
                try
                {
                    this.LoTrinh = loTrinh;
                    string address = loTrinh.LoTrinh_DiaChi;
                    Distance = (double)loTrinh.Distance;
                    TinhTienTheoKm objTinhTien = new TinhTienTheoKm(this.loaiXe, Distance.To <int>());
                    G_TongTien = objTinhTien.TongTien1Chieu;
                    AppendTextBox(txtKmDuKien, Distance.To <int>());
                    AppendTextBox(deTGDuKienDen, deGioDon.DateTime.AddHours(Distance / 40));
                    AppendTextBox(txtTienDuKien, G_TongTien);
                    AppendTextBox(txtLoTrinh, address.RemoveRoutePr());
                }
                catch (Exception)
                {
                    AppendTextBox(txtLoTrinh, "Không có lộ trình");
                }
            }

            IsProcess = false;
        }
Beispiel #2
0
 public static float TinhQuangDuong(float start_lat, float start_lng, float end_lat, float end_lng)
 {
     return(TaxiReturn_Process.LayLoTrinh(start_lat, start_lng, end_lat, end_lng).Distance);
 }
Beispiel #3
0
        private void kếtThúcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var _model = gridView_Bookings.GetFocusedRow <Booking>();

            if (_model == null)
            {
                return;
            }
            int G_XNCode = ThongTinCauHinh.CompanyID;

            #region Trường hợp 1:Khách hàng hủy
            if (_model.OpCommand == m_HuyDieu)
            {
                //Bạn có muốn xóa cuốc khách chiều về này không ?
                //    if (new MessageBox.MessageBox().Show("Khách hàng hủy cuốc chiều về ?", "Thông báo", MessageBoxButtons.YesNo).ToLower() == "yes".ToLower())
                {
                    try
                    {
                        //cập nhật trạng thái của xe đường dài.
                        var xddd = new XeDiDuongDai();
                        xddd.UpdateStatus(_model.FK_TaxiReturn, Enum_XeBaoDiDuongDai_TrangThai.ChoGhepKhach, ThongTinDangNhap.USER_ID);
                        _model.UpdateStatus(_model.PK_BooID, Enum_Bookings_OpStatus.KhachHangHuy, m_HuyDieu, ThongTinDangNhap.USER_ID);

                        if (_model.FK_TaxiReturn > 0)
                        {
                            TaxiReturn_Process.TripUpdateStatus(_model.FK_TaxiReturn, G_XNCode, Services.FastTaxi_OperationService.Trip.Status.DangDi);
                        }
                        //  this.Close();
                    }
                    catch (Exception ex)
                    {
                        new Log().WriteLog(ThongTinDangNhap.USER_ID, "ctrlListBook\\kếtThúcToolStripMenuItem_Click", DateTime.Now, ex.Message);
                        //  ShowMessageFail("[KH hủy] Quá trình lưu xảy ra bị lỗi");
                    }
                }
                return;
            }
            #endregion

            #region Từ chối
            if (_model.FK_TaxiReturn == 0)
            {
                new MessageBox.MessageBoxBA().Show("Cuốc khách chưa gián xe.\nvui lòng chọn trạng thái từ chối");
                return;
            }
            #endregion

            #region Trường hợp 2:Đã ghép.
            else
            {
                #region Mobile đã gặp xe
                if (_model.OpCommand == m_DaGapXe)
                {
                    try
                    {
                        string rs       = string.Empty;
                        var    themTrip = new XeDiDuongDai();
                        var    address  = new AutoCompleteAddress();
                        address.Bind();

                        #region Khởi tạo trip mới và chưa lưu
                        themTrip.ID = _model.FK_TaxiReturn;
                        try
                        {
                            //Thiếu : Thêm ID cha vào để quan hệ
                            if (themTrip.GetByKey())
                            {
                                themTrip.ParentID      = _model.FK_TaxiReturn;
                                themTrip.ID            = 0;
                                themTrip.LoTrinh       = string.Empty;
                                themTrip.LoTrinh_Diem  = string.Empty;
                                themTrip.KmDuKien      = 0;
                                themTrip.TrangThai     = (int)Enum_XeBaoDiDuongDai_TrangThai.ChoGhepKhach;
                                themTrip.CreatedDate   = TaxiReturn_Process.timerServer;
                                themTrip.CreatedByUser = ThongTinDangNhap.USER_ID;
                                themTrip.UpdatedDate   = null;
                                themTrip.UpdatedByUser = string.Empty;
                                // thời điểm bắt đầu của lái xe.
                                themTrip.ThoiDiemDi = themTrip.TGDuKien;
                                //_modelDetail.B
                                themTrip.DiaDiemDen = _model.ToAdress;
                                //address.Text = themTrip.DiaDiemDen;
                                //address.ReSearch();
                                themTrip.FK_QuanHuyenDenID = address.HuyenId;
                                themTrip.FK_TinhThanhDenID = address.TinhId;
                                themTrip.Den_ViDo          = _model.ToLat;
                                themTrip.Den_KinhDo        = _model.ToLng;


                                //lấy tọa độ của xe.
                                var _xeOnline = WCFService_Common.GetXeOnlineBySHX(themTrip.FK_SoHieuXe);
                                themTrip.Xe_KinhDo = _xeOnline.KinhDo;
                                themTrip.Xe_ViDo   = _xeOnline.ViDo;

                                // Lộ trình này là lộ trình của điểm DC
                                var lotrinh = TaxiReturn_Process.LayLoTrinh(themTrip.Di_ViDo, themTrip.Di_KinhDo, themTrip.Den_ViDo, themTrip.Den_KinhDo);
                                themTrip.LoTrinh      = lotrinh.LoTrinh_DiaChi;
                                themTrip.LoTrinh_Diem = lotrinh.LoTrinh_ToaDo;
                                themTrip.KmDuKien     = (int)lotrinh.Distance;

                                //Tính thời gian đi của book.
                                int SoPhutDiQuangDuongBC = TaxiReturn_Process.TinhThoiGianDiHetQuangDuong(_model.BC_Route_Distance);
                                themTrip.TGDuKien   = themTrip.TGDuKien.AddMinutes(SoPhutDiQuangDuongBC); // là thời điểm đến điểm C.
                                themTrip.ThoiDiemVe = themTrip.TGDuKien;
                                Xe objXe1 = new Xe().GetChiTietXe(themTrip.FK_SoHieuXe);
                                if (objXe1 != null)
                                {
                                    themTrip.BienSoXe = objXe1.BienKiemSoat;
                                    TinhTienTheoKm objTinhTien = new TinhTienTheoKm(objXe1.LoaiXeID, themTrip.KmDuKien);
                                    themTrip.TienDuKien = objTinhTien.TongTien1Chieu;
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                        #endregion

                        if (themTrip.KmDuKien >= g_KmDuKien)
                        {
                            rs = new MessageBox.MessageBoxBA().Show("Xe này có muốn đón cuốc chiều về khác không ?", "Thông báo", MessageBoxButtons.YesNo);
                        }

                        if (rs == "Yes")
                        {
                            themTrip.Insert();
                        }
                        themTrip.UpdateStatusV2(_model.FK_TaxiReturn, Enum_XeBaoDiDuongDai_TrangThai.None, ThongTinDangNhap.USER_ID, true, Enum_Bookings_OpStatus.MobileKetThuc, _model.PK_BooID);

                        #region Send server
                        try
                        {
                            TaxiReturn_Process.TripUpdateStatus(_model.FK_TaxiReturn, G_XNCode, Services.FastTaxi_OperationService.Trip.Status.KetThuc);
                            if (rs == "Yes" && themTrip.ID > 0)
                            {
                                var rsBoot = TaxiReturn_Process.ReplaceTrip(themTrip.ParentID, themTrip);
                                themTrip.UpdateIsAddedStaxi(themTrip.ID, ThongTinDangNhap.USER_ID, rsBoot);
                            }
                        }
                        catch (Exception ex)
                        {
                            new Log().WriteLog(ThongTinDangNhap.USER_ID, "Lưu trên form khách cần xe", DateTime.Now, "Gửi lên server sảy ra lỗi:" + ex.Message);
                        }

                        //chỉ cần Kết thúc cái Book chưa có hàm gửi lên server
                        try
                        {
                            //  if (!G_DoNotSendToServer)
                            TaxiReturn_Process.FinishVehicleReturn(_model.ClientKey);
                        }
                        catch (Exception ex)
                        {
                            new Log().WriteLog(ThongTinDangNhap.USER_ID, "Lưu trên form khách cần xe", DateTime.Now, "Gửi lên server sảy ra lỗi:" + ex.Message);
                        }

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        new Log().WriteLog(ThongTinDangNhap.USER_ID, "Lưu trên form khách cần xe", DateTime.Now, "Cập nhật dữ liệu lỗi:" + ex.Message);
                    }
                }
                #endregion

                #region Mobile chưa gặp xe
                else
                {
                    try
                    {
                        #region Điều hành kết thúc
                        string rs       = string.Empty;
                        var    themTrip = new XeDiDuongDai();
                        var    address  = new AutoCompleteAddress();
                        address.Bind();

                        #region Khởi tạo trip mới và chưa lưu
                        themTrip.ID = _model.FK_TaxiReturn;
                        try
                        {
                            //Thiếu : Thêm ID cha vào để quan hệ
                            if (themTrip.GetByKey())
                            {
                                themTrip.ParentID      = _model.FK_TaxiReturn;
                                themTrip.ID            = 0;
                                themTrip.LoTrinh       = string.Empty;
                                themTrip.LoTrinh_Diem  = string.Empty;
                                themTrip.KmDuKien      = 0;
                                themTrip.TrangThai     = (int)Enum_XeBaoDiDuongDai_TrangThai.ChoGhepKhach;
                                themTrip.CreatedDate   = TaxiReturn_Process.timerServer;
                                themTrip.CreatedByUser = ThongTinDangNhap.USER_ID;
                                themTrip.UpdatedDate   = null;
                                themTrip.UpdatedByUser = string.Empty;
                                // thời điểm bắt đầu của lái xe.
                                themTrip.ThoiDiemDi = themTrip.TGDuKien;
                                //_modelDetail.B
                                themTrip.DiaDiemDen = _model.ToAdress;
                                //address.Text = themTrip.DiaDiemDen;
                                //address.ReSearch();
                                themTrip.FK_QuanHuyenDenID = address.HuyenId;
                                themTrip.FK_TinhThanhDenID = address.TinhId;
                                themTrip.Den_ViDo          = _model.ToLat;
                                themTrip.Den_KinhDo        = _model.ToLng;


                                //lấy tọa độ của xe.
                                var _xeOnline = WCFService_Common.GetXeOnlineBySHX(themTrip.FK_SoHieuXe);
                                themTrip.Xe_KinhDo = _xeOnline.KinhDo;
                                themTrip.Xe_ViDo   = _xeOnline.ViDo;

                                // Lộ trình này là lộ trình của điểm DC
                                var lotrinh = TaxiReturn_Process.LayLoTrinh(themTrip.Di_ViDo, themTrip.Di_KinhDo, themTrip.Den_ViDo, themTrip.Den_KinhDo);
                                themTrip.LoTrinh      = lotrinh.LoTrinh_DiaChi;
                                themTrip.LoTrinh_Diem = lotrinh.LoTrinh_ToaDo;
                                themTrip.KmDuKien     = (int)lotrinh.Distance;

                                //Tính thời gian đi của book.
                                int SoPhutDiQuangDuongBC = TaxiReturn_Process.TinhThoiGianDiHetQuangDuong(_model.BC_Route_Distance);
                                themTrip.TGDuKien   = themTrip.TGDuKien.AddMinutes(SoPhutDiQuangDuongBC); // là thời điểm đến điểm C.
                                themTrip.ThoiDiemVe = themTrip.TGDuKien;
                                Xe objXe1 = new Xe().GetChiTietXe(themTrip.FK_SoHieuXe);
                                if (objXe1 != null)
                                {
                                    themTrip.BienSoXe = objXe1.BienKiemSoat;
                                    TinhTienTheoKm objTinhTien = new TinhTienTheoKm(objXe1.LoaiXeID, themTrip.KmDuKien);
                                    themTrip.TienDuKien = objTinhTien.TongTien1Chieu;
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                        #endregion

                        if (themTrip.KmDuKien >= g_KmDuKien)
                        {
                            rs = new MessageBox.MessageBoxBA().Show("Xe này có muốn đón cuốc chiều về khác không ?", "Thông báo", MessageBoxButtons.YesNo);
                        }


                        #region nếu chọn đón cuốc chiều về khác thì Thêm mới Trip
                        if (rs == "Yes")
                        {
                            themTrip.Insert();
                        }
                        themTrip.UpdateStatusV2(_model.FK_TaxiReturn, Enum_XeBaoDiDuongDai_TrangThai.None, ThongTinDangNhap.USER_ID, true, Enum_Bookings_OpStatus.KetThuc, _model.PK_BooID);
                        #endregion

                        #region Send server
                        try
                        {
                            TaxiReturn_Process.TripUpdateStatus(_model.FK_TaxiReturn, G_XNCode, Services.FastTaxi_OperationService.Trip.Status.KetThuc);
                            if (rs == "Yes" && themTrip.ID > 0)
                            {
                                var rsBoot = TaxiReturn_Process.ReplaceTrip(themTrip.ParentID, themTrip);
                                themTrip.UpdateIsAddedStaxi(themTrip.ID, ThongTinDangNhap.USER_ID, rsBoot);
                            }
                        }
                        catch (Exception ex)
                        {
                            new Log().WriteLog(ThongTinDangNhap.USER_ID, "Lưu trên form khách cần xe", DateTime.Now, "Gửi lên server sảy ra lỗi:" + ex.Message);
                        }

                        //chỉ cần Kết thúc cái Book chưa có hàm gửi lên server
                        try
                        {
                            //if (!G_DoNotSendToServer)
                            TaxiReturn_Process.FinishVehicleReturn(_model.ClientKey);
                        }
                        catch (Exception ex)
                        {
                            new Log().WriteLog(ThongTinDangNhap.USER_ID, "Lưu trên form khách cần xe", DateTime.Now, "Gửi lên server sảy ra lỗi:" + ex.Message);
                        }

                        #endregion
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        new Log().WriteLog(ThongTinDangNhap.USER_ID, "Kết thúc trên lưới Book", DateTime.Now, "Gửi lên server sảy ra lỗi:" + ex.Message);
                        new MessageBox.MessageBoxBA().Show("Quá trình xử lý sảy ra lỗi vui lòng liên hệ với quản trị");
                    }
                }
                #endregion
            }
            #endregion
        }
Beispiel #4
0
        /// <summary>
        /// Thực hiện thao tác lưu trữ dữ liệu.
        /// </summary>
        public void DoSave()
        {
            var fw = new ProgressBar();

            try
            {
                if (Model.ID <= 0)
                {
                    Model.CreatedByUser = ThongTinDangNhap.USER_ID;
                    Model.CreatedDate   = TaxiReturn_Process.timerServer;
                    Model.Insert();

                    #region Xử lý thông tin gửi lên server

                    if (ckb1Chieu.Checked && ckbFastTaxi.Visible && ckbFastTaxi.Checked && lue_TrangThaiDuyet.EditValue.To <int>() == (int)Enum_XeBaoDiDuongDai_TrangThaiDuyet.DaDuyet)
                    {
                        if (Distance >= 500)
                        {
                            ShowError("Hệ thống Staxi không hỗ trợ cuốc đi đường dài lớn hơn 500 km");
                        }
                        else
                        {
                            fw.Show();
                            var rs = TaxiReturn_Process.AddTrip(Model);
                            fw.Close();
                            if (rs != null && rs.AddTripSuccess)
                            {
                                //Add Trip lên server Thành Công
                                Model.IsAddedStaxi = true;
                            }
                            else
                            {
                                //Add Trip lên server thất bại
                                Model.IsAddedStaxi = false;
                            }
                            // cập nhật trạng thái
                            Model.UpdateIsAddedStaxi(Model.ID, ThongTinDangNhap.USER_ID, Model.IsAddedStaxi);
                            #region Quét xem có booking đề cử cho cuốc chiều về này hay ko
                            //kiểm tra Có danh sách các book đề cử cho xe này.
                            if (rs != null && rs.TripBookingsSend != null && rs.TripBookingsSend.Bookings.Length > 0)
                            {
                                frmListBooking frm = new frmListBooking()
                                {
                                    rs         = rs.TripBookingsSend,
                                    Books      = rs.TripBookingsSend.Bookings,
                                    G_TongTien = G_TongTien
                                };
                                if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                                {
                                    if (frm.Book != null) //chấp nhận
                                    {
                                        var book = new Booking();
                                        book.PK_BooID = frm.Book.PK_BooID;

                                        if (!book.GetByKey()) //trường hợp server chưa đẩy về thì sẽ tự động thêm book đã đc chấp nhận.
                                        {
                                            //Tạo book mới trên hệ thống.
                                            // dán lại xe nào được chấp nhận.
                                            book = ParseBooking(frm.Book);
                                            book.FK_TaxiReturn  = rs.TripBookingsSend.TripID;
                                            book.OpVehicle      = Model.FK_SoHieuXe;
                                            book.OpStatus       = (int)Enum_Bookings_OpStatus.ChapNhan;
                                            book.OpAcceptedUser = ThongTinDangNhap.USER_ID;
                                            book.OpAcceptedTime = book.GetTimeServer();
                                            book.CreatedDate    = book.OpAcceptedTime;
                                            book.Insert();
                                            //Tạo book deltail trên hệ thống.
                                            BookingsDetail detail = new BookingsDetail();
                                            detail.TripID    = Model.ID;
                                            detail.FK_BookID = book.PK_BooID;
                                            // detail.CalF
                                            var AB = TaxiReturn_Process.LayLoTrinh(Model.Den_ViDo, Model.Den_KinhDo, book.FromLat, book.FromLng);
                                            detail.ABRoute = AB.LoTrinh_ToaDo;
                                            var CD = TaxiReturn_Process.LayLoTrinh(book.ToLat, book.ToLng, Model.Di_ViDo, Model.Di_KinhDo);
                                            detail.CDRoute     = CD.LoTrinh_ToaDo;
                                            detail.Status      = (int)Enum_BookingsDetail_Status.DuocChapNhan;
                                            detail.DateUpdated = TaxiReturn_Process.timerServer;
                                            detail.Insert();
                                        }
                                        else
                                        {
                                            // dán lại xe nào được chấp nhận.
                                            book.FK_TaxiReturn  = rs.TripBookingsSend.TripID;
                                            book.OpVehicle      = Model.FK_SoHieuXe;
                                            book.OpStatus       = (int)Enum_Bookings_OpStatus.ChapNhan;
                                            book.OpAcceptedUser = ThongTinDangNhap.USER_ID;
                                            book.OpAcceptedTime = book.GetTimeServer();
                                            book.Update();
                                        }

                                        book.DaDieuDuocXe(frm.Book.PK_BooID, rs.TripBookingsSend.TripID, ThongTinDangNhap.USER_ID, ThongTinCauHinh.CompanyID);
                                    }
                                    else // Hủy điều
                                    {
                                        //Xác nhận hủy điều.
                                        if (new MessageBox.MessageBoxBA().Show("Bạn có muốn hủy cuốc này không", "Thông báo", MessageBox.MessageBoxButtonsBA.YesNo) == "Yes")
                                        {
                                            if (_model != null && _model.ID > 0)
                                            {
                                                _model.UpdatedByUser = ThongTinDangNhap.USER_ID;
                                                _model.HuyDieu();
                                                TaxiReturn_Process.TripUpdateStatus(_model.ID, ThongTinCauHinh.CompanyID, Services.FastTaxi_OperationService.Trip.Status.HuyDieu);
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                    }

                    #endregion

                    DialogResult = DialogResult.OK;
                    this.BeginInvoke((Action)(() => this.Close()));
                }
                else
                {
                    Model.UpdatedByUser = ThongTinDangNhap.USER_ID;
                    Model.UpdatedDate   = TaxiReturn_Process.timerServer;
                    Model.Update();

                    #region Gửi lên server
                    if (ckb1Chieu.Checked && ckbFastTaxi.Visible && ckbFastTaxi.Checked && lue_TrangThaiDuyet.EditValue.To <int>() == (int)Enum_XeBaoDiDuongDai_TrangThaiDuyet.DaDuyet)
                    {
                        if (Distance >= 500)
                        {
                            ShowError("Hệ thống Staxi không hỗ trợ cuốc đi đường dài lớn hơn 500 km");
                        }
                        else
                        {
                            //nếu gửi rồi thì sẽ EditTrip
                            if (Model.IsAddedStaxi)
                            {
                                TaxiReturn_Process.EditTrip(Model);
                            }
                            else     // Chưa gửi lên thì sẽ AddTrip
                            {
                                var rs = TaxiReturn_Process.AddTrip(Model);
                                if (rs != null)
                                {
                                    // cập nhật trạng thái
                                    Model.UpdateIsAddedStaxi(Model.ID, ThongTinDangNhap.USER_ID, rs.AddTripSuccess);
                                }
                            }
                        }
                    }
                    #endregion

                    DialogResult = DialogResult.OK;
                    try
                    {
                        this.BeginInvoke((Action)(() => this.Close()));
                    }
                    catch (Exception ex) { }
                }
                if (Model.IsKetThuc)
                {
                    Model.UpdateStatus(Model.ID, Enum_XeBaoDiDuongDai_TrangThai.None, ThongTinDangNhap.USER_ID, true);
                    TaxiReturn_Process.TripUpdateStatus(Model.ID, ThongTinCauHinh.CompanyID, Services.FastTaxi_OperationService.Trip.Status.KetThuc);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    fw.Invoke((MethodInvoker)fw.Close);
                }
                catch (Exception ex2)
                {
                    new MessageBox.MessageBoxBA().Show("fw:" + ex2.Message);
                }

                new MessageBox.MessageBoxBA().Show("Lỗi ngoại lệ xảy ra:" + ex.Message);
            }
        }