private int batchExecuteSQL(string[] sql) { int buffer = 0; SQLiteConnection _connection = new SQLiteConnection(this._connectionString); _connection.Open(); SQLiteTransaction trans = _connection.BeginTransaction(); SQLiteCommand cmd = _connection.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.Transaction = trans; try { for (int i = 0; i < sql.Length; i++) { cmd.CommandText = sql[i]; cmd.ExecuteNonQuery(); buffer++; //触发事件 if (buffer == NotifyAfter) { if (RowsCopied != null) { RowsCopied(this, new SQLiteRowsCopiedEventArgs(buffer, sql.Length)); } buffer = 0; } } if (buffer != 0) { if (RowsCopied != null) { RowsCopied(this, new SQLiteRowsCopiedEventArgs(buffer, sql.Length)); } buffer = 0; } //提交事务,只有所有的数据都没有问题才提交事务. trans.Commit(); //异步压缩,分析数据库,确保所得的分析是最佳的. ThreadPool.QueueUserWorkItem(new WaitCallback((object o) => { StaticSQLiteHelper.ExecuteNonQuery("VACUUM ANALYZE"); })); } catch (SQLiteException) { trans.Rollback(); return(0); } finally { trans.Dispose(); cmd.Dispose(); } return(sql.Length); }
private void setupWeight() { //Global.Empty = true; StaticSQLiteHelper.ExecuteNonQuery(string.Format("update class_course set 优先级=1 where 周课时<{0};", Global.DayPerWeek)); StaticSQLiteHelper.ExecuteNonQuery(string.Format("update class_course set 优先级=2 where 周课时={0};", Global.DayPerWeek)); StaticSQLiteHelper.ExecuteNonQuery(string.Format("update class_course set 优先级=3 where 周课时>{0};", Global.DayPerWeek)); //StaticSQLiteHelper.ExecuteNonQuery("update class_course set 优先级=0 where 学科名字='体育';"); }
private void adjust() { //设置副科和主科 string sql = "update class_course set 副科=0;"; StaticSQLiteHelper.ExecuteNonQuery(sql); sql = "update class_course set 副科=1 where 学科名字 in ('政治','历史','地理','体育','音乐','信息')"; //sql = "update class_course set 优先级=3 where 学科名字 in ('政治','历史','地理','体育','音乐','信息')"; StaticSQLiteHelper.ExecuteNonQuery(sql); sql = "insert into teacher values(0,'无','自习',' ');"; StaticSQLiteHelper.ExecuteNonQuery(sql); }
private void ChangeTeacher() { string sql = string.Format("select 教师编号 from teacher where 教师姓名='{0}'", otn); oti = Convert.ToInt32(StaticSQLiteHelper.ExecuteScalar(sql)); sql = string.Format("select 教师编号 from teacher where 教师姓名='{0}';", ntn); nti = Convert.ToInt32(StaticSQLiteHelper.ExecuteScalar(sql)); //更新课程设置 sql = string.Format("update class_course set 教师姓名='{0}' where 班级={1} and 学科名字='{2}'", ntn, ci, sn); StaticSQLiteHelper.ExecuteNonQuery(sql); //更新白天课程 sql = string.Format("update schedule set teacher_id={0} where class_id={1} and teacher_id={2}", nti, ci, oti); StaticSQLiteHelper.ExecuteNonQuery(sql); //更新晚上课程 sql = string.Format("update night set teacher_id={0} where class_id={1} and teacher_id={2}", nti, ci, oti); StaticSQLiteHelper.ExecuteNonQuery(sql); }
private void Import() { string sql; sql = Dictionary2Sql(GetTeacherInforFromTable(_dtClassTeacher)); StaticSQLiteHelper.ClearAndVacuumTable("teacher"); StaticSQLiteHelper.ExecuteNonQuery(sql); sql = GetTeacherSQLFromTable(_dtClassTeacher); StaticSQLiteHelper.ClearAndVacuumTable("class_course"); StaticSQLiteHelper.ExecuteNonQuery(sql); sql = GetCourseAssignSQLFromTable(_dtCourse); StaticSQLiteHelper.ExecuteNonQuery(sql); sql = GetMasterSQLFromTable(_dtClassTeacher); StaticSQLiteHelper.ExecuteNonQuery(sql); setupWeight(); adjust(); //Global.Dirty = true; }