private void btnSave_Click(object sender, EventArgs e) { if (txtTitle.Text.Trim().Length < 2) { MessageBox.Show("标题长度不能小于2"); return; } if (txtContent.Text.Trim().Length < 6) { MessageBox.Show("内容不能为空"); return; } DInfo info = new DInfo(); if (info.IsExistName(txtTitle.Text.Trim()) && model.Id < 1) { MessageBox.Show("名称已经存在"); return; } model.IsAlt = true; model.IsCtrl = true; model.IsShift = false; model.Key = "I"; model.Title = txtTitle.Text.Trim(); model.Content = txtContent.Text.Trim(); model.UserId = SystemInfo.userId; if (cbxType.SelectedValue != null) { model.TypeId = (int)cbxType.SelectedValue; } else { MType mType = new MType(); mType.Name = cbxType.Text.ToString(); DType dType = new DType(); int id = dType.Add(mType); if (id > 0) { model.TypeId = id; } else { model.TypeId = 9; } } if (model.Id < 1) { if (info.Add(model)) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); } } else { if (info.Update(model)) { MessageBox.Show("更新成功"); } else { MessageBox.Show("更新失败"); } } if (fMain != null) { fMain.LoadData("", 1); } else { this.Close(); } }