|
|
|
using CK.SCP.Controller;
|
|
|
|
using CK.SCP.Models;
|
|
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
|
|
using CK.SCP.Models.Enums;
|
|
|
|
using CK.SCP.Models.ScpEntity;
|
|
|
|
using CK.SCP.Utils;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Data.Entity.Migrations;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Runtime.Serialization.Json;
|
|
|
|
using System.Text;
|
|
|
|
using System.Web;
|
|
|
|
using System.Web.Services;
|
|
|
|
|
|
|
|
namespace WebService
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// WebService 的摘要说明
|
|
|
|
/// </summary>
|
|
|
|
[WebService(Namespace = "http://tempuri.org/")]
|
|
|
|
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
|
|
|
|
[System.ComponentModel.ToolboxItem(false)]
|
|
|
|
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
|
|
|
|
// [System.Web.Script.Services.ScriptService]
|
|
|
|
public class WebService : System.Web.Services.WebService
|
|
|
|
{
|
|
|
|
public class result
|
|
|
|
{
|
|
|
|
public int code;
|
|
|
|
public string msg;
|
|
|
|
}
|
|
|
|
public class result3
|
|
|
|
{
|
|
|
|
public int code { get; set; }
|
|
|
|
public string msg { get; set; }
|
|
|
|
}
|
|
|
|
public class result1
|
|
|
|
{
|
|
|
|
public int code { get; set; }
|
|
|
|
public string msg { get; set; }
|
|
|
|
public int count { get; set; }
|
|
|
|
public string data { get; set; }
|
|
|
|
|
|
|
|
}
|
|
|
|
public class result2
|
|
|
|
{
|
|
|
|
public string Extend1 { get; set; }
|
|
|
|
public decimal AskQty { get; set; }
|
|
|
|
public decimal AsnQty { get; set; }
|
|
|
|
public decimal AreQty { get; set; }
|
|
|
|
}
|
|
|
|
public class result4
|
|
|
|
{
|
|
|
|
public string AsnBillNum { get; set; }
|
|
|
|
public string AskBillNum { get; set; }
|
|
|
|
public string PoBillNum { get; set; }
|
|
|
|
public string VendId { get; set; }
|
|
|
|
public string ReceiveUser { get; set; }
|
|
|
|
public DateTime CreateTime { get; set; }
|
|
|
|
public DateTime ReceiveTime { get; set; }
|
|
|
|
public DateTime ShipTime { get; set; }
|
|
|
|
}
|
|
|
|
[WebMethod]
|
|
|
|
public string getObjectByJson(string jsonString)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var list = JsonConvert.DeserializeObject<List<V_TB_ASK_DETAIL>>(jsonString);
|
|
|
|
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
List<string> ErrorList = new List<string>();
|
|
|
|
foreach (var ls in list)
|
|
|
|
{
|
|
|
|
String str = ls.PoBillNum.ToString();
|
|
|
|
String str1 = ls.VendId.ToString();
|
|
|
|
String str2 = ls.PartCode.ToString();
|
|
|
|
String str3 = ls.Extend1.ToString();
|
|
|
|
String str4 = ls.PoUnit.ToString();
|
|
|
|
var lsA = db.TB_PO.Count(p => p.PoBillNum == ls.PoBillNum && p.VendId == ls.VendId);
|
|
|
|
if (lsA == 0)
|
|
|
|
{
|
|
|
|
ErrorList.Add(string.Format("订单号【{0}】不存在", str));
|
|
|
|
}
|
|
|
|
var la = db.TB_ASK_DETAIL.Count(p => p.Extend1 == ls.Extend1);
|
|
|
|
if (la > 0)
|
|
|
|
{
|
|
|
|
ErrorList.Add(string.Format("唯一码【{0}】已经存在了", str3));
|
|
|
|
}
|
|
|
|
var ls1 = db.TA_PART.Count(P => P.PartCode == ls.PartCode);
|
|
|
|
if (ls1 == 0)
|
|
|
|
{
|
|
|
|
ErrorList.Add(string.Format("零件号【{0}】不存在", str2));
|
|
|
|
}
|
|
|
|
var Unit = db.TA_PART.Count(P => P.PartCode == ls.PartCode && P.Unit == ls.PoUnit);
|
|
|
|
if (Unit == 0)
|
|
|
|
{
|
|
|
|
ErrorList.Add(string.Format("零件号【{0}】单位不对", str2));
|
|
|
|
}
|
|
|
|
var ved = db.TB_PO_DETAIL.Count(p => p.PoBillNum == ls.PoBillNum && p.PartCode == ls.PartCode);
|
|
|
|
if (ved == 0)
|
|
|
|
{
|
|
|
|
ErrorList.Add(string.Format("订单号【{0}】中不存在零件号【{1}】", str1, str2));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var lv = db.TB_PO_DETAIL.SingleOrDefault(p => p.PoBillNum == ls.PoBillNum && p.PartCode == ls.PartCode);
|
|
|
|
if (lv.PlanQty < ls.AskQty)
|
|
|
|
{
|
|
|
|
ErrorList.Add(string.Format("订单号【{0}】中零件号【{1}】的要货数量超过SCP中的最大要货数量", str1, str2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
string st = string.Join(",", ErrorList.ToArray());
|
|
|
|
result co = new result();
|
|
|
|
if (ErrorList.Count == 0)
|
|
|
|
{
|
|
|
|
foreach (var ls in list)
|
|
|
|
{
|
|
|
|
var lt = db.TB_ASK.Count(p => p.PoBillNum == ls.PoBillNum && p.EndTime == ls.EndTime && p.VendId == ls.VendId);
|
|
|
|
var orderlist = list.GroupBy(p => p.PoBillNum).ToList();
|
|
|
|
orderlist.ForEach((p) =>
|
|
|
|
{
|
|
|
|
var list1 = p.ToList();
|
|
|
|
if (list1.Count > 0)
|
|
|
|
{
|
|
|
|
TB_ASK ASK = new TB_ASK();
|
|
|
|
ASK.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCode1();
|
|
|
|
ASK.PoBillNum = ls.PoBillNum;
|
|
|
|
ASK.VendId = ls.VendId;
|
|
|
|
ASK.Site = "BJBMPT";
|
|
|
|
ASK.CreateTime = ls.CreateTime;
|
|
|
|
ASK.CreateUser = ls.CreateUser;
|
|
|
|
ASK.UpdateTime = DateTime.Now;
|
|
|
|
ASK.UpdateUser = ls.CreateUser;
|
|
|
|
ASK.IsDeleted = false;
|
|
|
|
ASK.GUID = Guid.NewGuid();
|
|
|
|
ASK.State = (int)AskState.Release;
|
|
|
|
ASK.ModType = 1;
|
|
|
|
ASK.BeginTime = ls.CreateTime;
|
|
|
|
ASK.EndTime = ls.EndTime;
|
|
|
|
ASK.ErpBillNum = ls.PoBillNum;
|
|
|
|
ASK.Buyer = ls.CreateUser;
|
|
|
|
ASK.SubSite = ls.SubSite;
|
|
|
|
ASK.Remark = ls.Remark;
|
|
|
|
db.TB_ASK.AddOrUpdate(ASK);
|
|
|
|
db.SaveChanges();
|
|
|
|
list.ForEach((itm) =>
|
|
|
|
{
|
|
|
|
TB_ASK_DETAIL ASKK = new TB_ASK_DETAIL();
|
|
|
|
ASKK.AskBillNum = ASK.AskBillNum;
|
|
|
|
ASKK.PoBillNum = ls.PoBillNum;
|
|
|
|
ASKK.PartCode = ls.PartCode;
|
|
|
|
var pline = db.TB_PO_DETAIL.SingleOrDefault(t => t.PartCode == ls.PartCode && t.PoBillNum == ls.PoBillNum);
|
|
|
|
ASKK.PoLine = pline.PoLine;
|
|
|
|
ASKK.Currency = "CNY";
|
|
|
|
ASKK.Price = pline.Price;
|
|
|
|
ASKK.AskQty = ls.AskQty;
|
|
|
|
ASKK.BeginTime = DateTime.Now;
|
|
|
|
ASKK.EndTime = ls.EndTime;
|
|
|
|
ASKK.PoUnit = ls.PoUnit;
|
|
|
|
ASKK.LocUnit = ls.PoUnit;
|
|
|
|
ASKK.State = (int)AskState.Release;
|
|
|
|
ASKK.CreateTime = ls.CreateTime;
|
|
|
|
ASKK.CreateUser = ls.CreateUser;
|
|
|
|
ASKK.IsDeleted = false;
|
|
|
|
ASKK.GUID = Guid.NewGuid();
|
|
|
|
ASKK.SubSite = ls.SubSite;
|
|
|
|
ASKK.Site = "BJBMPT";
|
|
|
|
ASKK.Extend1 = ls.Extend1.ToString();
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(ASKK);
|
|
|
|
db.SaveChanges();
|
|
|
|
ErrorList.Add(string.Format("数据无误,插入成功"));
|
|
|
|
|
|
|
|
co.msg = "数据无误,插入成功";
|
|
|
|
co.code = 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
co.msg = st;
|
|
|
|
co.code = 1;
|
|
|
|
}
|
|
|
|
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(result));
|
|
|
|
//创建存储区为内存流
|
|
|
|
System.IO.MemoryStream ms = new MemoryStream();
|
|
|
|
//将json字符串写入内存流中
|
|
|
|
serializer.WriteObject(ms, co);
|
|
|
|
System.IO.StreamReader reader = new StreamReader(ms);
|
|
|
|
ms.Position = 0;
|
|
|
|
string strRes = reader.ReadToEnd();
|
|
|
|
reader.Close();
|
|
|
|
ms.Close();
|
|
|
|
return strRes;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(WebService), "WebService", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
result3 co1 = new result3();
|
|
|
|
co1.code = 1;
|
|
|
|
co1.msg = e.ToString();
|
|
|
|
String string_json_txt = Newtonsoft.Json.JsonConvert.SerializeObject(co1);
|
|
|
|
return string_json_txt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[WebMethod]
|
|
|
|
public string SeachQueryOut(string jsonString)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
List<result2> ErrorList3 = new List<result2>();
|
|
|
|
List<result1> ErrorList2 = new List<result1>();
|
|
|
|
var list = JsonConvert.DeserializeObject<V_TB_ASK_DETAIL>(jsonString);
|
|
|
|
List<string> ErrorList = new List<string>();
|
|
|
|
var Sub = list.Extend1;
|
|
|
|
Sub.Split();
|
|
|
|
int count1 = 0;
|
|
|
|
List<string> result = Sub.Split(',').ToList();
|
|
|
|
foreach (var Subsite in result)
|
|
|
|
{
|
|
|
|
|
|
|
|
var lssk = db.TB_ASK_DETAIL.Count(p => p.Extend1 == Subsite);
|
|
|
|
if (lssk == 0)
|
|
|
|
{
|
|
|
|
//result1 co1 = new result1();
|
|
|
|
string strd = null;
|
|
|
|
|
|
|
|
//string strd3 = strd1 + strd + strd2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var ls1 = db.TB_ASN_DETAIL.Count(p => p.Extend1 == Subsite);
|
|
|
|
decimal AskQty = 0;
|
|
|
|
decimal AsnQty = 0;
|
|
|
|
decimal AreQty = 0;
|
|
|
|
|
|
|
|
if (ls1 > 0)
|
|
|
|
{
|
|
|
|
var ls2 = db.TB_ASK_DETAIL.SingleOrDefault(p => p.Extend1 == Subsite);
|
|
|
|
AskQty = ls2.AskQty;
|
|
|
|
AsnQty = 0;
|
|
|
|
AreQty = 0;
|
|
|
|
}
|
|
|
|
if (ls1 == 0)
|
|
|
|
{
|
|
|
|
var ls5 = db.TB_ASK_DETAIL.SingleOrDefault(p => p.Extend1 == Subsite);
|
|
|
|
AskQty = ls5.AskQty;
|
|
|
|
AsnQty = 0;
|
|
|
|
AreQty = 0;
|
|
|
|
}
|
|
|
|
else if (ls1 == 1)
|
|
|
|
{
|
|
|
|
var _lst = db.TB_ASN_DETAIL.SingleOrDefault(p => p.Extend1 == Subsite);
|
|
|
|
|
|
|
|
var ask = db.TB_ASK_DETAIL.SingleOrDefault(p => p.Extend1 == Subsite);
|
|
|
|
var _ly = db.TB_RECEIVE_DETAIL.Count(p => p.PoBillNum == _lst.PoBillNum && p.PartCode == _lst.PartCode);
|
|
|
|
if (_ly == 1)
|
|
|
|
{
|
|
|
|
var _ly2 = db.TB_RECEIVE_DETAIL.SingleOrDefault(p => p.PoBillNum == _lst.PoBillNum && p.PartCode == _lst.PartCode);
|
|
|
|
AreQty = _ly2.Qty;
|
|
|
|
AsnQty = _lst.Qty;
|
|
|
|
AskQty = ask.AskQty - _lst.Qty - _ly2.Qty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ls1 > 1)
|
|
|
|
{
|
|
|
|
var asn = db.TB_ASN_DETAIL.Where(p => p.Extend1 == Subsite).ToList();
|
|
|
|
|
|
|
|
var Amount = asn.Sum(t => t.Qty);
|
|
|
|
AsnQty = Amount;
|
|
|
|
|
|
|
|
var arr = asn.First();
|
|
|
|
var arr1 = db.TB_RECEIVE_DETAIL.Where(p => p.PoBillNum == arr.PoBillNum && p.PartCode == arr.PartCode).ToList();
|
|
|
|
var cc = arr1.Sum(t => t.Qty);
|
|
|
|
AreQty = cc;
|
|
|
|
var ask = db.TB_ASK_DETAIL.SingleOrDefault(p => p.Extend1 == Subsite);
|
|
|
|
AskQty = ask.AskQty - cc - Amount;
|
|
|
|
//string st = string.Join(",", ErrorList.ToArray());
|
|
|
|
}
|
|
|
|
result2 sum = new result2();
|
|
|
|
sum.Extend1 = Subsite;
|
|
|
|
sum.AskQty = AskQty;
|
|
|
|
sum.AsnQty = AsnQty;
|
|
|
|
sum.AreQty = AreQty;
|
|
|
|
//ErrorList3.Add(sum);
|
|
|
|
String string_json = Newtonsoft.Json.JsonConvert.SerializeObject(sum);
|
|
|
|
result1 co1 = new result1();
|
|
|
|
string strr = string_json;
|
|
|
|
ErrorList.Add(strr);
|
|
|
|
count1++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String string_json_txt1 = Newtonsoft.Json.JsonConvert.SerializeObject(ErrorList);
|
|
|
|
result1 co2 = new result1();
|
|
|
|
co2.code = 0;
|
|
|
|
co2.msg = "查询成功";
|
|
|
|
co2.count = count1;
|
|
|
|
co2.data = string_json_txt1;
|
|
|
|
String string_json_txt = Newtonsoft.Json.JsonConvert.SerializeObject(co2);
|
|
|
|
string str = string_json_txt.Substring(1, string_json_txt.Length - 1);
|
|
|
|
string str1 = str.Remove(str.Length - 1, 1);
|
|
|
|
|
|
|
|
if (str1.Contains("data\":\"["))
|
|
|
|
{
|
|
|
|
str1 = str1.Replace("data\":\"[", "data\":[");
|
|
|
|
}
|
|
|
|
str1 = str1.Replace("\\", "");
|
|
|
|
str1 = str1.Replace("\"{", "{\"");
|
|
|
|
str1 = str1.Replace("}\"", "\"}");
|
|
|
|
//str1 = str1.;
|
|
|
|
str1 = str1.Substring(0, str1.Length - 2) + "}";
|
|
|
|
return str1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(WebService), "WebService", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
result3 co1 = new result3();
|
|
|
|
co1.code = 1;
|
|
|
|
co1.msg = e.ToString();
|
|
|
|
String string_json_txt = Newtonsoft.Json.JsonConvert.SerializeObject(co1);
|
|
|
|
return string_json_txt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
[WebMethod]
|
|
|
|
public string getAsnByJson()
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
DateTime date = DateTime.Now;
|
|
|
|
DateTime dare1 = date.AddDays(-7);
|
|
|
|
result co = new result();
|
|
|
|
result4 ac = new result4();
|
|
|
|
int count1 = 0;
|
|
|
|
List<string> ErrorList = new List<string>();
|
|
|
|
var list = db.TB_ASN.Where(p => p.ReceiveTime > dare1&&p.State==3).ToList();
|
|
|
|
if (list.Count > 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach(var ls in list)
|
|
|
|
{
|
|
|
|
ac.AsnBillNum = ls.AsnBillNum;
|
|
|
|
ac.AskBillNum = ls.AskBillNum;
|
|
|
|
ac.VendId = ls.VendId;
|
|
|
|
ac.PoBillNum = ls.PoBillNum;
|
|
|
|
ac.ReceiveUser = ls.ReceiveUser;
|
|
|
|
ac.CreateTime = ls.CreateTime;
|
|
|
|
ac.ReceiveTime =DateTime.Parse(ls.ReceiveTime.ToString());
|
|
|
|
ac.ShipTime = DateTime.Parse(ls.ShipTime.ToString());
|
|
|
|
String string_json = Newtonsoft.Json.JsonConvert.SerializeObject(ac);
|
|
|
|
ErrorList.Add(string_json);
|
|
|
|
count1++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String string_json_txt1 = Newtonsoft.Json.JsonConvert.SerializeObject(ErrorList);
|
|
|
|
result1 co2 = new result1();
|
|
|
|
co2.code = 0;
|
|
|
|
co2.msg = "查询成功";
|
|
|
|
co2.count = count1;
|
|
|
|
co2.data = string_json_txt1;
|
|
|
|
String string_json_txt = Newtonsoft.Json.JsonConvert.SerializeObject(co2);
|
|
|
|
string str = string_json_txt.Substring(1, string_json_txt.Length - 1);
|
|
|
|
string str1 = str.Remove(str.Length - 1, 1);
|
|
|
|
|
|
|
|
if (str1.Contains("data\":\"["))
|
|
|
|
{
|
|
|
|
str1 = str1.Replace("data\":\"[", "data\":[");
|
|
|
|
}
|
|
|
|
str1 = str1.Replace("\\", "");
|
|
|
|
str1 = str1.Replace("\"{", "{");
|
|
|
|
str1 = str1.Replace("}\"", "}");
|
|
|
|
//str1 = str1.;
|
|
|
|
str1 = str1.Substring(0, str1.Length - 2) + "]"+"}";
|
|
|
|
return str1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(WebService), "WebService", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
result3 co1 = new result3();
|
|
|
|
co1.code = 1;
|
|
|
|
co1.msg = e.ToString();
|
|
|
|
String string_json_txt = Newtonsoft.Json.JsonConvert.SerializeObject(co1);
|
|
|
|
return string_json_txt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|