Пример #1
0
        private void listViewNF1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                #region listview双击获取item事件,同时获取路径,名称
                ListViewHitTestInfo info = listViewNF1.HitTest(e.X, e.Y);
                bll = new travelInfoBLL();
                if (info.Item != null)
                {
                    ListViewItem item = info.Item as ListViewItem;
                    selecteditempath   = item.Tag.ToString();
                    this.txtTitle.Text = oldfilesname = Path.GetFileNameWithoutExtension(selecteditempath);
                    string tmppath = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["baoxiao_path"], DateTime.Now.Year.ToString(), "tmp", txtTitle.Text) + ".dat";

                    if (!File.Exists(tmppath))
                    {
                        if (MessageBox.Show("不存在该tmp'文件,是否从excel导入?", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            // bll.serialize_zongjie( bll.getZongJie());
                            bll.excel2ZongJie(selecteditempath);
                            DataGridView_LoadData(bll.getZongJie(), tmppath);
                            bll.serialize_zongjie(tmppath);
                        }
                        return;
                    }
                    if (oldlistItem != item)
                    {//首先判断是否listview点击同一个项,然后清除datagridview,再反系列化数据,然后清除文本框
                        oldlistItem = item;
                        this.dataGridView1.Rows.Clear();
                        dataGridView_LoadData(tmppath);
                        CleanTextBox();
                    }
                    else
                    {
                        MessageBox.Show("您选中的是同一个选项");
                    }
                    listviewitem_selected = true;
                }
                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            ListViewItem item = this.listViewNF1.SelectedItems[0];

            selecteditempath = item.Tag.ToString();
            string tmppath = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["baoxiao_path"], DateTime.Now.Year.ToString(), "tmp", txtTitle.Text) + ".dat";

            if (File.Exists(tmppath))
            {
                File.Delete(tmppath);
                MessageBox.Show("delete 文件成功");
            }
            bll = new travelInfoBLL();
            bll.excel2ZongJie(selecteditempath);
            bll.serialize_zongjie(tmppath);
            MessageBox.Show(item.Text + " dat文件创建成功!");
            LogHelper.log(item.Text + " dat文件创建成功!");
            dataGridView_LoadData(tmppath);
        }
Пример #3
0
        //完成按钮,生成dat文件
        private void btnFinish_Click(object sender, EventArgs e)
        {
            try
            {
                //改了标题
                if (oldfilesname != string.Empty && oldfilesname != this.txtTitle.Text.Trim())
                {
                    //删掉老的file 和老的excel文件
                    string tmpPath = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["baoxiao_path"], DateTime.Now.Year.ToString(), "tmp", oldfilesname) + ".dat";
                    File.Delete(tmpPath);

                    tmpPath      = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["baoxiao_path"], DateTime.Now.Year.ToString(), oldfilesname) + ".xlsx";
                    nowfilepath  = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["baoxiao_path"], DateTime.Now.Year.ToString(), this.txtTitle.Text.Trim()) + ".xlsx";
                    titlechanged = true;
                    File.Delete(tmpPath);

                    MessageBox.Show("标题已经改变,因此删除了老的dat文件和老的excel报销文件");
                    //生成新的dat文件
                    tmpPath = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["baoxiao_path"], DateTime.Now.Year.ToString(), "tmp", this.txtTitle.Text.Trim()) + ".dat";
                    bll.serialize_zongjie(tmpPath);
                    MessageBox.Show("新dat文件生成正常");
                    //生成新的excel文件
                    File.Copy(System.Configuration.ConfigurationManager.AppSettings["excel_module"], nowfilepath);
                    //刷新listview
                    string dt       = DateTime.Now.Year.ToString();
                    string destpath = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["baoxiao_path"], dt);
                    if (Directory.Exists(destpath))
                    {
                        this.listViewNF1.Items.Clear();
                        //load file
                        CommonHelper.loadFile(destpath, this.listViewNF1, this.largeimagelist, this.smallimagelist);
                    }
                }
                else
                {
                    //未改标题
                    if (this.listviewitem_selected == false)
                    {
                        //未选中,则需要重选,否则没有办法保存
                        MessageBox.Show("请选中所要保存的文件项");
                    }
                    else
                    {
                        if (this.dataGridView1.Rows.Count > 0)
                        {
                            string tmpPath = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["baoxiao_path"], DateTime.Now.Year.ToString(), "tmp", this.txtTitle.Text) + ".dat";
                            //save bll.list to tmp file
                            bll.serialize_zongjie(tmpPath);
                            MessageBox.Show("写入dat文件完成");
                        }
                        else
                        {
                            MessageBox.Show("没有数据输入");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }