DudgetController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. using LeaRun.Application.Busines.InstallManage;
  2. using LeaRun.Application.Entity.InstallManage;
  3. using LeaRun.Util;
  4. using LeaRun.Util.WebControl;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Web;
  12. using System.Web.Mvc;
  13. namespace LeaRun.Application.Web.Areas.InstallManage.Controllers
  14. {
  15. public class DudgetController : MvcControllerBase
  16. {
  17. //
  18. // GET: /InstallManage/Dudget/
  19. private InstallDudgetBLL installDudgetbll = new InstallDudgetBLL();
  20. private InstallApplyBLL InstallApplybll = new InstallApplyBLL();
  21. public ActionResult Index()
  22. {
  23. return View();
  24. }
  25. public ActionResult Form()
  26. {
  27. return View();
  28. }
  29. DataTable dtGoods;
  30. DataSet ds;
  31. DataTable dtType;
  32. DataTable dtUnit;
  33. public ActionResult Forma()
  34. {
  35. try
  36. {
  37. ds = installDudgetbll.GetBudgetDetail();
  38. dtType = ds.Tables[0];
  39. dtGoods = ds.Tables[1];
  40. dtUnit = ds.Tables[2];
  41. List<InstallMaterialTypeEntity> typeList = new List<InstallMaterialTypeEntity>();
  42. List<InstallMaterialGoodsEntity> goodsList = new List<InstallMaterialGoodsEntity>();
  43. List<InstallMaterialUnitEntity> unitList = new List<InstallMaterialUnitEntity>();
  44. InstallMaterialTypeEntity typeEntity = new InstallMaterialTypeEntity();
  45. InstallMaterialGoodsEntity goodsEntity = new InstallMaterialGoodsEntity();
  46. InstallMaterialUnitEntity unitEntity = new InstallMaterialUnitEntity();
  47. PropertyInfo[] propertyType = typeEntity.GetType().GetProperties();
  48. PropertyInfo[] propertyGoods = goodsEntity.GetType().GetProperties();
  49. PropertyInfo[] propertyUnit = unitEntity.GetType().GetProperties();
  50. string tempType = "";
  51. foreach (DataRow row in dtType.Rows)
  52. {
  53. InstallMaterialTypeEntity typeEntityTemp = new InstallMaterialTypeEntity();
  54. foreach (PropertyInfo pi in propertyType)
  55. {
  56. tempType = pi.Name;
  57. //检查DataTable是否包含此列
  58. if (dtType.Columns.Contains(tempType))
  59. {
  60. //判断此属性是否有set
  61. if (!pi.CanWrite)
  62. continue;
  63. object value = row[tempType];
  64. if (value != DBNull.Value)
  65. pi.SetValue(typeEntityTemp, value, null);
  66. }
  67. }
  68. typeList.Add(typeEntityTemp);
  69. }
  70. string tempGoods = "";
  71. foreach (DataRow row in dtGoods.Rows)
  72. {
  73. InstallMaterialGoodsEntity goodsEntityTemp = new InstallMaterialGoodsEntity();
  74. foreach (PropertyInfo pi in propertyGoods)
  75. {
  76. tempGoods = pi.Name;
  77. if (dtGoods.Columns.Contains(tempGoods))
  78. {
  79. if (!pi.CanWrite)
  80. continue;
  81. object value = row[tempGoods];
  82. if (value != DBNull.Value)
  83. pi.SetValue(goodsEntityTemp, value, null);
  84. }
  85. }
  86. goodsList.Add(goodsEntityTemp);
  87. }
  88. string tempUnit = "";
  89. foreach (DataRow row in dtUnit.Rows)
  90. {
  91. InstallMaterialUnitEntity unitEntityTemp = new InstallMaterialUnitEntity();
  92. foreach (PropertyInfo pi in propertyUnit)
  93. {
  94. tempUnit = pi.Name;
  95. //检查DataTable是否包含此列
  96. if (dtUnit.Columns.Contains(tempUnit))
  97. {
  98. //判断此属性是否有set
  99. if (!pi.CanWrite)
  100. continue;
  101. object value = row[tempUnit];
  102. if (value != DBNull.Value)
  103. pi.SetValue(unitEntityTemp, value, null);
  104. }
  105. }
  106. unitList.Add(unitEntityTemp);
  107. }
  108. ViewBag.databaseType = typeList;
  109. ViewBag.databaseGoods = goodsList;
  110. ViewBag.databaseUnit = unitList;
  111. return View();
  112. }
  113. catch (Exception ex)
  114. {
  115. return Content("");
  116. }
  117. }
  118. /// <summary>
  119. ///
  120. /// </summary>
  121. /// <returns></returns>
  122. public ActionResult GetBudgetDetail(string materialID)
  123. {
  124. //try
  125. //{
  126. // dtGoods = installDudgetbll.GetBudgetDetailGoods(materialID);
  127. // string JsonString = string.Empty;
  128. // JsonString = JsonConvert.SerializeObject(dtGoods);
  129. // var JsonData = new
  130. // {
  131. // rows = JsonConvert.DeserializeObject(JsonString),
  132. // };
  133. // return Content(JsonData.ToJson());
  134. //}
  135. try
  136. {
  137. dtGoods = installDudgetbll.GetBudgetDetailGoods(materialID);
  138. List<InstallMaterialGoodsEntity> goodsList = new List<InstallMaterialGoodsEntity>();
  139. InstallMaterialGoodsEntity goodsEntity = new InstallMaterialGoodsEntity();
  140. PropertyInfo[] propertyGoods = goodsEntity.GetType().GetProperties();
  141. string tempGoods = "";
  142. foreach (DataRow row in dtGoods.Rows)
  143. {
  144. InstallMaterialGoodsEntity goodsEntityTemp = new InstallMaterialGoodsEntity();
  145. foreach (PropertyInfo pi in propertyGoods)
  146. {
  147. tempGoods = pi.Name;
  148. if (dtGoods.Columns.Contains(tempGoods))
  149. {
  150. if (!pi.CanWrite)
  151. continue;
  152. object value = row[tempGoods];
  153. if (value != DBNull.Value)
  154. pi.SetValue(goodsEntityTemp, value, null);
  155. }
  156. }
  157. goodsList.Add(goodsEntityTemp);
  158. }
  159. ViewBag.databaseGoods110 = goodsList;
  160. return Content(goodsList.ToJson());
  161. //return View();
  162. }
  163. catch (Exception ex)
  164. {
  165. return Content("");
  166. }
  167. }
  168. public ActionResult GetListJson(string startTime, string endTime, String type, Pagination pagination)
  169. {
  170. InstallApplyEntity entity = new InstallApplyEntity();
  171. if (type == null)
  172. {
  173. entity.budgetType = 0;
  174. entity.SurveyType = 1;
  175. }
  176. else
  177. {
  178. entity.budgetType = int.Parse(type);
  179. entity.SurveyType = 1;
  180. }
  181. if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime))
  182. {
  183. var data = InstallApplybll.getInstallApplyList(startTime, endTime, pagination, entity);
  184. var watch = CommonHelper.TimerStart();
  185. var JsonData = new
  186. {
  187. rows = JsonConvert.DeserializeObject(data),
  188. total = pagination.total,
  189. page = pagination.page,
  190. records = pagination.records,
  191. costtime = CommonHelper.TimerEnd(watch)
  192. };
  193. return Content(JsonData.ToJson());
  194. }
  195. else
  196. {
  197. entity.budgetType = 0;
  198. entity.SurveyType = 1;
  199. var data = InstallApplybll.getInstallApplyList(startTime, endTime, pagination, entity);
  200. var watch = CommonHelper.TimerStart();
  201. var JsonData = new
  202. {
  203. rows = JsonConvert.DeserializeObject(data),
  204. total = pagination.total,
  205. page = pagination.page,
  206. records = pagination.records,
  207. costtime = CommonHelper.TimerEnd(watch)
  208. };
  209. return Content(JsonData.ToJson());
  210. }
  211. return Content("");
  212. }
  213. public ActionResult GetDudgetListByApply(String applyId, Pagination pagination)
  214. {
  215. String json = "";
  216. if (!String.IsNullOrEmpty(applyId))
  217. {
  218. try
  219. {
  220. var data = installDudgetbll.getInstallDudgetList(applyId, pagination);
  221. var watch = CommonHelper.TimerStart();
  222. var JsonData = new
  223. {
  224. rows = JsonConvert.DeserializeObject(data),
  225. total = pagination.total,
  226. page = pagination.page,
  227. records = pagination.records,
  228. costtime = CommonHelper.TimerEnd(watch)
  229. };
  230. return Content(JsonData.ToJson());
  231. }
  232. catch (Exception ex)
  233. {
  234. return Content("");
  235. }
  236. }
  237. return Content("");
  238. }
  239. #region 保存数据
  240. [HttpPost]
  241. [AjaxOnly]
  242. public ActionResult SaveForm(String applyId)
  243. {
  244. installDudgetbll.SaveForm(applyId);
  245. return Success("操作成功。");
  246. }
  247. #endregion
  248. #region 保存数据
  249. [HttpPost]
  250. [AjaxOnly]
  251. public ActionResult SaveForma(String applyId, string data)
  252. {
  253. //var postData = $("#Type") $("#name") $("#myGoodsSpec" + $("#unit")t + $("#number") $("#price"). + $("#LabourCost").val() + spit + $("#Description").val();;
  254. InstallDudgetEntity entity = new InstallDudgetEntity();
  255. string[] listdata = data.Split('*');
  256. entity.Apply_ID = Convert.ToInt32(applyId);
  257. entity.Version = listdata[2];
  258. entity.Type = listdata[0];
  259. entity.unit = listdata[3];
  260. entity.number = Convert.ToInt32(listdata[4]);
  261. entity.price = Convert.ToInt32(listdata[5]);
  262. entity.LabourCost = Convert.ToDecimal(listdata[6]);
  263. entity.name = listdata[1];
  264. installDudgetbll.SaveForma(applyId, entity);
  265. return Success("操作成功。");
  266. }
  267. //public ActionResult SaveForma(String applyId, InstallDudgetEntity entity)
  268. //{
  269. // installDudgetbll.SaveForma(applyId, entity);
  270. // return Success("操作成功。");
  271. //}
  272. #endregion
  273. }
  274. }