纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

269 lines
11 KiB

using Newtonsoft.Json;
using NFine.Application.ProductManage;
using NFine.Code;
using NFine.Code.Excel;
using NFine.Domain.Entity.ProductManage;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web.Mvc;
namespace NFine.Web.Areas.ProductManage.Controllers
{
public class OrderManageController : ControllerBase
{
private MaintainApp maintainApp = new MaintainApp();
private PreSellApp presellApp = new PreSellApp();
private PreSellDetailApp preselldetailApp = new PreSellDetailApp();
[HttpGet]
[HandlerAjaxOnly]
public ActionResult GetGridJson(Pagination pagination, string keyword, string keyword2)
{
//var data = maintainAppApp.GetList(keyword);
var data = new
{
rows = presellApp.GetListZS(pagination, keyword, keyword2),
total = pagination.total,
page = pagination.page,
records = pagination.records
};
return Content(data.ToJson());
}
[HttpGet]
[HandlerAjaxOnly]
public ActionResult GetGridJsonMX(string keyValue, string keyword)
{
var data = preselldetailApp.GetList2(keyValue, keyword);
return Content(data.ToJson());
}
[HttpGet]
[HandlerAjaxOnly]
public ActionResult GetFormJson(string keyValue)
{
var data = maintainApp.GetForm(keyValue);
return Content(data.ToJson());
}
[HttpPost]
public void Export(string keyValue, string keyword)
{
var data = preselldetailApp.GetList2(keyValue, keyword);
DataTable dt = (DataTable)data;
if (dt != null && dt.Rows.Count > 0)
{
string PreSellNo = presellApp.GetPreSellNo(dt.Rows[0]["F_Id"].ToString());
dt.Columns.Remove("F_Id");
dt.Columns.Remove("Product_Id");
GridViewExportUtil.Export(dt, PreSellNo);
}
}
[HttpPost]
[HandlerAjaxOnly]
[ValidateAntiForgeryToken]
public ActionResult ConfirmOrders(string keyValue)
{
string confirmUserID = NFine.Code.OperatorProvider.Provider.GetCurrent().UserId;
string[] array = keyValue.Split(',');
List<ICSProductPreSellEntity> ppsList = new List<ICSProductPreSellEntity>();
List<ICSProductEntity> pList = new List<ICSProductEntity>();
ICSProductPreSellEntity entity = null;
foreach (string id in array)
{
entity = new ICSProductPreSellEntity();
entity.F_Id = keyValue;
entity.IsConfirm = true;
entity.ConfirmUserId = confirmUserID;
entity.ConfirmTime = DateTime.Now;
ppsList.Add(entity);
List<string> PIDs = presellApp.GetProductID(keyValue);
if (PIDs != null)
{
foreach (string pid in PIDs)
{
ICSProductEntity model = new ICSProductEntity();
model = maintainApp.GetForm(pid);
if (model != null)
{
model.F_Id = pid;
model.IsLock = true;
pList.Add(model);
}
}
}
}
presellApp.UpdateForm(ppsList, pList, keyValue);
#region 调用WebService,创建销售订单
string idList = "";
for (int i = 0; i < ppsList.Count; i++)
{
if (i == 0)
idList = "'" + ppsList[i].F_Id + "'";
else
idList += ",'" + ppsList[i].F_Id + "'";
}
DataTable dt = preselldetailApp.GetListForWebService(idList);
List<ServiceReference1.SO_SOMain> contextList = new List<ServiceReference1.SO_SOMain>();
List<ServiceReference1.SO_SODetails> contextLists = new List<ServiceReference1.SO_SODetails>();
ServiceReference1.SO_SOMain context = new ServiceReference1.SO_SOMain();
ServiceReference1.SO_SODetails contexts = new ServiceReference1.SO_SODetails();
string PreSellNo = "";//单据号
for (int i = 0; i < dt.Rows.Count; i++)
{
if (PreSellNo != dt.Rows[i]["PreSellNo"].ToString())
{
if (i > 0)
{
context.bodyList = contextLists.ToArray();
contextList.Add(context);
}
context = new ServiceReference1.SO_SOMain();
PreSellNo = dt.Rows[i]["PreSellNo"].ToString();
context.cSOCode = PreSellNo;
context.cCusCode = dt.Rows[i]["F_CusCode"].ToString();
context.isDel = false;
context.UserCode = dt.Rows[i]["UserCode"].ToString();
contextLists = new List<ServiceReference1.SO_SODetails>();
}
contexts = new ServiceReference1.SO_SODetails();
contexts.cInvCode = dt.Rows[i]["ProductSN"].ToString();
contexts.iPrice = string.IsNullOrEmpty(dt.Rows[i]["Amount"].ToString()) ?
0 : Convert.ToDecimal(dt.Rows[i]["Amount"].ToString());
contextLists.Add(contexts);
if (i == dt.Rows.Count - 1)
{
context.bodyList = contextLists.ToArray();
contextList.Add(context);
}
}
ServiceReference1.U8ERP5Client client = new ServiceReference1.U8ERP5Client();
ServiceReference1.Result cresult = new ServiceReference1.Result();
cresult = client.InsertRd32(contextList.ToArray());
if (cresult.IsSuccess == false)
{
throw new Exception(cresult.MESSAGE);
}
#endregion
return Success("Pre sale order confirmed successfully.");
}
[HttpPost]
[HandlerAjaxOnly]
[ValidateAntiForgeryToken]
public ActionResult CancelConfirmOrders(string keyValue)
{
string confirmUserID = NFine.Code.OperatorProvider.Provider.GetCurrent().UserId;
string[] array = keyValue.Split(',');
List<ICSProductPreSellEntity> ppsList = new List<ICSProductPreSellEntity>();
List<ICSProductEntity> pList = new List<ICSProductEntity>();
ICSProductPreSellEntity entity = null;
foreach (string id in array)
{
entity = new ICSProductPreSellEntity();
entity.F_Id = keyValue;
entity.IsConfirm = false;
entity.ConfirmUserId = null;
entity.ConfirmTime = null;
ppsList.Add(entity);
List<string> PIDs = presellApp.GetProductID(keyValue);
if (PIDs != null)
{
foreach (string pid in PIDs)
{
ICSProductEntity model = new ICSProductEntity();
model = maintainApp.GetForm(pid);
if (model != null)
{
model.F_Id = pid;
model.IsLock = false;
pList.Add(model);
}
}
}
}
presellApp.UpdateFormC(ppsList, pList);
#region 调用WebService,删除销售订单
string idList = "";
for (int i = 0; i < ppsList.Count; i++)
{
if (i == 0)
idList = "'" + ppsList[i].F_Id + "'";
else
idList += ",'" + ppsList[i].F_Id + "'";
}
DataTable dt = preselldetailApp.GetListForWebService(idList);
List<ServiceReference1.SO_SOMain> contextList = new List<ServiceReference1.SO_SOMain>();
List<ServiceReference1.SO_SODetails> contextLists = new List<ServiceReference1.SO_SODetails>();
ServiceReference1.SO_SOMain context = new ServiceReference1.SO_SOMain();
ServiceReference1.SO_SODetails contexts = new ServiceReference1.SO_SODetails();
string PreSellNo = "";//单据号
for (int i = 0; i < dt.Rows.Count; i++)
{
if (PreSellNo != dt.Rows[i]["PreSellNo"].ToString())
{
if (i > 0)
{
context.bodyList = contextLists.ToArray();
contextList.Add(context);
}
context = new ServiceReference1.SO_SOMain();
PreSellNo = dt.Rows[i]["PreSellNo"].ToString();
context.cSOCode = PreSellNo;
context.cCusCode = dt.Rows[i]["F_CusCode"].ToString();
context.isDel = true;
context.UserCode = dt.Rows[i]["UserCode"].ToString();
contextLists = new List<ServiceReference1.SO_SODetails>();
}
contexts = new ServiceReference1.SO_SODetails();
contexts.cInvCode = dt.Rows[i]["ProductSN"].ToString();
contexts.iPrice = Convert.ToDecimal(dt.Rows[i]["Amount"].ToString());
contextLists.Add(contexts);
if (i == dt.Rows.Count - 1)
{
context.bodyList = contextLists.ToArray();
contextList.Add(context);
}
}
ServiceReference1.U8ERP5Client client = new ServiceReference1.U8ERP5Client();
ServiceReference1.Result cresult = new ServiceReference1.Result();
cresult = client.InsertRd32(contextList.ToArray());
if (cresult.IsSuccess == false)
{
throw new Exception(cresult.MESSAGE);
}
#endregion
return Success("Pre sale order cancel confirmed successfully.");
}
[HttpPost]
[HandlerAjaxOnly]
[ValidateAntiForgeryToken]
public ActionResult SubmitForm(ICSProductEntity productEntity, string keyValue)
{
maintainApp.SubmitForm(productEntity, keyValue);
return Success("Successful operation.");
}
[HttpPost]
[HandlerAjaxOnly]
[HandlerAuthorize]
[ValidateAntiForgeryToken]
public ActionResult DeleteForm(string keyValue)
{
maintainApp.DeleteForm(keyValue);
return Success("Delete success.");
}
}
}