You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
5.3 KiB
199 lines
5.3 KiB
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Data;
|
|
using SSWMS.Common;
|
|
|
|
namespace SSWMS.Client
|
|
{
|
|
/// <summary>
|
|
/// 导入类型
|
|
/// </summary>
|
|
public enum ImportType
|
|
{
|
|
Excel,
|
|
Xml
|
|
}
|
|
|
|
/// <summary>
|
|
/// ImportWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class ImportExcelDialog : Window
|
|
{
|
|
ImportType emImportType = ImportType.Excel;
|
|
bool _IsCommit = true; //是否提交保存
|
|
string _tableConverterCode = null;
|
|
DataSet dsImport = null;
|
|
|
|
public DataTable dt = null;
|
|
|
|
/// <summary>
|
|
/// 导入文件类型
|
|
/// </summary>
|
|
public ImportType U_ImportType
|
|
{
|
|
set { emImportType = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入的数据集集合
|
|
/// </summary>
|
|
public DataSet U_ImportDataSet
|
|
{
|
|
get { return dsImport; }
|
|
set { dsImport = value; }
|
|
}
|
|
|
|
#region ------构造函数
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
public ImportExcelDialog(bool IsCommit)
|
|
{
|
|
InitializeComponent();
|
|
this._IsCommit = IsCommit;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
public ImportExcelDialog(bool IsCommit,string TableConverterCode):this(IsCommit)
|
|
{
|
|
this._tableConverterCode = TableConverterCode;
|
|
this.cmbTemplateName.IsEnabled = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 加载窗体
|
|
/// </summary>
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
//加载所有模板
|
|
//this.LoadTemplate();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按钮事件
|
|
/// </summary>
|
|
private void WrapPanel_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
Button btn = e.OriginalSource as Button;
|
|
if (btn != null)
|
|
{
|
|
switch (btn.Name)
|
|
{
|
|
case "btnOpen":
|
|
this.OpenFile();
|
|
break;
|
|
case "btnImport":
|
|
this.ImportFile();
|
|
break;
|
|
case "btnClose":
|
|
this.Close();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 选择导入文件
|
|
/// </summary>
|
|
private void OpenFile()
|
|
{
|
|
System.Windows.Forms.OpenFileDialog opDig = new System.Windows.Forms.OpenFileDialog();
|
|
|
|
//判断导入文件类型
|
|
switch (emImportType)
|
|
{
|
|
case ImportType.Excel:
|
|
break;
|
|
case ImportType.Xml:
|
|
this.ImportXml();
|
|
break;
|
|
}
|
|
|
|
if (opDig.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
this.txtFileName.Text = opDig.FileName;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入文件
|
|
/// </summary>
|
|
private void ImportFile()
|
|
{
|
|
if (string.IsNullOrEmpty(this.txtFileName.Text) )
|
|
{
|
|
MessageDialog.ShowException(string.Format("请检查{0}输入值是否为空值",
|
|
string.Format("[{0}/{1}]", this.lblTemplateName.Text, this.lblFileName.Text)));
|
|
return;
|
|
}
|
|
|
|
//判断导入文件类型
|
|
switch (emImportType)
|
|
{
|
|
case ImportType.Excel:
|
|
this.ImportGoodsExcel();
|
|
break;
|
|
case ImportType.Xml:
|
|
this.ImportXml();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void ImportGoodsExcel()
|
|
{
|
|
try
|
|
{
|
|
//获得Excel数据源
|
|
//dt = new SSWMS.Common.Excel().ImportToDataTable(this.txtFileName.Text, true);
|
|
|
|
//if (dt.Rows.Count > 0)
|
|
// {
|
|
// dt.TableName = "ExcelImport";
|
|
|
|
// this.DialogResult = true;
|
|
// }
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageDialog.ShowException(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入XML文件
|
|
/// </summary>
|
|
private void ImportXml()
|
|
{
|
|
if (this.dsImport != null)
|
|
{
|
|
this.dsImport.ReadXml(this.txtFileName.Text);
|
|
|
|
//判断是否提交保存
|
|
if (this._IsCommit)
|
|
{
|
|
try
|
|
{
|
|
string sResult = string.Empty;
|
|
int intAffect = WCFChannel._I_BaseService.UpdateDataTable(dsImport.Tables[0], dsImport.Tables[0].TableName, out sResult);
|
|
MessageDialog.ShowResult(intAffect > 0, sResult);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageDialog.ShowException(ex);
|
|
}
|
|
return;
|
|
}
|
|
|
|
this.DialogResult = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|