yangle
2023-03-10 dabd6d20c31442d461fc30c49aa04abd4549be6b
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DBUtility
{
    public  class ClsXt_BaseBill
    {
 
        public string BillType;      //单据类型
        public string HBillSubType;      //单据子类型
        public string MvarItemKey;    //表名
        public string MvarItemKeySub; // 子表名
        public string MvarItemKeySub2; // 子表名
        public string MvarItemKeySub3; // 子表名
        public string MvarItemKeySub4; // 子表名
        public string MvarItemKeySubForWeb; //子表视图WEB
        public string MvarItemKeySubForWeb2; //子表2视图WEB
        public string MvarItemKeyForWeb; //主表视图WEB
 
        public string MvarReportTitle;  //标题 
        public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        public SQLHelper.ClsCNK3 oK3Cn = new SQLHelper.ClsCNK3();
        public SQLHelper.ClsCNK3 oCnK3 = new SQLHelper.ClsCNK3();
 
        public ClsXt_BaseBill()
        {
            BillType = "";
            MvarItemKey = "";
            MvarItemKeySub = "";
            MvarItemKeySub2 = "";
            MvarItemKeySub3 = "";
            MvarItemKeySub4 = "";
            MvarReportTitle = "";
            MvarItemKeySubForWeb = ""; 
            MvarItemKeySubForWeb2 = "";  //新增
            MvarItemKeyForWeb = "";
        }
 
        #region 固定代码 
 
        ~ClsXt_BaseBill()
        {
            
        }
        //反作废
        public bool AbandonCancelltion(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                DataSet ds = oCn.RunProcReturn("select * from " + MvarItemKey + " where HInterID=" + lngBillKey.ToString(), MvarItemKey);
                if (ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
                {
                    oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='',HDeleteDate=null,HBillStatus=3 Where HInterID=" + lngBillKey.ToString());
                }
                else if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
                {
                    oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='',HDeleteDate=null,HBillStatus=2 Where HInterID=" + lngBillKey.ToString());
                }
                else
                {
                    oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='',HDeleteDate=null,HBillStatus=1 Where HInterID=" + lngBillKey.ToString());
                }
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //反关闭
        public bool CancelClose(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                DataSet ds = oCn.RunProcReturn("select * from " + MvarItemKey + " where HInterID=" + lngBillKey.ToString(), MvarItemKey);
                if (ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "")
                {
                    oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='',HCloseDate=null,HBillStatus=4 Where HInterID=" + lngBillKey.ToString());
                }
                else if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
                {
                    oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='',HCloseDate=null,HBillStatus=2 Where HInterID=" + lngBillKey.ToString());
                }
                else
                {
                    oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='',HCloseDate=null,HBillStatus=1 Where HInterID=" + lngBillKey.ToString());
                }
 
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //反审核
        public bool AbandonCheck(Int64 lngBillKey, ref string sReturn)
        {
 
            if (isUse(lngBillKey, ref sReturn))
            {
                return false;
            }
            try
            {
                DataSet ds = oCn.RunProcReturn("select * from " + MvarItemKey + " where HInterID=" + lngBillKey.ToString(), MvarItemKey);
                if (ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "")
                {
                    oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=4 Where HInterID=" + lngBillKey.ToString());
                }
                else if (ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
                {
                    oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=3 Where HInterID=" + lngBillKey.ToString());
                }
                else
                {
                    oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=1 Where HInterID=" + lngBillKey.ToString());
                }
               
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //审核
        public bool CheckBill(Int64 lngBillKey, ref string sReturn)
        {
           
            try
            {
                string  HChecker = ClsPub.CurUserName ;
                string  HCheckDate =ClsPub.GetServerDate(-1);
                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='" + HChecker + "',HCheckDate='" + HCheckDate + "',HBillStatus=2 Where HInterID=" + lngBillKey.ToString());
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //审核
        public bool CheckBill(Int64 lngBillKey,string sUser, ref string sReturn)
        {
 
            try
            {
                string HChecker = sUser;
                string HCheckDate = ClsPub.GetServerDate(-1);
                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='" + HChecker + "',HCheckDate='" + HCheckDate + "' Where HInterID=" + lngBillKey.ToString());
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //关闭
        public bool CloseBill(Int64 lngBillKey, ref string sReturn)
        {
 
            try
            {
                string HCloseMan = ClsPub.CurUserName;
                string HCloseDate = ClsPub.GetServerDate(-1); 
                oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='" + HCloseMan + "',HCloseDate='" + HCloseDate + "',HBillStatus=3 Where HInterID=" + lngBillKey.ToString());
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //关闭
        public bool CloseBill(Int64 lngBillKey, string sUser, ref string sReturn)
        {
 
            try
            {
                string HCloseMan = sUser;
                string HCloseDate = ClsPub.GetServerDate(-1);
                oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='" + HCloseMan + "',HCloseDate='" + HCloseDate + "' Where HInterID=" + lngBillKey.ToString());
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //作废
        public bool Cancelltion(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                string HDeleteMan = ClsPub.CurUserName;
                string HDeleteDate = ClsPub.GetServerDate(-1);
                oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='" + HDeleteMan + "',HDeleteDate='" + HDeleteDate + "',HBillStatus=4 Where HInterID=" + lngBillKey.ToString());
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
 
        //作废
        public bool Cancelltion(Int64 lngBillKey,string sUser, ref string sReturn)
        {
            try
            {
                string HDeleteMan = sUser;
                string HDeleteDate = ClsPub.GetServerDate(-1);
                oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='" + HDeleteMan + "',HDeleteDate='" + HDeleteDate + "' Where HInterID=" + lngBillKey.ToString());
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //保养计划删除子表1
        public void DeleteBillSub(Int64 lngBillKey)
        {
            oCn.RunProc("Delete From " + MvarItemKeySub + "  where HInterID=" + lngBillKey.ToString());
        }
        //保养计划删除子表2
        public void DeleteBillSub2(Int64 lngBillKey)
        {
            if (MvarItemKeySub2 != "")
            {
                oCn.RunProc("Delete From " + MvarItemKeySub2 + "  where HInterID=" + lngBillKey.ToString());
            }
        }
        //删除子表
        public void DeleteBillSub3(Int64 lngBillKey)
        {
            if (MvarItemKeySub3 != "")
            {
                oCn.RunProc("Delete From " + MvarItemKeySub3 + "  where HInterID=" + lngBillKey.ToString());
            }
        }
        //删除子表
        public void DeleteBillSub4(Int64 lngBillKey)
        {
            if (MvarItemKeySub4 != "")
            {
                oCn.RunProc("Delete From " + MvarItemKeySub4 + "  where HInterID=" + lngBillKey.ToString());
            }
        }
        //删除主表
        public void DeleteBillMain(Int64 lngBillKey)
        {
            oCn.RunProc("Delete From " + MvarItemKey + "  where HInterID=" + lngBillKey.ToString());
        }
        //删除单据
        public virtual bool DeleteBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                oCn.BeginTran();
                //删除关联
                DeleteRelation(ref sReturn, lngBillKey);
                //删除明细表
                DeleteBillSub(lngBillKey);
                DeleteBillSub2(lngBillKey);
                DeleteBillSub3(lngBillKey);
                DeleteBillSub4(lngBillKey);
                //删除主表
                DeleteBillMain(lngBillKey);
                sReturn = "删除单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                throw (e);
            }
        }
        //是否被关联
        public bool isUse(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //查询主表
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select HinterID from " + MvarItemKeySub + "  Where HInterID=" + lngBillKey.ToString() + " and isnull(HRelationQty,0)<>0 ", MvarItemKey);
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    sReturn = "单据已被关联,不能操作!";
                    return true;
                }
                sReturn = "";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //读取下张单据
        public bool GetNextBill(ref string sReturn,string HBillNo)
        {
            try
            {
                //查询主表
                Int64 lMainID = 0;
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select Top 1 HinterID from " + MvarItemKey + "  Where HBillNo>'" +  HBillNo + "' and HBillType='" + this.BillType + "' Order By HInterID ", MvarItemKey);
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                    if (lMainID != 0)
                    {
                        if (ShowBill(lMainID, ref sReturn))
                        {
                            sReturn = "查询下张单据成功";
                            return true;
                        }
                    }
                }
                sReturn = "查询下张单据失败";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //读取上张单据
        public bool GetPrevousBill(ref string sReturn, string HBillNo)
        {
            try
            {
                //查询主表
                Int64 lMainID = 0;
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select Top 1 HinterID from " + MvarItemKey + "  Where HBillNo<'" + HBillNo + "' and HBillType='" + BillType + "' Order By HInterID Desc", MvarItemKey);
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                    if (lMainID != 0)
                    {
                        if (ShowBill(lMainID, ref sReturn))
                        {
                            sReturn = "查询上张单据成功";
                            return true;
                        }
                    }
                }
                sReturn = "查询上张单据失败";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //读取首张单据
        public bool GetFirstBill(ref string sReturn)
        {
            try
            {
                //查询主表
                Int64 lMainID = 0;
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select Top 1 HinterID from " + MvarItemKey + "  Where   HBillType='" + BillType + "' Order By HInterID ", MvarItemKey);
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                    if (lMainID != 0)
                    {
                        if (ShowBill(lMainID, ref sReturn))
                        {
                            sReturn = "查询首张单据成功";
                            return true;
                        }
                    }
                }
                sReturn = "查询首张单据失败";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //读取末张单据
        public bool GetLastBill(ref string sReturn)
        {
            try
            {
                //查询主表
                Int64 lMainID = 0;
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select Top 1 HinterID from " + MvarItemKey + "  Where   HBillType='" + BillType + "' Order By HInterID Desc", MvarItemKey);
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                    if (lMainID != 0)
                    {
                        if (ShowBill(lMainID, ref sReturn))
                        {
                            sReturn = "查询末张单据成功";
                            return true;
                        }
                    }
                }
                sReturn = "查询末张单据失败";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //MAINID是否重复
        public virtual bool IsExistMainID(ref string sReturn, Int64 lngBillKey, ClsPub.Enum_BillStatus oBillStatus)
        {
            try
            {
                string sSql = "";
                if (oBillStatus == ClsPub.Enum_BillStatus.BillStatus_AddNew)
                {
                    sSql = "Select HInterID from " + MvarItemKey + "  where HInterID =" + lngBillKey + "";
 
                    DataSet Ds;
                    Ds = oCn.RunProcReturn(sSql, " + MvarItemKey + ");
                    if (Ds.Tables[0].Rows.Count != 0)
                    {
                        sReturn = "ID重复";
                        return true;
                    }
                }
                sReturn = "ID未重复";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //K3单据号是否重复
        public bool IsExistBillNoK3(ref string sReturn, string sBillNo, ClsPub.Enum_BillStatus oBillStatus, Int64 lngBillKey)
        {
            try
            {
                string sSql = "";
                if (oBillStatus == ClsPub.Enum_BillStatus.BillStatus_AddNew)
                {
                    sSql = "Select FInterID from " + MvarItemKey + "  where ftrantype='" + BillType + "'and FBillNO ='" + sBillNo + "'";
                }
                else
                {
                    sSql = "Select FInterID from " + MvarItemKey + "  where ftrantype='" + BillType + "'and FBillNO ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString();
                }
                DataSet Ds;
                Ds = oCnK3.RunProcReturn(sSql, " + MvarItemKey + ");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    sReturn = "单号重复";
                    return true;
                }
                sReturn = "单号未重复";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //单据号是否重复
        public virtual bool IsExistBillNo(ref string sReturn, string sBillNo, ClsPub.Enum_BillStatus oBillStatus, Int64 lngBillKey)
        {
            string sSql = "";
            try
            {
           
                if (oBillStatus == ClsPub.Enum_BillStatus.BillStatus_AddNew)
                {
                    sSql = "Select HInterID from " + MvarItemKey + "  where hbilltype='" + BillType + "'and HBillNO ='" + sBillNo + "'";
                }
                else
                {
                    sSql = "Select HInterID from " + MvarItemKey + "  where hbilltype='" + BillType + "'and HBillNO ='" + sBillNo + "' and HInterID<>" + lngBillKey.ToString();
                }
                DataSet Ds ;
                Ds = oCn.RunProcReturn(sSql, " + MvarItemKey + ");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    sReturn = "单号重复";
                    return true;
                }
                sReturn = "单号未重复";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message+"sql:"+ sSql;
                return false;
            }
        }
        #endregion
        //修改单据
        public virtual bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            return true;
        }
        //新增单据
        public virtual bool AddBill( ref string sReturn)
        {
            return true;
        }
        //显示单据
        public virtual bool ShowBill(Int64 lngBillKey, ref string sReturn)
        {
            return true;
        }
       
 
        //删除关联
        public virtual void  DeleteRelation(ref string sReturn, Int64 lngBillKey)
        {
            sReturn = "";
            return;
        }
 
        //新增关联
        public virtual void AddNewRelation(ref string sReturn, Int64 lngBillKey)
        {
            sReturn = "";
            return;
        }
 
        //读取下张单据K3
        public bool GetNextBillK3(ref string sReturn, string HBillNo)
        {
            try
            {
                //查询主表
                Int64 lMainID = 0;
                DataSet Ds;
                Ds = oCnK3.RunProcReturn("Select Top 1 FinterID from " + MvarItemKey + "  Where FBillNo>'" + HBillNo + "' and FTranType='" + this.BillType + "' Order By FInterID ", MvarItemKey);
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["FInterID"].ToString());
                    if (lMainID != 0)
                    {
                        if (ShowBill(lMainID, ref sReturn))
                        {
                            sReturn = "查询下张单据成功";
                            return true;
                        }
                    }
                }
                sReturn = "查询下张单据失败";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
 
        //读取首张单据K3
        public bool GetFirstBillK3(ref string sReturn)
        {
            try
            {
                //查询主表
                Int64 lMainID = 0;
                DataSet Ds;
                Ds = oCnK3.RunProcReturn("Select Top 1 FinterID from " + MvarItemKey + "  Where   FTranType='" + BillType + "' Order By FInterID ", MvarItemKey);
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["FInterID"].ToString());
                    if (lMainID != 0)
                    {
                        if (ShowBill(lMainID, ref sReturn))
                        {
                            sReturn = "查询首张单据成功";
                            return true;
                        }
                    }
                }
                sReturn = "查询首张单据失败";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
 
        //读取末张单据K3
        public bool GetLastBillK3(ref string sReturn)
        {
            try
            {
                //查询主表
                Int64 lMainID = 0;
                DataSet Ds;
                Ds = oCnK3.RunProcReturn("Select Top 1 FinterID from " + MvarItemKey + "  Where   FTranType='" + BillType + "' Order By FInterID Desc", MvarItemKey);
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["FInterID"].ToString());
                    if (lMainID != 0)
                    {
                        if (ShowBill(lMainID, ref sReturn))
                        {
                            sReturn = "查询末张单据成功";
                            return true;
                        }
                    }
                }
                sReturn = "查询末张单据失败";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
 
        //读取上张单据K3
        public bool GetPrevousBillK3(ref string sReturn, string HBillNo)
        {
            try
            {
                //查询主表
                Int64 lMainID = 0;
                DataSet Ds;
                Ds = oCnK3.RunProcReturn("Select Top 1 FinterID from " + MvarItemKey + "  Where FBillNo<'" + HBillNo + "' and FTranType='" + BillType + "' Order By FInterID Desc", MvarItemKey);
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["FInterID"].ToString());
                    if (lMainID != 0)
                    {
                        if (ShowBill(lMainID, ref sReturn))
                        {
                            sReturn = "查询上张单据成功";
                            return true;
                        }
                    }
                }
                sReturn = "查询上张单据失败";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
 
        //显示单据头
        public DataSet ShowBillMain(Int64 lngBillKey,string sShowItem, ref string sReturn)
        {
            string s = "";
            try
            {
                //查询主表
                DataSet Ds;
                s = "Select " + sShowItem + " from " + MvarItemKeyForWeb + " Where HInterID=" + lngBillKey.ToString();
                Ds = oCn.RunProcReturn("Select " + sShowItem + " from " + MvarItemKeyForWeb + " Where HInterID=" + lngBillKey.ToString(), MvarItemKeyForWeb);
                if (Ds==null ||  Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "单据头未找到!";
                    return null;
                }
                sReturn = "显示单据头成功!";
                return Ds;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return null;
            }
        }
 
        //显示单据头2
        public DataSet ShowBillMain(Int64 lngBillKey, Int64 HEntryID, string sShowItem, ref string sReturn)
        {
            string s = "";
            try
            {
                //查询主表
                DataSet Ds;
                s = "Select " + sShowItem + " from " + MvarItemKeyForWeb + " Where HInterID=" + lngBillKey.ToString() + " and HEntryID=" + HEntryID;
                Ds = oCn.RunProcReturn("Select " + sShowItem + " from " + MvarItemKeyForWeb + " Where HInterID=" + lngBillKey.ToString() + " and HEntryID=" + HEntryID, MvarItemKeyForWeb);
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "单据头未找到!";
                    return null;
                }
                sReturn = "显示单据头成功!";
                return Ds;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return null;
            }
        }
 
        //显示单体
        public DataSet ShowBillSub(Int64 lngBillKey, string sShowItem, ref string sReturn)
        {
            string s = "";
            try
            {
                //查询主表
                DataSet Ds;
                s = "Select " + sShowItem + "  from " + MvarItemKeySubForWeb + " Where HInterID=" + lngBillKey.ToString() + " order by HEntryID ";
                Ds = oCn.RunProcReturn("Select " + sShowItem + "  from " + MvarItemKeySubForWeb + " Where HInterID=" + lngBillKey.ToString() + " order by HEntryID ", MvarItemKeySubForWeb);
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "单据体未找到!";
                    return null;
                }
                sReturn = "显示单据体成功!";
                return Ds;
            }
            catch (Exception e)
            {
                sReturn = e.Message + s ;
                return null;
            }
        }
 
        //显示表体
        public DataSet ShowBillSub(Int64 lngBillKey, Int64 HEntryID, string sShowItem, ref string sReturn)
        {
            string s = "";
            try
            {
                //查询主表
                DataSet Ds;
                s = "Select " + sShowItem + "  from " + MvarItemKeySubForWeb + " Where HInterID=" + lngBillKey.ToString() + " and HEntryID=" + HEntryID + " order by HEntryID ";
                Ds = oCn.RunProcReturn("Select " + sShowItem + "  from " + MvarItemKeySubForWeb + " Where HInterID=" + lngBillKey.ToString() + " and HEntryID=" + HEntryID + " order by HEntryID ", MvarItemKeySubForWeb);
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "单据体未找到!";
                    return null;
                }
                sReturn = "显示单据体成功!";
                return Ds;
            }
            catch (Exception e)
            {
                sReturn = e.Message + s;
                return null;
            }
        }
 
        //显示表体2
        public DataSet ShowBillSub2(Int64 lngBillKey, Int64 HEntryID, string sShowItem, ref string sReturn)
        {
            string s = "";
            try
            {
                //查询主表
                DataSet Ds;
                s = "Select " + sShowItem + "  from " + MvarItemKeySubForWeb2 + " Where HInterID=" + lngBillKey.ToString() + " and HEntryID=" + HEntryID + " order by HEntryID ";
                Ds = oCn.RunProcReturn("Select " + sShowItem + "  from " + MvarItemKeySubForWeb2 + " Where HInterID=" + lngBillKey.ToString() + " and HEntryID=" + HEntryID + " order by HEntryID ", MvarItemKeySubForWeb2);
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "单据体未找到!";
                    return null;
                }
                sReturn = "显示单据体成功!";
                return Ds;
            }
            catch (Exception e)
            {
                sReturn = e.Message + s;
                return null;
            }
        }
 
 
 
        //更新打印次数
        public void UpDatePrintQty(Int64 lngBillKey, ref string sReturn)
        {
 
            try
            {
                oCn.RunProc(" Update " + MvarItemKey + " set HPrintQty=HPrintQty + 1  Where HInterID=" + lngBillKey.ToString());
                sReturn = "";
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
 
 
    }
 
}