private void CLzero() { this.lblCLzl.Text = "归零中!"; Application.DoEvents(); this.cheng[this.CLcheng].setZERO(); Thread.Sleep(this.cheng[this.CLcheng].chengPara.zeroSpeed); this.cheng[this.CLcheng].getVal(); Label lblClzl = this.lblCLzl; Decimal?showVal; string str; if (this.cheng[this.CLcheng].showVal.HasValue) { showVal = this.cheng[this.CLcheng].showVal; str = showVal.Value.ToString("0.### g"); } else { str = "无值"; } lblClzl.Text = str; this.lblCLwd.Text = this.cheng[this.CLcheng].WenDing ? "稳定" : ""; Application.DoEvents(); showVal = this.cheng[this.CLcheng].showVal; int num1; if (showVal.HasValue) { showVal = this.cheng[this.CLcheng].showVal; Decimal num2 = -this.cheng[this.CLcheng].chengPara.JingDu; if ((!(showVal.GetValueOrDefault() < num2) ? 0 : (showVal.HasValue ? 1 : 0)) == 0) { showVal = this.cheng[this.CLcheng].showVal; Decimal jingDu = this.cheng[this.CLcheng].chengPara.JingDu; if ((!(showVal.GetValueOrDefault() > jingDu) ? 0 : (showVal.HasValue ? 1 : 0)) == 0) { num1 = this.cheng[this.CLcheng].WenDing ? 1 : (!this.cheng[this.CLcheng].chengPara.zeroWD ? 1 : 0); goto label_8; } } } num1 = 0; label_8: if (num1 == 0) { ++this.CLerrTPcount; this.CLokCount = 0; this.lblTPerr.Text = this.CLerrTPcount.ToString(); } else { ++this.CLokCount; } if (this.CLerrTPcount >= 3) { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav"; this.TSsound.Play(); this.lblTS.Visible = false; frmTS frmTs = new frmTS(this.CLrl, this.CLcheng, this.CLdeng, "电子称归零失败,检查设备!!!", "“确认”再试一次", "“清除”取消称料", Keys.Back); DialogResult dialogResult = frmTs.ShowDialog((IWin32Window)this); frmTs.Close(); this.lblTS.Visible = true; if (dialogResult == DialogResult.OK) { this.CLerrTPcount = 0; this.CLokCount = 0; this.lblTPerr.Text = ""; this.CLzero(); } else { this.CLend(); } } else if (this.CLokCount >= this.cheng[this.CLcheng].chengPara.zeroCi) { this.CLerrTPcount = 0; this.CLokCount = 0; this.CLallowKey = true; this.lblTPerr.Text = ""; this.CLtimer.Interval = this.cheng[this.CLcheng].chengPara.scanSpeed; this.CLtimer.Start(); } else { this.CLzero(); } }
private void this_KeyUp(object sender, KeyEventArgs e) { if (this.staCL == frmCL.enumSta.显示空白 || this.staCL == frmCL.enumSta.显示有料) { this.lblKeyS.Text += e.KeyValue.ToString("X2"); Application.DoEvents(); if (Settings.Default.paraKeyB == 18 && e.KeyCode == Keys.F1 || Settings.Default.paraKeyB == 16 && (e.KeyCode == Keys.OemPeriod || e.KeyCode == Keys.Decimal)) { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\ding.wav"; this.TSsound.Play(); frmCLsch frmClsch = Settings.Default.paraKeyB != 18 ? new frmCLsch("“返回”退出", Keys.Escape) : new frmCLsch("“F2”退出", Keys.F2); DialogResult dialogResult = frmClsch.ShowDialog((IWin32Window)this); frmClsch.Close(); if (dialogResult == DialogResult.OK) { if (this.showLD(frmClsch.txtSch.Text)) { this.staCL = frmCL.enumSta.显示有料; this.dgvData.CurrentCell = this.dgvData.Rows[0].Cells[this.colRL.Name]; this.showRow(); } else { this.staCL = frmCL.enumSta.显示空白; } } this.lblKeyS.Text = ""; } else if (e.KeyCode == Keys.Prior) { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\ding.wav"; this.TSsound.Play(); if (this.dgvData.CurrentCell != null) { int rowIndex = this.dgvData.CurrentCell.RowIndex; if (rowIndex > 0) { this.dgvData.CurrentCell = this.dgvData.Rows[rowIndex - 1].Cells[this.colRL.Name]; this.showRow(); } } this.lblKeyS.Text = ""; } else if (e.KeyCode == Keys.Next) { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\ding.wav"; this.TSsound.Play(); if (this.dgvData.CurrentCell != null) { int rowIndex = this.dgvData.CurrentCell.RowIndex; if (rowIndex < this.dgvData.RowCount - 1) { this.dgvData.CurrentCell = this.dgvData.Rows[rowIndex + 1].Cells[this.colRL.Name]; this.showRow(); } } this.lblKeyS.Text = ""; } else { if (e.KeyCode != Keys.Return) { return; } this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\ding.wav"; this.TSsound.Play(); if (this.staCL == frmCL.enumSta.显示有料 && this.lblKeyS.Text.Length == 2) { this.CLstart(); } this.lblKeyS.Text = ""; } } else { if (this.staCL != frmCL.enumSta.称料正在 || !this.CLallowKey) { return; } if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete) { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\ding.wav"; this.TSsound.Play(); this.CLtimer.Stop(); this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\ding.wav"; this.TSsound.Play(); this.lblTS.Visible = false; frmTS frmTs = Settings.Default.paraKeyB != 18 ? new frmTS(this.CLrl, this.CLcheng, this.CLdeng, "确定取消称料吗!!!", "“确认”退出称料", "“返回”继续称料", Keys.Escape) : new frmTS(this.CLrl, this.CLcheng, this.CLdeng, "确定取消称料吗!!!", "“确认”退出称料", "“ F2 ”继续称料", Keys.F2); DialogResult dialogResult = frmTs.ShowDialog((IWin32Window)this); frmTs.Close(); this.lblTS.Visible = true; switch (dialogResult) { case DialogResult.OK: if (this.cheng[this.CLcheng].showVal.Value > new Decimal(0)) { this.CLzlmb = new Decimal(0); this.CLzlpz = new Decimal(0); this.CLsave(); this.dgvData.CurrentRow.Cells[this.colCL.Name].Value = (object)(this.dgvData.CurrentRow.Cells[this.colCL.Name].FormattedValue.ToString() == "" ? this.cheng[this.CLcheng].showVal.Value : (Decimal)this.dgvData.CurrentRow.Cells[this.colCL.Name].Value + this.cheng[this.CLcheng].showVal.Value); } this.CLend(); break; case DialogResult.Cancel: this.CLtimer.Start(); break; } } else if (Settings.Default.paraKeyB == 18 && e.KeyCode == Keys.F2 || Settings.Default.paraKeyB == 16 && e.KeyCode == Keys.Prior) { this.CLtimer.Enabled = false; frmCLinputMC frmClinputMc = new frmCLinputMC((Decimal)this.dgvData.CurrentRow.Cells[this.colYL.Name].Value, "“确认”应用免称", "“返回”退出输入", Keys.Escape); this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\ding.wav"; this.TSsound.Play(); if (frmClinputMc.ShowDialog((IWin32Window)this) == DialogResult.OK) { this.CLzlmc = Convert.ToDecimal(frmClinputMc.txtZL.Text); this.CLzlmb = (Decimal)this.dgvData.CurrentRow.Cells[this.colYL.Name].Value - this.CLzlmc + this.CLzlpz; this.lblCLmbzl.Text = this.CLzlmb.ToString("0.####克"); this.lblCLmcpz.Text = (this.CLzlmc == new Decimal(0) ? "" : "(免称:" + this.CLzlmc.ToString("0.####克") + ")") + (this.CLzlpz == new Decimal(0) ? "" : "(皮重:" + this.CLzlpz.ToString("0.####克") + ")"); } frmClinputMc.Close(); this.CLtimer.Enabled = true; } } }
private void CLstart() { if (this.dgvData.CurrentRow.Index < 0) { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav"; this.TSsound.Play(); frmError frmError = new frmError("当前称料行不存在!请再次查询!"); int num = (int)frmError.ShowDialog((IWin32Window)this); frmError.Close(); } else { //DBpf dbpf = new DBpf(Settings.Default.DBconn); //T_PFmain tPfmain = dbpf.T_PFmain.Where<T_PFmain>((Expression<Func<T_PFmain, bool>>)(a => a.danhao == this.txtLDH.Text)).SingleOrDefault<T_PFmain>(); T_PFmain tPfmain = db.Queryable <T_PFmain>() .Where(a => a.danhao == this.txtLDH.Text) .First(); if (tPfmain == null || tPfmain.sta != "已审核") { //dbpf.Dispose(); this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav"; this.TSsound.Play(); frmError frmError = new frmError("料单未审核或不存在!请再次查询!"); int num = (int)frmError.ShowDialog((IWin32Window)this); frmError.Close(); } else { //T_PFdata tPfdata = dbpf.T_PFdata.Where<T_PFdata>((Expression<Func<T_PFdata, bool>>)(a => a.SN == (long)this.dgvData.CurrentRow.Cells[this.colSN.Name].Value)).SingleOrDefault<T_PFdata>(); T_PFdata tPfdata = db.Queryable <T_PFdata>() .Where(a => a.SN == (long)this.dgvData.CurrentRow.Cells[this.colSN.Name].Value) .First(); if (tPfdata == null || tPfdata.ranliao != this.dgvData.CurrentRow.Cells[this.colRL.Name].Value.ToString()) { //dbpf.Dispose(); this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav"; this.TSsound.Play(); frmError frmError = new frmError("料单数据发生了改变!请再次查询!"); int num = (int)frmError.ShowDialog((IWin32Window)this); frmError.Close(); } else { Decimal num1 = new Decimal(0); Decimal num2; if (this.txtLDH.Text.StartsWith("LD") || this.txtLDH.Text.Length == 10 && this.txtLDH.Text.StartsWith("8")) { num2 = tPfdata.yongliang; if (tPfdata.yongliangDW == "Kg" || tPfdata.yongliangDW == "L") { num2 *= new Decimal(1000); } } else { num2 = tPfdata.JLyongliang; if (tPfdata.JLyongliangDW == "Kg" || tPfdata.JLyongliangDW == "L") { num2 *= new Decimal(1000); } } if (num2 != (Decimal)this.dgvData.CurrentRow.Cells[this.colYL.Name].Value) { //dbpf.Dispose(); this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav"; this.TSsound.Play(); frmError frmError = new frmError("料单数据发生了改变!请再次查询!"); int num3 = (int)frmError.ShowDialog((IWin32Window)this); frmError.Close(); } else { //dbpf.Dispose(); if (this.dgvData.CurrentRow.Cells[this.colCL.Name].FormattedValue.ToString() != "" && Convert.ToDecimal(this.dgvData.CurrentRow.Cells[this.colCL.Name].FormattedValue.ToString()) > new Decimal(0)) { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav"; this.TSsound.Play(); this.lblTS.Visible = false; frmTS frmTs = new frmTS(this.CLrl, this.CLcheng, this.CLdeng, "该染料已称过,再称一次吗!!!", "“确认”再称一次", "“清除”取消称料", Keys.Back); DialogResult dialogResult = frmTs.ShowDialog((IWin32Window)this); frmTs.Close(); this.lblTS.Visible = true; if (dialogResult != DialogResult.OK) { return; } } if (this.CLcheng < 0) { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav"; this.TSsound.Play(); frmError frmError = new frmError("无法找到合适的称,请核对!"); int num3 = (int)frmError.ShowDialog((IWin32Window)this); frmError.Close(); } else { if (!this.plcCL.OpenDeng(this.CLdeng)) { this.plcCL.OpenDeng(this.CLdeng); } this.staCL = frmCL.enumSta.称料正在; this.CLerrTPcount = 0; this.CLokCount = 0; this.CLallowKey = false; this.lblTPerr.Text = ""; this.CLzero(); } } } } } }
private void CLtimer_Tick(object sender, EventArgs e) { this.CLtimer.Stop(); if (this.lblTS.ForeColor == Color.DarkRed) { this.lblTS.ForeColor = Color.Yellow; } else { this.lblTS.ForeColor = Color.DarkRed; } if (this.CLdeng > 0) { DataGridViewCell cell = this.dgvDH.Rows[(this.CLdeng - 1) / 8].Cells[(this.CLdeng - 1) % 8]; cell.Style.BackColor = !(cell.Style.BackColor == Color.Red) ? Color.Red : Color.Green; } this.cheng[this.CLcheng].getVal(); this.lblCLzl.Text = !this.cheng[this.CLcheng].showVal.HasValue ? "无值" : this.cheng[this.CLcheng].showVal.Value.ToString("0.### g"); this.lblCLwd.Text = this.cheng[this.CLcheng].WenDing ? "稳定" : ""; if (!this.cheng[this.CLcheng].showVal.HasValue) { this.lblCLzl.Text = ""; this.lblCLwd.Text = ""; this.lblCLwc.Text = this.lblCLmbzl.Text; ++this.CLerrTPcount; if (this.CLerrTPcount >= 3) { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav"; this.TSsound.Play(); this.lblTS.Visible = false; frmTS frmTs = new frmTS(this.CLrl, this.CLcheng, this.CLdeng, "电子称读取失败,检查设备!!!", "“确认”再试一次", "“清除”取消称料", Keys.Back); DialogResult dialogResult = frmTs.ShowDialog((IWin32Window)this); frmTs.Close(); this.lblTS.Visible = true; if (dialogResult == DialogResult.OK) { this.CLerrTPcount = 0; this.CLokCount = 0; this.lblTPerr.Text = ""; } else { this.CLend(); return; } } this.CLtimer.Start(); } else { this.CLerrTPcount = 0; this.lblTPerr.Text = ""; Decimal num1 = this.cheng[this.CLcheng].showVal.Value; this.lblCLwc.Text = (this.CLzlmb - num1).ToString("0.####克"); if (this.CLzlmb > new Decimal(0)) { int num2 = (int)(num1 / this.CLzlmb * new Decimal(100)); this.pBarCL.Value = num2 < 0 ? 0 : (num2 > 100 ? 100 : num2); } else { this.pBarCL.Value = 100; } if (num1 >= this.CLzlmb - this.CLzlyc && num1 <= this.CLzlmb + this.CLzlyc) { if (this.TSsound.SoundLocation != Application.StartupPath + "\\Sound\\CLok.wav") { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\CLok.wav"; this.TSsound.PlayLooping(); } } else if (num1 >= -this.cheng[this.CLcheng].chengPara.JingDu && num1 <= this.cheng[this.CLcheng].chengPara.JingDu) { if (this.TSsound.SoundLocation != Application.StartupPath + "\\Sound\\CLbegin.wav") { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\CLbegin.wav"; this.TSsound.PlayLooping(); } } else if (num1 > this.CLzlmb + this.CLzlyc) { if (this.TSsound.SoundLocation != Application.StartupPath + "\\Sound\\CLover.wav") { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\CLover.wav"; this.TSsound.PlayLooping(); } } else if (num1 < this.CLzlmb - this.cheng[this.CLcheng].chengPara.JingDu * new Decimal(200)) { if (this.TSsound.SoundLocation != Application.StartupPath + "\\Sound\\CLfar.wav") { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\CLfar.wav"; this.TSsound.PlayLooping(); } } else if (num1 >= this.CLzlmb - this.cheng[this.CLcheng].chengPara.JingDu * new Decimal(200) && this.TSsound.SoundLocation != Application.StartupPath + "\\Sound\\CLnear.wav") { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\CLnear.wav"; this.TSsound.PlayLooping(); } if (num1 < this.CLzlmb - this.CLzlyc || num1 > this.CLzlmb + this.CLzlyc || this.cheng[this.CLcheng].chengPara.OKwd && !this.cheng[this.CLcheng].WenDing) { this.CLokCount = 0; } else { ++this.CLokCount; } if (this.CLokCount >= this.cheng[this.CLcheng].chengPara.OKci) { this.CLsave(); this.dgvData.CurrentRow.Cells[this.colCL.Name].Value = (object)(this.dgvData.CurrentRow.Cells[this.colCL.Name].FormattedValue.ToString() == "" ? num1 + this.CLzlmc - this.CLzlpz : (Decimal)this.dgvData.CurrentRow.Cells[this.colCL.Name].Value + num1 + this.CLzlmc - this.CLzlpz); if (this.dgvData.CurrentRow.Index < this.dgvData.RowCount - 1) { this.dgvData.CurrentCell = this.dgvData.Rows[this.dgvData.CurrentRow.Index + 1].Cells[this.colRL.Name]; Application.DoEvents(); } else { this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav"; this.TSsound.Play(); frmCLend frmClend = new frmCLend(); int num2 = (int)frmClend.ShowDialog((IWin32Window)this); frmClend.Close(); } this.CLend(); } else { this.CLtimer.Start(); } } }