품목검색기능ㅊ추가

This commit is contained in:
chi
2021-03-11 14:44:21 +09:00
parent 87da6dbe5f
commit b4746b6247
12 changed files with 660 additions and 77 deletions

View File

@@ -0,0 +1,148 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Web.Http;
namespace Project
{
public class ItemController : BaseController
{
// PUT api/values/5
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
[HttpGet]
public string Test()
{
return "test";
}
[HttpGet]
public HttpResponseMessage Find()
{
//로그인이 되어있지않다면 로그인을 가져온다
MethodResult result;
result = View();
var gets = Request.GetQueryNameValuePairs();// GetParameters(data);
var key_search = gets.Where(t => t.Key == "search").FirstOrDefault();
var model = GetGlobalModel();
var getParams = Request.GetQueryNameValuePairs();// GetParameters(data);
//기본값을 찾아서 없애줘야한다
var searchkey = string.Empty;
if (key_search.Key != null && key_search.Value.isEmpty() == false) searchkey = key_search.Value.Trim();
var tbody = new System.Text.StringBuilder();
//테이블데이터생성
var itemcnt = 0;
if (searchkey.isEmpty() == false)
{
var db = new EEEntitiesMain();
var rows = db.vFindSID.Where(t => t.sid.Contains(searchkey) || t.name.Contains(searchkey) || t.manu.Contains(searchkey) || t.model.Contains(searchkey));
itemcnt = rows.Count();
foreach (var item in rows)
{
tbody.AppendLine("<tr>");
tbody.AppendLine($"<th scope='row'>{item.Location}</th>");
tbody.AppendLine($"<td>{item.sid}</td>");
tbody.AppendLine($"<td>{item.name}</td>");
tbody.AppendLine($"<td>{item.model}</td>");
if (item.price == null)
tbody.AppendLine($"<td>--</td>");
else
{
var price = (double)item.price / 1000.0;
tbody.AppendLine($"<td>{price.ToString("N0")}</td>");
}
tbody.AppendLine($"<td>{item.manu}</td>");
tbody.AppendLine($"<td>{item.supply}</td>");
if (item.remark.Length > 10)
tbody.AppendLine($"<td>{item.remark.Substring(0, 10)}...</td>");
else
tbody.AppendLine($"<td>{item.remark}</td>");
tbody.AppendLine("</tr>");
}
}
//아잍쳄이 없는경우
if (itemcnt == 0)
{
tbody.AppendLine("<tr>");
tbody.AppendLine("<th scope='row'>1</th>");
tbody.AppendLine("<td colspan='6'>자료가 없습니다</td>");
tbody.AppendLine("</tr>");
}
var contents = result.Content.Replace("{search}", searchkey);
contents = contents.Replace("{tabledata}", tbody.ToString());
contents = contents.Replace("{cnt}", itemcnt.ToString());
//공용값 적용
ApplyCommonValue(ref contents);
//최종문자 적용
result.Content = contents;
var resp = new HttpResponseMessage()
{
Content = new StringContent(
result.Content,
System.Text.Encoding.UTF8,
"text/html")
};
return resp;
}
[HttpGet]
public HttpResponseMessage Index()
{
//로그인이 되어있지않다면 로그인을 가져온다
MethodResult result;
result = View();
var model = GetGlobalModel();
var getParams = Request.GetQueryNameValuePairs();// GetParameters(data);
//기본값을 찾아서 없애줘야한다
var contents = result.Content;
//공용값 적용
ApplyCommonValue(ref contents);
//최종문자 적용
result.Content = contents;
var resp = new HttpResponseMessage()
{
Content = new StringContent(
result.Content,
System.Text.Encoding.UTF8,
"text/html")
};
return resp;
}
}
}