private void queryBtn_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(batchInfoTextBox.Text)) { using (var db = JunShengDb.Create()) { var batchInfos = JunShengDb.QueryBatchInfosByBatch(db, batchInfoTextBox.Text).ToArray(); if (batchInfos.Length > 0) { var dataTable = new DataTable(); var ccc = new DataColumn(nameof(BatchItem.BatchNo)); dataTable.Columns.Add(new DataColumn(nameof(BatchItem.BatchNo))); dataTable.Columns.Add(new DataColumn(nameof(BatchItem.SerinalNo))); dataTable.Columns.Add(new DataColumn(nameof(BatchItem.QRCodeContent))); foreach (var info in batchInfos) { var row = dataTable.NewRow(); row[nameof(BatchItem.BatchNo)] = info.BatchNo; row[nameof(BatchItem.SerinalNo)] = info.SerinalNo; row[nameof(BatchItem.QRCodeContent)] = info.QRCodeContent; dataTable.Rows.Add(row); } dataGridView1.DataSource = dataTable; dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells); } } } }
public static JunShengDb Create() { string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); dir = Path.Combine(dir, "JunSheng"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string fullPath = Path.Combine(dir, _defaultFileNameh); var db = new JunShengDb(fullPath); db.CreateTable <BatchItem>(); db.CreateTable <Batch>(); return(db); }
private AppContext() { DB = JunShengDb.Create(); }