コード例 #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);
        }