Beispiel #1
0
        //测试新增
        private void button1_Click(object sender, EventArgs e)
        {
            int k = 0;

            for (int i = 0; i < 100; i++)
            {
                Task.Factory.StartNew(new Action(() =>
                {
                    try
                    {
                        DBHelper.BeginTransaction();

                        BS_Template model = new BS_Template();
                        model.id          = m_TemplateDal.GetMaxId().ToString();
                        model.code        = k.ToString("0000");
                        model.name        = "测试" + k.ToString();
                        model.remarks     = "测试" + k.ToString();
                        model.type        = ((int)Enums.TemplateType.Notice).ToString();
                        m_TemplateDal.Insert(model);
                        //throw new Exception("a");

                        BS_Test test = new BS_Test();
                        test.id      = m_TestDal.GetMaxId().ToString();
                        test.code    = "测试" + k.ToString();
                        test.name    = "测试" + k.ToString();
                        test.remarks = "测试" + k.ToString();
                        m_TestDal.Insert(test);

                        DBHelper.CommitTransaction();

                        k++;
                        if (k == 100)
                        {
                            MessageBox.Show("插入数据成功");
                            this.Invoke(new InvokeDelegate(() =>
                            {
                                BindList();
                            }));
                        }
                    }
                    catch (Exception ex)
                    {
                        DBHelper.RollbackTransaction();
                        MessageBox.Show(ex.Message);
                    }
                }));
            }
        }