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.
 
 
 
 
 

482 lines
21 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CK.SCP.Models;
using CK.SCP.Models.ScpEntity;
using CK.SCP.Utils;
using CK.SCP.Controller;
using FineUI;
using SCP.Code;
using CK.SCP.Models.Enums;
namespace SCP.SupplierData
{
public partial class SCP_ASN_CREATE : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetV_TB_POData();
if (Request.QueryString["State"] != null)
{
if (Request.QueryString["State"] == "1")
{
BindDetail(true);
}
else
{
BindDetail();
}
}
else
{
BindDetail();
}
SetRoleRule();
TranslatorAgents(Toolbar1);
TranslatorAgent(Grid_V_TB_ASK_DETAIL);
TranslatorAgents(FormRow_1);
TranslatorAgents(FormRow_2);
TranslatorAgents(FormRow_3);
}
}
private void SetRoleRule()
{
IsPriceVisible(Grid_V_TB_ASK_DETAIL, "价格");
}
public void SearchV_TB_ASK_DETAILData(Action<IQueryable<V_TB_ASK_DETAIL>> p_action)
{
V_TB_ASK_DETAIL _entity = new V_TB_ASK_DETAIL();
_entity.AskBillNum = Request["AskBillNum"];
SCP_ASK_CONTROLLER.Get_V_TB_ASK_DETAIL_List(_entity, (_ret) => {
if (_ret.State == ReturnStatus.Succeed)
{
p_action(_ret.Result);
}
});
}
public void GetV_TB_POData()
{
V_TB_ASK _entity = new V_TB_ASK();
_entity.AskBillNum = Request["AskBillNum"];
_entity.UserInAddress = CurrentUser.FactoryList;
_entity.UserInVendIds = CurrentUser.VenderList;
SCP_ASK_CONTROLLER.Get_V_TB_ASK_List(_entity, (_ret) =>
{
if (_ret.State == ReturnStatus.Succeed)
{
var _result = _ret.Result.FirstOrDefault();
Session["Ask"] = _result;
this.TXT_AskBillNum.Text = _result.AskBillNum;
this.TXT_State.Text = _result.State.ToString();
this.TXT_Site.Text = _result.Site_Desc;
this.TXT_State_Desc.Text = _result.State_DESC;
this.TXT_VendName.Text = _result.VendName;
this.TXT_Remark.Text = _result.Remark;
this.TXT_SubSite.Text = _result.SubSite;
this.TXT_Extend1.Text = _result.Extend1;
this.TXT_Extend2.Text = _result.Extend2;
this.TXT_Extend3.Text = _result.Extend3;
DP_ShipTime.SelectedDate = DateTime.Now;
DDL_PORT.DataSource = ScpCache.PortList.Where(p => CurrentUser.FactoryList.Contains(p.FACTORY_ID));
DDL_PORT.DataBind();
DDL_PORT.SelectedValue = _result.ReceivedPort;
#region 按钮控制
#endregion
}
});
}
public void BindDetail(bool p_state=false)
{
SearchV_TB_ASK_DETAILData((ret) => {
Grid_V_TB_ASK_DETAIL.RecordCount = ret.Count();
var list = SortAndPage<V_TB_ASK_DETAIL>(ret, Grid_V_TB_ASK_DETAIL);
var _ls = SCP_ASK_CONTROLLER.Get_CAN_SHIPQTY(list.ToList());
var _notifyList = new List<string>();
_ls.ForEach(p =>
{
if (p.PackQty == 1 || p.PackQty == 0)
{
_notifyList.Add(string.Format("请注意零件编号{0}行号{1}标包数为1是否填写正确,如果不正确请修改", p.PartCode, p.PoLine));
}
p.Batch = DateTime.Now.ToString("yyMMdd");
p.ProduceDate = DateTime.Now;
if (p_state == true)
{
p.TempQty = p.CanQty;
}
else
{
p.TempQty = 0;
}
}
);
Grid_V_TB_ASK_DETAIL.DataSource = _ls;
Grid_V_TB_ASK_DETAIL.DataBind();
if (_notifyList.Count > 0)
{
Alert.Show(string.Join("<br>", _notifyList));
}
});
}
private void IsBatch(string batch)
{
try
{
batch = batch.Trim();
if (batch.Length != 6)
{
Alert.Show($"批次号【{batch}】必需是6位,格式为 YYMMDD");
}
int y = Convert.ToInt32(batch.Substring(0, 2));
int m = Convert.ToInt32(batch.Substring(2, 2));
int d = Convert.ToInt32(batch.Substring(4, 2));
var date = new DateTime(y, m, d);
if (date.Date > DateTime.Now.Date)
{
Alert.Show($"批次号【{batch}】错误,不应大于发货日期");
}
}
catch
{
Alert.Show($"批次号【{batch}】错误,批次必需是 YYMMDD ");
}
}
List<V_TB_ASK_DETAIL> _askDetaillist = new List<V_TB_ASK_DETAIL>();
protected void btnCreate_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(TXT_AskBillNum.Text) || string.IsNullOrEmpty(TXT_ShipUser.Text) || DP_ReceiveTime.SelectedDate==null || DP_ShipTime.SelectedDate==null)
{
PageContext.RegisterStartupScript(Alert.GetShowInTopReference("要货看板单据编号、发货人、到货时间、收货时间不能为空"));
return;
}
var _model=Session["Ask"] as V_TB_ASK;
if (_model == null)
{
PageContext.RegisterStartupScript(Alert.GetShowInTopReference("编辑的数据不正确"));
return;
}
if (_model.State != (int)AskState.Confirm && _model.State != (int)AskState.Receive && _model.State != (int)AskState.Ship)
{
Alert.Show("要货看板必须为确认后状态");
return;
}
Dictionary<int, Dictionary<string, object>> modifiedDict = Grid_V_TB_ASK_DETAIL.GetModifiedDict();
for (int i = 0, count = Grid_V_TB_ASK_DETAIL.Rows.Count; i < count; i++)
{
V_TB_ASK_DETAIL _entity = new V_TB_ASK_DETAIL();
object[] rowDataKeys = Grid_V_TB_ASK_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.ShippedQty = ConvertHelper.To<Decimal>(rowDataKeys[4]);
_entity.ReceivedQty = ConvertHelper.To<Decimal>(rowDataKeys[5]);
_entity.BeginTime = ConvertHelper.To<DateTime>(rowDataKeys[6]);
_entity.EndTime = ConvertHelper.To<DateTime>(rowDataKeys[7]);
_entity.PoUnit = rowDataKeys[8] as string;
_entity.LocUnit = rowDataKeys[9] as string;
_entity.Price = ConvertHelper.To<Decimal>(rowDataKeys[10]);
_entity.Currency = rowDataKeys[11] as string;
_entity.PackQty = ConvertHelper.To<Decimal>(rowDataKeys[12]);
_entity.UnConv = ConvertHelper.To<Decimal>(rowDataKeys[13]);
_entity.DockCode = rowDataKeys[14] as string;
_entity.State = ConvertHelper.To<Int32>(rowDataKeys[15]);
_entity.Remark = rowDataKeys[21] as string; //把用户信息传给备注
_entity.CreateTime = ConvertHelper.To<DateTime>(rowDataKeys[17]);
_entity.CreateUser = rowDataKeys[18] as string;
_entity.UpdateTime = ConvertHelper.To<DateTime?>(rowDataKeys[19]);
_entity.UpdateUser = rowDataKeys[20] as string;
_entity.UpdateInfo = rowDataKeys[21] as string;
_entity.IsDeleted = ConvertHelper.To<Boolean>(rowDataKeys[22]);
_entity.PartDesc1 = rowDataKeys[23] as string;
_entity.CurrencyDesc = rowDataKeys[24] as string;
_entity.Site = rowDataKeys[25] as string;
_entity.VendName = rowDataKeys[26] as string;
_entity.PartDesc2 = rowDataKeys[27] as string;
_entity.AskBillNum = rowDataKeys[28] as string;
_entity.AskQty = ConvertHelper.To<Decimal>(rowDataKeys[29]);
_entity.TempQty = ConvertHelper.To<decimal>(rowDataKeys[30]);
_entity.ReceivedPort = rowDataKeys[31] as string;
_entity.ReduceQty = ConvertHelper.To<decimal>(rowDataKeys[33]);
_entity.ValidityDays = ConvertHelper.To<int>(rowDataKeys[34]);
_entity.Batch = ConvertHelper.To<string>(rowDataKeys[35]);
_entity.ProduceDate = DateTime.Now;
if (Convert.ToDecimal(_entity.AskQty) == 0)
{
PageContext.RegisterStartupScript(Alert.GetShowInTopReference("要货看板数量不能为 0"));
return;
}
if (modifiedDict.Keys.Contains(i))
{
var modifyValue = modifiedDict[i];
var _Qty1 = modifyValue.Keys.Contains("TempQty") ? modifyValue["TempQty"] : _entity.TempQty;
var _Batch1 = modifyValue.Keys.Contains("Batch") ? modifyValue["Batch"] : _entity.Batch;
var _VendBatch = modifyValue.Keys.Contains("VendBatch") ? modifyValue["VendBatch"].ToString() : _entity.Batch;
var _ProduceDate = modifyValue.Keys.Contains("ProduceDate") ? modifyValue["ProduceDate"].ToString() : _entity.ProduceDate.ToString();
if (modifyValue.Keys.Contains("SubSite"))
{
_entity.SubSite = modifyValue["SubSite"].ToString();
}
if (modifyValue.Keys.Contains("Extend1"))
{
_entity.Extend1 = modifyValue["Extend1"].ToString();
}
if (modifyValue.Keys.Contains("Extend2"))
{
_entity.Extend2 = modifyValue["Extend2"].ToString();
}
if (modifyValue.Keys.Contains("Extend3"))
{
_entity.Extend3 = modifyValue["Extend3"].ToString();
}
if (string.IsNullOrEmpty(_VendBatch) || string.IsNullOrEmpty(_ProduceDate))
{
Alert.Show("供应商批次和生产日期不能为空!");
return;
}
object _PackQty = 0;
if (modifyValue.Keys.Contains("PackQty"))
{
_PackQty = modifyValue["PackQty"];
}
else
{
_PackQty = _entity.PackQty;
}
decimal QtyAll = 0;
if (ConvertHelper.To<decimal>(_Qty1) > 0)
{
V_TB_ASK_DETAIL _detail = ConvertHelper.GetObjectClone<V_TB_ASK_DETAIL>(_entity);
var number = ConvertHelper.To<decimal>(_Qty1);
QtyAll += number;
if (QtyAll > 0)
{
DateTime _d = DateTime.Now;
if (_ProduceDate == null && DateTime.TryParse(_ProduceDate.ToString(), out _d) == false)
{
Alert.Show("日期填写错误!");
return;
}
DateTime dt = DateTime.Parse(_ProduceDate.ToString());
_detail.Batch = GetBatch(dt); //_Batch1.ToString().Trim();
_detail.TempQty = number;
_detail.PackQty = ConvertHelper.To<decimal>(_PackQty);
_detail.VendBatch = _VendBatch.ToString();
_detail.ProduceDate = dt;
_askDetaillist.Add(_detail);
}
}
if (modifyValue.Keys.Contains("Qty2") && modifyValue.Keys.Contains("Batch2"))
{
var _Qty2 = modifyValue["Qty2"];
var _Batch2 = modifyValue["Batch2"];
if (_Batch2.ToString().Trim() != "" && ConvertHelper.To<decimal>(_Qty2) > 0)
{
V_TB_ASK_DETAIL _detail = ConvertHelper.GetObjectClone<V_TB_ASK_DETAIL>(_entity);
IsBatch(_Batch2.ToString().Trim());
var number = ConvertHelper.To<decimal>(_Qty2);
QtyAll += number;
if (QtyAll > 0)
{
_detail.Batch = _Batch2.ToString().Trim();
_detail.TempQty = number;
_detail.PackQty = ConvertHelper.To<decimal>(_PackQty);
_detail.VendBatch = _VendBatch.ToString();
_detail.ProduceDate = DateTime.Parse(_ProduceDate.ToString());
_askDetaillist.Add(_detail);
}
}
}
if (modifyValue.Keys.Contains("Qty3") && modifyValue.Keys.Contains("Batch3"))
{
var _Qty3 = modifyValue["Qty3"];
var _Batch3 = modifyValue["Batch3"];
if (_Batch3.ToString().Trim() != "" && ConvertHelper.To<decimal>(_Qty3) > 0)
{
V_TB_ASK_DETAIL _detail = ConvertHelper.GetObjectClone<V_TB_ASK_DETAIL>(_entity);
IsBatch(_Batch3.ToString().Trim());
var number = ConvertHelper.To<decimal>(_Qty3);
QtyAll += number;
if (QtyAll > 0)
{
_detail.Batch = _Batch3.ToString().Trim();
_detail.TempQty = number;
_detail.PackQty = ConvertHelper.To<decimal>(_PackQty);
_detail.VendBatch = _VendBatch.ToString();
_detail.ProduceDate = DateTime.Parse(_ProduceDate.ToString());
_askDetaillist.Add(_detail);
}
}
}
if (QtyAll > _entity.AskQty - _entity.ShippedQty - _entity.ReduceQty)
{
PageContext.RegisterStartupScript(Alert.GetShowInTopReference(_entity.PartCode + "发货数量>可发数量-减产数量"));
return;
}
_entity.ShippedQty = _entity.ShippedQty + QtyAll;
}
else
{
if (_entity.TempQty > 0)
{
V_TB_ASK_DETAIL _detail = ConvertHelper.GetObjectClone<V_TB_ASK_DETAIL>(_entity);
_entity.Batch = DateTime.Now.ToString("yyMMdd");
_entity.VendBatch = DateTime.Now.ToString("yyMMdd");
_entity.ShippedQty = _entity.TempQty;
_entity.ProduceDate = DateTime.Now;
_entity.PackQty = _entity.PackQty;
_askDetaillist.Add(_detail);
}
}
}
_model.ShipTime = DP_ShipTime.SelectedDate;
_model.ShipUser = TXT_ShipUser.Text;
_model.ReceiveTime = DP_ReceiveTime.SelectedDate;
_model.ReceiveUser = _model.Buyer;
List<string> _ls = new List<string>();
if (_askDetaillist.Count == 0)
{
Alert.Show("发货数量未填写");
return;
}
if (CurrentUser.FactoryList.Count > 0)
{
if (CurrentUser.FactoryList.FirstOrDefault()== "CNS" || CurrentUser.FactoryList.FirstOrDefault() == "BJCIAI")
{
_askDetaillist.ForEach(p =>
{
p.VendBatch = p.Batch;
});
}
}
var ret=SCP_ASK_CONTROLLER.Save_ASK_TO_ASN(_model, _askDetaillist, TXT_PlateNumber.Text, CurrentUser.ChineseName ,CurrentUser.CellPhone);
if (ret.State == ReturnStatus.Succeed)
{
Alert.Show("生成发货单成功!");
GetV_TB_POData();
BindDetail();
}
}
private string GetBatch(DateTime dt)
{
string strResult = "";
if (dt != null)
{
string strYear = dt.Year.ToString().Substring(2, 2);
string strMonth = "";
int iMonth = dt.Month;
if (iMonth.ToString().Length == 1)
{
strMonth = "0" + iMonth.ToString();
}
else
{
strMonth = iMonth.ToString();
}
string strDay = dt.Day.ToString();
if (strDay.Length == 1)
{
strDay = "0" + strDay;
}
strResult = strYear + strMonth + strDay;
}
return strResult;
}
protected void Grid_V_TB_ASK_DETAIL_PageIndexChange(object sender, GridPageEventArgs e)
{
BindDetail();
}
protected void ddlGridPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid_V_TB_ASK_DETAIL.PageSize = Convert.ToInt32(ddlGridPageSize.SelectedValue);
BindDetail();
}
protected void Grid_V_TB_ASK_DETAIL_RowDataBound(object sender, GridRowEventArgs e)
{
//GridRow row = Grid_V_TB_ASK_DETAIL.Rows[e.RowIndex];
//object[] rowDataKeys = Grid_V_TB_ASK_DETAIL.DataKeys[e.RowIndex];
////var TXT_PackQty = (NumberBox)row.FindControl("TXT_PackQty");
////var txtBatch1 = (System.Web.UI.WebControls.TextBox)row.FindControl("txtBatch1");
////var txtBatch2 = (System.Web.UI.WebControls.TextBox)row.FindControl("txtBatch2");
////var txtBatch3 = (System.Web.UI.WebControls.TextBox)row.FindControl("txtBatch3");
////var txtQty1 = (System.Web.UI.WebControls.TextBox)row.FindControl("txtQty1");
////var txtQty2 = (System.Web.UI.WebControls.TextBox)row.FindControl("txtQty2");
////var txtQty3 = (System.Web.UI.WebControls.TextBox)row.FindControl("txtQty3");
//var _shippedQty = ConvertHelper.To<Decimal>(rowDataKeys[4]);
//var _askQty = ConvertHelper.To<Decimal>(rowDataKeys[29]);
//var a = row.TemplateContainers;
//if (_shippedQty >= _askQty)
//{
// //foreach (GridColumn column in Grid_V_TB_ASK_DETAIL.Columns)
// //{
// // e
// // e.CellCssClasses[column.ColumnIndex] = "f-grid-cell-uneditable";
// //}
//}
//else
//{
// //txtQty1.Text = "0";
// //txtBatch1.Text = DateTime.Now.ToString("yyMMdd");
//}
}
protected void btnAll_Click(object sender, EventArgs e)
{
BindDetail(true);
}
//protected void btnSet_Click(object sender, EventArgs e)
//{
//}
}
}