Пример #1
0
        public ActionResult Add()
        {
            CountyView countyView = new CountyView();

            countyView.BindDDLs(countyView, db);

            return(View(countyView));
        }
Пример #2
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (Request.QueryString["action"] != null)
     {
         string shortSpelling = string.Empty;
         string spelling      = string.Empty;
         int    hotlevel      = 0;
         if (!string.IsNullOrEmpty(this.txtShortSpelling.Text.Trim()))
         {
             shortSpelling = this.txtShortSpelling.Text.Trim();
         }
         if (!string.IsNullOrEmpty(this.txtSpelling.Text.Trim()))
         {
             spelling = this.txtSpelling.Text.Trim();
         }
         if (!string.IsNullOrEmpty(this.txtHotLevel.Text.Trim()))
         {
             hotlevel = int.Parse(this.txtHotLevel.Text.Trim());
         }
         CountyView countyView = new CountyView()
         {
             Code          = this.txtCountyCode.Text.Trim(),
             Name          = this.txtChineseName.Text.Trim(),
             ShortSpelling = shortSpelling,
             Spelling      = spelling,
             HotLevel      = hotlevel,
             CityCode      = this.ddlCityName.SelectedValue,
         };
         if (Request.QueryString["action"].ToString() == "add")
         {
             try
             {
                 FoundationService.AddCounty(countyView, CurrentUser.UserName);
                 RegisterScript("alert('添加成功!'); window.location.href='County.aspx'");
             } catch (Exception ex) {
                 ShowExceptionMessage(ex, "添加");
             }
         }
         else
         {
             try
             {
                 FoundationService.UpdateCounty(countyView, CurrentUser.UserName);
                 RegisterScript("alert('修改成功!'); window.location.href='County.aspx?Search=Back'");
             } catch (Exception ex) {
                 ShowExceptionMessage(ex, "修改");
             }
         }
     }
 }
Пример #3
0
 internal static County GetCounty(CountyView countyView)
 {
     if (null == countyView)
     {
         throw new ArgumentNullException("countyView");
     }
     countyView.Validate();
     return(new County(countyView.Code.Trim())
     {
         CityCode = StringUtility.Trim(countyView.CityCode),
         Name = StringUtility.Trim(countyView.Name),
         Spelling = StringUtility.Trim(countyView.Spelling),
         ShortSpelling = StringUtility.Trim(countyView.ShortSpelling),
         HotLevel = countyView.HotLevel
     });
 }
Пример #4
0
        public ActionResult Index()
        {
            ICountiesRepository  countiesRepository  = new CountiesRepository(db);
            ICountriesRepository countriesRepository = new CountriesRepository(db);

            int    page       = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1;
            int    pageSize   = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]);
            string sortOrder  = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC";
            string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "CountyPK";
            string ordering   = sortColumn + " " + sortOrder;

            ordering = ordering.Trim();

            IQueryable <CountyView> counties = CountyView.GetCountyView(countiesRepository.GetValid(), countriesRepository.GetValid())
                                               .OrderBy(ordering);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                counties = counties.Where(c => c.Name.Contains(searchString));
            }

            counties = counties.Page(page, pageSize);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                ViewData["numberOfRecords"] = countiesRepository.GetValid().Where(c => c.Name.Contains(searchString)).Count();
            }
            else
            {
                ViewData["numberOfRecords"] = countiesRepository.GetValid().Count();
            }

            int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize;

            if (page > numberOfPages)
            {
                string url = LinkHelper.getQueryStringArray(new string[] { "page" });
                return(Redirect("County?" + url + "page=" + numberOfPages));
            }
            else
            {
                return(View("Index", counties.ToList()));
            }
        }
Пример #5
0
        public static void AddCounty(CountyView countyView, string account)
        {
            var county = County.GetCounty(countyView);

            if (QueryCounty(county.Code) != null)
            {
                throw new ChinaPay.Core.Exception.KeyRepeatedException("代码[" + county.Code + "]已存在");
            }
            var sameNameCounty = QueryCountyByName(county.Name);

            if (sameNameCounty != null && sameNameCounty.CityCode == county.CityCode)
            {
                throw new ChinaPay.Core.Exception.KeyRepeatedException("名称[" + county.Name + "]已存在");
            }
            CountyCollection.Instance.Add(county.Code, county);
            saveAddLog("县", county.ToString(), county.Code, account);
        }
Пример #6
0
        public ActionResult Edit(int?countyPK)
        {
            if (countyPK != null)
            {
                ICountiesRepository countiesRepository = new CountiesRepository(db);
                County     county     = countiesRepository.GetCountyByPK((int)countyPK);
                CountyView countyView = new CountyView();

                countyView.ConvertFrom(county, countyView);
                countyView.BindDDLs(countyView, db);

                return(View(countyView));
            }
            else
            {
                return(RedirectToAction("Index", "County"));
            }
        }
Пример #7
0
        public static void UpdateCounty(CountyView countyView, string account)
        {
            var county         = County.GetCounty(countyView);
            var originalCounty = QueryCounty(county.Code);

            if (null == originalCounty)
            {
                throw new ChinaPay.Core.CustomException("原县不存在");
            }
            var sameNameCounty = QueryCountyByName(county.Name);

            if (sameNameCounty != null && sameNameCounty.Code != county.Code && sameNameCounty.CityCode == county.CityCode)
            {
                throw new ChinaPay.Core.Exception.KeyRepeatedException("名称[" + county.Name + "]已存在");
            }
            var originalContent = originalCounty.ToString();

            CountyCollection.Instance.Update(county.Code, county);
            saveUpdateLog("县", originalContent, county.ToString(), county.Code, account);
        }
Пример #8
0
        public ActionResult Edit(CountyView countyView, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                ICountiesRepository countiesRepository = new CountiesRepository(db);
                County county = countiesRepository.GetCountyByPK((int)countyView.CountyPK);

                countyView.ConvertTo(countyView, county);

                countiesRepository.SaveChanges();

                TempData["message"] = LayoutHelper.GetMessage("UPDATE", county.CountyPK);

                return(RedirectToAction("Index", "County"));
            }
            else
            {
                countyView.BindDDLs(countyView, db);

                return(View(countyView));
            }
        }