示例#1
0
        public static void AddDecryptCount(string type, Counter counter)
        {
            if (counter == null)
            {
                return;
            }

            if (PHONE.Equals(type))
            {
                Interlocked.Increment(ref counter.DecryptPhoneNum);
            }
            else if (NICK.Equals(type))
            {
                Interlocked.Increment(ref counter.DecryptNickNum);
            }
            else if (RECEIVER_NAME.Equals(type))
            {
                Interlocked.Increment(ref counter.DecryptReceiverNameNum);
            }
            else if (SIMPLE.Equals(type))
            {
                Interlocked.Increment(ref counter.DecryptSimpleNum);
            }
            else if (SEARCH.Equals(type))
            {
                Interlocked.Increment(ref counter.DecryptSearchNum);
            }
        }
示例#2
0
        public IHttpActionResult PostPHONE(PHONE pHONE)
        {
            db.PHONEs.Add(pHONE);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = pHONE.ID }, pHONE));
        }
示例#3
0
        public IHttpActionResult PutPHONE(int id, PHONE pHONE)
        {
            if (id != pHONE.ID)
            {
                return(BadRequest());
            }

            db.Entry(pHONE).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PHONEExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#4
0
        /// <summary>
        /// 解密(每个用户单独分配秘钥)
        /// </summary>
        /// <param name="data">
        /// 密文数据 手机号码格式:$手机号码前3位明文$base64(encrypt(phone后8位))$111$
        /// simple格式:~base64(encrypt(nick))~111~
        /// </param>
        /// <param name="type">解密字段类型(例如:simple\phone)</param>
        /// <param name="session">用户身份,用户级加密必填</param>
        /// <returns></returns>
        public string Decrypt(string data, string type, string session)
        {
            if (string.IsNullOrEmpty(data) || data.Length < 4)
            {
                return(data);
            }

            // 获取分隔符
            Nullable <char> charValue = null;

            SecurityBiz.GetSeparatorCharMap().TryGetValue(type, out charValue);

            if (charValue == null)
            {
                throw new SecretException("type error");
            }

            // 校验
            char separator = charValue.Value;

            if (!(data[0] == separator && data[data.Length - 1] == separator))
            {
                return(data);
            }
            SecretData secretDataDO = null;

            if (data[data.Length - 2] == separator)
            {
                secretDataDO = SecurityBiz.GetIndexSecretData(data, separator);
            }
            else
            {
                secretDataDO = SecurityBiz.GetSecretData(data, separator);
            }

            // 非法密文
            if (secretDataDO == null)
            {
                return(data);
            }

            // 如果密文数据的版本号小于0代表公共秘钥
            if (secretDataDO.SecretVersion < 0)
            {
                secretDataDO.SecretVersion = Math.Abs(secretDataDO.SecretVersion.Value);
                session = null;
            }
            securityCounter.AddDecryptCount(type, session);// 计数器
            SecretContext secretContextDO = secretCore.GetSecret(session, secretDataDO.SecretVersion);
            string        decryptValue    = SecurityUtil.AESDecrypt(secretDataDO.OriginalBase64Value, secretContextDO.Secret);

            if (PHONE.Equals(type) && !secretDataDO.Search)
            {
                // 加上手机号前3位,手机号只加密了后8位
                return(secretDataDO.OriginalValue + decryptValue);
            }
            return(decryptValue);
        }
示例#5
0
        /// <summary>
        /// 加密之后格式。 手机号码格式:$手机号码前3位明文$base64(encrypt(phone后8位))$111$
        /// nick格式:~base64(encrypt(nick))~111~
        /// </summary>
        /// <param name="data">明文数据</param>
        /// <param name="type">加密字段类型(例如:nick\phone)</param>
        /// <param name="session">用户身份,用户级加密必填</param>
        /// <param name="version">秘钥历史版本</param>
        /// <returns></returns>
        private string Encrypt(string data, string type, string session, Nullable <Int64> version)
        {
            if (string.IsNullOrEmpty(data))
            {
                return(data);
            }
            SecretContext secretContext = secretCore.GetSecret(session, version);

            if (secretContext == null)
            {
                throw new SecretException("secretKey is null");
            }
            if (secretContext.Secret == null)
            {
                return(data);
            }

            string separator = null;

            SecurityBiz.GetSeparatorMap().TryGetValue(type, out separator);
            if (separator == null)
            {
                throw new SecretException("type error");
            }

            SecurityCounter.AddEncryptCount(type);// 计数器
            bool isEncryptIndex = secretCore.IsIndexEncrypt(type, version);

            // 支持密文检索
            if (isEncryptIndex)
            {
                if (PHONE.Equals(type))
                {
                    return(SecurityBiz.EncryptPhoneIndex(data, separator, secretContext));
                }
                else
                {
                    int compressLen = secretCore.GetCompressLen();
                    int slideSize   = secretCore.GetSlideSize();
                    return(SecurityBiz.EncryptNormalIndex(data, compressLen, slideSize, separator, secretContext));
                }
            }
            else
            {
                if (PHONE.Equals(type))
                {
                    return(SecurityBiz.EncryptPhone(data, separator, secretContext));
                }
                else
                {
                    return(SecurityBiz.EncryptNormal(data, separator, secretContext));
                }
            }
        }
示例#6
0
        public IHttpActionResult GetPHONE(int id)
        {
            PHONE pHONE = db.PHONEs.Find(id);

            if (pHONE == null)
            {
                return(NotFound());
            }

            return(Ok(pHONE));
        }
示例#7
0
        public IHttpActionResult DeletePHONE(int id)
        {
            PHONE pHONE = db.PHONEs.Find(id);

            if (pHONE == null)
            {
                return(NotFound());
            }

            db.PHONEs.Remove(pHONE);
            db.SaveChanges();

            return(Ok(pHONE));
        }
示例#8
0
 public static void AddDecryptCount(string type)
 {
     if (PHONE.Equals(type))
     {
         Interlocked.Increment(ref DecryptPhoneNum);
     }
     else if (NICK.Equals(type))
     {
         Interlocked.Increment(ref DecryptNickNum);
     }
     else if (RECEIVER_NAME.Equals(type))
     {
         Interlocked.Increment(ref DecryptReceiverNameNum);
     }
 }
示例#9
0
 public static void AddSearchCount(string type)
 {
     if (PHONE.Equals(type))
     {
         Interlocked.Increment(ref SearchPhoneNum);
     }
     else if (NICK.Equals(type))
     {
         Interlocked.Increment(ref SearchNickNum);
     }
     else if (RECEIVER_NAME.Equals(type))
     {
         Interlocked.Increment(ref SearchReceiverNameNum);
     }
 }
示例#10
0
        /// <summary>
        /// 密文检索。 手机号码格式:$base64(H-MAC(phone后4位))$ simple格式:base64(H-MAC(滑窗))
        /// </summary>
        /// <param name="data">明文数据</param>
        /// <param name="type">加密字段类型(例如:simple\phone)</param>
        /// <param name="session">用户身份,用户级加密必填</param>
        /// <param name="version">秘钥历史版本</param>
        /// <returns></returns>
        private string Search(string data, string type, string session, Nullable <Int64> version)
        {
            if (string.IsNullOrEmpty(data))
            {
                return(data);
            }

            SecretContext secretContext = secretCore.GetSecret(session, version);

            if (secretContext == null)
            {
                throw new SecretException("secretKey is null");
            }
            if (secretContext.Secret == null)
            {
                return(data);
            }

            string separator = null;

            SecurityBiz.GetSeparatorMap().TryGetValue(type, out separator);
            if (separator == null)
            {
                throw new SecretException("type error");
            }

            // 公共秘钥版本号用负数区分
            if (session == null)
            {
                SecretContext publicSecretContext = new SecretContext();
                publicSecretContext.Secret        = secretContext.Secret;
                publicSecretContext.SecretVersion = -secretContext.SecretVersion;
                secretContext = publicSecretContext;
            }

            securityCounter.AddSearchCount(type, session);// 计数器
            if (PHONE.Equals(type))
            {
                return(SecurityBiz.SearchPhoneIndex(data, separator, secretContext));
            }
            else
            {
                int compressLen = secretCore.GetCompressLen();
                int slideSize   = secretCore.GetSlideSize();
                return(SecurityBiz.SearchNormalIndex(data, compressLen, slideSize, secretContext));
            }
        }
 public bool UpdatePhone(PHONE Entity)
 {
     using (KARYABDBEntities db = new KARYABDBEntities())
     {
         try
         {
             // var Skill = db.SKILLS.FirstOrDefault(q => q.ID == SkillID);
             db.PHONES.Attach(Entity);
             var Entry = db.Entry(Entity);
             Entry.State = EntityState.Modified;
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
 public long SetPhone(PHONE Phone, long HumanID)
 {
     using (KARYABDBEntities db = new KARYABDBEntities())
     {
         try
         {
             db.Configuration.ProxyCreationEnabled = false;
             db.PHONES.Add(Phone);
             db.SaveChanges();
             OWNERSPHO owenersPhone = new OWNERSPHO();
             owenersPhone.PHONENUMBERID = Phone.ID;
             owenersPhone.PHONEOWNERID  = HumanID;
             db.OWNERSPHOES.Add(owenersPhone);
             db.SaveChanges();
             return(Phone.ID);
         }
         catch
         {
             return(0);
         }
     }
 }
        public bool DeletePhone(PHONE Entity)
        {
            using (KARYABDBEntities db = new KARYABDBEntities())
            {
                try
                {
                    db.Configuration.ProxyCreationEnabled = false;
                    PHONE     entity = db.PHONES.FirstOrDefault(q => q.ID == Entity.ID);
                    OWNERSPHO Owner  = db.OWNERSPHOES.FirstOrDefault(q => q.PHONENUMBERID == Entity.ID);
                    db.OWNERSPHOES.Attach(Owner);
                    db.OWNERSPHOES.Remove(Owner);
                    db.SaveChanges();
                    db.PHONES.Attach(entity);
                    db.PHONES.Remove(entity);
                    db.SaveChanges();

                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
示例#14
0
        protected object GetObjectById(int _id, bool _master, string _slaveType, string _masterType)
        {
            switch (typeof(T).Name)
            {
            case "FAMILY":
                FAMILY family = null;
                if (_id == 0)
                {
                    family = egoEntities.FAMILY.FirstOrDefault();
                }
                else
                {
                    family = egoEntities.FAMILY.FirstOrDefault(x => x.FAMILYID == _id);
                }
                return(family == null ? new FAMILY() : family);

            case "PERSON":
                PERSON person = null;
                if (_master)
                {
                    person = _id == 0 ? egoEntities.PERSON.FirstOrDefault() : egoEntities.PERSON.FirstOrDefault(x => x.PERSONID == _id);
                }
                else
                {
                    if (_masterType == "GYMGROUP")
                    {
                        PERSON_GYMGROUP person_gymGroup = new PERSON_GYMGROUP();
                        person_gymGroup = _id == 0 ? egoEntities.PERSON_GYMGROUP.FirstOrDefault() : egoEntities.PERSON_GYMGROUP.FirstOrDefault(x => x.PERSON_GYMGROUP_ID == _id);
                        return(person_gymGroup == null ? new PERSON_GYMGROUP() : person_gymGroup);
                    }
                    else if (_masterType == "FAMILY")
                    {
                        person = _id == 0 ? egoEntities.PERSON.FirstOrDefault() : egoEntities.PERSON.FirstOrDefault(x => x.PERSONID == _id);
                    }
                }
                return(person == null ? new PERSON() : person);

            case "PHONE":
                PHONE Phone = null;
                Phone = _id == 0 ? egoEntities.PHONE.FirstOrDefault() : egoEntities.PHONE.FirstOrDefault(x => x.PHONEID == _id);
                return(Phone == null ? new PHONE() : Phone);

            case "DISCOUNT":
                DISCOUNT Discount = null;
                Discount = _id == 0 ? egoEntities.DISCOUNT.FirstOrDefault() : egoEntities.DISCOUNT.FirstOrDefault(x => x.DISCOUNTID == _id);
                return(Discount == null ? new DISCOUNT() : Discount);

            case "PAYMENT":
                PAYMENT Payment = null;
                Payment = _id == 0 ? egoEntities.PAYMENT.FirstOrDefault() : egoEntities.PAYMENT.FirstOrDefault(x => x.PAYMENTID == _id);
                return(Payment == null ? new PAYMENT() : Payment);

            case "DOCUMENT":
                DOCUMENT Document = null;
                Document = _id == 0 ? egoEntities.DOCUMENT.FirstOrDefault() : egoEntities.DOCUMENT.FirstOrDefault(x => x.DOCUMENTID == _id);
                return(Document == null ? new DOCUMENT() : Document);

            case "GYMGROUP":
                if (_master)
                {
                    GYMGROUP GymGroup = null;
                    GymGroup = _id == 0 ? egoEntities.GYMGROUP.FirstOrDefault() : egoEntities.GYMGROUP.FirstOrDefault(x => x.GYMGROUPID == _id);
                    return(GymGroup == null ? new GYMGROUP() : GymGroup);
                }
                else
                {
                    PERSON_GYMGROUP Person_GymGroup = new PERSON_GYMGROUP();
                    Person_GymGroup = _id == 0 ? egoEntities.PERSON_GYMGROUP.FirstOrDefault() : egoEntities.PERSON_GYMGROUP.First(x => x.PERSON_GYMGROUP_ID == _id);
                    return(Person_GymGroup == null ? new PERSON_GYMGROUP() : Person_GymGroup);
                }
            }

            return(null);
        }
示例#15
0
 public PhoneSearchView(PHONE phone)
 {
     this.PHONEID     = phone.PHONEID;
     this.PHONENUMBER = phone.PHONENUMBER;
 }
示例#16
0
        private static void CreatePerson(List <ExcelModel> _ExcelModel, EGOEntities _EGOEntities, FrmSetting _FrmSetting)
        {
            _FrmSetting.progressBar.Value   = 0;
            _FrmSetting.progressBar.Maximum = _ExcelModel.Count;
            int i = 0;

            try
            {
                foreach (var ExcelModel in _ExcelModel)
                {
                    i++;
                    _FrmSetting.label1.Text = "Création de l'adhérent:" + ExcelModel.NOM + " " + ExcelModel.PRENOM + i + "/" + _ExcelModel.Count;
                    _FrmSetting.label1.Refresh();
                    _FrmSetting.progressBar.Value = i;
                    _FrmSetting.progressBar.Refresh();

                    FAMILY Family;
                    if (!_EGOEntities.FAMILY.Any(x => x.LASTNAME == ExcelModel.NOM && x.ZIPCODE == ExcelModel.CP))
                    {
                        Family = CreateFamily(ExcelModel, _EGOEntities);
                    }
                    else
                    {
                        Family = _EGOEntities.FAMILY.First(x => x.LASTNAME == ExcelModel.NOM && x.ZIPCODE == ExcelModel.CP);
                    }

                    PERSON Person = new PERSON();
                    Person.FAMILYID   = Family.FAMILYID;
                    Person.LASTNAME   = ExcelModel.NOM.ToUpper();
                    Person.FIRSTNAME  = ExcelModel.PRENOM.ToUpper();
                    Person.BIRTHDATE  = ExcelModel.NEELE;
                    Person.HOURLYRATE = 0;

                    _EGOEntities.PERSON.Add(Person);

                    GYMGROUP GymGroup;
                    if (!_EGOEntities.GYMGROUP.Any(x => x.GYMGROUPNAME == ExcelModel.GROUPE))
                    {
                        GymGroup = CreateGymGroup(ExcelModel, _EGOEntities);
                    }
                    else
                    {
                        GymGroup = _EGOEntities.GYMGROUP.First(x => x.GYMGROUPNAME == ExcelModel.GROUPE);
                    }

                    PERSON_GYMGROUP Person_GymGroup = new PERSON_GYMGROUP();
                    Person_GymGroup.GYMGROUPID = GymGroup.GYMGROUPID;
                    Person_GymGroup.PERSONID   = Person.PERSONID;
                    Person_GymGroup.KINDID     = 1;

                    _EGOEntities.PERSON_GYMGROUP.Add(Person_GymGroup);

                    if (!_EGOEntities.PHONE.Any(x => x.FAMILYID == Family.FAMILYID && x.PHONENUMBER == ExcelModel.TELEPHONE))
                    {
                        PHONE Phone = new PHONE();
                        Phone.FAMILYID    = Family.FAMILYID;
                        Phone.PHONENUMBER = ExcelModel.TELEPHONE;
                        _EGOEntities.PHONE.Add(Phone);
                    }

                    if (!_EGOEntities.PHONE.Any(x => x.FAMILYID == Family.FAMILYID && x.PHONENUMBER == ExcelModel.PORTABLE))
                    {
                        PHONE Phone = new PHONE();
                        Phone.FAMILYID    = Family.FAMILYID;
                        Phone.PHONENUMBER = ExcelModel.PORTABLE;
                        _EGOEntities.PHONE.Add(Phone);
                    }

                    DOCUMENT Document;
                    if (ExcelModel.FICHE)
                    {
                        Document = new DOCUMENT();
                        Document.DOCUMENTTYPEID = 1;
                        Document.PERSONID       = Person.PERSONID;
                        Document.DOCUMENTYEAR   = Common.CurrentStartYear();
                        _EGOEntities.DOCUMENT.Add(Document);
                    }
                    if (ExcelModel.AUTPAR)
                    {
                        Document = new DOCUMENT();
                        Document.DOCUMENTTYPEID = 2;
                        Document.PERSONID       = Person.PERSONID;
                        Document.DOCUMENTYEAR   = Common.CurrentStartYear();
                        _EGOEntities.DOCUMENT.Add(Document);
                    }
                    if (ExcelModel.PHOTO)
                    {
                        Document = new DOCUMENT();
                        Document.DOCUMENTTYPEID = 3;
                        Document.PERSONID       = Person.PERSONID;
                        Document.DOCUMENTYEAR   = Common.CurrentStartYear();
                        _EGOEntities.DOCUMENT.Add(Document);
                    }
                    if (ExcelModel.CM)
                    {
                        Document = new DOCUMENT();
                        Document.DOCUMENTTYPEID = 4;
                        Document.PERSONID       = Person.PERSONID;
                        Document.DOCUMENTYEAR   = Common.CurrentStartYear();
                        _EGOEntities.DOCUMENT.Add(Document);
                    }

                    PAYMENT Payment;
                    if (ExcelModel.ECH1MONTANT != 0)
                    {
                        Payment = new PAYMENT();
                        if (ExcelModel.ECH1NUMCHEQUE != 0)
                        {
                            Payment.PAYMENTTYPEID = 2;
                        }
                        else
                        {
                            Payment.PAYMENTTYPEID = 1;
                        }
                        Payment.FAMILYID    = Family.FAMILYID;
                        Payment.GYMYEAR     = Common.CurrentStartYear();
                        Payment.PAYMENTDATE = DateTime.ParseExact("30/09/2020", "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        Payment.CHECKNUMBER = ExcelModel.ECH1NUMCHEQUE;
                        Payment.AMOUNT      = ExcelModel.ECH1MONTANT;
                        _EGOEntities.PAYMENT.Add(Payment);
                    }
                    if (ExcelModel.ECH2MONTANT != 0)
                    {
                        Payment = new PAYMENT();
                        if (ExcelModel.ECH2NUMCHEQUE != 0)
                        {
                            Payment.PAYMENTTYPEID = 2;
                        }
                        else
                        {
                            Payment.PAYMENTTYPEID = 1;
                        }
                        Payment.FAMILYID    = Family.FAMILYID;
                        Payment.GYMYEAR     = Common.CurrentStartYear();
                        Payment.PAYMENTDATE = DateTime.ParseExact("30/11/2020", "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        Payment.CHECKNUMBER = ExcelModel.ECH2NUMCHEQUE;
                        Payment.AMOUNT      = ExcelModel.ECH2MONTANT;
                        _EGOEntities.PAYMENT.Add(Payment);
                    }
                    if (ExcelModel.ECH3MONTANT != 0)
                    {
                        Payment = new PAYMENT();
                        if (ExcelModel.ECH3NUMCHEQUE != 0)
                        {
                            Payment.PAYMENTTYPEID = 2;
                        }
                        else
                        {
                            Payment.PAYMENTTYPEID = 1;
                        }
                        Payment.FAMILYID    = Family.FAMILYID;
                        Payment.GYMYEAR     = Common.CurrentStartYear();
                        Payment.PAYMENTDATE = DateTime.ParseExact("28/02/2021", "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        Payment.CHECKNUMBER = ExcelModel.ECH3NUMCHEQUE;
                        Payment.AMOUNT      = ExcelModel.ECH3MONTANT;
                        _EGOEntities.PAYMENT.Add(Payment);
                    }
                    if (ExcelModel.ECH4MONTANT != 0)
                    {
                        Payment = new PAYMENT();
                        if (ExcelModel.ECH4NUMCHEQUE != 0)
                        {
                            Payment.PAYMENTTYPEID = 2;
                        }
                        else
                        {
                            Payment.PAYMENTTYPEID = 1;
                        }
                        Payment.FAMILYID    = Family.FAMILYID;
                        Payment.GYMYEAR     = Common.CurrentStartYear();
                        Payment.PAYMENTDATE = DateTime.ParseExact("30/04/2021", "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        Payment.CHECKNUMBER = ExcelModel.ECH4NUMCHEQUE;
                        Payment.AMOUNT      = ExcelModel.ECH4MONTANT;
                        _EGOEntities.PAYMENT.Add(Payment);
                    }
                    if (ExcelModel.COTISLICENCE != 0)
                    {
                        Payment = new PAYMENT();

                        Payment.PAYMENTTYPEID = 2;
                        Payment.FAMILYID      = Family.FAMILYID;
                        Payment.GYMYEAR       = Common.CurrentStartYear();
                        Payment.PAYMENTDATE   = DateTime.ParseExact("28/09/2020", "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        Payment.CHECKNUMBER   = ExcelModel.ECH4NUMCHEQUE;
                        Payment.AMOUNT        = ExcelModel.COTISLICENCE;
                        _EGOEntities.PAYMENT.Add(Payment);
                    }

                    if (!ExcelModel.Nouvelle)
                    {
                        DISCOUNT Discount = new DISCOUNT();
                        Discount.FAMILYID     = Family.FAMILYID;
                        Discount.DISCOUNTYEAR = Common.CurrentStartYear();
                        Discount.DESCRIPTION  = "Cotisation";
                        Discount.AMOUNT       = 35;

                        _EGOEntities.DISCOUNT.Add(Discount);

                        Discount              = new DISCOUNT();
                        Discount.FAMILYID     = Family.FAMILYID;
                        Discount.DISCOUNTYEAR = Common.CurrentStartYear();
                        Discount.DESCRIPTION  = "Ancienneté";
                        Discount.AMOUNT       = ExcelModel.REDUCANCIEN;

                        _EGOEntities.DISCOUNT.Add(Discount);
                    }

                    _EGOEntities.SaveChanges();
                }

                _FrmSetting.label1.Text = "Création des réductions familiales";
                CreateFamilyDiscount(_EGOEntities);
                _EGOEntities.SaveChanges();
                _FrmSetting.label1.Text       = "Fin";
                _FrmSetting.progressBar.Value = 0;
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }