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 DeiNiu.wms.win.utils; 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 DeiNiu.wms.win.utils.print; using System.Net; using System.IO; using elelab; using System.ServiceModel; using System.ServiceModel.Description; using DevExpress.XtraEditors.Repository; using DeiNiu.wms.win.epick; namespace DeiNiu.wms.win { public partial class SeedsOutService : BasicRibbonForm { private ServiceHost host = null; public static List labelPool = new List(); string svrUrl = "http://127.0.0.1:9998/DNLight"; //this is for medicine branch test // lWmslocation lgt = new lWmslocation(); // private string fieldName = Wmslocation.fields.locationId.ToString(); int count, selectedId,status; private string lastQuery = ""; private DataTable dt; private int selectedRowIndex = -1; private bool isAdding = true; // private LocStructs locs; // private List selectedLocations; private List selectedIds; String oDeskId=""; String oCom = ""; Dictionary mapComs = new Dictionary(); Dictionary portOrder = new Dictionary(); Dictionary deskBarcode = new Dictionary(); Dictionary deskSeedsNo = new Dictionary(); static log4net.ILog log = log4net.LogManager.GetLogger("light"); public SeedsOutService() { InitializeComponent(); initialControls(); WmsConstants.WAVE_CURRENT_LIGHTS_STATUS.Clear(); //WmsConstants.WAVE_CURRENT_PICK_STATUS.Clear(); elelab.pick.init_port(enumLabelPickType.seed,true); elelab.pick.lightOffEvent += testPicked; btnShowId.Enabled = false; if (elelab.pick.activeComports.Count == 0) { lbLightsInfo.Text = "拣选设备连接错误"; } else { initComs(); lbLightsInfo.Text = "拣选设备连接正常"; } //启动播种服务,远程终端如pda分播时,启动该服务 Thread threadPreProcess = new Thread(startHost2); threadPreProcess.IsBackground = true; threadPreProcess.Start(); // resetAllLights(); initialTimer(); /* oDeskId = System.Configuration.ConfigurationManager.AppSettings["DeskId"]; if (!string.IsNullOrEmpty(oDeskId)) { txtDeskId.Text = oDeskId; txtOperater.SelectAll(); txtOperater.Focus(); }*/ } #region initialControls private void initialControls() { initialComboBoxes(); initialPagerControls(); initialDataGrid(); initialQueryInput(); setValidationRule(); txtBarcode.GotFocus += new EventHandler(txtBarcode_GotFocus); txtBarcode.MouseUp += new MouseEventHandler(txtBarcode_MouseUp); txtSeedNo.GotFocus += new EventHandler(txtSeedNo_GotFocus); txtSeedNo.MouseUp += new MouseEventHandler(txtSeedNo_MouseUp); txtOperater.GotFocus += new EventHandler(txtOperater_GotFocus); txtOperater.MouseUp += new MouseEventHandler(txtOperater_MouseUp); } void txtOperater_GotFocus(object sender, EventArgs e) { txtOperater.Tag = true; //设置标记 txtOperater.SelectAll(); //注意1 } void txtOperater_MouseUp(object sender, MouseEventArgs e) { //如果鼠标左键操作并且标记存在,则执行全选 if (e.Button == MouseButtons.Left && txtOperater.Tag != null && (bool)txtOperater.Tag == true) { txtOperater.SelectAll(); } //取消全选标记 txtOperater.Tag = false; } void txtSeedNo_GotFocus(object sender, EventArgs e) { txtSeedNo.Tag = true; //设置标记 txtSeedNo.SelectAll(); //注意1 } void txtSeedNo_MouseUp(object sender, MouseEventArgs e) { //如果鼠标左键操作并且标记存在,则执行全选 if (e.Button == MouseButtons.Left && txtSeedNo.Tag != null && (bool)txtSeedNo.Tag == true) { txtSeedNo.SelectAll(); } //取消全选标记 txtSeedNo.Tag = false; } void txtBarcode_GotFocus(object sender, EventArgs e) { txtBarcode.Tag = true; //设置标记 txtBarcode.SelectAll(); //注意1 } void txtBarcode_MouseUp(object sender, MouseEventArgs e) { //如果鼠标左键操作并且标记存在,则执行全选 if (e.Button == MouseButtons.Left && txtBarcode.Tag != null && (bool)txtBarcode.Tag == true) { txtBarcode.SelectAll(); } //取消全选标记 txtBarcode.Tag = false; } private void initialComboBoxes() { } private void setValidationRule() { // dxValidationProvider1.SetValidationRule(comWarehouseQuery, ValidationRules.notEmptyValidationRule); //txtGoodType.Properties.MaxLength = 40; //txtGoodDesc.Properties.MaxLength = 250; //textEdit1.Properties.MaxLength = txtGoodType.Properties.MaxLength; } private void initialQueryInput() { } private void initialPagerControls() { pager1.MaximumSize = new Size(0, 20); pager1.EventPaging += new DeiNiu.Controls.pager.EventPagingHandler(pager_EventPaging); #region DataGridView与Pager控件绑定 this.pager1.PageCurrent = 1;//当前页为第一页 pager1.PageSize = 200;//每页行数 // this.pager1.Bind();//绑定 #endregion } private void initialDataGrid() { this.gridView1.OptionsBehavior.AutoPopulateColumns = false; this.gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus; this.gridView1.OptionsBehavior.Editable = false; this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false; this.gridView1.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(this.gridView1_FocusedRowObjectChanged); this.gridView1.DataSourceChanged += new System.EventHandler(this.gridView1_DataSourceChanged); //show line number this.gridView1.IndicatorWidth = 60; this.gridView1.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView1_CustomDrawRowIndicator); gridView1.CustomColumnDisplayText += gridView_CustomColumnDisplayText; gridView1.RowCellStyle += gridView1_RowCellStyle; gridView1.CustomColumnDisplayText += gridView1_CustomColumnDisplayText; } //显示行的序号 private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } } private void initialDataGridColumns() { setupGridView(gridView1, true); // gridviewGoodsType.PopulateColumns(); /* gridView1.Columns.Clear(); // gridviewGoodsType.Columns.Remove(gridviewGoodsType.Columns["DealerPrice"]); GridColumn myCol0 = new GridColumn() { Caption = "ID", Visible = true, FieldName = "id" }; myCol0.Visible = false; this.gridView1.Columns.Add(myCol0); GridColumn myCol1 = new GridColumn() { Caption = "播种单号", Visible = true, FieldName = WmsImportSeeds.fields.seedsNo.ToString(), MinWidth = 100 }; GridColumn myCol2 = new GridColumn() { Caption = "商品编号", Visible = true, FieldName = WmsImportSeeds.fields.barcode.ToString(), MinWidth = 100 }; GridColumn myCol3 = new GridColumn() { Caption = "商品名称", Visible = true, FieldName = WmsImportSeeds.fields.itemName.ToString(), MaxWidth = 300 }; GridColumn myCol4 = new GridColumn() { Caption = "大类名", Visible = true, FieldName = WmsImportSeeds.fields.category1.ToString(), MaxWidth = 100 }; // GridColumn myCol5 = new GridColumn() { Caption = "中类名", Visible = true, FieldName = WmsImportSeeds.fields.category2.ToString(), MaxWidth = 100 }; // GridColumn myCol6 = new GridColumn() { Caption = "小类名", Visible = true, FieldName = WmsImportSeeds.fields.category3.ToString(), MaxWidth = 100 }; GridColumn myCol7 = new GridColumn() { Caption = "门店名称", Visible = true, FieldName = WmsImportSeeds.fields.custName.ToString(), MaxWidth = 200 }; GridColumn myCol8 = new GridColumn() { Caption = "单位", Visible = true, FieldName = WmsImportSeeds .fields.unit.ToString(), MaxWidth = 80}; GridColumn myCol9 = new GridColumn() { Caption = "规格", Visible = true, FieldName = WmsImportSeeds.fields.spec.ToString(), MaxWidth = 120 }; GridColumn myCol10 = new GridColumn() { Caption = "发货数量", Visible = true, FieldName = WmsImportSeeds.fields.count.ToString(), MaxWidth = 80 }; GridColumn myCol11 = new GridColumn() { Caption = "实发数量", Visible = true, FieldName = WmsImportSeeds.fields.countOut.ToString(), MaxWidth = 80 }; GridColumn myCol12 = new GridColumn() { Caption = "灯ID", Visible = true, FieldName = WmsImportSeeds.fields.elabId.ToString(), MaxWidth = 80 }; GridColumn myCol16 = new GridColumn() { Caption = "端口号", Visible = true, FieldName = WmsImportSeeds.fields.port.ToString(), MaxWidth = 80 }; GridColumn myCol13 = new GridColumn() { Caption = "员工编号", Visible = true, FieldName = WmsImportSeeds.fields.operater.ToString(), MaxWidth = 80 }; GridColumn myCol14 = new GridColumn() { Caption = "分播台", Visible = true, FieldName = WmsImportSeeds.fields.deskId.ToString(), MaxWidth = 80 }; GridColumn myCol15 = new GridColumn() { Caption = "备注", Visible = true, FieldName = WmsImportSeeds.fields.description.ToString(), MaxWidth = 80 }; GridColumn myCol17 = new GridColumn() { Caption = "灯色", Visible = true, FieldName = WmsImportSeeds.fields.color.ToString(), MaxWidth = 80 }; GridColumn myCol29 = new GridColumn() { Caption = "标签点亮", Visible = true, FieldName = "isLightUp" }; // GridColumn myCol30 = new GridColumn() { Caption = "拣货状态", Visible = true, FieldName = "state" }; GridColumn myCol30 = new GridColumn() { Caption = "拣货状态", Visible = true, FieldName = "statedesc", MinWidth = 80 }; GridColumn myCol18 = new GridColumn() { Caption = "分播时间", Visible = true, FieldName = WmsImportSeeds.fields.picktime.ToString(), MinWidth = 150, MaxWidth = 250 }; this.gridView1.Columns.Add(myCol14); this.gridView1.Columns.Add(myCol13); this.gridView1.Columns.Add(myCol1); this.gridView1.Columns.Add(myCol2); this.gridView1.Columns.Add(myCol3); this.gridView1.Columns.Add(myCol7); this.gridView1.Columns.Add(myCol10); this.gridView1.Columns.Add(myCol11); this.gridView1.Columns.Add(myCol8); this.gridView1.Columns.Add(myCol12); this.gridView1.Columns.Add(myCol18); // this.gridView1.Columns.Add(myCol29); this.gridView1.Columns.Add(myCol17); this.gridView1.Columns.Add(myCol30); this.gridView1.Columns.Add(myCol15); // this.gridView1.Columns.Add(myCol16); this.gridView1.Columns.Add(myCol9); // this.gridView1.Columns.Add(myCol4); // this.gridView1.Columns.Add(myCol5); // this.gridView1.Columns.Add(myCol6); 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; gridControl1.RepositoryItems.Add(ri); myCol29.ColumnEdit = ri; //绑定到GridColumn */ gridView1.BestFitColumns(); //gridView1.Focus(); gridView1.OptionsView.ColumnAutoWidth = false; //自动列宽 //gridView1.OptionsView.ColumnAutoWidth = false; //this.gridView1.BestFitColumns(); //this.gridView1.Columns[2].MinWidth = 500; //this.gridView1.Columns[1].BestFit(); //for (int I = 0; I < gridView1.Columns.Count; I++) //{ // this.gridView1.Columns[I].BestFit() //} } /// /// 设置列表数据的日期格式 /// /// /// public static void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { if (e.Column.FieldName == "createtime" || e.Column.FieldName == "picktime") { e.Column.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss"; } } #endregion /// /// loading data /// private int loadData() { //this.gridviewGoodsType.DataSource = lgt.GetAllActiveData().Tables[0].DefaultView; try { clearInputs(); showWaitForm(); string query = "("; foreach(int deskId in deskBarcode.Keys) { query += "( seedsNo= '"+ deskSeedsNo[deskId] +"' and deskId =" + deskId + " and barcode='" + deskBarcode[deskId] + "') or "; } query += " 1=2)"; query += " and state >0 "; this.pager1.PageCurrent = lastQuery.Equals(query) ? this.pager1.PageCurrent : 1; //根据查询条件的变化给pager赋值 int start = (pager1.PageSize * (pager1.PageCurrent - 1) + 1); int end = (pager1.PageSize * pager1.PageCurrent); lastQuery = query; // DataSet ds = lis.queryDeskSeeds(query, start, end); // dt = pickClient.lightSeeds() // int cnt = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString()); //dt = lgt.Query(query, start, end); //string.IsNullOrEmpty(query) ? lgt.GetGoodType.getAllData(start, end) : lgt.g; // dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] }; this.gridControl1.DataSource = dt.DefaultView; initialDataGridColumns(); //update selected row index to the last updated one. //this.btnQuery.Enabled = true; decimal countOut=0; foreach (DataRow dr in dt.Rows) { // WmsImportSeeds_tmp wis = new WmsImportSeeds_tmp(dr); // countOut += wis.countOut; } lbSumCnt.Text = countOut+""; closeWaitForm(); return 1;// lgt.getRowCount(query); // return lgt.GetGoodType.QueryCount(); } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); //btnQuery.Enabled = true; } return 0; } /// /// 分页控件产生的事件 /// private int pager_EventPaging(DeiNiu.Controls.pager.EventPagingArg e) { selectedRowIndex = 0; //reset currentRowIndex return loadData(); } private void gridView_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { } private bool validData() { bool isvalid = dxValidationProvider1.Validate(); // MessageBox.Show("goodtype is " + txtGoodType.Text +", is valid ? " + isvalid); return isvalid; //String gdtype = txtGoodType.Text.Trim(); //if (gdtype.Length == 0) //{ // dxValidationProvider.Validate(); // return false; //} //return true; } private void gridView1_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e) { if (gridView1.FocusedRowHandle < 0 || gridView1.FocusedRowHandle == selectedRowIndex) { if (gridView1.IsGroupRow(e.RowHandle)) //set first row of group selected { selectedRowIndex = gridView1.GetChildRowHandle(e.RowHandle, 0); // setCurrentRequestDetail(); } return; ; } } private void clearInputs() { } private bool getCurrentObject() { if (selectedRowIndex < 0 || dt.Rows.Count <= selectedRowIndex) { MessageBox.Show("请在列表里选择数据"); return false; } // DataRow currentRow = dt.Rows[selectedRowIndex]; DataRowView dr = (DataRowView)(GetGridViewFilteredAndSortedData(gridView1)[selectedRowIndex]); return true; } private void gridView1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) { } private void gridView1_DataSourceChanged(object sender, EventArgs e) { if (selectedRowIndex > 0 && dt.Rows.Count > selectedRowIndex) { gridView1.FocusedRowHandle = selectedRowIndex; gridView1.MakeRowVisible(selectedRowIndex); } } protected void query() { pager1.Bind(); } private void startQuery() { // this.btnQuery.Enabled = false; showWaitForm(); try { query();// loadData(); } catch (Exception e) { MessageBox.Show(e.Message); } finally { // WaitFormService.Close(); closeWaitForm(); } } private void txtQuery_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13) { query(); } } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { } bool isNewLocationQuery = false; private void SeedsOut_FormClosing(object sender, FormClosingEventArgs e) { /* int port = Convert.ToInt16(combComs.Text.Substring(3)); if (unart_manage.com_manage[port] == null) { return; }*/ try { // resetAllLights(); //pick.clearLabels(port); // client.Close(); host.Close(); timer.Enabled = false; // turnOffLights();// elelab.pick.init_port(enumLabelPickType.pick); } catch { } } private bool getCurrentObjects() { int[] selectedRows = gridView1.GetSelectedRows(); // selectedLocations = new List(); selectedIds = new List(); foreach (int i in selectedRows) { DataRow currentRow = dt.Rows[i]; selectedIds.Add(Convert.ToInt32(currentRow["ID"].ToString())); } if (selectedRows.Length == 0) { showErrorMsg("请选择一条数据"); return false; } DialogResult r = MessageBox.Show(string.Format("确定要更新选中的{0}条货位信息吗?", selectedRows.Length), "确认修改", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); return r == DialogResult.Yes; } private void bbiExport_ItemClick(object sender, ItemClickEventArgs e) { // exportExcel("分播记录",gridView1); } private void gridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) { if (gridView1.FocusedRowHandle <0 || gridView1.FocusedRowHandle == selectedRowIndex) { // return; } selectedRowIndex = gridView1.FocusedRowHandle; clearInputs(); if (selectedRowIndex < 0) { return; } getCurrentObject(); // showErrorMsg("selection:"+ selectedRowIndex); // setCurrentRequestDetail(); } private void txtBarcode_Enter(object sender, EventArgs e) { } private void txtBarcode_EditValueChanged(object sender, EventArgs e) { } String lastScanBarcode = String.Empty; private void txtBarcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) { return; } string barcode = txtBarcode.Text; if (string.IsNullOrEmpty(barcode)) { return; } if (!validSeeds()) { return; } try { operater = Convert.ToInt32(this.txtOperater.Text.Trim()); } catch { showErrorMsg("请扫描输入正确的操作员ID"); txtOperater.SelectAll(); txtOperater.Focus(); return; } int color = getColor(operater); if (lastScanBarcode !=String.Empty && lastScanBarcode != barcode) { elelab.pick.clearOrder(currentPort, color); } lastScanBarcode = barcode; bool isValidData = chkValid.Checked; //lightUp( lis.startNewSeed(deskId, seedsNo, barcode, operater, color,isValidData),color); //lightSeeds(barcode); startQuery(); txtBarcode.Focus(); } Dictionary colors = new Dictionary(); int colorcnt = 0; private int getColor(int operater) { int color = 0; if (colors.ContainsKey(operater)) { color = colors[operater]; } else { colors[operater] = ++colorcnt; color = colors[operater]; } //红蓝调换 if (color == 3) { return 1; }else if (color == 1) { return 3; }else return color; } void lightSeeds(String barcode) { String svrUrl = System.Configuration.ConfigurationManager.AppSettings["BaseUri"]; svrUrl = svrUrl + "lightSeed?deskId={0}&seedsNo={1}&barcode={2}"; svrUrl = string.Format(svrUrl, deskId, seedsNo, barcode); lbUrl.Text = HttpGet(svrUrl, null); } public static string HttpGet(string Url, string postDataStr) { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (string.IsNullOrEmpty(postDataStr) ? "" : "?") + postDataStr); request.Method = "GET"; request.ContentType = "text/html;charset=UTF-8"; request.Timeout = 10000; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8); string retString = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); return retString; } catch (Exception ex) { return ex.Message; } } int deskId = 0; int operater = 0; String seedsNo = String.Empty; private bool validSeeds() { try { deskId = Convert.ToInt16(this.txtDeskId.Text.Trim()); if(!oDeskId.Equals(this.txtDeskId.Text.Trim())){ writeConfig("DeskId", txtDeskId.Text.Trim()); oDeskId = this.txtDeskId.Text.Trim(); } } catch { showErrorMsg("请检查输入的数字是否正确"); this.txtDeskId.SelectAll(); this.txtDeskId.Focus(); return false; } seedsNo = this.txtSeedNo.Text.Trim() ; if (seedsNo == String.Empty) { showErrorMsg("请检查输入的分播单编号是否正确"); this.txtSeedNo.SelectAll(); this.txtSeedNo.Focus(); return false; } return deskId > 0 && seedsNo!=String.Empty; } private void btnQuery_Click(object sender, EventArgs e) { //this.btnQuery.Enabled = false; if( log.IsDebugEnabled) { log.Debug(getMsg("seedsOutService","test msg")); } startQuery(); } static string getMsg(string className, string msg) { return string.Format("{0} {1}", className, msg); } int getOrder(int port) { if (portOrder.ContainsKey(port)) { if (portOrder[port] > 250) { portOrder[port] = 1; } else { portOrder[port]++; } } else { portOrder[port] = 1; } return portOrder[port]; } void lightUp(List lables, int userId) { //to lightup if (lables.Count == 0 || currentPort==0) { return; } int port = lables[0].port; int deskId = lables[0].deskId; #if DEBUG //deskId = 51; #endif deskBarcode[deskId] = lables[0].barcode; deskSeedsNo[deskId] = lables[0].seedsNo; foreach (string key in mapComs.Keys) { if( deskId == mapComs[key]) { port = Convert.ToInt16(key.Substring(3)); break; } } int order = port; enumLabelPickType pickType = enumLabelPickType.seedsDesk; if (port == 0)//一次分播 { port = currentPort; order = 100; pickType = enumLabelPickType.seedsDesk; WmsConstants.SEEDS_PORT_USERID_ID[100] = userId; }else WmsConstants.SEEDS_PORT_USERID_ID[port] = userId; #if DEBUG // port = 17; #endif // order =getOrder(port); elelab.pick.init_port(pickType); elelab.pick.lightLabels2(lables, port, order, pickType); if (InvokeRequired) { this.Invoke(new showStatus(delegate () { //startQuery(); })); } else { //startQuery(); } /* if (elelab.pick.activeComports.Count == 0) { lbLightsInfo.Text = "拣选设备连接错误"; } else { lbLightsInfo.Text = "连接正常"; } */ } delegate void showStatus(); void startHost2() { // lbStatus.Text = "服务启动失败"; try { // svrUrl = System.Configuration.ConfigurationManager.AppSettings["BaseUri"]; svrUrl = "http://127.0.0.1:9999/DNLight"; Uri baseAddress = new Uri(svrUrl); ServiceLight service = new ServiceLight(); // service.newLabels += this.newLabels; service.lightUp += this.lightUp; service.turnOff += this.turnOff; service.clOrder += this.clearOrder; host = new ServiceHost(service, baseAddress); elelab.pick.lightOffEvent += testPicked; WebHttpBinding binding = new WebHttpBinding(); ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IServiceLight), binding, baseAddress); WebHttpBehavior httpBehavior = new WebHttpBehavior(); endpoint.Behaviors.Add(httpBehavior); List lstIp = Util.GetLocalIpAddress("InterNetwork"); string showSvr = svrUrl; if (lstIp.Count > 0) { showSvr = svrUrl.Replace("127.0.0.1", lstIp[0]); } host.Opened += delegate { log.Debug("服务启动"); if (InvokeRequired) { this.Invoke(new showStatus(delegate() { lbStatus.Text = "服务已启动"; lbUrl.Text = showSvr; })); } else { lbStatus.Text = "服务已启动"; lbUrl.Text = showSvr; // lbStatus.Text = "服务启动失败"; // lbUrl.Text =""; } }; host.Open(); } catch (Exception e) { MessageBox.Show("启动服务失败: "+e.Message); } } private void clearOrder(int deskId ) { int orderNo = 0; int port = 0; foreach (string key in mapComs.Keys) { if (deskId == mapComs[key]) { port = Convert.ToInt16(key.Substring(3)); break; } } orderNo = port; if (deskId == 0) { port = currentPort; orderNo = 100; } elelab.pick.clearOrder(port, orderNo); } void newLabels(List lables) { labelPool = labelPool.Union(lables).ToList(); labelPool = labelPool.Concat(lables).ToList(); } void turnOff(int portNo) { if (unart_manage.com_manage[portNo] == null) { return; } dis_id id; //id.ele_id = Convert.ToInt16(new_id.Text); id.order = 1; id.ele_id = 65535; id.state = 1; unart_manage.com_manage[portNo].init_port.write_clear_comment(id); } void testPicked(int eleId, int port, int eleAddress, int count) { if (InvokeRequired) { this.Invoke(new showStatus(delegate() { showResult(eleId, port, eleAddress, count); })); } else { showResult(eleId, port, eleAddress, count); } } void showResult(int eleId, int color, int eleAddress, int count) { // lbreturn.Text = string.Format("标签ID:{0} 颜色:{1} 地址:{2} 数量:{3}", eleId, color, eleAddress, count); } private void btnExport_Click(object sender, EventArgs e) { int pageSize = pager1.PageSize; pager1.PageSize =pager1.NMax; query(); seedsNo = this.txtSeedNo.Text.Trim(); // exportExcel("分播明细-" + deskId + "-" + seedsNo + "-" + operater, gridView1); pager1.PageSize = pageSize; query(); closeWaitForm(); } 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(updateLableStatus);//到达时间的时候执行事件; timer.AutoReset = true;//设置是执行一次(false)还是一直执行(true); timer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件; timer.Start(); } delegate void loadNewCurrentWave(); private void updateLableStatus(object source, System.Timers.ElapsedEventArgs e) { try { if (InvokeRequired) { this.Invoke(new loadNewCurrentWave(delegate() { // lbLightsInfo.Text = (lights.Count > 0 ? "" : "未检测到通道灯"); updateLableStatus(); })); } else { //lbLightsInfo.Text = (lights.Count > 0 ? "" : "未检测到通道灯"); updateLableStatus(); } } catch (Exception er) { // LogHelper.WriteLog(typeof(GoodsOutForm), er); log.Error(er); } } private void updateLableStatus(){ string key = ""; if (dt == null || dt.Rows.Count == 0) { return; } /* WmsImportSeeds label; DataView dv = dt.DefaultView; dv.RowFilter = "state <=3"; dv.Sort = "state"; if (dv.Count == 0) { //all picked, wave end // endWave(); return; } try { foreach (DataRow dr in dt.Rows) { label = new WmsImportSeeds(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; } int deskid = label.deskId; int orderNo = 100; foreach (string k in mapComs.Keys) { if (deskId == mapComs[k]) { orderNo = Convert.ToInt16(k.Substring(3)); break; } } if (WmsConstants.SEEDS_CURRENT_PICK_STATUS[orderNo].ContainsKey(key)) { dr["state"] = 3;// WmsConstants.WAVE_CURRENT_PICK_STATUS[key] ? 1 : 0; } }}catch(Exception er) { // log.Error(er); } dv.RowFilter = ""; // 如果 dv.RowFilter ="isPicked =0"; 则已拣的不再显示 gridControl1.DataSource = dt.DefaultView; */ } string[] color = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }; private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { if (string.IsNullOrEmpty(e.DisplayText)) { return; } if (e.Column.FieldName == "color") { if (color.Contains(e.DisplayText)) { int display = -100; string disTxt = e.DisplayText; try { display = Convert.ToInt16(e.DisplayText); e.DisplayText = getColorD(display); } catch { return; } } } else if (e.Column.FieldName == "state") { if ("1".Equals(e.DisplayText)) { e.DisplayText = "等待分播"; } else if("2".Equals(e.DisplayText)) { e.DisplayText = "正在分播"; } else if ("3".Equals(e.DisplayText)) { e.DisplayText = "完成分播"; } } } string getColorD(int color) { string colorName = ""; switch (color) { case 1: colorName = "红"; break; case 2: colorName = "绿"; break; case 3: colorName = "蓝"; break; case 4: colorName = "红闪"; break; case 5: colorName = "绿闪"; break; case 6: colorName = "蓝闪"; break; case 7: colorName = "红绿"; break; case 8: colorName = "红蓝"; break; case 9: colorName = "绿蓝"; break; case 10: colorName = "红绿蓝"; break; default: colorName = "红"; break; } return colorName; } void initComs() { String[] Portname = System.IO.Ports.SerialPort.GetPortNames(); mapComs.Clear(); combComs.Properties.TextEditStyle = TextEditStyles.DisableTextEditor; combComs.Properties.Items.Clear(); ComboBoxItemCollection col = combComs.Properties.Items; col.BeginUpdate(); oCom = System.Configuration.ConfigurationManager.AppSettings["Com"]; int oldIndex = 0; try { for (int i = 0; i < Portname.Length; i++) { String comText= Portname[i]; //col.Add(i); col.Add(comText); if (!string.IsNullOrEmpty(oCom) && oCom == Portname[i]) { oldIndex = i; } mapComs.Add(comText, getConfigIntValue(comText)); } } finally { col.EndUpdate(); } combComs.SelectedIndex = oldIndex; if (combComs.Properties.Items.Count> 0) { initialCom(); } } protected int getConfigIntValue(string key) { String text = System.Configuration.ConfigurationManager.AppSettings[key]; try { return Convert.ToInt32(text); } catch { } return 0; } Dictionary coms = new Dictionary(); dnwms activePort; int currentPort = 0; void initialCom() { try { int port = Convert.ToInt16(combComs.Text.Substring(3)); resetLights(); if (coms.Keys.Contains(port)) { if (String.IsNullOrEmpty(oCom) || !oCom.Equals(combComs.Text)) { writeConfig("Com", combComs.Text); oCom = combComs.Text; } currentPort = port; this.lbComstatus.Text = string.Format(combComs.Text + " 打开{0}", "成功"); } else { this.lbComstatus.Text = string.Format(combComs.Text + " 打开{0}", "失败"); } } catch(Exception e) { lbStatus.Text = string.Format(e.Message); } btnShowId.Enabled = currentPort > 0; } private void resetLights() { int port = Convert.ToInt16(combComs.Text.Substring(3)); if (unart_manage.com_manage[port] == null) { return; } activePort = unart_manage.com_manage[port].init_port; //activePort.check_state = true; if (pick.reset_device(port)) { coms[port] = activePort; } } private void resetAllLights() { foreach (string key in mapComs.Keys) { int port = Convert.ToInt16(key.Substring(3)); if (unart_manage.com_manage[port] == null) { continue; } activePort = unart_manage.com_manage[port].init_port; //activePort.check_state = true; if (pick.reset_device(port)) { coms[port] = activePort; } Thread.Sleep(500); } } private void btnInitialCom_Click(object sender, EventArgs e) { int deskid = 0; try { deskid = Convert.ToInt32(textEdit1.Text); } catch (Exception ex) { showErrorMsg("请输入分播台编号,编号需为整数"); return; } mapComs[combComs.Text] = deskid; writeConfig(combComs.Text, textEdit1.Text); } private void txtDeskId_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) { return; } string id = txtDeskId.Text.Trim(); if (string.IsNullOrEmpty(id)) { txtDeskId.SelectAll(); txtDeskId.Focus(); } try { deskId = Convert.ToInt16(id); } catch (Exception er) { txtDeskId.SelectAll(); txtDeskId.Focus(); return ; } txtOperater.SelectAll(); txtOperater.Focus(); } private void txtOperater_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) { return; } string id = txtOperater.Text; if (string.IsNullOrEmpty(id)) { txtOperater.SelectAll(); txtOperater.Focus(); return; } try { operater = Convert.ToInt32(id); } catch (Exception er) { txtOperater.SelectAll(); txtOperater.Focus(); return; } txtSeedNo.SelectAll(); txtSeedNo.Focus(); } private void txtSeedNo_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) { return; } txtBarcode.SelectAll(); txtBarcode.Focus(); } bool showId = true; private void combComs_SelectedIndexChanged(object sender, EventArgs e) { initialCom(); if (mapComs.ContainsKey(combComs.Text)) { textEdit1.Text = mapComs[combComs.Text] + ""; } } private void ribbon_Click(object sender, EventArgs e) { } private void simpleButton1_Click(object sender, EventArgs e) { if (currentPort == 0) { return; } if (showId) { pick.displayLabels(currentPort); } else { pick.clearLabels(currentPort); } showId = !showId; } private void chkValid_CheckedChanged(object sender, EventArgs e) { if (chkValid.Checked) { txtBarcode.BackColor = Color.Red; } else { txtBarcode.BackColor = Color.White; } txtBarcode.SelectAll(); txtBarcode.Focus(); try { operater = Convert.ToInt32(this.txtOperater.Text.Trim()); } catch { showErrorMsg("请扫描输入正确的操作员ID"); txtOperater.SelectAll(); txtOperater.Focus(); return; } elelab.pick.clearOrder(currentPort, getColor(operater)); } } }