using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CoreFS.CA06;
using System.Collections;
using Infragistics.Win.UltraWinGrid;
using Core.Mes.Client.Comm.Tool;
using Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Control;
using Core.StlMes.Client.YdmPipeManage.Tool;
using Core.StlMes.Client.YdmPipeManage.Entity;
using Infragistics.Win;
namespace Core.StlMes.Client.YdmPipeManage
{
public partial class FrmPipeBillOfLadingClose : FrmBase
{
///
/// 登入用户的销售组织权限
///
private string[] _salgPermissions;
public FrmPipeBillOfLadingClose()
{
InitializeComponent();
this.IsLoadUserView = true;
}
private void FrmPipeBillOfLadingClose_Load(object sender, EventArgs e)
{
InitDate();
_salgPermissions = BaseMethod.InitPermissions(this.ValidDataPurviewIds, ob);
EntityHelper.ShowGridCaption(ultraGridOrder.DisplayLayout.Bands[0]);
EntityHelper.ShowGridCaption(ultraGridJustNo.DisplayLayout.Bands[0]);
BaseMethod.setOtherColumnReadOnly(ultraGridBillNo, new string[] { "Chc" });
BaseMethod.setOtherColumnReadOnly(ultraGridOrder, new string[] { "Chc" });
BaseMethod.setOtherColumnReadOnly(ultraGridJustNo, new string[] { "Chc", "SendNum" });
BaseMethod.InitCellPosition(ultraGridOrder, new string[] {"PlanWt", "PlanNum", "ActWt", "ActNum", "DelvryQty", "WgtEstmt" });
BaseMethod.InitCellPosition(ultraGridJustNo, new string[] { "ActLenMin", "ActLenMax", "ActCount", "ActWeight", "ActCountLoad", "ActWeightLoad", "ActCountKc", "ActWeightKc", "SendNum" });
EntityHelper.setColumnShowOrHidden(this.ultraGridOrder, new string[] { "PrtFlag", "SaleAreaDesc", "CreateName" }, false);
}
private void ChcCheckedChanged(object sender, EventArgs e)
{
if (ChcLadingSeq.Checked)
{
TxtLadingSeq.Enabled = true;
}
else
{
TxtLadingSeq.Enabled = false;
}
if (ChcLadingStatus.Checked)
{
ComLadingStatus.Enabled = true;
}
else
{
ComLadingStatus.Enabled = false;
}
if (ChcOrderNo.Checked)
{
TxtOrderNo.Enabled = true;
}
else
{
TxtOrderNo.Enabled = false;
}
if (ChcTime.Checked)
{
TimeBegin.Enabled = true;
TimeEnd.Enabled = true;
}
else
{
TimeEnd.Enabled = false;
TimeBegin.Enabled = false;
}
}
///
/// 初始时间
///
private void InitDate()
{
DateTime now = DateTime.Now;
DateTime dt1 = new DateTime(now.Year, now.Month, 1);//当月第一天
DateTime dt2 = dt1.AddMonths(1).AddDays(-1);//当月最后一天
TimeBegin.Value = DateTime.Parse(dt1.ToString("yyyy-MM-dd")+" 00:00:00");
TimeEnd.Value = DateTime.Parse(dt2.ToString("yyyy-MM-dd")+" 23:59:59");
}
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
DoQuery();
break;
case "BillClose":
BillClose();
break;
case "UpdateClose":
UpdateClose();
break;
case "BillCut":
BillCut();
break;
case"Print":
printData();
break;
case "Print2":
printData2();
break;
case "Export":
GridHelper.ulGridToExcel(ultraGridJustNo, "提单炉信息");
break;
case "Close":
this.Close();
break;
}
}
///
/// 单据打印(非套打)
///
private void printData2()
{
string TallyNo = "";
UltraGridRow ugr = this.ultraGridBillNo.ActiveRow;
if (ugr == null) { MessageUtil.ShowTips("无数据,请确认!"); return; }
TallyNo = ugr.Cells["BILL_NO"].Text.Trim();
string LOADVEHICLE_TYPE = ugr.Cells["LOADVEHICLE_TYPE"].Text.Trim();
string SALE_ORG = ugr.Cells["SALE_ORG"].Text.Trim();
string strurl = "";
DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose.getBillStatus", new Object[] { TallyNo }, this.ob);
if (dt.Rows.Count > 0)
{
if (dt.Rows[0]["LOADVEHICLE_TYPE"].ToString().Equals("1"))
{
if (int.Parse(dt.Rows[0]["BILL_STATUS"].ToString()) < 4)
{
MessageUtil.ShowTips("提单不是关闭的不能打印!");
return;
}
}
else
{
if (dt.Rows[0]["ISPRECLOSE"].ToString().Equals("0"))
{
MessageUtil.ShowTips("虚单未第一次关闭!");
return;
}
}
}
if (this.CustomInfo == "120504")
{
if (LOADVEHICLE_TYPE.Equals("实际"))
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderTH.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();
}
else
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderXDTH.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();
}
}
else
{
//if (_salgPermissions.Length == 1)
//{
if (SALE_ORG.Equals("100102"))
{
if (LOADVEHICLE_TYPE.Equals("实际"))
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderGouMao.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();//实单
}
else
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderXDGouMao.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();//虚单
}
}
else
{
if (LOADVEHICLE_TYPE.Equals("实际"))
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorder2.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();
}
else
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderXD2.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();
}
}
}
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
ServerHelper.SetData("com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose.updatePintFlag", new object[] { time, TallyNo }, ob);
BillDocPrintExcel fBug = new BillDocPrintExcel(ob, strurl);
fBug.AutoSize = true;
fBug.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
fBug.Text = "出库单打印";
fBug.ShowDialog();
fBug.StartPosition = FormStartPosition.CenterScreen;
DoQuery();
}
private void printData()
{
string TallyNo = "";
UltraGridRow ugr = this.ultraGridBillNo.ActiveRow;
if (ugr == null) { MessageUtil.ShowTips("无数据,请确认!"); return; }
TallyNo = ugr.Cells["BILL_NO"].Text.Trim();
string LOADVEHICLE_TYPE = ugr.Cells["LOADVEHICLE_TYPE"].Text.Trim();
string SALE_ORG = ugr.Cells["SALE_ORG"].Text.Trim();
string strurl = "";
DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose.getBillStatus", new Object[] { TallyNo }, this.ob);
if (dt.Rows.Count > 0)
{
if (dt.Rows[0]["LOADVEHICLE_TYPE"].ToString().Equals("1"))
{
if (int.Parse(dt.Rows[0]["BILL_STATUS"].ToString()) < 4)
{
MessageUtil.ShowTips("提单不是关闭的不能打印!");
return;
}
}
else
{
if (dt.Rows[0]["ISPRECLOSE"].ToString().Equals("0"))
{
MessageUtil.ShowTips("虚单未第一次关闭!");
return;
}
}
}
if (this.CustomInfo == "120504")
{
if (LOADVEHICLE_TYPE.Equals("实际"))
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderTH.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();
}
else
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderXDTH.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();
}
}
else
{
//if (_salgPermissions.Length == 1)
//{
if (SALE_ORG.Equals("100102"))
{
if (LOADVEHICLE_TYPE.Equals("实际"))
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderGouMao.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();//实单
}
else
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderXDGouMao.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();//虚单
}
}
else
{
if (LOADVEHICLE_TYPE.Equals("实际"))
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorder.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();
}
else
{
strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderXD.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();
}
}
//}
//else
//{
// if (LOADVEHICLE_TYPE.Equals("实际"))
// {
// strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorder.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();
// }
// else
// {
// strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepYdmOutboundorderXD.cpt" + "&P_BILL_NO=" + TallyNo + "&USERID=" + this.UserInfo.GetUserID();
// }
//}
}
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
ServerHelper.SetData("com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose.updatePintFlag", new object[] { time, TallyNo }, ob);
BillDocPrintExcel fBug = new BillDocPrintExcel(ob, strurl);
fBug.AutoSize = true;
fBug.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
fBug.Text = "出库单打印";
fBug.ShowDialog();
fBug.StartPosition = FormStartPosition.CenterScreen;
DoQuery();
}
private void DoQuery()
{
ArrayList param = new ArrayList();
string billNo = "";
if (ChcLadingSeq.Checked)
{
billNo = TxtLadingSeq.Text.Trim();
}
string orderNo = "";
if (ChcOrderNo.Checked)
{
orderNo = TxtOrderNo.Text.Trim();
}
string billStatus = "";
if (ChcLadingStatus.Checked)
{
billStatus = ComLadingStatus.Value.ToString();
}
string strBegin = "1900-01-01 00:00:00";
string strEnd = "9900-01-01 00:00:00";
if (ChcTime.Checked)
{
if (TimeBegin.Value == null || TimeEnd.Value == null)
{
MessageUtil.ShowWarning("请选择正确的创建时间");
return;
}
strBegin = TimeBegin.Value.ToString();
strEnd = TimeEnd.Value.ToString();
}
//string[] arr = BaseMethod.InitPermissions(this.ValidDataPurviewIds,this.ob);
string[] arr = this.ValidDataPurviewIds;
param.Add(billNo);
param.Add(orderNo);
param.Add(billStatus);
param.Add(strBegin);
param.Add(strEnd);
DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose.getBiltNo", new Object[] { param, arr, this.CustomInfo}, this.ob);
GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
if (dt == null || dt.Rows.Count == 0)
{
QueryOrder("");
QueryJustStoveInfo("");
}
BaseMethod.SetUltraGridRowColor(ultraGridBillNo, new string[] { "LOADVEHICLE_TYPE" }, new string[] { "虚拟" }, Color.GreenYellow);
}
private void ultraGridBillNo_AfterRowActivate(object sender, EventArgs e)
{
UltraGridRow ugr = ultraGridBillNo.ActiveRow;
if (ugr == null)
{
return;
}
QueryOrder(ugr.GetCellValue("BILL_NO").ToString());
QueryJustStoveInfo(ugr.GetCellValue("BILL_NO").ToString());
}
private void QueryOrder(string billNo)
{
List listSource = EntityHelper.GetData(
"com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose.getOrderInfoByBiltNo", new object[] { billNo }, this.ob);
ydmZcBillMyEntityBindingSource.DataSource = listSource;
}
private void QueryJustStoveInfo(string billNo)
{
ultraGridJustNo.UpdateData();
List listSource = EntityHelper.GetData(
"com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose.getJustStoveNoInfoByBiltNo", new object[] { billNo }, this.ob);
ydmZcBillCyEntityBindingSource.DataSource = listSource;
foreach (UltraGridRow row in ultraGridJustNo.Rows)
{
//理货在途量
row.Cells["ActCountKc"].Value = (double.Parse(row.Cells["ActTallCount"].Value.ToString()) - double.Parse(row.Cells["ActCountLoad"].Value.ToString())).ToString();
if (double.Parse(row.Cells["ActCountKc"].Value.ToString()) != 0.0)
{
row.Cells["ActWeightKc"].Value = (double.Parse(row.Cells["ActTallWt"].Value.ToString()) - double.Parse(row.Cells["ActWeightLoad"].Value.ToString())).ToString("f3");
}
else
{
row.Cells["ActWeightKc"].Value = "0.000";
}
//提单在途量
row.Cells["ActCountZy"].Value = (double.Parse(row.Cells["ActCount"].Value.ToString()) - double.Parse(row.Cells["ActCountLoad"].Value.ToString())).ToString();
if (double.Parse(row.Cells["ActCountZY"].Value.ToString()) != 0.0)
{
row.Cells["ActWeightZy"].Value = (double.Parse(row.Cells["ActWeight"].Value.ToString()) - double.Parse(row.Cells["ActWeightLoad"].Value.ToString())).ToString("f3");
}
else
{
row.Cells["ActWeightZY"].Value = "0.000";
}
if (row.Cells["orderUnit"].Text.Equals("吨"))
{
//row.Cells["SendNum"].Value = row.Cells["ActWeightLoad"].Value.ToString();
row.Cells["SendNum"].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly;
}
else if (row.Cells["OrderUnit"].Text.Equals("支") || row.Cells["OrderUnit"].Text.Equals("个"))
{
//row.Cells["SendNum"].Value = row.Cells["ActCountLoad"].Value.ToString();
row.Cells["SendNum"].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly;
}
else
{
row.Cells["SendNum"].Appearance.BackColor = Color.FromArgb(255, 255, 128);
row.Cells["SendNum"].Appearance.BackHatchStyle = BackHatchStyle.None;
row.Cells["SendNum"].Activation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit;
}
}
}
private void ultraGridOrder_AfterRowActivate(object sender, EventArgs e)
{
UltraGridRow ugr = ultraGridOrder.ActiveRow;
if (ugr == null)
{
return;
}
foreach (UltraGridRow ugrJ in ultraGridJustNo.Rows)
{
if (ugrJ.Cells["OrdLnDlyPk"].Text.Equals(ugr.Cells["OrdLnDlyPk"].Text))
{
ugrJ.Appearance.BackColor = Color.Wheat;
}
else
{
ugrJ.Appearance.BackColor = Color.White;
}
}
}
///
/// 提单关闭
///
private void BillClose()
{
ultraGridJustNo.UpdateData();
UltraGridRow ugr = ultraGridBillNo.ActiveRow;
ArrayList list1 = new ArrayList();
ArrayList pram1 = new ArrayList();
if (ugr == null)
{
MessageUtil.ShowWarning("请选择提单号!");
return;
}
if (MessageUtil.ShowYesNoAndQuestion("是否提单关闭?") == DialogResult.No)
{
return;
}
string billNo = ugr.Cells["BILL_NO"].Value.ToString();
string sendNo = ugr.Cells["SEND_PLAN_NO"].Value.ToString();
string prcls = ugr.Cells["PRD_CLS"].Value.ToString();
string name = this.UserInfo.GetUserName();
string sendNumber = "";
string loadvehicleType = ugr.Cells["LOADVEHICLE_TYPE"].Value.ToString();
//炉号信息
foreach (UltraGridRow row in ultraGridJustNo.Rows)
{
ArrayList list = new ArrayList();
if (row.Cells["ActCountLoad"].Text.Trim() != "0")
{
if (row.Cells["SendNum"].Text.Trim() == "0.000")
{
MessageUtil.ShowTips("请填写提单炉信息里面的实发数!");
return;
//sendNumber = "0";
}
else
{
sendNumber = row.Cells["SendNum"].Value.ToString();
}
}
else { sendNumber = "0"; }
list.Add(sendNumber);
list.Add(row.Cells["ActCountLoad"].Value.ToString());
list.Add(row.Cells["JudgeStoveNo"].Value.ToString());
list.Add(row.Cells["BatchNo"].Value.ToString());
list.Add(row.Cells["GroupNo"].Value.ToString());
list.Add(row.Cells["OrdLnDlyPk"].Value.ToString());
list.Add(row.Cells["OrderUnit"].Value.ToString());
list.Add(row.Cells["PrtFlag"].Value.ToString());
list.Add(row.Cells["StdCode"].Value.ToString2());
list1.Add(list);
}
///合同信息
foreach (UltraGridRow row in ultraGridOrder.Rows)
{
ArrayList pram = new ArrayList();
pram.Add(row.Cells["BillNoSeq"].Value.ToString());
pram.Add(row.Cells["OrdLnDlyPk"].Value.ToString());
pram1.Add(pram);
}
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose";
ccp.MethodName = "BillClose";
ccp.ServerParams = new object[] { billNo, sendNo, name, list1, pram1, prcls, loadvehicleType };
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode != -1)
{
MessageUtil.ShowTips(ccp.ReturnInfo);
if (ccp.ReturnInfo.Equals("提单关闭成功!"))
{
if (!_salgPermissions[0].Equals("100102"))
{
printData();
}
DoQuery();
BaseMethod.UltraGridLocation(ultraGridBillNo, new string[] { "BILL_NO" }, new string[] { billNo });
}
}
}
///
/// 提单划断
///
private void BillCut()
{
UltraGridRow ugr = ultraGridBillNo.ActiveRow;
if (ugr == null)
{
MessageUtil.ShowWarning("请选择提单号!");
return;
}
if (MessageUtil.ShowYesNoAndQuestion("是否提单划断?") == DialogResult.No)
{
return;
}
string billNo = ugr.Cells["BILL_NO"].Value.ToString();
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose";
ccp.MethodName = "BillCut";
ccp.ServerParams = new object[] { billNo };
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode != -1)
{
MessageUtil.ShowTips(ccp.ReturnInfo);
if (ccp.ReturnInfo.Equals("提单划断成功!"))
{
DoQuery();
BaseMethod.UltraGridLocation(ultraGridBillNo, new string[] { "BILL_NO" }, new string[] { billNo });
}
}
}
///
/// 按回车键触发查询按钮
///
///
///
private void ContPublic_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
DoQuery();
}
}
///
/// 填写时触发
///
///
///
private void ultraGridJustNo_CellChange(object sender, CellEventArgs e)
{
if (e.Cell.Column.Key.Equals("SendNum"))
{
if (e.Cell.Row.Cells["SendNum"].Value == null)
{
e.Cell.Row.Cells["SendNum"].Value = "0";
}
else
{
ultraGridJustNo.UpdateData();
string actCount = e.Cell.Row.Cells["SendNum"].Value.ToString();
if (!StringUtil.IsFloat(actCount) || actCount == "0")//actCount == "" || int.Parse(actCount)==0
{
e.Cell.Row.Cells["SendNum"].Value = "0";
}
else
{
e.Cell.Row.Cells["SendNum"].Value = e.Cell.Row.Cells["SendNum"].Value.ToString();
}
}
//DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose.queryOrderUnit", new Object[] { e.Cell.Row.Cells["OrdLnDlyPk"].Text.Trim() }, this.ob);
//if (dt.Rows.Count > 0)
//{
// if (dt.Rows[0]["ORDER_UNIT"].ToString().Equals("吨") || dt.Rows[0]["ORDER_UNIT"].ToString().Equals("支"))
// {
// MessageUtil.ShowTips("该炉对应合同信息交货行计量单位为:"+dt.Rows[0]["ORDER_UNIT"].ToString()+"不能填!");
// e.Cell.Row.Cells["SendNum"].Value = "0";
// return;
// }
//}
}
}
///
/// 撤销关闭提单
///
private void UpdateClose()
{
ultraGridBillNo.UpdateData();
UltraGridRow ugr = ultraGridBillNo.ActiveRow;
if (ugr == null) return;
if (MessageUtil.ShowYesNoAndQuestion("是否撤销关闭提单?") == DialogResult.No) return;
string billNo = ugr.Cells["BILL_NO"].Value.ToString();
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.ydm.pipemanage.CorePipeBillOfLadingClose";
ccp.MethodName = "updateBill";
ccp.ServerParams = new object[] { billNo};
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode != -1)
{
MessageUtil.ShowTips(ccp.ReturnInfo);
if (ccp.ReturnInfo.Equals("撤销关闭提单成功!"))
{
DoQuery();
BaseMethod.UltraGridLocation(ultraGridBillNo, new string[] { "BILL_NO" }, new string[] { billNo });
}
}
}
}
}