tijian_tieying/web/dccdc/Controllers/DiQuController.cs
2025-02-20 12:14:39 +08:00

298 lines
8.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using dccdc.BLL;
using Newtonsoft.Json;
using dccdc.Models;
namespace dccdc.Controllers
{
public class DiQuController : Controller
{
// GET: DiQu
public ActionResult Index()
{
return View();
}
public ActionResult DiQuList()
{
return View();
}
[HttpGet]
public String getDqModelList()
{
DiQu dqbll = new DiQu();
string list = JsonConvert.SerializeObject(dqbll.getDqModelList());
return list;
}
public String getDqModel(FormCollection data)
{
DiQu dqbll = new DiQu();
DQmodel model = new DQmodel();
model.dqid = data["dqid"];
model.pid = data["pid"];
model.text = data["text"];
model.type = data["type"];
string list = JsonConvert.SerializeObject(dqbll.getDqModel(model));
return list;
}
[HttpPost]
public String saveDqModel(FormCollection data)
{
DiQu dqbll = new DiQu();
DQmodel model = new DQmodel();
model.dqid = data["dqid"];
model.pid = data["pid"];
model.text = data["text"];
model.type = data["type"];
string list = JsonConvert.SerializeObject(dqbll.saveDqModel(model));
return list;
}
#region
public ActionResult SzProvince()
{
return View();
}
public string GetSzProvince(int page, int pagesize)
{
dccdc.BLL.DiQu c = new dccdc.BLL.DiQu();
int count = c.getShengCount();
var list = c.getShengList(page, pagesize);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { Total = count, Rows = list });
}
[HttpGet]
public ActionResult EditSzProvince(string id)
{
var bll = new dccdc.BLL.DiQu();
if (id != "")
{
var model = bll.getProvince(id);
var viewModel = new Sz_province
{
provinceCode = model.provinceCode,
provinceName = model.provinceName
};
return View(viewModel);
}
else
{
return View();
}
}
[HttpPost]
public ActionResult EditSzProvince(Sz_province model)
{
ModelState.Remove("Id");
if (!ModelState.IsValid)
{
var errors = ModelState.Values.SelectMany(v => v.Errors);
return View(model);
}
dccdc.BLL.DiQu c = new dccdc.BLL.DiQu();
Sz_province viewModel = new Sz_province
{
provinceCode = model.provinceCode,
provinceName = model.provinceName
};
//修改
object obj = c.saveProvince(viewModel);
return Json(obj);
}
#endregion
#region
public ActionResult DQSzCity()
{
return View();
}
public string GetSzCity(int page, int pagesize)
{
dccdc.BLL.DiQu c = new dccdc.BLL.DiQu();
int count = c.getShiCount();
var list = c.getSzcityList(page, pagesize);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { Total = count, Rows = list });
}
[HttpGet]
public ActionResult EditSzCity(string id)
{
var bll = new dccdc.BLL.DiQu();
if (id != "")
{
var model = bll.getSzcityBycityCode(id);
var viewModel = new Sz_city
{
cityCode = model.cityCode,
cityName = model.cityName,
provinceCode = model.provinceCode
};
return View(viewModel);
}
else
{
return View();
}
}
[HttpPost]
public ActionResult EditSzCity(Sz_city model)
{
ModelState.Remove("Id");
if (!ModelState.IsValid)
{
var errors = ModelState.Values.SelectMany(v => v.Errors);
return View(model);
}
dccdc.BLL.DiQu c = new dccdc.BLL.DiQu();
Sz_city dtomodel = new Sz_city
{
cityCode = model.cityCode,
cityName = model.cityName,
provinceCode = model.provinceCode
};
//修改
object obj = c.saveCity(dtomodel);
return Json(obj);
}
#endregion
#region
public ActionResult DQSzCounty()
{
return View();
}
public string GetSzCounty(int page, int pagesize)
{
dccdc.BLL.DiQu c = new dccdc.BLL.DiQu();
int count = c.getSzcountyCount();
var list = c.getSzcountyList(page, pagesize);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { Total = count, Rows = list });
}
[HttpGet]
public ActionResult EditSzCounty(string id)
{
var bll = new dccdc.BLL.DiQu();
if (id != "")
{
var model = bll.getSzcounty(id);
Sz_county viewModel = new Sz_county
{
cityCode = model.cityCode,
countyName = model.countyName,
countyCode = model.countyCode
};
return View(viewModel);
}
else
{
return View();
}
}
[HttpPost]
public ActionResult EditSzCounty(Sz_county model)
{
ModelState.Remove("Id");
if (!ModelState.IsValid)
{
var errors = ModelState.Values.SelectMany(v => v.Errors);
return View(model);
}
dccdc.BLL.DiQu c = new dccdc.BLL.DiQu();
Sz_county dtomodel = new Sz_county
{
cityCode = model.cityCode,
countyName = model.countyName,
countyCode = model.countyCode
};
//修改
object obj = c.saveCounty(dtomodel);
return Json(obj);
}
#endregion
#region
public ActionResult SzTown()
{
return View();
}
public string GetSzTown(int page, int pagesize)
{
dccdc.BLL.WeiHuBll c = new dccdc.BLL.WeiHuBll();
int count = c.getCount();
var list = c.getListPage(page, pagesize);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { Total = count, Rows = list });
}
[HttpGet]
public ActionResult EditSzTown(string id)
{
var bll = new dccdc.BLL.DiQu();
if (id != "")
{
var model = bll.getTown(Convert.ToInt32(id));
var viewModel = new Sz_town
{
townCode = model.townCode,
townName = model.townName,
countyCode = model.countyCode,
newCode = model.newCode,
newName = model.newName
};
return View(viewModel);
}
else
{
return View();
}
}
[HttpPost]
public ActionResult EditSzTown(Sz_town model)
{
ModelState.Remove("Id");
if (!ModelState.IsValid)
{
var errors = ModelState.Values.SelectMany(v => v.Errors);
return View(model);
}
dccdc.BLL.DiQu c = new dccdc.BLL.DiQu();
Sz_town viewModel = new Sz_town
{
townCode = model.townCode,
townName = model.townName,
countyCode = model.countyCode,
newCode = model.newCode,
newName = model.newName
};
//修改
object obj = c.saveTown(viewModel);
return Json(obj);
}
#endregion
}
}