Example #1
0
        //批量导入身高
        private void BatchInputHeight_Click(object sender, RoutedEventArgs e)
        {
            string         acitivityId    = Uid;
            CheckDataUtill checkDataUtill = new CheckDataUtill();
            OpenFileDialog ofd            = new OpenFileDialog
            {
                Title  = "请选择批量导入文件",
                Filter = "excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*"
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string    path     = Path.GetFullPath(ofd.FileName);
                DataTable dt       = checkDataUtill.DBExcelToDataTable(path, "Sheet1");
                int       errcount = 0;
                try
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string studentId  = dt.Rows[i][0].ToString();
                        string height     = dt.Rows[i][2].ToString();
                        double height_int = double.Parse(height);
                        int    count      = dbUtill.UpdateStudentHeight(studentId, height_int);
                        if (count < 1)
                        {
                            System.Windows.MessageBox.Show("导入失败,不存在学号为" + studentId + "的学生", "错误");
                            errcount = ++errcount;
                        }
                    }
                    if (errcount == 0)
                    {
                        System.Windows.MessageBox.Show("全部导入成功", "成功");
                    }
                    else
                    {
                        System.Windows.MessageBox.Show("导入失败" + errcount.ToString() + "条", "错误");
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show("批量导入失败,因为" + ex.Message, "错误");
                }
            }
        }
Example #2
0
        //批量导入
        private void BathInoutBtn_Click(object sender, RoutedEventArgs e)
        {
            CheckDataUtill checkDataUtill = new CheckDataUtill();
            OpenFileDialog ofd            = new OpenFileDialog
            {
                Title  = "请选择批量导入文件",
                Filter = "excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*"
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string    path = Path.GetFullPath(ofd.FileName);
                DataTable dt   = checkDataUtill.DBExcelToDataTable(path, "Sheet1");
                try
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string memberName = dt.Rows[i][0].ToString();
                        string birthday   = dt.Rows[i][1].ToString();
                        string sex        = dt.Rows[i][2].ToString();
                        int    sex_int;
                        if (sex.Equals("男"))
                        {
                            sex_int = 0;
                        }
                        else
                        {
                            sex_int = 1;
                        }
                        string height       = dt.Rows[i][3].ToString();
                        double memberHeight = double.Parse(height);
                        dbUtill.AddMember(memberName, birthday, sex_int, memberHeight);
                    }
                    System.Windows.MessageBox.Show("导入成功", "提示");
                    Init();
                }
                catch (Exception ex)
                {
                }
            }
        }