using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraGrid.Views.Base;
//using DeiNiu.wms.Logical;
using DeiNiu.wms.Data;
using DevExpress.XtraGrid.Columns;
using System.Threading;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraEditors.DXErrorProvider;
using DeiNiu.wms.Data.Model;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DeiNiu.Utils;
using DevExpress.XtraEditors.Repository;
// using DeiNiu.wms.win.ServiceReferenceOutRequest; //远程
using DeiNiu.wms.win.ServiceReferenceStockOutRequest;
using DeiNiu.wms.win.ServiceReferenceStockOutPickRequest;
using Deiniu.win.elelab;
using DNLightSvr;
using System.ServiceModel;
using System.ServiceModel.Description; //开发环境
// using DeiNiu.wms.win.ServiceReferenceOutRequestLocal;//本地
namespace DeiNiu.wms.win
{
public partial class GoodsOutServiceForm : BasicRibbonForm
{
private string lastQuery = "";
private DataTable dtPickOrders;
private int selectedRowIndex = -1;
private WmsOutPickRequest selectedRequest;
int preCnt = 0;
Thread threadPreProcess;
bool autoOrder, autoWave =true;
bool isManualRefreshPickList = false;
// string currentWaveOrder = "";
DataTable dtException;
DataTable dtBulks;
WmsOutPickDetail_tmp exceptionDetail;
int selectedLine = -1;
string selectedSales = "";
public GoodsOutServiceForm()
{
debug("start 出库。。。。。。");
lightPart.lightOffEvent += partFinished;
InitializeComponent();
initialControls();
initialBackGroundTasks();
isLoading = false;
startHost();
debug("end 出库。。。。。。");
}
#region initialControls
bool isLoading = true;
private void initialControls()
{
// initialPagerControls();
initialDataGrid();
initialQueryInput();
setValidationRule();
initialTimer();
// updateLightsStatus();
getPartFinishIds();
}
private void initialBackGroundTasks()
{
lightAllLabels();
Thread threadPreProcess = new Thread(searchLight);
threadPreProcess.IsBackground = true;
threadPreProcess.Start();
}
void lightAllLabels()
{
loadWaveDetails();
initLights();
string result = lightPart.lightsUp(pickClient.getPartPickedData((int)enumPickState.未拣), enumLabelPickType.pick);
closeClient();
}
private void setValidationRule()
{
// dxValidationProvider.SetValidationRule(comWarehouse, ValidationRules.notEmptyValidationRule);
//txtGoodType.Properties.MaxLength = 40;
//txtGoodDesc.Properties.MaxLength = 250;
//textEdit1.Properties.MaxLength = txtGoodType.Properties.MaxLength;
}
private void initialQueryInput()
{
}
private void initialGridView3Columns(GridView gridview)
{
{
setupGridView(gridview, true, true, false);
}
gridview.FocusRectStyle = DrawFocusRectStyle.None;
// gridviewGoodsType.PopulateColumns();
gridview.Columns.Clear();
// gridviewGoodsType.Columns.Remove(gridviewGoodsType.Columns["DealerPrice"]);
GridColumn myCol0 = new GridColumn() { Caption = "ID", Visible = true, FieldName = "id" };
myCol0.Visible = false;
gridview.Columns.Add(myCol0);
GridColumn myCol011 = new GridColumn() { Caption = "分区", Visible = true, FieldName = "partName" };
gridview.Columns.Add(myCol011);
GridColumn myCol1 = new GridColumn() { Caption = "商品编码", Visible = true, FieldName = WmsGoods.fields.goodsId.ToString() };
GridColumn myCol2 = new GridColumn() { Caption = "商品名称", Visible = true, FieldName = WmsGoods.exfields.goodsName.ToString() };
GridColumn myCol3 = new GridColumn() { Caption = "厂家", Visible = true, FieldName = WmsGoods.exfields.manufacturer.ToString() };
GridColumn myCol4 = new GridColumn() { Caption = "规格", Visible = true, FieldName = WmsGoods.exfields.spec.ToString() };
GridColumn myCol5 = new GridColumn() { Caption = "单位", Visible = true, FieldName = WmsGoods.exfields.unit.ToString() };
// GridColumn myCol6 = new GridColumn() { Caption = "大包装数量", Visible = true, FieldName = WmsGoods.exfields.bigCount.ToString() };
GridColumn myCol7 = new GridColumn() { Caption = "剂型", Visible = true, FieldName = WmsGoods.exfields.type.ToString() };
GridColumn myCol8 = new GridColumn() { Caption = "商品类型", Visible = true, FieldName = WmsGoods.exfields.goodsTypeName.ToString() };
// GridColumn myCol9 = new GridColumn() { Caption = "大零", Visible = true, FieldName = WmsGoods.fields.bulkMax.ToString() };
// GridColumn myCol10 = new GridColumn() { Caption = "小整", Visible = true, FieldName = WmsGoods.fields.batchMax1.ToString() };
// GridColumn myCol11 = new GridColumn() { Caption = "大整", Visible = true, FieldName = WmsGoods.fields.batchMax2.ToString() };
GridColumn myCol12 = new GridColumn() { Caption = "国药准字", Visible = true, FieldName = WmsGoods.exfields.regeditCode.ToString() };
GridColumn myCol100 = new GridColumn() { Caption = "数量", Visible = true, FieldName = WmsOutDetail.fields.count.ToString() };
GridColumn myCol101 = new GridColumn() { Caption = "零货", Visible = true, FieldName = WmsOutDetail.fields.count.ToString() };
// GridColumn myCol102 = new GridColumn() { Caption = "整货", Visible = true, FieldName = WmsOutDetail.fields.batch1Count.ToString() };
// GridColumn myCol103 = new GridColumn() { Caption = "大整", Visible = true, FieldName = WmsOutDetail.fields.batch2Count.ToString() };
// GridColumn myCol104 = new GridColumn() { Caption = "箱", Visible = true, FieldName = WmsOutDetail.fields.boxcnt.ToString() };
GridColumn myCol14 = new GridColumn() { Caption = "批号", Visible = true, FieldName = WmsOutDetail.fields.batch.ToString() };
GridColumn myCol15 = new GridColumn() { Caption = "生产日期", Visible = true, FieldName = WmsOutDetail.fields.productDate.ToString() };
GridColumn myCol16 = new GridColumn() { Caption = "有效期", Visible = true, FieldName = WmsOutDetail.fields.validDate.ToString() };
GridColumn myCol17 = new GridColumn() { Caption = "状态", Visible = true, FieldName = WmsOutDetail.fields.state.ToString() };
GridColumn myCol18 = new GridColumn() { Caption = "说明", Visible = true, FieldName = WmsOutDetail.fields.description.ToString() };
GridColumn myCol20 = new GridColumn() { Caption = "波次", Visible = true, FieldName = WmsOutPickLable.fields.dpsOrder.ToString() };
GridColumn myCol21 = new GridColumn() { Caption = "颜色", Visible = true, FieldName = "colorName" };
GridColumn myCol22 = new GridColumn() { Caption = "货位", Visible = true, FieldName = WmsOutPickLable.fields.locationId.ToString() };
GridColumn myCol23 = new GridColumn() { Caption = "标签", Visible = true, FieldName = WmsOutPickLable.fields.elabId.ToString() };
GridColumn myCol24 = new GridColumn() { Caption = "客户", Visible = true, FieldName = WmsOutPickRequest.fields.customerName.ToString() };
GridColumn myCol25 = new GridColumn() { Caption = "出库单", Visible = true, FieldName = WmsOutPickRequest.fields.pickOrderNo.ToString() };
GridColumn myCol26 = new GridColumn() { Caption = "复核异常", Visible = true, FieldName = "exception" };
GridColumn myCol27 = new GridColumn() { Caption = "复核数量", Visible = true, FieldName = WmsOutPickDetail.fields.confirmedCount.ToString() };
GridColumn myCol28 = new GridColumn() { Caption = "说明", Visible = true, FieldName = WmsOutPickDetail.fields.validRemark.ToString() };
GridColumn myCol281 = new GridColumn() { Caption = "复核台", Visible = true, FieldName = "desk" };
GridColumn myCol29 = new GridColumn() { Caption = "标签点亮", Visible = true, FieldName = "isLightUp" };
GridColumn myCol30 = new GridColumn() { Caption = "拣货状态", Visible = true, FieldName = "isPicked" };
GridColumn myCol31 = new GridColumn() { Caption = "输送口", Visible = true, FieldName = "desk" };
RepositoryItemImageComboBox repositoryImageComboBox2 = new RepositoryItemImageComboBox();//新建一个RepositoryItemImageComboBox
repositoryImageComboBox2.GlyphAlignment = DevExpress.Utils.HorzAlignment.Center;
repositoryImageComboBox2.SmallImages = imageList1; //指定一组图片
string[] s = new String[] {"1","0"};
for (int i = 0; i < s.Length; i++)
repositoryImageComboBox2.Items.Add(new ImageComboBoxItem(s[i], i + 1, i));//对应值绑定对应的图片
RepositoryItem ri = repositoryImageComboBox2 as RepositoryItem;
myCol29.ColumnEdit = ri; //绑定到GridColumn
myCol30.ColumnEdit = ri;
if (WmsConstants.OUT_LIGHT_ENABLE)
{
gridview.Columns.Add(myCol29);
gridview.Columns.Add(myCol30);
}
gridview.Columns.Add(myCol25);
gridview.Columns.Add(myCol21);
gridview.Columns.Add(myCol22);
gridview.Columns.Add(myCol23);
gridview.Columns.Add(myCol101);
gridview.Columns.Add(myCol5);
// gridview.Columns.Add(myCol17);
gridview.Columns.Add(myCol24);
gridview.Columns.Add(myCol31);
gridview.Columns.Add(myCol7);
gridview.Columns.Add(myCol14);
gridview.Columns.Add(myCol3);
gridview.Columns.Add(myCol15);
gridview.Columns.Add(myCol16);
gridview.Columns.Add(myCol3);
gridview.Columns.Add(myCol8);
//gridview.Columns.Add(myCol9);
gridview.Columns.Add(myCol2);
// gridview.Columns.Add(myCol6);
gridview.Columns.Add(myCol4);
gridview.Columns.Add(myCol12);
gridview.Columns.Add(myCol1);
gridview.Columns.Add(myCol18);
//to show bottom scroll bar
gridview.OptionsView.ColumnAutoWidth = false;
gridview.BestFitColumns();
// gridView2.Focus();
}
#endregion
DateTime lastRefreshTime;
int refreshInterval = 15;
//完成任务时需要调用
delegate void loadNewPickOrders();
///
/// 更新拣选明细
///
private void updatePickDetails() {
}
DateTime lastWaveRequestTime;
delegate void loadNewCurrentWave();
///
/// start new wave
///
public void waveStart() {
//swAutoWave.Enabled = true;
//btnNewWave.Enabled = !autoWave;
// loadWaveDetails();
TimeSpan ts = DateTime.Now - lastWaveRequestTime;
if (ts.TotalDays >10)
{
lastWaveRequestTime = DateTime.Now;
return;
}
else
{
int sleepTime = 5;// (int)spinWave.Value;//波次间隔 5s
if (ts.TotalSeconds < sleepTime)
{
return;
}
}
if (!canNewWave) // if (!lgt.canNewWave)
{
return;
}
if (autoWave)
{
// int sleepTime = (int) spinWave.Value * 1000;//波次间隔 5s
//while (!lgt.canNewWave)
//{
// Thread.CurrentThread.Join(1000);
//}
// Thread.CurrentThread.Join(sleepTime);
this.clearWaveData();
newWave();
lastWaveRequestTime = DateTime.Now;
}
else
{
// btnNewWave.Enabled = dtBulks== null || dtBulks.Rows.Count == 0 ;
}
}
void loadWaveDetails()
{
debug("start to loadWaveDetails.....");
if (InvokeRequired)
{
this.Invoke(new loadNewCurrentWave(delegate()
{
// swAutoWave.Enabled = true;
// btnNewWave.Enabled = !autoWave;
this.loadPickOrdersInWave();
// this.loadPickOrders();//更新等待订单列表
// btnEndWave.Enabled = true;
}));
}
else
{
// swAutoWave.Enabled = true;
// btnNewWave.Enabled = !autoWave;
this.loadPickOrdersInWave();
// btnEndWave.Enabled = true;
}
debug("end loadWaveDetails....");
}
// Thread threadNewWave;
private void newWave()
{
try
{
debug("start to create new wave .....");
Thread threadNewWave = new Thread(newPickWave);
threadNewWave.IsBackground = true;
threadNewWave.Start();
// loadWaveDetails();
// lgt.newPickWave();
debug(" create new wave in new thread.....");
}
catch (DeiNiuException de)
{
showErrorMsg(de.Message);
}
catch (Exception er)
{
showErrorMsg(er.Message);
}
}
private void loadPickOrdersInWave()
{
debug("start loadPickOrdersInWave.....");
//showWaitForm();
try
{
// dtBulks = lgt.getWmsOutPickRequest.getBulkDetailInCurrentWave().Tables[0];
dtBulks = pickClient.getPartionBulkDetailInCurrentWave();
closeClient();
gridControl2.DataSource = null;
updateLableStatus(dtBulks);
debug(string.Format("load bulk details in current wave,count {0} ", dtBulks.Rows.Count));
gridControl3.DataSource = dtBulks.DefaultView;
initialGridView3Columns(gridView3);
// btnRelight.Enabled = dtBulks.Rows.Count > 0;
WmsConstants.WAVE_CURRENT_ORDER = "";
// btnNewWave.Enabled = dtBulks.Rows.Count == 0;
if (dtBulks.Rows.Count > 0)
{
WmsConstants.WAVE_LAST_FREE_TIME = DateTime.MinValue;
//if (string.IsNullOrEmpty(WmsConstants.WAVE_CURRENT_ORDER))
{
string waveStarTime = dtBulks.Rows[0]["createtime"].ToString();
DateTime lastWaveTime = Convert.ToDateTime(waveStarTime);
string currentWaveOrder = dtBulks.Rows[0]["dpsOrder"].ToString();
WmsConstants.WAVE_LAST_TIME = lastWaveTime;
WmsConstants.WAVE_CURRENT_ORDER = currentWaveOrder; //只显示有零货的波次
}
debug("start getPickDetailByWaveOrder.....");
//DataTable dtBatch = lgt.getWmsOutPickRequest.getPickDetailByWaveOrder(WmsConstants.WAVE_CURRENT_ORDER).Tables[0];
/*
DataTable dtBatch = pickClient.getPickDetailByWaveOrder(WmsConstants.WAVE_CURRENT_ORDER);
closeClient();
debug("end getPickDetailByWaveOrder.....1");
DataView dv = dtBatch.DefaultView;
dv.RowFilter = "volType >0";
gridControl2.DataSource = dv;
debug("end getPickDetailByWaveOrder.....2");
* */
}
else
{
if (WmsConstants.WAVE_LAST_FREE_TIME == DateTime.MinValue)
{
WmsConstants.WAVE_LAST_FREE_TIME = DateTime.Now;
}
}
}
catch (Exception er)
{
// setCurrentRequestDetail();
showErrorMsg(er.Message);
}
closeWaitForm();
debug("end loadPickOrdersInWave.....");
}
private void clearInputs()
{
}
System.Timers.Timer timer = new System.Timers.Timer();//实例化Timer类
//private void timeCnt()
//{
// timer.Start(); ;
//}
private void initialTimer()
{
int intTime = 1000;
timer.Interval = intTime;//设置间隔时间,为毫秒;
timer.Elapsed += new System.Timers.ElapsedEventHandler(showWaveSpan);//到达时间的时候执行事件;
timer.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
timer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
// timer.Start();
}
private void showWaveSpan(object source, System.Timers.ElapsedEventArgs e)
{
// debug(string.Format(" timer loop begin .... " ));
TimeSpan ts = DateTime.Now - WmsConstants.WAVE_LAST_TIME;// WmsConstants.WAVE_LAST_TIME;
try
{
if (InvokeRequired)
{
this.Invoke(new loadNewCurrentWave(delegate()
{
// lbLightsInfo.Text = (lights.Count > 0 ? "" : "未检测到通道灯");
//refreshOrderList();
updateLableStatus();
// waveStart();
/*
if (string.IsNullOrEmpty(WmsConstants.WAVE_CURRENT_ORDER)) //start new wave
{
lbWaveSpan.ForeColor = Color.Green;
TimeSpan ts1 = DateTime.Now - WmsConstants.WAVE_LAST_FREE_TIME;
lbWaveSpan.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", ts1.Hours, ts1.Minutes, ts1.Seconds);
// debug(string.Format(" timer loop to start new wave.... "));
// this.clearWaveData();
waveStart();// newWave();
}
else
{
lbWaveSpan.ForeColor = Color.Black;
lbWaveSpan.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", ts.Hours, ts.Minutes, ts.Seconds);
}
*/
}));
}
else
{
//lbLightsInfo.Text = (lights.Count > 0 ? "" : "未检测到通道灯");
updateLableStatus();
// waveStart();
/*
if (string.IsNullOrEmpty(WmsConstants.WAVE_CURRENT_ORDER)) //start new wave
{
lbWaveSpan.ForeColor = Color.Green;
TimeSpan ts1 = DateTime.Now - WmsConstants.WAVE_LAST_FREE_TIME;
lbWaveSpan.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", ts1.Hours, ts1.Minutes, ts1.Seconds);
// this.clearWaveData();
waveStart();// newWave();
}
else
{
lbWaveSpan.ForeColor = Color.Black;
lbWaveSpan.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", ts.Hours, ts.Minutes, ts.Seconds);
}
* */
}
}
catch (Exception er)
{
LogHelper.WriteLog(typeof(GoodsOutForm), er);
}
// debug(string.Format(" timer loop end .... "));
}
private void btnDelete_Click(object sender, EventArgs e)
{
}
private void initialDataGrid()
{
this.gridView2.IndicatorWidth = 40;
this.gridView2.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView_CustomDrawRowIndicator);
this.gridView3.IndicatorWidth = 40;
this.gridView3.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView_CustomDrawRowIndicator);
//this.gridView3.IndicatorWidth = 40;
//this.gridView3.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView_CustomDrawRowIndicator);
}
private void gridView2_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
if (sender == gridView2)
{
if (e.Column.FieldName == "state")
{
switch (e.DisplayText)
{
case "1" :
e.DisplayText = "已出货";
break;
case "0":
e.DisplayText = "待出货";
break;
case "2":
e.DisplayText = "出现错误";
break;
case "":
e.DisplayText = "待出货";
break;
//default:
// e.DisplayText = "未分配货位";
}
}
}
}
void gridView_RowCellStyle(object sender,DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
var currentView = sender as GridView;
if( currentView == null){return;}
string state = currentView.GetDataRow(e.RowHandle)["priority"].ToString().Trim();
if (state == "0")
{
return;
}
bool isFocused = e.RowHandle == currentView.FocusedRowHandle;
DevExpress.Utils.AppearanceDefault rowStyle = null;
DevExpress.Utils.AppearanceDefault appBlueRed =
new DevExpress.Utils.AppearanceDefault (Color.White, Color.Red, Color.Empty, Color.Blue, System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
DevExpress.Utils.AppearanceDefault appYB =
new DevExpress.Utils.AppearanceDefault(Color.White, Color.Red, Color.Green);
DevExpress.Utils.AppearanceDefault alertFocus = new DevExpress.Utils.AppearanceDefault(Color.White, Color.Red, Color.Green, Color.Yellow);
DevExpress.Utils.AppearanceDefault alert = new DevExpress.Utils.AppearanceDefault(Color.Red, Color.White );
DevExpress.Utils.AppearanceDefault highPriorityFocus = new DevExpress.Utils.AppearanceDefault(Color.White, Color.Green);
DevExpress.Utils.AppearanceDefault highPriority = new DevExpress.Utils.AppearanceDefault(Color.Green, Color.White);
if (state == "1")
{
rowStyle = isFocused ? highPriorityFocus : highPriority;
}
else if (state == "2")
{
rowStyle = isFocused ? alertFocus : alert;
}
DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, rowStyle);
/*
if (sender == this.gridView2)
{
if (this.gridView2.GetDataRow(e.RowHandle)["state"].ToString().Trim() == "2")
{
DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, alert);
}
}else if(sender == this.gridView1){
if ( state == "2")
{
if (currentView != null && e.RowHandle == currentView.FocusedRowHandle)
{
DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, alertFocus);
}
else
{
DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, alert);
}
}
else if (state == "1")
{
DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, passed);
}
}
*/
}
/*
private void setCurrentRequestDetail()
{
if (!getCurrentObject() || selectedRequest == null )
{
return;
}
showWaitForm();
try
{
}
catch (Exception e)
{
showErrorMsg(e.Message);
}
closeWaitForm();
}
*/
/*
private void btnNewWave_Click(object sender, EventArgs e)
{
clearWaveData();
btnNewWave.Enabled = false;
newWave();
}
*/
void turnOffLights()
{
if (lights.Count == 0)
{
//searchLight();
// return;
}
// Model.dis_id_comment id;
Model.dis_id id;
//id.ele_id = Convert.ToInt16(new_id.Text);
id.order = 1;
id.ele_id = 65535;
id.state = 1;
//id.
foreach (int port in light.activeComports)
{
if (port == 0)
{
continue;
}
// unart_manage.com_manage[port].write_reset_device(); 复位各个硬件,通道灯,标签。。。
coms.com_manage[port].init_port.write_clear_comment(id);
if (!lights.ContainsKey(port))
{
continue;
}
foreach (int lt in lights[port])
{
Model.close_channel_led idx;
idx.channel_id = lt;
idx.state = 1;
coms.com_manage[port].init_port.write_close_channel_led(idx);
}
// a.write_clear_comment(id);
}
}
Dictionary> lights = new Dictionary>();
void searchLight()
{
Model.modify_id id;
// System.Threading.Thread.Sleep(50);
foreach (int port in light.activeComports)
{
if (port == 0)
{
continue;
}
for (int i = 5000; i <= 5100; i++)
{
id.order = 0;
id.new_ele_id = 0;
id.old_ele_id = i;
id.state = 1;
bool ret = coms.com_manage[port].init_port.search_light_id(id);
if (ret)
{
if (!lights.ContainsKey(port))
{
lights[port] = new List();
}
lights[port].Add(i);
}
}
}
}
void endWave(bool isForce=false)
{
showWaitForm();
if (isForce)
{
// pick.init_port(enumLabelPickType.pick);
turnOffLights();
}
try
{
pickClient.finishCurrentWave(WmsConstants.WAVE_CURRENT_ORDER,isForce);
closeClient();
}
catch(Exception e)
{
closeWaitForm();
showErrorMsg(e.Message);
}
clearWaveData();
// waveStart();
// btnEndWave.Enabled = false;
// btnRelight.Enabled = false;
_canNewWave = true;
closeWaitForm();
}
private void clearWaveData()
{
WmsConstants.WAVE_CURRENT_ORDER = "";
// lbWaveNo.Text = "空闲";
// WmsConstants.WAVE_LAST_FREE_TIME = DateTime.Now;
// timer.Stop();
//lbWaveSpan.Text = "00:00:00";
//lbWaveSpan.Text = string.Format(" ");
// loadPickOrdersInWave();
//gridControl3.DataSource =null;
if (dtBulks != null)
{
// dtBulks.Clear();
}
// gridControl3.DataSource = null;
gridControl2.DataSource = null;
}
private void btnRefresh_Click(object sender, EventArgs e)
{
showWaitForm();
// elelab.pick.init_port(enumLabelPickType.pick);
loadPickOrdersInWave();
closeWaitForm();
}
private void btnRelight_Click(object sender, EventArgs e)
{
// turnOffLights();
//lightLabelsCurrentWave();
}
private void lightLabelsCurrentWave(int[] parts)
{
if (!WmsConstants.OUT_LIGHT_ENABLE)
{
return;
}
debug("start relightCurrentWave.....");
//Thread light = new Thread(lgt.lightLables);
//light.IsBackground = true;
//light.Start();
closeWaitForm();
if (parts.Length == 0)
{
return;
}
//showWaitForm("正在点亮标签...");
if (InvokeRequired)
{
this.Invoke(new loadNewCurrentWave(delegate()
{ loadWaveDetails();
}));
}
else
{
loadWaveDetails();
}
try
{
lightLables(parts); // lgt.lightLables();
}
catch(Exception er)
{
closeWaitForm();
showErrorMsg(er,er.Message);
}
finally
{
closeWaitForm();
}
debug("end relightCurrentWave.....");
}
//private void checkAuto_CheckedChanged(object sender, EventArgs e)
//{
// spinOrder.Enabled = checkAuto.Checked;
//}
private void updateLableStatus(DataTable dt = null)
{
if (!WmsConstants.OUT_LIGHT_ENABLE)
{
return;
}
string key = "";
if (dt != null)
{
foreach (DataRow dr in dt.Rows)
{
if (dr["state"].ToString().Equals("1"))
{
key = Util.getLightKey(Convert.ToInt16(dr["color"].ToString()), Convert.ToInt16(dr["elabId"].ToString()), Convert.ToInt16(dr["elabAddress"].ToString()));
WmsConstants.WAVE_CURRENT_PICK_STATUS[key] = true;
}
}
}
if (dtBulks == null || dtBulks.Rows.Count == 0)
{
return;
}
WmsOutPickLable label;
DataView dv = dtBulks.DefaultView;
dv.RowFilter = "isPicked =0";
dv.Sort = "isPicked";
if (dv.Count ==0)
{
//all picked, wave end
endWave();
return;
}
foreach (DataRow dr in dtBulks.Rows)
{
label = new WmsOutPickLable(dr);
key = Util.getLightKey(label.color, label.elabId, label.elabAddress);
if( WmsConstants.WAVE_CURRENT_LIGHTS_STATUS.ContainsKey(key)){
dr["isLightUp"] = WmsConstants.WAVE_CURRENT_LIGHTS_STATUS[key] ? 1 : 0;
}
if (WmsConstants.WAVE_CURRENT_PICK_STATUS.ContainsKey(key))
{
dr["isPicked"] = WmsConstants.WAVE_CURRENT_PICK_STATUS[key] ? 1 : 0;
}
}
dv.RowFilter = ""; // 如果 dv.RowFilter ="isPicked =0"; 则已拣的不再显示
gridControl3.DataSource = dtBulks.DefaultView;
}
private void GoodsOutForm_FormClosing(object sender, FormClosingEventArgs e)
{
// outClient.Close();
// closeClient();
autoWave = false;
timer.Enabled = false;
turnOffLights();// elelab.pick.init_port(enumLabelPickType.pick);
}
//-------------below moved from logic layer
WmsOutPickRequest outRequest = new WmsOutPickRequest();
WmsStockRecord stkRecord = new WmsStockRecord();
WmsOutPickLable pickLabelDetail = new WmsOutPickLable();
///
/// 点亮待拣选标签
///
private void lightLablesInSvc()
{
pickClient.lightLables();
closeClient();
}
///
/// 点亮待拣选标签
///
private void lightLables(int[] parts)
{
// lightLablesInSvc();
//lightLabelsInWinformSvc();
if (!WmsConstants.OUT_LIGHT_ENABLE)
{
return;
}
if (parts.Length == 0)
{
return;
}
initLights();
// turnOffLights();
lastWave = DateTime.Now;
WmsConstants.WAVE_CURRENT_LIGHTS_STATUS.Clear();
bool exist = pickClient.getCurrentPickList((int)enumPickState.未拣).Rows.Count > 0;
closeClient();
if (!exist)
{
return;
}
showWaitForm("正在点亮标签...");
string result = lightPart.lightsUp(pickClient.getPartsPickList( parts,(int)enumPickState.未拣), enumLabelPickType.pick);
closeClient();
//#if DEBUG
closeWaitForm();
/*
if (!string.IsNullOrEmpty(result))
{
// lbLightsInfo.Text = result;
if (WmsConstants.OUT_SPEAK_WAVE)
{
speak(errorMsg);
}
// showErrorMsg(result);
}
else if ( light.activeComports.Count == 0)
{
if ( WmsConstants.OUT_SPEAK_WAVE)
{
speak(errorMsg);
}
}
else
{
//#endif
//speak(WmsConstants.WAVE_CURRENT_ORDER);
if (WmsConstants.WAVE_CURRENT_ORDER.Length > 0)
{
if (WmsConstants.OUT_SPEAK_WAVE)
{
speak(WmsConstants.WAVE_CURRENT_ORDER + " 开始捡货啦");
}
}
LogHelper.debug(typeof(GoodsOutForm), "开始拣货 :" + WmsConstants.WAVE_CURRENT_ORDER);
}
*/
// speak("Go! Go! Go!");
}
void initLights()
{
string errorMsg = "灯光设备连接错误";
if (InvokeRequired)
{
this.Invoke(new loadNewCurrentWave(delegate()
{
lbLightsInfo.Text = "连接正常";
lightPart.initPort(enumLabelPickType.pick);
if (lightPart.activeComports.Count == 0)
{
lbLightsInfo.Text = errorMsg;
// showErrorMsg("拣选设备连接错误,请检查设备连接");
return;
}
}));
}
else
{
lbLightsInfo.Text = "连接正常";
lightPart.initPort(enumLabelPickType.pick);
if (lightPart.activeComports.Count == 0)
{
lbLightsInfo.Text = errorMsg;
// showErrorMsg("拣选设备连接错误,请检查设备连接");
return;
}
}
}
private static bool _canNewWave = true;
//Int64 lastWave =0;
DateTime lastWave;
public bool canNewWave
{
get
{
// _canNewWave = _canNewWave && outRequest.canNewWave();
if (!autoWave)
{
return true;
}
if (_canNewWave)
{
lastWave = DateTime.Now;
}
else
{
TimeSpan ts = DateTime.Now - lastWave;
if (ts.TotalMilliseconds > WmsConstants.MAX_SECONDS_BETWEEN_WAVES) //强制开始新波次,有可能会有再次发送亮灯数据时
{
_canNewWave = true;
lastWave = DateTime.Now;
}
}
return _canNewWave;//|| outRequest.canNewWave() ;//|| true;
// return _canNewWave; // pickLabelDetail.getCurrentPickList(enumLabelPickState.notPicked).Tables[0].Rows.Count > 0;
}
}
public void newPickWave()
{
if (!canNewWave)
{
return;
}
int[] lstPartion ;
_canNewWave = false;
// bool exist = false;
try
{
showWaitForm("正在配置新波次");
lstPartion= pickClient.newPartPickWave();
closeClient();
// WmsConstants.WAVE_CURRENT_PICK_STATUS.Clear();
lightLabelsCurrentWave(lstPartion);
LogHelper.debug(typeof(GoodsOutForm), "开始新波次 :" + WmsConstants.WAVE_CURRENT_ORDER);
}
catch (Exception er)
{
LogHelper.WriteLog(this.GetType(), er);
#if debug
showErrorMsg(er.Message);
#endif
}
lastWaveRequestTime = DateTime.Now;
//_canNewWave = true;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
if (string.IsNullOrEmpty(e.DisplayText))
{
return;
}
if (e.Column.FieldName == WmsOutPickRequest.fields.priority.ToString())
{
if (!pickDetailStatus.ContainsValue(e.DisplayText))
{
int display = -100;
string disTxt = e.DisplayText;
try
{
display = Convert.ToInt16(e.DisplayText);
e.DisplayText = this.pickPriority[display];
}
catch
{
return;
}
}
// e.DisplayText = pickDetailStatus.ContainsKey(display) ? pickDetailStatus[display] : display+"";
}
}
void partFinished(int eleId)
{
int partion = eleId;// -WmsConstants.PART_FINISH_LABLE_ID_PLUS;
// see if all lights data picked
int[] parts = {partion};
DataTable dt = pickClient.getPartsPickList(parts,(int)enumPickState.未拣);
if (dt.Rows.Count > 0) //未完成,则重新点亮本区域任务
{
Thread.Sleep(2000);
// WmsConstants.partStatus[eleId] = true;
lightLables(parts);
return;
}
pickClient.finishPartWave(partion, false);
closeClient();
newWave();
}
void getPartFinishIds()
{
WmsConstants.PART_FINISH_LABLE_IDS = pickClient.getPartsFinishIds();
closeClient();
}
//---------------------service
private ServiceHost host = null;
public static List labelPool = new List();
string svrUrl = WmsConstants.LIGHT_SVR_ADDRESS;
string wmsUrl = "";
string postUrl = "";
delegate void showStatus();
void startHost()
{
// lbStatus.Text = "服务启动失败";
try
{
// svrUrl = System.Configuration.ConfigurationManager.AppSettings["BaseUri"];
wmsUrl = System.Configuration.ConfigurationManager.AppSettings["WMSuri"];
Uri baseAddress = new Uri(svrUrl);
LightService service = new LightService();
service.lightOd += this.lightByOrder;
// service.lightUp += this.lightUp;
host = new ServiceHost(service, baseAddress);
// elelab.DNLights.lightOffEvent += testPicked;
WebHttpBinding binding = new WebHttpBinding();
ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(ILightService), binding, baseAddress);
WebHttpBehavior httpBehavior = new WebHttpBehavior();
endpoint.Behaviors.Add(httpBehavior);
host.Opened += delegate
{
// addLog("服务已启动");
if (InvokeRequired)
{
this.Invoke(new showStatus(delegate()
{
lbStatus.Text = "服务已启动";
lbUrl.Text = "亮灯服务地址:" + svrUrl; ;
}));
}
else
{
lbStatus.Text = "服务已启动";
lbUrl.Text = "亮灯服务地址:" + svrUrl ;
}
};
host.Open();
}
catch (Exception e)
{
// addLog("启动服务失败: " + e.Message);
MessageBox.Show("启动服务失败: " + e.Message);
}
}
public int lightByOrder(string orderNo,bool isPickOrder, int partion)
{
DataTable dt = pickClient.getOrderPickList(orderNo, isPickOrder, partion);
closeClient();
if (dt.Rows.Count > 0)
{
initLights();
showWaitForm("正在点亮标签...");
string result = lightPart.lightsUp(dt, enumLabelPickType.pick);
closeWaitForm();
return 1;
}
return 0;
}
}
}