private void btnToDo_Click(object sender, EventArgs e) { try { string[] str = new string[dataGridView1.Rows.Count]; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Selected == true) { TryGameToDo tryGameToDoObject = new TryGameToDo(); tryGameToDoObject.Id = Convert.ToInt64(dataGridView1.Rows[i].Cells[0].Value); tryGameToDoObject.Url = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value); tryGameToDoObject.UserName = Convert.ToString(dataGridView1.Rows[i].Cells[2].Value); tryGameToDoObject.PassWord = Convert.ToString(dataGridView1.Rows[i].Cells[3].Value); tryGameToDoObject.ReMark = Convert.ToString(dataGridView1.Rows[i].Cells[4].Value); tryGameToDoObject.DeadLine = Convert.ToDateTime(dataGridView1.Rows[i].Cells[6].Value); tryGameToDoObject.IsDeleted = false; //sql = new SqLiteHelper("data source=mydb.db"); sql = new SqLiteHelper(); //创建名为TryGameToDo的数据表 sql.CreateTable("TryGameToDo", new string[] { "Id", "Url", "UserName", "PassWord", "ReMark", "DeadLine", "IsDeleted" }, new string[] { "INTEGER", "TEXT", "TEXT", "TEXT", "TEXT", "TEXT", "TEXT" }); //插入数据 sql.InsertValues("TryGameToDo", new string[] { tryGameToDoObject.Id.ToString(), tryGameToDoObject.Url, tryGameToDoObject.UserName, tryGameToDoObject.PassWord, tryGameToDoObject.ReMark, tryGameToDoObject.DeadLine.ToString(), tryGameToDoObject.IsDeleted.ToString() }); } } } catch (Exception ex) { MessageBox.Show("系统发生异常,请联系管理员!", "错误"); LogHelper.WriteLog("窗体异常", ex); } }
public Form1() { InitializeComponent(); //--------------------初始化数据库----------------------- sql = new SqLiteHelper("data source=" + Application.StartupPath + "\\mydb.db"); //创建名为table1的数据表 //sql.CreateTable("table1", new string[] { "BarCode", "Num", "Weight", "Volume", "Time", "UploadStatus" }, new string[] { "TEXT PRIMARY KEY", "INTEGER", "TEXT", "TEXT", "TEXT", "TEXT" }); sql.CreateTable("student", new string[] { "sno", "sname", "ssex", "sage", "sdept" }, new string[] { "TEXT PRIMARY KEY", "TEXT", "TEXT", "TEXT", "TEXT" }); sql.CreateTable("course", new string[] { "cno", "cname", "cpno", "ccredit" }, new string[] { "TEXT PRIMARY KEY", "TEXT", "TEXT", "TEXT" }); sql.CreateTable("teacher", new string[] { "tno", "tname", "tsex", "tage", "teb", "tpt", "cno1", "cno2", "cno3" }, new string[] { "TEXT PRIMARY KEY", "TEXT", "TEXT", "TEXT", "TEXT", "TEXT", "TEXT", "TEXT", "TEXT" }); sql.CreateTable("department", new string[] { "dno", "dname", "dmanager" }, new string[] { "TEXT PRIMARY KEY", "TEXT", "TEXT" }); sql.CreateTable("sct", new string[] { "GUID", "sno", "cno", "tno", "grade" }, new string[] { "TEXT PRIMARY KEY", "TEXT", "TEXT", "TEXT", "TEXT" }); //---------------------初始化界面----------------------- InitStudent(); InitCourse(); InitTeacher(); InitDepartment(); InitSct(); //-------------------------------------------------------- }
private void Init() { //ConsoleManager.Show();//打开信息打印窗口 LoginCommand = new DelegateCommand <Login>(runLoginCommand); LoginKeyDownCommand = new DelegateCommand <Login>(runLoginKeyDownCommand); sql = SqLiteHelper.getInstance; sql.ConnectionString = "data source=mydb.db"; sql.CreateTable("userTB", new string[] { "id", "username", "passwd", "userpower", "itemlist", "times" }, new string[] { "integer primary key AUTOINCREMENT", "varchar2(100) not null", "varchar2(100) not null", "int not null", "varchar2(100) not null", "int not null" }); //创建名为table1的数据表 DataTable dt = sql.ExecuteQuery("select count(*) from userTB"); int count = Convert.ToInt32(dt.Rows[0][0].ToString()); if (count == 0) { //是新表,需要创建管理员账户 sql.InsertValues("userTB", new string[] { null, "admin", "123456", "2", "1,1,1,1", "0" }); } }