Exemplo n.º 1
0
        private void ImportCmdExcute(object param)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Excel (*.XLS)|*.xls";;
            if ((bool)(openFileDialog.ShowDialog()))
            {
                string    excelName = openFileDialog.FileName;
                DataTable dt        = _excelHelper.LoadExcel(excelName);
                DataGridSource = dt.DefaultView;
            }
        }
Exemplo n.º 2
0
        public void DaoIn()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            ExcelHelp      _excelHelper   = new ExcelHelp();

            openFileDialog.Filter = "Excel (*.XLS)|*.xls";
            int i = 0, j = 0;

            if ((bool)(openFileDialog.ShowDialog()))
            {
                try
                {
                    DataTable     dt = _excelHelper.LoadExcel(openFileDialog.FileName);
                    List <wrench> s  = ListWrench(dt);
                    if (s != null && s.Count > 0)
                    {
                        foreach (wrench w in s)
                        {
                            try
                            {
                                if (Wrench.add(w))
                                {
                                    i++;
                                }
                                else
                                {
                                    j++;
                                    LogUtil.WriteLog(typeof(string), "序号为 " + w.id.ToString() + "到入失败:");
                                }
                            }
                            catch
                            {
                                j++;
                                LogUtil.WriteLog(typeof(wrench), w.wrenchBarCode + "导入失败!");
                            }
                        }
                        MessageBox.Show("成功导入" + i.ToString() + "条" + "   失败" + j.ToString() + "条");
                    }
                    // Wrench.addlist(ListWrench (dt));
                }
                catch (Exception ex)
                {
                    LogUtil.WriteLog(typeof(string), "工具批量导入失败:" + ex);
                    MessageBox.Show("批量导入工具信息失败,填写信息有误");
                    return;
                }
            }
        }