using LeaRun.Application.Busines.InstallManage; using LeaRun.Application.Entity.InstallManage; using LeaRun.Util; using LeaRun.Util.WebControl; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Web; using System.Web.Mvc; namespace LeaRun.Application.Web.Areas.InstallManage.Controllers { public class DudgetController : MvcControllerBase { // // GET: /InstallManage/Dudget/ private InstallDudgetBLL installDudgetbll = new InstallDudgetBLL(); private InstallApplyBLL InstallApplybll = new InstallApplyBLL(); public ActionResult Index() { return View(); } public ActionResult Form() { return View(); } DataTable dtGoods; DataSet ds; DataTable dtType; DataTable dtUnit; public ActionResult Forma() { try { ds = installDudgetbll.GetBudgetDetail(); dtType = ds.Tables[0]; dtGoods = ds.Tables[1]; dtUnit = ds.Tables[2]; List typeList = new List(); List goodsList = new List(); List unitList = new List(); InstallMaterialTypeEntity typeEntity = new InstallMaterialTypeEntity(); InstallMaterialGoodsEntity goodsEntity = new InstallMaterialGoodsEntity(); InstallMaterialUnitEntity unitEntity = new InstallMaterialUnitEntity(); PropertyInfo[] propertyType = typeEntity.GetType().GetProperties(); PropertyInfo[] propertyGoods = goodsEntity.GetType().GetProperties(); PropertyInfo[] propertyUnit = unitEntity.GetType().GetProperties(); string tempType = ""; foreach (DataRow row in dtType.Rows) { InstallMaterialTypeEntity typeEntityTemp = new InstallMaterialTypeEntity(); foreach (PropertyInfo pi in propertyType) { tempType = pi.Name; //检查DataTable是否包含此列 if (dtType.Columns.Contains(tempType)) { //判断此属性是否有set if (!pi.CanWrite) continue; object value = row[tempType]; if (value != DBNull.Value) pi.SetValue(typeEntityTemp, value, null); } } typeList.Add(typeEntityTemp); } string tempGoods = ""; foreach (DataRow row in dtGoods.Rows) { InstallMaterialGoodsEntity goodsEntityTemp = new InstallMaterialGoodsEntity(); foreach (PropertyInfo pi in propertyGoods) { tempGoods = pi.Name; if (dtGoods.Columns.Contains(tempGoods)) { if (!pi.CanWrite) continue; object value = row[tempGoods]; if (value != DBNull.Value) pi.SetValue(goodsEntityTemp, value, null); } } goodsList.Add(goodsEntityTemp); } string tempUnit = ""; foreach (DataRow row in dtUnit.Rows) { InstallMaterialUnitEntity unitEntityTemp = new InstallMaterialUnitEntity(); foreach (PropertyInfo pi in propertyUnit) { tempUnit = pi.Name; //检查DataTable是否包含此列 if (dtUnit.Columns.Contains(tempUnit)) { //判断此属性是否有set if (!pi.CanWrite) continue; object value = row[tempUnit]; if (value != DBNull.Value) pi.SetValue(unitEntityTemp, value, null); } } unitList.Add(unitEntityTemp); } ViewBag.databaseType = typeList; ViewBag.databaseGoods = goodsList; ViewBag.databaseUnit = unitList; return View(); } catch (Exception ex) { return Content(""); } } /// /// /// /// public ActionResult GetBudgetDetail(string materialID) { //try //{ // dtGoods = installDudgetbll.GetBudgetDetailGoods(materialID); // string JsonString = string.Empty; // JsonString = JsonConvert.SerializeObject(dtGoods); // var JsonData = new // { // rows = JsonConvert.DeserializeObject(JsonString), // }; // return Content(JsonData.ToJson()); //} try { dtGoods = installDudgetbll.GetBudgetDetailGoods(materialID); List goodsList = new List(); InstallMaterialGoodsEntity goodsEntity = new InstallMaterialGoodsEntity(); PropertyInfo[] propertyGoods = goodsEntity.GetType().GetProperties(); string tempGoods = ""; foreach (DataRow row in dtGoods.Rows) { InstallMaterialGoodsEntity goodsEntityTemp = new InstallMaterialGoodsEntity(); foreach (PropertyInfo pi in propertyGoods) { tempGoods = pi.Name; if (dtGoods.Columns.Contains(tempGoods)) { if (!pi.CanWrite) continue; object value = row[tempGoods]; if (value != DBNull.Value) pi.SetValue(goodsEntityTemp, value, null); } } goodsList.Add(goodsEntityTemp); } ViewBag.databaseGoods110 = goodsList; return Content(goodsList.ToJson()); //return View(); } catch (Exception ex) { return Content(""); } } public ActionResult GetListJson(string startTime, string endTime, String type, Pagination pagination) { InstallApplyEntity entity = new InstallApplyEntity(); if (type == null) { entity.budgetType = 0; entity.SurveyType = 1; } else { entity.budgetType = int.Parse(type); entity.SurveyType = 1; } if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime)) { var data = InstallApplybll.getInstallApplyList(startTime, endTime, pagination, entity); var watch = CommonHelper.TimerStart(); var JsonData = new { rows = JsonConvert.DeserializeObject(data), total = pagination.total, page = pagination.page, records = pagination.records, costtime = CommonHelper.TimerEnd(watch) }; return Content(JsonData.ToJson()); } else { entity.budgetType = 0; entity.SurveyType = 1; var data = InstallApplybll.getInstallApplyList(startTime, endTime, pagination, entity); var watch = CommonHelper.TimerStart(); var JsonData = new { rows = JsonConvert.DeserializeObject(data), total = pagination.total, page = pagination.page, records = pagination.records, costtime = CommonHelper.TimerEnd(watch) }; return Content(JsonData.ToJson()); } return Content(""); } public ActionResult GetDudgetListByApply(String applyId, Pagination pagination) { String json = ""; if (!String.IsNullOrEmpty(applyId)) { try { var data = installDudgetbll.getInstallDudgetList(applyId, pagination); var watch = CommonHelper.TimerStart(); var JsonData = new { rows = JsonConvert.DeserializeObject(data), total = pagination.total, page = pagination.page, records = pagination.records, costtime = CommonHelper.TimerEnd(watch) }; return Content(JsonData.ToJson()); } catch (Exception ex) { return Content(""); } } return Content(""); } #region 保存数据 [HttpPost] [AjaxOnly] public ActionResult SaveForm(String applyId) { installDudgetbll.SaveForm(applyId); return Success("操作成功。"); } #endregion #region 保存数据 [HttpPost] [AjaxOnly] public ActionResult SaveForma(String applyId, string data) { //var postData = $("#Type") $("#name") $("#myGoodsSpec" + $("#unit")t + $("#number") $("#price"). + $("#LabourCost").val() + spit + $("#Description").val();; InstallDudgetEntity entity = new InstallDudgetEntity(); string[] listdata = data.Split('*'); entity.Apply_ID = Convert.ToInt32(applyId); entity.Version = listdata[2]; entity.Type = listdata[0]; entity.unit = listdata[3]; entity.number = Convert.ToInt32(listdata[4]); entity.price = Convert.ToInt32(listdata[5]); entity.LabourCost = Convert.ToDecimal(listdata[6]); entity.name = listdata[1]; installDudgetbll.SaveForma(applyId, entity); return Success("操作成功。"); } //public ActionResult SaveForma(String applyId, InstallDudgetEntity entity) //{ // installDudgetbll.SaveForma(applyId, entity); // return Success("操作成功。"); //} #endregion } }