|
|
using Newtonsoft.Json.Linq;using Newtonsoft.Json;using NFine.Code;using NFine.Data.Extensions;using NFine.Domain._03_Entity.SRM;using NFine.Repository;using System;using System.Collections.Generic;using System.Configuration;using System.Data.Common;using System.Data;using System.IO;using System.Linq;using System.Net;using System.Text;using System.Threading.Tasks;
namespace NFine.Application.WMS{ public class ICSDeliveryNoticeApp : RepositoryFactory<ICSVendor> { public static DataTable Invmes = new DataTable(); /// <summary>
/// 采购到货查询
/// </summary>
/// <param name="jqgridparam"></param>
/// <returns></returns>
public DataTable GetDeliveryNoticeApplyNeg(ref Pagination jqgridparam) { DataTable dt = new DataTable(); List<DbParameter> parameter = new List<DbParameter>(); string sql = @"select a.ID,a.DNCode,a.Sequence,a.VenCode,a.DepCode,a.WHCode,a.DNType,a.InvCode,a.Quantity
,a.Amount,a.RCVQuantity,a.UnitPrice,a.Currency,a.Status,a.CreatePerson,a.CreateDateTime,a.POID,a.PODetailID,a.DNID,a.DNDetailID,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,a.EATTRIBUTE1,a.ASNCode,b.InvName ,f.Colspan ,f.ProjectCode ,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4 ,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10 ,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 from ICSDeliveryNotice a left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint where isnull(a.POID,'0') != '0'";
sql = string.Format(sql); DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); }
/// <summary>
/// 删除
/// </summary>
/// <param name="keyValue">传入ID</param>
/// <returns></returns>
public string DeleteICSDeliveryNotice(string keyValue) { //删除前校验
//站点信息
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSDeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'" , keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// <summary>
/// 无源头采购到货查询
/// </summary>
/// <param name="jqgridparam"></param>
/// <returns></returns>
public DataTable GetEDeliveryNoticeApplyNeg(ref Pagination jqgridparam) { DataTable dt = new DataTable(); List<DbParameter> parameter = new List<DbParameter>(); string sql = @"select a.ID,a.DNCode,a.Sequence,a.VenCode,a.DepCode,a.WHCode,a.DNType,a.InvCode,a.Quantity,c.VenName,e.DepName,g.WarehouseName as WHName
,a.Amount,a.RCVQuantity,a.UnitPrice,a.Currency,a.Status,a.CreatePerson,a.CreateDateTime,a.POID,a.PODetailID,a.DNID,a.DNDetailID,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,a.EATTRIBUTE1,a.ASNCode,b.InvName ,f.Colspan ,f.ProjectCode ,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4 ,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 from ICSDeliveryNotice a left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint left join ICSVendor c on c.VenCode=a.VenCode and c.WorkPoint=a.WorkPoint left join ICSDepartment e on e.DepCode=a.DepCode and e.WorkPoint=a.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint left join ICSWarehouse g on a.WHCode = g.WarehouseCode and a.WorkPoint=g.WorkPoint where isnull(a.POID,'0') = '0'";
sql = string.Format(sql); DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// <summary>
/// 采购删除
/// </summary>
/// <param name="keyValue"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public string DeleteDeliveryNoticeApplyNeg(string keyValue) { //站点信息
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty;
sql += string.Format(@"DELETE FROM dbo.ICSDeliveryNotice WHERE Id IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); //sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
try { if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) {
} } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// <summary>
/// 获取部门
/// </summary>
/// <param name="InvCode"></param>
/// <returns></returns>
public DataTable GetSelectICSVenCode() { string sql = string.Empty;
DataTable dt = null;
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; sql = @"
select a.VenCode,a.VenName from dbo.ICSVendor a";
sql = string.Format(sql, WorkPoint); dt = SqlHelper.GetDataTableBySql(sql); return dt; } /// <summary>
/// 选择表格—采购订单行选择
/// </summary>
/// <param name="ID"></param>
/// <param name="jqgridparam"></param>
/// <returns></returns>
public DataTable GetPurOrder(string POCode, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; List<DbParameter> parameter = new List<DbParameter>(); DataTable table = new DataTable(); string wherestr = ""; if (!string.IsNullOrEmpty(POCode)) { wherestr += " and a.POCode like '%" + POCode + "%'"; } string sql = @"select a.ID,a.POCode,a.Sequence,a.InvCode,a.Quantity,a.Amount,a.InQuantity,a.ExtensionID,a.MUSER
,a.MUSERName,a.MTIME,b.InvName ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 from ICSPurchaseOrder a left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint where a.WorkPoint = '" + WorkPoint + "'" + wherestr;
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
} public void ClearTemp() { Invmes.Rows.Clear(); } public DataTable GetICSDeliveryNoticeReturnTemporary(string ID) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string wherestr = ""; //if (!string.IsNullOrEmpty(ID))
//{
// wherestr += "and a.DNCode = " + DNCode + " and a.Sequence = " + Sequence;
//}
string sql = @"select a.ID,a.DNCode,a.Sequence,a.VenCode,a.DepCode,a.WHCode,a.DNType,a.InvCode,a.Quantity,c.WarehouseCode,c.WarehouseName
,a.Amount,a.RCVQuantity,a.UnitPrice,a.Currency,a.Status,a.CreatePerson,a.CreateDateTime,a.POID,a.PODetailID,a.DNID,a.DNDetailID,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,a.ASNCode,b.InvName ,f.Colspan ,f.ProjectCode ,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4 ,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10 ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 from ICSDeliveryNotice a left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint left join ICSWarehouse c on a.WHCode = c.WarehouseCode and a.WorkPoint=c.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint where a.ID in (" + ID + ") ";
// where a.WorkPoint = '" + WorkPoint + "' " + wherestr;
DataTable table = Repository().FindDataSetBySql(sql).Tables[0]; DataTable dtCloned = table.Clone(); foreach (DataColumn col in dtCloned.Columns) { col.DataType = typeof(string); } foreach (DataRow row in table.Rows) { DataRow newrow = dtCloned.NewRow(); foreach (DataColumn column in dtCloned.Columns) { newrow[column.ColumnName] = row[column.ColumnName].ToString();
} dtCloned.Rows.Add(newrow); } if (Invmes.Rows.Count > 0) { dtCloned.Merge(Invmes, false); } return dtCloned; } /// <summary>
/// 新增
/// </summary>
/// <param name="ICSASN"></param>
/// <returns></returns>
public string SaveICSDeliveryNoticeAppApplyNeg(string ICSASN) { string msg = ""; string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "EDeliveryNotice/Create"; string result = HttpPost(APIURL, ICSASN); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { msg = MessAge; } return msg; } /// <summary>
/// 修改
/// </summary>
/// <param name="ICSASN"></param>
/// <returns></returns>
public string UpdateICSDeliveryNoticeApplyNeg(string ICSASN) { string msg = ""; string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "EDeliveryNotice/Update"; string result = HttpPost(APIURL, ICSASN); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { msg = MessAge; } return msg; } /// <summary>
/// 获取单号
/// </summary>
/// <param name="WorkPoint"></param>
/// <returns></returns>
public string GetDNCode(string WorkPoint) { WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string DNCode = string.Empty; if (!string.IsNullOrEmpty(WorkPoint)) {
DNCode = GetSerialCode(WorkPoint, "ICSDeliveryNotice", "DNCode", "", 9); } if (!string.IsNullOrWhiteSpace(DNCode)) { string sqlISHave = @"SELECT ApplyCode FROM ICSMOApply a
WHERE a.ApplyCode = '{0}'";
sqlISHave = string.Format(sqlISHave, DNCode); DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave); if (dtIsHave.Rows.Count > 0) { throw new Exception("单号已存在!"); } } return DNCode; }
public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen) { string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}"; sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen }); return SqlHelper.ExecuteScalar(sql).ToString(); } /// <summary>
/// 接口api解析
/// </summary>
/// <param name="url"></param>
/// <param name="body"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static string HttpPost(string url, string body) { try { Encoding encoding = Encoding.UTF8; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
request.ContentType = "application/json; charset=utf-8";
byte[] buffer = encoding.GetBytes(body); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) { return reader.ReadToEnd(); } } catch (WebException ex) { throw new Exception(ex.Message); } } }}
|