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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Pub_Class;
using SQLHelper;
 
namespace BaseSet
{
    public partial class Gy_DataIn_MaterSP :BLL.Gy_DataInTmp
    {
        public Gy_DataIn_MaterSP()
        {
            InitializeComponent();
        }
 
        public int HMaterNumberCol = 0;             //²úÆ·´úÂë
        public int HSPNumberCol = 0;           //²Öλ
        //
        public const int HBeginRow = 2;         //ÓÐЧÊý¾Ý£¬¿ªÊ¼ÐÐÊý
        // 
        DAL.ClsGy_MaterStockPlace_Ctl oMaterSP = new DAL.ClsGy_MaterStockPlace_Ctl();
        DAL.ClsIF_StockPlace_View oSPHlp = new DAL.ClsIF_StockPlace_View();
        DAL.ClsIF_Material_View oMaterHlp = new DAL.ClsIF_Material_View();
        long j = -1;
        int c = 0;
 
        public override bool OpenExcelData()
        {
            base.sSheetName = txtHSheetName.Text;
            return base.OpenExcelData();
        } 
 
        /// <summary>
        ///  ³õʼ»¯½çÃæ
        /// </summary>
        public override void initData()
        {
            base.initData();
            base.sSheetName = txtHSheetName.Text ; 
            base.ModRightName = "Gy_DataIn_MaterSP";
            base.ModRightNameCheck = base.ModRightName + base.ModRightNameCheck;
            base.ModRightNameClose = base.ModRightName + base.ModRightNameClose;
            base.ModRightNameDelete = base.ModRightName + base.ModRightNameDelete;
            base.ModRightNameEdit = base.ModRightName + base.ModRightNameEdit;
            base.ModRightNameMoney = base.ModRightName + base.ModRightNameMoney;
            base.ModRightNameQty = base.ModRightName + base.ModRightNameQty;
            base.ModCaption = "ÎïÁÏÓë²Öλ¶ÔÓ¦¹ØÏµµ¼Èë";
            this.Text = base.ModCaption;
            lblCaption.Text = base.ModCaption;
            //
            //
        }
        //µ¼Èë
        public override void Sub_DataIn()
        {
            string hnumber = "";
            string HBillNo = "";
            //
            HMaterNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÎïÁϳ¤´úÂë", grdMain);
            HSPNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("²Öλ", grdMain);
            //ûÓÐÕÒµ½ÁÐ
            if (HMaterNumberCol == -1)
            {
                MessageBox.Show("ûÓÐÕÒµ½¡¾ÎïÁϳ¤´úÂë¡¿µÄ±êÌâ", "Ìáʾ");
                return;
            }
            if (HSPNumberCol == -1)
            {
                MessageBox.Show("ûÓÐÕÒµ½¡¾²Öλ¡¿µÄ±êÌâ", "Ìáʾ");
                return;
            }
            //
            if (!Checkdata())
            {
                return;
            }
            for (int i = 0; i <= grdMain.Rows.Count - 1; i++)
            {
                string sHNumber = "";
                if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HMaterNumberCol].Value) != "")
                {
                    //
                    //дÈëÀà
                    if (WriteClass(i))
                    {
                        //±£´æ¼Ç¼
                        if (!oMaterSP.AddNew())
                        {
                            MessageBox.Show("µ¼Èëʧ°Ü!Ô­Òò:" + DBUtility.ClsPub.sExeReturnInfo, "Ìáʾ");
                            return;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("ÎïÁÏ´úÂë»òÃû³ÆÎª¿Õ!Ô­Òò:" + DBUtility.ClsPub.sExeReturnInfo, "Ìáʾ");
                    return;
                }
            }
            MessageBox.Show("µ¼ÈëÍê±Ï");
            grdMain.DataSource = null;
        }
 
        //дÈëÀ࠴ӿؼþ
        private bool WriteClass(int row)
        {
            string sHNumber = "";
            string sHNameSP = ""; 
            //
            sHNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[row].Cells[HMaterNumberCol].Value);
            sHNameSP = DBUtility.ClsPub.isStrNull(grdMain.Rows[row].Cells[HSPNumberCol].Value);
            //ÅжÏÊÇ·ñÔÊÐí ±£´æ
 
            Model.ClsGy_MaterStockPlace_Model oSub = new Model.ClsGy_MaterStockPlace_Model();
            oMaterSP.DetailColl.Clear();
            //µÃµ½²ÖλÄÚÂë
            if (oSPHlp.GetInfoByNumber(sHNameSP))
            {
                oSub.HSPID = oSPHlp.omodel.HItemID;
            }
 
            //µÃµ½ÎïÁÏÄÚÂë
            if (oMaterHlp.GetInfoByNumber(sHNumber))
            {
                oSub.HMaterID = oMaterHlp.omodel.HItemID;
            }
            //дÈëÐÅÏ¢
            oSub.HSPGroupID = 0;
            oSub.HDeptID = 0;
            oSub.HQty = 1000000;
            oSub.HStopflag = true;
            oSub.HRemark = "";
            oSub.HMaker = DBUtility.ClsPub.CurUserName;
            oSub.HMakeDate = DBUtility.ClsPub.GetServerDate(-1);
            
            oMaterSP.DetailColl.Add(oSub);
            return true;
        }
 
        //¼ì²éÎïÁÏ
        private bool Checkdata()
        {
            bool b=false;
            string sErrMsg = "";
            string sMsg = "";
            for (int i = 0; i <= grdMain.Rows.Count - 1; i++)
            {
                string sHNumber = "";
                string sHNameSP = ""; 
                
                //
                sHNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HMaterNumberCol].Value);
                sHNameSP = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HSPNumberCol].Value);
                if (sHNumber != "" )
                {
                    // 
                    //ÉóºË´úÂëÊÇ·ñºÏÀí
                    if (!DBUtility.ClsPub.AllowNumber(sHNumber))
                    {
                        MessageBox.Show("ÎïÁÏ´úÂëÖв»ÄܳöÏÖÁ¬Ðø¡®.¡¯²¢ÇÒÊ×λĩλ²»ÄÜΪ¡®.¡¯£¡", "Ìáʾ");
                        return false;
                    }
                    //µÃµ½ÎïÁÏÄÚÂë
                    int j = i + HBeginRow;
                    if (!oMaterHlp.GetInfoByNumber(sHNumber))
                    {
                        sMsg = "[" + sHNumber + "]ÎïÁϲ»´æÔÚ";
                        if (sErrMsg.Contains(sMsg)==false)
                        {
                            sErrMsg = sErrMsg + "[" + sHNumber + "]ÎïÁϲ»´æÔÚ\r\n" ;
                        }
                        b = true;
                    }
                    //µÃµ½²ÖλÄÚÂë
                    if (!oSPHlp.GetInfoByName(sHNameSP))
                    {
                        sMsg = "[" + sHNameSP + "]²Öλ²»´æÔÚ";
                        if (sErrMsg.Contains(sMsg) == false)
                        {
                            sErrMsg = sErrMsg + "[" + sHNameSP + "]²Öλ²»´æÔÚ\r\n";
                        }
                        b = true;
                    }
                }               
            }
            if (b == true)
            {
                Pub_Control.ErrMsgBox oMsgbox = new Pub_Control.ErrMsgBox();
                oMsgbox.txtHErrMsg.Text = sErrMsg;
                oMsgbox.ShowDialog();
                return false;
            }
            else
            {
                return true;
            }
 
        }
 
    }
}