using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using ICSSoft.Frame.Data.Entity; using ICSSoft.Frame.Data.BLL; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.ReferForm.AppReferForm; namespace ICSSoft.Frame.APP { public partial class FormICSNCRPT : DevExpress.XtraEditors.XtraForm { public decimal goodqty; public decimal ngqty; public decimal lotqty; public string status; public string desc; public FormICSNCRPT() { InitializeComponent(); } public FormICSNCRPT(string qty) { InitializeComponent(); lotqty = Convert.ToDecimal(qty); txtlotqty.Text = qty; } #region 关闭 退出 private void btnClose_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 移动窗体 private const int WM_NCHITTEST = 0x84; private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2; //首先必须了解Windows的消息传递机制,当有鼠标活动消息时, //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION , //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。 //重写窗体,使窗体可以不通过自带标题栏实现移动 protected override void WndProc(ref Message m) { //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息, //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体, //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。 //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。 switch (m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if ((int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION; return; } //拦截双击标题栏、移动窗体的系统消息 if (m.Msg != 0xA3) { base.WndProc(ref m); } } #endregion #region 新增 修改 private void save_Click(object sender, EventArgs e) { try { if(string.IsNullOrEmpty(txtfpqty.Text)) throw new Exception("请先输入不良数量!"); if (Convert.ToDecimal(txtfpqty.Text) > Convert.ToDecimal(txtlotqty.Text)) throw new Exception("不良数量无法超过追踪单数量,请确认!"); if (string.IsNullOrEmpty(txtItemCode.Text)) { throw new Exception("判定结果不能为空,请确认!"); } if (txtItemCode.Text == "报废" && Convert.ToDecimal(txtfpqty.Text) <= 0) { throw new Exception("报废状态请填写不良数量!"); } if (txtItemCode.Text == "返修" && Convert.ToDecimal(txtfpqty.Text) <= 0) { throw new Exception("返修状态请填写返修数量!"); } if (txtItemCode.Text == "降级使用" && Convert.ToDecimal(txtfpqty.Text) <= 0) { throw new Exception("降级使用状态请填写降级使用数量!"); } this.goodqty = Convert.ToDecimal(txtgoodqty.Text); this.ngqty = (Convert.ToDecimal(txtfpqty.Text)); this.status = txtItemCode.Text; this.desc = txtdesc.Text; this.DialogResult =DialogResult.OK; this.Close(); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } //} } #endregion #region 取消 private void can_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } #endregion private void txtngqty_KeyPress(object sender, KeyPressEventArgs e) { if (txtItemCode.EditValue.ToString() == "") { e.Handled = true; return; } var textBox1 = (TextBox)sender; if (e.KeyChar == 0x20 || e.KeyChar == 0x2D || (int)e.KeyChar == 46) e.KeyChar = (char)0; //禁止空格键和负数/小数 if (e.KeyChar > 0x20) { try { double.Parse(((TextBox)sender).Text + e.KeyChar.ToString()); } catch { e.KeyChar = (char)0; //处理非法字符 } } } private void txtngqty_TextChanged(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtfpqty.Text)) return; txtgoodqty.Text = (lotqty - Convert.ToDecimal(txtfpqty.Text)).ToString(); } private void FormICSNCRPT_Load(object sender, EventArgs e) { #region 判定结果 string sql = @"SELECT '返修' as 判定结果 union all SELECT '降级使用' as 判定结果 union all SELECT '报废' as 判定结果 union all SELECT '合格' as 判定结果"; sql = string.Format(sql, AppConfig.WorkPointCode); DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; txtItemCode.Properties.ValueMember = "判定结果"; txtItemCode.Properties.DisplayMember = "判定结果"; txtItemCode.Properties.DataSource = dt; txtItemCode.Properties.NullText = "";//空时的值 txtItemCode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体 txtItemCode.Properties.ValidateOnEnterKey = true;//回车确认 txtItemCode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard txtItemCode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容 //自适应宽度 txtItemCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup; #endregion } private void txtItemCode_EditValueChanged(object sender, EventArgs e) { switch (txtItemCode.EditValue.ToString()) { case "返修": { txtfpqty.ReadOnly = false; labelFP.Text = "返修数量:"; labelFP.Location = new Point(label3.Location.X, labelFP.Location.Y); break; } case "报废": { txtfpqty.ReadOnly = false; labelFP.Text = "不良数量:"; labelFP.Location = new Point(label3.Location.X, labelFP.Location.Y); break; } case "合格": { txtfpqty.ReadOnly =true; labelFP.Text = "不良数量:"; labelFP.Location = new Point(label3.Location.X, labelFP.Location.Y); txtfpqty.Text ="0"; break; } case "降级使用": { txtfpqty.ReadOnly = false; labelFP.Text = "降级使用数量:"; labelFP.Location = new Point(label3.Location.X-23, labelFP.Location.Y); txtfpqty.Text = "0"; break; } } } } }