1
yhj
2024-07-24 5e5d945e91568b973faa27d8ab0bcef99fc4a6c5
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#region
 
using System;
using System.Data;
using CSFrameworkV5.Business;
using CSFrameworkV5.Business.BLL_Permission;
using CSFrameworkV5.CodeGeneratorCore;
using CSFrameworkV5.Core;
using CSFrameworkV5.Library.CommonClass;
using CSFrameworkV5.Library.UIForm;
using CSFrameworkV5.Models;
 
#endregion
 
namespace CSFrameworkV5.Library.PermissionForms
{
    public partial class frmGroupOrganization_Editor : frmBaseUI
    {
        private bllGroup _BLL = new bllGroup();
        private DataTable _DataSource;
        private string _RowID = ""; //主键值,当前组织架构的主键值。若是新增记录,返回新的GUID值。
 
        private bool _SaveOK; //是否保存成功
 
        //私有构造器
        private frmGroupOrganization_Editor()
        {
            InitializeComponent();
        }
 
        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }
 
        private void btnSave_Click(object sender, EventArgs e)
        {
            //重要! 必须结束当前记录的编辑状态
            _DataSource.Rows[0].EndEdit();
 
            var dtTmp = _DataSource.GetChanges();
            dtTmp.Rows[0][tb_MyGroup.LastUpdateDate] = DateTime.Now;
            dtTmp.Rows[0][tb_MyGroup.LastUpdatedBy] =
                Loginer.CurrentUser.Account;
            //dtTmp.Rows[0][tb_MyGroup.ParentGroupCode] = txtParentGroupCode.EditValue;
 
            _SaveOK = _BLL.Update(dtTmp);
 
            if (_SaveOK)
            {
                _RowID = dtTmp.Rows[0][tb_MyGroup.RowID].ToStringEx();
 
                MsgEx.ShowInformation("保存成功!");
                Close();
            }
        }
 
        /// <summary>
        ///     打开编辑窗体
        /// </summary>
        /// <param name="rowID">当前组织架构的主键值。若是新增记录,返回新的GUID值</param>
        /// <returns>是否保存成功</returns>
        public static bool Execute(ref string rowID)
        {
            var form = new frmGroupOrganization_Editor();
            form.InitEditor(rowID);
            form.ShowDialog();
            rowID = form._RowID;
            return form._SaveOK;
        }
 
        private void frmGroupOrganization_Editor_Load(object sender,
            EventArgs e)
        {
        }
 
        private void InitEditor(string rowID)
        {
            //记录主键为空,新增组织架构
            if (string.IsNullOrEmpty(rowID))
            {
                //获取空数据源
                _DataSource = _BLL.GetDataByKey("-");
 
                //添加一条记录,并设置主键值RowID
                _DataSource.Rows.Add(_DataSource.NewRow());
                _DataSource.Rows[0][tb_MyGroup.RowID] =
                    Guid.NewGuid().ToStringEx().Replace("-", "");
                _DataSource.Rows[0][tb_MyGroup.DataSetID] =
                    Loginer.CurrentUser.DBID;
            }
            else //编辑组织架构
            {
                //绑定数据源
                _DataSource = _BLL.GetDataByKey(rowID);
 
                txtGroupCode.Enabled = false;
                txtParentGroupCode.Enabled = false;
            }
 
            var attrs = DataDictCache.Cache.CustomerAttributes;
            txtAttributeCodes.BindingDataSource(attrs, "AttributeCode",
                "NativeName");
 
            DataBinderTools.BoundUser(txtOwner1);
            DataBinderTools.BoundUser(txtOwner2);
            DataBinderTools.BoundUser(txtLastUpdatedBy);
            DataBinderTools.BoundOrganization(txtParentGroupCode, imageList1);
            DataBinderTools.BoundCheckEdit(txtIsVisible);
 
            //绑定输入框数据源
            CommonTools.DoBindingEditorPanel(pcEditor, _DataSource);
 
            //在此可绑定其它自定义的输入框,参考frmCustomer的DoBindingSummaryEditor方法
            DataBinder.BindingControl(txtAttributeCodes, _DataSource,
                tb_MyGroup.AttributeCodes, "EditValue");
            DataBinder.BindingControl(txtParentGroupCode, _DataSource,
                tb_MyGroup.ParentGroupCode, "EditValue");
            DataBinder.BindingCheckEdit(txtIsVisible, _DataSource,
                tb_MyGroup.IsVisible);
 
            //CommonTools.SetEditorBindingValue(txtParentGroupCode, _DataSource.Rows[0][tb_MyGroup.ParentGroupCode], true);
 
            btnClose.Focus();
        }
 
        //检查主表数据完整性
        protected bool ValidatingData()
        {
            if (ConvertEx.ToString(txtGroupCode.EditValue).Trim() ==
                string.Empty)
            {
                MsgEx.ShowWaring("组织编号不能为空!");
                txtGroupCode.Focus();
                return false;
            }
 
            if (ConvertEx.ToString(txtGroupName.EditValue).Trim() ==
                string.Empty)
            {
                MsgEx.ShowWaring("组织名称不能为空!");
                txtGroupName.Focus();
                return false;
            }
 
            if (ConvertEx.ToString(txtAttributeCodes.EditValue).Trim() ==
                string.Empty)
            {
                MsgEx.ShowWaring("类别不能为空!");
                txtAttributeCodes.Focus();
                return false;
            }
 
            if (ConvertEx.ToString(txtOwner1.EditValue).Trim() == string.Empty)
            {
                MsgEx.ShowWaring("主管不能为空!");
                txtOwner1.Focus();
                return false;
            }
 
            return true;
        }
    }
}