private void KhoiTaoDanhBaOnMEM_CongTy_GetLast(DateTime LastUpdate)
 {
     try
     {
         List <DanhBaEx> listDBCongTy = new List <DanhBaEx>();
         listDBCongTy = DanhBaEx.GetDanhBaCONGTY_GetLast(LastUpdate);
         // thêm vào dic
         foreach (DanhBaEx dbcty in listDBCongTy)
         {
             // chưa tồn tài thì thêm vào ds
             if (!dicDanhBaCongTy.ContainsKey(dbcty.PhoneNumber))
             {
                 dicDanhBaCongTy.TryAdd(dbcty.PhoneNumber, dbcty);
             }
             else
             {
                 dicDanhBaCongTy[dbcty.PhoneNumber] = dbcty;
             }
             if (Global.IsDebug)
             {
                 LogError.WriteLogInfo("KhoiTaoDanhBaOnMEM_CongTy_GetLast:" + dbcty.PhoneNumber + "-" + dbcty.Address);
             }
         }
     }
     catch (Exception ex)
     {
         LogError.WriteLogError("KhoiTaoDanhBaOnMEM_CongTy_GetLast.", ex);
     }
 }
 private void KhoiTaoDanhBaOnMEM_KhachHang_GetLast(DateTime LastUpdate)
 {
     try
     {
         List <DanhBaEx> lstKhachVip = DanhBaKhachQuen.GetKhachQuens_LastUpdate_V2(LastUpdate);
         if (lstKhachVip != null && lstKhachVip.Count > 0)
         {
             g_ThoiDiemLayTruoc_KhachHang = DateTime.Now;
             foreach (var item in lstKhachVip)
             {
                 if (dicKhachQuen.ContainsKey(item.PhoneNumber))
                 {
                     dicKhachQuen[item.PhoneNumber] = item;
                 }
                 else
                 {
                     dicKhachQuen.TryAdd(item.PhoneNumber, item);
                 }
                 if (Global.IsDebug)
                 {
                     LogError.WriteLogInfo("KhoiTaoDanhBaOnMEM_KhachHang_GetLast:" + item.PhoneNumber + "-" + item.Address);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LogError.WriteLogError("KhoiTaoDanhBaOnMEM_KhachHang_GetLast.", ex);
     }
 }
 private void bwSync_LoadDanhBaKhachQuen_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         List <DanhBaEx> lstKhachVip = DanhBaKhachQuen.GetAllKhachQuens_V2();
         if (lstKhachVip != null && lstKhachVip.Count > 0)
         {
             DanhBaEx dicRet = new DanhBaEx();
             foreach (DanhBaEx item in lstKhachVip)
             {
                 if (dicKhachQuen.ContainsKey(dicRet.PhoneNumber))
                 {
                     continue;
                 }
                 dicKhachQuen.TryAdd(dicRet.PhoneNumber, dicRet);
                 if (Global.IsDebug)
                 {
                     LogError.WriteLogInfo("bwSync_LoadDanhBaKhachQuen_DoWork:" + dicRet.PhoneNumber + "-" + dicRet.Address);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LogError.WriteLogError("bwSync_LoadDanhBaKhachQuen_DoWork.", ex);
     }
 }
 private void KhoiTaoDanhBaOnMEM_DoiTac_GetLast(DateTime LastUpdate)
 {
     try
     {
         List <DanhBaEx> listDBMoiGioi = DanhBaEx.GetDanhBaMoiGioi_LastUpdate(LastUpdate);
         if (dicMoiGioi == null)
         {
             dicMoiGioi = new ConcurrentDictionary <string, DanhBaEx>();
         }
         foreach (DanhBaEx dbex in listDBMoiGioi)
         {
             DanhBaEx dbexOut = new DanhBaEx();
             if (!dicMoiGioi.ContainsKey(dbex.PhoneNumber))
             {
                 if (dbex.IsActive)
                 {
                     dicMoiGioi.TryAdd(dbex.PhoneNumber, dbex);
                 }
                 else
                 {
                     dicMoiGioi.TryRemove(dbex.PhoneNumber, out dbexOut);
                 }
             }
             else
             {
                 if (dbex.IsActive)
                 {
                     dicMoiGioi[dbex.PhoneNumber] = dbex;
                 }
             }
             if (Global.IsDebug)
             {
                 LogError.WriteLogInfo("KhoiTaoDanhBaOnMEM_DoiTac_GetLast:" + dbex.PhoneNumber + "-" + dbex.Address);
             }
         }
     }
     catch (Exception ex)
     {
         LogError.WriteLogError("KhoiTaoDanhBaOnMEM_DoiTac_GetLast.", ex);
     }
 }
        /// <summary>
        /// Load danh sách  cuộc gọi gần đây
        /// </summary>
        private void KhoiTaoCuocKhachOnlineLenMEM()
        {
            try
            {
                dicCuocOnline.Clear();
                DataTable dt = new Data.CuocGoi().GetCuocOnlines_v2();
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        DanhBaEx dicRet      = new DanhBaEx();
                        string   soDienThoai = dr["PhoneNumber"] == DBNull.Value ? string.Empty : dr["PhoneNumber"].ToString();
                        string   diaChi      = dr["DiaChiDonKhach"] == DBNull.Value ? string.Empty : dr["DiaChiDonKhach"].ToString();
                        if (soDienThoai != string.Empty && diaChi != string.Empty)
                        {
                            if (dicCuocOnline.ContainsKey(soDienThoai))
                            {
                                continue;
                            }

                            string   diaChiTra       = dr["DiaChiTraKhach"] == DBNull.Value ? string.Empty : dr["DiaChiTraKhach"].ToString();
                            int      vung            = dr["Vung"] == DBNull.Value ? 0 : int.Parse(dr["Vung"].ToString());
                            string   maDoiTac        = dr["MaDoiTac"] == DBNull.Value ? string.Empty : dr["MaDoiTac"].ToString();
                            string   loaiXe          = dr["LoaiXe"] == DBNull.Value ? string.Empty : dr["LoaiXe"].ToString();
                            float    kinhDo          = dr["GPS_KinhDo"] == DBNull.Value ? 0 : float.Parse(dr["GPS_KinhDo"].ToString());
                            float    viDo            = dr["GPS_ViDo"] == DBNull.Value ? 0 : float.Parse(dr["GPS_ViDo"].ToString());
                            string   lenhDienThoai   = dr["LenhDienThoai"] == DBNull.Value ? string.Empty : dr["LenhDienThoai"].ToString();
                            string   GhiChuDienThoai = dr["GhiChuDienThoai"] == DBNull.Value ? string.Empty : dr["GhiChuDienThoai"].ToString();
                            DateTime ThoiDiemGoi     = dr["ThoiDiemGoi"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(dr["ThoiDiemGoi"].ToString());
                            long     ID           = dr["ID"] == DBNull.Value ? 0 : long.Parse(dr["ID"].ToString());
                            int      SoLanGoi     = dr["SoLanGoi"] == DBNull.Value ? 0 : int.Parse(dr["SoLanGoi"].ToString());
                            int      KieuKHGoiDen = dr["KieuKhachHangGoiDen"] == DBNull.Value ? 0 : int.Parse(dr["KieuKhachHangGoiDen"].ToString());

                            dicRet.Address             = diaChi;
                            dicRet.PhoneNumber         = soDienThoai;
                            dicRet.Vung                = vung;
                            dicRet.MaDoiTac            = maDoiTac;
                            dicRet.LoaiXe              = loaiXe;
                            dicRet.Address_Destination = diaChiTra;
                            dicRet.GPS_KinhDo          = kinhDo;
                            dicRet.GPS_ViDo            = viDo;
                            dicRet.LenhTiepNhan        = lenhDienThoai;
                            dicRet.GhiChuTiepNhan      = GhiChuDienThoai;
                            dicRet.SoLanGoi            = SoLanGoi;
                            dicRet.IdCuocGoi           = ID;
                            dicRet.ThoiDiemGoi         = ThoiDiemGoi;
                            try
                            {
                                dicRet.KieuKHGoiDen = (KieuKhachHangGoiDen)KieuKHGoiDen;
                            }
                            catch
                            {
                                dicRet.KieuKHGoiDen = KieuKhachHangGoiDen.KhachHangBinhThuong;
                            }
                            dicCuocOnline.TryAdd(soDienThoai, dicRet);
                            if (Global.IsDebug)
                            {
                                LogError.WriteLogInfo("KhoiTaoCuocKhachOnlineLenMEM:" + soDienThoai + "-" + dicRet.Address);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogError.WriteLogError("KhoiTaoCuocKhachOnlineLenMEM.", ex);
            }
        }
        public DanhBaEx GetGlobalContacsInfo(string phoneNumber)
        {
            DanhBaEx item = new DanhBaEx();

            try
            {
                if (Global.IsDebug)
                {
                    LogError.WriteLogInfo("GetGlobalContacsInfo:" + phoneNumber);
                }


                if (dicMoiGioi.ContainsKey(phoneNumber))
                {
                    item = dicMoiGioi[phoneNumber];
                    if (Global.IsDebug)
                    {
                        LogError.WriteLogInfo("dicMoiGioi:" + phoneNumber + "-" + item.Address);
                    }
                    return(item);
                }
                // lấy từ cuốc online
                //lock (dicCuocOnline)
                //{
                if (dicCuocOnline.ContainsKey(phoneNumber))
                {
                    item = dicCuocOnline[phoneNumber];
                    if (Global.IsDebug)
                    {
                        LogError.WriteLogInfo("dicCuocOnline:" + dicCuocOnline.Count.ToString() + "-" + dicCuocOnline[phoneNumber].PhoneNumber + "-" + item.PhoneNumber + "-" + " - " + phoneNumber + item.Address);
                    }
                    return(dicCuocOnline[phoneNumber]);
                }
                //}

                if (dicKhachQuen.ContainsKey(phoneNumber))
                {
                    item = dicKhachQuen[phoneNumber];
                    if (Global.IsDebug)
                    {
                        LogError.WriteLogInfo("dicKhachQuen:" + phoneNumber + "-" + item.Address);
                    }
                    return(item);
                }

                // lấy theo danh bạ
                if (dicDanhBaCongTy.ContainsKey(phoneNumber))
                {
                    item = dicDanhBaCongTy[phoneNumber];
                    if (Global.IsDebug)
                    {
                        LogError.WriteLogInfo("dicDanhBaCongTy:" + phoneNumber + "-" + item.Address);
                    }
                    return(item);
                }
                //if (soDienThoai.StartsWith("04"))
                //{
                //    //Nếu là số điện thoại bàn ở HN thì mới check trong danh mục Bưu Điện.
                //    if (dicDanhBa_BuuDien.ContainsKey(soDienThoai))
                //    {
                //        item = dicDanhBa_BuuDien[soDienThoai];
                //        diaChi = item.Address;
                //        if (item.Name != "")
                //            diaChi = string.Format("[{0}]{1}", item.Name, diaChi);

                //        kieuKhachHang = KieuKhachHangGoiDen.KhachHangBinhThuong;
                //    }
                //}
            }
            catch (Exception ex)
            {
                LogError.WriteLogError("GetGlobalContacsInfo.", ex);
                return(item);
            }
            return(item);
        }