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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using GSBase.BaseFrom;
 
namespace GSBase.Control
{/// <summary>
 /// 高级按钮文本框
 /// </summary>
    public partial class AdvButtonText : UserControl
    {
        //public bool ChangeTextLeft
        /// <summary>
        ///标签标题;
        /// </summary> 
        public SelectQueryDlg SelectItemDlg;
        [Category("扩展功能"), Description("标题内容"), DefaultValue("Caption")]
        public string Caption
        {
            get { return lbCaption.Text; }
            set
            {
                if (lbCaption.Text != value)
                {
                    //int oldwith = lbCaption.Size.Width;
                    lbCaption.Text = value;
                    //int newwith = lbCaption.Size.Width;
 
                    //textEdit.Location = new Point(textEdit.Location.X + (newwith - oldwith), textEdit.Location.Y);
                    //btnButton.Location = new Point(btnButton.Location.X + (newwith - oldwith), btnButton.Location.Y);
                    //lbRemark.Location = new Point(lbRemark.Location.X + (newwith - oldwith), lbRemark.Location.Y);
                }
               // this.Refresh();
            }
        }
        private string captionT;
        public string CaptionT
        {
            get { return captionT; }
            set { captionT = value; }
        }
 
        /// <summary>
        /// 标题
        /// </summary>
        [Category("扩展功能"), Description("文本底色")]
        public Color TextBackColor
        {
            get { return textEdit.BackColor; }
            set
            {
                textEdit.BackColor = value;
            }
 
        }
 
        /// <summary>
        /// 数据值
        /// </summary>  
        [Category("扩展功能"), Description("只读模式")]
        public bool ReadOnly
        {
            get { return !btnButton.Enabled; }
            set
            {
                string s = this.Name;
                btnButton.Enabled = !value;
                textEdit.Properties.ReadOnly = value;
                if (value && textEdit.BackColor == Color.White)
                {
                    textEdit.Properties.AppearanceReadOnly.BackColor = Color.FromArgb(255, 247, 245, 241); //Color.WhiteSmoke;//
                    textEdit.Properties.AppearanceReadOnly.Options.UseBackColor = true;
                }
            }
        }
        /// <summary>
        /// 数据值
        /// </summary>  
        [Category("扩展功能"), Description("文本框内容")]
        public string EditValue
        {
            get { return textEdit.Text; }
            set
            {
                //这个如果不设置会引起列变化事件。
                if (textEdit.Text == value)
                    return;
                textEdit.Text = value;
            }
        }
 
        /// <summary>
        /// 备注字段
        /// </summary>
        [Category("扩展功能"), Description("备注内容")]
        public string Remark
        {
            get { return lbRemark.Text; }
            set
            {
                //这个如果不设置会引起列变化事件。
                if (lbRemark.Text == value)
                    return;
 
                lbRemark.Text = value;
            }
        }
        /// <summary>
        /// 是否验证
        /// </summary>
        private Boolean isValidated = true;
 
        /// <summary>
        /// 是否验证
        /// </summary>
        [Category("扩展功能"), Description("是否验证")]
        public Boolean IsValidated
        {
            get { return isValidated; }
            set { isValidated = value; }
        }
 
        /// <summary>
        /// 显示类型
        /// </summary>
        private ShowStyle textType = ShowStyle.BeRemark;
 
        /// <summary>
        /// 控件类型,分别:非备注模式,备注模式,文本框模式
        /// </summary>
        /// <value>The type of the text.</value>
        [Category("扩展功能"), Description("控件类型,分别:非备注模式,备注模式,文本框模式")]
        public ShowStyle TextType
        {
            get { return textType; }
            set
            {
                if (textType != value)
                {
                    switch (value)
                    {
                        case ShowStyle.BeRemark:
                            lbRemark.Visible = true;
                            lbRemark.Text = "Remark";
                            btnButton.Visible = true;
                            break;
                        case ShowStyle.NoRemark:
                            lbRemark.Visible = false;
                            lbRemark.Text = "";
                            btnButton.Visible = true;
                            break;
                        case ShowStyle.BeText:
                            lbRemark.Visible = false;
                            lbRemark.Text = "";
                            btnButton.Visible = false;
                            break;
                        default:
                            MessageBox.Show("输入无效的值");
                            break;
                    }
                }
                textType = value;
            }
        }
 
        /// <summary>
        /// 风格
        /// </summary>
        [Category("扩展功能"), Description("风格")]
        public IStyleController StyleController
        {
            get { return textEdit.StyleController; }
            set { textEdit.StyleController = value; }
        }
 
        /// <summary>
        /// 获取或设置一个值,该值指示控件是否可以对用户交互作出响应。
        /// </summary>
        /// <value></value>
        /// <returns>
        /// 如果控件可以对用户交互作出响应,则为 true;否则为 false。默认为 true。</returns>
        /// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
        public new bool Enabled
        {
            get { return textEdit.Enabled; }
            set
            {
                textEdit.Enabled = value;
                btnButton.Enabled = value;
                lbRemark.Enabled = value;
            }
        }
 
        /// <summary>
        /// DC编号
        /// </summary>
        private string datacatalogID;
 
        /// <summary>
        /// 数据目录编号DC
        /// </summary>
        /// <value>The datacatalog ID.</value>
        [Category("扩展功能"), Description("数据目录编号,如ADMDAA-01")]
        public string DatacatalogID
        {
            get { return datacatalogID; }
            set { datacatalogID = value; }
        }
 
        private string textField = string.Empty;
 
        /// <summary>
        /// 文本字段
        /// </summary>
        [Category("扩展功能"), Description("控件文本框对应的DC中字段,如DAA002")]
        public string TextField
        {
            get
            {
 
                if (textField == null)
                    return string.Empty;
                else
                    return textField.Trim();
            }
            set { textField = value; }
        }
 
        private string remarkField = string.Empty;
 
        /// <summary>
        /// 备注字段名
        /// </summary>
        [Category("扩展功能"), Description("对应DC中的字段,例如选择单别时会带出单据简称。如DAA002")]
        public string RemarkField
        {
            get
            {
                if (remarkField == null)
                    return string.Empty;
                else
                    return remarkField.Trim();
            }
            set { remarkField = value; }
        }
 
        private string _RemarkBindField = string.Empty;
        /// <summary>
        /// 备注绑定字段
        /// </summary>
        [Category("扩展功能"), Description("对应当前数据表中的字段。")]
        public string RemarkBindField
        {
            get
            {
                if (_RemarkBindField == null)
                    return string.Empty;
                else
                    return _RemarkBindField.Trim();
            }
            set { _RemarkBindField = value; }
        }
 
        /// <summary>
        /// 映射关系
        /// </summary>
        private string otherMapping;
 
        /// <summary>
        /// 设置或获取其他映射关系
        /// </summary>
        /// <value>The mapping.</value>
        [Category("扩展功能"), Description("其他关系字段映射关系统(用分号隔开):[控件.Text]=DAA001;[控件.Text]=DAA002")]
        public string OtherMapping
        {
            get
            {
                if (otherMapping == null)
                    return string.Empty;
                else
                    return otherMapping.Trim();
            }
            set { otherMapping = value; }
        }
 
        /// <summary>
        /// 条件筛选
        /// </summary>
        private string filter;
 
        /// <summary>
        /// 获取或设置筛选条件
        /// </summary>
        /// <value>The filter.</value>
        [Category("扩展功能"), Description("筛选条件(也可写固定条件).字段编号=[控件.属性] 如:DAA004='8032'AND DAA005=[控件2.Text]")]
        public string Filter
        {
            get { return filter; }
            set { filter = value; }
        }
 
        /// <summary>
        /// 文体大小
        /// </summary> 
        [Category("扩展功能"), Description("文本框大小")]
        public Size TextSize
        {
            get { return textEdit.Size; }
            set
            {
                if (textEdit.Size != value)
                {
                    int oldwith = textEdit.Size.Width;
                    textEdit.Size = value;
                    int newwith = textEdit.Size.Width;
 
                    btnButton.Location = new Point(btnButton.Location.X + (newwith - oldwith), btnButton.Location.Y);
                    lbRemark.Location = new Point(lbRemark.Location.X + (newwith - oldwith), lbRemark.Location.Y);
                }
                this.Refresh();
            }
        }
 
        /// <summary>
        /// 字体大小,此属性不要使用了,请使用Font。
        /// </summary> 
        [Category("扩展功能"), Description("字体")]
        public Font TextFont
        {
            get { return textEdit.Font; }
            set
            {
                if (textEdit.Font != value)
                {
                    textEdit.Font = value;
                    lbRemark.Font = value;
                    lbCaption.Font = value;
                }
                this.Refresh();
            }
        }
 
        /// <summary>
        /// 字体大小
        /// </summary> 
        [Category("扩展功能"), Description("字体")]
        public override Font Font
        {
            get { return textEdit.Font; }
            set
            {
                if (textEdit.Font != value)
                {
                    textEdit.Font = value;
                    lbRemark.Font = value;
                    lbCaption.Font = value;
                }
                this.Refresh();
            }
        }
 
 
        /// <summary>
        /// 字体大小
        /// </summary> 
        [Category("扩展功能"), Description("前景颜色")]
        public override Color ForeColor
        {
            get { return textEdit.ForeColor; }
            set
            {
                if (textEdit.ForeColor != value)
                {
                    textEdit.ForeColor = value;
                    lbRemark.ForeColor = value;
                    lbCaption.ForeColor = value;
                }
                this.Refresh();
            }
        }
 
        /// <summary>
        /// 背景颜色
        /// </summary> 
        //[Category("扩展功能"), Description("背景颜色")]
        //public override Color BackColor
        //{
        //    get { return this.BackColor; }
        //    set
        //    {
        //        if (textEdit.BackColor != value)
        //        {
        //            this.BackColor = value;
        //            //textEdit.BackColor = value; 
        //            //lbRemark.BackColor = value;
        //            //lbCaption.BackColor = value;
        //        }
        //        this.Refresh();
        //    }
        //}
 
 
        ///// <summary>
        ///// 文本框宽度
        ///// </summary> 
        //[Category("扩展功能"), Description("前景颜色")]
        //public new  int Width
        //{
        //    get { return textEdit.Width; }
        //    set
        //    {
        //        if (textEdit.Width != value)
        //        {
        //            textEdit.Width = value;
        //        }
        //        this.Refresh();
        //    }
        //}
 
 
        /// <summary>
        /// 实体类
        /// </summary>
        private object _SearchEntity;
 
        /// <summary>
        /// 数据实体类
        /// </summary>
        [Category("扩展功能"), Description("数据实体类")]
        public object SearchEntity
        {
            get { return _SearchEntity; }
            set { _SearchEntity = value; }
        }
 
        /// <summary>
        /// 引发 <see cref="E:System.Windows.Forms.Control.Paint"></see> 事件。
        /// </summary>
        /// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs"></see>。</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            //标题的列宽
            int with = lbCaption.Size.Width + 3;
            textEdit.Location = new Point(with, textEdit.Location.Y);
            //文本列宽+标题的列宽
            with = textEdit.Size.Width + with + 1;
            btnButton.Location = new Point(with, btnButton.Location.Y);
            //文本列宽+标题的列宽+按钮列宽
            with = btnButton.Size.Width + with + 1;
            lbRemark.Location = new Point(with, lbRemark.Location.Y);
            base.OnPaint(e);
        }
 
        /// <summary>
        /// 按钮点击事件
        /// </summary>
        [Category("扩展功能"), Description("按钮点选事件")]
        public event EventHandler ButtonClick;
 
        /// <summary>
        /// 验证文本事件
        /// </summary>
        [Category("扩展功能"), Description("文本框验证事件")]
        public event EventHandler TextValidated;
 
        /// <summary>
        /// 文本框数据变更事件
        /// </summary>
        [Category("扩展功能"), Description("文本框数据变更事件")]
        public event EventHandler ButtonDataChanged;
        /// <summary>
        /// 构造函数
        /// </summary>
        public AdvButtonText()
        {
            InitializeComponent();
 
 
            //this.BackColor = Color.FromArgb(255, 247, 245, 241);
            //lbCaption.BackColor = Color.FromArgb(255, 247, 245, 241);
            //lbRemark.BackColor = Color.FromArgb(255, 247, 245, 241);
            //this.Refresh();
            ////textEdit.Properties.AppearanceReadOnly.BackColor = Color.FromArgb(255, 247, 245, 241); //Color.WhiteSmoke;//
            ////textEdit.Properties.AppearanceReadOnly.Options.UseBackColor = true;
            ////lbRemark.BackColor =Color.Transparent;
            ////.BackColor = Color.Cyan;//Color.FromArgb(255, 247, 245, 241);
            btnButton.Click += new EventHandler(btnButton_Click);
            textEdit.Validated += new EventHandler(textEdit_Validated);
            lbCaption.TextChanged += new EventHandler(lbCaption_TextChanged);
            textEdit.Enter += new EventHandler(textEdit_Enter);
 
        }
 
        /// <summary>
        /// 进入文本框时的文本
        /// </summary>
        public string strOldText = "";
 
        /// <summary>
        /// 控件进入时,记录原本的文本
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void textEdit_Enter(object sender, EventArgs e)
        {
            if (ReadOnly == false)
                strOldText = textEdit.Text;
        }
 
        /// <summary>
        /// 设置文本框获得焦点
        /// </summary>
        public void GetFocus()
        {
            textEdit.Focus();
        }
 
        void lbCaption_TextChanged(object sender, EventArgs e)
        {
            if (lbCaption.Text.Trim() == "")
                textEdit.Location = new Point(0, 1);
        }
 
        /// <summary>
        /// 按钮点击事件
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public void btnButton_Click(object sender, EventArgs e)
        {
            DataRow[] RowList = new DataRow[1];
            if (ButtonClick != null && ReadOnly == false)
            {
                //DataRow SelectRow = GetQueryRowArray(this.datacatalogID, this.filter);
                //RowList[0]= SelectRow;
                ButtonClick(this, e);
            }
        }
 
        //private DataRow GetQueryRowArray(object dataCatalogID, object strFilter)
        //{
        //    return GetQueryRow(dataCatalogID, strFilter, "");
        //}
 
        //private DataRow GetQueryRow(object dataCatalogID, object strFilter, string v)
        //{
        //    SelectItemDlg.QueryType = SelectClickType.SingleRow;
        //    SelectItemDlg.Query = this;
        //    SelectItemDlg.SelfTitle = strTitle;
        //    //设置窗口标题
        //    if (SelectItemDlg.GetResultData(DataCatalogID, strFilter, out Error, _isUseCache) == true)
        //    {
        //        if (SelectItemDlg.ShowDialog() == DialogResult.OK)
        //            return (SelectItemDlg.ReturnRow == null) ? null : SelectItemDlg.ReturnRow;
        //        else
        //            return null;
        //    }
        //    else
        //    {
        //        //WriteLog(Error);
        //        return null;
        //    }
        //}
 
        //private DataRow GetQueryRow(string DataCatalogID, string strFilter)
        //{
        //    return GetQueryRow(DataCatalogID, strFilter, "");
        //}
        //string _bindableDataCatalogId = "";
        //string _bindableFilter = "";
        //private DataRow GetQueryRow(string dataCatalogID, string strFilter, string strTitle)
        //{
        //    #region 添加以备翻页复用(2018-1-5 G98118)
        //    _bindableDataCatalogId = dataCatalogID;
        //    _bindableFilter = strFilter;
        //    #endregion
 
        //    //   SelectItemDlg.QueryType = SelectClickType.RowArray;  //单行改为多行
        //    SelectItemDlg.QueryType = SelectClickType.SingleRow;
        //    SelectItemDlg.Query = this;
        //    SelectItemDlg.SelfTitle = strTitle;
        //    //设置窗口标题
        //    if (SelectItemDlg.GetResultData(DataCatalogID, strFilter, out Error, _isUseCache) == true)
        //    {
        //        if (SelectItemDlg.ShowDialog() == DialogResult.OK)
        //            return (SelectItemDlg.ReturnRow == null) ? null : SelectItemDlg.ReturnRow;
        //        else
        //            return null;
        //    }
        //    else
        //    {
        //        //WriteLog(Error);
        //        return null;
        //    }
        //}
 
        /// <summary>
        /// 包装激活数据绑定变更
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void FireButtonDataChanged(object sender, EventArgs e)
        {
            if (ButtonDataChanged != null)
                ButtonDataChanged(sender, e);
        }
 
        /// <summary>
        /// 文本框验证事件
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void textEdit_Validated(object sender, EventArgs e)
        {
            if (TextValidated != null && strOldText != textEdit.Text && ReadOnly == false)
            {
                try
                {
                    TextValidated(this, e);
                }
                catch
                {
                    return;
                }
                strOldText = "";
            }
        }
 
    }
 
    /// <summary>
    /// 显示样式
    /// </summary>
    public enum ShowStyle
    {
        /// <summary>
        /// 非备注模式
        /// </summary>
        NoRemark,
        /// <summary>
        /// 有备注模式
        /// </summary>
        BeRemark,
        /// <summary>
        /// 只有文本按钮模式
        /// </summary>
        BeText
    }
 
 
}