using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Data; namespace SiaSun.LMS.WPFClient.GOODS { /// /// PLAN_IMPORT.xaml 的交互逻辑 /// public partial class GOODS_IMPORT : AvalonDock.DocumentContent { public GOODS_IMPORT() { InitializeComponent(); } /// /// 加载窗体 /// private void DocumentContent_Loaded(object sender, RoutedEventArgs e) { } /// /// 按钮点击事件 /// private void WrapPanel_Click(object sender, RoutedEventArgs e) { Button btn = e.OriginalSource as Button; if (btn != null) { switch (btn.Name) { case "btnOpen": this.ImportExcel(); break; case "btnSave": this.Save(); break; case "btnRefresh": this.gridImport.ItemsSource = null; break; } } } /// /// 导入EXCEL数据 /// private void ImportExcel() { using (System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog()) { //openFileDialog.Filter = "Excel 2007文件|*.xlsx|Excel 2003|*.xls"; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string fileName = openFileDialog.FileName; if (string.IsNullOrEmpty(fileName)) { MainApp._MessageDialog.ShowDialog("请选择Excel文件"); return; } this.gridImport.ItemsSource = new SiaSun.LMS.Common.Excel().ImportToDataTable(fileName, true).DefaultView; } //Dialog.ImportExcelDialog winImport = new Dialog.ImportExcelDialog(false, "GOODS_MAIN_IMPORT"); //if (winImport.ShowDialog() == true) //{ // this.gridImport.ItemsSource = winImport.dsImport.Tables[0].DefaultView; // winImport.Close(); //} } } /// /// 保存 /// private void Save() { string mesResult = string.Empty; string sResult = string.Empty; bool bResult = true; try { DataTable dtImport = (this.gridImport.ItemsSource as DataView).Table; if (dtImport.Rows.Count == 0) { MainApp._MessageDialog.Show(false, "不存在导入的数据源"); return; } dtImport.TableName = "ExcelImport"; bResult = MainApp._I_BaseService.Invoke("PlanImport", "GoodsCreate", new object[] { dtImport,2 }, out sResult); if (bResult) { this.gridImport.ItemsSource = null; } MainApp._MessageDialog.Show(bResult, sResult); } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } } } }