예제 #1
0
        private void Input_Excel(object sender, RoutedEventArgs e)
        {
            ///弹出文件选择对话框,选取Excel文件
            ///把Excel文件内容读至数组
            ///把数组添加到表Inbound

            //DataTable dt = InputExcel.GetTable();
            DataTable dt = InputToExcel.ExcelToDataTable(true);

            try
            {
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        List <Model.Inbound> lists = new List <Model.Inbound>();
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            ///导入的数据模板
                            Model.Inbound u = new Model.Inbound();
                            // if (dt.Rows[i][0].GetType() == typeof(DBNull)) { u.Inbound_ID = ""; } else { u.Inbound_ID = dt.Rows[i][0].ToString(); }
                            u.Inbound_ID         = dt.Rows[i][0].ToString();
                            u.Inbound_Time       = dt.Rows[i][1].ToString();
                            u.Supplier_Name      = dt.Rows[i][2].ToString();
                            u.Box_ID             = dt.Rows[i][4].ToString();
                            u.Purchase_ID        = dt.Rows[i][3].ToString();
                            u.Material_ID        = dt.Rows[i][5].ToString();
                            u.Material_Spec      = dt.Rows[i][6].ToString();
                            u.Material_PQty      = Convert.ToInt32(dt.Rows[i][7]);
                            u.Material_SerialNum = dt.Rows[i][8].ToString();
                            lists.Add(u);
                        }
                        datagridinbound.ItemsSource = lists;
                    }
                }
                else
                {
                    MessageBox.Show("excel表格式错误,请重新导入");
                }
            }
            catch (ArgumentException a)
            {
                throw a;
            }
        }
예제 #2
0
        private void Input_Excel(object sender, RoutedEventArgs e)
        {
            ///弹出文件选择对话框,选取Excel文件
            ///把Excel文件内容读至数组
            ///把数组添加到表Outbound
            ///
            //DataTable dt = InputExcel.GetTable();
            DataTable dt = InputToExcel.ExcelToDataTable(true);

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    List <Model.Outbound> lists = new List <Model.Outbound>();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Model.Outbound u = new Model.Outbound();
                        u.Outbound_ID        = dt.Rows[i][0].ToString();
                        u.Outbound_Time      = dt.Rows[i][1].ToString();
                        u.Custom_Name        = dt.Rows[i][2].ToString();
                        u.Box_ID             = dt.Rows[i][4].ToString();
                        u.Sale_ID            = dt.Rows[i][3].ToString();
                        u.Material_ID        = dt.Rows[i][5].ToString();
                        u.Material_Spec      = dt.Rows[i][6].ToString();
                        u.Material_SQty      = Convert.ToInt32(dt.Rows[i][7]);
                        u.Material_SerialNum = dt.Rows[i][8].ToString();
                        lists.Add(u);
                    }
                    datagridoutbound.ItemsSource = lists;
                }
            }
            else
            {
                MessageBox.Show("excel表格式错误,请重新导入");
            }
        }