Пример #1
0
 private void ClearMeanings()  // clear Meanings list
 {
     if (Meanings != null && Meanings.Count > 0)
     {
         Meanings.Clear();
     }
 }
Пример #2
0
        public MainWindowViewModel()
        {
            this.ClearSearchCommand          = new DelegateCommand(() => Keyword = string.Empty);
            this.LoadSettingCommand          = new DelegateCommand(() => LoadSetting());
            this.SaveSettingCommand          = new DelegateCommand(() => SaveSetting());
            this.TextBoxEnterKeyEventCommand = new DelegateCommand <string>(async(keyword) =>
                                                                            await Task.Run(async() =>
            {
                if (string.IsNullOrEmpty(keyword))
                {
                    return;
                }

                Result result = await GetResult(keyword);

                DispatchService.Invoke(() =>
                {
                    Meanings.Clear();

                    ScrollToTop?.Invoke();

                    if (result != null && result?.Meanings?.Count > 0)
                    {
                        Meanings.AddRange(result.Meanings);
                    }
                    else
                    {
                        meanings.Add(new Meaning {
                            Word = $"未找到 (´;ω;`)"
                        });
                    }
                });
            }));
        }
Пример #3
0
        public void SetValue()
        {
            if (mEntity == null)
            {
                mEntity = new List <Dictionary <string, object> >();
            }

            System.Windows.Forms.CheckedListBox.CheckedItemCollection checkedMeans = this.clbMeans.CheckedItems;
            foreach (var item in checkedMeans)
            {
                var meanViewModel = item as MeaningViewModel;
                if (meanViewModel != null)
                {
                    Dictionary <string, object> dic = new Dictionary <string, object>();
                    Meanings mean = allMeanings.Where(m => m.Id == meanViewModel.Id).First();
                    dic.Add("Mean", mean);
                    dic.Add("Remark", DateTime.Now.ToString());
                    if (mEntity.Contains(dic))
                    {
                        continue;
                    }
                    this.mEntity.Add(dic);
                }
            }
        }
Пример #4
0
 public void AddMean(Meanings mean)
 {
     if (mean != null)
     {
         var meaningViewModel = new MeaningViewModel(mean, this.Font, _supposedWidth);
         this.Items.Add(meaningViewModel);
         this.SetItemChecked(this.Items.Count - 1, true);
         this.SetSelected(this.Items.Count - 1, true);
     }
 }
Пример #5
0
 public Meaning(Meanings mean, IList <Meanings> allMeanings, IDictionary <string, IList <Meanings> > currentRelationOfUserAndMeaning)
 {
     InitializeComponent();
     this.InitEvent();
     this.SetVisible(false);
     if (mean != null)
     {
         this.MeaningObject = mean;
         this.tbMean.Text   = mean.Desc;
     }
     this.allMeanings = allMeanings;
     this.currentRelationOfUserAndMeaning = currentRelationOfUserAndMeaning;
 }
Пример #6
0
        public void UpdateStatusWhenAddNewMean()
        {
            Meanings meaning = new Meanings()
            {
                Id = meaningBLL.GetMeaningPKValue() + 1, Desc = this.Mean.TrimEnd(), Remark = DateTime.Now.ToString()
            };

            meaningBLL.InsertOrUpdateMeaning(meaning);
            this.allMeanings.Add(meaning);
            this.MeaningObject = meaning;
            this.tbMean.Text   = this.MeaningObject.Desc;
            //this.IsNewMeaning = false;
            //this.AddMeaningButton.Enabled = true;
            this.tbMean.Enabled  = false;
            this.CheckBoxVisible = true;
        }
Пример #7
0
 private void OK(object sender, EventArgs args)
 {
     if (processor == null)
     {
         processor = new DeviceProcessor();
     }
     if (this.tbMean.Text == string.Empty)
     {
         MessageBox.Show("Please input the meaning");
     }
     else
     {
         if (meaning == null)
         {
             Meanings mean = new Meanings();
             object   o    = processor.QueryScalar("SELECT MAX(ID) FROM Meanings", null);
             mean.Id     = o != null && o.ToString() != string.Empty ? Convert.ToInt32(o) + 1 : 1;
             mean.Desc   = this.tbMean.Text.TrimEnd();
             mean.Remark = DateTime.Now.ToString();
             if (processor.Insert <Meanings>(mean, null))
             {
                 form.DialogResult = DialogResult.OK;
             }
             else
             {
                 MessageBox.Show("Saved Failure");
                 form.DialogResult = DialogResult.No;
             }
         }
         else
         {
             Meanings mean = new Meanings();
             mean.Id     = meaning.First().Key;
             mean.Desc   = this.tbMean.Text.TrimEnd();
             mean.Remark = DateTime.Now.ToString();
             if (processor.Update <Meanings>(mean, null))
             {
                 form.DialogResult = MessageBox.Show("Saved Successfully");
             }
             else
             {
                 MessageBox.Show("Saved Failure");
                 form.DialogResult = DialogResult.No;
             }
         }
     }
 }
Пример #8
0
        private void GetMeaning()
        {
            string username = tbAccount.Text.Trim().ToLower();
            List <UserMeanRelation> list    = _relation.GetMeaningByUser(username);
            List <Meanings>         allmean = _relation.GetAllMeans() as List <Meanings>;

            if (list != null && list.Count > 0)
            {
                var v = from p in list
                        join o in allmean on p.MeaningId equals o.Id
                        select new
                {
                    p.Username,
                    o.Id,
                    o.Desc
                };
                var dataSource = new List <MeaningViewModel>();
                foreach (var item in v)
                {
                    Meanings meaning = new Meanings()
                    {
                        Id = item.Id, Desc = item.Desc
                    };
                    dataSource.Add(new MeaningViewModel(meaning, clbMeanings.Font, clbMeanings.ClientSize.Width - 10));
                }

                if (v != null && v.Count() > 0)
                {
                    clbMeanings.DataSource    = dataSource;
                    clbMeanings.DisplayMember = "DisplayDesc";
                    clbMeanings.ValueMember   = "Id";
                }
                else
                {
                    Utils.ShowMessageBox(Messages.AssignMeaningFirst, Messages.TitleWarning);
                }
            }
            else
            {
                Utils.ShowMessageBox(Messages.AssignMeaningFirst, Messages.TitleWarning);
            }
        }
Пример #9
0
 public MeaningViewModel(Meanings mean, Font font, int displayWidth)
 {
     _mean         = mean;
     _font         = font;
     _displayWidth = displayWidth;
 }
Пример #10
0
 public Meaning(Meanings mn, UserMeanRelation ur) : this()
 {
     this._meanging = mn;
     this.relation  = ur;
 }
Пример #11
0
        public void InitEvents()
        {
            this.btnAddMean.Click += new EventHandler((a, b) =>
            {
                InputBoxDialog newMeanDialog = new InputBoxDialog(InputBoxTitle.AddMeaning, InputBoxTipMessage.AddMeaning, false);
                if (newMeanDialog.ShowDialog(this) == DialogResult.OK)
                {
                    Meanings meaning = new Meanings()
                    {
                        Id = this._meanBll.GetMeaningPKValue() + 1, Desc = newMeanDialog.InputBoxText.TrimEnd(), Remark = DateTime.Now.ToString()
                    };
                    this._meanBll.InsertOrUpdateMeaning(meaning);
                    this.allMeanings.Add(meaning);
                    if (this.clbMeans != null)
                    {
                        this.clbMeans.AddMean(meaning);
                    }
                }
            });

            this.btnEditMean.Click += new EventHandler((send, args) =>
            {
                InputBoxDialog updateMeanDialog = new InputBoxDialog(InputBoxTitle.EditMeaning, InputBoxTipMessage.EditMeaning, false);
                int selectedMeanId    = this.clbMeans.GetCurrentSelectedMean();
                Meanings selectedMean = null;
                if (allMeanings != null)
                {
                    selectedMean = allMeanings.Where <Meanings>(m => m.Id == selectedMeanId).FirstOrDefault();
                }
                if (selectedMean != null)
                {
                    updateMeanDialog.InputBoxText = selectedMean.Desc;
                    if (updateMeanDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        if (!updateMeanDialog.InputBoxText.TrimEnd().Equals(selectedMean.Desc, StringComparison.Ordinal))
                        {
                            selectedMean.Desc   = updateMeanDialog.InputBoxText.TrimEnd();
                            selectedMean.Remark = DateTime.Now.ToString();
                            this._meanBll.InsertOrUpdateMeaning(selectedMean);
                            this.clbMeans.Refresh();
                        }
                    }
                }
            });

            this.btnDeleteMean.Click += new EventHandler((send, args) =>
            {
                if (DialogResult.Yes == Utils.ShowMessageBox(Messages.DeleteMeaning, Messages.TitleWarning, MessageBoxButtons.YesNo))
                {
                    int selectedMeanId    = this.clbMeans.GetCurrentSelectedMean();
                    Meanings selectedMean = null;
                    if (allMeanings != null)
                    {
                        selectedMean = allMeanings.Where <Meanings>(m => m.Id == selectedMeanId).FirstOrDefault();
                    }
                    if (selectedMean != null)
                    {
                        this._meanBll.DeleteMeaningAndRelation(selectedMean);
                        allMeanings.Remove(selectedMean);
                        this.clbMeans.Items.Remove(selectedMean);
                        foreach (var item in this.newUserRelation.Values)
                        {
                            item.Remove(selectedMeanId);
                        }
                        this.clbMeans.Refresh();
                    }
                }
            });
        }