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.
 
 
 
 
 

286 lines
10 KiB

using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Linq.Expressions;
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 CK.SCP.Models.AppBoxEntity;
using System.Text;
using Newtonsoft.Json;
using System.Data;
namespace SCP.WarehouseData
{
public partial class SCP_RECEIVE_VIEW : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
IsRoleRight();
if (!IsPostBack)
{
LoadData();
}
}
public void IsRoleRight()
{
if (CurrentUser.FactoryList == null || CurrentUser.FactoryList.Count == 0)
{
Alert.Show("当前用户未选择地点!");
return;
}
}
public void LoadData()
{
ddlGridPageSize.SelectedValue = ConfigHelper.PageSize.ToString();
BindData();
}
public void BindData()
{
var _entity = new V_TB_RECEIVE();
_entity.RecvBillNum = txtReceiveBill.Text;//单据号
_entity.ErpRecvBillNum = txtErpBill.Text;//ERP单据号
if (!string.IsNullOrEmpty(ddl.SelectedValue))
{
//已收货:0,审核通过:1,已开票,2
int istate = Convert.ToInt32(ddl.SelectedValue);
if (istate == 0)
{
_entity.State = 0;
}
else if (istate == 1)
{
_entity.State = 1;
}
else if (istate == 2)
{
_entity.State = 2;
}
}
else
{
_entity.State = -1;
}
if (!string.IsNullOrEmpty(ddtype.SelectedValue))
{
string istate = ddtype.SelectedValue;
if (istate == "收货单")
{
_entity.BillType_DESC = "收货单";
}
else if (istate == "退货单")
{
_entity.BillType_DESC = "退货单";
}
}
_entity.UserInAddress = CurrentUser.FactoryList;
_entity.UserInVendIds = CurrentUser.VenderList;
_entity.VendId = txtSupplier.Text;//供应商代码
_entity.PoBillNum = txtPO.Text;//订单号
_entity.AsnBillNum = AsnBillNum.Text;//发货单号
_entity.OperName = OperName.Text;//操作员
if (txtShipTimeStar.SelectedDate != null)
{
_entity.ShipTimeStart = (DateTime)txtShipTimeStar.SelectedDate;
}
if (txtShipTimeEnd.SelectedDate != null)
{
_entity.ShipTimeEnd = (DateTime)txtShipTimeEnd.SelectedDate;
}
SCP_RECIVECE_CONTROLLER.Get_V_TB_RECEIVE_GG_List(_entity, (ret) =>
{
if (ret.State == ReturnStatus.Succeed)
{
Grid_V_TB_RECEIVE.RecordCount = ret.Result.Count();
var _list = SortAndPage(ret.Result, Grid_V_TB_RECEIVE);
Grid_V_TB_RECEIVE.DataSource = _list;
Grid_V_TB_RECEIVE.DataBind();
}
});
}
protected void ddlGridPageSize_OnSelectedIndexChanged(object sender, EventArgs e)
{
Grid_V_TB_RECEIVE.PageSize = Convert.ToInt32(ddlGridPageSize.SelectedValue);
BindData();
}
protected void Grid1_OnRowDoubleClick(object sender, GridRowClickEventArgs e)
{
string ID = GetSelectedDataKey(Grid_V_TB_RECEIVE, 1);
string STATE = Grid_V_TB_RECEIVE.Rows[e.RowIndex].Values[0].ToString();
if (string.IsNullOrEmpty(STATE))
{
STATE = "0";
}
if (STATE != "0" && STATE != "1" && STATE != "2")
{
STATE = "0";
}
string url = String.Format("../WarehouseData/SCP_RECEIVE_DETAIL_VIEW.aspx?ID={0}&STATE={1}", ID, STATE);
PageContext.RegisterStartupScript(Window1.GetShowReference(url));
}
//明细
protected void btnDetail_OnClick(object sender, EventArgs e)
{
List<int> listids = GetSelectedDataKeyIDs(Grid_V_TB_RECEIVE);
if (listids.Count == 0)
{
PageContext.RegisterStartupScript(Alert.GetShowInParentReference("请勾选要查看明细的单据"));
return;
}
if (listids.Count > 1)
{
PageContext.RegisterStartupScript(Alert.GetShowInParentReference("只能查看一条单据的明细"));
return;
}
string STATE = Grid_V_TB_RECEIVE.SelectedRow.Values[0].ToString();
if (string.IsNullOrEmpty(STATE))
{
STATE = "0";
}
if (STATE != "0" && STATE != "1" && STATE != "2")
{
STATE = "0";
}
string ErpRecvBillNum = GetSelectedDataKey(Grid_V_TB_RECEIVE,4);
string url = String.Format("../WarehouseData/SCP_RECEIVE_DETAIL.aspx?ID={0}&STATE={1}", ErpRecvBillNum, STATE);
PageContext.RegisterStartupScript(Window1.GetShowReference(url));
}
//查询
protected void BtnSearch_OnClick(object sender, EventArgs e)
{
BindData();
}
//显示面板
protected void btnShow_OnClick(object sender, EventArgs e)
{
gp1.Hidden = false;
}
//关闭面板
protected void OnClick(object sender, EventArgs e)
{
gp1.Hidden = true;
}
//审核通过
protected void btnCheck_OnClick(object sender, EventArgs e)
{
ICollection<Role> Roles = CurrentUser.Roles;
string strUserName = CurrentUser.Name;
List<int> listids = GetSelectedDataKeyIDs(Grid_V_TB_RECEIVE);
if (listids.Count == 0)
{
PageContext.RegisterStartupScript(Alert.GetShowInParentReference("请勾选要审核的单据"));
return;
}
var _ls = new List<string>();
int[] selections = Grid_V_TB_RECEIVE.SelectedRowIndexArray;
for (int i = 0, count = Grid_V_TB_RECEIVE.Rows.Count; i < count; i++)
{
if (selections.Contains(i))
{
object[] rowDataKeys = Grid_V_TB_RECEIVE.DataKeys[i];
_ls.Add(rowDataKeys[1] as string);
}
}
var ret = SCP_RECIVECE_CONTROLLER.Save_TB_RECEIVE_STATE(_ls, ReceiveState.Check, strUserName, CurrentUser.UsedDomain);
PageContext.RegisterStartupScript(Alert.GetShowInParentReference("审核成功"));
BindData();
}
protected void Grid1_OnPageIndexChange(object sender, GridPageEventArgs e)
{
Grid_V_TB_RECEIVE.PageIndex = e.NewPageIndex;
BindData();
}
//导出
protected void btnOutput_OnClick(object sender, EventArgs e)
{
var _entity = new V_TB_RECEIVE();
_entity.RecvBillNum = txtReceiveBill.Text;
if (!string.IsNullOrEmpty(ddl.SelectedValue))
{
_entity.State = Convert.ToInt32(ddl.SelectedValue);
}
else
{
_entity.State = -1;
}
_entity.PoBillNum = txtPO.Text;
_entity.AsnBillNum = AsnBillNum.Text;
_entity.OperName = OperName.Text;
if (CurrentUser.VenderList != null && CurrentUser.VenderList.Count > 0)
{
_entity.VendId = CurrentUser.VenderList[0];
}
if (CurrentUser.FactoryList != null && CurrentUser.FactoryList.Count > 0)
{
_entity.Site = CurrentUser.FactoryList[0];
}
List<string> _ls = new List<string>();
SCP_RECIVECE_CONTROLLER.Get_V_TB_RECEIVE_List(_entity, (ret) =>
{
if (ret.State == ReturnStatus.Succeed)
{
_ls = ret.Result.Select(p => p.RecvBillNum).ToList();
DataSet ds = null;
if (CurrentUser.VenderList.Count > 0)
{
ds = SCP_RECIVECE_CONTROLLER.GET_RECEIVE_EXECEL(_ls, CurrentUser.UsedDomain, CurrentUser.VenderList.FirstOrDefault());
}
else
{
ds = SCP_RECIVECE_CONTROLLER.GET_RECEIVE_EXECEL(_ls, CurrentUser.UsedDomain);
}
PageBase.DataSetToExcel(ds, "收货退货单");
}
});
}
protected void Grid_V_TB_RECEIVE_RowDataBound(object sender, GridRowEventArgs e)
{
//object[] rowDataKeys = Grid_V_TB_RECEIVE.DataKeys[e.RowIndex];
//string _recNum = rowDataKeys[2].ToString();
// StringBuilder _buffer = new StringBuilder();
// System.Web.UI.WebControls.Label _content = (System.Web.UI.WebControls.Label)Grid_V_TB_RECEIVE.Rows[e.RowIndex].FindControl("RowGrid1");
// if (_content != null)
// {
// _buffer.Append("<table><tr><td>订单行</td><td>零件号</td><td>零件名称</td><td>数量</td><td>单位</td></tr>");
// var _list = JsonConvert.DeserializeObject<List<V_TB_RECEIVE_DETAIL>>(_recNum);
// _list.ForEach(p =>
// {
// _buffer.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>"
// , p.PoLine, p.PartCode, p.PartDesc1, p.Qty, p.PoUnit);
// });
// _buffer.Append("</talbe>");
// _content.Text = _buffer.ToString();
// }
}
}
}