-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathOrderDesignControl.cs
5960 lines (5029 loc) · 206 KB
/
OrderDesignControl.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 System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Diagnostics;
using System.Xml;
using DigitalPlatform.GUI;
using DigitalPlatform.Xml;
using DigitalPlatform.IO;
using DigitalPlatform.Text;
using DigitalPlatform.Core;
namespace DigitalPlatform.CommonControl
{
/// <summary>
/// 订购信息交叉关系 控件
/// </summary>
public partial class OrderDesignControl : UserControl
{
// 是否处在初始化过程中。如果是,则 item 不响应 textchanged 事件。避免引起连锁更新其他文字栏
public bool InInitial { get; set; }
public ToolTip ToolTip { get; set; }
public bool CheckDupItem = true; // 是否在结束的时候检查三元组、四元组
internal bool m_bFocused = false;
bool m_bHideSelection = true;
internal int DisableNewlyOrderTextChanged = 0;
internal int DisableNewlyArriveTextChanged = 0;
public Item LastClickItem = null; // 最近一次click选择过的Item对象
string _sellerFilter = "";
// 书商名称过滤。"<不过滤>"或者空,表示不过滤
public string SellerFilter
{
get
{
return _sellerFilter;
}
set
{
_sellerFilter = value;
}
}
// 获取值列表时作为线索的数据库名
string m_strBiblioDbName = "";
public string BiblioDbName
{
get
{
return this.m_strBiblioDbName;
}
set
{
this.m_strBiblioDbName = value;
foreach (Item item in this.Items)
{
item.location.DbName = value;
}
}
}
// 获得缺省记录
/// <summary>
/// 获得缺省记录
/// </summary>
public event GetDefaultRecordEventHandler GetDefaultRecord = null;
/// <summary>
/// 获得值列表
/// </summary>
public event GetValueTableEventHandler GetValueTable = null;
// 2012/10/4
/// <summary>
/// 检查馆代码是否在管辖范围内
/// </summary>
public event VerifyLibraryCodeEventHandler VerifyLibraryCode = null;
// const int WM_NUMBER_CHANGED = API.WM_USER + 201;
int m_nInSuspend = 0;
// public int m_nTotalCopy = 0;
public List<Item> Items = new List<Item>();
bool m_bChanged = false;
public OrderDesignControl()
{
InitializeComponent();
}
bool m_bSeriesMode = false;
// 是否为期刊模式? true表示为期刊模式,false表示为图书模式
[Category("Appearance")]
[DescriptionAttribute("SeriesMode")]
[DefaultValue(false)]
public bool SeriesMode
{
get
{
return this.m_bSeriesMode;
}
set
{
if (this.m_bSeriesMode != value)
{
this.m_bSeriesMode = value;
SetSeriesMode(value);
}
}
}
void SetSeriesMode(bool bSeriesMode)
{
this.DisableUpdate();
for (int i = 0; i < this.Items.Count; i++)
{
Item item = this.Items[i];
item.SeriesMode = bSeriesMode;
}
if (bSeriesMode == true)
{
this.label_range.Visible = true;
this.label_range.Text = "时间范围";
this.label_issueCount.Visible = true;
}
else
{
// this.label_range.Visible = false;
this.label_range.Visible = true; // ????
this.label_range.Text = "预计出版时间";
this.label_issueCount.Visible = false;
}
this.EnableUpdate();
}
bool m_bArriveMode = false;
// 是否为验收模式? true表示为验收模式,false表示为订购模式
[Category("Appearance")]
[DescriptionAttribute("ArriveMode")]
[DefaultValue(false)]
public bool ArriveMode
{
get
{
return this.m_bArriveMode;
}
set
{
this.m_bArriveMode = value;
SetArriveMode(value);
}
}
void SetArriveMode(bool bArriveMode)
{
if (bArriveMode == true)
{
// 验收态
/*
this.label_orderedTotalCopy.Text = "已验收总复本数(&O):";
this.label_newlyOrderTotalCopy.Text = "新验收总复本数(&N):";
* */
this.label_copy.ForeColor = Color.Red;
this.label_price.ForeColor = Color.Red;
this.label_location.ForeColor = Color.Red;
this.label_newlyOrderTotalCopy.Visible = false;
this.textBox_newlyOrderTotalCopy.Visible = false;
this.button_newItem.Visible = false;
this.label_arrivedTotalCopy.Visible = true;
this.textBox_arrivedTotalCopy.Visible = true;
// 2008/11/3
this.panel_targetRecPath.Visible = true;
this.label_newlyArriveTotalCopy.Visible = true;
this.textBox_newlyArriveTotalCopy.Visible = true;
// 2008/11/3
this.button_fullyAccept.Visible = true;
}
else
{
// false 表示订购态
/*
this.label_orderedTotalCopy.Text = "已订购总复本数(&O):";
this.label_newlyOrderTotalCopy.Text = "新订购总复本数(&N):";
* */
this.label_copy.ForeColor = this.ForeColor;
this.label_price.ForeColor = this.ForeColor;
this.label_location.ForeColor = this.ForeColor;
this.label_newlyOrderTotalCopy.Visible = true;
this.textBox_newlyOrderTotalCopy.Visible = true;
this.button_newItem.Visible = true;
this.label_arrivedTotalCopy.Visible = false;
this.textBox_arrivedTotalCopy.Visible = false;
// 2008/11/3
this.panel_targetRecPath.Visible = false;
this.label_newlyArriveTotalCopy.Visible = false;
this.textBox_newlyArriveTotalCopy.Visible = false;
// 2008/11/3
this.button_fullyAccept.Visible = false;
}
}
public void EnsureVisible(Item item)
{
int[] row_heights = this.tableLayoutPanel_content.GetRowHeights();
int nYOffs = row_heights[0];
int i = 1;
foreach (Item cur_item in this.Items)
{
if (cur_item == item)
break;
nYOffs += row_heights[i++];
}
// this.AutoScrollPosition = new Point(this.AutoScrollOffset.X, 1000);
this.AutoScrollPosition = new Point(this.AutoScrollOffset.X, nYOffs);
}
bool m_bOrderedTotalCopyVisible = false;
// 已订购份数 是否可见?
internal bool OrderedTotalCopyVisible
{
get
{
return this.m_bOrderedTotalCopyVisible;
}
set
{
if (this.m_bOrderedTotalCopyVisible != value)
{
this.m_bOrderedTotalCopyVisible = value;
this.textBox_orderedTotalCopy.Visible = value;
this.label_orderedTotalCopy.Visible = value;
}
}
}
bool m_bArrivedTotalCopyVisible = false;
// 已验收份数 是否可见?
internal bool ArrivedTotalCopyVisible
{
get
{
return this.m_bArrivedTotalCopyVisible;
}
set
{
if (this.m_bArrivedTotalCopyVisible != value)
{
this.m_bArrivedTotalCopyVisible = value;
this.textBox_arrivedTotalCopy.Visible = value;
this.label_arrivedTotalCopy.Visible = value;
}
}
}
// 验收目标记录路径
public string TargetRecPath
{
get
{
return this.textBox_targetRecPath.Text;
}
set
{
this.textBox_targetRecPath.Text = value;
}
}
[Category("Appearance")]
[DescriptionAttribute("HideSelection")]
[DefaultValue(true)]
public bool HideSelection
{
get
{
return this.m_bHideSelection;
}
set
{
if (this.m_bHideSelection != value)
{
this.m_bHideSelection = value;
this.RefreshLineColor(); // 迫使颜色改变
}
}
}
/// <summary>
/// 内容是否发生过修改
/// </summary>
[Category("Content")]
[DescriptionAttribute("Changed")]
[DefaultValue(false)]
public bool Changed
{
get
{
return this.m_bChanged;
}
set
{
if (this.m_bChanged != value)
{
this.m_bChanged = value;
bool bOldChanged = this.m_bChanged;
if (value == false)
ResetLineState();
// 因为 ResetLineState 过程会导致 Changed 被修改为 true
this.m_bChanged = bOldChanged;
Debug.Assert(bOldChanged == this.m_bChanged, "");
}
}
}
// return:
// -1 error
// 0 succeed
public static int VerifyDateRange(string strValue,
out string strError)
{
strError = "";
string strStart = "";
string strEnd = "";
int nRet = strValue.IndexOf("-");
if (nRet == -1)
{
strStart = strValue;
if (strStart.Length != 8)
{
strError = "时间范围 '" + strValue + "' 格式不正确";
return -1;
}
strEnd = "";
}
else
{
strStart = strValue.Substring(0, nRet).Trim();
if (strStart.Length != 8)
{
strError = "时间范围 '" + strValue + "' 内 '" + strStart + "' 格式不正确";
return -1;
}
strEnd = strValue.Substring(nRet + 1).Trim();
if (strStart.Length != 8)
{
strError = "时间范围 '" + strValue + "' 内 '" + strEnd + "' 格式不正确";
return -1;
}
}
if (String.Compare(strStart, strEnd) > 0)
{
strError = "时间范围内的起始时间不应大于结束时间";
return -1;
}
return 0;
}
// 是否为虚拟价格。就是说有 {} 包围的价格
public static bool IsVirtual(string strPrice)
{
if (string.IsNullOrEmpty(strPrice))
return false;
if (strPrice.StartsWith("{"))
return true;
return false;
}
// 进行检查
// return:
// -1 函数运行出错
// 0 检查没有发现错误
// 1 检查发现了错误
public int Check(out string strError)
{
strError = "";
int nRet = 0;
bool bStrict = true; // 是否严格检查
// 检查是否每行都输入了价格、份数
for (int i = 0; i < this.Items.Count; i++)
{
Item item = this.Items[i];
// 只检查新规划的事项
if ((item.State & ItemState.ReadOnly) != 0)
continue;
// 跳过未曾修改过的事项
if ((item.State & ItemState.New) == 0
&& (item.State & ItemState.Changed) == 0)
continue;
// 进行检查
// return:
// -1 函数运行出错
// 0 检查没有发现错误
// 1 检查发现了错误
nRet = item.location.Check(out strError);
if (nRet != 0)
{
strError = "第 " + (i + 1).ToString() + " 行: 馆藏分配去向 格式有问题: " + strError;
return 1;
}
// 2009/11/9
string strTotalPrice = "";
try
{
strTotalPrice = item.TotalPrice;
}
catch (Exception ex)
{
strError = "获取item.TotalPrice时出错: " + ex.Message;
return -1;
}
if (String.IsNullOrEmpty(strTotalPrice) == true)
{
// 总价为空的时候,必须输入订购价
if (String.IsNullOrEmpty(item.Price) == true
&& string.IsNullOrEmpty(item.FixedPrice) == true)
{
strError = "第 " + (i + 1).ToString() + " 行: 尚未输入价格";
return 1;
}
}
else
{
if (String.IsNullOrEmpty(item.StateString) == true
&& String.IsNullOrEmpty(item.Price) == false)
{
strError = "第 " + (i + 1).ToString() + " 行: 当输入了价格 ('" + item.Price + "') 时,必须把总价格设置为空 (但现在为 '" + strTotalPrice + "')";
return 1;
}
}
if (this.ArriveMode == false) // 2009/2/4
{
// 订购模式
if (String.IsNullOrEmpty(item.CopyString) == true)
{
strError = "第 " + (i + 1).ToString() + " 行: 尚未输入复本数";
return 1;
}
// 自动计算出订购价
if (string.IsNullOrEmpty(item.OldFixedPrice) == false
&& IsVirtual(item.OldFixedPrice) == false
&& string.IsNullOrEmpty(item.OldPrice) == true
&& string.IsNullOrEmpty(item.TotalPrice) == true)
{
// return:
// -1 计算过程出现错误
// 0 strFixedPrice 为空,无法计算
// 1 计算成功
nRet = ComputeOrderPriceByFixedPrice(item.OldFixedPrice,
item.OldDiscount,
out string strWishOrderPrice,
out strError);
if (nRet == -1)
{
strError = "第 " + (i + 1).ToString() + " 行: 根据订购码洋 '" + item.OldFixedPrice + "' 和订购折扣 '" + item.OldDiscount + "' 自动计算订购价时出错: " + strError;
return -1;
}
if (nRet == 1)
{
item.OldPrice = strWishOrderPrice;
item.Price = strWishOrderPrice;
}
}
#if NO
// 自动计算出码洋
if (string.IsNullOrEmpty(item.OldFixedPrice) == true
&& string.IsNullOrEmpty(item.OldDiscount) == false
&& string.IsNullOrEmpty(item.OldPrice) == false)
{
// TODO: 注意订购价可能为 "CNY100/3" 形态
// return:
// -1 计算过程出现错误
// 0 strPrice 为空,无法计算
// 1 计算成功
nRet = ComputeFixedPriceByOrderPrice(item.OldPrice,
item.OldDiscount,
out string strResultPrice,
out strError);
if (nRet == -1)
{
strError = "第 " + (i + 1).ToString() + " 行: 根据订购价 '" + item.OldPrice + "' 和订购折扣 '" + item.OldDiscount + "' 自动计算订码洋时出错: " + strError;
return -1;
}
if (nRet == 1)
{
if (string.IsNullOrEmpty(strResultPrice) == false)
strResultPrice = "{" + strResultPrice + "}"; // {} 表示这是计算出来的,不是原始值
item.OldDiscount = strResultPrice;
item.Discount = strResultPrice;
}
}
#endif
if (string.IsNullOrEmpty(item.OldPrice) == false)
{
// 2018/8/1
// 检查码洋、折扣、订购价之间的关系
// return:
// -2 码洋和订购价货币单位不同,无法进行校验。TODO: 今后可增加汇率表,让这种情况变得可以校验
// -1 校验过程出错
// 0 校验发现三者关系不正确
// 1 校验三者关系正确
nRet = VerifyOrderPriceByFixedPrice(StringUtil.Unquote(item.OldFixedPrice, "{}"),
item.OldDiscount,
item.OldPrice,
out string strWishOldPrice,
out strError);
if (nRet != 1)
{
if (nRet == -1)
{
strError = "第 " + (i + 1).ToString() + " 行: 验证订购码洋 '" + item.OldFixedPrice + "' 和订购折扣 '" + item.OldDiscount + "' 和订购价 '" + item.OldPrice + "' 关系时出错: " + strError;
return 1;
}
strError = "第 " + (i + 1).ToString() + " 行: 订购码洋 '" + item.OldFixedPrice + "' 和订购折扣 '" + item.OldDiscount + "' 计算出的结果 '" + strWishOldPrice + "' 和订购价 '" + item.OldPrice + "' 不符";
return 1;
}
}
}
else
{
// 验收模式
// 不一定每一行都要验收
// TODO: 是否检查一下至少有一行验收了?不太好检查。
// 自动计算出验收价
if (string.IsNullOrEmpty(item.FixedPrice) == false
&& IsVirtual(item.FixedPrice) == false
&& string.IsNullOrEmpty(item.Price) == true)
{
// return:
// -1 计算过程出现错误
// 0 strFixedPrice 为空,无法计算
// 1 计算成功
nRet = ComputeOrderPriceByFixedPrice(item.FixedPrice,
item.Discount,
out string strWishOrderPrice,
out strError);
if (nRet == -1)
{
strError = "第 " + (i + 1).ToString() + " 行: 根据验收码洋 '" + item.FixedPrice + "' 和验收折扣 '" + item.Discount + "' 自动计算验收价时出错: " + strError;
return -1;
}
if (nRet == 1)
item.Price = strWishOrderPrice;
}
if (string.IsNullOrEmpty(item.Price) == false)
{
// 2018/8/1
// 检查码洋、折扣、订购价之间的关系
// return:
// -2 码洋和订购价货币单位不同,无法进行校验。TODO: 今后可增加汇率表,让这种情况变得可以校验
// -1 校验过程出错
// 0 校验发现三者关系不正确
// 1 校验三者关系正确
nRet = VerifyOrderPriceByFixedPrice(StringUtil.Unquote(item.FixedPrice, "{}"),
item.Discount,
item.Price,
out string strWishPrice,
out strError);
if (nRet != 1)
{
if (nRet == -1)
{
strError = "第 " + (i + 1).ToString() + " 行: 验证验收码洋 '" + item.FixedPrice + "' 和验收折扣 '" + item.Discount + "' 和验收价 '" + item.Price + "' 关系时出错: " + strError;
return 1;
}
strError = "第 " + (i + 1).ToString() + " 行: 验收码洋 '" + item.FixedPrice + "' 和验收折扣 '" + item.Discount + "' 计算出的结果 '" + strWishPrice + "' 和验收价 '" + item.Price + "' 不符";
return 1;
}
}
}
if (this.SeriesMode == true)
{
// 期刊
if (String.IsNullOrEmpty(item.RangeString) == true)
{
strError = "第 " + (i + 1).ToString() + " 行: 尚未输入时间范围";
return 1;
}
if (item.RangeString.Length != (2 * 8 + 1))
{
strError = "第 " + (i + 1).ToString() + " 行: 尚未输入完整的时间范围";
return 1;
}
// return:
// -1 error
// 0 succeed
nRet = VerifyDateRange(item.RangeString,
out strError);
if (nRet == -1)
{
strError = "第 " + (i + 1).ToString() + " 行: " + strError;
return 1;
}
if (String.IsNullOrEmpty(item.IssueCountString) == true)
{
strError = "第 " + (i + 1).ToString() + " 行: 尚未输入期数";
return 1;
}
}
else
{
// 图书
if (item.IssueCountValue != 1)
{
item.IssueCountValue = 1;
//strError = "第 " + (i + 1).ToString() + " 行: 图书订购只允许期数为 1";
//return 1;
}
}
if (bStrict == true)
{
if (String.IsNullOrEmpty(item.Source) == true
&& item.Seller != "交换" && item.Seller != "赠")
{
strError = "第 " + (i + 1).ToString() + " 行: 尚未输入经费来源";
return 1;
}
// 2009/2/15
if (item.Seller == "交换" || item.Seller == "赠")
{
if (String.IsNullOrEmpty(item.Source) == false)
{
strError = "第 " + (i + 1).ToString() + " 行: 如果渠道为 交换 或 赠,则经费来源必须为空";
return 1;
}
}
if (String.IsNullOrEmpty(item.Seller) == true)
{
strError = "第 " + (i + 1).ToString() + " 行: 尚未输入渠道";
return 1;
}
/*
if (String.IsNullOrEmpty(item.CatalogNo) == true)
{
strError = "第 " + (i + 1).ToString() + " 行: 尚未输入书目号";
return 1;
}
* */
if (String.IsNullOrEmpty(item.Class) == true)
{
strError = "第 " + (i + 1).ToString() + " 行: 尚未输入类别";
return 1;
}
}
}
if (bStrict == true)
{
// 检查 渠道 + 经费来源 + 价格 3元组是否有重复
for (int i = 0; i < this.Items.Count; i++)
{
Item item = this.Items[i];
// 只检查新规划的事项
if ((item.State & ItemState.ReadOnly) != 0)
continue;
// 2009/2/4 只检查新输入的订购事项
if (String.IsNullOrEmpty(item.StateString) == false)
continue;
string strLocationString = item.location.Value;
LocationCollection locations = new LocationCollection();
nRet = locations.Build(strLocationString, out strError);
if (nRet == -1)
{
strError = "第 " + (i + 1).ToString() + " 行: 馆藏分配去向字符串 '" + strLocationString + "' 格式错误: " + strError;
return -1;
}
string strUsedLibraryCodes = StringUtil.MakePathList(locations.GetUsedLibraryCodes());
// 检查馆代码是否在管辖范围内
// 只检查修改过的事项
if (IsChangedItem(item) == true
&& this.VerifyLibraryCode != null)
{
VerifyLibraryCodeEventArgs e = new VerifyLibraryCodeEventArgs();
e.LibraryCode = strUsedLibraryCodes;
this.VerifyLibraryCode(this, e);
if (string.IsNullOrEmpty(e.ErrorInfo) == false)
{
strError = "第 " + (i + 1).ToString() + " 行: 馆藏分配去向错误: " + e.ErrorInfo;
return -1;
}
}
for (int j = i + 1; j < this.Items.Count; j++)
{
Item temp_item = this.Items[j];
// 只检查新规划的事项
if ((temp_item.State & ItemState.ReadOnly) != 0)
continue;
// 跳过未曾修改过的事项
if (IsChangedItem(temp_item) == false)
continue;
// 2009/2/4 只检查新输入的订购事项
if (String.IsNullOrEmpty(temp_item.StateString) == false)
continue;
string strTempLocationString = temp_item.location.Value;
LocationCollection temp_locations = new LocationCollection();
nRet = temp_locations.Build(strTempLocationString, out strError);
if (nRet == -1)
{
strError = "第 " + (j + 1).ToString() + " 行: 馆藏分配去向字符串 '" + strTempLocationString + "' 格式错误: " + strError;
return -1;
}
string strTempUsedLibraryCodes = StringUtil.MakePathList(temp_locations.GetUsedLibraryCodes());
if (this.CheckDupItem == true)
{
if (this.SeriesMode == false)
{
// 对图书检查四元组
if (item.Seller == temp_item.Seller
&& item.Source == temp_item.Source
&& item.Price == temp_item.Price
&& strUsedLibraryCodes == strTempUsedLibraryCodes)
{
strError = "第 " + (i + 1).ToString() + " 行 和 第 " + (j + 1) + " 行之间 渠道/经费来源/价格/馆藏分配去向(中所含的馆代码) 四元组重复,需要将它们合并为一行";
return 1;
}
}
else
{
// 对期刊检查五元组
if (item.Seller == temp_item.Seller
&& item.Source == temp_item.Source
&& item.Price == temp_item.Price
&& item.RangeString == temp_item.RangeString
&& strUsedLibraryCodes == strTempUsedLibraryCodes)
{
strError = "第 " + (i + 1).ToString() + " 行 和 第 " + (j + 1) + " 行之间 渠道/经费来源/时间范围/价格/馆藏分配去向(中所含的馆代码) 五元组重复,需要将它们合并为一行";
return 1;
}
}
}
}
}
}
return 0;
}
static bool IsChangedItem(Item item)
{
if ((item.State & ItemState.Changed) != 0
|| (item.State & ItemState.New) != 0)
return true;
return false;
}
// 获得总份数。包括了所有新规划的和已订购(已验收)的事项
public int GetTotalCopy()
{
int value = 0;
for (int i = 0; i < this.Items.Count; i++)
{
Item cur_element = this.Items[i];
value += cur_element.CopyValue;
}
return value;
}
// 获得新规划的总份数。不包括已订购(已验收)的事项
public int GetNewlyOrderTotalCopy()
{
Debug.Assert(this.ArriveMode == false, "本函数只能在订购状态下使用");
int value = 0;
for (int i = 0; i < this.Items.Count; i++)
{
Item cur_element = this.Items[i];
if ((cur_element.State & ItemState.ReadOnly) != 0)
continue;
value += cur_element.CopyValue;
}
return value;
}
// 获得新验收的总份数。不包括未订购的事项。不包括(显示为只读的)已验收事项
public int GetNewlyArriveTotalCopy()
{
Debug.Assert(this.ArriveMode == true, "本函数只能在验收状态下使用");
int value = 0;
for (int i = 0; i < this.Items.Count; i++)
{
Item cur_element = this.Items[i];
value += cur_element.location.ArrivedCount - cur_element.location.ReadOnlyArrivedCount;
}
return value;
}
// 检测是否有事项尚未订购(状态为空,表示刚刚输入了采购数据)
// return:
// -1 error
// 0 没有处于未订购状态的事项
// 1 有部分处于未订购状态的事项
// 2 全部事项都是未订购状态
public int NotOrdering(out string strMessage)
{
strMessage = "";
int nNotOrderItemCount = 0;
for (int i = 0; i < this.Items.Count; i++)
{
Item cur_element = this.Items[i];
if (String.IsNullOrEmpty(cur_element.StateString) == true)
{
Debug.Assert(cur_element.location.ReadOnly == true, "");
nNotOrderItemCount++;
}
}
if (nNotOrderItemCount == this.Items.Count)
{
strMessage = "全部 " + this.Items.Count.ToString() + " 个事项都处在未订购状态";
return 2;
}
if (nNotOrderItemCount > 0)
{
strMessage = "全部 " + this.Items.Count + " 个事项中有 " + nNotOrderItemCount.ToString() + " 个事项处在未订购状态";
return 1;
}
strMessage = "没有事项处在未订购状态";
return 0;
}
// 获得可新验收的最大总份数。包含了本函数操作前已经新验收的份数。
public int GetNewlyArrivingTotalCopy()
{
Debug.Assert(this.ArriveMode == true, "本函数只能在验收状态下使用");
int value = 0;
for (int i = 0; i < this.Items.Count; i++)
{
Item cur_element = this.Items[i];
// 要看看item本身的状态是不是完全不允许验收 2008/11/12
if (cur_element.location.ReadOnly == true)
continue;
value += cur_element.location.Count - cur_element.location.ReadOnlyArrivedCount;
}
return value;
}
// 获得已订购(已验收)的总份数。不包括新规划的事项
public int GetOrderedTotalCopy()
{
Debug.Assert(this.ArriveMode == false, "本函数只能在订购状态下使用");
int value = 0;
for (int i = 0; i < this.Items.Count; i++)
{
Item cur_element = this.Items[i];
if ((cur_element.State & ItemState.ReadOnly) == 0)
continue;
value += cur_element.CopyValue;
}
return value;
}
// 获得已验收的总份数。不包括新规划的事项
public int GetArrivedTotalCopy()
{
Debug.Assert(this.ArriveMode == true, "本函数只能在验收状态下使用");
int value = 0;
for (int i = 0; i < this.Items.Count; i++)
{
Item cur_element = this.Items[i];
value += cur_element.location.ReadOnlyArrivedCount;
/*
if ((cur_element.State & ItemState.ReadOnly) == 0)
continue;
value += cur_element.CopyValue;
* */
}
return value;
}
public void SelectAll()
{
for (int i = 0; i < this.Items.Count; i++)
{
Item cur_element = this.Items[i];
if ((cur_element.State & ItemState.Selected) == 0)
cur_element.State |= ItemState.Selected;
}
this.Invalidate();
}
public void SelectItem(Item element,
bool bClearOld)
{
if (bClearOld == true)
{
for (int i = 0; i < this.Items.Count; i++)
{
Item cur_element = this.Items[i];
if (cur_element == element)
continue; // 暂时不处理当前行
if ((cur_element.State & ItemState.Selected) != 0)
{
cur_element.State -= ItemState.Selected;