private void codeTextBox_Validating(object sender, CancelEventArgs e) { TextBox box = sender as TextBox; string str = box.Text.Trim(); int code = 0, innerCode = 0; try { code = Convert.ToInt32(str); innerCode = Convert.ToInt32(productIDTextBox.Text); } catch { MessageBox.Show("必需是數字!"); e.Cancel = true; return; } BasicDataSet.ProductDataTable table = basicDataSet.Product; foreach (BasicDataSet.ProductRow row in table.Rows) { if (row.Code == code) { if (row.ProductID == innerCode) { continue; // 同一個產品 } MessageBox.Show("代碼<" + code.ToString() + ">和 " + row.ProductID.ToString() + "行的重複"); e.Cancel = true; } } }
void Item2Buffer(ByteBuilder Buf, CSaleItem item) { int index = productBindingSource.Find("ProductID", item.ProductID); string s = "產品" + item.ProductID.ToString(); if (index >= 0) { object o = productBindingSource.DataSource; BasicDataSet ds = (BasicDataSet)o; BasicDataSet.ProductDataTable t = ds.Product; BasicDataSet.ProductRow row = t[index]; s = row.Name; } int m; do { m = GB2312.GetByteCount(s); if (m <= 16) { break; } s = s.Substring(0, s.Length - 1); } while (true); int n = 16 - m + s.Length; Buf.AppendPadRight(s, n, GB2312); Buf.Append(d2str(item.Volume, 6), GB2312); // Buf.Append(d2str(item.Price , 5), GB2312); Buf.Append(d2str(item.Total, 10), GB2312); Buf.Append("\r\n", GB2312); }
private void 儲存SToolStripButton_Click(object sender, EventArgs e) { if (!this.Validate()) { MessageBox.Show("有資料錯誤, 請改好再存!"); return; } productBindingSource.EndEdit(); BasicDataSet.ProductDataTable table = (BasicDataSet.ProductDataTable)basicDataSet.Product.GetChanges(); if (table == null) { MessageBox.Show("沒有改動任何資料! 不用存"); return; } productTableAdapter.Update(basicDataSet.Product); MessageBox.Show(table.Rows.Count.ToString() + "筆有改動,己存檔!"); }