ningshuxia
2023-02-24 1e4b358de58e36bfbf692ab2538ff9e7d60fd025
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;
 
namespace IStation.WinFormUI.Project
{
    /// <summary>
    /// 编辑项目窗体
    /// </summary>
    public partial class EditProjectDlg : DevExpress.XtraEditors.XtraForm
    {
        public EditProjectDlg() 
        {
            InitializeComponent();
            this.IconOptions.Icon = Properties.Resource.app;
            this.dataLayoutControl1.SetupLayoutControl();
        }
 
        /// <summary>
        /// 回调事件
        /// </summary>
        public event Action<Model.Project> ReloadDataEvent;
        private Model.Project _model = null;
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(long projectId)
        {
            var rhs = new BLL.Project().GetById(projectId);
            _model = new Model.Project(rhs);
            this.NameTextEdit.EditValue = _model.Name;
            this.TagNameTextEdit.EditValue = _model.TagName;
            this.DescriptionMemoEdit.EditValue = _model.Description;
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(Model.Project rhs)
        {
            _model = new Model.Project(rhs);
            this.NameTextEdit.EditValue = _model.Name;
            this.TagNameTextEdit.EditValue = _model.TagName;
            this.DescriptionMemoEdit.EditValue = _model.Description;
        }
 
        //验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.NameTextEdit.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.NameTextEdit,"必填项");
                return false;
            }
            return true;
        }
 
        //确定
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!Valid())
                return;
            _model.Name = this.NameTextEdit.Text.Trim();
            _model.TagName = this.TagNameTextEdit.Text.Trim();
            _model.Description = this.DescriptionMemoEdit.Text.Trim(); 
            var bll = new BLL.Project();
            var bol = bll.Update(_model);
            if (!bol)
            {
                XtraMessageBox.Show("更新失败!");
                return;
            }
 
            if (this.ReloadDataEvent != null)
            {
                var model = bll.GetById(_model.Id);
                this.ReloadDataEvent.Invoke(model);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
 
    }
}