예제 #1
0
        /// <summary>
        /// 显示窗口
        /// </summary>
        private static void ShowForm()
        {
            LoadingHelper.CloseForm();

            loadingForm = new LoadingForm();
            loadingForm.ShowDialog();
        }
예제 #2
0
        // 初始化模板数据
        private void LoadResourceTemplate()
        {
            try
            {
                //显示等待框
                LoadingHelper.ShowLoadingForm();
                this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

                // 临时文件路径
                String filePath = Application.StartupPath + "\\data_template.xlsx";
                // 释放资源文件到临时文件
                byte[]     data_template = global::StudentPhotoCollection.Properties.Resources.data_template;
                FileStream fs            = new FileStream(filePath, FileMode.Create);
                fs.Write(data_template, 0, data_template.Length);
                fs.Close();

                // 加载默认表格数据
                LoadFileData(filePath);
            }
            catch (Exception e)
            {
                Console.WriteLine("+++++++++初始化模板数据发生未知异常+++++++++");
                Console.WriteLine(e.Message);
                //弹框提示
                MessageBox.Show(e.Message, "初始化模板数据未知异常");
            }
            finally
            {
                //关闭等待框
                LoadingHelper.CloseLoadingForm();
                this.Cursor = System.Windows.Forms.Cursors.Default;
            }
        }
예제 #3
0
        private void TextBox_sjmb_Click(object sender, EventArgs e)
        {
            //导入数据模板
            //选择数据模板
            this.openFileDialog_chooseFile = new OpenFileDialog();
            // 设定打开的文件类型
            openFileDialog_chooseFile.Filter = "Files|*.xls;*.xlsx";
            // 设置打开的路径
            if (this.textBox_sjmb.Text.Length > 0)
            {
                // 打开记忆
                openFileDialog_chooseFile.InitialDirectory = this.textBox_sjmb.Text.Substring(0, this.textBox_sjmb.Text.LastIndexOf("\\") + 1); //获取路径,不带文件名
            }
            else
            {
                // 打开桌面
                openFileDialog_chooseFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            }

            // 如果选定了文件
            if (openFileDialog_chooseFile.ShowDialog() == DialogResult.OK)
            {
                //显示等待框
                LoadingHelper.ShowLoadingForm();
                this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

                // 取得文件路径及文件名
                string filePath = openFileDialog_chooseFile.FileName;
                // 显示文件路径及文件名
                this.textBox_sjmb.Text = filePath;
                // 每次打开清空内容
                this.dataGridView.DataSource = null;
                // 读出excel并放入datatable
                string sheetName = this.textBox_excelSheetName.Text;
                // 输出到dataGridView
                this.dataGridView.DataSource = ReadExcelToTable(filePath, sheetName);

                // 初始化拍摄照片自动保存照片名的列、保存文件夹的列
                comboBox_photoName.Items.Clear();
                comboBox_saveFile01.Items.Clear();
                comboBox_saveFile02.Items.Clear();
                for (int i = 0; i < this.dataGridView.Columns.Count; i++)
                {
                    //禁止排序
                    this.dataGridView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;

                    comboBox_photoName.Items.Add(this.dataGridView.Columns[i].HeaderText);
                    //如果有姓名这一列,则直接使用它作为默认的照片名,否则需要人工选择一列名作为图片保存名
                    if (this.dataGridView.Columns[i].HeaderText.Contains("姓名") || this.dataGridView.Columns[i].HeaderText.Contains("名字"))
                    {
                        comboBox_photoName.SelectedIndex = i;
                        ComboBox_photoName_SelectedIndexChanged(null, null);
                    }

                    comboBox_saveFile01.Items.Add(this.dataGridView.Columns[i].HeaderText);
                    //如果有年级这一列,则直接使用它作为默认的文件夹1,否则可以人工选择一列名作为文件夹1(可不选)
                    if (this.dataGridView.Columns[i].HeaderText.Contains("年级"))
                    {
                        comboBox_saveFile01.SelectedIndex = i;
                        ComboBox_saveFile01_SelectedIndexChanged(null, null);
                    }

                    comboBox_saveFile02.Items.Add(this.dataGridView.Columns[i].HeaderText);
                    //如果有班级这一列,则直接使用它作为默认的文件夹2,否则可以人工选择一列名作为文件夹2(可不选)
                    if (this.dataGridView.Columns[i].HeaderText.Contains("班级"))
                    {
                        comboBox_saveFile02.SelectedIndex = i;
                        ComboBox_saveFile02_SelectedIndexChanged(null, null);
                    }
                }

                // 启用导出数据按钮
                this.button_ExportData.Enabled = true;


                //关闭等待框
                LoadingHelper.CloseLoadingForm();
                this.Cursor = System.Windows.Forms.Cursors.Default;
            }
        }
예제 #4
0
        /// <summary>
        /// 根据文件路径加载表格数据
        /// </summary>
        /// <param name="filePath">excel文件存放的路径</param>
        private void LoadFileData(string filePath)
        {
            try
            {
                //显示等待框
                LoadingHelper.ShowLoadingForm();
                this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

                // 显示文件路径及文件名
                this.textBox_sjmb.Text = filePath;
                // 每次打开清空内容
                this.dataGridView.DataSource = null;
                // 读出excel并放入datatable
                string sheetName = this.textBox_excelSheetName.Text;
                // 输出到dataGridView
                this.dataGridView.DataSource = ReadExcelToTable(filePath, sheetName);

                // 初始化拍摄照片自动保存照片名的列、保存文件夹的列
                comboBox_photoName.Items.Clear();
                comboBox_saveFile01.Items.Clear();
                comboBox_saveFile02.Items.Clear();
                for (int i = 0; i < this.dataGridView.Columns.Count; i++)
                {
                    //禁止排序
                    this.dataGridView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;

                    comboBox_photoName.Items.Add(this.dataGridView.Columns[i].HeaderText);
                    //如果有姓名这一列,则直接使用它作为默认的照片名,否则需要人工选择一列名作为图片保存名
                    if (this.dataGridView.Columns[i].HeaderText.Contains("姓名") || this.dataGridView.Columns[i].HeaderText.Contains("名字"))
                    {
                        comboBox_photoName.SelectedIndex = i;
                        ComboBox_photoName_SelectedIndexChanged(null, null);
                    }

                    comboBox_saveFile01.Items.Add(this.dataGridView.Columns[i].HeaderText);
                    //如果有年级这一列,则直接使用它作为默认的文件夹1,否则可以人工选择一列名作为文件夹1(可不选)
                    if (this.dataGridView.Columns[i].HeaderText.Contains("年级"))
                    {
                        comboBox_saveFile01.SelectedIndex = i;
                        ComboBox_saveFile01_SelectedIndexChanged(null, null);
                    }

                    comboBox_saveFile02.Items.Add(this.dataGridView.Columns[i].HeaderText);
                    //如果有班级这一列,则直接使用它作为默认的文件夹2,否则可以人工选择一列名作为文件夹2(可不选)
                    if (this.dataGridView.Columns[i].HeaderText.Contains("班级"))
                    {
                        comboBox_saveFile02.SelectedIndex = i;
                        ComboBox_saveFile02_SelectedIndexChanged(null, null);
                    }
                }

                // 启用导出数据按钮
                this.button_ExportData.Enabled = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("+++++++++加载表格数据发生未知异常+++++++++");
                Console.WriteLine(e.Message);
                //弹框提示
                MessageBox.Show(e.Message, "加载表格数据未知异常");
            }
            finally
            {
                //关闭等待框
                LoadingHelper.CloseLoadingForm();
                this.Cursor = System.Windows.Forms.Cursors.Default;
            }
        }