using System; using System.Linq; using System.Net.Http; using System.Web.Http; namespace Project { public class PurchaseController : 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(""); tbody.AppendLine($"{item.Location}"); tbody.AppendLine($"{item.sid}"); tbody.AppendLine($"{item.name}"); tbody.AppendLine($"{item.model}"); if (item.price == null) tbody.AppendLine($"--"); else { var price = (double)item.price / 1000.0; tbody.AppendLine($"{price.ToString("N0")}"); } tbody.AppendLine($"{item.manu}"); tbody.AppendLine($"{item.supply}"); if (item.remark.Length > 10) tbody.AppendLine($"{item.remark.Substring(0, 10)}..."); else tbody.AppendLine($"{item.remark}"); tbody.AppendLine(""); } } //아잍쳄이 없는경우 if (itemcnt == 0) { tbody.AppendLine(""); tbody.AppendLine("1"); tbody.AppendLine("자료가 없습니다"); tbody.AppendLine(""); } 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 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 EEEntitiesPurchase(); var sd = DateTime.Now.ToString("yyyy-MM-01"); var rows = db.vPurchase.Where(t => t.gcode == FCOMMON.info.Login.gcode && t.pdate.CompareTo(sd) >= 0).OrderByDescending(t => t.pdate); itemcnt = rows.Count(); foreach (vPurchase item in rows) { tbody.AppendLine(""); tbody.AppendLine($"{item.pdate.Substring(5)}"); if (item.state == "---") tbody.AppendLine($"{item.state}"); else if (item.state == "Received") tbody.AppendLine($"{item.state}"); else tbody.AppendLine($"{item.state}"); tbody.AppendLine($"{item.name}"); tbody.AppendLine($"{item.sid}"); tbody.AppendLine($"{item.pumname}"); if (item.pumscale.Length > 10) tbody.AppendLine($"{item.pumscale.Substring(0, 10)}..."); else tbody.AppendLine($"{item.pumscale}"); tbody.AppendLine($"{item.pumqty}"); tbody.AppendLine($"{item.pumprice}"); tbody.AppendLine($"{item.pumamt}"); tbody.AppendLine($"{item.supply}"); if (item.project != null && item.project.Length > 10) tbody.AppendLine($"{item.project.Substring(0, 10)}..."); else tbody.AppendLine($"{item.project}"); if (item.bigo.Length > 10) tbody.AppendLine($"{item.bigo.Substring(0, 10)}..."); else tbody.AppendLine($"{item.bigo}"); tbody.AppendLine(""); } //} //아잍쳄이 없는경우 if (itemcnt == 0) { tbody.AppendLine(""); tbody.AppendLine("1"); tbody.AppendLine("자료가 없습니다"); tbody.AppendLine(""); } 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; } } }