using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions; namespace Core.LZMes.Client.UIM.comm { public partial class YardControl : UserControl { private const string _numPattern = @"^\d+$"; private const string _layerPattern = @"^[ABCabc]?$"; private const string _yardPattern = @"^[2-7]?$";//= @"^[3-5]?$" private bool _enabled = true; public new bool Enabled { get { return _enabled;} set { _enabled = value; uteYard.Enabled = _enabled; uteRow.Enabled = _enabled; uteFl.Enabled = _enabled; uteCol.Enabled = _enabled; } } public string Stock { get { return string.IsNullOrEmpty(uteYard.Text) ? "" : Convert.ToInt32(uteYard.Text,10).ToString(); } set { uteYard.Text = value; } } public string Row { get { return string.IsNullOrEmpty(uteRow.Text) ? "" : Convert.ToInt32(uteRow.Text, 10).ToString(); } set { uteRow.Text = value; } } public string Column { get { return string.IsNullOrEmpty(uteCol.Text) ? "" : Convert.ToInt32(uteCol.Text, 10).ToString(); } set { uteCol.Text = value; } } public string Layer { get { return string.IsNullOrEmpty(uteFl.Text) ? "" : uteFl.Text; } set { uteFl.Text = value; } } public YardControl() { InitializeComponent(); } public string GetYardFlag() { string yardFlag = string.Empty; if (!string.IsNullOrEmpty(uteYard.Text) && !string.IsNullOrEmpty(uteRow.Text) && !string.IsNullOrEmpty(uteFl.Text) && !string.IsNullOrEmpty(uteCol.Text)) { string rowStr = Convert.ToInt32(uteRow.Text,10).ToString(), colStr = Convert.ToInt32(uteCol.Text,10).ToString(); if (colStr.Length < 2) { colStr = "0" + colStr; } while (rowStr.Length < 3) { rowStr = "0" + rowStr; } yardFlag = uteYard.Text + "-" + colStr + uteFl.Text + "-" + rowStr; } return yardFlag; } public string GetYardFlagZJ() { string yardFlag = string.Empty; if (!string.IsNullOrEmpty(uteYard.Text) && !string.IsNullOrEmpty(uteRow.Text) && !string.IsNullOrEmpty(uteFl.Text) && !string.IsNullOrEmpty(uteCol.Text)) { string rowStr = Convert.ToInt32(uteRow.Text, 10).ToString(), colStr = Convert.ToInt32(uteCol.Text, 10).ToString(); if (colStr.Length < 2) { colStr = "0" + colStr; } while (rowStr.Length < 2) { rowStr = "0" + rowStr; } yardFlag = uteYard.Text + "-" + colStr + uteFl.Text + "-" + rowStr; } return yardFlag; } public void SetYardFlag(string yardFlag) { try { if (string.IsNullOrEmpty(yardFlag)) { uteYard.Text = string.Empty; uteRow.Text = string.Empty; uteFl.Text = string.Empty; uteCol.Text = string.Empty; } else { string[] flags = yardFlag.Split(new char[] { '-' }); if (flags.Length == 3) { uteYard.Text = flags[0]; uteCol.Text = flags[1].Substring(1, flags[1].Length - 2); uteFl.Text = flags[1].Substring(flags[1].Length - 1); uteRow.Text = flags[2]; } } } catch (Exception ex) { } } public new void Focus() { uteYard.Focus(); } private void uteYard_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 39 || e.KeyValue == 40 || e.KeyValue == 13) { uteCol.Focus(); } } private void uteYard_KeyPress(object sender, KeyPressEventArgs e) { if (!"2345".Contains(e.KeyChar) && (int)e.KeyChar != 8) { e.Handled = true; } e.KeyChar = char.ToUpper(e.KeyChar); } private void uteYard_TextChanged(object sender, EventArgs e) { Infragistics.Win.UltraWinEditors.UltraTextEditor te = (Infragistics.Win.UltraWinEditors.UltraTextEditor)sender; if (!Regex.IsMatch(te.Text, _yardPattern)) { te.Text = string.Empty; } if (te.Text.Length > 0) { uteCol.Focus(); uteCol.SelectAll(); } } private void uteRow_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 37 || e.KeyValue == 38) { uteFl.Focus(); uteFl.SelectAll(); } } private void uteRow_KeyPress(object sender, KeyPressEventArgs e) { if (((((int)e.KeyChar) < 48 || ((int)e.KeyChar) > 57)) && (int)e.KeyChar != 8) { e.Handled = true; } if ((int)e.KeyChar == 8 && string.IsNullOrEmpty(uteRow.Text)) { uteFl.Focus(); uteFl.SelectAll(); } } private void uteRow_TextChanged(object sender, EventArgs e) { Infragistics.Win.UltraWinEditors.UltraTextEditor te = (Infragistics.Win.UltraWinEditors.UltraTextEditor)sender; if (!Regex.IsMatch(te.Text, _numPattern)) { te.Text = string.Empty; } } private void uteFl_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 39 || e.KeyValue == 40 || e.KeyValue == 13) { uteRow.Focus(); uteRow.SelectAll(); } else if (e.KeyValue == 37 || e.KeyValue == 38) { uteCol.Focus(); uteCol.SelectAll(); } } private void uteFl_KeyPress(object sender, KeyPressEventArgs e) { if (!"AaBbCc".Contains(e.KeyChar) && (int)e.KeyChar != 8) { e.Handled = true; } if ((int)e.KeyChar == 8 && string.IsNullOrEmpty(uteFl.Text)) { uteCol.Focus(); uteCol.SelectAll(); } } private void uteFl_TextChanged(object sender, EventArgs e) { Infragistics.Win.UltraWinEditors.UltraTextEditor te = (Infragistics.Win.UltraWinEditors.UltraTextEditor)sender; if (!Regex.IsMatch(te.Text, _layerPattern)) { te.Text = string.Empty; } else { te.Text = te.Text.ToUpper(); } if (te.Text.Length > 0) { uteRow.Focus(); uteRow.SelectAll(); } } private void uteCol_KeyPress(object sender, KeyPressEventArgs e) { if (((((int)e.KeyChar) < 48 || ((int)e.KeyChar) > 57)) && (int)e.KeyChar != 8) { e.Handled = true; } if ((int)e.KeyChar == 8 && string.IsNullOrEmpty(uteCol.Text)) { uteYard.Focus(); uteYard.SelectAll(); } } private void uteCol_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 39 || e.KeyValue == 40 || e.KeyValue == 13) { uteFl.Focus(); uteFl.SelectAll(); } else if (e.KeyValue == 37 || e.KeyValue == 38) { uteYard.Focus(); uteYard.SelectAll(); } } private void uteCol_TextChanged(object sender, EventArgs e) { Infragistics.Win.UltraWinEditors.UltraTextEditor te = (Infragistics.Win.UltraWinEditors.UltraTextEditor)sender; if (!Regex.IsMatch(te.Text, _numPattern)) { te.Text = string.Empty; } if (te.Text.Length > 1) { uteFl.Focus(); uteFl.SelectAll(); } } } }