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.
 
 
 
 
 

513 lines
21 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.Code;
using CK.SCP.Models;
using System.Text;
namespace SCP.PlanData
{
public partial class SCP_ASK_DETAIL : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!string.IsNullOrEmpty(Request["AskBillNum"].Trim()))
{
F_PO_DETAIL.Hidden = false;
GetV_TB_POData();
BindDetail();
SetRoleRule();
}
else
{
F_PO_DETAIL.Hidden = true;
SearchV_TB_ASK_DETAIL_VIEW((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_CONTRACT_CONTROLLER.GET_CONTRACT_PRICE_LIST(list.ToList());
Grid_V_TB_ASK_DETAIL.DataSource = SCP_ASK_CONTROLLER.Get_CAN_SHIPQTY(_ls); ;
Grid_V_TB_ASK_DETAIL.DataBind();
});
}
}
}
private void SetRoleRule()
{
IsPriceVisible(Grid_V_TB_ASK_DETAIL, "单价");
}
private void BindResource()
{
BTN_refresh.Text = GetNameByKey(BTN_refresh.Text);
this.btnCompleteForce.Text = GetNameByKey(btnCompleteForce.Text);
//this.btnConfirm.Text = GetNameByKey(this.btnConfirm.Text);
this.btnReject.Text = GetNameByKey(this.btnReject.Text);
//this.btnRelease.Text = GetNameByKey(this.btnRelease.Text);
this.BTN_SAVE.Text = GetNameByKey(this.BTN_SAVE.Text);
this.btnCompleteForce.Text = GetNameByKey(this.btnCompleteForce.Text);
txtRemark.Label = GetNameByKey(txtRemark.Label);
TXT_PoBillNum.Label = GetNameByKey(TXT_PoBillNum.Label);
TXT_Site.Label = GetNameByKey(TXT_Site.Label);
TXT_State_DESC.Label = GetNameByKey(TXT_State_DESC.Label);
TXT_VendName.Label = GetNameByKey(TXT_VendName.Label);
foreach (var itm in Grid_V_TB_ASK_DETAIL.Columns)
{
GetNameByKey(itm.HeaderText);
}
}
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.UserInAddress = CurrentUser.FactoryList;
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();
if (_result != null)
{
Session["Ask"] = _result;
this.TXT_PoBillNum.Text = _result.PoBillNum;
this.TXT_Site.Text = _result.Site_Desc;
this.TXT_State_DESC.Text = _result.State_DESC;
TXT_ModType.Text = _result.ModType.ToString();
TXT_State.Text = _result.State == null ? string.Empty : _result.State.Value.ToString();
this.TXT_VendName.Text = _result.VendName;
this.txtRemark.Text = _result.Remark;
TextTotal.Text = _result.Total.ToString();
DP_BeginTime.SelectedDate = _result.BeginTime;
TXT_VendId.Text = _result.VendId;
//DDL_PORT.DataSource = ScpCache.PortList.Where(p => CurrentUser.FactoryList.Contains(p.FACTORY_ID));
//DDL_PORT.DataBind();
//DDL_PORT.SelectedValue = _result.ReceivedPort;
#region 按钮控制
//新建
if (_result.State == (int)AskState.New)
{
// btnRelease.Hidden = false;
// btnReleaseCancel.Hidden = true;
btnCompleteForce.Hidden = true;
btnReject.Hidden = false;
BTN_SAVE.Hidden = false;
btnReduce.Hidden = true;
btnDeleted.Hidden = false;
btnModifyDate.Hidden = false;
}
//发布
if (_result.State == (int)AskState.Release)
{
// btnRelease.Hidden = true;
// btnReleaseCancel.Hidden = false;
btnCompleteForce.Hidden = true;
btnReject.Hidden = false;
BTN_SAVE.Hidden = true;
btnReduce.Hidden = true;
if (_result.ModType == (int)BillModType.Contract)
{
btnReduce.Hidden = false;
}
// btnConfirm.Hidden = false;
}
//确认
if (_result.State == (int)AskState.Confirm)
{
// btnRelease.Hidden = true;
// btnReleaseCancel.Hidden = true;
BTN_SAVE.Hidden = true;
btnReject.Hidden = true;
btnReduce.Hidden = true;
if (_result.ModType == (int)BillModType.Contract)
{
btnReduce.Hidden = false;
}
}
//作废
if (_result.State == (int)AskState.Reject)
{
// btnRelease.Hidden = true;
// btnReleaseCancel.Hidden = true;
btnReject.Hidden = true;
btnCompleteForce.Hidden = true;
btnReduce.Hidden = true;
// btnConfirm.Hidden = true;
}
if (_result.State == (int)AskState.Ship)
{
// btnRelease.Hidden = true;
// btnReleaseCancel.Hidden = true;
btnReject.Hidden = true;
if (_result.ModType == (int)BillModType.Contract)
{
btnReduce.Hidden = false;
}
BTN_SAVE.Hidden = true;
}
#endregion
}
else
{
btnCompleteForce.Hidden = true;
btnReject.Hidden = true;
BTN_SAVE.Hidden = true;
btnReduce.Hidden = true;
btnDeleted.Hidden = true;
btnModifyDate.Hidden = true;
BTN_refresh.Hidden = true;
}
}
});
}
public void BindDetail()
{
SearchV_TB_ASK_DETAILData((ret) =>
{
var _str= Request["AskBillNum"];
var _list=_str.Split(',').ToList();
ret = ret.Where(p => _list.Contains(p.AskBillNum));
Grid_V_TB_ASK_DETAIL.RecordCount = ret.Count();
var list = SortAndPage<V_TB_ASK_DETAIL>(ret, Grid_V_TB_ASK_DETAIL);
var _ls = SCP_CONTRACT_CONTROLLER.GET_CONTRACT_PRICE_LIST(list.ToList());
Grid_V_TB_ASK_DETAIL.DataSource = SCP_ASK_CONTROLLER.Get_CAN_SHIPQTY(_ls);
Grid_V_TB_ASK_DETAIL.DataBind();
});
}
protected void btnOutput_Click(object sender, EventArgs e)
{
}
//protected void btnConfirm_Click(object sender, EventArgs e)
//{
// SET_PO_STATE("供应商确认成功!", AskState.Confirm);
//}
protected void btnRelease_Click(object sender, EventArgs e)
{
SET_PO_STATE("发布成功!", AskState.Release);
}
protected void btnReleaseCancel_Click(object sender, EventArgs e)
{
SET_PO_STATE("取消发布成功!", AskState.New);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
protected void btnCompleteForce_Click(object sender, EventArgs e)
{
SET_PO_STATE("强制归档成功!", AskState.CompleteForce);
}
protected void btnReject_Click(object sender, EventArgs e)
{
SET_PO_STATE("作废成功!", AskState.Reject);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
private void SET_PO_STATE(string p_msg, AskState p_state)
{
if (Session["Ask"] != null)
{
var _ask = Session["Ask"] as V_TB_ASK;
string site = CurrentUser.FactoryList.FirstOrDefault();
var ret = SCP_ASK_CONTROLLER.Save_TB_ASK_STATE_BMPT(new List<string>() { _ask.AskBillNum }, p_state, site);
if (ret.State == ReturnStatus.Succeed)
{
switch (p_state)
{
case AskState.Release:
if (CurrentUser.ConfigList.ContainsKey("供应商邮件"))
{
if (CurrentUser.FactoryList != null && CurrentUser.FactoryList.Count > 0)
{
SCP.Common.MailManager.SendMail(_ask.VendId, string.Format("发布了新的要货看板编号{0}", _ask.AskBillNum), string.Format("新的要货单信息{0}", _ask.AskBillNum), CurrentUser.FactoryList.FirstOrDefault());
}
}
Alert.Show(p_msg);
GetV_TB_POData();
BindDetail();
break;
case AskState.Receive:
//SCP.Common.MailManager.SendMail(_ask.VendId, "", "");
break;
case AskState.New:
break;
case AskState.Ship:
// SCP.Common.MailManager.SendMail(_ask.VendId, "", "");
break;
case AskState.Confirm:
break;
case AskState.CompleteForce:
if (CurrentUser.ConfigList.ContainsKey("供应商邮件"))
{
if (CurrentUser.FactoryList != null && CurrentUser.FactoryList.Count > 0)
{
SCP.Common.MailManager.SendMail(_ask.VendId, string.Format("强制归档了的要货看板,要货看板编号{0}", _ask.AskBillNum), string.Format("新的要货单信息{0}", _ask.AskBillNum), CurrentUser.FactoryList.FirstOrDefault());
}
}
Alert.Show(p_msg);
GetV_TB_POData();
BindDetail();
break;
case AskState.Reject:
break;
default:
break;
}
}
else
{
Alert.Show(ret.Message);
}
}
}
protected void Grid_V_TB_ASK_DETAIL_PageIndexChange(object sender, GridPageEventArgs e)
{
BindDetail();
}
protected void BTN_SAVE_Click(object sender, EventArgs e)
{
List<TB_ASK_DETAIL> _list = new List<TB_ASK_DETAIL>();
for (int i = 0, count = Grid_V_TB_ASK_DETAIL.Rows.Count; i < count; i++)
{
GridRow row = Grid_V_TB_ASK_DETAIL.Rows[i];
TB_ASK_DETAIL _entity = new TB_ASK_DETAIL();
object[] rowDataKeys = Grid_V_TB_ASK_DETAIL.DataKeys[i];
_entity.UID = ConvertHelper.To<Int32>(rowDataKeys[0]);
System.Web.UI.WebControls.TextBox _txt = (System.Web.UI.WebControls.TextBox)row.FindControl("NB_PublishNum");
if (string.IsNullOrEmpty(_txt.Text))
{
_txt.Text = "0";
}
_entity.AskQty = decimal.Parse(_txt.Text);
if (_entity.AskQty > 0)
{
_list.Add(_entity);
}
}
if (_list.Count > 0)
{
var _first = _list.FirstOrDefault();
if (_first.State != (int)AskState.New)
{
Alert.Show("不是要货看板【新建】状态,不能保存信息!");
}
}
var ret = SCP_ASK_CONTROLLER.Save_TB_ASK_DETAIL(_list, AskState.New);
if (ret.State == ReturnStatus.Succeed)
{
var list = ret.Result;
Alert.Show("保存要货看板成功!");
GetV_TB_POData();
BindDetail();
}
else
{
Alert.Show(string.Join(",", ret.MessageList.ToArray()));
}
}
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)
{
if (TXT_ModType.Text == ((int)BillModType.Contract).ToString())
{
GridRow row = Grid_V_TB_ASK_DETAIL.Rows[e.RowIndex];
System.Web.UI.WebControls.TextBox _txt = (System.Web.UI.WebControls.TextBox)row.FindControl("NB_PublishNum");
_txt.Enabled = true;
}
else
{
GridRow row = Grid_V_TB_ASK_DETAIL.Rows[e.RowIndex];
System.Web.UI.WebControls.TextBox _txt = (System.Web.UI.WebControls.TextBox)row.FindControl("NB_PublishNum");
_txt.Enabled = false;
}
}
protected void btnReduce_Click(object sender, EventArgs e)
{
var _ask = Session["Ask"] as V_TB_ASK;
List<V_TB_ASK_DETAIL> _askList = new List<V_TB_ASK_DETAIL>();
for (int i = 0, count = Grid_V_TB_ASK_DETAIL.Rows.Count; i < count; i++)
{
GridRow row = Grid_V_TB_ASK_DETAIL.Rows[i];
V_TB_ASK_DETAIL _entity = new V_TB_ASK_DETAIL();
object[] rowDataKeys = Grid_V_TB_ASK_DETAIL.DataKeys[i];
_entity.UID = ConvertHelper.To<Int64>(rowDataKeys[0]);
_entity.PoLine = ConvertHelper.To<int>(rowDataKeys[2]);
_entity.AskQty = ConvertHelper.To<Decimal>(rowDataKeys[7]);
_entity.PartCode = rowDataKeys[3].ToString();
_entity.PartDesc1 = rowDataKeys[4].ToString();
_entity.PartDesc2 = rowDataKeys[5].ToString();
_entity.ReduceQty = ConvertHelper.To<decimal>(rowDataKeys[8]);
_entity.AskBillNum = _ask.AskBillNum;
_entity.PoBillNum = _ask.PoBillNum;
System.Web.UI.WebControls.TextBox _txt = (System.Web.UI.WebControls.TextBox)row.FindControl("NB_PublishNum");
_entity.AskQty = decimal.Parse(_txt.Text);
if (_entity.AskQty != 0)//不能减产都0
{
_askList.Add(_entity);
}
}
var ret = SCP_ASK_CONTROLLER.Save_ASK_MODIF_QTY(_ask, _askList);
if (ret.State == ReturnStatus.Succeed)
{
if (ret.Result == true)
{
if (CurrentUser.FactoryList != null && CurrentUser.FactoryList.Count > 0)
{
SCP.Common.MailManager.SendMail(_ask.VendId, string.Format("要货看板编号{0}零件信息要货数量有变更", _ask.AskBillNum), string.Format("要货看板编号{0}零件信息有变更", _ask.AskBillNum), CurrentUser.FactoryList.FirstOrDefault());
}
BindDetail();
Alert.Show("数量修改成功,请联系供应商,并已经发邮件给供应商!");
}
else
{
Alert.Show(string.Join("<br>", ret.MessageList));
}
}
}
public void SearchV_TB_ASK_DETAIL_VIEW(Action<IQueryable<V_TB_ASK_DETAIL>> p_action)
{
V_TB_ASK_DETAIL _entity = new V_TB_ASK_DETAIL();
_entity.UserInAddress = CurrentUser.FactoryList;
_entity.AskBillNum = Request["AskBillNum"];
if (string.IsNullOrEmpty(Request["AskBillNum"].Trim()))
{
if (!string.IsNullOrEmpty("PartCode"))
{
_entity.PartCode = Request["PartCode"];
}
if (!string.IsNullOrEmpty(Request["State"]))
{
_entity.State = int.Parse(Request["State"]);
}
if (!string.IsNullOrEmpty(Request["PartCodeDesc"]))
{
_entity.PartDesc1 = Request["PartCodeDesc"];
}
}
SCP_ASK_CONTROLLER.Get_V_TB_ASK_DETAIL_List(_entity, (_ret) =>
{
if (_ret.State == ReturnStatus.Succeed)
{
p_action(_ret.Result);
}
});
}
protected void btnDeleted_Click(object sender, EventArgs e)
{
List<V_TB_ASK_DETAIL> _askList = new List<V_TB_ASK_DETAIL>();
if (Grid_V_TB_ASK_DETAIL.Rows.Count == 1)
{
Alert.Show("明细数量必须大于1,不能删除!");
return;
}
for (int i = 0, count = Grid_V_TB_ASK_DETAIL.Rows.Count; i < count; i++)
{
if (Grid_V_TB_ASK_DETAIL.SelectedRowIndexArray.Contains(i))
{
V_TB_ASK_DETAIL _entity = new V_TB_ASK_DETAIL();
object[] rowDataKeys = Grid_V_TB_ASK_DETAIL.DataKeys[i];
_entity.UID = ConvertHelper.To<Int64>(rowDataKeys[0]);
_askList.Add(_entity);
}
}
SCP_ASK_CONTROLLER.DEL_V_TB_ASK_DETAIL(_askList, (rs) => {
if(rs.State==ReturnStatus.Succeed)
{
if (rs.Result == true)
{
BindDetail();
}
else
{
Alert.Show("删除明细失败!");
}
}
});
}
protected void btnModifyDate_Click(object sender, EventArgs e)
{
var _ask = Session["Ask"] as V_TB_ASK;
if (DP_BeginTime.SelectedDate == null || DP_BeginTime.SelectedDate == null)
{
Alert.Show("订货日期或到货日期不能为空!");
return;
}
List<V_TB_ASK_DETAIL> _askList = new List<V_TB_ASK_DETAIL>();
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<Int64>(rowDataKeys[0]);
_entity.BeginTime = DP_BeginTime.SelectedDate.Value;
_entity.EndTime = DP_EndTime.SelectedDate.Value;
_askList.Add(_entity);
}
var ret=SCP_ASK_CONTROLLER.Save_TB_ASK_DETAIL_DATE(_askList);
if (ret.State == ReturnStatus.Succeed)
{
Alert.Show("日期修改成功");
BindDetail();
}
}
}
}