public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[BasicCity]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            BasicCity BasicCity = new BasicCity();

            BasicCity = JsonToObject.ConvertJsonToModel(BasicCity, json);

            IList <BasicCity> BasicCityList = Entity.BasicCity.Where(n => n.State == 1 && n.PId == BasicCity.PId).ToList();

            DataObj.Data = BasicCityList.EntityToJson();
            DataObj.Code = "0000";
            DataObj.OutString();
        }
        public void Save(BasicCity BasicCity)
        {
            BasicCity baseBasicCity = Entity.BasicCity.FirstOrDefault(n => n.Id == BasicCity.Id);

            baseBasicCity = Request.ConvertRequestToModel <BasicCity>(baseBasicCity, BasicCity);
            Entity.SaveChanges();
            BaseRedirect();
        }
Exemplo n.º 3
0
 void UnselectCity(BasicCity city)
 {
     (city.OutputInfo as OutputInfoWPF).cityShape.Stroke =
         (city.InputInfo as CityInputInfoWPF).strokeColorBeforeSelection;
     (city.OutputInfo as OutputInfoWPF).cityShape.StrokeThickness =
         (city.InputInfo as CityInputInfoWPF).strokeThicknessBeforeSelection;
     selectedCity.Remove(city);
 }
        public void ChangeStatus(BasicCity BasicCity, string InfoList, string Clomn, string Value)
        {
            if (string.IsNullOrEmpty(InfoList))
            {
                InfoList = BasicCity.Id.ToString();
            }
            int Ret = Entity.ChangeEntity <BasicCity>(InfoList, Clomn, Value);

            Entity.SaveChanges();
            Response.Write(Ret);
        }
Exemplo n.º 5
0
    protected void showInfoCity(string cityID)
    {
        BasicCity basicCity = new BasicCity();

        if (!string.IsNullOrEmpty(cityID))
        {
            basicCity             = new BasicCityService().GetCityByCityID(cityID);
            this.txtCityName.Text = basicCity.Name;
            this.txtCityCode.Text = basicCity.Code;
        }
    }
Exemplo n.º 6
0
 void SendUnits(BasicCity city)
 {
     foreach (var i in selectedCity)
     {
         if (i.PlayerId == PlayerId)
         {
             i.SendUnit(city);
         }
     }
     UnselectAll();
 }
        public void Delete(BasicCity BasicCity, string InfoList, int?IsDel)
        {
            if (string.IsNullOrEmpty(InfoList))
            {
                InfoList = BasicCity.Id.ToString();
            }
            int Ret = Entity.MoveToDeleteEntity <BasicCity>(InfoList, IsDel, AdminUser.UserName);

            Entity.SaveChanges();
            Response.Write(Ret);
        }
Exemplo n.º 8
0
        int GetAvgDistance(BasicCity city)
        {
            double avg = 0;

            foreach (var bs in botCities)
            {
                avg += bs.BuildOptimalPath(city, out BasicCity realDest).Count;
            }
            avg /= botCities.Count();

            return((int)Math.Round(avg));
        }
Exemplo n.º 9
0
 double GetEnemyArmy(BasicCity cityTo)
 {
     if (cityTo.PlayerId == 0)
     {
         return(cityTo.currWarriors +
                rushWithMinimumMoreUnits);
     }
     else
     {
         return(cityTo.currWarriors +
                rushWithMinimumMoreUnits +
                GetAvgSpeed() * GetAvgDistance(cityTo) / cityTo.ticksPerIncome);
     }
 }
Exemplo n.º 10
0
 public void Add(DaiLiApply DaiLiApply)
 {
     //TODO:因为代理级别业务修改,这里这要改变
     //if (BasicAgent.Levels == 3) {
     //    DaiLiApply Temp = Entity.DaiLiApply.FirstOrDefault(n => n.Agent == BasicAgent.Id && (n.OrderState == 1 || n.OrderState == 2));
     //    if (Temp != null) {
     //        Response.Write("有未处理完成订单在处理中~");
     //        return;
     //    }
     //}
     DaiLiApply            = Request.ConvertRequestToModel <DaiLiApply>(DaiLiApply, DaiLiApply);
     DaiLiApply.AddTime    = DateTime.Now;
     DaiLiApply.Agent      = BasicAgent.Id;
     DaiLiApply.AId        = AdminUser.Id;
     DaiLiApply.Amoney     = 0;
     DaiLiApply.OrderState = 1;//1待处理 2已开通 3取消
     if (DaiLiApply.Area.IsNullOrEmpty())
     {
         int Area = 0;
         try
         {
             Area = Int32.Parse(DaiLiApply.Area);
         }
         catch (Exception) { }
         if (!Area.IsNullOrEmpty())
         {
             BasicCity     BasicCity     = Entity.BasicCity.FirstOrNew(n => n.Id == Area);
             BasicProvince BasicProvince = Entity.BasicProvince.FirstOrNew(n => n.Id == BasicCity.PId);
             DaiLiApply.Area = BasicProvince.Name + "|" + BasicCity.Name;
         }
     }
     //if (BasicAgent.Levels == 3) {
     //    DaiLiApply.Remark = "金牌代理申请升级钻石代理";
     //}
     //Entity.DaiLiApply.AddObject(DaiLiApply);
     //Entity.SaveChanges();
     //if (BasicAgent.Levels == 3) {
     //    Response.Redirect("/Agent/DaiLiApply/Edit.html");
     //}
     //if (BasicAgent.Levels == 4)
     //{
     //    Response.Redirect("/Agent/DaiLiApply/Index.html");
     //}
 }
 public ActionResult Edit(BasicCity BasicCity)
 {
     if (BasicCity.Id != 0)
     {
         BasicCity = Entity.BasicCity.FirstOrDefault(n => n.Id == BasicCity.Id);
     }
     if (BasicCity == null)
     {
         ViewBag.ErrorMsg = "数据不存在";
         return(View("Error"));
     }
     ViewBag.BasicCity         = BasicCity;
     ViewBag.BasicProvinceList = Entity.BasicProvince.Where(n => n.State == 1).ToList();
     if (Request.UrlReferrer != null)
     {
         Session["Url"] = Request.UrlReferrer.ToString();
     }
     return(View());
 }
Exemplo n.º 12
0
        public override bool TickReact()
        {
            if (lp.ControlInfoForParts[0].Count != 0)
            {
                command = new Command {
                    fromType = Command.FromType.Direct,
                    toType   = Command.ToType.Direct,
                };
                BasicCity from = null;
                BasicCity to   = null;

                bool findFirst = false;
                foreach (var fromCity in lp.ControlInfoForParts[this.PlayerId].Keys)
                {
                    from = fromCity;
                    foreach (var city in lp.ControlInfoForParts[0].Keys)
                    {
                        from.BuildOptimalPath(city, out BasicCity real);
                        if (real == city && from.currWarriors * from.sendPersent * 3 * from.atkPersent > city.GetDefWarriors())
                        {
                            to        = city;
                            findFirst = true;
                            break;
                        }
                    }
                    if (findFirst)
                    {
                        break;
                    }
                }

                if (to != null)
                {
                    command.to           = to;
                    command.from         = from;
                    command.warriorsType = Command.WarriorsType.Count;
                    command.warriors     = (ushort)(to.currWarriors);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 13
0
    protected void btnDel_Click(object sender, EventArgs e)
    {
        string value = this.hfldCityID.Value;

        if (!string.IsNullOrEmpty(value))
        {
            BasicCityService basicCityService = new BasicCityService();
            BasicCity        cityByCityID     = basicCityService.GetCityByCityID(value);
            try
            {
                basicCityService.Delete(cityByCityID);
                this.BindGv();
                base.RegisterScript("top.ui.show('系统提示:\\n\\n删除成功!');");
            }
            catch
            {
                base.RegisterScript("top.ui.alert('系统提示:\\n\\n删除失败!');");
            }
        }
    }
Exemplo n.º 14
0
        void SelectCity(BasicCity city, bool IsRemoveIfSelected)
        {
            if (!selectedCity.Contains(city))
            {
                if (city.PlayerId == PlayerId)
                {
                    var inInfo  = city.InputInfo as CityInputInfoWPF;
                    var outInfo = city.OutputInfo as OutputInfoWPF;

                    selectedCity.Add(city);
                    inInfo.strokeColorBeforeSelection     = outInfo.cityShape.Stroke;
                    inInfo.strokeThicknessBeforeSelection = outInfo.cityShape.StrokeThickness;
                    outInfo.cityShape.Stroke          = this.citySelectedStrokeColor;
                    outInfo.cityShape.StrokeThickness = this.citySelectedStrokeThickness;
                }
            }
            else if (IsRemoveIfSelected)
            {
                UnselectCity(city);
            }
        }
        public ActionResult Index(BasicCity BasicCity, EFPagingInfo <BasicCity> p, int IsFirst = 0)
        {
            if (IsFirst == 0)
            {
                PageOfItems <BasicCity> BasicCityList1 = new PageOfItems <BasicCity>(new List <BasicCity>(), 0, 10, 0, new Hashtable());
                ViewBag.BasicCityList     = BasicCityList1;
                ViewBag.BasicCity         = BasicCity;
                ViewBag.BasicProvinceList = Entity.BasicProvince.Where(n => n.State == 1).ToList();

                ViewBag.Add    = this.checkPower("Add");
                ViewBag.Edit   = this.checkPower("Edit");
                ViewBag.Delete = this.checkPower("Delete");
                ViewBag.Save   = this.checkPower("Save");
                return(View());
            }
            if (!BasicCity.PId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.PId == BasicCity.PId);
            }
            if (!BasicCity.Name.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Name.Contains(BasicCity.Name));
            }
            if (!BasicCity.State.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.State == (BasicCity.State == 99?0:BasicCity.State));
            }
            p.OrderByList.Add("PId", "DESC");
            p.OrderByList.Add("Id", "ASC");
            IPageOfItems <BasicCity> BasicCityList = Entity.Selects <BasicCity>(p);

            ViewBag.BasicCityList     = BasicCityList;
            ViewBag.BasicCity         = BasicCity;
            ViewBag.BasicProvinceList = Entity.BasicProvince.Where(n => n.State == 1).ToList();
            ViewBag.Add    = this.checkPower("Add");
            ViewBag.Edit   = this.checkPower("Edit");
            ViewBag.Delete = this.checkPower("Delete");
            ViewBag.Save   = this.checkPower("Save");
            return(View());
        }
Exemplo n.º 16
0
        public override bool TickReact()
        {
            command = new Command {
                fromType     = Command.FromType.NearestCity,
                toType       = Command.ToType.Direct,
                warriorsType = Command.WarriorsType.Count
            };

            BasicCity weakesCity = null;

            foreach (var control in lp.ControlInfoForParts)
            {
                foreach (var city in control)
                {
                    if (city.Key.PlayerId == this.PlayerId)
                    {
                        break;
                    }

                    if (city.Value.AllyUnitsMovingToCity.Count == 0 && city.Value.EnemyUnitsMovingToCity.Count == 0 &&
                        (weakesCity == null || weakesCity.GetDefWarriors() > city.Key.GetDefWarriors())
                        )
                    {
                        weakesCity = city.Key;
                    }
                }
            }

            if (weakesCity != null)
            {
                command.to       = weakesCity;
                command.warriors = (ushort)(weakesCity.GetDefWarriors() + 1);
                return(true);
            }

            return(false);
        }
Exemplo n.º 17
0
        //---------------------------------------------- Methods - behavior ----------------------------------------------

        void CalculateWhoNeedToBeRushed()
        {
            List <List <BasicCity> > potentialRushes = new List <List <BasicCity> >();

            for (byte i = 1; i <= rushChances.Count; ++i)
            {
                potentialRushes.Add(new List <BasicCity>());

                foreach (var city in canAttackDirectly)
                {
                    uint potentialArmy = CalcPotentialArmy(i, city.defPersent);
                    if (!rushingCities.Contains(city) &&
                        GetEnemyArmy(city) < potentialArmy
                        )
                    {
                        bool isInPrev = false;
                        foreach (var rush in potentialRushes)
                        {
                            if (rush.Contains(city))
                            {
                                isInPrev = true;
                                break;
                            }
                        }
                        if (!isInPrev)
                        {
                            potentialRushes[i - 1].Add(city);
                        }
                    }
                }
            }


            List <KeyValuePair <byte, byte> > rushChance = new List <KeyValuePair <byte, byte> >(potentialRushes.Count);

            int tmp = 0;

            while (tmp != potentialRushes.Count)
            {
                if (potentialRushes[tmp].Count != 0)
                {
                    rushChance.Add(new KeyValuePair <byte, byte>(rushChances[tmp].Key, rushChances[tmp].Value));
                }
                ++tmp;
            }

            if (rushChance.Count != 0)
            {
                int potentialRushPos = 0;

                byte sumPersent = 0;
                foreach (var i in rushChance)
                {
                    sumPersent += i.Value;
                }
                if (sumPersent != 100)
                {
                    for (int i = 0; i < rushChance.Count; ++i)
                    {
                        rushChance[i] = new KeyValuePair <byte, byte>(rushChance[i].Key,
                                                                      (byte)Math.Round((double)(rushChance[i].Value) / sumPersent * 100));
                    }
                }

                byte randPersent = Rand.NextPersent();
                for (int i = 0; i < rushChance.Count; ++i)
                {
                    if (randPersent <= rushChance[i].Value)
                    {
                        potentialRushPos = rushChance[i].Key - 1;
                        break;
                    }
                    else
                    {
                        randPersent -= rushChance[i].Value;
                    }
                }

                var potentialRush = potentialRushes[potentialRushPos];
                rushCity        = potentialRush[Rand.Next(0, potentialRush.Count)];
                isRushing       = true;
                rushWaveRemains = (byte)(potentialRushPos + 1);
            }
        }
Exemplo n.º 18
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(this.action))
     {
         BasicCity        basicCity        = new BasicCity();
         BasicCityService basicCityService = new BasicCityService();
         DataTable        dataTable        = new DataTable();
         if (this.action == "Add")
         {
             string cmdText = "SELECT * FROM Basic_City WHERE Name='" + this.txtCityName.Text + "'";
             dataTable = basicCityService.ExecuteQuery(cmdText, new SqlParameter[0]);
             if (dataTable.Rows.Count > 0)
             {
                 base.RegisterScript("top.ui.alert('系统提示:\\n\\n 该城市名称已经存在!');");
                 return;
             }
             cmdText   = "SELECT * FROM Basic_City WHERE Code='" + this.txtCityCode.Text + "'";
             dataTable = basicCityService.ExecuteQuery(cmdText, new SqlParameter[0]);
             if (dataTable.Rows.Count > 0)
             {
                 base.RegisterScript("top.ui.alert('系统提示:\\n\\n 该城市编码已经存在!');");
                 return;
             }
             cmdText   = "SELECT MAX(OrderNo) FROM Basic_City WHERE ProvinceId='" + this.hlfdProvinceID.Value + "'";
             dataTable = basicCityService.ExecuteQuery(cmdText, new SqlParameter[0]);
             string value = dataTable.Rows[0][0].ToString();
             int    num   = 0;
             if (!string.IsNullOrEmpty(value))
             {
                 num = Convert.ToInt32(value);
             }
             basicCity.Id         = Guid.NewGuid();
             basicCity.Name       = this.txtCityName.Text.Trim();
             basicCity.Code       = this.txtCityCode.Text.Trim();
             basicCity.ProvinceId = new Guid(this.hlfdProvinceID.Value);
             basicCity.OrderNo    = new int?(num + 1);
             basicCityService.Add(basicCity);
             base.RegisterScript("top.ui.tabSuccess({ parentName: '_cityEdit' });");
             return;
         }
         else
         {
             if (this.action == "Edit")
             {
                 string cmdText = string.Concat(new string[]
                 {
                     "SELECT * FROM Basic_City WHERE Name='",
                     this.txtCityName.Text,
                     "' AND Id NOT IN('",
                     this.hlfdCityID.Value,
                     "')"
                 });
                 dataTable = basicCityService.ExecuteQuery(cmdText, new SqlParameter[0]);
                 if (dataTable.Rows.Count > 0)
                 {
                     base.RegisterScript("top.ui.alert('系统提示:\\n\\n 该城市名称已经存在!');");
                     return;
                 }
                 cmdText = string.Concat(new string[]
                 {
                     "SELECT * FROM Basic_City WHERE Code='",
                     this.txtCityCode.Text,
                     "' AND Id NOT IN('",
                     this.hlfdCityID.Value,
                     "')"
                 });
                 dataTable = basicCityService.ExecuteQuery(cmdText, new SqlParameter[0]);
                 if (dataTable.Rows.Count > 0)
                 {
                     base.RegisterScript("top.ui.alert('系统提示:\\n\\n 该城市编码已经存在!');");
                     return;
                 }
                 basicCity      = basicCityService.GetCityByCityID(this.hlfdCityID.Value);
                 basicCity.Name = this.txtCityName.Text.Trim();
                 basicCity.Code = this.txtCityCode.Text.Trim();
                 basicCityService.Update(basicCity);
                 base.RegisterScript("top.ui.tabSuccess({ parentName: '_cityEdit' });");
             }
         }
     }
 }
 public void Add(BasicCity BasicCity)
 {
     Entity.BasicCity.AddObject(BasicCity);
     Entity.SaveChanges();
     BaseRedirect();
 }
Exemplo n.º 20
0
 private City(BasicCity basic)
     : base(basic)
 {
 }
Exemplo n.º 21
0
 public static City FromBasic(BasicCity basic)
 {
     return(new City(basic));
 }
Exemplo n.º 22
0
        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="ApplyJoin"></param>
        /// <param name="p"></param>
        /// <param name="STime"></param>
        /// <param name="ETime"></param>
        /// <param name="IsShowSupAgent"></param>
        /// <returns></returns>
        public FileResult ExcelExport(ApplyJoin ApplyJoin, EFPagingInfo <ApplyJoin> p, DateTime?STime, DateTime?ETime, bool?IsShowSupAgent)
        {
            p.PageSize = 9999999;
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p.SqlWhere.Add(f => f.AddTime > STime && f.AddTime < ETime);
            if (!ApplyJoin.ServiceType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.ServiceType == ApplyJoin.ServiceType);
            }
            if (!ApplyJoin.ApplyType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.ApplyType == ApplyJoin.ApplyType);
            }
            if (!ApplyJoin.Linker.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Linker.Contains(ApplyJoin.Linker));
            }
            if (!ApplyJoin.Mobile.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Mobile.Contains(ApplyJoin.Mobile));
            }
            if (!ApplyJoin.ComName.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.ComName.Contains(ApplyJoin.ComName));
            }
            if (!ApplyJoin.Province.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Province == ApplyJoin.Province);
            }
            if (!ApplyJoin.City.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.City == ApplyJoin.City);
            }
            if (!ApplyJoin.TiePaiAgentId.IsNullOrEmpty())
            {
                if (ApplyJoin.TiePaiAgentId == 1)
                {
                    p.SqlWhere.Add(f => f.TiePaiAgentId != null);
                }
                else
                {
                    p.SqlWhere.Add(f => f.TiePaiAgentId == null);
                }
            }
            if (!ApplyJoin.State.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.State == ApplyJoin.State);
            }
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <ApplyJoin> ApplyJoinList = Entity.Selects <ApplyJoin>(p);

            DataTable table = new DataTable();
            DataRow   row   = null;

            // 创建 datatable
            table.Columns.Add(new DataColumn("联系人", typeof(string)));
            table.Columns.Add(new DataColumn("手机号", typeof(string)));
            table.Columns.Add(new DataColumn("公司名称", typeof(string)));
            table.Columns.Add(new DataColumn("所在省", typeof(string)));
            table.Columns.Add(new DataColumn("所在市", typeof(string)));
            table.Columns.Add(new DataColumn("申请时间", typeof(string)));
            table.Columns.Add(new DataColumn("状态", typeof(string)));
            table.Columns.Add(new DataColumn("上级代理名", typeof(string)));
            table.Columns.Add(new DataColumn("是否贴牌", typeof(string)));

            // 填充数据
            foreach (var item in ApplyJoinList)
            {
                BasicProvince BasicProvince = Entity.BasicProvince.FirstOrNew(n => n.Id == item.Province);
                BasicCity     BasicCity     = Entity.BasicCity.FirstOrNew(n => n.Id == item.City);
                string        stateName     = "";
                row    = table.NewRow();
                row[0] = item.Linker;
                row[1] = item.Mobile;
                row[2] = item.ComName;
                row[3] = BasicProvince.Name;
                row[4] = BasicCity.Name;
                row[5] = item.AddTime.ToString("yyyy-MM-dd");
                switch (item.State)
                {
                case 1:
                    stateName = "未跟进";
                    break;

                case 2:
                    stateName = "跟进中";
                    break;

                case 3:
                    stateName = "无意向";
                    break;

                case 4:
                    stateName = "已完成";
                    break;

                default:
                    break;
                }

                row[6] = stateName;
                row[7] = item.AgentName;
                row[8] = item.TiePaiAgentId != null ? "是" : "否";

                table.Rows.Add(row);
            }
            string Time = STime.IsNullOrEmpty() ? "" : STime.Value.ToString("yyyy-MM-dd") + "至" + (ETime.IsNullOrEmpty() ? "" : ETime.Value.ToString("yyyy-MM-dd"));

            return(this.ExportExcelBase(table, "合作申请    " + Time));
        }
Exemplo n.º 23
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        int col_firstNames   = 0;
        int col_lastName     = 1;
        int col_dateOfBirth  = 2;
        int col_email        = 3;
        int col_municipality = 4;
        int col_address      = 5;
        int col_postalCode   = 6;
        int col_city         = 7;
        int col_phone        = 8;
        int col_dateJoined   = 9;
        int col_active       = 10;

        int currentRow      = -1;
        int currentImported = 0;

        DateTime T0 = DateTime.Now;

        Dictionary <string, BasicCity> postcodes   = PirateDb.GetDatabase().GetCitiesPerPostalCode(loadCntry.Identity);
        Dictionary <string, BasicCity> cityPerName = new Dictionary <string, BasicCity>();
        Dictionary <int, BasicCity>    cityPerId   = new Dictionary <int, BasicCity>();

        foreach (BasicCity bc in postcodes.Values)
        {
            cityPerName[bc.Name.ToLower().Replace(" ", "")] = bc;
            cityPerId[bc.Identity] = bc;
        }

        People allpeople = People.GetAll();
        Dictionary <string, Person> peoplePerKey = new Dictionary <string, Person>();

        foreach (Person p in allpeople)
        {
            peoplePerKey[p.Email.ToLower().Replace(" ", "") + p.Birthdate.ToString("yyMMdd")] = p;
        }

        Memberships memberships = Memberships.ForOrganization(currentOrg);
        Dictionary <int, Membership> membershipsDict = new Dictionary <int, Membership>();

        foreach (Membership ms in memberships)
        {
            membershipsDict[ms.PersonId] = ms;
        }

        string[] rows = TextBoxImport.Text.Replace("\r\n", "\n").Split('\n');
        using (TransactionScope txScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 30, 0)))
        {
            foreach (string row in rows)
            {
                ++currentRow;
                string[] cols = (row + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t").Split('\t');

                Geography mainGeo = null;
                string    name    = cols[col_firstNames] + " " + cols[col_lastName];
                if (!Formatting.ValidateEmailFormat(cols[col_email]))
                {
                    AddError(currentRow, "Bad email format:" + cols[col_email]);
                    continue;
                }
                BasicCity foundCity = null;
                Dictionary <int, Geography> geos = new Dictionary <int, Geography>();
                string pcode = cols[col_postalCode].Trim();
                if (pcode != "")
                {
                    while (pcode.Length < loadCntry.PostalCodeLength)
                    {
                        pcode = "0" + pcode;
                    }

                    if (!postcodes.ContainsKey(pcode))
                    {
                        AddError(currentRow, "Invalid postal code:" + pcode);
                    }
                    else
                    {
                        foundCity = postcodes[pcode];
                        mainGeo   = Geography.FromIdentity(foundCity.GeographyId);
                        geos[foundCity.GeographyId] = mainGeo;
                    }
                }
                else if (cols[col_city].Trim() != "")
                {
                    if (!cityPerName.ContainsKey(cols[col_city].ToLower().Replace(" ", "")))
                    {
                        AddError(currentRow, "Invalid postal code:" + pcode);
                    }
                    else
                    {
                        foundCity = cityPerName[cols[col_city].ToLower().Replace(" ", "")];
                        mainGeo   = Geography.FromIdentity(foundCity.GeographyId);
                        geos[foundCity.GeographyId] = mainGeo;
                    }
                }

                foreach (Geography g in geotree)
                {
                    string[] names = g.Name.ToLower().Replace(" ", "").Split('/');
                    foreach (string partName in names)
                    {
                        if (partName == cols[col_municipality].ToLower().Replace(" ", ""))
                        {
                            mainGeo          = g;
                            geos[g.Identity] = g;
                        }
                    }
                }

                if (geos.Count == 0 || geos.Count > 1)
                {
                    AddError(currentRow, "Warning only: can not find a specific local geography");
                }


                DateTime dob           = NormalizeDate(cols[col_dateOfBirth]);
                DateTime doj           = NormalizeDate(cols[col_dateJoined]);
                string   key           = cols[col_email].ToLower().Replace(" ", "") + dob.ToString("yyMMdd");
                Person   currentPerson = null;

                if (!peoplePerKey.ContainsKey(key))
                {
                    if (mainGeo == null)
                    {
                        mainGeo = loadCntry.Geography;
                    }
                    currentPerson           = Person.Create(name, cols[col_email], "ABCABCABCABC", cols[col_phone], cols[col_address], pcode, cols[col_city], loadCntry.Code, dob, PersonGender.Unknown);
                    currentPerson.Geography = mainGeo;
                    PWLog.Write(PWLogItem.Person, currentPerson.Identity, PWLogAction.PersonCreated, "Created Person from Import", "Import for " + currentOrg.Name);
                }
                else
                {
                    currentPerson = peoplePerKey[key];
                    AddError(currentRow, "Warning only: Person with email already existed ");

                    if (currentPerson.Birthdate < new DateTime(1901, 1, 1))
                    {
                        currentPerson.Birthdate = dob;
                    }
                    if (currentPerson.Phone.Length < cols[col_phone].Length)
                    {
                        currentPerson.Phone = cols[col_phone];
                    }
                    if (currentPerson.Street.Length < cols[col_address].Length)
                    {
                        currentPerson.Street = cols[col_address];
                    }
                    if (currentPerson.PostalCode.CompareTo(pcode) < 0)
                    {
                        currentPerson.PostalCode = pcode;
                    }
                    if (currentPerson.CityName.Length < cols[col_city].Length)
                    {
                        currentPerson.CityName = cols[col_city];
                    }

                    if (mainGeo != null && mainGeo.Identity != currentPerson.GeographyId)
                    {
                        currentPerson.Geography = mainGeo;
                    }
                }

                // add membership
                if (!membershipsDict.ContainsKey(currentPerson.Identity))
                {
                    Membership newMs = Membership.Import(currentPerson, currentOrg, doj, nowValue.AddYears(100));
                    newMs.SetPaymentStatus(MembershipPaymentStatus.PaymentRecieved, nowValue);
                }

                // add activist
                if (cols[col_active] == "1")
                {
                    currentPerson.CreateActivist(true, true);
                    PWLog.Write(currentPerson, PWLogItem.Person, currentPerson.Identity, PWLogAction.ActivistJoin, "New activist joined.", "Import for " + currentOrg.Name);
                }

                ++currentImported;
            }
            txScope.Complete();
        }

        StringBuilder sb = new StringBuilder();

        sb.AppendLine("ProcessTime= " + Math.Round(DateTime.Now.Subtract(T0).TotalSeconds));
        sb.AppendLine("Rows read= " + currentRow);
        sb.AppendLine("Rows imported= " + currentImported);
        sb.AppendLine("Errors and warnings");
        foreach (int row in errRows.Keys)
        {
            sb.AppendLine("Line: " + row);
            sb.AppendLine(rows[row]);

            foreach (string err in errRows[row])
            {
                sb.AppendLine("     " + err);
            }
            sb.AppendLine("");
        }
        TextBoxResult.Text = sb.ToString();
    }
Exemplo n.º 24
0
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[UserCardInfo]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            UserCard UserCard = new UserCard();

            UserCard = JsonToObject.ConvertJsonToModel(UserCard, json);
            //获取用户信息
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == UserCard.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }
            if (baseUsers.MiBao != 1)//未设置支付密码
            {
                DataObj.OutError("2008");
                return;
            }
            UserCard = Entity.UserCard.FirstOrDefault(n => n.Id == UserCard.Id && n.UId == baseUsers.Id && n.State == 1);
            if (UserCard == null)//不存在
            {
                DataObj.OutError("1001");
                return;
            }

            if (!UserCard.Province.IsNullOrEmpty())
            {
                BasicProvince BasicProvince = Entity.BasicProvince.FirstOrDefault(n => n.Id == UserCard.Province);
                if (BasicProvince != null)
                {
                    UserCard.ProvinceName = BasicProvince.Name;
                }
            }
            if (!UserCard.City.IsNullOrEmpty())
            {
                BasicCity BasicCity = Entity.BasicCity.FirstOrDefault(n => n.Id == UserCard.City);
                if (BasicCity != null)
                {
                    UserCard.CityName = BasicCity.Name;
                }
            }

            UserCard.Cols = "Id,Bank,Card,Name,Type,Deposit,Province,City,District,Bin,BId,ProvinceName,CityName,Mobile";
            DataObj.Data  = UserCard.OutJson();
            DataObj.Code  = "0000";
            DataObj.OutString();
        }
Exemplo n.º 25
0
 public BasicCityEvent(BasicCity City)
 {
     city = City;
 }