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 Pur.Entity;
using Core.Mes.Client.Comm.Control;
using Pur.Entity.ck;
using Infragistics.Win.UltraWinGrid;
using System.Collections;
using Core.Mes.Client.Comm.Tool;
using com.hnshituo.pur.vo;
using Core.Mes.Client.Comm.Server;
using Pur.PublicTools;
namespace Pur.ck
{
public partial class ExcDeliveryHandle : FrmPmsBase
{
public ExcDeliveryHandle()
{
InitializeComponent();
}
private void ExcDeliveryHandle_Load(object sender, EventArgs e)
{
ck_Ctime.Checked = true;
txt_CreateTimeS.Value = DateTime.Now.AddMonths(-1);
txt_CreateTimeS.Enabled = true;
txt_CreateTimeE.Value = Convert.ToDateTime(DateTime.Now.ToShortDateString()).AddHours(23).AddMinutes(59);
txt_CreateTimeE.Enabled = true;
txt_status.SelectedIndex = 1;//默认待处置状态
GridHelper.SetExcludeColumnsActive(GridSubM.DisplayLayout.Bands[0], new string[] { });
GridHelper.SetExcludeColumnsActive(GridHandledSubM.DisplayLayout.Bands[0], new string[] { });
GridHelper.SetExcludeColumnsActive(GridReturnedSubM.DisplayLayout.Bands[0], new string[] { });
PublicPur.InitCellEdit(new UltraGrid[] { GridHandle }, new string[] { "CHK","remark2","AGAINQTY", "RETURNEDQTY", "HANDLEDQTY" });
PublicPur.InitCellPositionRight(new UltraGrid[] { GridHandle }, new string[] { "AGAINQTY", "RETURNEDQTY", "HANDLEDQTY" });
PublicPur.InitColumnShowLength(new UltraGrid[] { GridHandle }, 0, new string[] { "AGAINQTY", "RETURNEDQTY", "HANDLEDQTY" }, 3, false);
Get_ExcSubM();
}
#region toolbar工具栏
///
/// 菜单栏
///
///
///
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
Get_ExcSubM();
break;
case "Confirm":
Con_ExcSubM();
break;
case "Cancel":
cancel_ExcSubM();
break;
case "doPrintDelivery":
doPrintDelivery();
break;
case "doPrintReturn":
doPrintReturn();
break;
case "Close":
this.Close();
break;
}
}
///
/// 查询
///
private void Get_ExcSubM()
{
try
{
this.Cursor = Cursors.WaitCursor;
subM.Clear();
handledSubM.Clear();
returnSubM.Clear();
Hashtable map = new Hashtable();
map.Add("deliverySubId", txt_deliverySubId.Text.Trim());
map.Add("orderId", txt_OrderId.Text.Trim());
map.Add("suppName", txt_suppName.Text.Trim());
map.Add("invPhysicName", QInphysicNoJL.Text.Trim());
map.Add("deliveryLocation", QLocationNoJL.Text.Trim());
if (ck_Ctime.Checked && !string.IsNullOrEmpty(txt_CreateTimeS.Text))
{
map.Add("createTimeBegin", Convert.ToDateTime(txt_CreateTimeS.Value));
}
if (ck_Ctime.Checked && !string.IsNullOrEmpty(txt_CreateTimeE.Text))
{
map.Add("createTimeEnd", Convert.ToDateTime(txt_CreateTimeE.Value));
}
if (txt_status.SelectedIndex != -1)
{
map.Add("statusHandle", txt_status.Value.ToString().Trim());//all:全部 wait:待处理 did:已处理
}
DataTable dt = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubMService", "doQueryDeliverySubMList", new object[] { map });
GridHelper.CopyDataToDatatable(dt, DTSubM, true);
GridHelper.RefreshAndAutoSize(GridSubM);
}
catch(Exception ex)
{
MessageUtil.ShowTips("查询送货单主表数据失败:"+ex.Message);
}
finally
{
this.Cursor = Cursors.Default;
}
}
///
/// 处理结果提交
///
private void Con_ExcSubM()
{
try
{
this.Cursor = Cursors.WaitCursor;
List list = new List();
//校验数据
GridHandle.UpdateData();
foreach (UltraGridRow row in GridHandle.Rows)
{
if (Convert.ToBoolean(row.GetCellValue("CHK")))
{
///"AGAINQTY", "RETURNEDQTY", "HANDLEDQTY"
String strSubSqe = row.GetCellValue("deliverySubLineSqe").ToString().Trim();
String strId = row.GetCellValue("id").ToString().Trim();
//校验异常单
if (!testExceptionC(strId, 1))
{
return;
}
double dbAGAINQTY = 0;//补货量
double dbRETURNEDQTY = 0;//退货量
double dbHANDLEDQTY = 0;//让步量
double dbAllQty = 0;
double dbQty = 0;
Double.TryParse(row.GetCellValue("qty").ToString().Trim(), out dbQty);
Double.TryParse(row.GetCellValue("AGAINQTY").ToString().Trim(), out dbAGAINQTY);
Double.TryParse(row.GetCellValue("RETURNEDQTY").ToString().Trim(), out dbRETURNEDQTY);
Double.TryParse(row.GetCellValue("HANDLEDQTY").ToString().Trim(), out dbHANDLEDQTY);
dbAGAINQTY =Math.Round(dbAGAINQTY,3);//补货量
dbRETURNEDQTY =Math.Round(dbRETURNEDQTY,3);//退货量
dbHANDLEDQTY = Math.Round(dbHANDLEDQTY,3);//让步量
dbQty = Math.Round(dbQty, 3);//待处置量
dbAllQty = dbAGAINQTY + dbRETURNEDQTY + dbHANDLEDQTY;
if (dbAllQty > dbQty)
{
MessageUtil.ShowTips("送货单行:" + strSubSqe + "的异常单:" + strId + "的处置量总和不能大于待处置量:" + dbQty);
row.Activate();
return;
}
if (dbAGAINQTY <= 0 && dbRETURNEDQTY <= 0 && dbHANDLEDQTY <= 0)
{
MessageUtil.ShowTips("送货单行:" + strSubSqe + "的异常单:" + strId + "的处置量总需大于0");
row.Activate();
return;
}
ExcDeliveryException hand = new ExcDeliveryException();
hand.Id = strId;
hand.DeliverySubLineSqe = strSubSqe;
hand.HandledQty = dbHANDLEDQTY;
hand.ReturnedQty = dbRETURNEDQTY;
hand.AgainQty = dbAGAINQTY;
hand.HandleName = UserInfo.GetUserName();
hand.HandleUserid = UserInfo.GetUserID();
hand.HandleTime = DateTime.Now;
hand.Remark = row.GetCellValue("remark2").ToString().Trim();
hand.DeleteUserid = UserInfo.GetDeptid();
hand.DeleteName = UserInfo.GetDepartment();
list.Add(hand);
}
}
if (list.Count <= 0)
{
MessageUtil.ShowTips("请选择异常单进行处理");
return;
}
if (MessageUtil.ShowYesNoAndQuestion("确定提交处置包括送货单行:" +list[0].DeliverySubLineSqe+"在内的共"+list.Count+"条异常单处理结果?") != DialogResult.Yes)
{
return;
}
CoreResult crt = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryExceptionService", "doHandle", new object[] { list });
if (crt.Resultcode == 0)
{
MessageUtil.ShowTips("操作成功:" + crt.Resultmsg);
if(GridSubM.ActiveRow!=null)
{
String strDeliverySubId = GridSubM.ActiveRow.Cells["DeliverySubId"].Value.ToString().Trim();
if (!String.IsNullOrEmpty(strDeliverySubId))
{
doQuerySubLine(strDeliverySubId);
}
}
}
else
{
//操作失败
MessageUtil.ShowTips("操作失败:" + crt.Resultmsg);
}
}
catch (Exception ex)
{
MessageUtil.ShowTips("操作失败:" + ex);
}
finally
{
this.Cursor = Cursors.Default;
}
}
///
/// 取消处理
///
private void cancel_ExcSubM()
{
try
{
this.Cursor = Cursors.WaitCursor;
List list = new List();
//校验数据
GridHandle.UpdateData();
foreach (UltraGridRow row in GridHandle.Rows)
{
if (Convert.ToBoolean(row.GetCellValue("CHK")))
{
String strId = row.GetCellValue("id").ToString().Trim();
String strSubSqe = row.GetCellValue("deliverySubLineSqe").ToString().Trim();
//校验异常单
if (!testExceptionC(strId, 2))
{
return;
}
ExcDeliveryException hand = new ExcDeliveryException();
hand.DeliverySubLineSqe = strSubSqe;
hand.Id = strId;
hand.DeleteName = UserInfo.GetUserName();
hand.DeleteUserid = UserInfo.GetUserID();
hand.DeleteTime = DateTime.Now;
list.Add(hand);
}
}
if (list.Count <= 0)
{
MessageUtil.ShowTips("请选择异常单进行处理");
return;
}
if (MessageUtil.ShowYesNoAndQuestion("确定撤销处置包括送货单行:" + list[0].DeliverySubLineSqe + "在内的共" + list.Count + "条异常单处理结果?") != DialogResult.Yes)
{
return;
}
CoreResult crt = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryExceptionService", "docancel_Handle", new object[] { list });
if (crt.Resultcode == 0)
{
MessageUtil.ShowTips("操作成功:" + crt.Resultmsg);
if (GridSubM.ActiveRow != null)
{
String strDeliverySubId = GridSubM.ActiveRow.Cells["DeliverySubId"].Value.ToString().Trim();
if (!String.IsNullOrEmpty(strDeliverySubId))
{
doQuerySubLine(strDeliverySubId);
}
}
}
else
{
//操作失败
MessageUtil.ShowTips("操作失败:" + crt.Resultmsg);
}
}
catch (Exception ex)
{
MessageUtil.ShowTips("操作失败:" + ex);
}
finally
{
this.Cursor = Cursors.Default;
}
}
///
/// 打印检化验委托单
///
private void doPrintDelivery()
{
try
{
this.Cursor = Cursors.WaitCursor;
if (GridHandledSubM.ActiveRow == null && !GridHandledSubM.ActiveRow.HasChild())
{
MessageUtil.ShowTips("请选择让步接收送货单行进行操作!");
return;
}
String strDeliverySubId = GridHandledSubM.ActiveRow.GetCellValue("deliverySubId").ToString().Trim();
if (String.IsNullOrEmpty(strDeliverySubId))
{
MessageUtil.ShowTips("送货单号为空");
}
string strurl = "";
DataTable dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreBaseInfoNew.doQuery", new Object[] { "1223" }, this.ob);
DataRow[] drArr = dt.Select("validflag='1'");
if (drArr.Length != 1)
{
MessageUtil.ShowTips("基础数据维护错误:报表系统需维护有效的Ip且只能维护一个有效ip!");
return;
}
String TipsEnv = drArr[0]["baseName"].ToString();
String strUrlPort = "http://172.54.10.42:8080";//报表系统IP
String[] str = strUrlPort.Split(':');
String strUrl = str[0] + ":" + str[1];
if (ob.MainUrl.StartsWith(strUrl))
{
//测试环境
if (TipsEnv == "2")
{
strurl = strUrlPort + "/webroot/decision/view/report?viewlet=RepDeliverySubBillDev.cpt&op=view" + "&subId=" + strDeliverySubId;
}
else
{
strurl = strUrlPort + "/webroot/decision/view/report?viewlet=RepDeliverySubBill.cpt&op=view" + "&subId=" + strDeliverySubId;
}
}
else
{
//测试环境
if (TipsEnv == "2")
{
strurl = strUrlPort + "/webroot/decision/view/report?viewlet=RepDeliverySubBillDev.cpt&op=view" + "&subId=" + strDeliverySubId;
}
else
{
strurl = strUrlPort + "/webroot/decision/view/report?viewlet=RepDeliverySubBill.cpt&op=view" + "&subId=" + strDeliverySubId;
}
}
//if (ob.MainUrl.StartsWith("http://127.0.0.1"))
//{
// strurl = "http://localhost:8075/webroot/decision/view/report?viewlet=RepPurOrderDev.cpt&op=view" + "&cmbOrder=" + orderNo;
//}
//else
//{
// strurl = "http://localhost:8075/webroot/decision/view/report?viewlet=RepPurOrder.cpt&op=view" + "&cmbOrder=" + orderNo;
//}
FrmRepExcel fBug = new FrmRepExcel(ob, strurl);
fBug.AutoSize = true;
fBug.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
fBug.WindowState = FormWindowState.Maximized;
fBug.Text = "TPCO送货单";
fBug.Show();
}
finally
{
this.Cursor = Cursors.Default;
}
}
///
/// 打印退货单
///
private void doPrintReturn()
{
//
MessageUtil.ShowTips("开发中");
throw new NotImplementedException();
}
#endregion
#region 界面事件
private void GridSubM_AfterRowActivate(object sender, EventArgs e)
{
try
{
DTHandle.Clear();
handledSubM.Clear();
returnSubM.Clear();
String strDeliverySubId = GridSubM.ActiveRow.Cells["DeliverySubId"].Value.ToString().Trim();
if (!String.IsNullOrEmpty(strDeliverySubId))
{
doQuerySubLine(strDeliverySubId);
}
}
catch (Exception ex)
{
MessageUtil.ShowTips("加载异常单数据异常:"+ex.Message);
}
finally
{
this.Cursor = Cursors.Default;
}
}
private void GridHandle_AfterRowActivate(object sender, EventArgs e)
{
try
{
handledSubM.Clear();
returnSubM.Clear();
String strId = GridHandle.ActiveRow.GetCellValue("id").ToString().Trim();
if (String.IsNullOrEmpty(strId))
{
MessageUtil.ShowTips("异常单号为空,或请刷新界面重试");
return;
}
ExcDeliveryException hand = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryExceptionService", "findById", new object[] { strId });
if (hand == null)
{
MessageUtil.ShowTips("未发现异常单:" + strId + "信息记录,可能已被删除,或请刷新界面重试");
return;
}
if (hand.Validflag != "1")
{
MessageUtil.ShowTips("异常单:" + strId + "信息记录可能已被删除,或请刷新界面重试");
return;
}
//加载让步接收单:
if (!String.IsNullOrEmpty(hand.HandleSubId))
{
Hashtable map = new Hashtable();
map.Add("deliverySubId", hand.HandleSubId);
DataTable dt = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubMService", "doQueryDeliverySubMList", new object[] { map });
GridHelper.CopyDataToDatatable(dt, DTHandleSubM, true);
GridHelper.RefreshAndAutoSize(GridHandledSubM);
}
//加载退货单
if (!String.IsNullOrEmpty(hand.ReturnedSubId))
{
ExcDeliveryReturn er = new ExcDeliveryReturn();
er.ReturnId = hand.ReturnedSubId;
er.Validflag = "1";
DataTable dt2 = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryReturnService", "doQuery_Return", new object[] { er });
GridHelper.CopyDataToDatatable(dt2, DTReturnSubM, true);
GridHelper.RefreshAndAutoSize(GridReturnedSubM);
}
}
catch (Exception ex)
{
MessageUtil.ShowTips("加载处置单据异常:"+ex.Message);
}
}
private void GridReturnedSubM_AfterRowActivate(object sender, EventArgs e)
{
try
{
DTReturnSubD.Clear();
String strReturnId = GridReturnedSubM.ActiveRow.GetCellValue("RETURNID").ToString();
if (!String.IsNullOrEmpty(strReturnId))
{
ExcDeliveryReturnC erc = new ExcDeliveryReturnC();
erc.ReturnId = strReturnId;
erc.Validflag = "1";
DataTable dt3 = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryReturnCService", "find", new object[] { erc, 0, 0 });
GridHelper.CopyDataToDatatable(dt3, DTReturnSubD, true);
GridHelper.RefreshAndAutoSize(GridReturnedSubD);
}
}
catch (Exception ex)
{
MessageUtil.ShowTips("加载退货单行失败:" + ex.Message);
}
}
private void GridHandledSubM_AfterRowActivate(object sender, EventArgs e)
{
try
{
DTHandleSubD.Clear();
UltraGridRow uge = GridHandledSubM.ActiveRow;
String strDeliverySubId = uge.GetCellValue("deliverySubId").ToString().Trim();
if (!String.IsNullOrEmpty(strDeliverySubId))
{
ExcDeliverySubC EdSc = new ExcDeliverySubC();
EdSc.DeliverySubId = strDeliverySubId;
EdSc.Validflag = "1";
DataTable dt = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubCService", "Query_C", new object[] { EdSc });
GridHelper.CopyDataToDatatable(dt, DTHandleSubD, true);
GridHelper.RefreshAndAutoSize(GridHandledSubD);
}
}
catch (Exception ex)
{
MessageUtil.ShowTips("加载让步接收单行失败:" + ex.Message);
}
}
private void GridHandle_InitializeRow(object sender, InitializeRowEventArgs e)
{
if (e.Row.Cells["status"].Value.ToString().Equals("已作废"))
{
e.Row.Appearance.ForeColor = Color.Red;
}
else if (e.Row.Cells["status"].Value.ToString().Equals("已处置"))
{
e.Row.Appearance.ForeColor = Color.Gray;
}
else
{
e.Row.Appearance.ForeColor = Color.Black;
}
}
#endregion
#region 公共函数
///
/// 查询异常单信息
///
///
private void doQuerySubLine(String strDeliverySubId)
{
if (String.IsNullOrEmpty(strDeliverySubId))
{
MessageUtil.ShowTips("送货单号为空");
}
ExcDeliveryException hand = new ExcDeliveryException();
hand.DeliverySubId = strDeliverySubId;
hand.Validflag = "1";
if(txt_status.SelectedIndex!=-1)
{
//all:全部 wait:待处理 did:已处理
String strStatus=txt_status.Value.ToString().Trim();
if(strStatus=="wait")
{
hand.Status="1";
}
else if(strStatus=="did")
{
hand.Status="2";
}
}
DataTable dt = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryExceptionService", "doQuery_Exceptions", new object[] { hand });
GridHelper.CopyDataToDatatable(dt, DTHandle, true);
GridHelper.RefreshAndAutoSize(GridHandle);
}
///
/// 校验异常单
///
///
///
private bool testExceptionC(string strId, int i)
{
if (String.IsNullOrEmpty(strId))
{
MessageUtil.ShowTips("异常单号为空,或请刷新界面重试");
return false;
}
ExcDeliveryException hand = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryExceptionService", "findById", new object[] { strId });
if (hand == null)
{
MessageUtil.ShowTips("未发现异常单:" + strId + "信息记录,可能已被删除,或请刷新界面重试");
return false;
}
if (hand.Validflag != "1")
{
MessageUtil.ShowTips("异常单:" + strId + "信息记录可能已被删除,或请刷新界面重试");
return false;
}
if (i == 1)
{
if (hand.Status != "1")
{
MessageUtil.ShowTips("异常单:" + strId + "已处置,或请刷新界面重试");
return false;
}
}
else if (i == 2)
{
if (hand.Status != "2")
{
MessageUtil.ShowTips("异常单:" + strId + "不在已处置状态,或请刷新界面重试");
return false;
}
}
else
{
MessageUtil.ShowTips("参数异常");
return false;
}
return true;
}
#endregion
}
}