YL
2021-11-09 4ed78cf207b3a6222407c5fe0295cbfa38b44f55
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms; 
using System.Data.OleDb;
using System.Data.Sql;
 
namespace BaseSet
{
    public partial class Gy_NetWeight_DataIn : Form
    {
        //ClsGy_NetWeight_DataIn oTmp = new ClsGy_NetWeight_DataIn();
 
        DAL.ClsGy_NetWeight_Ctl BillNew = new DAL.ClsGy_NetWeight_Ctl();
        DAL.ClsK3_Material_View oMat = new DAL.ClsK3_Material_View();
        DAL.ClsGy_ICBomBill oBom = new DAL.ClsGy_ICBomBill();
        
        //
 
        public Gy_NetWeight_DataIn()
        {
            InitializeComponent();
        }
 
 
        private void initHeadCaption()
        {
 
        }
 
        //
        private void yl_Click(object sender, EventArgs e)
        {
            WriteClass(cmbHDataInTmp.Text);
        }
 
        //Êý¾Ýµ¼Èë
        public void WriteClass(string sName)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            string sColName;
            string sFieldName;
            if (sName == "¾»ÖØ×ÊÁϵ¼Èë")
            {
                for (int i = 0; i <= grdmain.Rows.Count - 1; i++)
                {
                    if (Mater_WriteClass(i))
                    {
                        if (!BillNew.DeleteByHMaterID(BillNew.oModel.HInterID))
                        {
                            MessageBox.Show("ɾ³ýʧ°Ü£¡");
                            return;
                        }
                        if (!BillNew.AddNew())
                        {
                            MessageBox.Show("±£´æÊ§°Ü£¡");
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("µÚ"+DBUtility.ClsPub.isStrNull(i)+"ÐУ¬ÎïÁÏδÕÒµ½£¡");
                        return;
                    }
                }
            }
            MessageBox.Show("µ¼ÈëÍê±Ï");
            grdmain.DataSource = null;
        }
 
        //дÈëÀ࠴ӿؼþ
        private bool Mater_WriteClass(int row)
        {
            //
            //BillNew.DetailColl = new List<Model.ClsGy_NetWeight_DataIn_M>();
            //Model.ClsGy_NetWeight_DataIn_M omodel = new Model.ClsGy_NetWeight_DataIn_M();
            //string sBillNo = "";
           // sBillNo = DBUtility.ClsPub.CreateBillCode("1812", ref DBUtility.ClsPub.sExeReturnInfo, true);//µÃµ½Ðµ¥ºÅ£¨È±ÉÙº¯Êý£©  Î´Íê³É
            int sMaterCol = DBUtility.Gy_BaseFun.Fun_GetCol("²úÆ·´úÂë", grdmain);
            int sQtyCol = DBUtility.Gy_BaseFun.Fun_GetCol("¾»ÖØ", grdmain);
 
            string sMaterNum = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sMaterCol].Value);
 
            long HMaterID = 0;
            long HBomID = 0;
            string HBomNumber = "";
            //дÈëÐÅÏ¢
            //
            if (oMat.GetInfoByNumber(sMaterNum))
            {
                HMaterID = oMat.omodel.HItemID;
                if (oBom.Get_BOMIDByMaterID(HMaterID, ref HBomID, ref HBomNumber))
                {
                    BillNew.oModel.HInterID = HBomID;
                    if (oBom.ShowBill(HBomID, ref  DBUtility.ClsPub.sExeReturnInfo))
                    {
                        foreach (Model.ClsGy_ICBomBillSub_K3 oSub in oBom.DetailColl)
                        {
                            if (oMat.GetInfoByID(oSub.HMaterID))
                            {
                                BillNew.oModel.HMaterID = oMat.omodel.HItemID;
                            }
                            else
                            {
                                BillNew.oModel.HMaterID = 0;
                                return false;
                            }
                        }
                    }
                }
                else
                {
                    BillNew.oModel.HInterID=0;
                    return false;
                }
            }
            else
            {
                BillNew.oModel.HInterID = 0;
                BillNew.oModel.HMaterID = 0;
                return false;
            }
            BillNew.oModel.HQty = DBUtility.ClsPub.isDoule(grdmain.Rows[row].Cells[sQtyCol].Value);
            
            return true;
        }
 
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void K3_OutMachFeeDataIn_Load(object sender, EventArgs e)
        {
            cmbHDataInTmp.SelectedIndex = 0;
            initHeadCaption();
        }
        public string ExcelPath;
        
        private void OpenExcelData(string sPath)
        {
            string sName;
            sName = "Sheet1";
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sPath + ";" +
                         "Extended Properties='Excel 8.0;IMEX=1'";
            DataSet ds = new DataSet();
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            try
            {
                OleDbDataAdapter Da = new OleDbDataAdapter("select * from [" + sName + "$]", conn);
                Da.Fill(ds);
                grdmain.DataSource = ds.Tables[0];
            }
            catch(Exception e)
            {
                MessageBox.Show("ÒýÈëEXCELÊý¾Ýʧ°Ü£¡ÇëÓë¹ÜÀíÔ±ÁªÏµ£¡" + e.Message);
            }
        }
 
        private void button1_Click_1(object sender, EventArgs e)
        {
            OpenExcelFile.Title = "Open Excel File  ";
            OpenExcelFile.FileName = "";
            OpenExcelFile.Filter = "Microsoft Office Excel Files(*.xls)|*.xls|(*.csv)|*.csv";
            OpenExcelFile.ShowDialog();
            if (OpenExcelFile.FileName != "")
            {
                ExcelPath = OpenExcelFile.FileName;
                OpenExcelData(ExcelPath);
            }
            else
            {
                ExcelPath = "";
            }
 
        }
 
    }
}