public static void Save(QuestionnaireItem QuestionnaireItem) { Save(new List <QuestionnaireItem>() { QuestionnaireItem }); }
public static void Remove(QuestionnaireItem QuestionnaireItem) { //更新資料庫 QuestionnaireItemAccessor.Delete(QuestionnaireItem); //更新記憶体 _QuestionnaireItemCache.Remove(QuestionnaireItem); }
internal static void Delete(QuestionnaireItem QuestionnaireItem) { using (SqlConnection SqlConnection = ConnectionManager.GetConnection()) { using (SqlCommand SqlCommand = SqlConnection.CreateCommand()) { SqlCommand.CommandText = "Delete " + " Order_QuestionnaireItem " + "WHERE " + " Id = @Id "; SqlCommand.Parameters.AddWithValue("Id", QuestionnaireItem.Id); SqlConnection.Open(); SqlCommand.ExecuteNonQuery(); } } }
internal static void UpdateInsert(List <QuestionnaireItem> QuestionnaireItems) { using (SqlConnection SqlConnection = ConnectionManager.GetConnection()) { SqlConnection.Open(); for (int i = 0; i < (QuestionnaireItems.Count / 200) + (QuestionnaireItems.Count % 200 == 0 ? 0 : 1); i++) { List <QuestionnaireItem> PartCourseItems = QuestionnaireItems.Skip(i * 200).Take(200).ToList(); StringBuilder CommandText = new StringBuilder(); SqlCommand SqlCommand = SqlConnection.CreateCommand(); for (int j = 0; j < PartCourseItems.Count; j++) { CommandText.Append("UPDATE" + " Order_QuestionnaireItem " + "SET " + " Title = @Title" + j + " ,ShortTitle = @ShortTitle" + j + " ,OptionType = @OptionType" + j + " ,Options = @Options" + j + " ,Sort = @Sort" + j + " ,UpdateTime = @UpdateTime" + j + " WHERE " + " Id = @Id" + j + " IF @@ROWCOUNT = 0 " + "BEGIN " + "INSERT INTO " + " Order_QuestionnaireItem " + "(Id, Title, ShortTitle, OptionType, Options, Sort, UpdateTime, CreateTime ) " + "VALUES " + " ( " + " @Id" + j + " ,@Title" + j + " ,@ShortTitle" + j + " ,@OptionType" + j + " ,@Options" + j + " ,@Sort" + j + " ,@UpdateTime" + j + " ,@CreateTime" + j + " ) " + " END " ); QuestionnaireItem QuestionnaireItem = PartCourseItems[j]; SqlCommand.Parameters.AddWithValue("Id" + j, QuestionnaireItem.Id); SqlCommand.Parameters.AddWithValue("Title" + j, QuestionnaireItem.Title); SqlCommand.Parameters.AddWithValue("ShortTitle" + j, QuestionnaireItem.ShortTitle); SqlCommand.Parameters.AddWithValue("OptionType" + j, QuestionnaireItem.OptionType.ToString()); SqlCommand.Parameters.AddWithValue("Options" + j, string.Join(",", QuestionnaireItem.Options)); SqlCommand.Parameters.AddWithValue("Sort" + j, QuestionnaireItem.Sort); SqlCommand.Parameters.AddWithValue("UpdateTime" + j, QuestionnaireItem.UpdateTime); SqlCommand.Parameters.AddWithValue("CreateTime" + j, QuestionnaireItem.CreateTime); } SqlCommand.CommandText = CommandText.ToString(); SqlCommand.ExecuteNonQuery(); } } }