ch
2022-05-30 f9ef44a67fbf73f073efe65600bc25e204fde04f
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace BLL
{
    public partial class Xt_UserGroup : Form
    {
        public Xt_UserGroup()
        {
            InitializeComponent();
        }
 
 
        public Pub_Class.ClsPub.Enum_InputMode InputMode;  //¼Èë״̬±êÖ¾(0-·Ç¼Èë״̬ 1-Ôö¼Ó 2-ÐÞ¸Ä)
        public long HGroupID; 
        //´°Ìå¼ÓÔØ
        private void Xt_UserGroup_Load(object sender, EventArgs e)
        {
            lblError.Text = "";
            LbYes.Items.Clear();
            LbNo.Items.Clear();
            Init();
            Display();
        }
        //²éÕÒÊý¾Ý----Óû§
        private void Display()
        {
            if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNew)
            {
                try
                {
                    SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                    DataSet oDs = new DataSet();
                    oDs = oCn.RunProcReturn("select Czybm,Czymc from  Gy_Czygl order by Czymc", "Gy_Czygl", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (oDs == null)
                    {
                        MessageBox.Show("ÏÔʾʧ°Ü£¡Ô­Òò£º" + DBUtility.ClsPub.sExeReturnInfo);
                        return;
                    }
                    //
                    for (int i = 0; i <= oDs.Tables[0].Rows.Count - 1; i++)
                    {
                        LbNo.Items.Add(oDs.Tables[0].Rows[i][0].ToString().Trim() + "-" + oDs.Tables[0].Rows[i][1].ToString().Trim());
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Ìáʾ");
                    return;
                }
            }
            else
            {
                try
                {
                    SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                    DataSet oDs = new DataSet();
                    DataSet oDS = new DataSet();
                    //¼ÓÔØ²»Êô×é
                    oDs = oCn.RunProcReturn("select Czybm,Czymc from  Gy_Czygl"
                    + " where Czybm not IN (select userid  from  system_UserGroupInfo where Groupid=" + HGroupID.ToString() + ")", "Gy_Czygl", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (oDs == null)
                    {
                        MessageBox.Show("ÏÔʾʧ°Ü£¡Ô­Òò£º" + DBUtility.ClsPub.sExeReturnInfo);
                        return;
                    }
                    //
                    if (oDs.Tables[0].Rows.Count != 0)
                    {
                        for (int i = 0; i <= oDs.Tables[0].Rows.Count - 1; i++)
                        {
 
                            LbNo.Items.Add(oDs.Tables[0].Rows[i][0].ToString().Trim() + "-" + oDs.Tables[0].Rows[i][1].ToString().Trim());
                        }
                    }
                    //¼ÓÔØÊôÓÚ×é
                    oDS = oCn.RunProcReturn("select Czybm,Czymc from  Gy_Czygl"
                    + " where Czybm IN (select userid  from  system_UserGroupInfo where Groupid='" + HGroupID.ToString() + "')", "Gy_Czygl", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (oDS == null)
                    {
                        MessageBox.Show("ÏÔʾʧ°Ü£¡Ô­Òò£º" + DBUtility.ClsPub.sExeReturnInfo);
                        return;
                    }
                    //
                    if (oDS.Tables[0].Rows.Count != 0)
                    {
                        for (int i = 0; i <= oDS.Tables[0].Rows.Count - 1; i++)
                        {
 
                            LbYes.Items.Add(oDS.Tables[0].Rows[i][0].ToString().Trim() + "-" + oDS.Tables[0].Rows[i][1].ToString().Trim());
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Ìáʾ");
                    return;
                }
            }
        }
        //³õʼ»¯½çÃæ
        private void Init()
        {
            if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNew)
            {
            }
            else
            {
                ShowData(HGroupID);
            }
        }
        //¼ÓÔØ±íÍ·
        private void ShowData(long HGroupID)
        {
            DataSet oDs = new DataSet();
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            try
            {
                oDs = oCn.RunProcReturn("select * from  System_UserGroup where GroupID=" + HGroupID.ToString(), "System_UserGroup", ref DBUtility.ClsPub.sExeReturnInfo);
                if (oDs == null)
                {
                    MessageBox.Show("ÏÔʾʧ°Ü£¡Ô­Òò£º" + DBUtility.ClsPub.sExeReturnInfo);
                    return;
                }
                else if (oDs.Tables[0].Rows.Count != 0)
                {
                    txtGroup.Text = oDs.Tables[0].Rows[0]["GroupName"].ToString().Trim();
                    txtExplain.Text = oDs.Tables[0].Rows[0]["Explain"].ToString().Trim();
                    cmbHLev.Text = oDs.Tables[0].Rows[0]["HLev"].ToString().Trim();
                    //txtHCheckMoney.Text = oDs.Tables[0].Rows[0]["HCheckMoney"].ToString().Trim();
                    //txtHCheckPrice.Text = oDs.Tables[0].Rows[0]["HCheckPrice"].ToString().Trim();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Ìáʾ");
                return;
            }
        }
        //×óÒÆ
        private void cmdLeft_Click(object sender, EventArgs e)
        {
            if (this.LbNo.SelectedItems.Count > 0)
            {
                int i = this.LbNo.SelectedIndex;
                this.LbYes.Items.Add(this.LbNo.SelectedItem.ToString());
                this.LbNo.Items.RemoveAt(i);
            }
        }
        //È«²¿×óÒÆ
        private void cmdAllLeft_Click(object sender, EventArgs e)
        {
            if (this.LbNo.Items.Count > 0)
            {
                for (int i = 0; i <= this.LbNo.Items.Count - 1; i++)
                {
                    this.LbYes.Items.Add(this.LbNo.Items[i].ToString());
                    this.LbNo.Items.RemoveAt(i);
                    i--;
                }
            }
        }
        //ÓÒÒÆ
        private void cmdRight_Click(object sender, EventArgs e)
        {
            if (this.LbYes.SelectedItems.Count > 0)
            {
                int i = this.LbYes.SelectedIndex;
                this.LbNo.Items.Add(this.LbYes.SelectedItem.ToString());
                this.LbYes.Items.RemoveAt(i);
            }
        }
        //È«²¿ÓÒÒÆ
        private void cmdAllRight_Click(object sender, EventArgs e)
        {
            if (this.LbYes.Items.Count > 0)
            {
                for (int i = 0; i <= this.LbYes.Items.Count - 1; i++)
                {
                    this.LbNo.Items.Add(this.LbYes.Items[i].ToString());
                    this.LbYes.Items.RemoveAt(i);
                    i--;
                }
            }
        }
        //È¡Ïû
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //È·¶¨
        private void cmdOK_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            DataSet oDs = new DataSet();
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            if (!Sub_AllowSave())   //µ¥¾ÝÍêÕûÐÔÅжÏ
                return;
            if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNew)
            {
                oCn.RunProc("insert into  System_UserGroup (GroupName,HLev,Explain) "+
                "values ('" + txtGroup.Text.ToString() + "','" + cmbHLev.Text.ToString() + "','" + txtExplain.Text.ToString() + "')");
                oDs = oCn.RunProcReturn("Select * from  System_UserGroup where GroupName='" + txtGroup.Text.ToString()+"'","System_UserGroup");
                if (oDs == null || oDs.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("ÐÂÔöʧ°Ü£¡", "Ìáʾ");
                }
                this.HGroupID = DBUtility.ClsPub.isLong(oDs.Tables[0].Rows[0]["GroupID"]);
                oCn.RunProc("delete from  System_UserGroupInfo where GroupId=" + HGroupID.ToString());
                for (int i = 0; i <= LbYes.Items.Count - 1; i++)
                {
                    oCn.RunProc("insert into  System_UserGroupInfo (GroupId,UserId) values (" + HGroupID.ToString() + ",'" + Get_Code(this.LbYes.Items[i].ToString())+"')");
                }
                lblError.Text = "* ÐÂÔö³É¹¦£¡";
 
            }
            else
            {
                oCn.RunProc("update  System_UserGroup set GroupName='" + txtGroup.Text.ToString() + "',HLev='" + cmbHLev.Text.ToString() + "',Explain='" + txtExplain.Text.ToString() + "'"
                    + " where GroupId="+ HGroupID.ToString());
                //
                oCn.RunProc("delete from  System_UserGroupInfo where GroupId=" + HGroupID.ToString());
                for (int i = 0; i <= LbYes.Items.Count - 1; i++)
                {
                    oCn.RunProc("insert into  System_UserGroupInfo (GroupId,UserId) values (" + HGroupID.ToString() + ",'" + Get_Code(this.LbYes.Items[i].ToString()) + "')");
                }
                lblError.Text = "* Ð޸ijɹ¦£¡";
            }
        }
        //µ¥¾ÝÍêÕûÐÔÅжÏ
        private bool Sub_AllowSave()
        {
            if (txtGroup.Text.Trim() == "")
            {
                lblError.Text = "* ×éÃû²»ÄÜΪ¿Õ£¡";
                return false;
            }
            //if (cmbHLev.Text.Trim() == "")
            //{
            //    lblError.Text = "* ¸Úλ¼¶±ð²»ÄÜΪ¿Õ£¡";
            //    return false;
            //}
            //if (txtHCheckMoney.Text.Trim() == "")
            //{
            //    lblError.Text = "* ½ð¶î¿ØÖƲ»ÄÜΪ¿Õ£¡";
            //    return false;
            //}
            //if (txtHCheckPrice.Text.Trim() == "")
            //{
            //    lblError.Text = "* µ¥¼Û¿ØÖƲ»ÄÜΪ¿Õ£¡";
            //    return false;
            //}
            //×éÃû ÊÇ·ñÖØ¸´
            if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNew)
            {
                DataSet oDs = new DataSet();
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                oDs = oCn.RunProcReturn("select * from  System_UserGroup where GroupName='" + txtGroup.Text.ToString() + "'", "System_UserGroup");
                if (oDs.Tables[0].Rows.Count != 0)
                {
                    lblError.Text = "* ×éÃûÖØ¸´£¡";
                    return false;
                }
            }
            return true;
        }
        //²ð·Ö
        private string Get_Code(string sCode)
        {
            sCode = sCode.Trim();
            char c = Convert.ToChar("-");
            string[] s = sCode.Split(c);
            if (s.Length > 1)
            {
                return s[0].Trim();
            }
            else
            {
                return "0";
            }
        }
    }
}