public void Add(ExamClass model) { try { /* 操作本地数据 */ LocalData.Insert(0, model); } catch { Console.WriteLine("Error of adding data"); return; } }
public void Edit(int id, ExamClass model) { try { /* 操作本地数据 */ int ind = LocalData.FindIndex(item => item.Id == id); LocalData.RemoveAt(ind); LocalData.Insert(ind, model); } catch { Console.WriteLine("Error of editing data"); return; } }
public int Edit(int id, ExamClass model) { try { /* 操作本地数据 */ int ind = LocalData.FindIndex(item => item.Id == id); if (ind >= 0 && ind < LocalData.Count) { LocalData.RemoveAt(ind); LocalData.Insert(index, model); } return(UploadToSQL()); ///* 数据库同步操作 */ //using (var connect = new NpgsqlConnection(connectSql)) //{ // connect.Open(); // string updateSql = string.Format("UPDATE {0} SET Id=@param0, ClassNo=@param1, InstituteStudents=@param2, NumberStudents=@param3, " + // "InstituteProctors=@param4, NumberProctors=@param5 WHERE Id = {1};", tableName, id); // using (var updateCmd = new NpgsqlCommand(updateSql, connect)) // { // updateCmd.Parameters.AddWithValue("param0", NpgsqlDbType.Integer, model.Id); // updateCmd.Parameters.AddWithValue("param1", NpgsqlDbType.Text, model.ClassNo); // updateCmd.Parameters.AddWithValue("param2", NpgsqlDbType.Text, model.InstituteStudents); // updateCmd.Parameters.AddWithValue("param3", NpgsqlDbType.Integer, model.NumberStudents); // updateCmd.Parameters.AddWithValue("param4", NpgsqlDbType.Text, model.InstituteProctors); // updateCmd.Parameters.AddWithValue("param5", NpgsqlDbType.Integer, model.NumberProctors); // int count = updateCmd.ExecuteNonQuery(); // Console.WriteLine("Succeed to edit data of 'ClassNo:{0}' to Table: {1}.{2} ", model.ClassNo, sqlName, tableName); // return count; // } //} } catch { Console.WriteLine("Error of editing data to {0}.{1}", sqlName, tableName); return(-1); } }