private void btnTestMySQL_Click(object sender, EventArgs e) { try { if (false) { int k = 0; for (int i = 0; i < 10; i++) { Task.Factory.StartNew(new Action(() => { try { DBHelper.BeginTransaction(); utils_test model = new utils_test(); model.code = k.ToString("0000"); model.name = "测试" + k.ToString(); model.text = "测试" + k.ToString(); model.content = new byte[10]; model.content[1] = (byte)100; model.content[2] = (byte)99; model.content[3] = (byte)98; model.add_time = DateTime.Now; m_TestMySqlDal.Insert(model); DBHelper.CommitTransaction(); k++; if (k == 100) { MessageBox.Show("插入数据成功"); this.Invoke(new InvokeDelegate(() => { BindList(); })); } } catch (Exception ex) { DBHelper.RollbackTransaction(); MessageBox.Show(ex.Message); } })); } } Task.Factory.StartNew(() => { Thread.Sleep(100); List <utils_test> list = m_TestMySqlDal.GetList(); List <utils_test> list2 = m_TestMySqlDal.GetList("测试", DateTime.Now.Date, DateTime.Now.Date.AddDays(1).AddSeconds(-1)); MessageBox.Show("成功,list数量:" + list.Count); }); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 查询单个记录 /// </summary> public utils_test Get(string name) { SqlString sql = new SqlString(@" select * from utils_test t where 1=1 and name=@name", name); utils_test result = DBHelper.FindBySql <utils_test>(sql.SQL, sql.Params); return(result); }
private void btnTestMySQL_Click(object sender, EventArgs e) { try { #region 新增数据 if (false) { _task.Run(() => { int n = 1000; DateTime dt = DateTime.Now; List <Task> tList = new List <Task>(); for (int i = 1; i <= n; i++) { Task t = _task.Run((obj) => { var k = (int)obj; try { DBHelper.BeginTransaction(); utils_test model = new utils_test(); model.code = k.ToString("0000"); model.name = "测试" + k.ToString(); model.text = "测试" + k.ToString(); model.content = new byte[10]; model.content[1] = (byte)100; model.content[2] = (byte)99; model.content[3] = (byte)98; model.add_time = DateTime.Now; m_TestMySqlDal.Insert(model); DBHelper.CommitTransaction(); } catch (Exception ex) { DBHelper.RollbackTransaction(); MessageBox.Show(ex.Message); } }, i); tList.Add(t); } Task.WaitAll(tList.ToArray()); double d = DateTime.Now.Subtract(dt).TotalSeconds; MessageBox.Show(n + "条数据插入完成,耗时:" + d.ToString("0.000") + "秒"); this.Invoke(new Action(() => { BindList(); })); }); } #endregion #region 查询数据 if (true) { Task.Factory.StartNew(() => { try { Thread.Sleep(100); DateTime dt = DateTime.Now; utils_test info = m_TestMySqlDal.Get("测试1"); List <utils_test> list1 = m_TestMySqlDal.GetList3("测试", DateTime.Now.Date, DateTime.Now.Date.AddDays(1).AddSeconds(-1)); double d = DateTime.Now.Subtract(dt).TotalSeconds; MessageBox.Show("成功,list1总数:" + list1.Count + ",耗时:" + d.ToString("0.000") + "秒"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }); } #endregion #region 查询数据 if (false) { Task.Factory.StartNew(() => { try { Thread.Sleep(100); List <TWO_ORDER> list1 = m_TestMySqlDal.GetList("Shao", new DateTime(2020, 5, 1, 0, 0, 0), new DateTime(2020, 5, 15, 0, 0, 0), 1); PagerModel pager = new PagerModel(2, 10); List <TWO_ORDER> list2 = m_TestMySqlDal.GetListPage(ref pager, "Guo", new DateTime(2020, 5, 1, 0, 0, 0), new DateTime(2020, 5, 15, 0, 0, 0), 1); MessageBox.Show("成功,list1总数:" + list1.Count + ",list2总数:" + pager.totalRows + ",当前页:" + pager.page + ",当前页数量:" + list2.Count); } catch (Exception ex) { MessageBox.Show(ex.Message); } }); } #endregion } catch (Exception ex) { MessageBox.Show(ex.Message); } }