예제 #1
0
        static void background_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var trip = e.Argument as Trip;
                if (trip != null)
                {
                    if (trip.CurrentLatLng == null)
                    {
                        trip.CurrentLatLng = new LatLng {
                            Lat = trip.GPSDonVD, Lng = trip.GPSDonKD
                        };
                    }
                    Guid bookId = Guid.NewGuid();

                    CuocGoi.G5_DIENTHOAI_UpdateBookIdByIdCuocGoi(bookId, trip.IdCuocKhach, Enum_G5_Type.DieuApp, "");

                    //var done = InitTrip(bookId, trip.IdCuocKhach, trip.DiaChiDon, trip.GPSDonKD, trip.GPSDonVD,
                    //    trip.DiaChiTra, trip.GPSTraKD, trip.GPSTraVD, trip.Note,
                    //    trip.Quantity, trip.CarType, trip.CustomerType, trip.Phone, trip.CurrentLatLng, BookTripType.Normal,0);
                    //if (!done) // Không gửi được lên thì chuyển cuốc điều đàm.
                    //{
                    //    bookId = Guid.Empty;
                    //    CuocGoi.G5_DIENTHOAI_UpdateBookIdByIdCuocGoi(bookId, trip.IdCuocKhach, Enum_G5_Type.ChuyenSangDam, "");
                    //}
                    if (trip.SoLuong > 0)
                    {
                        CopyCuocGoi1163353336(trip.IdCuocKhach, trip.SoLuong, Enum_G5_Type.DieuApp);
                    }
                }
            }
            catch (Exception ex)
            {
                LogError.WriteLogError("Khởi tạo cuốc điều App", ex);
            }
        }
        public static bool SendInitTrip(CuocGoi objCuocGoi)
        {
            try
            {
                var tenKH = "";
                if (!string.IsNullOrEmpty(objCuocGoi.DiaChiGoi.Trim()))
                {
                    tenKH = string.Format("-[{0}]", objCuocGoi.DiaChiGoi.Trim());
                }
                LatLng currentLatLng = new LatLng {
                    Lat = (float)objCuocGoi.GPS_ViDo, Lng = (float)objCuocGoi.GPS_KinhDo
                };
                var from = new AddressInfo
                {
                    Address = string.Format("{0}{1}", objCuocGoi.DiaChiDonKhach, tenKH),
                    Name    = objCuocGoi.DiaChiDonKhach,
                    LatLng  = currentLatLng
                };
                var to = new AddressInfo
                {
                    Address = objCuocGoi.DiaChiTraKhach,
                    Name    = objCuocGoi.DiaChiTraKhach,
                    LatLng  = new LatLng {
                        Lat = (float)objCuocGoi.GPS_ViDo_Tra, Lng = (float)objCuocGoi.GPS_KinhDo_Tra
                    }
                };
                byte carType = 0;
                if (objCuocGoi.G5_CarType == "" || objCuocGoi.G5_CarType.Split(',').Length > 1)
                {
                    carType = 0;
                }
                else
                {
                    byte.TryParse(objCuocGoi.G5_CarType, out carType);
                }
                byte   customerType   = 0;
                var    vehicleOptions = new List <VehicleOption>();
                string xeDonChiDinh   = ""; // objCuocGoi.XeDenDiem != null && objCuocGoi.XeDenDiem != "" ? objCuocGoi.XeDenDiem : objCuocGoi.XeNhan;
                string xeDieuChiDinh  = ""; // objCuocGoi.TrangThaiCuocGoi == TrangThaiCuocGoiTaxi.DieuLaiAppLaiXe ? string.Empty : xeDonChiDinh;
                if (Config_Common.App_SendRadioTrip && objCuocGoi.XeDenDiem.IndexOf(".") <= 0)
                {
                    xeDonChiDinh  = objCuocGoi.XeDenDiem != null && objCuocGoi.XeDenDiem != "" ? objCuocGoi.XeDenDiem : objCuocGoi.XeNhan;
                    xeDieuChiDinh = objCuocGoi.TrangThaiCuocGoi == TrangThaiCuocGoiTaxi.DieuLaiAppLaiXe ? string.Empty : xeDonChiDinh;
                }
                if (!string.IsNullOrEmpty(xeDieuChiDinh))
                {
                    var lst = xeDieuChiDinh.Split('.');
                    foreach (var s in lst)
                    {
                        vehicleOptions.Add(new VehicleOption
                        {
                            Distance = 0,                            //Khoảng cách
                            Vehicle  = CommonBL.ConvertSangBienSo(s) // Chuyển đổi thành biển số
                        });
                    }
                }
                string[] arrVehicleDeny = null;
                if (!string.IsNullOrEmpty(objCuocGoi.XeNhan))
                {
                    arrVehicleDeny = new string[] { objCuocGoi.XeNhan };
                }
                else if (!string.IsNullOrEmpty(objCuocGoi.XeDungDiem))
                {
                    arrVehicleDeny = new string[] { objCuocGoi.XeDungDiem };
                }
                Direction chieu = Direction.One;
                if (objCuocGoi.Long_ChieuID == 2)
                {
                    chieu = Direction.Two;
                }
                int GiaPhuTroi_Km  = 0;
                int GiaPhuTroi_Gio = 0;
                int LoaiXeID       = 0;
                int.TryParse(objCuocGoi.Long_LoaiXeID, out LoaiXeID);
                if (CommonBL.ListDanhMucVuotGio != null)
                {
                    Data.BanCo.Entity.TuyenThueBao.VuotGioQuyDinh temp = CommonBL.ListDanhMucVuotGio.Find(a => a.FK_LoaiXeID == LoaiXeID);
                    if (temp != null)
                    {
                        if (chieu == Direction.Two)
                        {
                            int.TryParse(temp.GiaDinhMucVuot1KmHaiChieu.ToString(), out GiaPhuTroi_Km);
                            int.TryParse(temp.GiaDinhMucVuot1GioHaiChieu.ToString(), out GiaPhuTroi_Gio);
                        }
                        else
                        {
                            int.TryParse(temp.GiaDinhMucVuot1KmMotChieu.ToString(), out GiaPhuTroi_Km);
                        }
                    }
                }
                BookTripType tripType = BookTripType.Normal;
                if (objCuocGoi.LoaiCuocKhach == LoaiCuocKhach.ChoKhachDuongDai)
                {
                    tripType = BookTripType.Long;
                }
                if (objCuocGoi.BookId == Guid.Empty)//Chưa khởi tạo thì khởi tạo
                {
                    objCuocGoi.BookId = Guid.NewGuid();
                    CuocGoi.G5_DIENTHOAI_UpdateBookIdByIdCuocGoi(objCuocGoi.BookId, objCuocGoi.IDCuocGoi, Enum_G5_Type.DieuApp, objCuocGoi.LenhDienThoai);
                    LogError.WriteLogInfo(string.Format("G5_DIENTHOAI_UpdateBookIdByIdCuocGoi:{0}-{1}-{2} Taxi", objCuocGoi.IDCuocGoi, objCuocGoi.CuocGoiLaiIDs, objCuocGoi.BookId));
                }

                string comment   = objCuocGoi.GhiChuDienThoai;
                string ghichu    = "";
                string showphone = "0";
                if (Config_Common.AppLX_CMDID_ShowPhoneNumber > 0)
                {
                    //{"p":1, "c":"ghi chu"}
                    if (objCuocGoi.GhiChuDienThoai != null && objCuocGoi.GhiChuDienThoai != "")
                    {
                        ghichu = objCuocGoi.GhiChuDienThoai;
                    }
                    if ((objCuocGoi.ShowPhoneAppDriver != null && objCuocGoi.ShowPhoneAppDriver) || objCuocGoi.LenhDienThoai.Contains(CommandCode.LENH_SHOWPHONENUMBER))
                    {
                        showphone = "1";
                    }

                    comment = "{" + string.Format("\"p\":{0}, \"c\":\"{1}\"", showphone, ghichu) + "}";
                }
                //temp.GiaDinhMucVuot1GioHaiChieu
                return(Client.TryGet(p => p.SendInitTrip(
                                         objCuocGoi.BookId,
                                         from,
                                         to,
                                         comment,
                                         (byte)objCuocGoi.SoLuong,
                                         carType,
                                         customerType,
                                         objCuocGoi.PhoneNumber,
                                         vehicleOptions.ToArray(),
                                         currentLatLng,
                                         arrVehicleDeny,
                                         tripType,
                                         objCuocGoi.Money_Contract > 0 ? objCuocGoi.Money_Contract : objCuocGoi.Long_GiaTien,
                                         objCuocGoi.Long_Km,
                                         chieu,
                                         GiaPhuTroi_Km,
                                         GiaPhuTroi_Gio)).Value);
            }
            catch (Exception ex)
            {
                LogError.WriteLogError("App SendInitTrip", ex);
                return(false);
            }
        }