Example #1
0
        /// <summary>
        /// 减字列表选择条目变化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstChar_SelectedIndexChanged(object sender, EventArgs e)
        {
            //避免未保存的数据丢失,设置提醒
            if (charEditor.IsModified)
            {
                if (currentListIndex != lstChar.SelectedIndex)
                {
                    DialogResult result = MessageBox.Show("减字尚未保存,是否离开?", "警告",
                                                          System.Windows.Forms.MessageBoxButtons.YesNo);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        lstChar.SelectedIndex = currentListIndex;
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            currentListIndex = lstChar.SelectedIndex;
            CharNotationDataSet.CharRow currentRow = null;
            if (lstChar.SelectedItem != null)
            {
                currentRow = (CharNotationDataSet.CharRow)(lstChar.SelectedItem as DataRowView).Row;
            }
            //Char charCurrent = lstChar.SelectedItem as Char;
            Char charCurrent = null;

            if (currentRow != null)
            {
                charCurrent = dataTranslator.GetChar(currentRow);
            }
            //列表非空时必然会选择其中一项;但要避免出现空列表的情况
            if (charCurrent != null)
            {
                charEditor = new CharEditor(charCurrent.Clone() as Char);

                charEditor.ResetModifyStatus();

                txtName.Text              = charEditor.Name;
                txtCharName.Text          = charEditor.CharName;
                numUDSegment.Value        = (Decimal)charEditor.Segment;
                chkMain.Checked           = charEditor.IsMain;
                chkComplex.Checked        = charEditor.IsComplex;
                chkRestrictTop.Checked    = charEditor.RestrictTop;
                chkRestrictBottom.Checked = charEditor.RestrictBottom;
                chkRectTop.Checked        = charEditor.RestrictTopRect;
                chkRectBottom.Checked     = charEditor.RestrictBottomRect;

                picBoxEditor.Invalidate();  //重绘picbox
            }
        }
Example #2
0
        /// <summary>
        /// 点击“添加减字”按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddChar_Click(object sender, EventArgs e)
        {
            //未指定减字名称
            if (txtName.Text == "")
            {
                toolTipWarning.Show("名称还没起呢", txtName, 1000);
                return;
            }
            else if (txtCharName.Text == "")
            {
                toolTipWarning.Show("名称还没起呢", txtCharName, 1000);
                return;
            }
            //检查列表是否重复
            foreach (var item in lstChar.Items)
            {
                CharNotationDataSet.CharRow currentRow = (CharNotationDataSet.CharRow)(item as DataRowView).Row;
                if (currentRow.name.Trim() == txtName.Text)
                {
                    toolTipWarning.Show("名称已存在", txtName, 1000);
                    return;
                }
                else if (currentRow.char_name.Trim() == txtCharName.Text)
                {
                    toolTipWarning.Show("名称已存在", txtCharName, 1000);
                    return;
                }
            }
            //新建减字,必须使用深复制
            charEditor.CharName = txtCharName.Text;
            charEditor.Name     = txtName.Text;
            charEditor.Segment  = (int)numUDSegment.Value;
            charEditor.ResetModifyStatus();
            Char charTemp = charEditor.Clone() as Char;

            dataTranslator.AddChar(charTemp);
            lstChar.SelectedIndex = lstChar.FindStringExact(charEditor.CharName);
        }