Пример #1
0
        /// <summary>
        /// TreeViewにドラッグ&ドロップされたときにコピーされたファイルを読み込み、データベースに保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeView1_Drop(object sender, DragEventArgs e)
        {
            List<CsvDataTable> myList = new List<CsvDataTable>() { };
            //mList.Clear();
            string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
            string content = "";
            string line = "";
            foreach (String s in files)
            {

                if (!File.Exists(s))
                {
                    string[] folder = System.IO.Directory.GetFiles(s, "*.CSV", System.IO.SearchOption.AllDirectories);
                    foreach (String S in folder)
                    {
                        content = File.ReadAllText(S, Encoding.GetEncoding("Shift_JIS"));
                        using (StreamReader sr = new StreamReader(S, Encoding.GetEncoding("Shift_JIS")))
                        {
                            while ((line = sr.ReadLine()) != null)
                            {
                                CsvDataTable addCsvDataTable = new CsvDataTable(line);
                                myList.Add(addCsvDataTable);
                            }
                        }
                        
                    }
                    
                }
                else
                {
                    if (s.EndsWith(".csv") || s.EndsWith(".CSV"))
                    {
                        content = File.ReadAllText(s, Encoding.GetEncoding("Shift_JIS"));
                        using (StreamReader sr = new StreamReader(s, Encoding.GetEncoding("Shift_JIS")))
                        {
                            while ((line = sr.ReadLine()) != null)
                            {
                                CsvDataTable addCsvDataTable = new CsvDataTable(line);
                                myList.Add(addCsvDataTable);
                            }
                        }
                    }
                }
            }
            Insert(db_file, myList);
            createFromDataBaseToTreeView(db_file);
        }
Пример #2
0
 /// <summary>
 /// Shift + Sが押されたときに発生するイベント
 /// 現在表示されているリストを保存する
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
   private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
   {
       if ((Keyboard.Modifiers & ModifierKeys.Shift) > 0 && Key.S == e.Key)
       {
           MessageBoxResult result = MessageBox.Show("変更を保存しますか?", "編集中のCSVデータをデータベースに保存します。", MessageBoxButton.YesNoCancel);
           if (result == MessageBoxResult.Yes)
           {
               //「はい」が選択された時
               List<CsvDataTable> saveList = new List<CsvDataTable>();
               CsvDataTable addList = new CsvDataTable();
               DataView ddt = dataGrid1.ItemsSource as DataView;
                   foreach (DataRowView row in ddt)
                   {
                       addList.NationalLocalGovernmentCode = row[0] as string;
                       addList.OldPostalCode = row[1] as string;
                       addList.PostalCode = row[2] as string;
                       addList.Prefectures = row[3] as string;
                       addList.City = row[4] as string;
                       addList.TownArea = row[5] as string;
                       addList.PrefecturesKANZI = row[6] as string;
                       addList.CityKANZI = row[7] as string;
                       addList.TownAreaKANZI = row[8] as string;
                       addList.Case1 = row[9] as string;
                       addList.Case2 = row[10] as string;
                       addList.Case3 = row[11] as string;
                       addList.Case4 = row[12] as string;
                       addList.Case5 = row[13] as string;
                       addList.ReasonForChange = row[14] as string;
                       saveList.Add(new CsvDataTable(addList));
                   } 
               Update(db_file,selectedKey,selectedCategory,saveList);
           }
       }  
   }