-
Notifications
You must be signed in to change notification settings - Fork 2
/
FormMain.cs
1093 lines (997 loc) · 50.1 KB
/
FormMain.cs
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using QRCoder;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace QRCoderArt
{
/// <summary>
/// Class FormMain.
/// Форма использующая динамический интерфейс на плавающих панелях для работы с payload на базе GUITree
/// Implements the <see cref="System.Windows.Forms.Form" />
/// </summary>
/// <seealso cref="System.Windows.Forms.Form" />
public partial class FormMain : Form
{
/// <summary>
/// readyState
/// структура для фиксации ошибки (при пересоздании CTRL из GUITree) при первом запуске функции payload
/// </summary>
private readonly bool[] readyState = {false, //Data preparation completed
false, //MainForm is Load
false }; //Mainform is Show
readonly GUITree ReflectionData;
/// <summary>
/// Initializes a new instance of the <see cref="FormMain" /> class.
/// </summary>
public FormMain()
{
CallBack_SetParam.callbackEventHandler = new CallBack_SetParam.callbackEvent(this.CallbackReload); //subscribe (listen) to the general notification
InitializeComponent();
}
public FormMain(GUITree guiTree) : this()
{
ReflectionData = guiTree;
string baseName = "Payload"; //проще сразу указать имя
//this.cbPayload.DataSource = ReflectionData.GetMembersClassName_(baseName); //get list names classes members QRCoder.PayloadGenerator
this.cbPayload.DataSource = new BindingSource(ReflectionData.GetMembersClassName(baseName), null);
this.cbPayload.DisplayMember = "Key"; //Имя
this.cbPayload.ValueMember = "Value"; //значение
// this.cbPayload.SelectedItem = 0;
// }
this.viewMode.DataSource = Enum.GetValues(typeof(ImageLayout));
this.viewMode.SelectedIndex = 4;
this.QRCodeString.Dock = DockStyle.Fill;
this.QRCodeError.Dock = DockStyle.Fill;
this.QRCodeString.Visible = true;
}
/// <summary>
/// Handles the Load event of the FormMain control.
/// устанавливает флаг readyState[1] для первого корректного вызова payload
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private void FormMain_Load(object sender, EventArgs e)
{
//заполним выпадающие списки из enum
eccLevel.DataSource = Enum.GetValues(typeof(QRCodeGenerator.ECCLevel));
// eccLevel.SelectedIndex = eccLevel.FindStringExact(QRCodeGenerator.ECCLevel.Q.ToString());
eccLevel.SelectedItem = QRCodeGenerator.ECCLevel.M;
artQuietZoneRenderingStyle.DataSource = Enum.GetValues(typeof(ArtQRCode.QuietZoneStyle));
artQuietZoneRenderingStyle.SelectedItem = ArtQRCode.QuietZoneStyle.Dotted;
artBackgroundImageStyle.DataSource = Enum.GetValues(typeof(ArtQRCode.BackgroundImageStyle));
artBackgroundImageStyle.SelectedItem = ArtQRCode.BackgroundImageStyle.DataAreaOnly;
QRCodeString.Text = "enter your text or select payload + constructor + fill in the parameters";
readyState[1] = true; //MainForm is Load
Art.Parent = null; //скрыть вкладку
/*
var account = "40702810138250123017";
var bic = "044525225";
var bankName = "ОАО \"БАНК\"";
var name = "ООО «Три кита»";
var correspAcc = "30101810965770000413";
PayloadGenerator.RussiaPaymentOrder.OptionalFields of = new PayloadGenerator.RussiaPaymentOrder.OptionalFields() { KPP = "12345", Category ="zzz" };
var generator = new PayloadGenerator.RussiaPaymentOrder(name, account, bankName, bic, correspAcc, of);
string payload = generator.ToString();
*/
}
/// <summary>
/// Handles the Shown event of the FormMain control.
/// устанавливает флаг readyState[2] для первого корректного вызова payload
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private void FormMain_Shown(object sender, EventArgs e)
{
RebuildingGUITreePanel(this.cbPayload, null);
readyState[2] = true; //Main form is Show
}
#region //REFLECTION
#region //GuiTreePanel
/// <summary>
/// ClearGUITreePanel
/// очистить все CTRL из плавающей панели payload
/// </summary>
/// <param name="panelGUITree">плавающая панель CTRL из GUITree</param>
private void ClearGUITreePanel(Control panelGUITree)
{
if (panelGUITree.HasChildren)
{
for (int i = panelGUITree.Controls.Count - 1; i >= 0; i--) //not foreach use...
{
Control cn = panelGUITree.Controls[0];
// cn -= new System.EventHandler(cn, payload_Changed);
panelGUITree.Controls.Remove(cn);
cn.Dispose();
}
}
}
/// <summary>
/// CreateGUITreePanel
/// создать CTRL panel из GUITree
/// </summary>
/// <param name="panelGUITree">плавающая панель CTRL из GUITree</param>
private void CreateGUITreePanel(Control panelGUITree)
{
int labelWidth = 135;// 122;// 135;
int sizeWidth = 263;
int reverseShift = 5; // paddind compensation for nested controls
int controlWidth;
Panel tPanel;
Padding padding = new Padding(0, 1, 1, 1);
Stack<Panel> panels = new Stack<Panel>();
panels.Push((Panel)panelGUITree);
panelPayload.Visible = false; //render off
foreach (var prop in ReflectionData.GetTree())
{
// this.Refresh();
controlWidth = prop.nullValue ? 113 : 128;
// controlWidth = prop.fNull ? 103 : 128;
if (panels.Peek().Name != prop.parentName && panels.Peek().Name != panelGUITree.Name)
{
tPanel = panels.Pop(); //go back to the previous panel
}
Label lb = new Label
{
Name = prop.name,
AutoSize = false,
Margin = padding
}; //Label();
if (prop.dataType != "Constructor")
{
lb.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
lb.Text = prop.name;
lb.Size = new Size(labelWidth - prop.nestingLevel * reverseShift, 20);
panels.Peek().Controls.Add(lb);
}
else
{
lb.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
lb.Text = prop.name + " constructor's"; //(panels.Peek().Name == "panelPayload" ? "Class: " : "subClass: ") + prop.fName + " constructor's";
lb.Size = new Size(sizeWidth - prop.nestingLevel * reverseShift, 20);
panels.Peek().Controls.Add(lb);
}
switch (prop.formType)
{
case "TextBox":
TextBox tb = new TextBox
{
Size = new Size(controlWidth, 20),
Margin = padding,
Name = "" + prop.name,
AccessibleName = prop.id.ToString(),// "Get",
AccessibleDescription = prop.dataType //type in tooltype
};
tb.MouseHover += new System.EventHandler(ToolTipMouseHover);
tb.TextChanged += new EventHandler(GetPayloadStringFromGUITreePanel);
switch (prop.dataType)
{
case "Single":
case "Int32":
case "UInt32":
case "UInt64":
case "Decimal":
case "Double":
tb.BackColor = Color.GhostWhite;//.OldLace;// LightBlue;
tb.KeyPress += new KeyPressEventHandler(FilterOnlyReal);
tb.Text = prop.defaultValue == null ? "" : Convert.ToString(prop.defaultValue);
break;
default:
tb.Text = prop.defaultValue == null ? "" : Convert.ToString(prop.defaultValue);
break;
}
panels.Peek().Controls.Add(tb);
if (prop.nullValue)
{
CheckBox chtb = new CheckBox
{
Size = new Size(13, 20),
Margin = padding,
Name = "" + prop.name,
AccessibleDescription = "Nullable" //type in tooltype
};
chtb.MouseHover += new System.EventHandler(ToolTipMouseHover);
chtb.CheckedChanged += (sender, e) => tb.Enabled = (chtb.CheckState == CheckState.Checked); // GeyPayLoadStringFromForm(null, null);
panels.Peek().Controls.Add(chtb);
tb.Enabled = false;// chtb.Checked;
}
// DataBindings.Add("Text", ReflectionData.pointTree.Value.formValue, "formValue");
break;
case "CheckBox":
CheckBox chb = new CheckBox
{
Size = new Size(controlWidth, 20),
Margin = padding,
Name = "" + prop.name,
AccessibleName = prop.id.ToString(),// "Get",
AccessibleDescription = prop.dataType
};
chb.CheckedChanged += new EventHandler(GetPayloadStringFromGUITreePanel);
panels.Peek().Controls.Add(chb);
break;
case "dataGridView":
DataGridView dgv = new DataGridView
{
Size = new Size(103, 20),
Margin = padding,
Name = "" + prop.name,
DataSource = new Dictionary<string, string> { ["plugin"] = "plugin + pluginOption", ["-"] = "-" }, //!!! refresh from callback -> CallBack_GetParam
//new Dictionary<string, string>{["plugin"] = plugin + (string.IsNullOrEmpty(pluginOption)? "": $";{pluginOption}")}
AccessibleName = prop.id.ToString(),// "Get",
AccessibleDescription = prop.dataType
};
dgv.MouseHover += new System.EventHandler(ToolTipMouseHover);
dgv.DataSourceChanged += new EventHandler(GetPayloadStringFromGUITreePanel);
panels.Peek().Controls.Add(dgv);
// case "Button": //for custom parameter
Button bt = new Button
{
Size = new Size(23, 20),
Margin = padding,
Name = "" + prop.name,
Text = "...",
AccessibleName = "",// "Get";
FlatStyle = FlatStyle.System,
AccessibleDescription = "setting a custom parameter"// prop.fType;
};
bt.MouseHover += new System.EventHandler(ToolTipMouseHover);
bt.Click += new EventHandler(SetPropretyPairs);
// bt.Click += (sender, e) => {dictionaryForm a = new dictionaryForm(); a.ShowDialog(); };
panels.Peek().Controls.Add(bt);
break;
case "DateTime":
DateTimePicker dtp = new DateTimePicker
{
Size = new Size(controlWidth, 20),
Margin = padding,
Name = "" + prop.name,
AccessibleName = prop.id.ToString(),// "Get",
AccessibleDescription = prop.dataType,
Format = DateTimePickerFormat.Short
};
dtp.ValueChanged += new EventHandler(GetPayloadStringFromGUITreePanel);
dtp.EnabledChanged += new EventHandler(GetPayloadStringFromGUITreePanel);
panels.Peek().Controls.Add(dtp);
if (prop.nullValue)
{
CheckBox chdtp = new CheckBox
{
Size = new Size(13, 20),
Margin = padding,
Name = "" + prop.name,
AccessibleDescription = "Nullable" //type in tooltype
};
chdtp.MouseHover += new System.EventHandler(ToolTipMouseHover);
chdtp.CheckedChanged += (sender, e) => dtp.Enabled = (chdtp.CheckState == CheckState.Checked);// GeyPayLoadStringFromForm(null, null);
panels.Peek().Controls.Add(chdtp);
dtp.Enabled = false;// chdtp.Checked;
}
break;
case "ComboBox":
ComboBox cmb = new ComboBox
{
// cmb.BeginUpdate();
Name = "" + prop.name,
AccessibleName = prop.id.ToString(),// "Get",
//cmb.AccessibleDescription = prop.fType;
DataSource = new BindingSource(prop.dataSource, null), //получить конструкторы member
DisplayMember = "Key", //Имя
ValueMember = "Value", //значение
SelectedItem = 0,
DropDownStyle = ComboBoxStyle.DropDownList
};
if (prop.dataType == "Constructor")
{
// cmb.Name += "ctor_";
cmb.AccessibleDescription = "Constructor";
cmb.SelectedIndexChanged += new EventHandler(RebuildingGUITreePanel);
panels.Peek().Controls.Add(cmb);
cmb.Size = new Size(sizeWidth - prop.nestingLevel * reverseShift, 20);
FlowLayoutPanel cPanel = new FlowLayoutPanel
{
Name = "" + prop.name,
AutoSize = true,
Padding = new Padding(0, 2, 0, 2),
BorderStyle = BorderStyle.FixedSingle
};
panels.Peek().Controls.Add(cPanel);
panels.Push(cPanel);
Control cntrl = this.FilterControls(c => c.Name != null && c.Name.Equals(prop.name) && c is Label).First();
cntrl.Text += " (" + prop.dataSource.Count.ToString() + ")";
}
else
{
cmb.SelectedIndexChanged += new EventHandler(GetPayloadStringFromGUITreePanel);
cmb.Size = new Size(controlWidth, 20);
cmb.Margin = padding;
panels.Peek().Controls.Add(cmb);
if (prop.nullValue)
{
CheckBox chcmb = new CheckBox
{
Size = new Size(13, 20),
Margin = padding,
Name = "" + prop.name,
AccessibleDescription = "Nullable" //type in tooltype
};
chcmb.MouseHover += new System.EventHandler(ToolTipMouseHover);
chcmb.CheckedChanged += (sender, e) => cmb.Enabled = (chcmb.CheckState == CheckState.Checked);// GeyPayLoadStringFromForm(null, null);
panels.Peek().Controls.Add(chcmb);
cmb.Enabled = false;// chdtp.Checked;
}
}
// cmb.EndUpdate();
break;
}
}
panelPayload.Visible = true; //render on
}
/// <summary>
/// RebuildingGUITreePanel
/// обновить GUITree панель или ее фрагмент GUITreeNodes
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private void RebuildingGUITreePanel(object sender, EventArgs e)
{
ComboBox combo = sender as ComboBox;
Control[] panel = combo.Name == "cbPayload" ?
this.FilterControls(c => c.Name != null && c.Name.Equals("panelPayload") && c is FlowLayoutPanel) :
this.FilterControls(c => c.Name != null && c.Name.Equals(combo.Name) && c is FlowLayoutPanel);
if (combo.SelectedItem != null)
{
readyState[0] = false; //full ready:= Data preparation not completed
ClearGUITreePanel(panel.First()); //clear payload panel
if (combo.Name == "cbPayload")
{
// ReflectionData.GetGUITree(ReflectionData.GetMemberByName(combo.Text));//, combo.Name);
ReflectionData.GetGUITree(((KeyValuePair<string, object>)combo.SelectedItem).Value);
// ReflectionData.GetGUITree(ReflectionData.GetMemberByName(combo.Name));
}
else
{
//clear child from parentName in tree
// ReflectionData.
ReflectionData.GetGUITreeNodes(((ConstructorInfo)((KeyValuePair<string, object>)combo.SelectedItem).Value), panel[0].GetNestleLevel("panelPayload"), combo.Name);
}
CreateGUITreePanel(panel.First()); //create payload panel from constructor parameters
// this.Refresh();
readyState[0] = true; //full ready:= Data preparation completed
GetPayloadStringFromGUITreePanel(null, null);
}
}
/// <summary>
/// ReadGUITreePanel
/// прочитать текущие значения CTRL панели GUITree и
/// собрать массив параметров для инициализации конструктора
/// </summary>
/// <param name="panelGUITree">The panel.</param>
/// <param name="errorList">error List</param>
/// <returns>Dictionary<System.String, System.Object>.</returns>
private Dictionary<string, object> GetParamFromGUITreePanel(FlowLayoutPanel panelGUITree, List<InvokeError> errorList)
{
object ret;// = null;
Dictionary<string, object> ParamFromControl = new Dictionary<string, object>();
if (panelPayload.HasChildren)
{
foreach (Control cntrl in panelGUITree.Controls)
{
// if (cntrl.Created && cntrl.AccessibleName == "Get" && cntrl.Parent.Name == panelGUITree.Name)
if (cntrl.Created && Guid.TryParse(cntrl.AccessibleName, out var newGuid) && cntrl.Parent.Name == panelGUITree.Name)
{
ret = null;
if (cntrl.Enabled)
{
switch (cntrl.AccessibleDescription)
{
case "Constructor":
ConstructorInfo ctor = (ConstructorInfo)((KeyValuePair<string, object>)((ComboBox)cntrl).SelectedItem).Value;
Control[] pan = panelPayload.FilterControls(c => c.Name != null
&& c.Name == cntrl.Name && c is FlowLayoutPanel);
// //!!! recursion
ret = new GUIInvoke().GetInvokeCtor(ctor, GetParamFromGUITreePanel((FlowLayoutPanel)pan[0], errorList), errorList);
break;
case "String":
ret = ((TextBox)cntrl).Text;
break;
case "Double":
ret = Convert.ToDouble(((TextBox)cntrl).Text == "" ? "0" : ((TextBox)cntrl).Text);
break;
case "Single":
ret = Convert.ToSingle(((TextBox)cntrl).Text == "" ? "0" : ((TextBox)cntrl).Text);
break;
case "Int32":
ret = Convert.ToInt32(((TextBox)cntrl).Text == "" ? "0" : ((TextBox)cntrl).Text);
break;
case "UInt32":
ret = Convert.ToUInt32(((TextBox)cntrl).Text == "" ? "0" : ((TextBox)cntrl).Text);
break;
case "UInt64":
ret = Convert.ToUInt64(((TextBox)cntrl).Text == "" ? "0" : ((TextBox)cntrl).Text);
break;
case "Decimal":
ret = Convert.ToDecimal(((TextBox)cntrl).Text == "" ? "0" : ((TextBox)cntrl).Text);
break;
case "Boolean":
ret = ((CheckBox)cntrl).Checked;
break;
case "DateTime":
ret = ((DateTimePicker)cntrl).Value;
break;
case "Dictionary`2":
if (cntrl.Parent.Name == "ShadowSocksConfig" && cntrl.Name == "parameters")
//get param pairs
{
ret = ((DataGridView)cntrl).DataSource;
}
break;
default:
if (cntrl.GetType().Name == "ComboBox")
ret = ((KeyValuePair<string, object>)((ComboBox)cntrl).SelectedItem).Value;
break;
}
}
ParamFromControl.Add(cntrl.Name, ret);
}
}
}
return ParamFromControl;
}
/// <summary>
/// GetPayloadStringFromGUITreePanel
/// прочитать параметры панели GUITree и вызвать базовый метод payload ((invoke ToString() execute))
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private void GetPayloadStringFromGUITreePanel(object sender, EventArgs e)
{
List<InvokeError> errorList = new List<InvokeError>();
if (readyState[0] && readyState[1] && readyState[2]) //full ready:= Data preparation completed && form load && form show
{
Dictionary<string, object> ParamFromControl = null;
Control[] panel = this.FilterControls(c => c.Name != null && c.Name.Equals(cbPayload.Text) && c is FlowLayoutPanel);
//собрать массив параметров для инициализации конструктора
ParamFromControl = GetParamFromGUITreePanel((FlowLayoutPanel)panel[0], errorList);
//инициализировать конструктор payload
Control[] cmb = this.FilterControls(c => c.Name != null && c.Name.Equals(cbPayload.Text) && c is ComboBox);
ConstructorInfo ctrm = (ConstructorInfo)((System.Collections.Generic.KeyValuePair<string, object>)((ComboBox)cmb[0]).SelectedItem).Value;
object ctorObj = new GUIInvoke().GetInvokeCtor(ctrm, ParamFromControl, errorList);
//выполнить главный метод
string payloadStr = new GUIInvoke().GetInvokeMember(ctorObj, ctrm, errorList);
if (ctorObj != null && errorList.Count() == 0)
{
if (ctrm.GetParameters().Length == 0) //constrictor without parameters = there is no constructor
{
QRCodeString.Text = ctrm.ReflectedType.GetMethod("ToString").Invoke(ctorObj, new object[] { }).ToString();
}
else
QRCodeString.Text = ctrm.ReflectedType.GetMethod("ToString").Invoke(ctorObj, null).ToString();
QRCodeError.Visible = false;
QRCodeString.Visible = true;
}
else
{
QRCodeString.Visible = false;
QRCodeError.DocumentText = new GUIInvoke().GetHTMLFormattedErrorDescription(cmb[0].Name, errorList);
QRCodeString.Visible = false;
QRCodeError.Visible = true;
pictureBoxQRCode.BackgroundImage = global::QRCoderArt.Properties.Resources.qr_no;
}
}
}
#endregion
#region //EventGuiTreePanel
/// <summary>
/// ToolTipMouseHover
/// отобразить всплывающую подсказку из AccessibleDescription
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private void ToolTipMouseHover(object sender, EventArgs e)
{
toolTip1.SetToolTip((System.Windows.Forms.Control)sender,
((System.Windows.Forms.Control)sender).AccessibleDescription);
}
/// <summary>
/// FilterOnlyReal
/// проверка ввода на числа с плавающей точкой (контролируя системный разделитель)
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="KeyPressEventArgs" /> instance containing the event data.</param>
private void FilterOnlyReal(object sender, KeyPressEventArgs e)
{
string sep = ((float)1 / 2).ToString().Substring(1, 1); // system sparator
/*
bool lCheck = false;
TextBox cnt = sender as TextBox;
string txt = (cnt.Text + e.KeyChar).Replace(" ", "");
switch (cnt.AccessibleDescription)
{
case "Single":
lCheck = Regex.IsMatch(txt, @"^([0-9\b\" + sep + "]){1,10}$");
break;
case "Int32":
break;
case "UInt32":
lCheck = Regex.IsMatch(txt, @"^([0-9\b\" + sep + "]){1,10}$");
break;
case "UInt64":
lCheck = Regex.IsMatch(txt, @"^([0-9\b\" + sep + "]){1,20}$");
break;
case "Decimal":
break;
case "Double":
break;
default:
lCheck = Regex.IsMatch(txt, @"^([0-9\b])");
break;
}
e.Handled = !lCheck;
*/
if (!(Char.IsDigit(e.KeyChar)) && !((e.KeyChar == Convert.ToChar(sep)) && (((TextBox)sender).Text.IndexOf(sep) == -1) && (((TextBox)sender).Text.Length != 0)))
{
if (e.KeyChar != (char)Keys.Back)
{
e.Handled = true;
}
}
}
/// <summary>
/// SetPropretyPairs
/// передать через асинхронное сообщение (callback) пары параметров ключ-значение во внешнюю форму на редактирование
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private void SetPropretyPairs(object sender, EventArgs e)
{
Button bt = sender as Button;
FormDictionary a = new FormDictionary();
Control[] cntrl = this.FilterControls(c => c.Name != null && c.Name.Equals(bt.Name) && c is DataGridView);
CallBack_GetParam.callbackEventHandler(bt.Name, bt.Parent.Name, (Dictionary<String, String>)((DataGridView)cntrl[0]).DataSource); //send a general notification
a.Owner = this;
a.ShowDialog();
}
#endregion
#endregion
#region //Interface
/// <summary>
/// выбор режима рендеринго
/// </summary>
private void baseMode_CheckedChanged(object sender, EventArgs e)
{
if (!baseMode.Checked)
{
Art.Parent = null;
Logo.Parent = baseTabControl;
}
else
{
Art.Parent = baseTabControl;
Logo.Parent = null;
}
Setting_Changed(null, null);
}
/// <summary>
/// диалог about
/// </summary>
private void Form1_HelpButtonClicked(object sender, CancelEventArgs e)
{
FormAbout a = new FormAbout();
a.ShowDialog();
}
/// <summary>
/// Gets the icon bitmap.
/// </summary>
/// <returns>Bitmap.</returns>
private Bitmap GetIconBitmap()
{
if (logoIconPath.Text.Length == 0)
return null;
try
{
return new Bitmap(logoIconPath.Text);
}
catch (Exception)
{
return null;
}
}
/// <summary>
/// Gets the art bitmap.
/// </summary>
/// <returns>Bitmap.</returns>
private Bitmap GetArtBitmap()
{
if (artIconPath.Text.Length == 0)
return null;
try
{
return new Bitmap(artIconPath.Text);
}
catch (Exception)
{
return null;
}
}
/// <summary>
/// Gets the artpattern bitmap.
/// </summary>
/// <returns>Bitmap.</returns>
private Bitmap GetArtPatternBitmap()
{
if (artPatternPath.Text.Length == 0)
return null;
try
{
return new Bitmap(artPatternPath.Text);
}
catch (Exception)
{
return null;
}
}
/// <summary>
/// расположение картинки QRCode в ViewMode окне
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private void ViewMode_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxQRCode.BackgroundImageLayout = (ImageLayout)Enum.Parse(typeof(ImageLayout), viewMode.Text);// Enum.GetName(typeof(ImageLayout), "2"); //Enum.Parse(typeof(ImageLayout), sender.ToString());
}
#endregion
#region //QR Setting
/// <summary>
/// RenderQrCode создать картинку QR кода
/// </summary>
private void RenderQrCode()
{
using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
{
using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(QRCodeString.Text, (QRCodeGenerator.ECCLevel)eccLevel.SelectedItem))
{
if (!baseMode.Checked)
{
using (QRCode qrCode = new QRCode(qrCodeData))
{
pictureBoxQRCode.BackgroundImage = qrCode.GetGraphic(
(int)basePixelsPerModule.Value,
baseDarkColor.BackColor,
baseLightColor.BackColor,
GetIconBitmap(),
(int)logoIconSizePercent.Value,
(int)logoIconBorderWidth.Value,
baseDrawQuietZones.Checked,
logoIconPath.Text != "" && logoIconBorderWidth.Value > 0 ? logoBackColor.BackColor : baseLightColor.BackColor
);
pictureBoxQRCode.Size = new System.Drawing.Size(pictureBoxQRCode.Width, pictureBoxQRCode.Height);
}
}
else
{
using (ArtQRCode qrCode = new ArtQRCode(qrCodeData))
{
pictureBoxQRCode.BackgroundImage = qrCode.GetGraphic(
(int)basePixelsPerModule.Value,
baseDarkColor.BackColor,
baseLightColor.BackColor,
artBackgroundColor.BackColor,
GetArtBitmap(),
(double)artPixelSizeFactor.Value,
baseDrawQuietZones.Checked,
(ArtQRCode.QuietZoneStyle)artQuietZoneRenderingStyle.SelectedItem,
(ArtQRCode.BackgroundImageStyle)artBackgroundImageStyle.SelectedItem,
GetArtPatternBitmap()
);
pictureBoxQRCode.Size = new System.Drawing.Size(pictureBoxQRCode.Width, pictureBoxQRCode.Height);
}
}
}
}
//Set the SizeMode to center the image.
//pictureBoxQRCode.SizeMode = PictureBoxSizeMode.CenterImage;
pictureBoxQRCode.SizeMode = PictureBoxSizeMode.StretchImage;
}
/// <summary>
/// Setting_Changed
/// общий обработчик события изменения параметров панели GUITree
/// </summary>
private void Setting_Changed(object sender, EventArgs e)
{
RenderQrCode(); //create QR image
}
/// <summary>
/// проверить есть путь к картинке Logo или нет
/// </summary>
private void logoIconPath_TextChanged(object sender, EventArgs e)
{
panelLogo.Enabled = logoIconPath.Text != "";
Setting_Changed(null, null);
}
/// <summary>
/// проверить есть путь к картинке Art или нет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void artPatternPath_TextChanged(object sender, EventArgs e)
{
//panelArt.Enabled = artIconPath.Text != "";
Setting_Changed(null, null);
}
#endregion
#region Open Save Dialod and Setting
/// <summary>
/// диалог выбора файла
/// </summary>
/// <param name="name">имя файла</param>
/// <param name="filter">фильтр</param>
/// <returns></returns>
private string getFileName(string name, string filter)
{
//filter = string.Empty;
/*
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
string sep = string.Empty;
foreach (var c in codecs)
{
string codecName = c.CodecName.Substring(8).Replace("Codec", "Files").Trim();
filter = String.Format("{0}{1}{2} ({3})|{3}", filter, sep, codecName, c.FilenameExtension);
sep = "|";
}
filter = String.Format("{0}{1}{2} ({3})|{3}", filter, sep, "All Files", "*.*");
*/
filter = "png Image|*.png|jpeg Image|*.jpg|gif Image|*.gif|bmp Image|*.bmp";
openFileDialogSetting.Title = name;
openFileDialogSetting.Filter = filter;
// openFileDialogSetting.DefaultExt = defaultExt;
DialogResult dr = openFileDialogSetting.ShowDialog();
if (dr == DialogResult.Abort)
return "";
if (dr == DialogResult.Cancel)
return "";
return openFileDialogSetting.FileName.ToString();
}
/// <summary>
/// диалог сохранения файла
/// </summary>
/// <returns></returns>
private SaveFileDialog setFileName(string name, string filter, string filename)
{
//filter = string.Empty;
filter = "png Image|*.png|jpeg Image|*.jpg|gif Image|*.gif|bmp Image|*.bmp";
saveFileDialogSetting.Title = name;
saveFileDialogSetting.Filter = filter;
saveFileDialogSetting.FileName = filename;
DialogResult dr = saveFileDialogSetting.ShowDialog();
if (dr == DialogResult.Abort)
return null;
if (dr == DialogResult.Cancel)
return null;
return saveFileDialogSetting;
}
/// <summary>
/// кнопка выбор Logo (для сброса - выбрать и отказаться)
/// </summary>
private void SelectIconBtn_Click(object sender, EventArgs e)
{
logoIconPath.Text = getFileName("Select Logo image file", "");
}
/// <summary>
/// кнопка выбор Art (для сброса - выбрать и отказаться)
/// </summary>
private void SelectArtBtn_Click(object sender, EventArgs e)
{
artIconPath.Text = getFileName("Select Art image file", "");
}
/// <summary>
/// кнопка выбор ArtPattern (3 квадрата по углам) (для сброса - выбрать и отказаться)
/// </summary>
private void artPatternButton_Click(object sender, EventArgs e)
{
artPatternPath.Text = getFileName("Select ArtPattern image file", "");
}
/// <summary>
/// Handles the Click event of the Btn_save control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
/// <exception cref="System.NotSupportedException">File extension is not supported</exception>
private void Btn_save_Click(object sender, EventArgs e)
{
SaveFileDialog saveDialod = setFileName("Select save QRCode filename", "", "QRCode_" + DateTime.Now.ToString("yyyyMMddHHmm"));
// If the file name is not an empty string open it for saving.
if (saveDialod.FileName != "")
{
// Saves the Image via a FileStream created by the OpenFile method.
using (FileStream fs = (System.IO.FileStream)saveDialod.OpenFile())
{
// Saves the Image in the appropriate ImageFormat based upon the
// File type selected in the dialog box.
// NOTE that the FilterIndex property is one-based.
ImageFormat imageFormat = null;
switch (saveDialod.FilterIndex)
{
case 1:
imageFormat = ImageFormat.Bmp;
break;
case 2:
imageFormat = ImageFormat.Png;
break;
case 3:
imageFormat = ImageFormat.Jpeg;
break;
case 4:
imageFormat = ImageFormat.Gif;
break;
default:
throw new NotSupportedException("File extension is not supported");
}
pictureBoxQRCode.BackgroundImage.Save(fs, imageFormat);
}
}
}
#endregion
#region Select Color Dialog
/// <summary>
/// диалог выбора цвета
/// </summary>
/// <param name="initColor"></param>
/// <returns></returns>
private Color getColor(Color initColor)
{
colorDialogSetting.FullOpen = true;
colorDialogSetting.Color = initColor;
if (colorDialogSetting.ShowDialog() == DialogResult.OK)
return colorDialogSetting.Color;
else
return initColor;
}
/// <summary>
/// цвет темной зоны
/// </summary>
private void baseDarkColor_Click(object sender, EventArgs e)
{
baseDarkColor.BackColor = getColor(baseDarkColor.BackColor);// Color.Black);
Setting_Changed(null, null);
}
/// <summary>
/// цвет светлой зоны
/// </summary>
private void baseLightColor_Click(object sender, EventArgs e)
{
baseLightColor.BackColor = getColor(baseLightColor.BackColor);
Setting_Changed(null, null);
}
/// <summary>
/// цвет за/под лого
/// </summary>
private void logoBackColor_Click(object sender, EventArgs e)
{
logoBackColor.BackColor = getColor(logoBackColor.BackColor);
Setting_Changed(null, null);
}
/// <summary>
/// цвет за/под фоновой картинкой
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void artBackgroundColor_Click(object sender, EventArgs e)
{
artBackgroundColor.BackColor = getColor(artBackgroundColor.BackColor);
Setting_Changed(null, null);
}
#endregion
#region //CALLBACK InPut (подписка на внешние сообщения)
/// <summary>
/// Callbacks the reload.
/// входящее асинхронное сообщение для подписанных слушателей с передачей текущих параметров
/// </summary>
/// <param name="controlName">имя CTRL</param>
/// <param name="controlParentName">имя родителя CNTRL</param>
/// <param name="param">параметры ключ-значение.</param>
private void CallbackReload(string controlName, string controlParentName, Dictionary<String, String> param)
{
if (param.Count() != 0)
{
Control[] cntrl = this.FilterControls(c => c.Name != null && c.Name.Equals(controlName) && c is DataGridView);
((DataGridView)cntrl[0]).DataSource = param;
}
}
#endregion
}
#region //CALLBACK OutPut (собственные сообщения)
/// <summary>
/// CallBack_GetParam
/// исходящее асинхронное сообщение для подписанных слушателей с передачей текущих параметров
/// </summary>