/// <summary> /// 重置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnReset_Click(object sender, RoutedEventArgs e) { this._id = 0; this._model = null; this.txtTitle.Text = ""; this.txtContent.Text = ""; this.btnOk.Content = "添加"; }
private void lstNote_SelectionChanged(object sender, SelectionChangedEventArgs e) { this._id = 0; if (this.lstNote.SelectedItems.Count > 0) { this.btnOk.Content = "修改"; this._model = lstNote.SelectedItem as Entity.Note; this._id = this._model.Id; this.txtTitle.Text = this._model.Title; this.txtContent.Text = this._model.Content; this.cboType.SelectedValue = this._model.TypeId; this._id = this._model.Id; } }
/// <summary> /// 构造 /// </summary> public NoteViewModel() { this._note = new Entity.Note(); DeleteCommand = new CommandBase(Delete); SaveCommand = new CommandBase(Save); CloseCommand = new CommandBase(Close); LoadCommand = new CommandBase(Close); if (!IsInDesignMode) { List <Entity.Note> list = this._dalNote.GetList(" 1=1 ", null, " CreateDate DESC");//记事列表 NoteList = new ListCollectionView(list); } this.NoteList.SortDescriptions.Add(new SortDescription("Note.ModifyDate", ListSortDirection.Descending)); this.NoteList.CurrentChanged += NoteList_CurrentChanged; //this.NoteList.Filter = this.FilterNote; }
/// <summary> /// 添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOk_Click(object sender, RoutedEventArgs e) { this._model = new Entity.Note(); string title = this.txtTitle.Text.Trim(); string content = this.txtContent.Text.Trim(); if (title.Length == 0 || content.Length == 0) { MessageBox.Show("标题或内容不能为空!", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); return; } this._model.Title = title; this._model.Content = content; this._model.CreateDate = DateTime.Now; this._model.TypeId = Convert.ToInt64(this.cboType.SelectedValue.ToString()); try { if (this._id == 0)//新增 { this._dalNote.Add(this._model); MessageBox.Show("添加成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } else { this._model.ModifyDate = DateTime.Now; this._dalNote.Update(this._model, " Id=" + this._id); MessageBox.Show("修改成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } btnReset_Click(null, null); return; } catch (Exception ex) { Log.SaveLog("NoteListModule btnOK_Click", ex.ToString()); MessageBox.Show("系统异常,操作失败!", "错误", MessageBoxButton.OK, MessageBoxImage.Error); } finally { Bind(); } }
//列表菜单 private void Item_Click(object sender, EventArgs e) { Button btn = (Button)sender; this._model = (Entity.Note)btn.DataContext; string btnContent = btn.Content.ToString().Replace(" ", ""); if (btnContent == "删除") { MessageBoxResult mbr = MessageBox.Show("确定删除?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (mbr == MessageBoxResult.Yes) { try { _dalNote.Delete(" Id=" + this._model.Id); } catch (Exception ex) { Log.SaveLog("MainWindow DropList 删除选中项", ex.ToString()); } Bind(); } } }
public int update(Entity.Note entity) { return(this.repository.update(entity)); }
public Entity.Note insert(Entity.Note entity) { return(this.repository.insert(entity)); }
/// <summary> /// 保存 /// </summary> /// <param name="Id"></param> private void Save(object param) { this._note = (Entity.Note)param; //_dalNote.Delete(" Id=" + id); }