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.Grid; using DevExpress.XtraGrid.Columns; using DeiNiu.Utils; using DevExpress.XtraEditors.Controls; namespace DeiNiu.wms.win { public partial class BoxReg : BasicRibbonForm { DataTable dtWaves; DataTable dtCurrentWave; bool isAfter = false; public BoxReg() { InitializeComponent(); txtBoxID.GotFocus += new EventHandler(textEditBarcode_GotFocus); txtBoxID.MouseUp += new MouseEventHandler(textEditBarcode_MouseUp); isAfter = WmsConstants.OUT_REGIST_BOX_AFTER_PICKED; // rdGrpType.SelectedIndex = isAfter ? 0 : 1; lgAfter.Visibility = isAfter ? DevExpress.XtraLayout.Utils.LayoutVisibility.Always:DevExpress.XtraLayout.Utils.LayoutVisibility.Never; refreshData(); initialTimer(); initialDataGrid(); bindWaves(); // focusInput(); resetInfo(); } void textEditBarcode_MouseUp(object sender, MouseEventArgs e) { //如果鼠标左键操作并且标记存在,则执行全选 if (e.Button == MouseButtons.Left && this.txtBoxID.Tag != null && (bool)txtBoxID.Tag == true) { txtBoxID.SelectAll(); } //取消全选标记 txtBoxID.Tag = false; } void textEditBarcode_GotFocus(object sender, EventArgs e) { txtBoxID.Tag = true; //设置标记 // txtBoxID.SelectAll(); //注意1 } void initialDataGrid() { this.gvBoxes.OptionsSelection.MultiSelect = false;//按shift / control 多选 this.gvBoxes.OptionsBehavior.AutoPopulateColumns = false; this.gvBoxes.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus; this.gvBoxes.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.CellFocus; this.gvBoxes.OptionsBehavior.Editable = false; this.gvBoxes.OptionsSelection.EnableAppearanceFocusedCell = false; //show line number this.gvBoxes.IndicatorWidth = 40; this.gvBoxes.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView_CustomDrawRowIndicator); gvBoxes.CustomColumnDisplayText += gridv_CustomColumnDisplayText; gvBoxes.RowCellStyle += gridView1_RowCellStyle; } private void initialDataGridColumns(GridView gridView1) { setupGridView(gridView1, false); //setupGridView(gridView2, false,false); //setupGridView(gridView3, false,false); // gridviewGoodsType.PopulateColumns(); gridView1.Columns.Clear(); // gridviewGoodsType.Columns.Remove(gridviewGoodsType.Columns["DealerPrice"]); GridColumn myCol0 = new GridColumn() { Caption = "ID", Visible = true, FieldName = "id" }; myCol0.Visible = false; gridView1.Columns.Add(myCol0); GridColumn myCol1 = new GridColumn() { Caption = "颜色", Visible = true, FieldName = "color"}; GridColumn myCol2 = new GridColumn() { Caption = "箱子编号", Visible = true, FieldName = "boxid" }; GridColumn myCol3 = new GridColumn() { Caption = "容积", Visible = true, FieldName = "volume" }; GridColumn myCol4 = new GridColumn() { Caption = "", Visible = true, FieldName = " " }; gridView1.Columns.Add(myCol1); gridView1.Columns.Add(myCol4); gridView1.Columns.Add(myCol2); gridView1.Columns.Add(myCol4); gridView1.Columns.Add(myCol3); //to show bottom scroll bar gridView1.OptionsView.ColumnAutoWidth = true; // gridView1.BestFitColumns(); gridView1.Focus(); // initialGridView2Columns(); //gridControl2.DataSource = null; } private void gridv_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { //if (sender == gridViewValidated) { if (e.Column.FieldName == "color") { if (!pickDetailStatus.ContainsValue(e.DisplayText)) { int display = -100; string disTxt = e.DisplayText; try { display = Convert.ToInt16(e.DisplayText); e.DisplayText = enumColors[display]; } catch { return; } } } } } private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { //e.Appearance.Font = new System.Drawing.Font("", 20, FontStyle.Bold); //下面是指定到具体单元格的字体显示红色 //if (e.RowHandle == 2 && e.Column.FieldName == "kunZs") //{ // e.Appearance.ForeColor = Color.Red; //} /* //而下面则是指定到具体某列的字体显示红色 if (e.Column.FieldName == "kunZs" || e.Column.FieldName == "Zzl" || e.Column.FieldName == "mperz" || e.Column.FieldName == "kunZl" || e.Column.FieldName == "mperkun") { e.Appearance.ForeColor = Color.Red; e.Appearance.Font = new System.Drawing.Font("", 9, FontStyle.Bold); } if (e.Column.FieldName == "整件" || e.Column.FieldName == "散件") { e.Appearance.ForeColor = Color.Red; e.Appearance.Font = new System.Drawing.Font("", 10, FontStyle.Bold); } * */ } private void txtBoxID_KeyUp(object sender, KeyEventArgs e) { string boxId = txtBoxID.Text.Trim(); resetInfo(); if (boxId.Length < 6) { return; } string waveNo = isAfter ? tabWaves.SelectedTabPageIndex == 0 ? comboWaves.Text : lastpickingWave : currentWave; if (string.IsNullOrEmpty(currentWave)) { this.lbRegResult.Text = "注册失败,无波次信息"; txtBoxID.SelectAll(); return; } try { int color = Convert.ToInt16( boxId.Substring(0, 2)); // if (!isAfter || tabWaves.SelectedTabPageIndex == 0) // { if (ComboColors.SelectedIndex > 0) { string colorText = ComboColors.Properties.Items[ ComboColors.SelectedIndex].Description; if (enumColors.ContainsValue(colorText)) { foreach (int key in enumColors.Keys) { if (enumColors[key] == colorText) { color = key; break; } } } } // } lbColor.Text = enumColors.ContainsKey(color)?enumColors[color] :"未知颜色"; this.lbRegResult.Text = pickClient.regBox(boxId, waveNo, color) ? "注册成功" : "注册失败"; closeClient(); closeClient(); // queryBoundBoxes(); txtBoxID.Text = ""; // txtBoxID.SelectAll(); focusInput(); } catch(Exception er) { // showErrorMsg(er,""); lbRegResult.Text = er.Message; focusInput(); } } private void resetInfo() { lbRegResult.Text = ""; lbColor.Text = ""; // lbCurrentWave.Text = ""; } void refreshData() { DataSet ds = pickClient.getBoxRegWaves(); closeClient(); dtWaves = ds.Tables[0]; dtCurrentWave = ds.Tables[1]; } void bindWaves() { if (!isAfter) { return; } try { if (dtWaves == null) { refreshData(); } List waves = new List(); string lastwave = ""; foreach (DataRow dr in dtWaves.Rows) { if (lastwave == dr["waveOrder"].ToString()) { continue; } lastwave = dr["waveOrder"].ToString(); waves.Add(lastwave); } initialComboBoxs(comboWaves, waves.ToArray(), ""); // bindColors(); } catch (Exception e) { showErrorMsg(e, e.Message); } finally { focusInput(); } } void bindColors() { if (dtWaves == null) { return; } DataView dv = isAfter ? dtWaves.DefaultView : dtCurrentWave.DefaultView ; string waveOrder = isAfter ? this.tabWaves.SelectedTabPageIndex ==0 ?comboWaves.Text:this.lbLastPickingWaveNo.Text :currentWave; dv.RowFilter = string.Format("dpsOrder ='{0}'", waveOrder); List colors = new List(); colors.Add("自动"); foreach (DataRowView dr in dv) { colors.Add(enumColors[Convert.ToInt16(dr["desk"].ToString().Trim())]); } // initialComboBoxs(ComboColors, colors.ToArray(), "自动"); ComboColors.Properties.Items.Clear(); foreach(string color in colors){ RadioGroupItem rgi = new RadioGroupItem(); rgi.Description = color; ComboColors.Properties.Items.Add(rgi); } // ComboColors.Lines = colors.ToArray(); // this.gridControlBoxes.DataSource = dv; } void queryBoundBoxes() { try { string waveOrder = isAfter ? this.tabWaves.SelectedTabPageIndex == 0 ? comboWaves.Text: this.lbLastPickingWaveNo.Text :currentWave; lbCurrentWave.Text = waveOrder; DataTable dt = pickClient.getBoxsByWave(waveOrder, -1); closeClient(); initialDataGridColumns(gvBoxes); gridControlBoxes.DataSource = dt; } catch (Exception e) { showErrorMsg(e, ""); } finally { // focusInput(); } } private void comboWaves_SelectedIndexChanged(object sender, EventArgs e) { if (tabWaves.SelectedTabPageIndex == 1) { bindColors(); queryBoundBoxes(); } } private void btnRefresh_Click(object sender, EventArgs e) { bindWaves(); bindCurrentWave(null,null); } string lastpickingWave = "",currentWave =""; delegate void whatisthisfor(); private void bindCurrentWave(object source, System.Timers.ElapsedEventArgs e) { try { DataSet ds = pickClient.getBoxRegWaves(); closeClient(); dtCurrentWave = ds.Tables[1]; DataTable dt = ds.Tables[0]; string tmpC ="",tmpL = ""; if (dtCurrentWave.Rows.Count > 0) { tmpC = dtCurrentWave.Rows[0][0].ToString(); } if (dt.Rows.Count > 0) { tmpL = dt.Rows[0][0].ToString(); } if (InvokeRequired) { this.Invoke(new whatisthisfor(delegate() { // focusInput(); if(!isAfter && tmpC != currentWave){ lbCurrentWave.Text = tmpC; currentWave = tmpC; } if (!isAfter) { bindColors(); queryBoundBoxes(); focusInput(); return; } if (tmpL != lastpickingWave) { this.lbLastPickingWaveNo.Text = tmpL; lastpickingWave = tmpL; // if (tabWaves.SelectedTabPageIndex == 0) { bindColors(); queryBoundBoxes(); } bindWaves(); } else { focusInput(); } // focusInput(); })); return; } if (!isAfter && tmpC != currentWave) { lbCurrentWave.Text = tmpC; currentWave = tmpC; } if (!isAfter) { bindColors(); queryBoundBoxes(); focusInput(); return; } if (tmpL != lastpickingWave) { this.lbLastPickingWaveNo.Text = tmpL; lastpickingWave = tmpL; // if (tabWaves.SelectedTabPageIndex == 0) { bindColors(); queryBoundBoxes(); } bindWaves(); } // focusInput(); } catch (Exception er) { showErrorMsg(er, ""); } } System.Timers.Timer timer = new System.Timers.Timer();//实例化Timer类 private void initialTimer() { int intTime = 5000; timer.Interval = intTime;//设置间隔时间,为毫秒; timer.Elapsed += new System.Timers.ElapsedEventHandler(bindCurrentWave );//到达时间的时候执行事件; timer.AutoReset = true;//设置是执行一次(false)还是一直执行(true); timer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件; timer.Start(); } private void tabWaves_SelectedPageChanged(object sender, DevExpress.XtraLayout.LayoutTabPageChangedEventArgs e) { bindColors(); queryBoundBoxes(); focusInput(); } private void focusInput() { LogHelper.debug(this.GetType(),string.Format("当前是焦点吗?{0}。。。。开始获得焦点",txtBoxID.Focused)); if (!txtBoxID.Focused) { txtBoxID.Focus(); } } private void rdGrpType_SelectedIndexChanged(object sender, EventArgs e) { isAfter = rdGrpType.SelectedIndex == 0; lgAfter.Visibility = isAfter ? DevExpress.XtraLayout.Utils.LayoutVisibility.Always : DevExpress.XtraLayout.Utils.LayoutVisibility.Never; bindCurrentWave(null,null); bindColors(); queryBoundBoxes(); focusInput(); } } }