private void FactRecvTextBox_TextChanged(object sender, EventArgs e) { //先验证输入是否正确 string word = ((TextBox)sender).Text.Trim(); if (!string.IsNullOrEmpty(word) && !ValueMarked.CheckMoney(word)) { ((TextBox)sender).Text = faceRecvPrices; //不成功就等于原来的数 ((TextBox)sender).SelectionStart = ((TextBox)sender).Text.Length; //把鼠标移到最后面 } else { faceRecvPrices = word; } //计算应找零的值 int wantPrice, faceRecv; if (!string.IsNullOrEmpty(salesRecvTextBox.Text) && int.TryParse(salesRecvTextBox.Text, out wantPrice) && !string.IsNullOrEmpty(FactRecvTextBox.Text) && int.TryParse(FactRecvTextBox.Text, out faceRecv)) { returnBackTextBox.Text = (faceRecv - wantPrice).ToString(); } }
private void saleRecvTextBox_TextChanged(object sender, EventArgs e) { string word = ((TextBox)sender).Text.Trim(); if (!string.IsNullOrEmpty(word) && !ValueMarked.CheckMoney(word)) { ((TextBox)sender).Text = faceSalesPrice; //不成功就等于原来的数 ((TextBox)sender).SelectionStart = ((TextBox)sender).Text.Length; //把鼠标移到最后面 } else { faceSalesPrice = word; } }
private void button1_Click(object sender, EventArgs e) { //检查是否输入已符合规范 if (dataGridView.Rows.Count <= 1) { MessageBox.Show("没有需要付款的项,请检查!"); return; } foreach (DataGridViewRow item in dataGridView.Rows) { if (null != item.Cells[1].Value && !string.IsNullOrEmpty(item.Cells[1].Value.ToString())) { //有商品标签代码 if (null == item.Cells[2].Value || string.IsNullOrEmpty(item.Cells[2].Value.ToString())) { //但是没有找到相应的商品名称 MessageBox.Show("商品填写不正确,请检查标签代码!"); return; } if (null == item.Cells[3].Value || string.IsNullOrEmpty(item.Cells[3].Value.ToString()) || !ValueMarked.CheckMoney(item.Cells[3].Value.ToString())) { //原价没有填 MessageBox.Show("原价填写不正确,请检查!"); return; } if (null == item.Cells[5].Value || string.IsNullOrEmpty(item.Cells[5].Value.ToString()) || !ValueMarked.CheckMoney(item.Cells[5].Value.ToString())) { //结算价没有填 MessageBox.Show("结算价填写不正确,请检查!"); return; } if (null == item.Cells[7].Value || string.IsNullOrEmpty(item.Cells[7].Value.ToString()) || !ValueMarked.CheckMoney(item.Cells[7].Value.ToString())) { //金额价没有填 MessageBox.Show("金额填写不正确,请检查!"); return; } } } if (string.IsNullOrEmpty(saleRecvTextBox.Text) || !ValueMarked.CheckMoney(saleRecvTextBox.Text)) { MessageBox.Show("应付金额填写不正确,请检查!"); return; } //检查是否有付款页面已经打开 if (null == m_sc) { m_sc = new SaleConfirm(); m_sc.SetSalesRecv(saleRecvTextBox.Text); DialogResult dr = m_sc.ShowDialog(); if (dr == DialogResult.OK) { //打印发票 TicketPrinter tp = new TicketPrinter(); foreach (DataGridViewRow item in dataGridView.Rows) { if (item.Cells[1].Value != null && item.Cells[2].Value != null && item.Cells[3].Value != null && item.Cells[4].Value != null && item.Cells[5].Value != null && item.Cells[6].Value != null && item.Cells[7].Value != null && !string.IsNullOrEmpty(item.Cells[1].Value.ToString()) && !string.IsNullOrEmpty(item.Cells[2].Value.ToString()) && !string.IsNullOrEmpty(item.Cells[3].Value.ToString()) && !string.IsNullOrEmpty(item.Cells[4].Value.ToString()) && !string.IsNullOrEmpty(item.Cells[5].Value.ToString()) && !string.IsNullOrEmpty(item.Cells[6].Value.ToString()) && !string.IsNullOrEmpty(item.Cells[7].Value.ToString())) { SalesClothes sc = new SalesClothes(); sc.TagCode = item.Cells[1].Value.ToString(); sc.Name = item.Cells[2].Value.ToString(); sc.Price = item.Cells[3].Value.ToString(); sc.Count = item.Cells[6].Value.ToString(); sc.SalePrice = item.Cells[7].Value.ToString(); tp.AddItem(sc); } } if (!string.IsNullOrEmpty(upOffTextBox.Text) && !string.IsNullOrEmpty(saleRecvTextBox.Text)) { tp.SetPrices(upOffTextBox.Text, saleRecvTextBox.Text); } PrinterErr perr = tp.Print(); switch (perr) { case PrinterErr.NoLPTPrinter: MessageBox.Show("找不到LPT打印机,请检查打印机的连接!"); break; case PrinterErr.CanNotOpenPrinter: MessageBox.Show("无法打开LPT1打印机,请检查打印机的端口是否正确!"); break; case PrinterErr.Success: default: MessageBox.Show("发票打印成功!"); dataGridView.Rows.Clear(); upOffTextBox.Text = ""; saleRecvTextBox.Text = ""; break; } } m_sc = null; } }
private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (3 == e.ColumnIndex || 5 == e.ColumnIndex || 7 == e.ColumnIndex) { int oldPrice; int newPrice; if (!string.IsNullOrEmpty(e.FormattedValue.ToString()) && !ValueMarked.CheckMoney(e.FormattedValue.ToString())) { //非货币 e.Cancel = true; this.dataGridView.CancelEdit(); } else if (e.ColumnIndex == 3) { if (int.TryParse(e.FormattedValue.ToString(), out oldPrice)) { if (oldPrice < 0) { //原价输入负值 e.Cancel = true; this.dataGridView.CancelEdit(); } if (dataGridView[5, e.RowIndex].Value != null && int.TryParse(dataGridView[5, e.RowIndex].Value.ToString(), out newPrice) && newPrice > oldPrice) { //结算价高于原价或原价输入负值 e.Cancel = true; this.dataGridView.CancelEdit(); } } } else if (e.ColumnIndex == 5) { if (int.TryParse(e.FormattedValue.ToString(), out newPrice)) { if (newPrice < 0) { //结算价输入负值 e.Cancel = true; this.dataGridView.CancelEdit(); } if (dataGridView[3, e.RowIndex].Value != null && int.TryParse(dataGridView[3, e.RowIndex].Value.ToString(), out oldPrice) && newPrice > oldPrice) { //结算价高于原价 e.Cancel = true; this.dataGridView.CancelEdit(); } } } } else if (4 == e.ColumnIndex) { int discount; if (string.IsNullOrEmpty(e.FormattedValue.ToString()) || !int.TryParse(e.FormattedValue.ToString(), out discount) || discount > 100 || discount <= 0) { e.Cancel = true; this.dataGridView.CancelEdit(); } } else if (6 == e.ColumnIndex) { int count; if (string.IsNullOrEmpty(e.FormattedValue.ToString()) || !int.TryParse(e.FormattedValue.ToString(), out count) || count > 999 || count < -999) { e.Cancel = true; this.dataGridView.CancelEdit(); } } }