123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- 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<InstallMaterialTypeEntity> typeList = new List<InstallMaterialTypeEntity>();
- List<InstallMaterialGoodsEntity> goodsList = new List<InstallMaterialGoodsEntity>();
- List<InstallMaterialUnitEntity> unitList = new List<InstallMaterialUnitEntity>();
- 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("");
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- 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<InstallMaterialGoodsEntity> goodsList = new List<InstallMaterialGoodsEntity>();
- 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
- }
- }
|