private void btnDb_Click(object sender, EventArgs e) { string sql = ""; foreach (var p in es) { sql = $"UPDATE bookshelflocations set CoordinateX = '{p.PointX}', CoordinateY = '{p.PointY}' WHERE BookShelfName = '{p.PointName}';"; DapperUtils.Execute(sql); Thread.Sleep(100); } MessageBox.Show("导出成功"); }
private void InitLv() { //设置detail视图 lvPoints.View = View.Details; lvPoints.FullRowSelect = true; lvPoints.MultiSelect = false; lvPoints.GridLines = true; lvPoints.SelectedIndexChanged += LvPoints_SelectedIndexChanged; //创建表头 Dictionary <string, int> chDicts = new Dictionary <string, int>() { ["点位名称"] = 150, ["点位坐标x"] = 80, ["点位坐标y"] = 80 }; foreach (var kv in chDicts) { ColumnHeader ch = new ColumnHeader(); ch.Text = kv.Key; ch.Width = kv.Value; ch.TextAlign = HorizontalAlignment.Left; lvPoints.Columns.Add(ch); } //从数据库加载数据 var data = DapperUtils.Query <BookShelfLocation>("SELECT * from bookshelflocations").OrderBy(x => x.BookShelfName); //添加lv内容 this.lvPoints.BeginUpdate(); foreach (var item in data) { List <string> contents = new List <string>() { item.BookShelfName, item.CoordinateX.ToString(), item.CoordinateY.ToString() }; this.lvPoints.Items.Add(new ListViewItem(contents.ToArray())); } this.lvPoints.EndUpdate(); }