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.
491 lines
20 KiB
491 lines
20 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using CK.SCP.Models.Enums;
|
|
using CK.SCP.Models.ScpEntity;
|
|
using CK.SCP.Utils;
|
|
using CK.SCP.Controller;
|
|
using FineUI;
|
|
using SCP.Common;
|
|
using CK.SCP.Models;
|
|
using System.Data;
|
|
using NPOI.Util;
|
|
|
|
namespace SCP.PlanData
|
|
{
|
|
public partial class SCP_PO_CREATE_ASK : PageBase
|
|
{
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
GetV_TB_POData();
|
|
BindDetail();
|
|
SetRoleRule();
|
|
CheckRolesMenu();
|
|
BindDDL_Site();
|
|
}
|
|
}
|
|
private void BindDDL_Site()
|
|
{
|
|
var _ls = ScpCache.ADRESSList.Where(p =>p.SubSite == CurrentUser.UserdSite).ToList();
|
|
DDL_Site.DataSource = _ls;
|
|
DDL_Site.DataBind();
|
|
var name = CurrentUser.Name.ToString();
|
|
var buyer = SCPDB.TB_ADDRESS_BUYER.FirstOrDefault(q => q.Buyer == name);
|
|
if (buyer != null)
|
|
{
|
|
DDL_Site.SelectedIndex = _ls.IndexOf(_ls.FirstOrDefault(q => q.UID == buyer.AddressUID));
|
|
}
|
|
}
|
|
|
|
private void SetRoleRule()
|
|
{
|
|
IsPriceVisible(Grid_V_TB_PO_DETAIL, "价格");
|
|
DDL_ReceivedPort.DataSource = ScpCache.PortList.Where(p => CurrentUser.FactoryList.Contains(p.FACTORY_ID));
|
|
DDL_ReceivedPort.DataBind();
|
|
|
|
}
|
|
private void CheckRolesMenu()
|
|
{
|
|
if (CurrentUser.RoleList.Contains("采购人员") && ((CurrentUser.UserdSite == "CQ01") || (CurrentUser.UserdSite == "CD01")))
|
|
{
|
|
DDL_Site.Hidden = false;
|
|
|
|
}
|
|
else
|
|
{
|
|
TXT_Site.Hidden = false;
|
|
}
|
|
}
|
|
protected void BtnClose_Click(object sender, EventArgs e)
|
|
{
|
|
gp1.Hidden = true;
|
|
}
|
|
protected void btnShow_Click(object sender, EventArgs e)
|
|
{
|
|
gp1.Hidden = false;
|
|
}
|
|
public void SearchV_TB_PO_DETAIL(Action<IQueryable<V_TB_PO_DETAIL>> p_action)
|
|
{
|
|
V_TB_PO_DETAIL _entity = new V_TB_PO_DETAIL();
|
|
_entity.PoBillNum = Request["PoBillNum"];
|
|
SCP_PO_CONTROLLER.Get_V_TB_PO_DETAIL_List(_entity, (_ret) =>
|
|
{
|
|
|
|
if (_ret.State == ReturnStatus.Succeed)
|
|
{
|
|
p_action(_ret.Result);
|
|
}
|
|
});
|
|
|
|
}
|
|
public void GetV_TB_POData()
|
|
|
|
{
|
|
V_TB_PO _entity = new V_TB_PO();
|
|
_entity.PoBillNum = Request["PoBillNum"];
|
|
_entity.UserInSubSite = CurrentUser.SubSiteList;
|
|
|
|
_entity.UserInAddress = CurrentUser.FactoryList;
|
|
//_entity.UserInVendIds = CurrentUser.VenderList;
|
|
SCP_PO_CONTROLLER.Get_V_TB_PO_List(_entity, (_ret) =>
|
|
{
|
|
if (_ret.State == ReturnStatus.Succeed)
|
|
{
|
|
var _result = _ret.Result.FirstOrDefault();
|
|
Session["Order"] = _result;
|
|
this.TXT_PoBillNum.Text = _result.PoBillNum;
|
|
if (_result.ModType == (int)BillModType.Contract)
|
|
{
|
|
this.DP_BeginTime.SelectedDate = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
this.DP_BeginTime.SelectedDate = _result.BeginTime;
|
|
}
|
|
|
|
this.TXT_VendId.Text = _result.VendId;
|
|
this.TXT_Site.Text = _result.Site_Desc;
|
|
this.TXT_State_DESC.Text = _result.State_DESC;
|
|
|
|
this.TXT_VendName.Text = _result.VendName;
|
|
this.txtRemark.Text = _result.Remark;
|
|
}
|
|
});
|
|
}
|
|
public void BindDetail()
|
|
{
|
|
var qadOrder = Session["order"] as V_TB_PO;
|
|
SearchV_TB_PO_DETAIL((ret) =>
|
|
{
|
|
if (!string.IsNullOrEmpty(TextArea_PartCode.Text))
|
|
{
|
|
List<string> _strlist = new List<string>();
|
|
string[] sArray = TextArea_PartCode.Text.Split(',');
|
|
foreach (string y in sArray)
|
|
{
|
|
_strlist.Add(y);
|
|
}
|
|
ret = ret.Where(p => _strlist.Contains(p.PartCode));
|
|
}
|
|
this.Grid_V_TB_PO_DETAIL.RecordCount = ret.Count();
|
|
var list = SortAndPage<V_TB_PO_DETAIL>(ret, Grid_V_TB_PO_DETAIL);
|
|
var _ls = SCP_CONTRACT_CONTROLLER.GET_CONTRACT_PRICE_LIST(SCP_PO_CONTROLLER.LOAD_PO_DETAIL_SUM_ASK(list.ToList()));
|
|
if (qadOrder != null)
|
|
{
|
|
if (qadOrder.ModType == (int)BillModType.Non_Contract)
|
|
{
|
|
_ls.ForEach(p =>
|
|
{
|
|
var _tempQty = (p.TempQty == null) ? 0 : (decimal)p.TempQty;
|
|
if (_tempQty <= p.PlanQty)
|
|
{
|
|
p.PublishQty = p.PlanQty - _tempQty;
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_ls.ForEach(p =>
|
|
{
|
|
p.EndTime = DateTime.Now;
|
|
|
|
});
|
|
|
|
}
|
|
}
|
|
//_ls.ForEach(p => p.EndTime = qadOrder.EndTime);
|
|
|
|
Grid_V_TB_PO_DETAIL.DataSource = _ls;
|
|
Grid_V_TB_PO_DETAIL.DataBind();
|
|
|
|
if (CurrentUser.FactoryList != null && CurrentUser.FactoryList.Count > 0)
|
|
{
|
|
if (CurrentUser.FactoryList.FirstOrDefault() == "CNS")
|
|
{
|
|
if (qadOrder != null)
|
|
{
|
|
if (qadOrder.ModType == (int)BillModType.Non_Contract)
|
|
{
|
|
var _column = Grid_V_TB_PO_DETAIL.FindColumn("PublishQty");
|
|
_column.Hidden = true;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
});
|
|
}
|
|
protected void Grid_V_TB_PO_DETAIL_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
BindDetail();
|
|
}
|
|
protected void ddlGridPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Grid_V_TB_PO_DETAIL.PageSize = Convert.ToInt32(ddlGridPageSize.SelectedValue);
|
|
|
|
BindDetail();
|
|
}
|
|
|
|
|
|
protected void BtnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
BindDetail();
|
|
}
|
|
|
|
|
|
protected void btnRelease_Click(object sender, EventArgs e)
|
|
{
|
|
var qadOrder = Session["order"] as V_TB_PO;
|
|
//qadOrder.ReceivedPort = DDL_PORT.SelectedValue;
|
|
if (DP_BeginTime.SelectedDate == null)
|
|
{
|
|
Alert.Show("要货日期没有填写!");
|
|
return;
|
|
}
|
|
|
|
qadOrder.BeginTime = DP_BeginTime.SelectedDate;
|
|
|
|
|
|
List<string> _lineList = new List<string>();
|
|
if (!string.IsNullOrEmpty(CurrentUser.Name))
|
|
{
|
|
List<V_TB_PO_DETAIL> qadOrderList = new List<V_TB_PO_DETAIL>();
|
|
Dictionary<int, Dictionary<string, object>> modifiedDict = Grid_V_TB_PO_DETAIL.GetModifiedDict();
|
|
//if(modifiedDict.Count>0)
|
|
//{
|
|
for (int i = 0, count = Grid_V_TB_PO_DETAIL.Rows.Count; i < count; i++)
|
|
{
|
|
V_TB_PO_DETAIL _entity = new V_TB_PO_DETAIL();
|
|
object[] rowDataKeys = Grid_V_TB_PO_DETAIL.DataKeys[i];
|
|
_entity.UID = ConvertHelper.To<Int32>(rowDataKeys[0]);
|
|
_entity.PoBillNum = rowDataKeys[1] as string;
|
|
_entity.PoLine = ConvertHelper.To<Int32>(rowDataKeys[2]);
|
|
_entity.PartCode = rowDataKeys[3] as string;
|
|
_entity.PlanQty = ConvertHelper.To<Decimal>(rowDataKeys[4]);
|
|
_entity.ShippedQty = ConvertHelper.To<Decimal>(rowDataKeys[5]);
|
|
_entity.ReceivedQty = ConvertHelper.To<Decimal>(rowDataKeys[6]);
|
|
_entity.RejectQty = rowDataKeys[7] as string;
|
|
_entity.BeginTime = ConvertHelper.To<DateTime?>(rowDataKeys[8]);
|
|
_entity.EndTime = ConvertHelper.To<DateTime?>(rowDataKeys[9]);
|
|
_entity.PoUnit = rowDataKeys[10] as string;
|
|
_entity.LocUnit = rowDataKeys[11] as string;
|
|
_entity.Price = ConvertHelper.To<Decimal>(rowDataKeys[12]);
|
|
_entity.Currency = rowDataKeys[13] as string;
|
|
_entity.PackQty = ConvertHelper.To<Decimal>(rowDataKeys[14]);
|
|
_entity.UnConv = ConvertHelper.To<Decimal>(rowDataKeys[15]);
|
|
_entity.DockCode = rowDataKeys[16] as string;
|
|
_entity.State = ConvertHelper.To<Int32>(rowDataKeys[17]);
|
|
|
|
_entity.Remark = rowDataKeys[18] as string;
|
|
_entity.CreateTime = ConvertHelper.To<DateTime>(rowDataKeys[19]);
|
|
_entity.CreateUser = rowDataKeys[20] as string;
|
|
_entity.UpdateTime = ConvertHelper.To<DateTime?>(rowDataKeys[21]);
|
|
_entity.UpdateUser = rowDataKeys[22] as string;
|
|
_entity.UpdateInfo = rowDataKeys[23] as string;
|
|
_entity.IsDeleted = ConvertHelper.To<Boolean>(rowDataKeys[24]);
|
|
_entity.PartDesc1 = rowDataKeys[25] as string;
|
|
_entity.CurrencyDesc = rowDataKeys[26] as string;
|
|
_entity.ErpBillNum = rowDataKeys[27] as string;
|
|
_entity.ModType = ConvertHelper.To<int>(rowDataKeys[28]);
|
|
_entity.Contacter = rowDataKeys[29] as string;
|
|
_entity.Site = rowDataKeys[30] as string;
|
|
_entity.Buyer = rowDataKeys[31] as string;
|
|
_entity.BuyerPhone = rowDataKeys[32] as string;
|
|
_entity.VendName = rowDataKeys[33] as string;
|
|
_entity.PartDesc2 = rowDataKeys[34] as string;
|
|
_entity.TempQty = ConvertHelper.To<Decimal>(rowDataKeys[35]);
|
|
_entity.BeginTime = DP_BeginTime.SelectedDate;
|
|
_entity.PartState = rowDataKeys[38] as string;
|
|
if (qadOrder.ModType == (int)BillModType.Non_Contract)
|
|
{
|
|
_entity.PublishQty = ConvertHelper.To<Decimal>(rowDataKeys[36]);
|
|
|
|
}
|
|
_entity.ReceivedPort = rowDataKeys[37] as string;
|
|
_entity.DockCode = rowDataKeys[37] as string;
|
|
|
|
if (modifiedDict.Keys.Contains(i))
|
|
{
|
|
var modifyValue = modifiedDict[i];
|
|
var Remark = modifyValue.Keys.Contains("Remark") ? modifyValue["Remark"] : _entity.Remark;
|
|
if (Remark != null)
|
|
{
|
|
_entity.Remark = Remark.ToString();
|
|
}
|
|
|
|
if (modifyValue.Keys.Contains("PublishQty"))
|
|
{
|
|
var _publishQty = modifyValue["PublishQty"];
|
|
decimal _out = 0;
|
|
bool _result = decimal.TryParse(_publishQty.ToString(), out _out);
|
|
if (_result == false)
|
|
{
|
|
_lineList.Add(string.Format("产品名称:{0}订单数量:{1}", _entity.PartDesc1, _publishQty.ToString()));
|
|
}
|
|
if (_out == 0)
|
|
{
|
|
continue;
|
|
}
|
|
_entity.PublishQty = _out;
|
|
}
|
|
if (modifyValue.Keys.Contains("ReceivedPort"))
|
|
{
|
|
_entity.ReceivedPort = modifyValue["ReceivedPort"].ToString();
|
|
_entity.DockCode = modifyValue["ReceivedPort"].ToString();
|
|
}
|
|
|
|
if (modifyValue.Keys.Contains("Price"))
|
|
{
|
|
_entity.Price = ConvertHelper.To<decimal>(modifyValue["Price"]);
|
|
|
|
}
|
|
if (modifyValue.Keys.Contains("EndTime"))
|
|
{
|
|
var _endTime = modifyValue["EndTime"];
|
|
if (_endTime == null)
|
|
{
|
|
_lineList.Add("要货时间未填写!");
|
|
return;
|
|
}
|
|
DateTime _date = DateTime.Now;
|
|
bool _result1 = DateTime.TryParse(_endTime.ToString(), out _date);
|
|
if (_result1 == false)
|
|
{
|
|
_lineList.Add(string.Format("产品名称:{0}截至日期:{1}", _entity.PartDesc1, _endTime.ToString()));
|
|
}
|
|
|
|
else
|
|
{
|
|
_entity.EndTime = _date;
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
if (_entity.EndTime == null)
|
|
{
|
|
Alert.Show("到货时间不能为空!");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if (DatePicker2.SelectedDate != null)
|
|
{
|
|
_entity.EndTime = DatePicker2.SelectedDate;
|
|
}
|
|
if (_entity.PublishQty != null && _entity.PublishQty > 0)
|
|
{
|
|
qadOrderList.Add(_entity);
|
|
}
|
|
}
|
|
if (qadOrder != null && qadOrderList.Count > 0)
|
|
{
|
|
if (qadOrder.ModType == 2)
|
|
{
|
|
qadOrderList.ForEach(p =>
|
|
{
|
|
if (p.PublishQty + (decimal)p.TempQty > (decimal)p.PlanQty)
|
|
{
|
|
_lineList.Add(p.PartCode + p.PartDesc1 + "填写数量大于订单数量");
|
|
}
|
|
});
|
|
}
|
|
qadOrderList.ForEach(p =>
|
|
{
|
|
if (p.EndTime == null)
|
|
{
|
|
_lineList.Add("(" + p.PartCode + ")" + p.PartDesc1 + "要货数量或到货日期填写错误!");
|
|
|
|
}
|
|
if (p.PartState.ToUpper() == "SP")
|
|
{
|
|
_lineList.Add("(" + p.PartCode + ")" + "状态为SP不可以生成要货看板!");
|
|
}
|
|
});
|
|
if (_lineList.Count > 0)
|
|
{
|
|
Alert alert = new Alert();
|
|
alert.Message = string.Join("<br>", _lineList.ToArray());
|
|
alert.Title = "明细订单录入提示";
|
|
alert.MessageBoxIcon = (MessageBoxIcon)Enum.Parse(typeof(MessageBoxIcon), "Error", true);
|
|
alert.Target = (Target)Enum.Parse(typeof(Target), "Self", true);
|
|
alert.Show();
|
|
return;
|
|
|
|
}
|
|
|
|
string str = string.Empty;
|
|
if (!string.IsNullOrEmpty(CurrentUser.HomePhone))
|
|
{
|
|
str += CurrentUser.HomePhone;
|
|
}
|
|
if (!string.IsNullOrEmpty(CurrentUser.CellPhone))
|
|
{
|
|
if (!string.IsNullOrEmpty(str))
|
|
{
|
|
str = str + ";" + CurrentUser.CellPhone;
|
|
}
|
|
else
|
|
{
|
|
str = CurrentUser.CellPhone;
|
|
}
|
|
}
|
|
|
|
if (CurrentUser.FactoryList != null && CurrentUser.FactoryList.Count > 0)
|
|
{
|
|
if (CurrentUser.FactoryList.FirstOrDefault() == "CNS")
|
|
{
|
|
if (qadOrder.ModType == 2)
|
|
{
|
|
int i = 0;
|
|
qadOrderList.ForEach(p =>
|
|
{
|
|
if (p.PlanQty != p.PublishQty)
|
|
{
|
|
i = 1;
|
|
}
|
|
});
|
|
if (i == 1)
|
|
{
|
|
Alert.Show("离散单不能修改数量!");
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
var _ls = qadOrderList.Where(itm => string.IsNullOrEmpty(itm.PartDesc1) && string.IsNullOrEmpty(itm.PartDesc2)).ToList();
|
|
|
|
if (_ls.Count > 0)
|
|
{
|
|
string _str = "不能生成要货看板原因\n\r";
|
|
_str = _str + string.Join("\n\r", _ls.Select(itm => itm.PartCode).ToArray());
|
|
_str = _str + "零件不存在!";
|
|
Alert.Show(_str);
|
|
return;
|
|
}
|
|
if (CurrentUser.FactoryList != null && CurrentUser.FactoryList.Count > 0)
|
|
{
|
|
if (CurrentUser.FactoryList.FirstOrDefault() == "CQBMPT")
|
|
{
|
|
qadOrder.Remark = "";
|
|
qadOrderList.ForEach(p => { p.Remark = string.Empty; });
|
|
}
|
|
}
|
|
string Ssite = "";
|
|
if ((CurrentUser.UserdSite == "CQ01") || (CurrentUser.UserdSite == "CD01"))
|
|
{
|
|
Ssite = DDL_Site.SelectedValue;
|
|
}
|
|
string Stremark = txtRemark.Text;
|
|
// 判断 价格是否是财务审核状态
|
|
var errorlist = SCP_PO_CONTROLLER.GetPriceError(qadOrderList, qadOrder);
|
|
if (errorlist.Count()>0)
|
|
{
|
|
Alert.Show(string.Join("<br>", errorlist.ToArray()));
|
|
return;
|
|
}
|
|
var ret = SCP_PO_CONTROLLER.Save_PO_TO_ASK_CQ(qadOrder, qadOrderList, CurrentUser.ChineseName, str, CurrentUser.Name, Stremark, Ssite);
|
|
if (ret.Result == true)
|
|
{
|
|
if (ret.MessageList.Count > 0)
|
|
{
|
|
Alert.Show(string.Join("<br>", ret.MessageList.ToArray()));
|
|
return;
|
|
}
|
|
GetV_TB_POData();
|
|
BindDetail();
|
|
Alert.Show("生成要货看板成功!");
|
|
}
|
|
}
|
|
}
|
|
//}
|
|
}
|
|
|
|
|
|
|
|
protected void Grid_V_TB_PO_DETAIL_RowDataBound(object sender, GridRowEventArgs e)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|
{
|
|
BindDetail();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|