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 com.hnshituo.ck;
using Pur.Pop_upWindow;
using Infragistics.Win.UltraWinEditors;
using Pur.configure;
namespace Pur.ck
{
public partial class ExcDeliveryManagNewJL : FrmPmsBase
{
String WMmatcode = "";
String WMsuppCode = "";
String WMdeliveryCode = "";
public ExcDeliveryManagNewJL()
{
InitializeComponent();
try
{
string[] portnames = System.IO.Ports.SerialPort.GetPortNames(); //获取计算机串口数组
if (portnames is Infragistics.Win.UltraWinGrid.Nullable || portnames.Length < 1)
{
portnames = new string[10] { "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10" };
}
txt_com.DataSource = portnames;
this.txt_com.SelectedIndex = 0;
}
catch (Exception eex3)
{
MessageBox.Show(eex3.Message);
}
}
private void ExcDeliveryManagNewJL_Load(object sender, EventArgs e)
{
ck_isAllMeter.Checked = true;
ck_Ctime.Checked = false;
txt_CreateTimeS.Value = DateTime.Now.AddMonths(-1);
txt_CreateTimeS.Enabled = false;
txt_CreateTimeE.Value = Convert.ToDateTime(DateTime.Now.ToShortDateString()).AddHours(23).AddMinutes(59);
txt_CreateTimeE.Enabled = false;
Ck_Etime.Checked = true;
txt_PlanedShipDateS.Value = DateTime.Now.AddDays(-3);
txt_PlanedShipDateS.Enabled = true;
txt_PlanedShipDateE.Value = Convert.ToDateTime(DateTime.Now.AddDays(3));
txt_PlanedShipDateE.Enabled = true;
txt_length.SelectedIndex = 0;
ultraTabControl1.SelectedTab= ultraTabControl1.Tabs[0];
txt_QtyJL.ReadOnly = false;
txt_status.SelectedIndex = 1;//默认待发送计量委托
GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] {});
GridHelper.SetExcludeColumnsActive(ultraGrid2.DisplayLayout.Bands[0], new string[] {});
GridHelper.SetExcludeColumnsActive(ultraGrid3.DisplayLayout.Bands[0], new string[] {});
GridHelper.SetExcludeColumnsActive(ultraGrid4.DisplayLayout.Bands[0], new string[] {});
ultraExpandableGroupBox4.Expanded = true;
Get_ExcSubM();
}
#region toolbar工具栏
///
/// 菜单栏
///
///
///
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
Get_ExcSubM();
break;
case "Close":
this.Close();
break;
}
}
///
/// 查询
///
private void Get_ExcSubM()
{
try
{
//查询待计量的通知单头
this.Cursor = Cursors.WaitCursor;
clearSampleTabJL();
if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[1])
{
dataSet1.Clear();
Hashtable map = new Hashtable();
map.Add("deliverySubId", txt_deliverySubId.Text.Trim());
map.Add("orderId", txt_OrderId.Text.Trim());
map.Add("supperId", txt_suppCode.Text.Trim());
map.Add("validDataPurviewIds", this.ValidDataPurviewIds);
map.Add("itemCode", txt_itemCode.Text.ToString().Trim());
map.Add("itemName", txt_itemName.Text.ToString().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 (Ck_Etime.Checked && !string.IsNullOrEmpty(txt_PlanedShipDateS.Text))
{
map.Add("planedShipDate", Convert.ToDateTime(txt_PlanedShipDateS.Value));
}
if (Ck_Etime.Checked && !string.IsNullOrEmpty(txt_PlanedShipDateE.Text))
{
map.Add("planedDeliveryDate", Convert.ToDateTime(txt_PlanedShipDateE.Value));
}
if (txt_status.SelectedIndex != -1)
{
map.Add("statusJL", txt_status.Value.ToString().Trim());
}
DataTable dt = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubMService", "doQueryDeliverySubMList", new object[] { map });
GridHelper.CopyDataToDatatable(dt, dataTable1, true);
GridHelper.RefreshAndAutoSize(ultraGrid1);
}
else
{
dataSet2.Clear();
//通知单头
ExcDeliveryNoticeM EdnM = new ExcDeliveryNoticeM();
EdnM.OrderId = txt_OrderId.Text.ToString().Trim();
EdnM.NoticeId = txt_deliverySubId.Text.Trim();
if (ck_Ctime.Checked)
{
if (txt_CreateTimeS.Text != "")
{
EdnM.CreateTime = Convert.ToDateTime(txt_CreateTimeS.Value);
}
if (txt_CreateTimeE.Text != "")
{
EdnM.DeleteTime = Convert.ToDateTime(txt_CreateTimeE.Value);
}
}
if (Ck_Etime.Checked)
{
if (txt_PlanedShipDateS.Text != "")
{
EdnM.PlanedDeliveryDate = Convert.ToDateTime(txt_PlanedShipDateS.Value);
}
if (txt_PlanedShipDateE.Text != "")
{
EdnM.PlanedDeliveryDate = Convert.ToDateTime(txt_PlanedShipDateE.Value);
}
}
EdnM.ValidDataPurviewIds = this.ValidDataPurviewIds;
EdnM.SuppCode = txt_suppCode.Text.Trim();
EdnM.UpdateName = txt_itemName.Text.Trim();
EdnM.UpdateUserid = txt_itemCode.Text.Trim();
if (txt_status.SelectedIndex != -1)
{
EdnM.DeleteUserid = txt_status.Value.ToString().Trim();//是否需要计量
}
DataTable dt10 = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryNoticeMService", "find_Exc", new object[] { EdnM });
GridHelper.CopyDataToDatatable(dt10, dataTable3, true);
GridHelper.RefreshAndAutoSize(ultraGrid3);
}
}
catch (Exception ex)
{
MessageUtil.ShowTips("查询送货单主表数据失败:" + ex.Message);
}
finally
{
this.Cursor = Cursors.Default;
}
}
#endregion
#region 界面事件
///
/// 加载待计量送货单行
///
///
///
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
WMmatcode = "";
WMsuppCode = "";
WMdeliveryCode = "";
txt_message.Text = "";
queryDeliverySubC("");
}
///
/// 加载待计量通知单头
///
///
///
private void ultraGrid3_AfterRowActivate(object sender, EventArgs e)
{
WMmatcode = "";
WMsuppCode = "";
WMdeliveryCode = "";
txt_message.Text = "";
queryNoticeC("");
}
///
/// 选择计量的送货单行
///
///
///
private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
{
//根据物送货单行不允许编辑数量
try
{
if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[1])
{
WMmatcode = "";
WMsuppCode = "";
WMdeliveryCode = "";
txt_message.Text = "";
String strDeliverySubLineSqe = ultraGrid2.ActiveRow.GetCellValue("deliverySubLineSqe").ToString().Trim();
// String strDeliverySubId = ultraGrid2.ActiveRow.Cells["DeliverySubId"].Value.ToString().Trim();
//if (String.IsNullOrEmpty(strDeliverySubId))
//{
// MessageUtil.ShowTips("送货单号为空");
//}
if (String.IsNullOrEmpty(strDeliverySubLineSqe))
{
MessageUtil.ShowTips("送货单行号为空");
}
ExcDeliverySubC dsc = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubCService", "findById", new object[] { strDeliverySubLineSqe });
ExcDeliverySubM dsm = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubMService", "findById", new object[] { dsc.DeliverySubId });
//计量数据加载
txt_QtyJL.Text = dsc.Qty + "";
ck_meterFlag.Checked = dsc.MeteringFlag == null ? false : (dsc.MeteringFlag == "1" ? true : false);
if (ck_meterFlag.Checked)
{
ck_meterFlag.Enabled = true;
}
else
{
ck_meterFlag.Enabled = true;
}
txt_carNumJL.Text = dsc.CarNum;
txt_batchNo.Text = dsc.BatchNo;
CoreResult crt = new CoreResult();
if (dsc.ItemCode == "Y01010001")
{
crt.Resultcode = 0;
crt.Resultmsg = "105";
}
else
{
crt = this.execute("com.hnshituo.pur.jl.service.MeasureService", "getWMMatCode", new object[] { dsc.ItemCode });
}
CoreResult crt2 = this.execute("com.hnshituo.pur.jl.service.MeasureService", "getWMSuppCode", new object[] { dsm.SuppCode });
CoreResult crt3 = this.execute("com.hnshituo.pur.jl.service.MeasureService", "getWMdeliveryCode", new object[] { dsm.DeliveryLocation });
if (crt2.Resultcode != 0 || crt.Resultcode != 0 || crt3.Resultcode != 0)
{
if (crt.Resultcode != 0)
{
txt_message.Text = crt.Resultmsg + "\r\n";
}
else
{
WMmatcode = crt.Resultmsg;
}
if (crt2.Resultcode != 0)
{
txt_message.Text = txt_message.Text + crt2.Resultmsg + "\r\n";
}
else
{
WMsuppCode = crt2.Resultmsg;
}
if (crt3.Resultcode != 0)
{
txt_message.Text = txt_message.Text + crt3.Resultmsg + "\r\n";
}
else
{
WMdeliveryCode = crt3.Resultmsg;
}
return;
}
WMmatcode = crt.Resultmsg;
WMsuppCode = crt2.Resultmsg;
WMdeliveryCode = crt3.Resultmsg;
}
}
catch (Exception ex)
{
MessageUtil.ShowTips(ex.Message);
}
}
///
/// 选择计量的通知单行
///
///
///
private void ultraGrid4_AfterRowActivate(object sender, EventArgs e)
{
try
{
if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[0])
{
WMmatcode = "";
WMsuppCode = "";
WMdeliveryCode = "";
txt_message.Text = "";
//通知单行允许编辑数量
String strNoticeLineSqe = ultraGrid4.ActiveRow.GetCellValue("noticeLineSqe").ToString().Trim();
if (String.IsNullOrEmpty(strNoticeLineSqe))
{
MessageUtil.ShowTips("通知单行号为空");
}
ExcDeliveryNoticeC dsc = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryNoticeCService", "findById", new object[] { strNoticeLineSqe });
ExcDeliveryNoticeM dsm = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryNoticeMService", "findById", new object[] { dsc.NoticeId });
double dbcreatedQty = (double)(dsc.CreatedQty == null ? 0 : dsc.CreatedQty);
Double canJLQty = (double)dsc.Qty - dbcreatedQty;
//计量数据加载
txt_QtyJL.Text = canJLQty + "";
ck_meterFlag.Checked = dsc.MeteringFlag == null ? false : (dsc.MeteringFlag == "1" ? true : false);
if (ck_meterFlag.Checked)
{
ck_meterFlag.Enabled = false;
}
else
{
ck_meterFlag.Enabled = true;
}
txt_carNumJL.Text = "";
CoreResult crt = new CoreResult();
if (dsc.ItemCode == "Y01010001")
{
crt.Resultcode = 0;
crt.Resultmsg = "105";
}
else
{
crt = this.execute("com.hnshituo.pur.jl.service.MeasureService", "getWMMatCode", new object[] { dsc.ItemCode });
}
CoreResult crt2 = this.execute("com.hnshituo.pur.jl.service.MeasureService", "getWMSuppCode", new object[] { dsm.SuppCode });
CoreResult crt3 = this.execute("com.hnshituo.pur.jl.service.MeasureService", "getWMdeliveryCode", new object[] { dsm.DeliveryLocation });
if (crt2.Resultcode != 0 || crt.Resultcode != 0 || crt3.Resultcode != 0)
{
if (crt.Resultcode != 0)
{
txt_message.Text = crt.Resultmsg + "\r\n";
}
else
{
WMmatcode = crt.Resultmsg;
}
if (crt2.Resultcode != 0)
{
txt_message.Text = txt_message.Text + crt2.Resultmsg + "\r\n";
}
else
{
WMsuppCode = crt2.Resultmsg;
}
if (crt3.Resultcode != 0)
{
txt_message.Text = txt_message.Text + crt3.Resultmsg + "\r\n";
}
else
{
WMdeliveryCode = crt3.Resultmsg;
}
return;
}
WMmatcode = crt.Resultmsg;
WMsuppCode = crt2.Resultmsg;
WMdeliveryCode = crt3.Resultmsg;
}
}
catch (Exception ex)
{
MessageUtil.ShowTips("获取通知单行计量数据失败:" + ex.Message);
}
}
///
/// 创建时间
///
///
///
private void ck_Ctime_CheckedChanged(object sender, EventArgs e)
{
txt_CreateTimeS.Enabled = ck_Ctime.Checked;
txt_CreateTimeE.Enabled = ck_Ctime.Checked;
}
///
/// 交期控制
///
///
///
private void Ck_Etime_CheckedChanged(object sender, EventArgs e)
{
txt_PlanedShipDateS.Enabled = Ck_Etime.Checked;
txt_PlanedShipDateE.Enabled = Ck_Etime.Checked;
}
///
/// 通知单还是送货单控制
///
///
///
private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e)
{
clearSampleTabJL();
if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[0])
{
txt_QtyJL.ReadOnly = false;
clearJL();
queryNoticeC("");
}
else
{
clearJL();
txt_QtyJL.ReadOnly = false;
queryDeliverySubC("");
}
}
//清卡计量编辑区
private void clearJL()
{
txt_carNumJL.Clear();
txt_length.SelectedIndex = 0;
txt_batchNo.Clear();
}
///
/// 点击写卡
///
///
///
private void txt_addJL_Click(object sender, EventArgs e)
{
//if (ConnectCard() == false)
//{
// return;
//}
if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[0])
{
if (Write1() == true)
{
queryDeliverySubC("");
}
}
else if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[1])
{
if (Write() == true)
{
queryNoticeC("");
}
}
else
{
MessageUtil.ShowTips("请选择送货单或者通知单");
}
testConnectCard();
//ReadCard();
}
///
/// 测试连接
///
///
///
private void btn_testConnectJL_Click(object sender, EventArgs e)
{
testConnectCard();
}
///
/// 读卡
///
///
///
private void btn_testReadJL_Click(object sender, EventArgs e)
{
ReadCard();
}
///
/// 清卡
///
///
///
private void btn_clearIC_Click(object sender, EventArgs e)
{
Clear_IC_ChuKuDaTa();
}
#endregion
#region 读卡
private TalentICTGXControl.TalentICTGXClass icClass;
///
/// 连接
///
///
private bool getConnect()
{
try
{
txt_message.Text = "";
if (icClass == null)
{
icClass = new TalentICTGXControl.TalentICTGXClass();
//委托OnFindCard事件,icClass_OnFindCard是该事件要执行的方法。
//此事件在当IC卡放到读卡器上时触发。
icClass.OnFindCard += new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard);
}
//icClass.AlarmBeep(2);
string txtCom = txt_com.SelectedItem.ToString();
int comNum = (short)(short.Parse(txtCom.Replace("COM", "")) - 1);
icClass.CommPort = comNum;
if (!icClass.Active)
{
icClass.ToFindCard = true;
// MessageUtil.ShowTips("ConnectCard.icClass.Active: " + icClass.Active);
if (icClass.Active)
{
//MessageUtil.ShowTips("IC卡连接成功!");
txt_message.Text = "IC卡连接成功!" + "\r\n";
//AlarmBeep(int times)方法实现了让IC卡读卡器发出警示音,
//参数为发出几次警示音。
icClass.AlarmBeep(2);
return true;
}
else
{
txt_message.Text = "IC卡连接失败!或请切换端口尝试" + "\r\n";
return false;
}
}
else
{
return true;
}
}
catch (Exception e)
{
txt_message.Text = "IC卡连接失败!" + e.Message+"\r\n";
return false;
}
}
///
/// 关闭连接
///
///
private bool disConnect()
{
if (icClass.Active)
{
icClass.AlarmBeep(1);
//设置Active属性为false,则断开与读卡器的连接。
icClass.ToFindCard = false;
icClass.Active = false;
txt_message.Text =txt_message.Text+ "IC卡已断开与读卡器连接!" + "\r\n";
return true;
}
else
{
return true;
}
}
//出库清卡
private void Clear_IC_ChuKuDaTa()
{
if (getConnect() == false)
{
return;
}
//车辆已经计量完成或者不计量则清卡,车辆没有计量完成则不清卡
//清卡函数为 icClass.ClearCard
if ((icClass.grossA == 0) || ((icClass.grossA > 0) && (!string.IsNullOrEmpty(icClass.grosstime)) && (icClass.tareA > 0) && (!string.IsNullOrEmpty(icClass.taretime))))
{
if (MessageUtil.ShowYesNoAndQuestion("确定清卡?") != DialogResult.Yes)
{
return;
}
if (icClass.ClearCard() == true)
{
txt_message.Text = txt_message.Text + "IC卡已清卡!" + "\r\n";
}
else
{
txt_message.Text = txt_message.Text + "IC卡已清卡!" + "\r\n";
}
icClass.AlarmBeep(1);
}
}
///
/// 连接读卡器string txtCom = ultraComboEditor1.SelectedItem.ToString();
///
///
private bool ConnectCard()
{
try
{
txt_message.Text = "";
if (icClass == null)
{
icClass = new TalentICTGXControl.TalentICTGXClass();
//委托OnFindCard事件,icClass_OnFindCard是该事件要执行的方法。
//此事件在当IC卡放到读卡器上时触发。
icClass.OnFindCard += new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard);
}
//icClass.AlarmBeep(2);
string txtCom = txt_com.SelectedItem.ToString();
int comNum = (short)(short.Parse(txtCom.Replace("COM", "")) - 1);
icClass.CommPort = comNum;
if (icClass.Active)
{
icClass.Active = false;
txt_message.Text = "初始连接中!" + "\r\n";
}
if (!icClass.Active)
{
icClass.ToFindCard = true;
// MessageUtil.ShowTips("ConnectCard.icClass.Active: " + icClass.Active);
if (icClass.Active)
{
//MessageUtil.ShowTips("IC卡连接成功!");
txt_message.Text = "IC卡连接成功!" + "\r\n";
//AlarmBeep(int times)方法实现了让IC卡读卡器发出警示音,
//参数为发出几次警示音。
icClass.AlarmBeep(2);
return true;
}
else
{
txt_message.Text = "IC卡连接失败!或请切换端口尝试" + "\r\n";
return false;
}
}
else
{
txt_message.Text = "初始连接失败!" + "\r\n";
return false;
}
}
catch (Exception ex)
{
txt_message.Text = txt_message.Text+ex + "\r\n";
return false;
}
}
///
/// 测试连接读卡器string txtCom = ultraComboEditor1.SelectedItem.ToString();
///
///
private bool testConnectCard()
{
try
{
txt_message.Text = "";
icClass = new TalentICTGXControl.TalentICTGXClass();
//委托OnFindCard事件,icClass_OnFindCard是该事件要执行的方法。
//此事件在当IC卡放到读卡器上时触发。
icClass.OnFindCard += new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard);
//icClass.AlarmBeep(2);
string txtCom = txt_com.SelectedItem.ToString();
int comNum = (short)(short.Parse(txtCom.Replace("COM", "")) - 1);
icClass.CommPort = comNum;
if (!icClass.Active)
{
icClass.ToFindCard = true;
// MessageUtil.ShowTips("ConnectCard.icClass.Active: " + icClass.Active);
if (icClass.Active)
{
//MessageUtil.ShowTips("IC卡连接成功!");
txt_message.Text = "IC卡连接成功!" + "\r\n";
//AlarmBeep(int times)方法实现了让IC卡读卡器发出警示音,
//参数为发出几次警示音。
icClass.AlarmBeep(2);
return true;
}
else
{
txt_message.Text = "IC卡连接失败!或请切换端口尝试" + "\r\n";
return false;
}
}
else
{
icClass.AlarmBeep(1);
//设置Active属性为false,则断开与读卡器的连接。
icClass.ToFindCard = false;
icClass.Active = false;
txt_message.Text = "IC卡已断开与读卡器连接!" + "\r\n";
return false;
}
}
catch (Exception ex)
{
txt_message.Text = txt_message.Text + ex + "\r\n";
return false;
}
}
void icClass_OnFindCard()
{
icClass.OnFindCard -= new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard);
icClass.OnDropCard += new TalentICTGXControl.ITalentICTGXEvents_OnDropCardEventHandler(icClass_OnDropCard);
}
void icClass_OnDropCard()
{
//将OnDropCard事件从委托链中删除,并加入OnFindCard事件到委托链中。
//这样就实现了程序中自动寻卡的功能。
icClass.OnDropCard -= new TalentICTGXControl.ITalentICTGXEvents_OnDropCardEventHandler(icClass_OnDropCard);
icClass.OnFindCard += new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard);
}
//void icClass_OnConnect()
//{
// MessageUtil.ShowTips("icClass_OnConnect");
//}
//void icClass_OnError()
//{
// MessageUtil.ShowTips("icClass_OnError");
//}
///
/// 读卡
///
///
/// 读IC卡信息
///
private void ReadCard()
{
try
{
if (getConnect() == false)
{
return;
}
icClass.PrepareReadTemp();
if (icClass.DoReadTemp(1, 39))
{
txt_message.Text = txt_message.Text+"读卡成功!" + "\r\n";
}
else
{
txt_message.Text = txt_message.Text + "读卡失败!" + "\r\n";
}
//if (icClass.DoReadTemp(1, 39))
//{
int count = icClass.RecordCount;
//if (count == 0) //判断卡上的记录数
//{
// txt_message.Text = txt_message.Text + "读卡失败!" + "\r\n";
// return "";
//}
//else
//{
// icCardNo = icClass.ICNo;
//}
string strDeliverySubLineSqe = icClass.poorder;//订单号(最好8位,现在计量表中没有8位的单号,避免单号重复)
string suppCode=icClass.sourceunitcode;//供应商代码(计量系统)
string suppName=icClass.sourceunit;//客户名称
string itemCode=icClass.A_materialcode;//物料代码(计量系统)
string itemName=icClass.A_material;//物料名称tg
string deliveryLocationCode=icClass.targetunitcode ;//去向代码
string deliveryLocation=icClass.targetunit;//去向名称
string icCardNo = icClass.ICNo;
string carNo = icClass.carno;
String A_length = icClass.A_length;
icClass.EndReadTemp();
txt_message.Text = txt_message.Text + "卡号:" + icCardNo + "\r\n";
txt_message.Text = txt_message.Text + "车号:" + carNo + "\r\n";
disConnect();
if (String.IsNullOrEmpty(icCardNo))
{
txt_message.Text =txt_message.Text+ "或请点击“连接”按钮重试" +"\r\n";
return;
}
if (String.IsNullOrEmpty(carNo))
{
txt_message.Text = txt_message.Text + "若未读到信息请点击“连接”按钮重试" + "\r\n";
}
ExcDeliverySubC sub = new ExcDeliverySubC();
sub.DeliverySubId = icCardNo;
sub.DeliverySubLineSqe = strDeliverySubLineSqe;
sub.CreateUserid = suppCode;
sub.CreateName = suppName;
sub.ItemCode = itemCode;
sub.ItemName = itemName;
sub.UpdateName = deliveryLocation;
sub.UpdateUserid = deliveryLocationCode;
sub.DeleteName = A_length;
sub.CarNum = carNo;
frmPopJLDaTaReview frm = new frmPopJLDaTaReview(this.ob, sub);
frm.Text = "[" + icCardNo + "]" + "卡信息";
frm.ShowDialog();
// return icCardNo;
}
catch (Exception ex)
{
txt_message.Text = txt_message.Text+ex + "\r\n";
//return "-1";
}
}
///
/// 送货单写卡写IC卡信息
///
///
///
///
///
private bool Write()
{
if (testCode() == false)
{
return false;
}
if (getConnect() == false)
{
return false;
}
if (icClass == null)
{
return false;
}
//if (icClass.IsIC == false)
//{
// MessageUtil.ShowTips("请放IC卡!" + icClass.IsIC);
// return false;
//}
//else
{
if (ultraGrid2.ActiveRow == null)
{
MessageUtil.ShowTips("请选择发货单行进行操作!");
return false;
}
String strDeliverySubLineSqe = ultraGrid2.ActiveRow.GetCellValue("deliverySubLineSqe").ToString().Trim();
if (String.IsNullOrEmpty(strDeliverySubLineSqe))
{
MessageUtil.ShowTips("送货单行号为空");
}
ExcDeliverySubC dsc = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubCService", "findById", new object[] { strDeliverySubLineSqe });
if (dsc.MeteringFlag != "1")
{
if (MessageUtil.ShowYesNoAndQuestion("该物料不需要过磅,是否继续操作 ?") != DialogResult.Yes)
{
return false;
}
}
if (dsc.Ismeter == "1")
{
if (MessageUtil.ShowYesNoAndQuestion("该物料已委托计量,确定再次写卡 ?") != DialogResult.Yes)
{
return false;
}
}
String strDeliverySubId = dsc.DeliverySubId;
if (String.IsNullOrEmpty(strDeliverySubId))
{
MessageUtil.ShowTips("送货单号为空");
return false;
}
ExcDeliverySubM dsm = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubMService", "findById", new object[] { strDeliverySubId });
String suppCode = dsm.SuppCode;
String suppName = dsm.SuppName;
String deliveryLocationCode = dsm.DeliveryLocationCode;
String deliveryLocation = dsm.DeliveryLocation;
String itemCode = dsc.ItemCode;
String itemName = dsc.ItemName;
if (txt_carNumJL.Text.Trim() == "")
{
MessageUtil.ShowTips("车号不能为空!");
txt_carNumJL.Focus();
return false;
}
if (MessageUtil.ShowYesNoAndQuestion("确定生成供方:" + suppName + " 的计量委托?") != DialogResult.Yes)
{
return false;
}
icClass.PrepareWriteTemp();
icClass.taskcode = "9";
icClass.operatype = "9";//
icClass.card_initflag = "3";//
//icClass.totalcount = int.Parse(strDeliverySubLineSqe.Replace(orderId, "")); //送货单行号的序号
icClass.carno = txt_carNumJL.Text.Trim();//车号
icClass.poorder = strDeliverySubLineSqe;//订单号(最好8位,现在计量表中没有8位的单号,避免单号重复)
icClass.A_materialcode = WMmatcode;//物料代码(计量系统)
icClass.sourceunitcode = WMsuppCode;//供应商代码(计量系统)
icClass.sourceunit = suppName;//客户名称
icClass.A_material = itemName;//物料名称tg
icClass.targetunitcode = WMdeliveryCode;//去向代码
icClass.targetunit = deliveryLocation;//去向名称
icClass.A_length = txt_length.Value.ToString().Trim();//是否每车刷卡 1:是(每次都要刷卡)0:否(此车只刷一次卡,长期有效)
icClass.DoWriteTemp();
if (icClass.Errored == true)
{
txt_message.Text = txt_message.Text + "写IC卡错误,请重新点击确认" + "\r\n";
// MessageUtil.ShowTips("写IC卡错误,请重新点击确认!");
return false;
}
if (icClass.Active)
{
icClass.AlarmBeep(3);
txt_message.Text = txt_message.Text + "写IC卡完成" + "\r\n";
//MessageUtil.ShowTips("写IC卡完成。");
disConnect();
//修改送货单行状态
ExcDeliverySubC EdnC = new ExcDeliverySubC();
EdnC.DeliverySubLineSqe = strDeliverySubLineSqe;
EdnC.Ismeter = "1";
EdnC.MeteringFlag = "1";
CoreResult crt = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubCService", "doUpdate", new object[] { EdnC });
}
}
return true;
}
///
/// 通知单行写卡写IC卡信息
///
///
///
///
///
private bool Write1()
{
if (testCode() == false)
{
return false;
}
if (getConnect() == false)
{
return false;
}
if (icClass == null)
{
return false;
}
//if (icClass.IsIC == false)
//{
// MessageUtil.ShowTips("请放IC卡!" + icClass.IsIC);
// return false;
//}
//else
{
if (ultraGrid4.ActiveRow == null)
{
MessageUtil.ShowTips("请选择通知单行进行操作!");
return false;
}
String strNoticeLineSqe = ultraGrid4.ActiveRow.GetCellValue("noticeLineSqe").ToString().Trim();
if (String.IsNullOrEmpty(strNoticeLineSqe))
{
MessageUtil.ShowTips("通知单行号为空");
}
ExcDeliveryNoticeC dsc = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryNoticeCService", "findById", new object[] { strNoticeLineSqe });
if (dsc.MeteringFlag != "1")
{
if (MessageUtil.ShowYesNoAndQuestion("该物料不需要过磅,是否继续操作 ?") != DialogResult.Yes)
{
return false;
}
}
if (txt_QtyJL.Value == null)
{
MessageUtil.ShowTips("请输入计量重量");
}
double dbCreateQty = Convert.ToDouble(txt_QtyJL.Value);
double dbcreatedQty=(double)(dsc.CreatedQty == null ? 0 :dsc.CreatedQty);
Double canJLQty = (double)dsc.Qty - dbcreatedQty;
if (canJLQty<=0)
{
MessageUtil.ShowTips("已经全部生成送货单,或请采用送货单进行发送计量委托");
return false;
}
if (dbCreateQty > canJLQty)
{
MessageUtil.ShowTips("该通知单行最大可编制:" + canJLQty);
return false;
}
String strNoticeId = dsc.NoticeId;
ExcDeliveryNoticeM dsm = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryNoticeMService", "findById", new object[] { strNoticeId });
//准备数据写入
ExcDeliverySubM sm = new ExcDeliverySubM();
sm.NoticeId = strNoticeId;
sm.Status = "1";
sm.OrderId = dsm.OrderId;
sm.DeliveryLocationCode = dsm.DeliveryLocationCode;
sm.DeliveryLocation = dsm.DeliveryLocation;
sm.SuppCode = dsm.SuppCode;
sm.SuppName = dsm.SuppName;
sm.PlanedDeliveryDate = DateTime.Now;
sm.Validflag = "1";
sm.CreateName = UserInfo.GetUserName();
sm.CreateUserid = UserInfo.GetUserID();
sm.CreateTime = DateTime.Now;
sm.DeliveryCondition = dsm.DeliveryCondition;
sm.BuyerDeptCode = UserInfo.GetDeptid();
sm.DeliveryType = dsm.DeliveryType;
sm.ReceiveType = dsc.ReceiveType;
List list = new List();
ExcDeliverySubC sc = new ExcDeliverySubC();
sc.NoticeId = strNoticeId;
sc.OrderId = dsc.OrderId;
sc.OrderLineSqe = dsc.OrderLineSqe;
sc.NoticeLineSqe = dsc.NoticeLineSqe;
sc.ItemCode = dsc.ItemCode;
sc.ItemDesc = dsc.ItemDesc;
sc.ItemDescE = dsc.ItemDescE;
sc.ItemName = dsc.ItemName;
sc.ItemUom = dsc.ItemUom;
sc.ItemUomId = dsc.ItemUomId;
sc.WeightUnit = dsc.WeightUnit;
sc.ItemUomConefficient = dsc.ItemUomConefficient;
sc.ItemUseUom = dsc.ItemUseUom;
sc.ItemAttr = dsc.ItemAttr;//物料属性
sc.ItemAttrId = dsc.ItemAttrId;//属性编码
sc.ItemStandardsCode = dsc.ItemStandardsCode;
sc.ItemStandardsId = dsc.ItemStandardsId;
sc.ItemUnique = dsc.ItemUnique;
sc.Qty = dbCreateQty;//送货数量
String strBatchNo = txt_batchNo.Text.Trim();
if (dsc.BatchFlag == "1")//批次控制
{
if (String.IsNullOrEmpty(strBatchNo))
{
MessageUtil.ShowTips("物料:" + dsc.ItemName + "为批次控制物料,请输入生成批次号!");
return false;
}
}
sc.BatchNo = strBatchNo;
if (String.IsNullOrEmpty(txt_carNumJL.Text.Trim()))
{
MessageUtil.ShowTips("请输入车号!");
return false;
}
String strCarNumC = txt_carNumJL.Text.Trim();
sc.CarNum = strCarNumC;
sc.ReceiveType = dsc.ReceiveType;
sc.BuyerName = dsc.BuyerName;
sc.MeteringFlag ="1";
sc.BatchFlag = dsc.BatchFlag;
sc.PcFlag = dsc.PcFlag;
sc.Ismeter = "1";
sc.CreateName = UserInfo.GetUserName();
sc.CreateUserid = UserInfo.GetUserID();
sc.CreateTime = DateTime.Now;
sc.Validflag = "1";
sc.Status = "1";//待收货
sc.ShippedQty = 0;
sc.ShipQty = 0;
sc.ReceivedQty = 0;
sc.PackageType = dsc.PackageType;
list.Add(sc);
if (MessageUtil.ShowYesNoAndQuestion("确定生成供方:" + dsm.SuppName + "的计量委托?") != DialogResult.Yes)
{
return false;
}
CoreResult re = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubMService", "insert_PC", new object[] { sm, list });
if (re.Resultcode != 0)
{
MessageUtil.ShowTips("发送计量委托失败:生成送货单失败" + re.Resultmsg);
return false;
}
String suppCode = dsm.SuppCode;
String suppName = dsm.SuppName;
String deliveryLocationCode = dsm.DeliveryLocationCode;
String deliveryLocation = dsm.DeliveryLocation;
String itemCode = dsc.ItemCode;
String itemName = dsc.ItemName;
String strDeliverySubId = re.Resultmsg;
String strDeliverySubLineSqe = re.Resultdata.ToString();
if (String.IsNullOrEmpty(strDeliverySubId))
{
MessageUtil.ShowTips("送货单号为空");
}
if (String.IsNullOrEmpty(strDeliverySubLineSqe))
{
MessageUtil.ShowTips("送货单行号为空");
}
icClass.PrepareWriteTemp();
icClass.taskcode = "9";
icClass.operatype = "9";//
icClass.card_initflag = "3";//
//icClass.totalcount = int.Parse(strDeliverySubLineSqe.Replace(orderId, "")); //送货单行号的序号
icClass.carno = txt_carNumJL.Text;//车号
icClass.poorder = strDeliverySubLineSqe;//订单号(最好8位,现在计量表中没有8位的单号,避免单号重复)
icClass.sourceunit = suppName;//客户名称
icClass.A_materialcode = WMmatcode;//物料代码(计量系统)
icClass.sourceunitcode = WMsuppCode;//供应商代码(计量系统)
icClass.A_material = itemName;//物料名称tg
icClass.targetunitcode = WMdeliveryCode;//去向代码
icClass.targetunit = deliveryLocation;//去向名称
icClass.A_length = txt_length.Value.ToString().Trim();//是否每车刷卡 1:是(每次都要刷卡)0:否(此车只刷一次卡,长期有效)
icClass.B_memo = memo.Text;
icClass.DoWriteTemp();
if (icClass.Errored == true)
{
txt_message.Text = txt_message.Text + "写IC卡错误,请重新点击确认" + "\r\n";
//MessageUtil.ShowTips("写IC卡错误,请重新点击确认!");
return false;
}
if (icClass.Active)
{
icClass.AlarmBeep(3);
txt_message.Text = txt_message.Text + "写IC卡完成,同时生成送货单:" +strDeliverySubId+ "\r\n";
// MessageUtil.ShowTips("写IC卡完成。");
disConnect();
}
}
return true;
}
private bool testCode()
{
if (WMmatcode.Trim() == "" || WMsuppCode.Trim() == "" || WMdeliveryCode.Trim() == "")
{
if (WMmatcode.Trim() == "")
{
txt_message.Text = txt_message.Text + "该物料编码未在计量系统维护,请联系计控维护" + "\r\n";
}
if (WMsuppCode.Trim() == "")
{
txt_message.Text = txt_message.Text + "该供方编码未在计量系统维护,请联系计控维护" + "\r\n";
}
if (WMdeliveryCode.Trim() == "")
{
txt_message.Text = txt_message.Text + "该交付地址未在计量系统维护,请联系计控维护" + "\r\n";
}
return false;
}
return true;
}
#endregion
#region 公共用函数
private bool testSubC(string strDeliverySubLineSqe)
{
ExcDeliverySubC dsc = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubCService", "findById", new object[] { strDeliverySubLineSqe });
if (dsc == null)
{
MessageUtil.ShowTips("未发现送货单行:" + strDeliverySubLineSqe + "信息记录,可能已被删除,或请刷新界面重试");
return false;
}
if (dsc.Validflag != "1")
{
MessageUtil.ShowTips("送货单行:" + strDeliverySubLineSqe + "信息记录可能已被删除,或请刷新界面重试");
return false;
}
if (!String.IsNullOrEmpty(dsc.CheckNo))
{
MessageUtil.ShowTips("送货单行:" + strDeliverySubLineSqe + "已生成检化验委托,无需重复操作!");
return false;
}
return true;
}
//清空jl编辑区
private void clearSampleTabJL()
{
txt_QtyJL.Value = 0;
ck_meterFlag.Checked = false;
ck_meterFlag.Enabled = true;
txt_carNumJL.Clear();
}
///
/// 校验检验号是否可以作废
///
///
///
private bool testSampleNo(string strCheckNo)
{
CheckconsignDetail detail = new CheckconsignDetail();
detail.CheckNo = strCheckNo;
List list = this.execute>("com.hnshituo.pur.ck.service.CheckconsignDetailService", "find", new object[] { detail, 0, 0 });
if (list != null)
{
if (list.Count > 0)
{
foreach (CheckconsignDetail det in list)
{
if (det.Flag != "-1")
{
MessageUtil.ShowTips("该检化验项委托可能已发送,不能作废!");
return false;
}
}
}
else
{
MessageUtil.ShowTips("未发现检化验号:" + strCheckNo + "检验项明细!");
return false;
}
}
else
{
MessageUtil.ShowTips("未发现检化验号:" + strCheckNo + "检验项明细!");
return false;
}
return true;
}
///
/// 初检或者取消初检校验
///
///
///
///
private bool testDeliveryStatus(String deliverySubId, int p)
{
if (String.IsNullOrEmpty(deliverySubId))
{
MessageUtil.ShowTips("送货单行号为空,无法校验数据有效性");
return false;
}
ExcDeliverySubC subc = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubCService", "findById", new object[] { deliverySubId });
if (subc == null)
{
MessageUtil.ShowTips("未发现送货单行:" + deliverySubId + "信息记录,可能已作废,或请刷新界面重试");
return false;
}
if (subc.Validflag != "1")
{
MessageUtil.ShowTips("未发现送货单行:" + deliverySubId + "信息记录,可能已作废,或请刷新界面重试");
return false;
}
String testStatus = subc.Status;
if (String.IsNullOrEmpty(subc.DeliverySubId))
{
MessageUtil.ShowTips("未找到送货单行的头信息");
return false;
}
ExcDeliverySubM subM = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubMService", "findById", new object[] { subc.DeliverySubId });
if (subM == null)
{
MessageUtil.ShowTips("未发现送货单:" + subc.DeliverySubId + "信息记录,可能已作废,或请刷新界面重试");
return false;
}
if (subM.Validflag != "1")
{
MessageUtil.ShowTips("未发现送货单:" + subc.DeliverySubId + "信息记录,可能已作废,或请刷新界面重试");
return false;
}
if (subM.Status != "1")
{
MessageUtil.ShowTips("送货单:" + subc.DeliverySubId + "可能已经收货完成,或请刷新界面重试");
return false;
}
//完成初检校验
if (p == 1)
{
if (testStatus != "1")
{
MessageUtil.ShowTips("送货单行:" + deliverySubId + "可能已经初检完成,或请刷新界面重试");
return false;
}
}
//取消初检校验
else if (p == 2)
{
if (testStatus != "2" && testStatus != "3")
{
MessageUtil.ShowTips("送货单行:" + deliverySubId + "可能还未完成初检或已经(待检)入库,或请刷新界面重试");
return false;
}
}
else
{
MessageUtil.ShowTips("未知参数:" + p);
return false;
}
return true;
}
///
/// 查询送货单行
///
private void queryDeliverySubC(String tips)
{
try
{
dataTable2.Clear();
UltraGridRow uge = ultraGrid1.ActiveRow;
if (uge == null)
{
return;
}
String strDeliverySubId = uge.GetCellValue("deliverySubId").ToString().Trim();
if (String.IsNullOrEmpty(strDeliverySubId))
{
MessageUtil.ShowTips("送货单号为空");
}
if (tips != "0")
{
dataTable2.Clear();
ultraGrid2.Update();
}
ExcDeliverySubC EdSc = new ExcDeliverySubC();
EdSc.DeliverySubId = strDeliverySubId;
EdSc.Validflag = "1";
if (ck_isAllMeter.Checked)
{
EdSc.MeteringFlag = "1";
}
if (txt_status.SelectedIndex == 1)//待计量
{
EdSc.Ismeter = "0";
}
else if (txt_status.SelectedIndex == 2)//已经计量
{
EdSc.Ismeter = "1";
}
else//全部
{
//
}
DataTable dt = this.execute("com.hnshituo.pur.ck.service.ExcDeliverySubCService", "Query_C", new object[] { EdSc });
GridHelper.CopyDataToDatatable(dt, dataTable2, true);
GridHelper.RefreshAndAutoSize(ultraGrid2);
}
catch (Exception ex)
{
MessageUtil.ShowTips("加载送货单行信息失败:" + ex);
}
}
///
/// 查询通知单行
///
private void queryNoticeC(String tips)
{
try
{
dataTable4.Clear();
UltraGridRow uge = ultraGrid3.ActiveRow;
if (uge == null)
{
return;
}
String strNoticeId = uge.Cells["NoticeId"].Value.ToString();
if (tips!= "0")
{
dataTable4.Clear();
ultraGrid4.Update();
}
ExcDeliveryNoticeC EdnC = new ExcDeliveryNoticeC();
EdnC.NoticeId = strNoticeId;
EdnC.Validflag = "1";
if (ck_isAllMeter.Checked)
{
EdnC.MeteringFlag = "1";
}
if (txt_status.SelectedIndex == 1)//待计量
{
EdnC.DeleteUserid = "0";
}
else if (txt_status.SelectedIndex == 2)//已经计量
{
EdnC.DeleteUserid = "1";
}
else//全部
{
//
}
DataTable dt = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryNoticeCService", "find_EdnC", new object[] { EdnC });
GridHelper.CopyDataToDatatable(dt, dataTable4, true);
GridHelper.RefreshAndAutoSize(ultraGrid4);
}
catch (Exception ex)
{
MessageUtil.ShowTips("加载通知单行信息失败:" + ex);
}
}
#endregion
private void txt_length_TextChanged(object sender, EventArgs e)
{
if(txt_length.Text.ToString()=="每车刷卡")
{
txt_length.Value = "1";
}
else
{
txt_length.Value = "0";
}
}
}
}