Guest User

Untitled

a guest
Jan 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. public ActionResult Report()
  2. {
  3.  
  4. return View();
  5. }
  6.  
  7. [HttpPost]
  8. public ActionResult Report(ReportModel incomingData)
  9. {
  10. //Вычисление количества продаж
  11. int count;
  12. if (incomingData.StartDate != null && incomingData.EndDate != null)
  13. {
  14. count = (from x in db.Orders where (x.Date >= incomingData.StartDate && x.Date <= incomingData.EndDate) select x).Count();
  15. }
  16. else count = 0;
  17. ViewBag.Count = count;
  18. //вычисление суммы по этим продажам
  19. decimal? result;
  20. if (incomingData.StartDate != null && incomingData.EndDate != null)
  21. {
  22. result=(from o in db.Orders
  23. join p in db.Products on o.ProductId equals p.ProductId
  24. let amount = o.Count * p.Cost
  25. where (o.Date >= incomingData.StartDate && o.Date <= incomingData.EndDate)
  26. select amount).DefaultIfEmpty(0).Sum();
  27. }
  28. else result = 0;
  29. ViewBag.Result = result;
  30. return View();
  31. }
  32.  
  33. @{
  34. ViewBag.Title = "Report";
  35. }
  36.  
  37. <h2>Report</h2>
  38. @using (Html.BeginForm())
  39. {
  40. <fieldset>
  41. <div>
  42. <label>Start Date</label>
  43. @Html.TextBox("StartDate")
  44. </div>
  45. <div>
  46. <label>End Date</label>
  47. @Html.TextBox("EndDate")
  48. </div>
  49. <input type="submit" value="Check" />
  50.  
  51. </fieldset>
  52. }
  53. <div>Всего продаж @ViewBag.Count</div>
  54. <div>Общая стоимость @ViewBag.Result</div>
  55.  
  56. @using (Html.BeginForm())
  57. {
  58.  
  59. <div>
  60. <label>Введите имя пользователя </label>
  61. @Html.TextBox("y")
  62. </div>
  63. <input type="submit" value="Запросить статистику" />
  64.  
  65. [HttpPost]
  66. public ActionResult Report(ReportModel incomingData,string y)
  67. {
  68. //Вычисление количества продаж
  69. int count;
  70. if (incomingData.StartDate != null && incomingData.EndDate != null)
  71. {
  72. count = (from x in db.Orders where (x.Date >= incomingData.StartDate && x.Date <= incomingData.EndDate) select x).Count();
  73. }
  74. else count = 0;
  75. ViewBag.Count = count;
  76. //вычисление суммы по этим продажам
  77. decimal? result;
  78. if (incomingData.StartDate != null && incomingData.EndDate != null)
  79. {
  80. result=(from o in db.Orders
  81. join p in db.Products on o.ProductId equals p.ProductId
  82. let amount = o.Count * p.Cost
  83. where (o.Date >= incomingData.StartDate && o.Date <= incomingData.EndDate)
  84. select amount).DefaultIfEmpty(0).Sum();
  85. }
  86. else result = 0;
  87. ViewBag.Result = result;
  88. //Вывод статистики по конкретному пользователю
  89. var query = from c in db.Customers
  90. join o in db.Orders on c.CustomerId equals o.CustomerId
  91. join p in db.Products on o.ProductId equals p.ProductId
  92. where c.Name==y
  93. select new
  94. {
  95. c.CustomerId,
  96. c.Name,
  97. c.Surname,
  98. Product=p.Name,
  99. p.Cost,
  100. c=o.Count,
  101. d=o.Date
  102. };
  103. ViewBag.Query = query;
  104. return View();
  105. }
  106.  
  107. @{
  108. ViewBag.Title = "Report";
  109. }
  110. <h2>Report</h2>
  111. @using (Html.BeginForm())
  112. {
  113. <fieldset>
  114. <div>
  115. <label>Start Date</label>
  116. @Html.TextBox("StartDate")
  117. </div>
  118. <div>
  119. <label>End Date</label>
  120. @Html.TextBox("EndDate")
  121. </div>
  122. <input type="submit" value="Check" />
  123.  
  124. </fieldset>
  125. }
  126. <div>Всего продаж @ViewBag.Count</div>
  127. <div>Общая стоимость @ViewBag.Result</div>
  128.  
  129. @using (Html.BeginForm())
  130. {
  131. <div>
  132. <label>Введите имя пользователя </label>
  133. @Html.TextBox("y")
  134. </div>
  135. <input type="submit" value="Запросить статистику" />
  136. }
  137.  
  138. <table class="table">
  139. <tr>
  140. <th>
  141. @Html.DisplayName("CustomerId")
  142. </th>
  143. <th>
  144. @Html.DisplayName("Name")
  145. </th>
  146. <th>
  147. @Html.DisplayName("Surname")
  148. </th>
  149. <th>
  150. @Html.DisplayName("Product")
  151. </th>
  152. <th>
  153. @Html.DisplayName("Cost")
  154. </th>
  155. <th>
  156. @Html.DisplayName("Count")
  157. </th>
  158. <th>
  159. @Html.DisplayName("Date")
  160. </th>
  161. </tr>
  162.  
  163. @foreach (var item in ViewBag.Query)
  164. {
  165. <tr>
  166. <td>
  167. @item
  168. </td>
  169. </tr>
  170. }
  171. </table>
  172.  
  173. using System;
  174. using System.ComponentModel.DataAnnotations;
  175.  
  176. namespace MVC_Fund6_2.Models
  177. {
  178. public class X
  179. {
  180. [Key]
  181. public int CustomerId { get; set; }
  182. public string Name { get; set; }
  183. public string Surname { get; set; }
  184. public string Product { get; set; }
  185. public decimal Cost { get; set; }
  186. public int Count { get; set; }
  187. public DateTime Date { get; set; }
  188. }
  189. }
  190.  
  191. using System.Linq;
  192. using System.Web.Mvc;
  193. using MVC_Fund6_2.Models;
  194.  
  195. namespace MVC_Fund6_2.Controllers
  196. {
  197. public class testController : Controller
  198. {
  199. private DatabaseContext db = new DatabaseContext();
  200. // GET: test
  201. public ActionResult Statistic()
  202. {
  203. var query = from c in db.Customers
  204. join o in db.Orders on c.CustomerId equals o.CustomerId
  205. join p in db.Products on o.ProductId equals p.ProductId //
  206. select new
  207. {
  208. c.CustomerId,
  209. c.Name,
  210. c.Surname,
  211. Product = p.Name,
  212. p.Cost,
  213. o.Count,
  214. o.Date
  215. };
  216. return View(query.ToList());
  217. }
  218. }
  219. }
  220.  
  221. @{
  222. ViewBag.Title = "Statistic";
  223. }
  224.  
  225. <h2>Statistic</h2>
  226.  
  227. <table class="table">
  228. @foreach (var item in Model) {
  229. <tr>
  230. <td>
  231. @item
  232. </td>
  233.  
  234. </tr>
  235. }
Add Comment
Please, Sign In to add comment